Add firmware function events
This commit is contained in:
38
docs/firmware_proto_transport.md
Normal file
38
docs/firmware_proto_transport.md
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# Firmware Proto Transport
|
||||||
|
|
||||||
|
## Goal
|
||||||
|
|
||||||
|
Add CDC and GATT private communication without rewriting the existing keyboard,
|
||||||
|
time, theme, and LED business logic.
|
||||||
|
|
||||||
|
The firmware side should:
|
||||||
|
|
||||||
|
- keep standard HID behavior for normal keys
|
||||||
|
- receive host commands over CDC and GATT
|
||||||
|
- report private state and function key events over CDC and GATT
|
||||||
|
- reuse existing modules where possible
|
||||||
|
|
||||||
|
## Completed Nodes
|
||||||
|
|
||||||
|
### Node 1: internal function events
|
||||||
|
|
||||||
|
Files:
|
||||||
|
|
||||||
|
- `src/events/function_bitmap_event.h`
|
||||||
|
- `src/events/function_bitmap_event.c`
|
||||||
|
- `src/events/function_key_event.h`
|
||||||
|
- `src/events/function_key_event.c`
|
||||||
|
|
||||||
|
Design notes:
|
||||||
|
|
||||||
|
- `function_bitmap_event` carries the 29-byte function bitmap from host
|
||||||
|
- `function_key_event` carries usage + action when a configured function key
|
||||||
|
is pressed or released
|
||||||
|
- these events isolate transport modules from keyboard internals
|
||||||
|
|
||||||
|
## Planned next nodes
|
||||||
|
|
||||||
|
- keyboard split logic uses `function_bitmap_event`
|
||||||
|
- CDC transport module
|
||||||
|
- GATT transport module
|
||||||
|
- nanopb integration and generated protocol code
|
||||||
28
src/events/function_bitmap_event.c
Normal file
28
src/events/function_bitmap_event.c
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#include "function_bitmap_event.h"
|
||||||
|
|
||||||
|
static void log_function_bitmap_event(const struct app_event_header *aeh)
|
||||||
|
{
|
||||||
|
const struct function_bitmap_event *event =
|
||||||
|
cast_function_bitmap_event(aeh);
|
||||||
|
|
||||||
|
APP_EVENT_MANAGER_LOG(aeh, "len=%u", event->dyndata.size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void profile_function_bitmap_event(struct log_event_buf *buf,
|
||||||
|
const struct app_event_header *aeh)
|
||||||
|
{
|
||||||
|
const struct function_bitmap_event *event =
|
||||||
|
cast_function_bitmap_event(aeh);
|
||||||
|
|
||||||
|
nrf_profiler_log_encode_uint16(buf, event->dyndata.size);
|
||||||
|
}
|
||||||
|
|
||||||
|
APP_EVENT_INFO_DEFINE(function_bitmap_event,
|
||||||
|
ENCODE(NRF_PROFILER_ARG_U16),
|
||||||
|
ENCODE("len"),
|
||||||
|
profile_function_bitmap_event);
|
||||||
|
|
||||||
|
APP_EVENT_TYPE_DEFINE(function_bitmap_event,
|
||||||
|
log_function_bitmap_event,
|
||||||
|
&function_bitmap_event_info,
|
||||||
|
APP_EVENT_FLAGS_CREATE(APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));
|
||||||
41
src/events/function_bitmap_event.h
Normal file
41
src/events/function_bitmap_event.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#ifndef FUNCTION_BITMAP_EVENT_H__
|
||||||
|
#define FUNCTION_BITMAP_EVENT_H__
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <app_event_manager.h>
|
||||||
|
#include <app_event_manager_profiler_tracer.h>
|
||||||
|
|
||||||
|
struct function_bitmap_event {
|
||||||
|
struct app_event_header header;
|
||||||
|
struct event_dyndata dyndata;
|
||||||
|
};
|
||||||
|
|
||||||
|
APP_EVENT_TYPE_DYNDATA_DECLARE(function_bitmap_event);
|
||||||
|
|
||||||
|
static inline void function_bitmap_event_submit(const uint8_t *data, size_t size)
|
||||||
|
{
|
||||||
|
struct function_bitmap_event *event = new_function_bitmap_event(size);
|
||||||
|
|
||||||
|
if ((size > 0U) && (data != NULL)) {
|
||||||
|
memcpy(event->dyndata.data, data, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
APP_EVENT_SUBMIT(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline const uint8_t *function_bitmap_event_get_data(
|
||||||
|
const struct function_bitmap_event *event)
|
||||||
|
{
|
||||||
|
return event->dyndata.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline size_t function_bitmap_event_get_size(
|
||||||
|
const struct function_bitmap_event *event)
|
||||||
|
{
|
||||||
|
return event->dyndata.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* FUNCTION_BITMAP_EVENT_H__ */
|
||||||
32
src/events/function_key_event.c
Normal file
32
src/events/function_key_event.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include "function_key_event.h"
|
||||||
|
|
||||||
|
static void log_function_key_event(const struct app_event_header *aeh)
|
||||||
|
{
|
||||||
|
const struct function_key_event *event =
|
||||||
|
cast_function_key_event(aeh);
|
||||||
|
|
||||||
|
APP_EVENT_MANAGER_LOG(aeh, "usage=0x%04x pressed=%u",
|
||||||
|
event->usage,
|
||||||
|
event->pressed);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void profile_function_key_event(struct log_event_buf *buf,
|
||||||
|
const struct app_event_header *aeh)
|
||||||
|
{
|
||||||
|
const struct function_key_event *event =
|
||||||
|
cast_function_key_event(aeh);
|
||||||
|
|
||||||
|
nrf_profiler_log_encode_uint16(buf, event->usage);
|
||||||
|
nrf_profiler_log_encode_uint8(buf, event->pressed ? 1U : 0U);
|
||||||
|
}
|
||||||
|
|
||||||
|
APP_EVENT_INFO_DEFINE(function_key_event,
|
||||||
|
ENCODE(NRF_PROFILER_ARG_U16,
|
||||||
|
NRF_PROFILER_ARG_U8),
|
||||||
|
ENCODE("usage", "pressed"),
|
||||||
|
profile_function_key_event);
|
||||||
|
|
||||||
|
APP_EVENT_TYPE_DEFINE(function_key_event,
|
||||||
|
log_function_key_event,
|
||||||
|
&function_key_event_info,
|
||||||
|
APP_EVENT_FLAGS_CREATE(APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));
|
||||||
27
src/events/function_key_event.h
Normal file
27
src/events/function_key_event.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef FUNCTION_KEY_EVENT_H__
|
||||||
|
#define FUNCTION_KEY_EVENT_H__
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <app_event_manager.h>
|
||||||
|
#include <app_event_manager_profiler_tracer.h>
|
||||||
|
|
||||||
|
struct function_key_event {
|
||||||
|
struct app_event_header header;
|
||||||
|
uint16_t usage;
|
||||||
|
bool pressed;
|
||||||
|
};
|
||||||
|
|
||||||
|
APP_EVENT_TYPE_DECLARE(function_key_event);
|
||||||
|
|
||||||
|
static inline void function_key_event_submit(uint16_t usage, bool pressed)
|
||||||
|
{
|
||||||
|
struct function_key_event *event = new_function_key_event();
|
||||||
|
|
||||||
|
event->usage = usage;
|
||||||
|
event->pressed = pressed;
|
||||||
|
APP_EVENT_SUBMIT(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* FUNCTION_KEY_EVENT_H__ */
|
||||||
Reference in New Issue
Block a user