Skip to content

Commit c09eabf

Browse files
committed
Merge branch 'fix/keyboard_bug_fix' into 'master'
feat(keyboard): upgrade version to v0.2.0 Closes AEG-1823 See merge request ae_group/esp-iot-solution!1063
2 parents 641cc22 + 8b0b0a4 commit c09eabf

File tree

12 files changed

+172
-57
lines changed

12 files changed

+172
-57
lines changed

docs/en/usb/usb_overview/usb_device_solutions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Links:
9595

9696
* `USB HID Keyboard and Mouse Example <https://github.com/espressif/esp-iot-solution/tree/master/examples/usb/device/usb_hid_device>`_
9797
* `USB HID Surface Dial Example <https://github.com/espressif/esp-iot-solution/tree/master/examples/usb/device/usb_surface_dial>`_
98+
* `USB Custom Keyboard Example <https://github.com/espressif/esp-iot-solution/tree/master/examples/keyboard>`_
9899

99100
USB Drag-and-Drop OTA Upgrade
100101
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

docs/zh_CN/usb/usb_overview/usb_device_solutions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ USB HID 设备方案基于 HID(Human Interface Device)协议标准,可作
9898

9999
* `USB HID 键盘和鼠标示例 <https://github.com/espressif/esp-iot-solution/tree/master/examples/usb/device/usb_hid_device>`_
100100
* `USB HID Surface Dial 示例 <https://github.com/espressif/esp-iot-solution/tree/master/examples/usb/device/usb_surface_dial>`_
101+
* `USB 客制化键盘示例 <https://github.com/espressif/esp-iot-solution/tree/master/examples/keyboard>`_
101102

102103
U 盘拖拽升级
103104
^^^^^^^^^^^^^^^

examples/keyboard/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,11 @@ How to modify key mappings:
7575
#### license
7676

7777
Note: keyboard_rgb_martix comes from the **QMK** project. Due to the use of the GPL license, if you have product plans based on this example, it is recommended to replace this component.
78+
79+
### Change LOG
80+
81+
* v0.2.0 - 2024-8-12
82+
83+
* Added support for lighting effects in BLE mode, with the keyboard backlight turning off by default after 60 seconds.
84+
* Resolved the issue with adjusting the speed of lighting effects.
85+
* Increased the number of default lighting effects to 30.

examples/keyboard/README_cn.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,11 @@ Win11 灯效
7575
#### license
7676

7777
Note: keyboard_rgb_martix 来自 **QMK** 工程,由于使用 GPL 协议,如果您有基于本示例的产品计划,建议替换该组件。
78+
79+
#### Change LOG
80+
81+
* v0.2.0 - 2024-8-12
82+
83+
* BLE 模式下支持灯效,默认 60s 关闭键盘灯光
84+
* 解决灯效速度调节问题
85+
* 默认支持灯效增加到 30 种

examples/keyboard/components/esp32_s3_kbd_kit/esp32_s3_kbd_kit.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ esp_err_t bsp_keyboard_init(keyboard_btn_handle_t *kbd_handle, keyboard_btn_conf
4040
}
4141

4242
static led_strip_handle_t s_led_strip = NULL;
43+
static bool s_led_enable = false;
4344

4445
esp_err_t bsp_ws2812_init(led_strip_handle_t *led_strip)
4546
{
@@ -67,12 +68,16 @@ esp_err_t bsp_ws2812_init(led_strip_handle_t *led_strip)
6768
.flags.invert_out = false, // whether to invert the output signal (useful when your hardware has a level inverter)
6869
};
6970

70-
led_strip_rmt_config_t rmt_config = {
71-
.clk_src = RMT_CLK_SRC_DEFAULT, // different clock source can lead to different power consumption
72-
.resolution_hz = 20 * 1000 * 1000, // 10MHz
73-
.flags.with_dma = false, // whether to enable the DMA feature
71+
// LED strip backend configuration: SPI
72+
led_strip_spi_config_t spi_config = {
73+
.clk_src = SPI_CLK_SRC_XTAL, // different clock source can lead to different power consumption
74+
.flags.with_dma = true, // Using DMA can improve performance and help drive more LEDs
75+
.spi_bus = SPI2_HOST, // SPI bus ID
7476
};
75-
led_strip_new_rmt_device(&strip_config, &rmt_config, &s_led_strip);
77+
78+
// LED Strip object handle
79+
ESP_ERROR_CHECK(led_strip_new_spi_device(&strip_config, &spi_config, &s_led_strip));
80+
7681
if (led_strip) {
7782
*led_strip = s_led_strip;
7883
}
@@ -81,10 +86,28 @@ esp_err_t bsp_ws2812_init(led_strip_handle_t *led_strip)
8186

8287
esp_err_t bsp_ws2812_enable(bool enable)
8388
{
89+
if (!enable) {
90+
gpio_hold_dis(KBD_WS2812_POWER_IO);
91+
}
8492
gpio_set_level(KBD_WS2812_POWER_IO, !enable);
93+
/*!< Make output stable in light sleep */
94+
if (enable) {
95+
gpio_hold_en(KBD_WS2812_POWER_IO);
96+
}
97+
s_led_enable = enable;
8598
return ESP_OK;
8699
}
87100

101+
esp_err_t bsp_ws2812_clear(void)
102+
{
103+
return led_strip_clear(s_led_strip);
104+
}
105+
106+
bool bsp_ws2812_is_enable(void)
107+
{
108+
return s_led_enable;
109+
}
110+
88111
esp_err_t bsp_lamp_array_init(uint32_t bind)
89112
{
90113
if (!s_led_strip) {

examples/keyboard/components/esp32_s3_kbd_kit/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ dependencies:
1414
led_strip:
1515
version: "^2.5.3"
1616

17-
lijunru-hub/keyboard_rgb_matrix: "^0.1.0"
17+
lijunru-hub/keyboard_rgb_matrix: "^0.1.1"

examples/keyboard/components/esp32_s3_kbd_kit/include/bsp/esp32_s3_kbd_kit.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ esp_err_t bsp_ws2812_init(led_strip_handle_t *led_strip);
1919

2020
esp_err_t bsp_ws2812_enable(bool enable);
2121

22+
esp_err_t bsp_ws2812_clear(void);
23+
24+
bool bsp_ws2812_is_enable(void);
25+
2226
esp_err_t bsp_lamp_array_init(uint32_t bind);
2327

2428
esp_err_t bsp_rgb_matrix_init(void);
Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
menu "ESP KeyBoard Example"
22

3-
config TUSB_VID
4-
hex "USB Device VID"
5-
default 0x303A
6-
config TUSB_PID
7-
hex "USB Device PID"
8-
default 0x8000
9-
config TUSB_MANUFACTURER
10-
string "USB Device Manufacture"
11-
default "Espressif"
12-
config TUSB_PRODUCT
13-
string "Product Name"
14-
default "HID Demo"
3+
menu "USB Configuration"
4+
config TUSB_VID
5+
hex "USB Device VID"
6+
default 0x303A
7+
config TUSB_PID
8+
hex "USB Device PID"
9+
default 0x8000
10+
config TUSB_MANUFACTURER
11+
string "USB Device Manufacture"
12+
default "Espressif"
13+
config TUSB_PRODUCT
14+
string "Product Name"
15+
default "HID Demo"
16+
endmenu
17+
18+
menu "Wireless Configuration"
19+
config LIGHT_SLEEP_TIMEOUT_MS
20+
int "Light Sleep Timeout"
21+
default 60000
22+
help
23+
"Time to enter light sleep mode and close all light when no key is pressed"
24+
endmenu
1525

1626
endmenu

examples/keyboard/main/btn_progress.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "settings.h"
1616
#include "esp_system.h"
1717
#include "esp_pm.h"
18+
#include "bsp/esp-bsp.h"
1819

1920
static btn_report_type_t report_type = TINYUSB_HID_REPORT;
2021
static light_type_t light_type = RGB_MATRIX;
@@ -114,9 +115,15 @@ void btn_progress(keyboard_btn_report_t kbd_report)
114115

115116
/*!< Change to win11 light or local light */
116117
case KC_NUM_LOCK:
117-
light_type = (light_type == RGB_MATRIX) ? LAMP_ARRAY_MATRIX : RGB_MATRIX;
118-
sys_param->light_type = light_type;
119-
settings_write_parameter_to_nvs();
118+
if (report_type == TINYUSB_HID_REPORT) {
119+
light_type = (light_type == RGB_MATRIX) ? LAMP_ARRAY_MATRIX : RGB_MATRIX;
120+
sys_param->light_type = light_type;
121+
settings_write_parameter_to_nvs();
122+
} else if (report_type == BLE_HID_REPORT) {
123+
light_type = RGB_MATRIX;
124+
sys_param->light_type = light_type;
125+
settings_write_parameter_to_nvs();
126+
}
120127
break;
121128

122129
case KC_KB_MUTE:
@@ -150,15 +157,26 @@ void btn_progress(keyboard_btn_report_t kbd_report)
150157

151158
case QK_BACKLIGHT_TOGGLE:
152159
rgb_matrix_toggle();
160+
if (!rgb_matrix_is_enabled()) {
161+
bsp_ws2812_clear();
162+
}
163+
bsp_ws2812_enable(rgb_matrix_is_enabled());
153164
break;
154165

155-
case RGB_MODE_FORWARD:
156-
rgb_matrix_mode(rgb_matrix_get_mode() + 1);
166+
case RGB_MODE_FORWARD: {
167+
uint16_t index = (rgb_matrix_get_mode() + 1) % RGB_MATRIX_EFFECT_MAX;
168+
rgb_matrix_mode(index);
157169
break;
170+
}
158171

159-
case RGB_MODE_REVERSE:
160-
rgb_matrix_mode(rgb_matrix_get_mode() - 1);
172+
case RGB_MODE_REVERSE: {
173+
uint16_t index = rgb_matrix_get_mode() - 1;
174+
if (index < 1) {
175+
index = RGB_MATRIX_EFFECT_MAX - 1;
176+
}
177+
rgb_matrix_mode(index);
161178
break;
179+
}
162180

163181
case RGB_TOG:
164182
rgb_matrix_sethsv(hsv_color[hsv_index][0], hsv_color[hsv_index][1], hsv_color[hsv_index][2]);
@@ -174,7 +192,7 @@ void btn_progress(keyboard_btn_report_t kbd_report)
174192
}
175193

176194
/*!< Find if consumer key release */
177-
for (int i = 0; i <= kbd_report.key_release_num; i++) {
195+
for (int i = 0; i < kbd_report.key_release_num; i++) {
178196
uint8_t row = kbd_report.key_release_data[i].output_index;
179197
uint8_t col = kbd_report.key_release_data[i].input_index;
180198
uint16_t kc = keymaps[mo_action_layer][row][col];

examples/keyboard/main/idf_component.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
version: 0.2.0
12
dependencies:
23
idf: ">=5.2"
34
espressif/tinyusb:

0 commit comments

Comments
 (0)