/* | |||||
Copyright 2011 Jun Wako <[email protected]> | |||||
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 <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef TIMER_AVR_H | |||||
#define TIMER_AVR_H 1 | |||||
#include <stdint.h> | |||||
#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 |
#ifndef NO_DEBUG | #ifndef NO_DEBUG | ||||
#define dprint(s) do { if (debug_enable) print(s); } while (0) | #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 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)) | #define dmsg(s) dprintf("%s at %s: %S\n", __FILE__, __LINE__, PSTR(s)) | ||||
/* DO NOT USE these anymore */ | /* DO NOT USE these anymore */ | ||||
#define debug(s) do { if (debug_enable) print(s); } while (0) | #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_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_P(s) do { if (debug_enable) print_P(s); } while (0) | ||||
#define debug_msg(s) do { \ | #define debug_msg(s) do { \ |
} debug_config_t; | } debug_config_t; | ||||
debug_config_t debug_config; | debug_config_t debug_config; | ||||
#ifdef __cplusplus | |||||
} | |||||
#endif | |||||
/* for backward compatibility */ | /* for backward compatibility */ | ||||
#define debug_enable (debug_config.enable) | #define debug_enable (debug_config.enable) | ||||
#define debug_matrix (debug_config.matrix) | #define debug_matrix (debug_config.matrix) | ||||
#define debug_keyboard (debug_config.keyboard) | #define debug_keyboard (debug_config.keyboard) | ||||
#define debug_mouse (debug_config.mouse) | #define debug_mouse (debug_config.mouse) | ||||
#ifdef __cplusplus | |||||
} | |||||
#endif | |||||
#endif | #endif |
void timer_init(void) | void timer_init(void) | ||||
{ | { | ||||
timer_count = 0; | |||||
SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */ | SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */ | ||||
} | } | ||||
#ifndef NODEBUG_H | #ifndef NODEBUG_H | ||||
#define NODEBUG_H 1 | #define NODEBUG_H 1 | ||||
#include "debug_config.h" | |||||
#define dprint(s) | #define dprint(s) | ||||
#define dprintln(s) | #define dprintln(s) | ||||
#define dprintf(fmt, ...) | #define dprintf(fmt, ...) |
#ifndef NO_PRINT | #ifndef NO_PRINT | ||||
#ifdef __AVR__ | |||||
#if defined(__AVR__) | |||||
#include "xprintf.h" | #include "xprintf.h" | ||||
#ifndef __cplusplus | #ifndef __cplusplus | ||||
#define print(s) xputs(PSTR(s)) | #define print(s) xputs(PSTR(s)) | ||||
#endif | #endif | ||||
#define println(s) xputs(PSTR(s "\n")) | |||||
#define println(s) xputs(PSTR(s "\r\n")) | |||||
#ifdef __cplusplus | #ifdef __cplusplus | ||||
extern "C" { | |||||
extern "C" | |||||
#endif | #endif | ||||
/* function pointer of sendchar to be used by print utility */ | /* function pointer of sendchar to be used by print utility */ | ||||
void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); | 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 print(s) xprintf(s) | ||||
#define println(s) xprintf(s "\n") | |||||
#define println(s) xprintf(s "\r\n") | |||||
/* TODO: to select output destinations: UART/USBSerial */ | /* TODO: to select output destinations: UART/USBSerial */ | ||||
#define print_set_sendchar(func) | #define print_set_sendchar(func) | ||||
COMMON_DIR = common | COMMON_DIR = common | ||||
OBJECTS += \ | OBJECTS += \ | ||||
$(OBJDIR)/$(COMMON_DIR)/mbed/timer.o \ | $(OBJDIR)/$(COMMON_DIR)/mbed/timer.o \ | ||||
$(OBJDIR)/$(COMMON_DIR)/mbed/xprintf.o \ | |||||
INCLUDE_PATHS += \ | INCLUDE_PATHS += \ | ||||
-I$(TMK_DIR)/$(COMMON_DIR) | -I$(TMK_DIR)/$(COMMON_DIR) | ||||
# $(OBJDIR)/$(COMMON_DIR)/action.o \ | |||||
# $(OBJDIR)/$(COMMON_DIR)/host.o \ | # $(OBJDIR)/$(COMMON_DIR)/host.o \ | ||||
# $(OBJDIR)/$(COMMON_DIR)/keyboard.o \ | # $(OBJDIR)/$(COMMON_DIR)/keyboard.o \ | ||||
# $(OBJDIR)/$(COMMON_DIR)/action.o \ | |||||
# $(OBJDIR)/$(COMMON_DIR)/action_tapping.o \ | # $(OBJDIR)/$(COMMON_DIR)/action_tapping.o \ | ||||
# $(OBJDIR)/$(COMMON_DIR)/action_macro.o \ | # $(OBJDIR)/$(COMMON_DIR)/action_macro.o \ | ||||
# $(OBJDIR)/$(COMMON_DIR)/action_layer.o \ | # $(OBJDIR)/$(COMMON_DIR)/action_layer.o \ |