Clang formatter changes
This commit is contained in:
parent
f357aeddc8
commit
ace8cc307e
4 changed files with 49 additions and 58 deletions
|
@ -21,4 +21,3 @@ typedef struct _split_data_t {
|
|||
int zmk_split_position_pressed(uint8_t position);
|
||||
|
||||
int zmk_split_position_released(uint8_t position);
|
||||
|
||||
|
|
|
@ -62,8 +62,8 @@ void activity_work_handler(struct k_work *work) {
|
|||
} else
|
||||
#endif /* IS_ENABLED(CONFIG_ZMK_SLEEP) */
|
||||
if (inactive_time > MAX_IDLE_MS) {
|
||||
set_state(ZMK_ACTIVITY_IDLE);
|
||||
}
|
||||
set_state(ZMK_ACTIVITY_IDLE);
|
||||
}
|
||||
}
|
||||
|
||||
K_WORK_DEFINE(activity_work, activity_work_handler);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* Copyright (c) 2022 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
* Copyright (c) 2022 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <zmk/split/common.h>
|
||||
#include <init.h>
|
||||
|
@ -20,7 +20,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
|||
#include <zmk/matrix.h>
|
||||
|
||||
#if !DT_HAS_CHOSEN(zmk_split_serial)
|
||||
#error "No zmk-split-serial node is chosen"
|
||||
#error "No zmk-split-serial node is chosen"
|
||||
#endif
|
||||
|
||||
#define UART_NODE1 DT_CHOSEN(zmk_split_serial)
|
||||
|
@ -29,17 +29,16 @@ static int uart_ready = 0;
|
|||
|
||||
static void split_serial_receive_thread(void *unused, void *unused1, void *unused2);
|
||||
|
||||
K_MEM_SLAB_DEFINE(split_memory_slab, sizeof(split_data_t), \
|
||||
K_MEM_SLAB_DEFINE(split_memory_slab, sizeof(split_data_t),
|
||||
CONFIG_ZMK_SPLIT_SERIAL_THREAD_QUEUE_SIZE, 4);
|
||||
|
||||
K_MSGQ_DEFINE(peripheral_event_msgq, sizeof(struct zmk_position_state_changed), \
|
||||
K_MSGQ_DEFINE(peripheral_event_msgq, sizeof(struct zmk_position_state_changed),
|
||||
CONFIG_ZMK_SPLIT_SERIAL_THREAD_QUEUE_SIZE, 4);
|
||||
|
||||
K_THREAD_DEFINE(split_central, CONFIG_ZMK_SPLIT_SERIAL_THREAD_STACK_SIZE,
|
||||
split_serial_receive_thread, NULL, NULL, NULL,
|
||||
K_PRIO_PREEMPT(CONFIG_ZMK_SPLIT_SERIAL_THREAD_PRIORITY), 0, 0);
|
||||
|
||||
|
||||
static void peripheral_event_work_callback(struct k_work *work) {
|
||||
struct zmk_position_state_changed ev;
|
||||
while (k_msgq_get(&peripheral_event_msgq, &ev, K_NO_WAIT) == 0) {
|
||||
|
@ -64,7 +63,6 @@ static uint8_t split_central_notify_func(const void *data, uint16_t length) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < SPLIT_DATA_LEN; i++) {
|
||||
changed_positions[i] = split_data->data[i] ^ position_state[i];
|
||||
position_state[i] = split_data->data[i];
|
||||
|
@ -102,51 +100,48 @@ static char *alloc_position_state_buffer() {
|
|||
return block_ptr;
|
||||
}
|
||||
|
||||
|
||||
static void free_position_state_buffer(char *block_ptr) {
|
||||
k_mem_slab_free(&split_memory_slab, (void **)&block_ptr);
|
||||
}
|
||||
|
||||
|
||||
static void uart_callback(const struct device *dev, struct uart_event *evt, void *user_data) {
|
||||
char *buf = NULL;
|
||||
|
||||
switch (evt->type) {
|
||||
|
||||
case UART_RX_STOPPED:
|
||||
LOG_DBG("UART device:%s rx stopped", serial_dev->name);
|
||||
break;
|
||||
case UART_RX_STOPPED:
|
||||
LOG_DBG("UART device:%s rx stopped", serial_dev->name);
|
||||
break;
|
||||
|
||||
case UART_RX_BUF_REQUEST:
|
||||
LOG_DBG("UART device:%s rx extra buf req", serial_dev->name);
|
||||
buf = alloc_position_state_buffer();
|
||||
if (NULL != buf) {
|
||||
int ret = uart_rx_buf_rsp(serial_dev, buf, sizeof(split_data_t));
|
||||
if (0 != ret) {
|
||||
LOG_WRN("UART device:%s rx extra buf req add failed: %d", serial_dev->name, ret);
|
||||
free_position_state_buffer(buf);
|
||||
}
|
||||
case UART_RX_BUF_REQUEST:
|
||||
LOG_DBG("UART device:%s rx extra buf req", serial_dev->name);
|
||||
buf = alloc_position_state_buffer();
|
||||
if (NULL != buf) {
|
||||
int ret = uart_rx_buf_rsp(serial_dev, buf, sizeof(split_data_t));
|
||||
if (0 != ret) {
|
||||
LOG_WRN("UART device:%s rx extra buf req add failed: %d", serial_dev->name, ret);
|
||||
free_position_state_buffer(buf);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case UART_RX_RDY:
|
||||
LOG_DBG("UART device:%s rx buf ready", serial_dev->name);
|
||||
break;
|
||||
case UART_RX_RDY:
|
||||
LOG_DBG("UART device:%s rx buf ready", serial_dev->name);
|
||||
break;
|
||||
|
||||
case UART_RX_BUF_RELEASED:
|
||||
LOG_DBG("UART device:%s rx buf released", serial_dev->name);
|
||||
split_central_notify_func(evt->data.rx_buf.buf, sizeof(split_data_t));
|
||||
free_position_state_buffer(evt->data.rx_buf.buf);
|
||||
break;
|
||||
case UART_RX_BUF_RELEASED:
|
||||
LOG_DBG("UART device:%s rx buf released", serial_dev->name);
|
||||
split_central_notify_func(evt->data.rx_buf.buf, sizeof(split_data_t));
|
||||
free_position_state_buffer(evt->data.rx_buf.buf);
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG_DBG("UART device:%s unhandled event: %u", serial_dev->name, evt->type);
|
||||
break;
|
||||
default:
|
||||
LOG_DBG("UART device:%s unhandled event: %u", serial_dev->name, evt->type);
|
||||
break;
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static void split_serial_receive_thread(void *unused, void *unused1, void *unused2) {
|
||||
if (!device_is_ready(serial_dev)) {
|
||||
LOG_WRN("UART device:%s not ready", serial_dev->name);
|
||||
|
@ -162,7 +157,7 @@ static void split_serial_receive_thread(void *unused, void *unused1, void *unuse
|
|||
uart_ready = 1;
|
||||
LOG_DBG("UART device:%s ready", serial_dev->name);
|
||||
|
||||
while(true) {
|
||||
while (true) {
|
||||
char *buf = alloc_position_state_buffer();
|
||||
if (NULL == buf) {
|
||||
k_msleep(100);
|
||||
|
@ -182,4 +177,3 @@ static void split_serial_receive_thread(void *unused, void *unused1, void *unuse
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* Copyright (c) 2022 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
* Copyright (c) 2022 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <zmk/split/common.h>
|
||||
#include <sys/util.h>
|
||||
|
@ -19,7 +19,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
|||
#include <zmk/matrix.h>
|
||||
|
||||
#if !DT_HAS_CHOSEN(zmk_split_serial)
|
||||
#error "No zmk-split-serial node is chosen"
|
||||
#error "No zmk-split-serial node is chosen"
|
||||
#endif
|
||||
|
||||
#define UART_NODE1 DT_CHOSEN(zmk_split_serial)
|
||||
|
@ -35,13 +35,12 @@ struct k_work_q service_work_q;
|
|||
K_MSGQ_DEFINE(position_state_msgq, sizeof(char[SPLIT_DATA_LEN]),
|
||||
CONFIG_ZMK_SPLIT_SERIAL_THREAD_QUEUE_SIZE, 4);
|
||||
|
||||
|
||||
void send_data_via_uart(const struct device *dev, char *data, size_t len) {
|
||||
if (!uart_ready) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i=0; i < len; i++) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
uart_poll_out(serial_dev, data[i]);
|
||||
}
|
||||
}
|
||||
|
@ -61,15 +60,15 @@ int send_position_state() {
|
|||
int err = k_msgq_put(&position_state_msgq, position_state, K_MSEC(100));
|
||||
if (err) {
|
||||
switch (err) {
|
||||
case -EAGAIN: {
|
||||
LOG_WRN("Position state message queue full, popping first message and queueing again");
|
||||
uint8_t discarded_state[SPLIT_DATA_LEN];
|
||||
k_msgq_get(&position_state_msgq, &discarded_state, K_NO_WAIT);
|
||||
return send_position_state();
|
||||
}
|
||||
default:
|
||||
LOG_WRN("Failed to queue position state to send (%d)", err);
|
||||
return err;
|
||||
case -EAGAIN: {
|
||||
LOG_WRN("Position state message queue full, popping first message and queueing again");
|
||||
uint8_t discarded_state[SPLIT_DATA_LEN];
|
||||
k_msgq_get(&position_state_msgq, &discarded_state, K_NO_WAIT);
|
||||
return send_position_state();
|
||||
}
|
||||
default:
|
||||
LOG_WRN("Failed to queue position state to send (%d)", err);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,4 +102,3 @@ int service_init(const struct device *_arg) {
|
|||
}
|
||||
|
||||
SYS_INIT(service_init, APPLICATION, CONFIG_ZMK_USB_INIT_PRIORITY);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue