define debug_printf variant as well

master
Stefan Dorn 2016-06-14 00:29:08 +01:00
parent 8748e15b59
commit 5a651b2854
3 changed files with 29 additions and 14 deletions

View File

@ -1226,7 +1226,7 @@ int8_t usb_extra_consumer_send() {
#ifdef KBD_DEBUG
// transmit a character. 0 returned on success, -1 on error
int8_t usb_debug_putchar(uint8_t c) {
int8_t usb_debug_putchar(char c) {
static uint8_t previous_timeout = 0;
uint8_t timeout, intr_state;
@ -1297,13 +1297,25 @@ void usb_debug_flush_output(void) {
SREG = intr_state;
}
void debug_print_ptr(const char *s) {
void usb_debug_print(const char *s) {
char c;
while ((c = pgm_read_byte(c))) {
usb_debug_putchar(c);
}
usb_debug_flush_output();
}
while (1) {
c = pgm_read_byte(s++);
if (!c) { break; }
if (c == '\n') { usb_debug_putchar('\r'); }
void usb_debug_printf(const char *fmt, ...) {
char buf[128];
va_list args;
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
for (int i = 0; i < sizeof(buf); i++) {
char c = buf[i];
if (!c) break;
usb_debug_putchar(c);
}
usb_debug_flush_output();
@ -1311,7 +1323,9 @@ void debug_print_ptr(const char *s) {
#endif
#ifdef KBD_DEBUG
#define debug_print(s) debug_print_ptr(PSTR(s))
#define debug_print(s) usb_debug_print(PSTR(s))
#define debug_printf(args...) usb_debug_printf(args)
#else
#define debug_print(s)
#define debug_printf(...)
#endif

View File

@ -10,8 +10,10 @@
#define USB_DEBUG_HID
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
@ -205,9 +207,8 @@ extern uint16_t consumer_key;
extern volatile uint8_t debug_flush_timer;
// this macro allows you to write print("some text") and
// the string is automatically placed into flash memory :)
void debug_print_ptr(const char *s);
void usb_debug_print(const char *s);
void usb_debug_printf(const char *fmt, ...);
int8_t usb_debug_putchar(uint8_t c); // transmit a character
int8_t usb_debug_putchar(char c); // transmit a character
void usb_debug_flush_output(void); // immediately transmit any buffered output

View File

@ -197,7 +197,7 @@ void layer_disable(uint8_t layer) {
layers_active[layer] = false;
if (layers_sticky[layer] != StickyNone) {
debug_print("sticky up!\n");
debug_printf("sticky %d up!\n", layer);
}
layers_sticky[layer] = StickyNone;
@ -486,7 +486,7 @@ void kbfun_layer_sticky() {
layer_disable_top();
}
layer_enable(layer, StickyOnceDown);
debug_print("sticky down!\n");
debug_printf("sticky %d down!\n", layer);
// this should be the only place we care about this flag being cleared
non_trans_key_pressed = false;
@ -501,7 +501,7 @@ void kbfun_layer_sticky() {
// was pressed, push the layer again, but in the
// StickyOnceUp state
layer_enable(layer, StickyOnceUp);
debug_print("sticky still down!\n");
debug_printf("sticky %d still down!\n", layer);
}
}
}