commit 75991f63b5a061592d57b59a9c4f46a078d19406
parent d19f5ce8b56e1199eb9e20ba83b38f8e3e915437
Author: Louis Burda <quent.burda@gmail.com>
Date: Sun, 5 Feb 2023 17:29:43 +0100
Forward warning from slave to master and dont call hid and cdc tasks on slave
Diffstat:
6 files changed, 41 insertions(+), 19 deletions(-)
diff --git a/src/hid.c b/src/hid.c
@@ -148,7 +148,7 @@ active_layers_push(uint layer, uint key)
active_layers[active_layers_top].key = key;
for (i = 0; i <= active_layers_top; i++) {
- INFO("%i. ACTIVE %u %u", i,
+ DEBUG("%i. ACTIVE %u %u", i,
active_layers[i].layer, active_layers[i].key);
}
}
diff --git a/src/main.c b/src/main.c
@@ -42,10 +42,12 @@ main(void)
start = board_millis();
while (true) {
tud_task();
- cdc_task();
led_task();
split_task();
- hid_task();
+ if (split_role == MASTER) {
+ cdc_task();
+ hid_task();
+ }
stop = board_millis();
DEBUG("Main loop: %i ms", stop - start);
@@ -141,8 +143,6 @@ process_cmd(char *cmd)
loglevel = LOG_INFO;
} else if (!strcmp(arg, "warn")) {
loglevel = LOG_WARN;
- } else if (!strcmp(arg, "err")) {
- loglevel = LOG_ERR;
} else {
printf("Invalid log level\n");
}
diff --git a/src/split.c b/src/split.c
@@ -36,7 +36,7 @@
enum {
CMD_SCAN_KEYMAT_REQ = 0x80,
CMD_SCAN_KEYMAT_RESP,
- CMD_STDIO_PUTS
+ CMD_SLAVE_WARN
};
static void uart_tx_sm_init(void);
@@ -49,7 +49,7 @@ static bool uart_await_tx(uint32_t timeout_ms);
static uint8_t uart_rx_byte(void);
static void uart_tx_byte(uint8_t c);
-static uint uart_recv(uint8_t *data, uint len);
+static uint uart_recv(uint8_t *data, uint len, bool nullterm);
static uint uart_send(const uint8_t *data, uint len);
static void handle_cmd(uint8_t cmd);
@@ -183,7 +183,7 @@ uart_tx_byte(uint8_t c)
}
uint
-uart_recv(uint8_t *data, uint len)
+uart_recv(uint8_t *data, uint len, bool nullterm)
{
uint recv;
@@ -193,6 +193,8 @@ uart_recv(uint8_t *data, uint len)
break;
}
*data++ = uart_rx_byte();
+ if (nullterm && !*data)
+ break;
}
return recv;
@@ -217,13 +219,13 @@ uart_send(const uint8_t *data, uint len)
void
handle_cmd(uint8_t start)
{
- uint8_t buf[128];
+ static uint8_t msgbuf[128];
uint8_t cmd;
if (start != 0xaa)
return;
- if (!uart_recv(&cmd, 1)) {
+ if (!uart_recv(&cmd, 1, false)) {
WARN("Got start byte without command");
return;
}
@@ -241,18 +243,18 @@ handle_cmd(uint8_t start)
WARN("Got SCAN_KEYMAT_RESP as slave");
break;
}
- if (uart_recv((uint8_t *) &halfmat, 4) != 4)
+ if (uart_recv((uint8_t *) &halfmat, 4, false) != 4)
WARN("Incomplete matrix received");
scan_pending = false;
break;
- case CMD_STDIO_PUTS:
+ case CMD_SLAVE_WARN:
if (split_role != MASTER) {
- WARN("Got STDIO_PUTS as slave");
+ WARN("Got SLAVE_WARN as slave");
break;
}
- memset(buf, 0, sizeof(buf));
- uart_recv(buf, sizeof(buf)-1);
- printf("SLAVE: %s\n", buf);
+ memset(msgbuf, 0, sizeof(msgbuf));
+ uart_recv(msgbuf, sizeof(msgbuf)-1, true);
+ WARN("SLAVE: %s\n", msgbuf);
break;
default:
WARN("Unknown uart cmd: %i", cmd);
@@ -339,3 +341,18 @@ split_task(void)
}
}
}
+
+void
+split_warn_master(const char *msg)
+{
+ uint32_t len;
+
+ if (!send_cmd(CMD_SLAVE_WARN)) {
+ WARN("UART send SLAVE_WARN failed");
+ return;
+ }
+
+ len = strlen(msg) + 1;
+ if (uart_send((const uint8_t *) msg, len) != len)
+ WARN("UART send warning failed");
+}
diff --git a/src/split.h b/src/split.h
@@ -11,4 +11,6 @@
void split_init(void);
void split_task(void);
+void split_warn_master(const char *msg);
+
extern int split_role;
diff --git a/src/util.c b/src/util.c
@@ -1,4 +1,6 @@
#include "util.h"
+
+#include "split.h"
#include "board.h"
#include "class/cdc/cdc_device.h"
#include "led.h"
@@ -11,7 +13,7 @@
#include <stdio.h>
-char warnlog[512];
+char warnlog[256];
int loglevel = LOG_INFO;
static void
@@ -49,6 +51,9 @@ stdio_log(int level, const char *fmtstr, ...)
va_start(cpy, fmtstr);
vsnprintf(warnlog, sizeof(warnlog), fmtstr, cpy);
va_end(cpy);
+
+ if (split_role == SLAVE)
+ split_warn_master(warnlog);
}
if (level > loglevel)
diff --git a/src/util.h b/src/util.h
@@ -9,7 +9,6 @@
#define ARRLEN(x) (sizeof(x) / sizeof((x)[0]))
-#define ERR(...) stdio_log(LOG_ERR, "ERR : " __VA_ARGS__)
#define WARN(...) stdio_log(LOG_WARN, "WARN : " __VA_ARGS__)
#define INFO(...) stdio_log(LOG_INFO, "INFO : " __VA_ARGS__)
#define DEBUG(...) stdio_log(LOG_DEBUG, "DEBUG: " __VA_ARGS__)
@@ -27,7 +26,6 @@
enum {
LOG_NONE,
- LOG_ERR,
LOG_WARN,
LOG_INFO,
LOG_DEBUG