diff --git a/app/src/studio/Kconfig b/app/src/studio/Kconfig index f2e2e10c25c..b9782583011 100644 --- a/app/src/studio/Kconfig +++ b/app/src/studio/Kconfig @@ -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 diff --git a/app/src/studio/gatt_rpc_interface.c b/app/src/studio/gatt_rpc_interface.c index 9329462a2fe..05d219d9e02 100644 --- a/app/src/studio/gatt_rpc_interface.c +++ b/app/src/studio/gatt_rpc_interface.c @@ -23,11 +23,9 @@ #include -#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; @@ -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); @@ -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! */ @@ -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)); diff --git a/app/src/studio/uart_rpc_interface.c b/app/src/studio/uart_rpc_interface.c index 2efa58218b2..028bad0269f 100644 --- a/app/src/studio/uart_rpc_interface.c +++ b/app/src/studio/uart_rpc_interface.c @@ -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); @@ -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)); @@ -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; @@ -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;