From 04fe78ee0a7fe9baed39f021799a3dbb24ebeb36 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 16 Jun 2014 15:38:39 +0900 Subject: [PATCH] Fix print and timer --- common/avr/timer_avr.h | 42 ++++++++++++++++++++++++++++++++++ common/{ => avr}/xprintf.S | 0 common/{ => avr}/xprintf.h | 0 common/debug.h | 4 ++-- common/debug_config.h | 9 ++++---- common/mbed/timer.c | 1 + common/nodebug.h | 2 -- common/print.h | 16 ++++++------- keyboard/mbed_onekey/common.mk | 3 ++- 9 files changed, 60 insertions(+), 17 deletions(-) create mode 100644 common/avr/timer_avr.h rename common/{ => avr}/xprintf.S (100%) rename common/{ => avr}/xprintf.h (100%) diff --git a/common/avr/timer_avr.h b/common/avr/timer_avr.h new file mode 100644 index 0000000..0e85eb1 --- /dev/null +++ b/common/avr/timer_avr.h @@ -0,0 +1,42 @@ +/* +Copyright 2011 Jun Wako + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifndef TIMER_AVR_H +#define TIMER_AVR_H 1 + +#include + +#ifndef TIMER_PRESCALER +# if F_CPU > 16000000 +# define TIMER_PRESCALER 256 +# elif F_CPU > 2000000 +# define TIMER_PRESCALER 64 +# elif F_CPU > 250000 +# define TIMER_PRESCALER 8 +# else +# define TIMER_PRESCALER 1 +# endif +#endif +#define TIMER_RAW_FREQ (F_CPU/TIMER_PRESCALER) +#define TIMER_RAW TCNT0 +#define TIMER_RAW_TOP (TIMER_RAW_FREQ/1000) + +#if (TIMER_RAW_TOP > 255) +# error "Timer0 can't count 1ms at this clock freq. Use larger prescaler." +#endif + +#endif diff --git a/common/xprintf.S b/common/avr/xprintf.S similarity index 100% rename from common/xprintf.S rename to common/avr/xprintf.S diff --git a/common/xprintf.h b/common/avr/xprintf.h similarity index 100% rename from common/xprintf.h rename to common/avr/xprintf.h diff --git a/common/debug.h b/common/debug.h index 399b2d0..8ca2569 100644 --- a/common/debug.h +++ b/common/debug.h @@ -25,13 +25,13 @@ along with this program. If not, see . #ifndef NO_DEBUG #define dprint(s) do { if (debug_enable) print(s); } while (0) -#define dprintln() do { if (debug_enable) print_crlf(); } while (0) +#define dprintln(s) do { if (debug_enable) println(s); } while (0) #define dprintf(fmt, ...) do { if (debug_enable) xprintf(fmt, ##__VA_ARGS__); } while (0) #define dmsg(s) dprintf("%s at %s: %S\n", __FILE__, __LINE__, PSTR(s)) /* DO NOT USE these anymore */ #define debug(s) do { if (debug_enable) print(s); } while (0) -#define debugln(s) do { if (debug_enable) print_crlf(); } while (0) +#define debugln(s) do { if (debug_enable) println(s); } while (0) #define debug_S(s) do { if (debug_enable) print_S(s); } while (0) #define debug_P(s) do { if (debug_enable) print_P(s); } while (0) #define debug_msg(s) do { \ diff --git a/common/debug_config.h b/common/debug_config.h index e00fd10..0e67ee4 100644 --- a/common/debug_config.h +++ b/common/debug_config.h @@ -38,14 +38,15 @@ typedef union { } debug_config_t; debug_config_t debug_config; +#ifdef __cplusplus +} +#endif + + /* for backward compatibility */ #define debug_enable (debug_config.enable) #define debug_matrix (debug_config.matrix) #define debug_keyboard (debug_config.keyboard) #define debug_mouse (debug_config.mouse) -#ifdef __cplusplus -} -#endif - #endif diff --git a/common/mbed/timer.c b/common/mbed/timer.c index a64a772..c357ceb 100644 --- a/common/mbed/timer.c +++ b/common/mbed/timer.c @@ -11,6 +11,7 @@ void SysTick_Handler(void) { void timer_init(void) { + timer_count = 0; SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */ } diff --git a/common/nodebug.h b/common/nodebug.h index aec790b..8ef123f 100644 --- a/common/nodebug.h +++ b/common/nodebug.h @@ -18,8 +18,6 @@ along with this program. If not, see . #ifndef NODEBUG_H #define NODEBUG_H 1 -#include "debug_config.h" - #define dprint(s) #define dprintln(s) #define dprintf(fmt, ...) diff --git a/common/print.h b/common/print.h index 6a6771f..4001bcf 100644 --- a/common/print.h +++ b/common/print.h @@ -35,7 +35,7 @@ #ifndef NO_PRINT -#ifdef __AVR__ +#if defined(__AVR__) #include "xprintf.h" @@ -44,21 +44,21 @@ #ifndef __cplusplus #define print(s) xputs(PSTR(s)) #endif -#define println(s) xputs(PSTR(s "\n")) +#define println(s) xputs(PSTR(s "\r\n")) #ifdef __cplusplus -extern "C" { +extern "C" #endif /* function pointer of sendchar to be used by print utility */ void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); -#elif __arm__ +#elif defined(__arm__) + +#include "mbed/xprintf.h" -#include "mbed.h" -Serial ser(UART_TX, UART_RX); -#define xprintf ser.printf #define print(s) xprintf(s) -#define println(s) xprintf(s "\n") +#define println(s) xprintf(s "\r\n") + /* TODO: to select output destinations: UART/USBSerial */ #define print_set_sendchar(func) diff --git a/keyboard/mbed_onekey/common.mk b/keyboard/mbed_onekey/common.mk index 975ae9d..101a822 100644 --- a/keyboard/mbed_onekey/common.mk +++ b/keyboard/mbed_onekey/common.mk @@ -1,16 +1,17 @@ COMMON_DIR = common OBJECTS += \ $(OBJDIR)/$(COMMON_DIR)/mbed/timer.o \ + $(OBJDIR)/$(COMMON_DIR)/mbed/xprintf.o \ INCLUDE_PATHS += \ -I$(TMK_DIR)/$(COMMON_DIR) +# $(OBJDIR)/$(COMMON_DIR)/action.o \ # $(OBJDIR)/$(COMMON_DIR)/host.o \ # $(OBJDIR)/$(COMMON_DIR)/keyboard.o \ -# $(OBJDIR)/$(COMMON_DIR)/action.o \ # $(OBJDIR)/$(COMMON_DIR)/action_tapping.o \ # $(OBJDIR)/$(COMMON_DIR)/action_macro.o \ # $(OBJDIR)/$(COMMON_DIR)/action_layer.o \ -- 2.39.2