[MERGE] Implement multiple logging backends (22159)
This commit is contained in:
parent
1648a63812
commit
cbb8b0de36
18 changed files with 111 additions and 35 deletions
|
@ -45,6 +45,31 @@ else ifeq ($(strip $(DEBUG_MATRIX_SCAN_RATE_ENABLE)), api)
|
||||||
OPT_DEFS += -DDEBUG_MATRIX_SCAN_RATE
|
OPT_DEFS += -DDEBUG_MATRIX_SCAN_RATE
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(strip $(CONSOLE_ENABLE)), yes)
|
||||||
|
SENDCHAR_DRIVER ?= console
|
||||||
|
else
|
||||||
|
SENDCHAR_DRIVER ?= none
|
||||||
|
endif
|
||||||
|
VALID_SENDCHAR_DRIVER_TYPES := console uart custom
|
||||||
|
ifneq ($(strip $(SENDCHAR_DRIVER)),none)
|
||||||
|
ifeq ($(filter $(SENDCHAR_DRIVER),$(VALID_SENDCHAR_DRIVER_TYPES)),)
|
||||||
|
$(call CATASTROPHIC_ERROR,Invalid SENDCHAR_DRIVER,SENDCHAR_DRIVER="$(SENDCHAR_DRIVER)" is not a valid logging driver type)
|
||||||
|
else
|
||||||
|
OPT_DEFS += -DSENDCHAR_DRIVER_$(strip $(shell echo $(SENDCHAR_DRIVER) | tr '[:lower:]' '[:upper:]'))
|
||||||
|
|
||||||
|
ifneq ($(strip $(SENDCHAR_DRIVER)), custom)
|
||||||
|
QUANTUM_SRC += $(QUANTUM_DIR)/logging/sendchar_$(strip $(shell echo $(SENDCHAR_DRIVER) | tr '[:upper:]' '[:lower:]')).c
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(strip $(SENDCHAR_DRIVER)), uart)
|
||||||
|
UART_DRIVER_REQUIRED = yes
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
OPT_DEFS += -DNO_PRINT
|
||||||
|
OPT_DEFS += -DNO_DEBUG
|
||||||
|
endif
|
||||||
|
|
||||||
AUDIO_ENABLE ?= no
|
AUDIO_ENABLE ?= no
|
||||||
ifeq ($(strip $(AUDIO_ENABLE)), yes)
|
ifeq ($(strip $(AUDIO_ENABLE)), yes)
|
||||||
ifeq ($(PLATFORM),CHIBIOS)
|
ifeq ($(PLATFORM),CHIBIOS)
|
||||||
|
|
7
keyboards/handwired/onekey/keymaps/uart_log/halconf.h
Normal file
7
keyboards/handwired/onekey/keymaps/uart_log/halconf.h
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
// Copyright 2023 QMK
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define HAL_USE_SERIAL TRUE
|
||||||
|
|
||||||
|
#include_next <halconf.h>
|
30
keyboards/handwired/onekey/keymaps/uart_log/keymap.c
Normal file
30
keyboards/handwired/onekey/keymaps/uart_log/keymap.c
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
// Copyright 2023 QMK
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
#include QMK_KEYBOARD_H
|
||||||
|
|
||||||
|
enum custom_keycodes {
|
||||||
|
KC_HELLO = SAFE_RANGE,
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
|
LAYOUT_ortho_1x1(KC_HELLO)
|
||||||
|
};
|
||||||
|
|
||||||
|
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
switch (keycode) {
|
||||||
|
case KC_HELLO:
|
||||||
|
if (record->event.pressed) {
|
||||||
|
println("Hello world!");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void keyboard_post_init_user(void) {
|
||||||
|
// Customise these values to desired behaviour
|
||||||
|
debug_enable=true;
|
||||||
|
debug_matrix=true;
|
||||||
|
//debug_keyboard=true;
|
||||||
|
//debug_mouse=true;
|
||||||
|
}
|
8
keyboards/handwired/onekey/keymaps/uart_log/mcuconf.h
Normal file
8
keyboards/handwired/onekey/keymaps/uart_log/mcuconf.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// Copyright 2023 QMK
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include_next <mcuconf.h>
|
||||||
|
|
||||||
|
#undef STM32_SERIAL_USE_USART1
|
||||||
|
#define STM32_SERIAL_USE_USART1 TRUE
|
3
keyboards/handwired/onekey/keymaps/uart_log/rules.mk
Normal file
3
keyboards/handwired/onekey/keymaps/uart_log/rules.mk
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
DEBUG_MATRIX_SCAN_RATE_ENABLE = api
|
||||||
|
|
||||||
|
SENDCHAR_DRIVER = uart
|
|
@ -16,7 +16,6 @@
|
||||||
*/
|
*/
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
#include "mschwingen.h"
|
#include "mschwingen.h"
|
||||||
#include "uart.h"
|
|
||||||
#include "print.h"
|
#include "print.h"
|
||||||
#include "sendchar.h"
|
#include "sendchar.h"
|
||||||
#include "sleep_led.h"
|
#include "sleep_led.h"
|
||||||
|
@ -25,15 +24,6 @@
|
||||||
#include "ws2812.h"
|
#include "ws2812.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef UART_DEBUG
|
|
||||||
# undef sendchar
|
|
||||||
static int8_t capture_sendchar(uint8_t c) {
|
|
||||||
// sendchar(c);
|
|
||||||
uart_write(c);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static uint16_t blink_cycle_timer;
|
static uint16_t blink_cycle_timer;
|
||||||
static bool blink_state = false;
|
static bool blink_state = false;
|
||||||
static uint8_t isRecording = 0;
|
static uint8_t isRecording = 0;
|
||||||
|
@ -88,11 +78,6 @@ void keyboard_pre_init_kb(void) {
|
||||||
gpio_set_pin_output(MODELM_STATUS_LED);
|
gpio_set_pin_output(MODELM_STATUS_LED);
|
||||||
gpio_write_pin_high(MODELM_STATUS_LED);
|
gpio_write_pin_high(MODELM_STATUS_LED);
|
||||||
_delay_ms(50);
|
_delay_ms(50);
|
||||||
#ifdef UART_DEBUG
|
|
||||||
uart_init(115200);
|
|
||||||
print_set_sendchar(capture_sendchar);
|
|
||||||
uprintf("\r\nHello world!\r\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
gpio_set_pin_output(SR_LOAD_PIN);
|
gpio_set_pin_output(SR_LOAD_PIN);
|
||||||
gpio_set_pin_output(SR_CLK_PIN);
|
gpio_set_pin_output(SR_CLK_PIN);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
UART_DEBUG ?= no
|
UART_DEBUG ?= no
|
||||||
|
|
||||||
ifeq ($(strip $(UART_DEBUG)), yes)
|
ifeq ($(strip $(UART_DEBUG)), yes)
|
||||||
OPT_DEFS += -DUART_DEBUG
|
SENDCHAR_DRIVER = uart
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
CUSTOM_MATRIX = lite
|
CUSTOM_MATRIX = lite
|
||||||
|
|
||||||
SRC += matrix.c
|
SRC += matrix.c
|
||||||
UART_DRIVER_REQUIRED = yes
|
|
||||||
SPI_DRIVER_REQUIRED = yes
|
SPI_DRIVER_REQUIRED = yes
|
||||||
|
|
||||||
OPT_DEFS += -DSLEEP_LED_ENABLE
|
OPT_DEFS += -DSLEEP_LED_ENABLE
|
||||||
|
|
|
@ -192,7 +192,7 @@ void set_activity_timestamps(uint32_t matrix_timestamp, uint32_t encoder_timesta
|
||||||
last_input_modification_time = MAX(matrix_timestamp, MAX(encoder_timestamp, pointing_device_timestamp));
|
last_input_modification_time = MAX(matrix_timestamp, MAX(encoder_timestamp, pointing_device_timestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only enable this if console is enabled to print to
|
// Only enable this if logging is enabled to print to
|
||||||
#if defined(DEBUG_MATRIX_SCAN_RATE)
|
#if defined(DEBUG_MATRIX_SCAN_RATE)
|
||||||
static uint32_t matrix_timer = 0;
|
static uint32_t matrix_timer = 0;
|
||||||
static uint32_t matrix_scan_count = 0;
|
static uint32_t matrix_scan_count = 0;
|
||||||
|
@ -203,9 +203,7 @@ void matrix_scan_perf_task(void) {
|
||||||
|
|
||||||
uint32_t timer_now = timer_read32();
|
uint32_t timer_now = timer_read32();
|
||||||
if (TIMER_DIFF_32(timer_now, matrix_timer) >= 1000) {
|
if (TIMER_DIFF_32(timer_now, matrix_timer) >= 1000) {
|
||||||
# if defined(CONSOLE_ENABLE)
|
|
||||||
dprintf("matrix scan frequency: %lu\n", matrix_scan_count);
|
dprintf("matrix scan frequency: %lu\n", matrix_scan_count);
|
||||||
# endif
|
|
||||||
last_matrix_scan_count = matrix_scan_count;
|
last_matrix_scan_count = matrix_scan_count;
|
||||||
matrix_timer = timer_now;
|
matrix_timer = timer_now;
|
||||||
matrix_scan_count = 0;
|
matrix_scan_count = 0;
|
||||||
|
|
8
quantum/logging/sendchar_console.c
Normal file
8
quantum/logging/sendchar_console.c
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// Copyright 2023 QMK
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
#include "sendchar.h"
|
||||||
|
int8_t console_write(uint8_t c);
|
||||||
|
|
||||||
|
int8_t sendchar(uint8_t c) {
|
||||||
|
return console_write(c);
|
||||||
|
}
|
19
quantum/logging/sendchar_uart.c
Normal file
19
quantum/logging/sendchar_uart.c
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
// Copyright 2023 QMK
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
#include "sendchar.h"
|
||||||
|
#include "uart.h"
|
||||||
|
|
||||||
|
#ifndef SENDCHAR_BAUD_RATE
|
||||||
|
# define SENDCHAR_BAUD_RATE 9600
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int8_t sendchar(uint8_t c) {
|
||||||
|
static bool s_init = false;
|
||||||
|
if (!s_init) {
|
||||||
|
uart_init(SENDCHAR_BAUD_RATE);
|
||||||
|
s_init = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
uart_write(c);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -39,10 +39,6 @@ endif
|
||||||
|
|
||||||
ifeq ($(strip $(CONSOLE_ENABLE)), yes)
|
ifeq ($(strip $(CONSOLE_ENABLE)), yes)
|
||||||
OPT_DEFS += -DCONSOLE_ENABLE
|
OPT_DEFS += -DCONSOLE_ENABLE
|
||||||
else
|
|
||||||
# TODO: decouple this so other print backends can exist
|
|
||||||
OPT_DEFS += -DNO_PRINT
|
|
||||||
OPT_DEFS += -DNO_DEBUG
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(strip $(NKRO_ENABLE)), yes)
|
ifeq ($(strip $(NKRO_ENABLE)), yes)
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#include "usb_device_state.h"
|
#include "usb_device_state.h"
|
||||||
#include "mousekey.h"
|
#include "mousekey.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "sendchar.h"
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "print.h"
|
#include "print.h"
|
||||||
|
|
||||||
|
|
|
@ -504,7 +504,7 @@ void send_digitizer(report_digitizer_t *report) {
|
||||||
|
|
||||||
#ifdef CONSOLE_ENABLE
|
#ifdef CONSOLE_ENABLE
|
||||||
|
|
||||||
int8_t sendchar(uint8_t c) {
|
int8_t console_write(uint8_t c) {
|
||||||
return (int8_t)send_report_buffered(USB_ENDPOINT_IN_CONSOLE, &c, sizeof(uint8_t));
|
return (int8_t)send_report_buffered(USB_ENDPOINT_IN_CONSOLE, &c, sizeof(uint8_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ void usb_event_queue_task(void);
|
||||||
#ifdef CONSOLE_ENABLE
|
#ifdef CONSOLE_ENABLE
|
||||||
|
|
||||||
/* Putchar over the USB console */
|
/* Putchar over the USB console */
|
||||||
int8_t sendchar(uint8_t c);
|
int8_t console_write(uint8_t c);
|
||||||
|
|
||||||
#endif /* CONSOLE_ENABLE */
|
#endif /* CONSOLE_ENABLE */
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,6 @@
|
||||||
#include "keyboard.h"
|
#include "keyboard.h"
|
||||||
#include "action.h"
|
#include "action.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "sendchar.h"
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#ifdef SLEEP_LED_ENABLE
|
#ifdef SLEEP_LED_ENABLE
|
||||||
# include "sleep_led.h"
|
# include "sleep_led.h"
|
||||||
|
@ -204,7 +203,7 @@ static void console_flush_task(void) {
|
||||||
while (Endpoint_IsReadWriteAllowed())
|
while (Endpoint_IsReadWriteAllowed())
|
||||||
Endpoint_Write_8(0);
|
Endpoint_Write_8(0);
|
||||||
|
|
||||||
// flush sendchar packet
|
// flush console packet
|
||||||
if (Endpoint_IsINReady()) {
|
if (Endpoint_IsINReady()) {
|
||||||
Endpoint_ClearIN();
|
Endpoint_ClearIN();
|
||||||
}
|
}
|
||||||
|
@ -582,7 +581,7 @@ void send_digitizer(report_digitizer_t *report) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* sendchar
|
* CONSOLE
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
#ifdef CONSOLE_ENABLE
|
#ifdef CONSOLE_ENABLE
|
||||||
# define SEND_TIMEOUT 5
|
# define SEND_TIMEOUT 5
|
||||||
|
@ -590,13 +589,13 @@ void send_digitizer(report_digitizer_t *report) {
|
||||||
*
|
*
|
||||||
* FIXME: Needs doc
|
* FIXME: Needs doc
|
||||||
*/
|
*/
|
||||||
int8_t sendchar(uint8_t c) {
|
int8_t console_write(uint8_t c) {
|
||||||
// Do not wait if the previous write has timed_out.
|
// Do not wait if the previous write has timed_out.
|
||||||
// Because sendchar() is called so many times, waiting each call causes big lag.
|
// Because console_write() is called so many times, waiting each call causes big lag.
|
||||||
// The `timed_out` state is an approximation of the ideal `is_listener_disconnected?` state.
|
// The `timed_out` state is an approximation of the ideal `is_listener_disconnected?` state.
|
||||||
static bool timed_out = false;
|
static bool timed_out = false;
|
||||||
|
|
||||||
// prevents console_flush_task() from running during sendchar() runs.
|
// prevents console_flush_task() from running during console_write() runs.
|
||||||
// or char will be lost. These two function is mutually exclusive.
|
// or char will be lost. These two function is mutually exclusive.
|
||||||
CONSOLE_FLUSH_SET(false);
|
CONSOLE_FLUSH_SET(false);
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "suspend.h"
|
#include "suspend.h"
|
||||||
#include "wait.h"
|
#include "wait.h"
|
||||||
#include "sendchar.h"
|
|
||||||
|
|
||||||
#ifdef SLEEP_LED_ENABLE
|
#ifdef SLEEP_LED_ENABLE
|
||||||
# include "sleep_led.h"
|
# include "sleep_led.h"
|
||||||
|
|
|
@ -179,7 +179,7 @@ void raw_hid_task(void) {
|
||||||
# define CONSOLE_BUFFER_SIZE 32
|
# define CONSOLE_BUFFER_SIZE 32
|
||||||
# define CONSOLE_EPSIZE 8
|
# define CONSOLE_EPSIZE 8
|
||||||
|
|
||||||
int8_t sendchar(uint8_t c) {
|
int8_t console_write(uint8_t c) {
|
||||||
rbuf_enqueue(c);
|
rbuf_enqueue(c);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue