diff --git a/firmware/keyboard/sipeed_keyboard_68/config/sipeed_mechanical_keyboard.c b/firmware/keyboard/sipeed_keyboard_68/config/sipeed_mechanical_keyboard.c index ccbca91..4f55ec2 100644 --- a/firmware/keyboard/sipeed_keyboard_68/config/sipeed_mechanical_keyboard.c +++ b/firmware/keyboard/sipeed_keyboard_68/config/sipeed_mechanical_keyboard.c @@ -65,9 +65,9 @@ static const smk_keycode_type smk_default_matrix_keymaps[LAYERS][LAYOUT_ROWS][LA /*< /==========='`.====='`.====='`.====='`.====='`.====='`.====='`.====='`.====='`.====='`.====='`.====='`.====='`==========/`======/`. / >*/ { _____ , Win , Mac , BClra , XXXXX , XXXXX , XXXXX , XXXXX , p4 , p5 , P6 , plus , enter , Home }, \ /*< /============='`==.==='`==.==='`==.==='`==.==='`==.==='`==.==='`==.==='`==.==='`==.==='`==.==='`==.==='`========.=======/`======/`. / >*/ - { _____ , XXXXX , XXXXX , RGBON , RGBOFF, XXXXX , XXXXX , XXXXX , p1 , P2 , P3 , XXXXX , _____ , End }, \ + { _____ , XXXXX , XXXXX , RGBON , RGBOFF, XXXXX , XXXXX , XXXXX , p1 , P2 , P3 , XXXXX , RGBBU , End }, \ /*< /=========.======='`.====='`==.==='`======'`======'`======'`======'`======'`====.='`====.='`====.='`====.=======/`======/`======/`. / >*/ - { _____ , _____ , _____ , _____ , p0 , MO(2) , dot , RGBMD, _____ , RGBMU } \ + { _____ , _____ , _____ , _____ , p0 , MO(2) , dot , RGBMD, RGBBD , RGBMU } \ /*< `---------'`--------'`--------'`------------------------------------------------'`------'`------'`------'`------'`------'`------'`. / >*/ /*< V V V V Layer 2 V V V V V V V / >*/ /*< `----------'`--------'`--------'`------------------------------------------------'`------'`------'`------'`------'`------'`------' >*/ diff --git a/firmware/keyboard/sipeed_keyboard_68/include/smk_spirgb.h b/firmware/keyboard/sipeed_keyboard_68/include/smk_spirgb.h index 8dd743a..3933dba 100644 --- a/firmware/keyboard/sipeed_keyboard_68/include/smk_spirgb.h +++ b/firmware/keyboard/sipeed_keyboard_68/include/smk_spirgb.h @@ -110,6 +110,10 @@ typedef struct RGB_COLOR_DESC { } RGB_COLOR_DESC; extern RGB_COLOR_DESC rgb_color_descriptor[10]; +void RGB_Set_Global_Enable(uint8_t enable); +void RGB_Set_Brightness_level_up(); +void RGB_Set_Brightness_level_down(); +void RGB_Set_Brightness_level(uint8_t level); DRGB rgb_alpha(DRGB source, uint8_t alpha); void rgb_loop_task(void *pvParameters); diff --git a/firmware/keyboard/sipeed_keyboard_68/keyboard/smk_keymap.c b/firmware/keyboard/sipeed_keyboard_68/keyboard/smk_keymap.c index 2c8f68e..e1b400a 100644 --- a/firmware/keyboard/sipeed_keyboard_68/keyboard/smk_keymap.c +++ b/firmware/keyboard/sipeed_keyboard_68/keyboard/smk_keymap.c @@ -3,6 +3,7 @@ #include "smk_endpoints.h" #include "events/rgb_switch_mode_event.h" #include "smk_ble.h" +#include "smk_spirgb.h" smk_keyboard_map_type * smk_keymap_init(const smk_keyboard_hardware_type * const hardware, QueueHandle_t queue_in, QueueHandle_t queue_out) { @@ -259,16 +260,16 @@ void smk_keymap_handle_keycode(smk_keyboard_map_type *map, const smk_event_type MAP_DEBUG("[SMK][KeyMap] KeyFunc RGB mode down\r\n"); break; case KF_RGB_OFF: - // TODO: Implement RGB off + RGB_Set_Global_Enable(0); break; case KF_RGB_ON: - // TODO: Implement RGB on + RGB_Set_Global_Enable(1); break; case KF_RGB_BRIGHTNESS_UP: - // TODO: Implement RGB brightness up + RGB_Set_Brightness_level_up(); break; case KF_RGB_BRIGHTNESS_DOWN: - // TODO: Implement RGB brightness down + RGB_Set_Brightness_level_down(); break; case KF_USB: endpoint = SMK_ENDPOINT_USB; diff --git a/firmware/keyboard/sipeed_keyboard_68/smk_spirgb.c b/firmware/keyboard/sipeed_keyboard_68/smk_spirgb.c index c6fec5c..20c3f0f 100644 --- a/firmware/keyboard/sipeed_keyboard_68/smk_spirgb.c +++ b/firmware/keyboard/sipeed_keyboard_68/smk_spirgb.c @@ -11,11 +11,13 @@ #include #include "smk_hid_protocol.h" +#include "easyflash.h" extern const int CAPS_KEY_LED; extern const float LED_GAMMA; uint8_t shared_kb_led=0; +uint8_t rgb_enable=1; static uint8_t gammalist[256]; @@ -27,6 +29,14 @@ static void init_gammalist() { } } +#define ENV_RGB_GLOBAL_ENABLE "RGB_GLOBAL_ENABLE" +#define ENV_RGB_GLOBAL_BRIGHTNESS_LEVEL "RGB_BR_LEVEL" + +void RGB_Set_Global_Enable(uint8_t enable) { + rgb_enable = enable; + ef_set_env_blob(ENV_RGB_GLOBAL_ENABLE, &enable, sizeof(enable)); +} + #if(SMK_RGB_USE_DMA) uint32_t RGB_DMA_Buffer[RGB_LENGTH*3]; @@ -93,6 +103,24 @@ void RGB_Transmit(struct device *spi, DRGB * rgbbuffer) { /* static */ int rgb_mode = 0; /* static */ uint8_t rgb_global_brightness = 120; +uint8_t rgb_global_brightness_level = 2; +uint8_t rgb_brightness_level_list[5] = {60, 90, 120, 150, 180}; + +void RGB_Set_Brightness_level(uint8_t level) { + rgb_global_brightness_level = level; + ef_set_env_blob(ENV_RGB_GLOBAL_BRIGHTNESS_LEVEL, &level, sizeof(level)); + rgb_global_brightness = rgb_brightness_level_list[level]; +} + +void RGB_Set_Brightness_level_up() { + rgb_global_brightness_level = (rgb_global_brightness_level+1) > 4 ? 4 : (rgb_global_brightness_level+1); + RGB_Set_Brightness_level(rgb_global_brightness_level); +} + +void RGB_Set_Brightness_level_down() { + rgb_global_brightness_level = (rgb_global_brightness_level-1) < 0 ? 0 : (rgb_global_brightness_level-1); + RGB_Set_Brightness_level(rgb_global_brightness_level); +} DRGB RGB_Buffer[RGB_LENGTH]; @@ -155,6 +183,9 @@ void rgb_loop_task(void *pvParameters) uint32_t i; init_gammalist(); + ef_get_env_blob(ENV_RGB_GLOBAL_ENABLE, &rgb_enable, sizeof(rgb_enable), NULL); + ef_get_env_blob(ENV_RGB_GLOBAL_BRIGHTNESS_LEVEL, &rgb_global_brightness_level, sizeof(rgb_global_brightness_level), NULL); + RGB_Set_Brightness_level(rgb_global_brightness_level); spi_register(SPI0_INDEX, "spi"); spi = device_find("spi"); @@ -176,6 +207,19 @@ void rgb_loop_task(void *pvParameters) for (;;) { vTaskDelay(10); + if (!rgb_enable) { + for (i = 0; i < RGB_LENGTH; i++) { + RGB_Buffer[i].word = 0; + } + #if(SMK_RGB_USE_DMA) + RGB_DMA_Transmit(spi, dma_ch3, RGB_Buffer); + #else + vTaskEnterCritical(); + RGB_Transmit(spi, RGB_Buffer); + vTaskExitCritical(); + #endif + continue; + } if (rgb_mode < RGB_MODE_COUNT) { @@ -187,12 +231,10 @@ void rgb_loop_task(void *pvParameters) int ceffid = ceff->eff_id; int ceffoffset = ceff->time_offset; rgb_effect_descriptor[ceffid].eff_func(ceff, timestamp - ceffoffset); - - if (rgb_global_brightness != 255) { - for (i = 0; i < RGB_LENGTH; i++) { - RGB_Buffer[i] = rgb_alpha(RGB_Buffer[i], rgb_global_brightness); - } - } + + for (i = 0; i < RGB_LENGTH; i++) { + RGB_Buffer[i] = rgb_alpha(RGB_Buffer[i], rgb_global_brightness); + } } timestamp ++;