From 867f115bee190515aa195dc3e58f1c381ea9695b Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 16 Jun 2014 11:12:45 +0900 Subject: Port timer to mbed --- common.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common.mk') diff --git a/common.mk b/common.mk index 62ac0ff78..9d58fa214 100644 --- a/common.mk +++ b/common.mk @@ -7,7 +7,7 @@ SRC += $(COMMON_DIR)/host.c \ $(COMMON_DIR)/action_layer.c \ $(COMMON_DIR)/action_util.c \ $(COMMON_DIR)/keymap.c \ - $(COMMON_DIR)/timer.c \ + $(COMMON_DIR)/avr/timer.c \ $(COMMON_DIR)/print.c \ $(COMMON_DIR)/bootloader.c \ $(COMMON_DIR)/suspend.c \ -- cgit v1.2.3 From c67ae2a6b546c822759352586c14cd9dccbbe0ff Mon Sep 17 00:00:00 2001 From: tmk Date: Tue, 17 Jun 2014 00:57:59 +0900 Subject: Port action_* to mbed --- common.mk | 2 +- common/action.c | 2 +- common/action.h | 13 ++++++++++--- common/action_layer.c | 2 +- common/action_layer.h | 2 +- common/action_macro.c | 8 ++++---- common/action_macro.h | 8 ++++---- common/action_util.c | 20 ++++++++++---------- common/action_util.h | 9 +++++++++ common/bootmagic.c | 2 +- common/host.c | 4 ++-- common/keyboard.c | 2 +- common/keyboard.h | 8 ++++---- common/keymap.c | 4 ++-- common/keymap.h | 2 +- common/print.h | 2 +- common/report.h | 22 +++++++++++----------- common/wait.h | 20 ++++++++++++++++++++ keyboard/mbed_onekey/HIDKeyboard.h | 11 +---------- keyboard/mbed_onekey/Makefile | 1 + keyboard/mbed_onekey/common.mk | 12 ++++++------ 21 files changed, 92 insertions(+), 64 deletions(-) create mode 100644 common/wait.h (limited to 'common.mk') diff --git a/common.mk b/common.mk index 9d58fa214..9b5ef0ea8 100644 --- a/common.mk +++ b/common.mk @@ -11,7 +11,7 @@ SRC += $(COMMON_DIR)/host.c \ $(COMMON_DIR)/print.c \ $(COMMON_DIR)/bootloader.c \ $(COMMON_DIR)/suspend.c \ - $(COMMON_DIR)/xprintf.S \ + $(COMMON_DIR)/avr/xprintf.S \ $(COMMON_DIR)/util.c diff --git a/common/action.c b/common/action.c index fddb97c50..94498fe6c 100644 --- a/common/action.c +++ b/common/action.c @@ -499,7 +499,7 @@ void clear_keyboard_but_mods(void) #endif } -bool is_tap_key(key_t key) +bool is_tap_key(keypos_t key) { action_t action = layer_switch_get_action(key); diff --git a/common/action.h b/common/action.h index 077711c23..8a4736d7b 100644 --- a/common/action.h +++ b/common/action.h @@ -25,6 +25,10 @@ along with this program. If not, see . #include "action_macro.h" +#ifdef __cplusplus +extern "C" { +#endif + /* tapping count and state */ typedef struct { bool interrupted :1; @@ -42,12 +46,11 @@ typedef struct { #endif } keyrecord_t; - /* Execute action per keyevent */ void action_exec(keyevent_t event); /* action for key */ -action_t action_for_key(uint8_t layer, key_t key); +action_t action_for_key(uint8_t layer, keypos_t key); /* macro */ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt); @@ -65,11 +68,15 @@ void unregister_mods(uint8_t mods); void clear_keyboard(void); void clear_keyboard_but_mods(void); void layer_switch(uint8_t new_layer); -bool is_tap_key(key_t key); +bool is_tap_key(keypos_t key); /* debug */ void debug_event(keyevent_t event); void debug_record(keyrecord_t record); void debug_action(action_t action); +#ifdef __cplusplus +} +#endif + #endif /* ACTION_H */ diff --git a/common/action_layer.c b/common/action_layer.c index 526e24d53..c535615f4 100644 --- a/common/action_layer.c +++ b/common/action_layer.c @@ -112,7 +112,7 @@ void layer_debug(void) -action_t layer_switch_get_action(key_t key) +action_t layer_switch_get_action(keypos_t key) { action_t action; action.code = ACTION_TRANSPARENT; diff --git a/common/action_layer.h b/common/action_layer.h index 034e00027..b6da353cf 100644 --- a/common/action_layer.h +++ b/common/action_layer.h @@ -72,6 +72,6 @@ void layer_xor(uint32_t state); /* return action depending on current layer status */ -action_t layer_switch_get_action(key_t key); +action_t layer_switch_get_action(keypos_t key); #endif diff --git a/common/action_macro.c b/common/action_macro.c index d85aee379..ba93fc8b2 100644 --- a/common/action_macro.c +++ b/common/action_macro.c @@ -14,10 +14,10 @@ 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 . */ -#include #include "action.h" #include "action_util.h" #include "action_macro.h" +#include "wait.h" #ifdef DEBUG_ACTION #include "debug.h" @@ -28,7 +28,7 @@ along with this program. If not, see . #ifndef NO_ACTION_MACRO -#define MACRO_READ() (macro = pgm_read_byte(macro_p++)) +#define MACRO_READ() (macro = MACRO_GET(macro_p++)) void action_macro_play(const macro_t *macro_p) { macro_t macro = END; @@ -58,7 +58,7 @@ void action_macro_play(const macro_t *macro_p) case WAIT: MACRO_READ(); dprintf("WAIT(%u)\n", macro); - { uint8_t ms = macro; while (ms--) _delay_ms(1); } + { uint8_t ms = macro; while (ms--) wait_ms(1); } break; case INTERVAL: interval = MACRO_READ(); @@ -77,7 +77,7 @@ void action_macro_play(const macro_t *macro_p) return; } // interval - { uint8_t ms = interval; while (ms--) _delay_ms(1); } + { uint8_t ms = interval; while (ms--) wait_ms(1); } } } #endif diff --git a/common/action_macro.h b/common/action_macro.h index 621826308..aedc32ec6 100644 --- a/common/action_macro.h +++ b/common/action_macro.h @@ -17,12 +17,12 @@ along with this program. If not, see . #ifndef ACTION_MACRO_H #define ACTION_MACRO_H #include -#include +#include "progmem.h" -#define MACRO_NONE 0 -#define MACRO(...) ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; }) - +#define MACRO_NONE 0 +#define MACRO(...) ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; }) +#define MACRO_GET(p) pgm_read_byte(p) typedef uint8_t macro_t; diff --git a/common/action_util.c b/common/action_util.c index 5f44b3812..dbee630d1 100644 --- a/common/action_util.c +++ b/common/action_util.c @@ -31,8 +31,8 @@ static uint8_t real_mods = 0; static uint8_t weak_mods = 0; #ifdef USB_6KRO_ENABLE -#define RO_ADD(a, b) ((a + b) % REPORT_KEYS) -#define RO_SUB(a, b) ((a - b + REPORT_KEYS) % REPORT_KEYS) +#define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS) +#define RO_SUB(a, b) ((a - b + KEYBOARD_REPORT_KEYS) % KEYBOARD_REPORT_KEYS) #define RO_INC(a) RO_ADD(a, 1) #define RO_DEC(a) RO_SUB(a, 1) static int8_t cb_head = 0; @@ -98,7 +98,7 @@ void del_key(uint8_t key) void clear_keys(void) { // not clear mods - for (int8_t i = 1; i < REPORT_SIZE; i++) { + for (int8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) { keyboard_report->raw[i] = 0; } } @@ -145,7 +145,7 @@ void clear_oneshot_mods(void) uint8_t has_anykey(void) { uint8_t cnt = 0; - for (uint8_t i = 1; i < REPORT_SIZE; i++) { + for (uint8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) { if (keyboard_report->raw[i]) cnt++; } @@ -162,7 +162,7 @@ uint8_t get_first_key(void) #ifdef NKRO_ENABLE if (keyboard_nkro) { uint8_t i = 0; - for (; i < REPORT_BITS && !keyboard_report->nkro.bits[i]; i++) + for (; i < KEYBOARD_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++) ; return i<<3 | biton(keyboard_report->nkro.bits[i]); } @@ -234,7 +234,7 @@ static inline void add_key_byte(uint8_t code) #else int8_t i = 0; int8_t empty = -1; - for (; i < REPORT_KEYS; i++) { + for (; i < KEYBOARD_REPORT_KEYS; i++) { if (keyboard_report->keys[i] == code) { break; } @@ -242,7 +242,7 @@ static inline void add_key_byte(uint8_t code) empty = i; } } - if (i == REPORT_KEYS) { + if (i == KEYBOARD_REPORT_KEYS) { if (empty != -1) { keyboard_report->keys[empty] = code; } @@ -278,7 +278,7 @@ static inline void del_key_byte(uint8_t code) } while (i != cb_tail); } #else - for (uint8_t i = 0; i < REPORT_KEYS; i++) { + for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) { if (keyboard_report->keys[i] == code) { keyboard_report->keys[i] = 0; } @@ -289,7 +289,7 @@ static inline void del_key_byte(uint8_t code) #ifdef NKRO_ENABLE static inline void add_key_bit(uint8_t code) { - if ((code>>3) < REPORT_BITS) { + if ((code>>3) < KEYBOARD_REPORT_BITS) { keyboard_report->nkro.bits[code>>3] |= 1<<(code&7); } else { dprintf("add_key_bit: can't add: %02X\n", code); @@ -298,7 +298,7 @@ static inline void add_key_bit(uint8_t code) static inline void del_key_bit(uint8_t code) { - if ((code>>3) < REPORT_BITS) { + if ((code>>3) < KEYBOARD_REPORT_BITS) { keyboard_report->nkro.bits[code>>3] &= ~(1<<(code&7)); } else { dprintf("del_key_bit: can't del: %02X\n", code); diff --git a/common/action_util.h b/common/action_util.h index f9d3161a8..a955638b4 100644 --- a/common/action_util.h +++ b/common/action_util.h @@ -20,6 +20,10 @@ along with this program. If not, see . #include #include "report.h" +#ifdef __cplusplus +extern "C" { +#endif + extern report_keyboard_t *keyboard_report; void send_keyboard_report(void); @@ -54,4 +58,9 @@ void oneshot_disable(void); uint8_t has_anykey(void); uint8_t has_anymod(void); uint8_t get_first_key(void); + +#ifdef __cplusplus +} +#endif + #endif diff --git a/common/bootmagic.c b/common/bootmagic.c index 642d5face..b002a5856 100644 --- a/common/bootmagic.c +++ b/common/bootmagic.c @@ -111,7 +111,7 @@ static bool scan_keycode(uint8_t keycode) matrix_row_t matrix_row = matrix_get_row(r); for (uint8_t c = 0; c < MATRIX_COLS; c++) { if (matrix_row & ((matrix_row_t)1<. */ #include -#include +//#include #include "keycode.h" #include "host.h" #include "util.h" @@ -55,7 +55,7 @@ void host_keyboard_send(report_keyboard_t *report) if (debug_keyboard) { dprint("keyboard_report: "); - for (uint8_t i = 0; i < REPORT_SIZE; i++) { + for (uint8_t i = 0; i < KEYBOARD_REPORT_SIZE; i++) { dprintf("%02X ", report->raw[i]); } dprint("\n"); diff --git a/common/keyboard.c b/common/keyboard.c index 2b66f20a0..b71d5bf13 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -100,7 +100,7 @@ void keyboard_task(void) for (uint8_t c = 0; c < MATRIX_COLS; c++) { if (matrix_change & ((matrix_row_t)1<. /* key report size(NKRO or boot mode) */ #if defined(PROTOCOL_PJRC) && defined(NKRO_ENABLE) # include "usb.h" -# define REPORT_SIZE KBD2_SIZE -# define REPORT_KEYS (KBD2_SIZE - 2) -# define REPORT_BITS (KBD2_SIZE - 1) +# define KEYBOARD_REPORT_SIZE KBD2_SIZE +# define KEYBOARD_REPORT_KEYS (KBD2_SIZE - 2) +# define KEYBOARD_REPORT_BITS (KBD2_SIZE - 1) #elif defined(PROTOCOL_LUFA) && defined(NKRO_ENABLE) # include "protocol/lufa/descriptor.h" -# define REPORT_SIZE NKRO_EPSIZE -# define REPORT_KEYS (NKRO_EPSIZE - 2) -# define REPORT_BITS (NKRO_EPSIZE - 1) +# define KEYBOARD_REPORT_SIZE NKRO_EPSIZE +# define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2) +# define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1) #else -# define REPORT_SIZE 8 -# define REPORT_KEYS 6 +# define KEYBOARD_REPORT_SIZE 8 +# define KEYBOARD_REPORT_KEYS 6 #endif @@ -115,16 +115,16 @@ extern "C" { * */ typedef union { - uint8_t raw[REPORT_SIZE]; + uint8_t raw[KEYBOARD_REPORT_SIZE]; struct { uint8_t mods; uint8_t reserved; - uint8_t keys[REPORT_KEYS]; + uint8_t keys[KEYBOARD_REPORT_KEYS]; }; #ifdef NKRO_ENABLE struct { uint8_t mods; - uint8_t bits[REPORT_BITS]; + uint8_t bits[KEYBOARD_REPORT_BITS]; } nkro; #endif } __attribute__ ((packed)) report_keyboard_t; diff --git a/common/wait.h b/common/wait.h new file mode 100644 index 000000000..40d00b0c7 --- /dev/null +++ b/common/wait.h @@ -0,0 +1,20 @@ +#ifndef WAIT_H +#define WAIT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(__AVR__) +# include +# define wait_ms(ms) _delay_ms(ms) +# define wait_us(us) _delay_us(us) +#elif defined(__arm__) +# include "wait_api.h" +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/keyboard/mbed_onekey/HIDKeyboard.h b/keyboard/mbed_onekey/HIDKeyboard.h index b00c97b9b..4ebe610a6 100644 --- a/keyboard/mbed_onekey/HIDKeyboard.h +++ b/keyboard/mbed_onekey/HIDKeyboard.h @@ -3,16 +3,7 @@ #include "stdint.h" #include "stdbool.h" #include "USBHID.h" - - -typedef union { - uint8_t raw[8]; - struct { - uint8_t mods; - uint8_t reserved; - uint8_t keys[6]; - }; -} __attribute__ ((packed)) report_keyboard_t; +#include "report.h" class HIDKeyboard : public USBDevice { diff --git a/keyboard/mbed_onekey/Makefile b/keyboard/mbed_onekey/Makefile index e194052c1..1bc91bc7e 100644 --- a/keyboard/mbed_onekey/Makefile +++ b/keyboard/mbed_onekey/Makefile @@ -15,6 +15,7 @@ OBJDIR = ./build OBJECTS = \ $(OBJDIR)/./HIDKeyboard.o \ + $(OBJDIR)/./mbed_driver.o \ $(OBJDIR)/./main.o SYS_OBJECTS = diff --git a/keyboard/mbed_onekey/common.mk b/keyboard/mbed_onekey/common.mk index 101a82205..6eb7f7699 100644 --- a/keyboard/mbed_onekey/common.mk +++ b/keyboard/mbed_onekey/common.mk @@ -2,20 +2,20 @@ COMMON_DIR = common OBJECTS += \ $(OBJDIR)/$(COMMON_DIR)/mbed/timer.o \ $(OBJDIR)/$(COMMON_DIR)/mbed/xprintf.o \ + $(OBJDIR)/$(COMMON_DIR)/action.o \ + $(OBJDIR)/$(COMMON_DIR)/action_tapping.o \ + $(OBJDIR)/$(COMMON_DIR)/action_macro.o \ + $(OBJDIR)/$(COMMON_DIR)/action_layer.o \ + $(OBJDIR)/$(COMMON_DIR)/action_util.o \ + $(OBJDIR)/$(COMMON_DIR)/host.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_tapping.o \ -# $(OBJDIR)/$(COMMON_DIR)/action_macro.o \ -# $(OBJDIR)/$(COMMON_DIR)/action_layer.o \ -# $(OBJDIR)/$(COMMON_DIR)/action_util.o \ # $(OBJDIR)/$(COMMON_DIR)/keymap.o \ # $(OBJDIR)/$(COMMON_DIR)/bootloader.o \ # $(OBJDIR)/$(COMMON_DIR)/suspend.o \ -- cgit v1.2.3 From e81c70149ecf73256f8bb7d77cefc07f2b91d2be Mon Sep 17 00:00:00 2001 From: tmk Date: Tue, 17 Jun 2014 22:41:14 +0900 Subject: Fix common files for mbed --- common.mk | 10 +-- common/avr/bootloader.c | 148 +++++++++++++++++++++++++++++++++++ common/avr/eeconfig.c | 45 +++++++++++ common/avr/suspend.c | 98 +++++++++++++++++++++++ common/avr/suspend_avr.h | 27 +++++++ common/bootloader.c | 148 ----------------------------------- common/eeconfig.c | 45 ----------- common/host.h | 4 +- common/keyboard.c | 1 - common/keymap.c | 1 - common/mbed/bootloader.c | 4 + common/mbed/suspend.c | 6 ++ common/mbed/xprintf.cpp | 46 +++++++++++ common/mbed/xprintf.h | 17 ++++ common/mousekey.c | 1 - common/mousekey.h | 20 +++-- common/progmem.h | 11 +++ common/suspend.c | 76 ------------------ common/suspend.h | 20 ----- keyboard/mbed_onekey/Makefile | 8 ++ keyboard/mbed_onekey/common.mk | 70 +++++++++++++++-- keyboard/mbed_onekey/config.h | 7 ++ keyboard/mbed_onekey/gcc.mk | 3 +- keyboard/mbed_onekey/main.cpp | 109 ++++++++++---------------- keyboard/mbed_onekey/mbed_driver.cpp | 41 ++++++++++ keyboard/mbed_onekey/mbed_driver.h | 3 + 26 files changed, 591 insertions(+), 378 deletions(-) create mode 100644 common/avr/bootloader.c create mode 100644 common/avr/eeconfig.c create mode 100644 common/avr/suspend.c create mode 100644 common/avr/suspend_avr.h delete mode 100644 common/bootloader.c delete mode 100644 common/eeconfig.c create mode 100644 common/mbed/bootloader.c create mode 100644 common/mbed/suspend.c create mode 100644 common/mbed/xprintf.cpp create mode 100644 common/mbed/xprintf.h create mode 100644 common/progmem.h delete mode 100644 common/suspend.c create mode 100644 keyboard/mbed_onekey/config.h create mode 100644 keyboard/mbed_onekey/mbed_driver.cpp create mode 100644 keyboard/mbed_onekey/mbed_driver.h (limited to 'common.mk') diff --git a/common.mk b/common.mk index 9b5ef0ea8..04f036477 100644 --- a/common.mk +++ b/common.mk @@ -7,18 +7,18 @@ SRC += $(COMMON_DIR)/host.c \ $(COMMON_DIR)/action_layer.c \ $(COMMON_DIR)/action_util.c \ $(COMMON_DIR)/keymap.c \ - $(COMMON_DIR)/avr/timer.c \ $(COMMON_DIR)/print.c \ - $(COMMON_DIR)/bootloader.c \ - $(COMMON_DIR)/suspend.c \ + $(COMMON_DIR)/util.c \ + $(COMMON_DIR)/avr/suspend.c \ $(COMMON_DIR)/avr/xprintf.S \ - $(COMMON_DIR)/util.c + $(COMMON_DIR)/avr/timer.c \ + $(COMMON_DIR)/avr/bootloader.c # Option modules ifdef BOOTMAGIC_ENABLE SRC += $(COMMON_DIR)/bootmagic.c - SRC += $(COMMON_DIR)/eeconfig.c + SRC += $(COMMON_DIR)/avr/eeconfig.c OPT_DEFS += -DBOOTMAGIC_ENABLE endif diff --git a/common/avr/bootloader.c b/common/avr/bootloader.c new file mode 100644 index 000000000..cda295b18 --- /dev/null +++ b/common/avr/bootloader.c @@ -0,0 +1,148 @@ +#include +#include +#include +#include +#include +#include +#include "bootloader.h" + +#ifdef PROTOCOL_LUFA +#include +#endif + + +/* Boot Section Size in *BYTEs* + * Teensy halfKay 512 + * Teensy++ halfKay 1024 + * Atmel DFU loader 4096 + * LUFA bootloader 4096 + * USBaspLoader 2048 + */ +#ifndef BOOTLOADER_SIZE +#warning To use bootloader_jump() you need to define BOOTLOADER_SIZE in config.h. +#define BOOTLOADER_SIZE 4096 +#endif + +#define FLASH_SIZE (FLASHEND + 1L) +#define BOOTLOADER_START (FLASH_SIZE - BOOTLOADER_SIZE) + + +/* + * Entering the Bootloader via Software + * http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html + */ +#define BOOTLOADER_RESET_KEY 0xB007B007 +uint32_t reset_key __attribute__ ((section (".noinit"))); + +/* initialize MCU status by watchdog reset */ +void bootloader_jump(void) { +#ifdef PROTOCOL_LUFA + USB_Disable(); + cli(); + _delay_ms(2000); +#endif + +#ifdef PROTOCOL_PJRC + cli(); + UDCON = 1; + USBCON = (1< +#include +#include +#include "eeconfig.h" + +void eeconfig_init(void) +{ + eeprom_write_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); + eeprom_write_byte(EECONFIG_DEBUG, 0); + eeprom_write_byte(EECONFIG_DEFAULT_LAYER, 0); + eeprom_write_byte(EECONFIG_KEYMAP, 0); + eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0); +#ifdef BACKLIGHT_ENABLE + eeprom_write_byte(EECONFIG_BACKLIGHT, 0); +#endif +} + +void eeconfig_enable(void) +{ + eeprom_write_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); +} + +void eeconfig_disable(void) +{ + eeprom_write_word(EECONFIG_MAGIC, 0xFFFF); +} + +bool eeconfig_is_enabled(void) +{ + return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); +} + +uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); } +void eeconfig_write_debug(uint8_t val) { eeprom_write_byte(EECONFIG_DEBUG, val); } + +uint8_t eeconfig_read_default_layer(void) { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); } +void eeconfig_write_default_layer(uint8_t val) { eeprom_write_byte(EECONFIG_DEFAULT_LAYER, val); } + +uint8_t eeconfig_read_keymap(void) { return eeprom_read_byte(EECONFIG_KEYMAP); } +void eeconfig_write_keymap(uint8_t val) { eeprom_write_byte(EECONFIG_KEYMAP, val); } + +#ifdef BACKLIGHT_ENABLE +uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); } +void eeconfig_write_backlight(uint8_t val) { eeprom_write_byte(EECONFIG_BACKLIGHT, val); } +#endif diff --git a/common/avr/suspend.c b/common/avr/suspend.c new file mode 100644 index 000000000..f44a036be --- /dev/null +++ b/common/avr/suspend.c @@ -0,0 +1,98 @@ +#include +#include +#include +#include +#include "matrix.h" +#include "action.h" +#include "backlight.h" +#include "suspend_avr.h" +#include "suspend.h" + + +#define wdt_intr_enable(value) \ +__asm__ __volatile__ ( \ + "in __tmp_reg__,__SREG__" "\n\t" \ + "cli" "\n\t" \ + "wdr" "\n\t" \ + "sts %0,%1" "\n\t" \ + "out __SREG__,__tmp_reg__" "\n\t" \ + "sts %0,%2" "\n\t" \ + : /* no outputs */ \ + : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \ + "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \ + "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \ + _BV(WDIE) | (value & 0x07)) ) \ + : "r0" \ +) + + +void suspend_power_down(void) +{ +#ifdef BACKLIGHT_ENABLE + backlight_set(0); +#endif +#ifndef NO_SUSPEND_POWER_DOWN + // Enable watchdog to wake from MCU sleep + cli(); + wdt_reset(); + + // Watchdog Interrupt and System Reset Mode + //wdt_enable(WDTO_1S); + //WDTCSR |= _BV(WDIE); + + // Watchdog Interrupt Mode + wdt_intr_enable(WDTO_120MS); + + // TODO: more power saving + // See PicoPower application note + // - I/O port input with pullup + // - prescale clock + // - BOD disable + // - Power Reduction Register PRR + // sleep in power down mode + set_sleep_mode(SLEEP_MODE_PWR_DOWN); + sleep_enable(); + sei(); + sleep_cpu(); + sleep_disable(); + + // Disable watchdog after sleep + wdt_disable(); +#endif +} + +bool suspend_wakeup_condition(void) +{ + matrix_scan(); + for (uint8_t r = 0; r < MATRIX_ROWS; r++) { + if (matrix_get_row(r)) return true; + } + return false; +} + +// run immediately after wakeup +void suspend_wakeup_init(void) +{ + // clear keyboard state + clear_keyboard(); +#ifdef BACKLIGHT_ENABLE + backlight_init(); +#endif +} + +#ifndef NO_SUSPEND_POWER_DOWN +/* watchdog timeout */ +ISR(WDT_vect) +{ + /* wakeup from MCU sleep mode */ +/* + // blink LED + static uint8_t led_state = 0; + static uint8_t led_count = 0; + led_count++; + if ((led_count & 0x07) == 0) { + led_set((led_state ^= (1< +#include +#include +#include +#include + + +#define wdt_intr_enable(value) \ +__asm__ __volatile__ ( \ + "in __tmp_reg__,__SREG__" "\n\t" \ + "cli" "\n\t" \ + "wdr" "\n\t" \ + "sts %0,%1" "\n\t" \ + "out __SREG__,__tmp_reg__" "\n\t" \ + "sts %0,%2" "\n\t" \ + : /* no outputs */ \ + : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \ + "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \ + "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \ + _BV(WDIE) | (value & 0x07)) ) \ + : "r0" \ +) + +#endif diff --git a/common/bootloader.c b/common/bootloader.c deleted file mode 100644 index cda295b18..000000000 --- a/common/bootloader.c +++ /dev/null @@ -1,148 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "bootloader.h" - -#ifdef PROTOCOL_LUFA -#include -#endif - - -/* Boot Section Size in *BYTEs* - * Teensy halfKay 512 - * Teensy++ halfKay 1024 - * Atmel DFU loader 4096 - * LUFA bootloader 4096 - * USBaspLoader 2048 - */ -#ifndef BOOTLOADER_SIZE -#warning To use bootloader_jump() you need to define BOOTLOADER_SIZE in config.h. -#define BOOTLOADER_SIZE 4096 -#endif - -#define FLASH_SIZE (FLASHEND + 1L) -#define BOOTLOADER_START (FLASH_SIZE - BOOTLOADER_SIZE) - - -/* - * Entering the Bootloader via Software - * http://www.fourwalledcubicle.com/files/LUFA/Doc/120730/html/_page__software_bootloader_start.html - */ -#define BOOTLOADER_RESET_KEY 0xB007B007 -uint32_t reset_key __attribute__ ((section (".noinit"))); - -/* initialize MCU status by watchdog reset */ -void bootloader_jump(void) { -#ifdef PROTOCOL_LUFA - USB_Disable(); - cli(); - _delay_ms(2000); -#endif - -#ifdef PROTOCOL_PJRC - cli(); - UDCON = 1; - USBCON = (1< -#include -#include -#include "eeconfig.h" - -void eeconfig_init(void) -{ - eeprom_write_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); - eeprom_write_byte(EECONFIG_DEBUG, 0); - eeprom_write_byte(EECONFIG_DEFAULT_LAYER, 0); - eeprom_write_byte(EECONFIG_KEYMAP, 0); - eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0); -#ifdef BACKLIGHT_ENABLE - eeprom_write_byte(EECONFIG_BACKLIGHT, 0); -#endif -} - -void eeconfig_enable(void) -{ - eeprom_write_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); -} - -void eeconfig_disable(void) -{ - eeprom_write_word(EECONFIG_MAGIC, 0xFFFF); -} - -bool eeconfig_is_enabled(void) -{ - return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); -} - -uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); } -void eeconfig_write_debug(uint8_t val) { eeprom_write_byte(EECONFIG_DEBUG, val); } - -uint8_t eeconfig_read_default_layer(void) { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); } -void eeconfig_write_default_layer(uint8_t val) { eeprom_write_byte(EECONFIG_DEFAULT_LAYER, val); } - -uint8_t eeconfig_read_keymap(void) { return eeprom_read_byte(EECONFIG_KEYMAP); } -void eeconfig_write_keymap(uint8_t val) { eeprom_write_byte(EECONFIG_KEYMAP, val); } - -#ifdef BACKLIGHT_ENABLE -uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); } -void eeconfig_write_backlight(uint8_t val) { eeprom_write_byte(EECONFIG_BACKLIGHT, val); } -#endif diff --git a/common/host.h b/common/host.h index a56e6c3b0..918af69e8 100644 --- a/common/host.h +++ b/common/host.h @@ -32,8 +32,8 @@ extern "C" { extern bool keyboard_nkro; #endif -uint8_t keyboard_idle; -uint8_t keyboard_protocol; +extern uint8_t keyboard_idle; +extern uint8_t keyboard_protocol; /* host driver */ diff --git a/common/keyboard.c b/common/keyboard.c index b71d5bf13..9a809ff4a 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -15,7 +15,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include -#include #include "keyboard.h" #include "matrix.h" #include "keymap.h" diff --git a/common/keymap.c b/common/keymap.c index 0df2e2edf..4c0b61b8c 100644 --- a/common/keymap.c +++ b/common/keymap.c @@ -14,7 +14,6 @@ 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 . */ -#include #include "keymap.h" #include "report.h" #include "keycode.h" diff --git a/common/mbed/bootloader.c b/common/mbed/bootloader.c new file mode 100644 index 000000000..b51e83943 --- /dev/null +++ b/common/mbed/bootloader.c @@ -0,0 +1,4 @@ +#include "bootloader.h" + + +void bootloader_jump(void) {} diff --git a/common/mbed/suspend.c b/common/mbed/suspend.c new file mode 100644 index 000000000..32651574f --- /dev/null +++ b/common/mbed/suspend.c @@ -0,0 +1,6 @@ +#include + + +void suspend_power_down(void) {} +bool suspend_wakeup_condition(void) { return true; } +void suspend_wakeup_init(void) {} diff --git a/common/mbed/xprintf.cpp b/common/mbed/xprintf.cpp new file mode 100644 index 000000000..4342b79f8 --- /dev/null +++ b/common/mbed/xprintf.cpp @@ -0,0 +1,46 @@ +#include +//#include +#include "mbed.h" +#include "mbed/xprintf.h" + + +#define STRING_STACK_LIMIT 120 + +/* mbed Serial */ +Serial ser(UART_TX, UART_RX); + +/* TODO: Need small implementation for embedded */ +int xprintf(const char* format, ...) +{ + /* copy from mbed/common/RawSerial.cpp */ + std::va_list arg; + va_start(arg, format); + int len = vsnprintf(NULL, 0, format, arg); + if (len < STRING_STACK_LIMIT) { + char temp[STRING_STACK_LIMIT]; + vsprintf(temp, format, arg); + ser.puts(temp); + } else { + char *temp = new char[len + 1]; + vsprintf(temp, format, arg); + ser.puts(temp); + delete[] temp; + } + va_end(arg); + return len; + +/* Fail: __builtin_va_arg_pack? + * https://gcc.gnu.org/onlinedocs/gcc-4.3.5/gcc/Constructing-Calls.html#Constructing-Calls + void *arg = __builtin_apply_args(); + void *ret = __builtin_apply((void*)(&(ser.printf)), arg, 100); + __builtin_return(ret) +*/ +/* Fail: varargs can not be passed to printf + //int r = ser.printf("test %i\r\n", 123); + va_list arg; + va_start(arg, format); + int r = ser.printf(format, arg); + va_end(arg); + return r; +*/ +} diff --git a/common/mbed/xprintf.h b/common/mbed/xprintf.h new file mode 100644 index 000000000..26bc529e5 --- /dev/null +++ b/common/mbed/xprintf.h @@ -0,0 +1,17 @@ +#ifndef XPRINTF_H +#define XPRINTF_H + +//#define xprintf(format, ...) __xprintf(format, ##__VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + +int xprintf(const char *format, ...); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/common/mousekey.c b/common/mousekey.c index 017be9411..23469476e 100644 --- a/common/mousekey.c +++ b/common/mousekey.c @@ -16,7 +16,6 @@ along with this program. If not, see . */ #include -#include #include "keycode.h" #include "host.h" #include "timer.h" diff --git a/common/mousekey.h b/common/mousekey.h index d8d7beaaa..6eede06b4 100644 --- a/common/mousekey.h +++ b/common/mousekey.h @@ -52,12 +52,16 @@ along with this program. If not, see . #endif -uint8_t mk_delay; -uint8_t mk_interval; -uint8_t mk_max_speed; -uint8_t mk_time_to_max; -uint8_t mk_wheel_max_speed; -uint8_t mk_wheel_time_to_max; +#ifdef __cplusplus +extern "C" { +#endif + +extern uint8_t mk_delay; +extern uint8_t mk_interval; +extern uint8_t mk_max_speed; +extern uint8_t mk_time_to_max; +extern uint8_t mk_wheel_max_speed; +extern uint8_t mk_wheel_time_to_max; void mousekey_task(void); @@ -66,4 +70,8 @@ void mousekey_off(uint8_t code); void mousekey_clear(void); void mousekey_send(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/common/progmem.h b/common/progmem.h new file mode 100644 index 000000000..09aeb8b7c --- /dev/null +++ b/common/progmem.h @@ -0,0 +1,11 @@ +#ifndef PROGMEM_H +#define PROGMEM_H 1 + +#if defined(__AVR__) +# include +#elif defined(__arm__) +# define PROGMEM +# define pgm_read_byte(p) *(p) +#endif + +#endif diff --git a/common/suspend.c b/common/suspend.c deleted file mode 100644 index 5b378892f..000000000 --- a/common/suspend.c +++ /dev/null @@ -1,76 +0,0 @@ -#include "suspend.h" -#include "matrix.h" -#include "action.h" -#include "backlight.h" - - -void suspend_power_down(void) -{ -#ifdef BACKLIGHT_ENABLE - backlight_set(0); -#endif -#ifndef NO_SUSPEND_POWER_DOWN - // Enable watchdog to wake from MCU sleep - cli(); - wdt_reset(); - - // Watchdog Interrupt and System Reset Mode - //wdt_enable(WDTO_1S); - //WDTCSR |= _BV(WDIE); - - // Watchdog Interrupt Mode - wdt_intr_enable(WDTO_120MS); - - // TODO: more power saving - // See PicoPower application note - // - I/O port input with pullup - // - prescale clock - // - BOD disable - // - Power Reduction Register PRR - // sleep in power down mode - set_sleep_mode(SLEEP_MODE_PWR_DOWN); - sleep_enable(); - sei(); - sleep_cpu(); - sleep_disable(); - - // Disable watchdog after sleep - wdt_disable(); -#endif -} - -bool suspend_wakeup_condition(void) -{ - matrix_scan(); - for (uint8_t r = 0; r < MATRIX_ROWS; r++) { - if (matrix_get_row(r)) return true; - } - return false; -} - -// run immediately after wakeup -void suspend_wakeup_init(void) -{ - // clear keyboard state - clear_keyboard(); -#ifdef BACKLIGHT_ENABLE - backlight_init(); -#endif -} - -#ifndef NO_SUSPEND_POWER_DOWN -/* watchdog timeout */ -ISR(WDT_vect) -{ - /* wakeup from MCU sleep mode */ -/* - // blink LED - static uint8_t led_state = 0; - static uint8_t led_count = 0; - led_count++; - if ((led_count & 0x07) == 0) { - led_set((led_state ^= (1< #include -#include -#include -#include - - -#define wdt_intr_enable(value) \ -__asm__ __volatile__ ( \ - "in __tmp_reg__,__SREG__" "\n\t" \ - "cli" "\n\t" \ - "wdr" "\n\t" \ - "sts %0,%1" "\n\t" \ - "out __SREG__,__tmp_reg__" "\n\t" \ - "sts %0,%2" "\n\t" \ - : /* no outputs */ \ - : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \ - "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \ - "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \ - _BV(WDIE) | (value & 0x07)) ) \ - : "r0" \ -) void suspend_power_down(void); diff --git a/keyboard/mbed_onekey/Makefile b/keyboard/mbed_onekey/Makefile index 1bc91bc7e..e686f424e 100644 --- a/keyboard/mbed_onekey/Makefile +++ b/keyboard/mbed_onekey/Makefile @@ -18,6 +18,8 @@ OBJECTS = \ $(OBJDIR)/./mbed_driver.o \ $(OBJDIR)/./main.o +CONFIG_H = config.h + SYS_OBJECTS = INCLUDE_PATHS = -I. @@ -25,6 +27,12 @@ INCLUDE_PATHS = -I. LIBRARY_PATHS = LIBRARIES = +# Build Options +# Comment out to disable +#BOOTMAGIC_ENABLE = yes +MOUSEKEY_ENABLE = yes + + include mbed.mk include common.mk include gcc.mk diff --git a/keyboard/mbed_onekey/common.mk b/keyboard/mbed_onekey/common.mk index 6eb7f7699..1bd7d6edb 100644 --- a/keyboard/mbed_onekey/common.mk +++ b/keyboard/mbed_onekey/common.mk @@ -1,21 +1,79 @@ COMMON_DIR = common OBJECTS += \ - $(OBJDIR)/$(COMMON_DIR)/mbed/timer.o \ - $(OBJDIR)/$(COMMON_DIR)/mbed/xprintf.o \ $(OBJDIR)/$(COMMON_DIR)/action.o \ $(OBJDIR)/$(COMMON_DIR)/action_tapping.o \ $(OBJDIR)/$(COMMON_DIR)/action_macro.o \ $(OBJDIR)/$(COMMON_DIR)/action_layer.o \ $(OBJDIR)/$(COMMON_DIR)/action_util.o \ $(OBJDIR)/$(COMMON_DIR)/host.o \ + $(OBJDIR)/$(COMMON_DIR)/keymap.o \ + $(OBJDIR)/$(COMMON_DIR)/keyboard.o \ + $(OBJDIR)/$(COMMON_DIR)/util.o \ + $(OBJDIR)/$(COMMON_DIR)/mbed/suspend.o \ + $(OBJDIR)/$(COMMON_DIR)/mbed/timer.o \ + $(OBJDIR)/$(COMMON_DIR)/mbed/xprintf.o \ + $(OBJDIR)/$(COMMON_DIR)/mbed/bootloader.o \ INCLUDE_PATHS += \ -I$(TMK_DIR)/$(COMMON_DIR) +CC_FLAGS += -include $(CONFIG_H) + + + +# Option modules +ifdef BOOTMAGIC_ENABLE + $(error Not Supported) + OBJECTS += $(OBJDIR)/$(COMMON_DIR)/bootmagic.o + OBJECTS += $(OBJDIR)/$(COMMON_DIR)/mbed/eeprom.o + OPT_DEFS += -DBOOTMAGIC_ENABLE +endif + +ifdef MOUSEKEY_ENABLE + OBJECTS += $(OBJDIR)/$(COMMON_DIR)/mousekey.o + OPT_DEFS += -DMOUSEKEY_ENABLE + OPT_DEFS += -DMOUSE_ENABLE +endif + +ifdef EXTRAKEY_ENABLE + $(error Not Supported) + OPT_DEFS += -DEXTRAKEY_ENABLE +endif + +ifdef CONSOLE_ENABLE + $(error Not Supported) + OPT_DEFS += -DCONSOLE_ENABLE +else + OPT_DEFS += -DNO_PRINT + OPT_DEFS += -DNO_DEBUG +endif + +ifdef COMMAND_ENABLE + $(error Not Supported) + SRC += $(COMMON_DIR)/command.c + OPT_DEFS += -DCOMMAND_ENABLE +endif + +ifdef NKRO_ENABLE + $(error Not Supported) + OPT_DEFS += -DNKRO_ENABLE +endif +ifdef SLEEP_LED_ENABLE + $(error Not Supported) + SRC += $(COMMON_DIR)/sleep_led.c + OPT_DEFS += -DSLEEP_LED_ENABLE + OPT_DEFS += -DNO_SUSPEND_POWER_DOWN +endif +ifdef BACKLIGHT_ENABLE + $(error Not Supported) + SRC += $(COMMON_DIR)/backlight.c + OPT_DEFS += -DBACKLIGHT_ENABLE +endif -# $(OBJDIR)/$(COMMON_DIR)/keyboard.o \ -# $(OBJDIR)/$(COMMON_DIR)/keymap.o \ -# $(OBJDIR)/$(COMMON_DIR)/bootloader.o \ -# $(OBJDIR)/$(COMMON_DIR)/suspend.o \ +ifdef KEYMAP_SECTION_ENABLE + $(error Not Supported) + OPT_DEFS += -DKEYMAP_SECTION_ENABLE + EXTRALDFLAGS = -Wl,-L$(TOP_DIR),-Tldscript_keymap_avr5.x +endif diff --git a/keyboard/mbed_onekey/config.h b/keyboard/mbed_onekey/config.h new file mode 100644 index 000000000..a3aadd038 --- /dev/null +++ b/keyboard/mbed_onekey/config.h @@ -0,0 +1,7 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#define MATRIX_ROWS 1 +#define MATRIX_COLS 1 + +#endif diff --git a/keyboard/mbed_onekey/gcc.mk b/keyboard/mbed_onekey/gcc.mk index e31527bbc..0fc41fe27 100644 --- a/keyboard/mbed_onekey/gcc.mk +++ b/keyboard/mbed_onekey/gcc.mk @@ -10,7 +10,8 @@ SIZE = $(GCC_BIN)arm-none-eabi-size CHKSUM = ~/Dropbox/MBED/tool/lpc-vector-checksum CPU = -mcpu=cortex-m0 -mthumb -CC_FLAGS = $(CPU) -c -g -fno-common -fmessage-length=0 -Wall -fno-exceptions -ffunction-sections -fdata-sections + +CC_FLAGS += $(CPU) -c -g -fno-common -fmessage-length=0 -Wall -fno-exceptions -ffunction-sections -fdata-sections CC_FLAGS += -MMD -MP CC_SYMBOLS = -DTARGET_LPC11U35_401 -DTARGET_M0 -DTARGET_NXP -DTARGET_LPC11UXX -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -D__CORTEX_M0 -DARM_MATH_CM0 -DMBED_BUILD_TIMESTAMP=1399108688.49 -D__MBED__=1 diff --git a/keyboard/mbed_onekey/main.cpp b/keyboard/mbed_onekey/main.cpp index 1df940aa9..b2f7243c8 100644 --- a/keyboard/mbed_onekey/main.cpp +++ b/keyboard/mbed_onekey/main.cpp @@ -1,66 +1,43 @@ -#include "mbed.h" -#include "HIDKeyboard.h" -#include "debug.h" -#include "timer.h" - -/* -//#define DEBUG -#ifdef DEBUG -Serial ser(UART_TX, UART_RX); -#define dprintf(fmt, ...) ser.printf(fmt, ## __VA_ARGS__) -#else -#define dprintf(fmt, ...) -#endif -*/ - - -// button and LEDs -DigitalIn isp(P0_1); -DigitalOut led_red(P0_20); -DigitalOut led_green(P0_21); - -//USBKeyboard -HIDKeyboard keyboard; - - -int main(void) { - //isp.mode(PullUp); - //led_red = 0; - //led_green = 0; - debug_enable = true; - dprintf("HIDKeyboard:\r\n"); - - timer_init(); - xprintf("timer: %i\r\n", timer_read()); - - report_keyboard_t report = { 2, 0, 4, }; //a - report_keyboard_t report_off = { 0 }; - - bool last_isp = isp; - uint32_t last_timer; - while (1) { - //keyboard.mediaControl(KEY_VOLUME_DOWN); - //keyboard.printf("Hello World from Mbed\r\n"); - //keyboard.keyCode('s', KEY_CTRL); - //keyboard.keyCode(KEY_CAPS_LOCK); - - //led_green = !led_green; - //leds = keyboard.lockStatus(); - //ser.putc(ser.getc()); - - if (last_isp == isp) continue; - if (isp == 0) { - led_red = 0; // on - xprintf("timer: %i\r\n", timer_read32()); - xprintf("diff: %i\r\n", timer_elapsed32(last_timer)); - //keyboard.sendReport(report); - } else { - led_red = 1; // off - //keyboard.sendReport(report_off); - } - last_isp = isp; - last_timer = timer_read(); - //led_green = !led_green; - //wait(0.5); - } -} +#include "mbed.h" +#include "debug.h" +#include "timer.h" +#include "action.h" +#include "keycode.h" +#include "host.h" +#include "host_driver.h" +#include "mbed_driver.h" + + +// Button and LEDs of LPC11U35 board +DigitalIn isp(P0_1); // ISP button +DigitalOut led_red(P0_20); +DigitalOut led_green(P0_21); + + +int main(void) { + isp.mode(PullUp); + led_red = 1; + led_green = 0; + + timer_init(); + host_set_driver(&mbed_driver); + + //debug_enable = true; + xprintf("mbed_onekey ver.eee:\r\n"); + + + bool last_isp = isp; + while (1) { + //led_green = !led_green; + if (last_isp == isp) continue; + last_isp = isp; + if (last_isp == 0) { + led_red = 0; // on + dprintf("timer: %i\r\n", timer_read()); + register_code(KC_A); + } else { + led_red = 1; // off + unregister_code(KC_A); + } + } +} diff --git a/keyboard/mbed_onekey/mbed_driver.cpp b/keyboard/mbed_onekey/mbed_driver.cpp new file mode 100644 index 000000000..333f8e378 --- /dev/null +++ b/keyboard/mbed_onekey/mbed_driver.cpp @@ -0,0 +1,41 @@ +#include "HIDKeyboard.h" +#include "host.h" +#include "host_driver.h" +#include "mbed_driver.h" + +HIDKeyboard keyboard; + + +/* Host driver */ +static uint8_t keyboard_leds(void); +static void send_keyboard(report_keyboard_t *report); +static void send_mouse(report_mouse_t *report); +static void send_system(uint16_t data); +static void send_consumer(uint16_t data); + +host_driver_t mbed_driver = { + keyboard_leds, + send_keyboard, + send_mouse, + send_system, + send_consumer +}; + + +static uint8_t keyboard_leds(void) +{ + return 0; +} +static void send_keyboard(report_keyboard_t *report) +{ + keyboard.sendReport(*report); +} +static void send_mouse(report_mouse_t *report) +{ +} +static void send_system(uint16_t data) +{ +} +static void send_consumer(uint16_t data) +{ +} diff --git a/keyboard/mbed_onekey/mbed_driver.h b/keyboard/mbed_onekey/mbed_driver.h new file mode 100644 index 000000000..dd1153b43 --- /dev/null +++ b/keyboard/mbed_onekey/mbed_driver.h @@ -0,0 +1,3 @@ +#include "host_driver.h" + +extern host_driver_t mbed_driver; -- cgit v1.2.3