Skip to content

Commit

Permalink
feat(rpc): Move max message size to Kconfig.
Browse files Browse the repository at this point in the history
  • Loading branch information
petejohanson committed Mar 15, 2024
1 parent a55de93 commit 9aeb3c0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
5 changes: 5 additions & 0 deletions app/src/studio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
menuconfig ZMK_STUDIO
bool "Studio Support"
select NANOPB
select ZMK_BEHAVIOR_METADATA
help
Add firmware support for realtime keymap updates (ZMK Studio

if ZMK_STUDIO

config ZMK_STUDIO_MAX_MSG_SIZE
int "Max RPC message size"
default 64

menu "Interfaces"

config ZMK_STUDIO_INTERFACE_UART
Expand Down
20 changes: 4 additions & 16 deletions app/src/studio/gatt_rpc_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@

#include <zephyr/logging/log.h>

#define MSG_SIZE 32

LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

NET_BUF_SIMPLE_DEFINE_STATIC(rx_buf, MSG_SIZE);
NET_BUF_SIMPLE_DEFINE_STATIC(rx_buf, CONFIG_ZMK_STUDIO_MAX_MSG_SIZE);

static enum studio_framing_state rpc_framing_state;

Expand All @@ -44,17 +42,6 @@ static ssize_t read_rpc_resp(struct bt_conn *conn, const struct bt_gatt_attr *at

LOG_DBG("Read response for length %d at offset %d", len, offset);
return 0;

// const uint8_t source = (uint8_t)(uint32_t)attr->user_data;
// uint8_t level = 0;
// int rc = zmk_split_get_peripheral_battery_level(source, &level);

// if (rc == -EINVAL) {
// LOG_ERR("Invalid peripheral index requested for battery level read: %d", source);
// return 0;
// }

// return bt_gatt_attr_read(conn, attr, buf, len, offset, &level, sizeof(uint8_t));
}

static void send_response(struct bt_conn *conn, const zmk_Response *response);
Expand Down Expand Up @@ -96,7 +83,8 @@ BT_GATT_SERVICE_DEFINE(
BT_GATT_CCC(rpc_ccc_cfg_changed, BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT));

static void send_response(struct bt_conn *conn, const zmk_Response *response) {
uint8_t resp_data[128];
uint8_t resp_data[CONFIG_ZMK_STUDIO_MAX_MSG_SIZE];

pb_ostream_t stream = pb_ostream_from_buffer(resp_data, ARRAY_SIZE(resp_data));

/* Now we are ready to encode the message! */
Expand All @@ -109,7 +97,7 @@ static void send_response(struct bt_conn *conn, const zmk_Response *response) {

size_t out_size = stream.bytes_written;

uint8_t resp_frame[128];
uint8_t resp_frame[CONFIG_ZMK_STUDIO_MAX_MSG_SIZE * 2];

int frame_encoded_size =
studio_framing_encode_frame(resp_data, out_size, resp_frame, sizeof(resp_frame));
Expand Down
9 changes: 2 additions & 7 deletions app/src/studio/uart_rpc_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
/* change this to any other UART peripheral if desired */
#define UART_DEVICE_NODE DT_CHOSEN(zmk_studio_rpc_uart)

#define MSG_SIZE 32

static const struct device *const uart_dev = DEVICE_DT_GET(UART_DEVICE_NODE);

NET_BUF_SIMPLE_DEFINE_STATIC(rx_buf, MSG_SIZE);
NET_BUF_SIMPLE_DEFINE_STATIC(rx_buf, CONFIG_ZMK_STUDIO_MAX_MSG_SIZE);

/* queue to store up to 10 messages (aligned to 4-byte boundary) */
K_MSGQ_DEFINE(req_msgq, sizeof(zmk_Request), 10, 4);
Expand All @@ -45,7 +43,7 @@ void rpc_cb(struct k_work *work) {
while (k_msgq_get(&req_msgq, &req, K_NO_WAIT) >= 0) {
zmk_Response resp = zmk_rpc_handle_request(&req);

uint8_t payload[32];
uint8_t payload[CONFIG_ZMK_STUDIO_MAX_MSG_SIZE];

pb_ostream_t stream = pb_ostream_from_buffer(payload, ARRAY_SIZE(payload));

Expand Down Expand Up @@ -93,8 +91,6 @@ static void serial_cb(const struct device *dev, void *user_data) {
while (uart_fifo_read(uart_dev, &c, 1) == 1) {
studio_framing_recv_byte(&rx_buf, &rpc_framing_state, c);

LOG_DBG("GOT %d", c);

if (rpc_framing_state == FRAMING_STATE_IDLE && rx_buf.len > 0) {
zmk_Request req = zmk_Request_init_zero;

Expand All @@ -114,7 +110,6 @@ static void serial_cb(const struct device *dev, void *user_data) {
}

static int uart_rpc_interface_init(void) {
LOG_ERR("INIT UART");
if (!device_is_ready(uart_dev)) {
LOG_ERR("UART device not found!");
return 0;
Expand Down

0 comments on commit 9aeb3c0

Please sign in to comment.