Compare commits
2 Commits
a8e0cfe1b3
...
019dd0a2c1
| Author | SHA1 | Date | |
|---|---|---|---|
| 019dd0a2c1 | |||
| 0a7706fff1 |
@@ -17,17 +17,6 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
|
||||
project(new_kbd)
|
||||
|
||||
if(NOT c_std_11 IN_LIST CMAKE_C_COMPILE_FEATURES)
|
||||
list(APPEND CMAKE_C_COMPILE_FEATURES c_std_11)
|
||||
endif()
|
||||
|
||||
set(PROTOBUF_PROTOC_EXECUTABLE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/protoc_nanopb.bat"
|
||||
CACHE FILEPATH "Project-local protoc wrapper for nanopb" FORCE)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH ${ZEPHYR_BASE}/modules/nanopb)
|
||||
include(nanopb)
|
||||
|
||||
zephyr_include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
|
||||
zephyr_include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/events)
|
||||
zephyr_include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/ui)
|
||||
@@ -44,19 +33,11 @@ target_compile_definitions(app PRIVATE
|
||||
APP_HID_KEYMAP_DEF_PATH=\"hid_keymap_def.h\"
|
||||
)
|
||||
|
||||
zephyr_nanopb_sources(app
|
||||
KeyBorad/proto/keyboard.proto
|
||||
)
|
||||
|
||||
target_link_libraries(app PRIVATE nanopb)
|
||||
|
||||
target_sources(app PRIVATE
|
||||
src/main.c
|
||||
src/events/battery_status_event.c
|
||||
src/events/config_event.c
|
||||
src/events/display_theme_event.c
|
||||
src/events/function_bitmap_event.c
|
||||
src/events/function_key_event.c
|
||||
src/events/hid_boot_event.c
|
||||
src/events/hid_host_ack_event.c
|
||||
src/events/hid_host_command_error_event.c
|
||||
@@ -78,16 +59,13 @@ target_sources(app PRIVATE
|
||||
src/modules/display_module.c
|
||||
src/modules/hid_host_command_module.c
|
||||
src/modules/hid_tx_manager_module.c
|
||||
src/modules/keyboard_proto.c
|
||||
src/modules/keyboard_module.c
|
||||
src/modules/led_state_module.c
|
||||
src/modules/mode_switch_module.c
|
||||
src/modules/qdec_module.c
|
||||
src/modules/time_manager_module.c
|
||||
src/modules/usb_cdc_proto_module.c
|
||||
src/modules/usb_hid_module.c
|
||||
src/modules/ble_hid_module.c
|
||||
src/modules/ble_gatt_proto_module.c
|
||||
src/ui/display_ui.c
|
||||
src/ui/fonts/ui_font_keyboard_small_18.c
|
||||
src/ui/fonts/ui_font_keyboard_time_48.c
|
||||
|
||||
@@ -36,13 +36,6 @@
|
||||
};
|
||||
};
|
||||
|
||||
&usbd {
|
||||
cdc_acm_uart0: cdc_acm_uart0 {
|
||||
compatible = "zephyr,cdc-acm-uart";
|
||||
label = "new_kbd CDC ACM";
|
||||
};
|
||||
};
|
||||
|
||||
&gpregret1 {
|
||||
status = "okay";
|
||||
|
||||
|
||||
5
prj.conf
5
prj.conf
@@ -68,11 +68,6 @@ CONFIG_BT_DIS_PNP_PID=0x0001
|
||||
|
||||
CONFIG_USB_DEVICE_STACK_NEXT=y
|
||||
CONFIG_USBD_HID_SUPPORT=y
|
||||
CONFIG_SERIAL=y
|
||||
CONFIG_UART_INTERRUPT_DRIVEN=y
|
||||
CONFIG_UART_LINE_CTRL=y
|
||||
CONFIG_USBD_CDC_ACM_CLASS=y
|
||||
CONFIG_CDC_ACM_SERIAL_INITIALIZE_AT_BOOT=n
|
||||
CONFIG_UDC_BUF_POOL_SIZE=8192
|
||||
CONFIG_UDC_BUF_COUNT=32
|
||||
CONFIG_USBD_MAX_UDC_MSG=20
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
#include "hid_protocol_event.h"
|
||||
#include "hid_report_event.h"
|
||||
#include "hid_vendor_mask_event.h"
|
||||
#include "function_bitmap_event.h"
|
||||
#include "function_key_event.h"
|
||||
#include "qdec_step_event.h"
|
||||
|
||||
#include <zephyr/sys/util.h>
|
||||
@@ -102,7 +100,6 @@ struct keyboard_state {
|
||||
uint8_t physical_usage_bm[KEYBOARD_BITMAP_SIZE];
|
||||
uint8_t mask_modifier_bm;
|
||||
uint8_t mask_bm[KEYBOARD_BITMAP_SIZE];
|
||||
uint8_t function_bm[KEYBOARD_BITMAP_SIZE];
|
||||
enum hid_protocol_type current_protocol;
|
||||
uint16_t consumer_usage;
|
||||
};
|
||||
@@ -127,16 +124,6 @@ static void keyboard_mask_init(void)
|
||||
{
|
||||
ks.mask_modifier_bm = 0xFF;
|
||||
memset(ks.mask_bm, 0xFF, sizeof(ks.mask_bm));
|
||||
memset(ks.function_bm, 0, sizeof(ks.function_bm));
|
||||
}
|
||||
|
||||
static bool function_usage_active(uint16_t usage_id)
|
||||
{
|
||||
if (usage_id > KEYBOARD_USAGE_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (ks.function_bm[usage_id / 8] & BIT(usage_id % 8)) != 0U;
|
||||
}
|
||||
|
||||
/* 查询某 usage 位在当前键盘位图里是否处于按下状态。 */
|
||||
@@ -311,11 +298,6 @@ static void submit_consumer_click_usage(uint16_t usage_id)
|
||||
*/
|
||||
static bool handle_keyboard_usage_event(const struct hid_keymap *map, bool pressed)
|
||||
{
|
||||
if (function_usage_active(map->usage_id)) {
|
||||
function_key_event_submit(map->usage_id, pressed);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!keyboard_usage_update(map->usage_id, pressed))
|
||||
return false;
|
||||
|
||||
@@ -331,11 +313,6 @@ static bool handle_keyboard_usage_event(const struct hid_keymap *map, bool press
|
||||
*/
|
||||
static bool handle_consumer_usage_event(const struct hid_keymap *map, bool pressed)
|
||||
{
|
||||
if (function_usage_active(map->usage_id)) {
|
||||
function_key_event_submit(map->usage_id, pressed);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (active_protocol_get() == HID_PROTO_BOOT)
|
||||
return false;
|
||||
|
||||
@@ -404,21 +381,6 @@ static bool handle_hid_vendor_mask_event(const struct hid_vendor_mask_event *eve
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool handle_function_bitmap_event(const struct function_bitmap_event *event)
|
||||
{
|
||||
const uint8_t *data = function_bitmap_event_get_data(event);
|
||||
size_t size = function_bitmap_event_get_size(event);
|
||||
|
||||
if (size != sizeof(ks.function_bm)) {
|
||||
LOG_WRN("Ignore function bitmap len=%u expect=%u",
|
||||
size, sizeof(ks.function_bm));
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(ks.function_bm, data, sizeof(ks.function_bm));
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool handle_qdec_step_event(const struct qdec_step_event *event)
|
||||
{
|
||||
int8_t step = qdec_step_event_get_step(event);
|
||||
@@ -453,10 +415,6 @@ static bool app_event_handler(const struct app_event_header *aeh)
|
||||
return handle_hid_vendor_mask_event(cast_hid_vendor_mask_event(aeh));
|
||||
}
|
||||
|
||||
if (is_function_bitmap_event(aeh)) {
|
||||
return handle_function_bitmap_event(cast_function_bitmap_event(aeh));
|
||||
}
|
||||
|
||||
if (is_module_state_event(aeh)) {
|
||||
const struct module_state_event *event = cast_module_state_event(aeh);
|
||||
|
||||
@@ -478,6 +436,5 @@ APP_EVENT_LISTENER(MODULE, app_event_handler);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, button_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, hid_protocol_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, hid_vendor_mask_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, function_bitmap_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, qdec_step_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, module_state_event);
|
||||
|
||||
Reference in New Issue
Block a user