Browse Source

Implement multiple logging backends

log_driver
zvecr 7 months ago
parent
commit
3006ed963c
19 changed files with 112 additions and 36 deletions
  1. +25
    -0
      builddefs/common_features.mk
  2. +7
    -0
      keyboards/handwired/onekey/keymaps/uart_log/halconf.h
  3. +30
    -0
      keyboards/handwired/onekey/keymaps/uart_log/keymap.c
  4. +8
    -0
      keyboards/handwired/onekey/keymaps/uart_log/mcuconf.h
  5. +3
    -0
      keyboards/handwired/onekey/keymaps/uart_log/rules.mk
  6. +0
    -15
      keyboards/ibm/model_m/mschwingen/mschwingen.c
  7. +1
    -1
      keyboards/ibm/model_m/mschwingen/post_rules.mk
  8. +1
    -1
      keyboards/ibm/model_m/mschwingen/rules.mk
  9. +1
    -3
      quantum/keyboard.c
  10. +8
    -0
      quantum/logging/sendchar_console.c
  11. +19
    -0
      quantum/logging/sendchar_uart.c
  12. +0
    -4
      tmk_core/protocol.mk
  13. +1
    -1
      tmk_core/protocol/arm_atsam/main_arm_atsam.c
  14. +0
    -1
      tmk_core/protocol/chibios/chibios.c
  15. +1
    -1
      tmk_core/protocol/chibios/usb_main.c
  16. +1
    -1
      tmk_core/protocol/chibios/usb_main.h
  17. +5
    -6
      tmk_core/protocol/lufa/lufa.c
  18. +0
    -1
      tmk_core/protocol/vusb/protocol.c
  19. +1
    -1
      tmk_core/protocol/vusb/vusb.c

+ 25
- 0
builddefs/common_features.mk 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)


+ 7
- 0
keyboards/handwired/onekey/keymaps/uart_log/halconf.h 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>

+ 30
- 0
keyboards/handwired/onekey/keymaps/uart_log/keymap.c 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;
}

+ 8
- 0
keyboards/handwired/onekey/keymaps/uart_log/mcuconf.h 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

+ 3
- 0
keyboards/handwired/onekey/keymaps/uart_log/rules.mk View File

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

+ 0
- 15
keyboards/ibm/model_m/mschwingen/mschwingen.c 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;
@ -103,11 +93,6 @@ void keyboard_pre_init_kb(void) {
setPinOutput(MODELM_STATUS_LED);
writePinHigh(MODELM_STATUS_LED);
_delay_ms(50);
#ifdef UART_DEBUG
uart_init(115200);
print_set_sendchar(capture_sendchar);
uprintf("\r\nHello world!\r\n");
#endif
setPinOutput(SR_LOAD_PIN);
setPinOutput(SR_CLK_PIN);


+ 1
- 1
keyboards/ibm/model_m/mschwingen/post_rules.mk View File

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

+ 1
- 1
keyboards/ibm/model_m/mschwingen/rules.mk View File

@ -19,7 +19,7 @@ DYNAMIC_MACRO_ENABLE = yes
UART_DEBUG = no
SRC += matrix.c
UART_DRIVER_REQUIRED = yes
SPI_DRIVER_REQUIRED = yes
OPT_DEFS += -DSLEEP_LED_ENABLE # we need our own sleep callbacks to turn of WS2812 LEDs


+ 1
- 3
quantum/keyboard.c View File

@ -184,7 +184,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;
@ -195,9 +195,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;


+ 8
- 0
quantum/logging/sendchar_console.c 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);
}

+ 19
- 0
quantum/logging/sendchar_uart.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;
}

+ 0
- 4
tmk_core/protocol.mk 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)


+ 1
- 1
tmk_core/protocol/arm_atsam/main_arm_atsam.c 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;


+ 0
- 1
tmk_core/protocol/chibios/chibios.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"


+ 1
- 1
tmk_core/protocol/chibios/usb_main.c View File

@ -930,7 +930,7 @@ void send_digitizer(report_digitizer_t *report) {
#ifdef CONSOLE_ENABLE
int8_t sendchar(uint8_t c) {
int8_t console_write(uint8_t c) {
rbuf_enqueue(c);
return 0;
}


+ 1
- 1
tmk_core/protocol/chibios/usb_main.h View File

@ -55,6 +55,6 @@ 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 */

+ 5
- 6
tmk_core/protocol/lufa/lufa.c 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"
@ -205,7 +204,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();
}
@ -589,7 +588,7 @@ void send_digitizer(report_digitizer_t *report) {
}
/*******************************************************************************
* sendchar
* CONSOLE
******************************************************************************/
#ifdef CONSOLE_ENABLE
# define SEND_TIMEOUT 5
@ -597,13 +596,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);


+ 0
- 1
tmk_core/protocol/vusb/protocol.c View File

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


+ 1
- 1
tmk_core/protocol/vusb/vusb.c View File

@ -176,7 +176,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;
}


Loading…
Cancel
Save