[MERGE] Implement multiple logging backends (22159)

This commit is contained in:
Drashna Jael're 2024-02-16 10:41:44 -08:00
parent f63ae38d1e
commit a331eefb31
No known key found for this signature in database
GPG Key ID: DBA1FD3A860D1B11
19 changed files with 112 additions and 36 deletions

View File

@ -44,6 +44,31 @@ else ifeq ($(strip $(DEBUG_MATRIX_SCAN_RATE_ENABLE)), api)
OPT_DEFS += -DDEBUG_MATRIX_SCAN_RATE
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
ifeq ($(strip $(AUDIO_ENABLE)), yes)
ifeq ($(PLATFORM),CHIBIOS)

View 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>

View 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;
}

View 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

View File

@ -0,0 +1,3 @@
DEBUG_MATRIX_SCAN_RATE_ENABLE = api
SENDCHAR_DRIVER = uart

View File

@ -16,21 +16,11 @@
*/
#include <util/delay.h>
#include "mschwingen.h"
#include "uart.h"
#include "print.h"
#include "sendchar.h"
#include "ws2812.h"
#include "sleep_led.h"
#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 bool blink_state = false;
static uint8_t isRecording = 0;
@ -104,11 +94,6 @@ void keyboard_pre_init_kb(void) {
gpio_set_pin_output(MODELM_STATUS_LED);
gpio_write_pin_high(MODELM_STATUS_LED);
_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_CLK_PIN);

View File

@ -1,5 +1,5 @@
UART_DEBUG ?= no
ifeq ($(strip $(UART_DEBUG)), yes)
OPT_DEFS += -DUART_DEBUG
SENDCHAR_DRIVER = uart
endif

View File

@ -1,7 +1,7 @@
CUSTOM_MATRIX = lite
SRC += matrix.c
UART_DRIVER_REQUIRED = yes
SPI_DRIVER_REQUIRED = yes
OPT_DEFS += -DSLEEP_LED_ENABLE

View File

@ -189,7 +189,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));
}
// 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)
static uint32_t matrix_timer = 0;
static uint32_t matrix_scan_count = 0;
@ -200,9 +200,7 @@ void matrix_scan_perf_task(void) {
uint32_t timer_now = timer_read32();
if (TIMER_DIFF_32(timer_now, matrix_timer) >= 1000) {
# if defined(CONSOLE_ENABLE)
dprintf("matrix scan frequency: %lu\n", matrix_scan_count);
# endif
last_matrix_scan_count = matrix_scan_count;
matrix_timer = timer_now;
matrix_scan_count = 0;

View 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);
}

View 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;
}

View File

@ -39,10 +39,6 @@ endif
ifeq ($(strip $(CONSOLE_ENABLE)), yes)
OPT_DEFS += -DCONSOLE_ENABLE
else
# TODO: decouple this so other print backends can exist
OPT_DEFS += -DNO_PRINT
OPT_DEFS += -DNO_DEBUG
endif
ifeq ($(strip $(NKRO_ENABLE)), yes)

View File

@ -136,7 +136,7 @@ void send_extra(report_extra_t *report) {
static char console_printbuf[CONSOLE_PRINTBUF_SIZE];
static uint16_t console_printbuf_len = 0;
int8_t sendchar(uint8_t c) {
int8_t console_write(uint8_t c) {
if (console_printbuf_len >= CONSOLE_PRINTBUF_SIZE) return -1;
console_printbuf[console_printbuf_len++] = c;

View File

@ -30,7 +30,6 @@
#include "usb_device_state.h"
#include "mousekey.h"
#include "led.h"
#include "sendchar.h"
#include "debug.h"
#include "print.h"

View File

@ -518,7 +518,7 @@ void send_digitizer(report_digitizer_t *report) {
#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));
}

View File

@ -53,7 +53,7 @@ void usb_event_queue_task(void);
#ifdef CONSOLE_ENABLE
/* Putchar over the USB console */
int8_t sendchar(uint8_t c);
int8_t console_write(uint8_t c);
#endif /* CONSOLE_ENABLE */

View File

@ -42,7 +42,6 @@
#include "keyboard.h"
#include "action.h"
#include "led.h"
#include "sendchar.h"
#include "debug.h"
#ifdef SLEEP_LED_ENABLE
# include "sleep_led.h"
@ -210,7 +209,7 @@ static void console_flush_task(void) {
while (Endpoint_IsReadWriteAllowed())
Endpoint_Write_8(0);
// flush sendchar packet
// flush console packet
if (Endpoint_IsINReady()) {
Endpoint_ClearIN();
}
@ -594,7 +593,7 @@ void send_digitizer(report_digitizer_t *report) {
}
/*******************************************************************************
* sendchar
* CONSOLE
******************************************************************************/
#ifdef CONSOLE_ENABLE
# define SEND_TIMEOUT 5
@ -602,13 +601,13 @@ void send_digitizer(report_digitizer_t *report) {
*
* 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.
// 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.
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.
CONSOLE_FLUSH_SET(false);

View File

@ -25,7 +25,6 @@
#include "debug.h"
#include "suspend.h"
#include "wait.h"
#include "sendchar.h"
#ifdef SLEEP_LED_ENABLE
# include "sleep_led.h"

View File

@ -182,7 +182,7 @@ void raw_hid_task(void) {
# define CONSOLE_BUFFER_SIZE 32
# define CONSOLE_EPSIZE 8
int8_t sendchar(uint8_t c) {
int8_t console_write(uint8_t c) {
rbuf_enqueue(c);
return 0;
}