From 19d94b5384a4d466cd76c2408e51c446cc60dadd Mon Sep 17 00:00:00 2001 From: Lei Yu Date: Tue, 14 Apr 2020 17:37:18 +0800 Subject: [PATCH 1/4] add dp60 indicator mode --- keyboards/dp60/keymaps/indicator/indicator.c | 224 +++++++++++++++++++ keyboards/dp60/keymaps/indicator/keymap.c | 17 ++ keyboards/dp60/keymaps/indicator/readme.md | 10 + keyboards/dp60/keymaps/indicator/rules.mk | 3 + 4 files changed, 254 insertions(+) create mode 100644 keyboards/dp60/keymaps/indicator/indicator.c create mode 100644 keyboards/dp60/keymaps/indicator/keymap.c create mode 100644 keyboards/dp60/keymaps/indicator/readme.md create mode 100644 keyboards/dp60/keymaps/indicator/rules.mk diff --git a/keyboards/dp60/keymaps/indicator/indicator.c b/keyboards/dp60/keymaps/indicator/indicator.c new file mode 100644 index 000000000000..a5e5d77b96a0 --- /dev/null +++ b/keyboards/dp60/keymaps/indicator/indicator.c @@ -0,0 +1,224 @@ +/* + * light weight WS2812 lib V2.0b + * + * Controls WS2811/WS2812/WS2812B RGB-LEDs + * Author: Tim (cpldcpu@gmail.com) + * + * Jan 18th, 2014 v2.0b Initial Version + * Nov 29th, 2015 v2.3 Added SK6812RGBW support + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * indicator.c + */ + +#include "dp60.h" + +#include "rgblight_list.h" +#include "rgblight.h" +#include +#include +#include + +#define RGB_INDICATOR_NUM 8 +#define RGB_INDICATOR_PIN B1 + +/* + This routine writes an array of bytes with RGB values to the Dataout pin + using the fast 800kHz clockless WS2811/2812 protocol. +*/ + +// Timing in ns +#define w_zeropulse 350 +#define w_onepulse 900 +#define w_totalperiod 1250 + +// Fixed cycles used by the inner loop +#define w_fixedlow 2 +#define w_fixedhigh 4 +#define w_fixedtotal 8 + +// Insert NOPs to match the timing, if possible +#define w_zerocycles (((F_CPU / 1000) * w_zeropulse) / 1000000) +#define w_onecycles (((F_CPU / 1000) * w_onepulse + 500000) / 1000000) +#define w_totalcycles (((F_CPU / 1000) * w_totalperiod + 500000) / 1000000) + +// w1 - nops between rising edge and falling edge - low +#define w1 (w_zerocycles - w_fixedlow) +// w2 nops between fe low and fe high +#define w2 (w_onecycles - w_fixedhigh - w1) +// w3 nops to complete loop +#define w3 (w_totalcycles - w_fixedtotal - w1 - w2) + +#if w1 > 0 +# define w1_nops w1 +#else +# define w1_nops 0 +#endif + +// The only critical timing parameter is the minimum pulse length of the "0" +// Warn or throw error if this timing can not be met with current F_CPU settings. +#define w_lowtime ((w1_nops + w_fixedlow) * 1000000) / (F_CPU / 1000) +#if w_lowtime > 550 +# error "Light_ws2812: Sorry, the clock speed is too low. Did you set F_CPU correctly?" +#elif w_lowtime > 450 +# warning "Light_ws2812: The timing is critical and may only work on WS2812B, not on WS2812(S)." +# warning "Please consider a higher clockspeed, if possible" +#endif + +#if w2 > 0 +# define w2_nops w2 +#else +# define w2_nops 0 +#endif + +#if w3 > 0 +# define w3_nops w3 +#else +# define w3_nops 0 +#endif + +#define w_nop1 "nop \n\t" +#define w_nop2 "rjmp .+0 \n\t" +#define w_nop4 w_nop2 w_nop2 +#define w_nop8 w_nop4 w_nop4 +#define w_nop16 w_nop8 w_nop8 +void inline ws2812_sendarray_mask_ind(uint8_t *data, uint16_t datlen, uint8_t maskhi) { + uint8_t curbyte, ctr, masklo; + uint8_t sreg_prev; + + // masklo =~maskhi&ws2812_PORTREG; + // maskhi |= ws2812_PORTREG; + masklo = ~maskhi & _SFR_IO8((RGB_INDICATOR_PIN >> 4) + 2); + maskhi |= _SFR_IO8((RGB_INDICATOR_PIN >> 4) + 2); + sreg_prev = SREG; + cli(); + + while (datlen--) { + curbyte = (*data++); + + asm volatile(" ldi %0,8 \n\t" + "loop%=: \n\t" + " out %2,%3 \n\t" // '1' [01] '0' [01] - re +#if (w1_nops & 1) + w_nop1 +#endif +#if (w1_nops & 2) + w_nop2 +#endif +#if (w1_nops & 4) + w_nop4 +#endif +#if (w1_nops & 8) + w_nop8 +#endif +#if (w1_nops & 16) + w_nop16 +#endif + " sbrs %1,7 \n\t" // '1' [03] '0' [02] + " out %2,%4 \n\t" // '1' [--] '0' [03] - fe-low + " lsl %1 \n\t" // '1' [04] '0' [04] +#if (w2_nops & 1) + w_nop1 +#endif +#if (w2_nops & 2) + w_nop2 +#endif +#if (w2_nops & 4) + w_nop4 +#endif +#if (w2_nops & 8) + w_nop8 +#endif +#if (w2_nops & 16) + w_nop16 +#endif + " out %2,%4 \n\t" // '1' [+1] '0' [+1] - fe-high +#if (w3_nops & 1) + w_nop1 +#endif +#if (w3_nops & 2) + w_nop2 +#endif +#if (w3_nops & 4) + w_nop4 +#endif +#if (w3_nops & 8) + w_nop8 +#endif +#if (w3_nops & 16) + w_nop16 +#endif + + " dec %0 \n\t" // '1' [+2] '0' [+2] + " brne loop%=\n\t" // '1' [+3] '0' [+4] + : "=&d"(ctr) + : "r"(curbyte), "I"(_SFR_IO_ADDR(_SFR_IO8((RGB_INDICATOR_PIN >> 4) + 2))), "r"(maskhi), "r"(masklo)); + } + + SREG = sreg_prev; +} + +extern rgblight_config_t rgblight_config; + +// led 0 for caps lock, led 1 for scroll lock, led 2 for num lock +// led 3~7 for layer 1~5 +LED_TYPE dp60_leds[RGB_INDICATOR_NUM]; +const LED_TYPE RGB_LED_RED = {RGB_RED}; +const LED_TYPE RGB_LED_GREEN = {RGB_GREEN}; +const LED_TYPE RGB_LED_BLUE = {RGB_BLUE}; +const LED_TYPE RGB_LED_PURPLE = {RGB_PURPLE}; + +void indicator_led_task(void) { + led_t led_state = (led_t)host_keyboard_leds(); + uint8_t pinmask = _BV(RGB_INDICATOR_PIN & 0xF); + + for (uint8_t i = 0; i < RGB_INDICATOR_NUM; i++) { + dp60_leds[i].r = 0; + dp60_leds[i].g = 0; + dp60_leds[i].b = 0; + } + if (led_state.caps_lock) { + dp60_leds[0] = rgblight_config.enable ? led[0] : RGB_LED_RED; + } + if (led_state.scroll_lock) { + dp60_leds[1] = rgblight_config.enable ? led[1] : RGB_LED_GREEN; + } + if (led_state.num_lock) { + dp60_leds[2] = rgblight_config.enable ? led[2] : RGB_LED_BLUE; + } + for (uint8_t j = 0; j < 5; j++) { + if (layer_state_is(j+1)) { + dp60_leds[j+3] = rgblight_config.enable ? led[j+3] : RGB_LED_PURPLE; + } + } + + _SFR_IO8((RGB_INDICATOR_PIN >> 4) + 1) |= _BV(RGB_INDICATOR_PIN&0xF); + ws2812_sendarray_mask_ind((uint8_t *)dp60_leds, RGB_INDICATOR_NUM * sizeof(LED_TYPE), pinmask); + + _delay_us(50); + //ws2812_setleds_pin(dp60_leds, RGB_INDICATOR_NUM, RGB_INDICATOR_PIN); +} + +__attribute__ ((weak)) +void matrix_scan_user(void) +{ +} + +void matrix_scan_kb() { + indicator_led_task(); + matrix_scan_user(); +} diff --git a/keyboards/dp60/keymaps/indicator/keymap.c b/keyboards/dp60/keymaps/indicator/keymap.c new file mode 100644 index 000000000000..3a65e1105abc --- /dev/null +++ b/keyboards/dp60/keymaps/indicator/keymap.c @@ -0,0 +1,17 @@ +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = LAYOUT_60_hhkb( + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,KC_EQL, KC_BSLS, KC_GRV, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC,KC_RBRC,KC_BSPC, + KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT, KC_ENT, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT, MO(1), + KC_LGUI, KC_LALT, LT(1,KC_SPC), KC_RALT,KC_RGUI ), + + [1] = LAYOUT_60_hhkb( + _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,_______,KC_PSCR, + RESET, RGB_TOG,RGB_MOD,_______,KC_F13,KC_F14,_______,_______,_______,_______,_______,KC_PGUP,KC_PGDN,_______, + KC_CAPS, _______,_______,_______,_______,_______,KC_LEFT,KC_DOWN, KC_UP,KC_RIGHT,KC_HOME,KC_END,_______, + _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, + _______,_______, _______, _______,_______), +}; diff --git a/keyboards/dp60/keymaps/indicator/readme.md b/keyboards/dp60/keymaps/indicator/readme.md new file mode 100644 index 000000000000..bb3fbbbe0b66 --- /dev/null +++ b/keyboards/dp60/keymaps/indicator/readme.md @@ -0,0 +1,10 @@ + +Indicator RGB leds support for the open source viper/eagle fr4 [plate](https://github.com/yulei/viper_plate.git) + +Three wires need to be soldered: + +B1 pin (SCLK at the board) to the plate's D pin + +VCC to plate's V + +GND to plate's G diff --git a/keyboards/dp60/keymaps/indicator/rules.mk b/keyboards/dp60/keymaps/indicator/rules.mk new file mode 100644 index 000000000000..6a7476b05330 --- /dev/null +++ b/keyboards/dp60/keymaps/indicator/rules.mk @@ -0,0 +1,3 @@ +RGBLIGHT_ENABLE = yes # Use RGB underglow light + +SRC += indicator.c From eb9a674883acd50e812f922312c71bb54212c4e3 Mon Sep 17 00:00:00 2001 From: Lei Yu Date: Thu, 30 Apr 2020 10:35:16 +0800 Subject: [PATCH 2/4] update according to #7720 --- keyboards/dp60/keymaps/indicator/config.h | 14 +++ keyboards/dp60/keymaps/indicator/indicator.c | 117 ++++++++++++------- keyboards/dp60/keymaps/indicator/rules.mk | 3 +- 3 files changed, 89 insertions(+), 45 deletions(-) create mode 100644 keyboards/dp60/keymaps/indicator/config.h diff --git a/keyboards/dp60/keymaps/indicator/config.h b/keyboards/dp60/keymaps/indicator/config.h new file mode 100644 index 000000000000..329b7c14bdae --- /dev/null +++ b/keyboards/dp60/keymaps/indicator/config.h @@ -0,0 +1,14 @@ +/** + * config.h + * + */ +#pragma once + +#include "config_common.h" + +#define RGB_INDICATOR_NUM 8 +#undef RGBLED_NUM +#define RGBLED_NUM (18+RGB_INDICATOR_NUM) + +#define RGB_INDICATOR_PIN B1 +#define RGBLIGHT_LAYERS diff --git a/keyboards/dp60/keymaps/indicator/indicator.c b/keyboards/dp60/keymaps/indicator/indicator.c index a5e5d77b96a0..72283310f8fe 100644 --- a/keyboards/dp60/keymaps/indicator/indicator.c +++ b/keyboards/dp60/keymaps/indicator/indicator.c @@ -29,13 +29,11 @@ #include "rgblight_list.h" #include "rgblight.h" +#include "ws2812.h" #include #include #include -#define RGB_INDICATOR_NUM 8 -#define RGB_INDICATOR_PIN B1 - /* This routine writes an array of bytes with RGB values to the Dataout pin using the fast 800kHz clockless WS2811/2812 protocol. @@ -96,7 +94,7 @@ #define w_nop4 w_nop2 w_nop2 #define w_nop8 w_nop4 w_nop4 #define w_nop16 w_nop8 w_nop8 -void inline ws2812_sendarray_mask_ind(uint8_t *data, uint16_t datlen, uint8_t maskhi) { +void inline indicator_sendarray_mask_ind(uint8_t *data, uint16_t datlen, uint8_t maskhi) { uint8_t curbyte, ctr, masklo; uint8_t sreg_prev; @@ -172,53 +170,84 @@ void inline ws2812_sendarray_mask_ind(uint8_t *data, uint16_t datlen, uint8_t ma SREG = sreg_prev; } +// caps led +const rgblight_segment_t PROGMEM dp60_capslock_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {18, 1, HSV_RED} +); + +// scroll led +const rgblight_segment_t PROGMEM dp60_scrolllock_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {19, 1, HSV_GREEN} +); + +// num led +const rgblight_segment_t PROGMEM dp60_numlock_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {20, 1, HSV_BLUE} +); + +// light 21 to 26 for layer 1-5 +const rgblight_segment_t PROGMEM dp60_layer1_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {21, 1, HSV_PURPLE} +); +const rgblight_segment_t PROGMEM dp60_layer2_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {22, 1, HSV_CYAN} +); +const rgblight_segment_t PROGMEM dp60_layer3_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {23, 1, HSV_YELLOW} +); +const rgblight_segment_t PROGMEM dp60_layer4_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {24, 1, HSV_PINK} +); +const rgblight_segment_t PROGMEM dp60_layer5_layer[] = RGBLIGHT_LAYER_SEGMENTS( + {25, 1, HSV_ORANGE} +); + +// rgb light layers +const rgblight_segment_t* const PROGMEM dp60_rgb_layers[] = RGBLIGHT_LAYERS_LIST( + dp60_capslock_layer, + dp60_scrolllock_layer, + dp60_numlock_layer, + dp60_layer1_layer, + dp60_layer2_layer, + dp60_layer3_layer, + dp60_layer4_layer, + dp60_layer5_layer +); + +void keyboard_post_init_user(void) { + // Enable the LED layers + rgblight_layers = dp60_rgb_layers; +} + extern rgblight_config_t rgblight_config; +extern void rgblight_layers_write(void); -// led 0 for caps lock, led 1 for scroll lock, led 2 for num lock -// led 3~7 for layer 1~5 -LED_TYPE dp60_leds[RGB_INDICATOR_NUM]; -const LED_TYPE RGB_LED_RED = {RGB_RED}; -const LED_TYPE RGB_LED_GREEN = {RGB_GREEN}; -const LED_TYPE RGB_LED_BLUE = {RGB_BLUE}; -const LED_TYPE RGB_LED_PURPLE = {RGB_PURPLE}; +void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) +{ + ws2812_setleds(led, RGBLED_NUM-RGB_INDICATOR_NUM); -void indicator_led_task(void) { - led_t led_state = (led_t)host_keyboard_leds(); uint8_t pinmask = _BV(RGB_INDICATOR_PIN & 0xF); - - for (uint8_t i = 0; i < RGB_INDICATOR_NUM; i++) { - dp60_leds[i].r = 0; - dp60_leds[i].g = 0; - dp60_leds[i].b = 0; - } - if (led_state.caps_lock) { - dp60_leds[0] = rgblight_config.enable ? led[0] : RGB_LED_RED; - } - if (led_state.scroll_lock) { - dp60_leds[1] = rgblight_config.enable ? led[1] : RGB_LED_GREEN; - } - if (led_state.num_lock) { - dp60_leds[2] = rgblight_config.enable ? led[2] : RGB_LED_BLUE; - } - for (uint8_t j = 0; j < 5; j++) { - if (layer_state_is(j+1)) { - dp60_leds[j+3] = rgblight_config.enable ? led[j+3] : RGB_LED_PURPLE; - } - } - - _SFR_IO8((RGB_INDICATOR_PIN >> 4) + 1) |= _BV(RGB_INDICATOR_PIN&0xF); - ws2812_sendarray_mask_ind((uint8_t *)dp60_leds, RGB_INDICATOR_NUM * sizeof(LED_TYPE), pinmask); - + _SFR_IO8((RGB_INDICATOR_PIN >> 4) + 1) |= pinmask; + indicator_sendarray_mask_ind((uint8_t *)(&led[RGBLED_NUM-RGB_INDICATOR_NUM]), RGB_INDICATOR_NUM * sizeof(LED_TYPE), pinmask); _delay_us(50); - //ws2812_setleds_pin(dp60_leds, RGB_INDICATOR_NUM, RGB_INDICATOR_PIN); } -__attribute__ ((weak)) -void matrix_scan_user(void) -{ +bool led_update_kb(led_t led_state) { + bool res = led_update_user(led_state); + if (res) { + rgblight_set_layer_state(0, led_state.caps_lock); + rgblight_set_layer_state(1, led_state.scroll_lock); + rgblight_set_layer_state(2, led_state.num_lock); + } + return res; } -void matrix_scan_kb() { - indicator_led_task(); - matrix_scan_user(); +layer_state_t layer_state_set_kb(layer_state_t state) { + state = layer_state_set_user(state); + rgblight_set_layer_state(3, layer_state_cmp(state, 1)); + rgblight_set_layer_state(4, layer_state_cmp(state, 2)); + rgblight_set_layer_state(5, layer_state_cmp(state, 3)); + rgblight_set_layer_state(6, layer_state_cmp(state, 4)); + rgblight_set_layer_state(7, layer_state_cmp(state, 5)); + return state; } diff --git a/keyboards/dp60/keymaps/indicator/rules.mk b/keyboards/dp60/keymaps/indicator/rules.mk index 6a7476b05330..81708748f209 100644 --- a/keyboards/dp60/keymaps/indicator/rules.mk +++ b/keyboards/dp60/keymaps/indicator/rules.mk @@ -1,3 +1,4 @@ -RGBLIGHT_ENABLE = yes # Use RGB underglow light + +RGBLIGHT_ENABLE = yes # Use RGB underglow light SRC += indicator.c From 39bba12b147db7680ccbdd87c4d99611b849adc8 Mon Sep 17 00:00:00 2001 From: Lei Yu Date: Thu, 15 Oct 2020 18:21:28 +0800 Subject: [PATCH 3/4] added license header and move the ws2812 codes to a seperate c file --- keyboards/dp60/config.h | 11 ++ keyboards/dp60/dp60.c | 12 ++ keyboards/dp60/dp60.h | 11 ++ keyboards/dp60/keymaps/allleds/keymap.c | 15 ++ keyboards/dp60/keymaps/default/keymap.c | 15 ++ keyboards/dp60/keymaps/indicator/config.h | 11 ++ keyboards/dp60/keymaps/indicator/indicator.c | 182 ++---------------- keyboards/dp60/keymaps/indicator/keymap.c | 15 ++ keyboards/dp60/keymaps/indicator/led_driver.c | 26 +++ keyboards/dp60/keymaps/indicator/rules.mk | 2 +- keyboards/dp60/keymaps/via/keymap.c | 21 +- keyboards/dp60/matrix.c | 17 +- 12 files changed, 166 insertions(+), 172 deletions(-) create mode 100644 keyboards/dp60/keymaps/indicator/led_driver.c diff --git a/keyboards/dp60/config.h b/keyboards/dp60/config.h index 3875d303ea49..dd2564d8d935 100644 --- a/keyboards/dp60/config.h +++ b/keyboards/dp60/config.h @@ -1,6 +1,17 @@ /** * config.h * + Copyright 2020 astro + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ #pragma once diff --git a/keyboards/dp60/dp60.c b/keyboards/dp60/dp60.c index 3e4780246356..475084b0496f 100644 --- a/keyboards/dp60/dp60.c +++ b/keyboards/dp60/dp60.c @@ -1,5 +1,17 @@ /** * dp60.c + * + Copyright 2020 astro + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ #include "dp60.h" diff --git a/keyboards/dp60/dp60.h b/keyboards/dp60/dp60.h index 32bbb6dc0c6f..6fb693f7ec44 100644 --- a/keyboards/dp60/dp60.h +++ b/keyboards/dp60/dp60.h @@ -1,6 +1,17 @@ /** * dp60.h * + Copyright 2020 astro + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ #pragma once diff --git a/keyboards/dp60/keymaps/allleds/keymap.c b/keyboards/dp60/keymaps/allleds/keymap.c index f3862c38fb84..66cc628d4cc0 100644 --- a/keyboards/dp60/keymaps/allleds/keymap.c +++ b/keyboards/dp60/keymaps/allleds/keymap.c @@ -1,3 +1,18 @@ +/** + * keymap.c + * + Copyright 2020 astro + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ #include QMK_KEYBOARD_H const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { diff --git a/keyboards/dp60/keymaps/default/keymap.c b/keyboards/dp60/keymaps/default/keymap.c index f3862c38fb84..66cc628d4cc0 100644 --- a/keyboards/dp60/keymaps/default/keymap.c +++ b/keyboards/dp60/keymaps/default/keymap.c @@ -1,3 +1,18 @@ +/** + * keymap.c + * + Copyright 2020 astro + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ #include QMK_KEYBOARD_H const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { diff --git a/keyboards/dp60/keymaps/indicator/config.h b/keyboards/dp60/keymaps/indicator/config.h index 329b7c14bdae..0476faca9425 100644 --- a/keyboards/dp60/keymaps/indicator/config.h +++ b/keyboards/dp60/keymaps/indicator/config.h @@ -1,6 +1,17 @@ /** * config.h * + Copyright 2020 astro + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ #pragma once diff --git a/keyboards/dp60/keymaps/indicator/indicator.c b/keyboards/dp60/keymaps/indicator/indicator.c index 72283310f8fe..a3a826e8a01b 100644 --- a/keyboards/dp60/keymaps/indicator/indicator.c +++ b/keyboards/dp60/keymaps/indicator/indicator.c @@ -1,174 +1,24 @@ -/* - * light weight WS2812 lib V2.0b - * - * Controls WS2811/WS2812/WS2812B RGB-LEDs - * Author: Tim (cpldcpu@gmail.com) - * - * Jan 18th, 2014 v2.0b Initial Version - * Nov 29th, 2015 v2.3 Added SK6812RGBW support - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - /** * indicator.c + * + Copyright 2020 astro + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ #include "dp60.h" #include "rgblight_list.h" #include "rgblight.h" -#include "ws2812.h" -#include -#include -#include - -/* - This routine writes an array of bytes with RGB values to the Dataout pin - using the fast 800kHz clockless WS2811/2812 protocol. -*/ - -// Timing in ns -#define w_zeropulse 350 -#define w_onepulse 900 -#define w_totalperiod 1250 - -// Fixed cycles used by the inner loop -#define w_fixedlow 2 -#define w_fixedhigh 4 -#define w_fixedtotal 8 - -// Insert NOPs to match the timing, if possible -#define w_zerocycles (((F_CPU / 1000) * w_zeropulse) / 1000000) -#define w_onecycles (((F_CPU / 1000) * w_onepulse + 500000) / 1000000) -#define w_totalcycles (((F_CPU / 1000) * w_totalperiod + 500000) / 1000000) -// w1 - nops between rising edge and falling edge - low -#define w1 (w_zerocycles - w_fixedlow) -// w2 nops between fe low and fe high -#define w2 (w_onecycles - w_fixedhigh - w1) -// w3 nops to complete loop -#define w3 (w_totalcycles - w_fixedtotal - w1 - w2) - -#if w1 > 0 -# define w1_nops w1 -#else -# define w1_nops 0 -#endif - -// The only critical timing parameter is the minimum pulse length of the "0" -// Warn or throw error if this timing can not be met with current F_CPU settings. -#define w_lowtime ((w1_nops + w_fixedlow) * 1000000) / (F_CPU / 1000) -#if w_lowtime > 550 -# error "Light_ws2812: Sorry, the clock speed is too low. Did you set F_CPU correctly?" -#elif w_lowtime > 450 -# warning "Light_ws2812: The timing is critical and may only work on WS2812B, not on WS2812(S)." -# warning "Please consider a higher clockspeed, if possible" -#endif - -#if w2 > 0 -# define w2_nops w2 -#else -# define w2_nops 0 -#endif - -#if w3 > 0 -# define w3_nops w3 -#else -# define w3_nops 0 -#endif - -#define w_nop1 "nop \n\t" -#define w_nop2 "rjmp .+0 \n\t" -#define w_nop4 w_nop2 w_nop2 -#define w_nop8 w_nop4 w_nop4 -#define w_nop16 w_nop8 w_nop8 -void inline indicator_sendarray_mask_ind(uint8_t *data, uint16_t datlen, uint8_t maskhi) { - uint8_t curbyte, ctr, masklo; - uint8_t sreg_prev; - - // masklo =~maskhi&ws2812_PORTREG; - // maskhi |= ws2812_PORTREG; - masklo = ~maskhi & _SFR_IO8((RGB_INDICATOR_PIN >> 4) + 2); - maskhi |= _SFR_IO8((RGB_INDICATOR_PIN >> 4) + 2); - sreg_prev = SREG; - cli(); - - while (datlen--) { - curbyte = (*data++); - - asm volatile(" ldi %0,8 \n\t" - "loop%=: \n\t" - " out %2,%3 \n\t" // '1' [01] '0' [01] - re -#if (w1_nops & 1) - w_nop1 -#endif -#if (w1_nops & 2) - w_nop2 -#endif -#if (w1_nops & 4) - w_nop4 -#endif -#if (w1_nops & 8) - w_nop8 -#endif -#if (w1_nops & 16) - w_nop16 -#endif - " sbrs %1,7 \n\t" // '1' [03] '0' [02] - " out %2,%4 \n\t" // '1' [--] '0' [03] - fe-low - " lsl %1 \n\t" // '1' [04] '0' [04] -#if (w2_nops & 1) - w_nop1 -#endif -#if (w2_nops & 2) - w_nop2 -#endif -#if (w2_nops & 4) - w_nop4 -#endif -#if (w2_nops & 8) - w_nop8 -#endif -#if (w2_nops & 16) - w_nop16 -#endif - " out %2,%4 \n\t" // '1' [+1] '0' [+1] - fe-high -#if (w3_nops & 1) - w_nop1 -#endif -#if (w3_nops & 2) - w_nop2 -#endif -#if (w3_nops & 4) - w_nop4 -#endif -#if (w3_nops & 8) - w_nop8 -#endif -#if (w3_nops & 16) - w_nop16 -#endif - - " dec %0 \n\t" // '1' [+2] '0' [+2] - " brne loop%=\n\t" // '1' [+3] '0' [+4] - : "=&d"(ctr) - : "r"(curbyte), "I"(_SFR_IO_ADDR(_SFR_IO8((RGB_INDICATOR_PIN >> 4) + 2))), "r"(maskhi), "r"(masklo)); - } - - SREG = sreg_prev; -} // caps led const rgblight_segment_t PROGMEM dp60_capslock_layer[] = RGBLIGHT_LAYER_SEGMENTS( @@ -221,15 +71,13 @@ void keyboard_post_init_user(void) { extern rgblight_config_t rgblight_config; extern void rgblight_layers_write(void); +extern void indicator_write(LED_TYPE *start_led, uint8_t num_leds); void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { - ws2812_setleds(led, RGBLED_NUM-RGB_INDICATOR_NUM); + ws2812_setleds(start_led, RGBLED_NUM-RGB_INDICATOR_NUM); - uint8_t pinmask = _BV(RGB_INDICATOR_PIN & 0xF); - _SFR_IO8((RGB_INDICATOR_PIN >> 4) + 1) |= pinmask; - indicator_sendarray_mask_ind((uint8_t *)(&led[RGBLED_NUM-RGB_INDICATOR_NUM]), RGB_INDICATOR_NUM * sizeof(LED_TYPE), pinmask); - _delay_us(50); + indicator_write(start_led + (RGBLED_NUM - RGB_INDICATOR_NUM), RGB_INDICATOR_NUM); } bool led_update_kb(led_t led_state) { diff --git a/keyboards/dp60/keymaps/indicator/keymap.c b/keyboards/dp60/keymaps/indicator/keymap.c index 3a65e1105abc..170d4eb95493 100644 --- a/keyboards/dp60/keymaps/indicator/keymap.c +++ b/keyboards/dp60/keymaps/indicator/keymap.c @@ -1,3 +1,18 @@ +/** + * keymap.c + * + Copyright 2020 astro + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ #include QMK_KEYBOARD_H const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { diff --git a/keyboards/dp60/keymaps/indicator/led_driver.c b/keyboards/dp60/keymaps/indicator/led_driver.c new file mode 100644 index 000000000000..2a1ac5a3852d --- /dev/null +++ b/keyboards/dp60/keymaps/indicator/led_driver.c @@ -0,0 +1,26 @@ +/** + * led_driver.c + * + Copyright 2020 astro + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#undef RGB_DI_PIN +#define RGB_DI_PIN RGB_INDICATOR_PIN +#define ws2812_setleds indicator_setleds +#define ws2812_setleds_pin indicator_setleds_pin +#include "ws2812.c" + +void indicator_write(LED_TYPE *start_led, uint8_t num_leds) +{ + indicator_setleds(start_led, num_leds); +} diff --git a/keyboards/dp60/keymaps/indicator/rules.mk b/keyboards/dp60/keymaps/indicator/rules.mk index 81708748f209..a8891659f72d 100644 --- a/keyboards/dp60/keymaps/indicator/rules.mk +++ b/keyboards/dp60/keymaps/indicator/rules.mk @@ -1,4 +1,4 @@ RGBLIGHT_ENABLE = yes # Use RGB underglow light -SRC += indicator.c +SRC += indicator.c led_driver.c diff --git a/keyboards/dp60/keymaps/via/keymap.c b/keyboards/dp60/keymaps/via/keymap.c index 8227055766eb..04e0d95fd781 100644 --- a/keyboards/dp60/keymaps/via/keymap.c +++ b/keyboards/dp60/keymaps/via/keymap.c @@ -1,3 +1,18 @@ +/** + * keymap.c + * + Copyright 2020 astro + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ #include QMK_KEYBOARD_H const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { @@ -7,7 +22,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT, KC_ENT, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT, MO(1), KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT,KC_RGUI, TG(1), KC_RCTL), - + [1] = LAYOUT_60_ansi_split_bs_rshift( _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,_______,KC_PSCR, RESET, RGB_TOG,RGB_MOD,_______,_______,_______,_______,_______,_______,_______,_______,KC_PGUP,KC_PGDN,_______, @@ -27,5 +42,5 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, _______,_______,_______,_______,_______,_______,_______, _______,_______,_______,_______,_______, _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, - _______,_______,_______, _______, _______,_______,_______,_______) -}; \ No newline at end of file + _______,_______,_______, _______, _______,_______,_______,_______) +}; diff --git a/keyboards/dp60/matrix.c b/keyboards/dp60/matrix.c index 3aa5925fe632..a9974757dde5 100644 --- a/keyboards/dp60/matrix.c +++ b/keyboards/dp60/matrix.c @@ -1,3 +1,18 @@ +/** + * matrix.c + * + Copyright 2020 astro + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ #include "quantum.h" static uint8_t debouncing = DEBOUNCE; @@ -242,4 +257,4 @@ static void select_col(uint8_t col) { writePinHigh(D5); break; } -} \ No newline at end of file +} From e65a7bbbc9435c57713b14b0bba2c9566738c2b9 Mon Sep 17 00:00:00 2001 From: Lei Yu Date: Mon, 19 Oct 2020 18:19:16 +0800 Subject: [PATCH 4/4] fixed conflict with master --- keyboards/dp60/keymaps/via/keymap.c | 40 ++++++++++++++--------------- keyboards/dp60/keymaps/via/rules.mk | 1 + 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/keyboards/dp60/keymaps/via/keymap.c b/keyboards/dp60/keymaps/via/keymap.c index 04e0d95fd781..5f2b007274cd 100644 --- a/keyboards/dp60/keymaps/via/keymap.c +++ b/keyboards/dp60/keymaps/via/keymap.c @@ -16,31 +16,31 @@ #include QMK_KEYBOARD_H const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { - [0] = LAYOUT_60_ansi_split_bs_rshift( - KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,KC_EQL, KC_DEL, KC_BSPC, - KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC,KC_RBRC,KC_BSLS, - KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT, KC_ENT, - KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT, MO(1), - KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT,KC_RGUI, TG(1), KC_RCTL), + [0] = LAYOUT_all( + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,KC_EQL, KC_DEL, KC_BSPC, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC,KC_RBRC,KC_BSLS, + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT, KC_NUHS, KC_ENT, + KC_LSFT, KC_NUBS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT, MO(1), + KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RGUI,KC_RALT, MO(1), KC_RCTL), - [1] = LAYOUT_60_ansi_split_bs_rshift( - _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,_______,KC_PSCR, - RESET, RGB_TOG,RGB_MOD,_______,_______,_______,_______,_______,_______,_______,_______,KC_PGUP,KC_PGDN,_______, - _______, _______,_______,_______,_______,_______,KC_LEFT,KC_DOWN, KC_UP,KC_RIGHT,KC_HOME,KC_END,_______, - _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, - _______,_______,_______, _______, _______,_______,TG(0),_______), + [1] = LAYOUT_all( + KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,_______,KC_DEL, + RESET, _______,KC_UP,_______,_______,_______,_______,_______,KC_PAUS,KC_SLCK,KC_PSCR,KC_PGUP,_______,KC_INS, + _______, KC_LEFT,KC_DOWN,KC_RIGHT,_______,_______,_______,_______, _______,_______,KC_HOME,KC_END,_______, _______, + _______,_______, _______,_______,_______,_______,_______,_______,_______,_______,_______,KC_PGDN,_______,_______, + _______,_______,_______, _______, _______,MO(2),TG(0),_______), - [2] = LAYOUT_60_ansi_split_bs_rshift( + [2] = LAYOUT_all( _______, _______,_______, _______,_______, _______,_______, _______,_______, _______,_______, _______,_______,_______,_______, - _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, - _______, _______,_______,_______,_______,_______,_______,_______, _______,_______,_______,_______,_______, - _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, - _______,_______,_______, _______, _______,_______,_______,_______), + _______, _______,KC_VOLU,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, + KC_MUTE, KC_MPRV,KC_VOLD,KC_MNXT,_______,_______,_______,_______, _______,_______,_______,_______,_______, _______, + _______, _______, RGB_TOG,RGB_MOD,RGB_RMOD,RGB_VAI,RGB_VAD,RGB_HUI,RGB_HUD,RGB_SAI,RGB_SAD,_______,_______,_______, + _______,_______,_______, KC_MPLY, _______,_______,_______,_______), - [3] = LAYOUT_60_ansi_split_bs_rshift( + [3] = LAYOUT_all( _______, _______,_______, _______,_______, _______,_______, _______,_______, _______,_______, _______,_______,_______,_______, _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, - _______, _______,_______,_______,_______,_______,_______,_______, _______,_______,_______,_______,_______, - _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, + _______, _______,_______,_______,_______,_______,_______,_______, _______,_______,_______,_______,_______,_______, + _______, _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______,_______,_______, _______, _______,_______,_______,_______) }; diff --git a/keyboards/dp60/keymaps/via/rules.mk b/keyboards/dp60/keymaps/via/rules.mk index 36b7ba9cbc98..e4b4d91da9ae 100644 --- a/keyboards/dp60/keymaps/via/rules.mk +++ b/keyboards/dp60/keymaps/via/rules.mk @@ -1,2 +1,3 @@ VIA_ENABLE = yes LTO_ENABLE = yes +RGBLIGHT_ENABLE = yes #enables underglow, but will not disable per key leds