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