From c5060ea81942b0e3f8577536ff78402a19abe3d3 Mon Sep 17 00:00:00 2001 From: tmk Date: Sat, 25 Aug 2012 15:49:08 +0900 Subject: test build of 'Host shield' in minimal env. --- common/debug.h | 19 ++++++++++++++----- common/host.h | 8 ++++++++ common/keyboard.h | 6 ++++++ common/print.h | 13 +++++++++++-- common/sendchar.h | 8 ++++++++ common/timer.h | 12 ++++++++++-- 6 files changed, 57 insertions(+), 9 deletions(-) (limited to 'common') diff --git a/common/debug.h b/common/debug.h index 230d3b3499..9cc8d882f3 100644 --- a/common/debug.h +++ b/common/debug.h @@ -18,19 +18,28 @@ along with this program. If not, see . #ifndef DEBUG_H #define DEBUG_H 1 +#include #include "print.h" -#define debug(s) if(debug_enable) print(s) +#define debug(s) if(debug_enable) print_P(PSTR(s)) #define debug_hex(c) if(debug_enable) phex(c) #define debug_hex16(i) if(debug_enable) phex16(i) #define debug_bin(c) if(debug_enable) pbin(c) #define debug_bin_reverse(c) if(debug_enable) pbin_reverse(c) -bool debug_enable; -bool debug_matrix; -bool debug_keyboard; -bool debug_mouse; +#ifdef __cplusplus +extern "C" { +#endif + +extern bool debug_enable; +extern bool debug_matrix; +extern bool debug_keyboard; +extern bool debug_mouse; + +#ifdef __cplusplus +} +#endif #endif diff --git a/common/host.h b/common/host.h index 11b9aacd7c..26bf3c362f 100644 --- a/common/host.h +++ b/common/host.h @@ -23,6 +23,10 @@ along with this program. If not, see . #include "host_driver.h" +#ifdef __cplusplus +extern "C" { +#endif + #ifdef NKRO_ENABLE extern bool keyboard_nkro; #endif @@ -54,4 +58,8 @@ void host_mouse_send(report_mouse_t *report); void host_system_send(uint16_t data); void host_consumer_send(uint16_t data); +#ifdef __cplusplus +} +#endif + #endif diff --git a/common/keyboard.h b/common/keyboard.h index 988dac36ed..51bf67379a 100644 --- a/common/keyboard.h +++ b/common/keyboard.h @@ -21,8 +21,14 @@ along with this program. If not, see . #include +#ifdef __cplusplus +extern "C" { +#endif void keyboard_init(void); void keyboard_proc(void); void keyboard_set_leds(uint8_t leds); +#ifdef __cplusplus +} +#endif #endif diff --git a/common/print.h b/common/print.h index 686fa89acc..d55f5695dc 100644 --- a/common/print.h +++ b/common/print.h @@ -29,11 +29,17 @@ #include -extern bool print_enable; - +// avoid collision with arduino/Print.h +#ifndef __cplusplus // this macro allows you to write print("some text") and // the string is automatically placed into flash memory :) #define print(s) print_P(PSTR(s)) +#endif + +#ifdef __cplusplus +extern "C" { +#endif +extern bool print_enable; void print_S(const char *s); void print_P(const char *s); @@ -41,5 +47,8 @@ void phex(unsigned char c); void phex16(unsigned int i); void pbin(unsigned char c); void pbin_reverse(unsigned char c); +#ifdef __cplusplus +} +#endif #endif diff --git a/common/sendchar.h b/common/sendchar.h index 7c81303c7a..7a64d00c7f 100644 --- a/common/sendchar.h +++ b/common/sendchar.h @@ -21,7 +21,15 @@ along with this program. If not, see . #include +#ifdef __cplusplus +extern "C" { +#endif + /* transmit a character. return 0 on success, -1 on error. */ int8_t sendchar(uint8_t c); +#ifdef __cplusplus +} +#endif + #endif diff --git a/common/timer.h b/common/timer.h index f9e8181e6f..d24d3eab62 100644 --- a/common/timer.h +++ b/common/timer.h @@ -23,10 +23,12 @@ along with this program. If not, see . #ifndef TIMER_PRESCALER # if F_CPU > 16000000 # define TIMER_PRESCALER 256 -# elif F_CPU >= 4000000 +# elif F_CPU > 2000000 # define TIMER_PRESCALER 64 -# else +# elif F_CPU > 250000 # define TIMER_PRESCALER 8 +# else +# define TIMER_PRESCALER 1 # endif #endif #define TIMER_RAW_FREQ (F_CPU/TIMER_PRESCALER) @@ -42,6 +44,9 @@ along with this program. If not, see . #define TIMER_DIFF_MS(a, b) TIMER_DIFF(a, b, UINT16_MAX) +#ifdef __cplusplus +extern "C" { +#endif extern volatile uint16_t timer_count; @@ -49,5 +54,8 @@ void timer_init(void); void timer_clear(void); uint16_t timer_read(void); uint16_t timer_elapsed(uint16_t last); +#ifdef __cplusplus +} +#endif #endif -- cgit v1.2.3 From e7c030375ac76907206db7f09cf9208b0c7c6e66 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 27 Aug 2012 15:18:01 +0900 Subject: Add USB to USB converter. unmature. --- common/report.h | 9 +++++++++ common/usb_keycodes.h | 1 + 2 files changed, 10 insertions(+) (limited to 'common') diff --git a/common/report.h b/common/report.h index 45f5c0b881..a73e0aba18 100644 --- a/common/report.h +++ b/common/report.h @@ -78,6 +78,11 @@ along with this program. If not, see . # define REPORT_KEYS 6 #endif + +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { uint8_t mods; uint8_t rserved; @@ -92,4 +97,8 @@ typedef struct { int8_t h; } __attribute__ ((packed)) report_mouse_t; +#ifdef __cplusplus +} +#endif + #endif diff --git a/common/usb_keycodes.h b/common/usb_keycodes.h index 9b6cce1532..04b398fa2a 100644 --- a/common/usb_keycodes.h +++ b/common/usb_keycodes.h @@ -24,6 +24,7 @@ along with this program. If not, see . #define IS_ERROR(code) (KB_ROLL_OVER <= (code) && (code) <= KB_UNDEFINED) +#define IS_ANY(code) (KB_A <= (code)) #define IS_KEY(code) (KB_A <= (code) && (code) <= KB_EXSEL) #define IS_MOD(code) (KB_LCTRL <= (code) && (code) <= KB_RGUI) #define IS_FN(code) (KB_FN0 <= (code) && (code) <= KB_FN7) -- cgit v1.2.3 From c77c5043a121f195b3a552feb8283424a0652ce2 Mon Sep 17 00:00:00 2001 From: tmk Date: Sun, 2 Sep 2012 23:47:18 +0900 Subject: usb_hid: Fix timer size uint16_t to uint32_t; --- common/debug.c | 9 +++++++++ common/timer.c | 34 ++++++++++++++++++++++++++++++---- common/timer.h | 9 ++++++--- 3 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 common/debug.c (limited to 'common') diff --git a/common/debug.c b/common/debug.c new file mode 100644 index 0000000000..41d566ee3a --- /dev/null +++ b/common/debug.c @@ -0,0 +1,9 @@ +#include +#include "debug.h" + + +bool debug_enable = false; +bool debug_matrix = false; +bool debug_keyboard = false; +bool debug_mouse = false; + diff --git a/common/timer.c b/common/timer.c index 48a38c9b68..8b8d37e8b3 100644 --- a/common/timer.c +++ b/common/timer.c @@ -22,7 +22,7 @@ along with this program. If not, see . // counter resolution 1ms -volatile uint16_t timer_count = 0; +volatile uint32_t timer_count = 0; void timer_init(void) { @@ -59,7 +59,20 @@ void timer_clear(void) inline uint16_t timer_read(void) { - uint16_t t; + uint32_t t; + + uint8_t sreg = SREG; + cli(); + t = timer_count; + SREG = sreg; + + return (t & 0xFFFF); +} + +inline +uint32_t timer_read32(void) +{ + uint32_t t; uint8_t sreg = SREG; cli(); @@ -72,14 +85,27 @@ uint16_t timer_read(void) inline uint16_t timer_elapsed(uint16_t last) { - uint16_t t; + uint32_t t; + + uint8_t sreg = SREG; + cli(); + t = timer_count; + SREG = sreg; + + return TIMER_DIFF_16((t & 0xFFFF), last); +} + +inline +uint32_t timer_elapsed32(uint32_t last) +{ + uint32_t t; uint8_t sreg = SREG; cli(); t = timer_count; SREG = sreg; - return TIMER_DIFF_MS(t, last); + return TIMER_DIFF_32(t, last); } // excecuted once per 1ms.(excess for just timer count?) diff --git a/common/timer.h b/common/timer.h index d24d3eab62..70b008e6c9 100644 --- a/common/timer.h +++ b/common/timer.h @@ -40,20 +40,23 @@ along with this program. If not, see . #endif #define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a)) -#define TIMER_DIFF_RAW(a, b) TIMER_DIFF(a, b, UINT8_MAX) -#define TIMER_DIFF_MS(a, b) TIMER_DIFF(a, b, UINT16_MAX) +#define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX) +#define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX) +#define TIMER_DIFF_32(a, b) TIMER_DIFF(a, b, UINT32_MAX) #ifdef __cplusplus extern "C" { #endif -extern volatile uint16_t timer_count; +extern volatile uint32_t timer_count; void timer_init(void); void timer_clear(void); uint16_t timer_read(void); +uint32_t timer_read32(void); uint16_t timer_elapsed(uint16_t last); +uint32_t timer_elapsed32(uint32_t last); #ifdef __cplusplus } #endif -- cgit v1.2.3 From 232ab308e358e41f3253d66fa009c1ebca0951a2 Mon Sep 17 00:00:00 2001 From: tmk Date: Tue, 4 Sep 2012 13:29:21 +0900 Subject: usb_hid: workaround for compile on Windows. --- common/timer.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'common') diff --git a/common/timer.h b/common/timer.h index 70b008e6c9..6437473ff7 100644 --- a/common/timer.h +++ b/common/timer.h @@ -43,11 +43,13 @@ along with this program. If not, see . #define TIMER_DIFF_8(a, b) TIMER_DIFF(a, b, UINT8_MAX) #define TIMER_DIFF_16(a, b) TIMER_DIFF(a, b, UINT16_MAX) #define TIMER_DIFF_32(a, b) TIMER_DIFF(a, b, UINT32_MAX) +#define TIMER_DIFF_RAW(a, b) TIMER_DIFF_8(a, b) #ifdef __cplusplus extern "C" { #endif + extern volatile uint32_t timer_count; @@ -57,6 +59,7 @@ uint16_t timer_read(void); uint32_t timer_read32(void); uint16_t timer_elapsed(uint16_t last); uint32_t timer_elapsed32(uint32_t last); + #ifdef __cplusplus } #endif -- cgit v1.2.3