aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2014-06-17 22:41:14 +0900
committertmk <nobody@nowhere>2014-07-30 14:07:43 +0900
commite81c70149ecf73256f8bb7d77cefc07f2b91d2be (patch)
treed918595b92aa099537640cd02285f914b343bd67
parentee70fe59ee8ebc6dcbf55171b1a2dd72e1744ae6 (diff)
downloadqmk_firmware-e81c70149ecf73256f8bb7d77cefc07f2b91d2be.tar.gz
qmk_firmware-e81c70149ecf73256f8bb7d77cefc07f2b91d2be.zip
Fix common files for mbed
-rw-r--r--common.mk10
-rw-r--r--common/avr/bootloader.c (renamed from common/bootloader.c)0
-rw-r--r--common/avr/eeconfig.c (renamed from common/eeconfig.c)0
-rw-r--r--common/avr/suspend.c (renamed from common/suspend.c)24
-rw-r--r--common/avr/suspend_avr.h27
-rw-r--r--common/host.h4
-rw-r--r--common/keyboard.c1
-rw-r--r--common/keymap.c1
-rw-r--r--common/mbed/bootloader.c4
-rw-r--r--common/mbed/suspend.c6
-rw-r--r--common/mbed/xprintf.cpp46
-rw-r--r--common/mbed/xprintf.h17
-rw-r--r--common/mousekey.c1
-rw-r--r--common/mousekey.h20
-rw-r--r--common/progmem.h11
-rw-r--r--common/suspend.h20
-rw-r--r--keyboard/mbed_onekey/Makefile8
-rw-r--r--keyboard/mbed_onekey/common.mk70
-rw-r--r--keyboard/mbed_onekey/config.h7
-rw-r--r--keyboard/mbed_onekey/gcc.mk3
-rw-r--r--keyboard/mbed_onekey/main.cpp109
-rw-r--r--keyboard/mbed_onekey/mbed_driver.cpp41
-rw-r--r--keyboard/mbed_onekey/mbed_driver.h3
23 files changed, 323 insertions, 110 deletions
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 \
7 $(COMMON_DIR)/action_layer.c \ 7 $(COMMON_DIR)/action_layer.c \
8 $(COMMON_DIR)/action_util.c \ 8 $(COMMON_DIR)/action_util.c \
9 $(COMMON_DIR)/keymap.c \ 9 $(COMMON_DIR)/keymap.c \
10 $(COMMON_DIR)/avr/timer.c \
11 $(COMMON_DIR)/print.c \ 10 $(COMMON_DIR)/print.c \
12 $(COMMON_DIR)/bootloader.c \ 11 $(COMMON_DIR)/util.c \
13 $(COMMON_DIR)/suspend.c \ 12 $(COMMON_DIR)/avr/suspend.c \
14 $(COMMON_DIR)/avr/xprintf.S \ 13 $(COMMON_DIR)/avr/xprintf.S \
15 $(COMMON_DIR)/util.c 14 $(COMMON_DIR)/avr/timer.c \
15 $(COMMON_DIR)/avr/bootloader.c
16 16
17 17
18# Option modules 18# Option modules
19ifdef BOOTMAGIC_ENABLE 19ifdef BOOTMAGIC_ENABLE
20 SRC += $(COMMON_DIR)/bootmagic.c 20 SRC += $(COMMON_DIR)/bootmagic.c
21 SRC += $(COMMON_DIR)/eeconfig.c 21 SRC += $(COMMON_DIR)/avr/eeconfig.c
22 OPT_DEFS += -DBOOTMAGIC_ENABLE 22 OPT_DEFS += -DBOOTMAGIC_ENABLE
23endif 23endif
24 24
diff --git a/common/bootloader.c b/common/avr/bootloader.c
index cda295b18..cda295b18 100644
--- a/common/bootloader.c
+++ b/common/avr/bootloader.c
diff --git a/common/eeconfig.c b/common/avr/eeconfig.c
index 5bd47dc6a..5bd47dc6a 100644
--- a/common/eeconfig.c
+++ b/common/avr/eeconfig.c
diff --git a/common/suspend.c b/common/avr/suspend.c
index 5b378892f..f44a036be 100644
--- a/common/suspend.c
+++ b/common/avr/suspend.c
@@ -1,7 +1,29 @@
1#include "suspend.h" 1#include <stdbool.h>
2#include <avr/sleep.h>
3#include <avr/wdt.h>
4#include <avr/interrupt.h>
2#include "matrix.h" 5#include "matrix.h"
3#include "action.h" 6#include "action.h"
4#include "backlight.h" 7#include "backlight.h"
8#include "suspend_avr.h"
9#include "suspend.h"
10
11
12#define wdt_intr_enable(value) \
13__asm__ __volatile__ ( \
14 "in __tmp_reg__,__SREG__" "\n\t" \
15 "cli" "\n\t" \
16 "wdr" "\n\t" \
17 "sts %0,%1" "\n\t" \
18 "out __SREG__,__tmp_reg__" "\n\t" \
19 "sts %0,%2" "\n\t" \
20 : /* no outputs */ \
21 : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
22 "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
23 "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
24 _BV(WDIE) | (value & 0x07)) ) \
25 : "r0" \
26)
5 27
6 28
7void suspend_power_down(void) 29void suspend_power_down(void)
diff --git a/common/avr/suspend_avr.h b/common/avr/suspend_avr.h
new file mode 100644
index 000000000..357102da4
--- /dev/null
+++ b/common/avr/suspend_avr.h
@@ -0,0 +1,27 @@
1#ifndef SUSPEND_AVR_H
2#define SUSPEND_AVR_H
3
4#include <stdint.h>
5#include <stdbool.h>
6#include <avr/sleep.h>
7#include <avr/wdt.h>
8#include <avr/interrupt.h>
9
10
11#define wdt_intr_enable(value) \
12__asm__ __volatile__ ( \
13 "in __tmp_reg__,__SREG__" "\n\t" \
14 "cli" "\n\t" \
15 "wdr" "\n\t" \
16 "sts %0,%1" "\n\t" \
17 "out __SREG__,__tmp_reg__" "\n\t" \
18 "sts %0,%2" "\n\t" \
19 : /* no outputs */ \
20 : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
21 "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
22 "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
23 _BV(WDIE) | (value & 0x07)) ) \
24 : "r0" \
25)
26
27#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" {
32extern bool keyboard_nkro; 32extern bool keyboard_nkro;
33#endif 33#endif
34 34
35uint8_t keyboard_idle; 35extern uint8_t keyboard_idle;
36uint8_t keyboard_protocol; 36extern uint8_t keyboard_protocol;
37 37
38 38
39/* host driver */ 39/* 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
15along with this program. If not, see <http://www.gnu.org/licenses/>. 15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17#include <stdint.h> 17#include <stdint.h>
18#include <util/delay.h>
19#include "keyboard.h" 18#include "keyboard.h"
20#include "matrix.h" 19#include "matrix.h"
21#include "keymap.h" 20#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.
14You should have received a copy of the GNU General Public License 14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>. 15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17#include <avr/pgmspace.h>
18#include "keymap.h" 17#include "keymap.h"
19#include "report.h" 18#include "report.h"
20#include "keycode.h" 19#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 @@
1#include "bootloader.h"
2
3
4void 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 @@
1#include <stdbool.h>
2
3
4void suspend_power_down(void) {}
5bool suspend_wakeup_condition(void) { return true; }
6void 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 @@
1#include <cstdarg>
2//#include <stdarg.h>
3#include "mbed.h"
4#include "mbed/xprintf.h"
5
6
7#define STRING_STACK_LIMIT 120
8
9/* mbed Serial */
10Serial ser(UART_TX, UART_RX);
11
12/* TODO: Need small implementation for embedded */
13int xprintf(const char* format, ...)
14{
15 /* copy from mbed/common/RawSerial.cpp */
16 std::va_list arg;
17 va_start(arg, format);
18 int len = vsnprintf(NULL, 0, format, arg);
19 if (len < STRING_STACK_LIMIT) {
20 char temp[STRING_STACK_LIMIT];
21 vsprintf(temp, format, arg);
22 ser.puts(temp);
23 } else {
24 char *temp = new char[len + 1];
25 vsprintf(temp, format, arg);
26 ser.puts(temp);
27 delete[] temp;
28 }
29 va_end(arg);
30 return len;
31
32/* Fail: __builtin_va_arg_pack?
33 * https://gcc.gnu.org/onlinedocs/gcc-4.3.5/gcc/Constructing-Calls.html#Constructing-Calls
34 void *arg = __builtin_apply_args();
35 void *ret = __builtin_apply((void*)(&(ser.printf)), arg, 100);
36 __builtin_return(ret)
37*/
38/* Fail: varargs can not be passed to printf
39 //int r = ser.printf("test %i\r\n", 123);
40 va_list arg;
41 va_start(arg, format);
42 int r = ser.printf(format, arg);
43 va_end(arg);
44 return r;
45*/
46}
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 @@
1#ifndef XPRINTF_H
2#define XPRINTF_H
3
4//#define xprintf(format, ...) __xprintf(format, ##__VA_ARGS__)
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10int xprintf(const char *format, ...);
11
12#ifdef __cplusplus
13}
14#endif
15
16
17#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 <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18#include <stdint.h> 18#include <stdint.h>
19#include <util/delay.h>
20#include "keycode.h" 19#include "keycode.h"
21#include "host.h" 20#include "host.h"
22#include "timer.h" 21#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 <http://www.gnu.org/licenses/>.
52#endif 52#endif
53 53
54 54
55uint8_t mk_delay; 55#ifdef __cplusplus
56uint8_t mk_interval; 56extern "C" {
57uint8_t mk_max_speed; 57#endif
58uint8_t mk_time_to_max; 58
59uint8_t mk_wheel_max_speed; 59extern uint8_t mk_delay;
60uint8_t mk_wheel_time_to_max; 60extern uint8_t mk_interval;
61extern uint8_t mk_max_speed;
62extern uint8_t mk_time_to_max;
63extern uint8_t mk_wheel_max_speed;
64extern uint8_t mk_wheel_time_to_max;
61 65
62 66
63void mousekey_task(void); 67void mousekey_task(void);
@@ -66,4 +70,8 @@ void mousekey_off(uint8_t code);
66void mousekey_clear(void); 70void mousekey_clear(void);
67void mousekey_send(void); 71void mousekey_send(void);
68 72
73#ifdef __cplusplus
74}
75#endif
76
69#endif 77#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 @@
1#ifndef PROGMEM_H
2#define PROGMEM_H 1
3
4#if defined(__AVR__)
5# include <avr/pgmspace.h>
6#elif defined(__arm__)
7# define PROGMEM
8# define pgm_read_byte(p) *(p)
9#endif
10
11#endif
diff --git a/common/suspend.h b/common/suspend.h
index 1c1e41ac3..9b76f280d 100644
--- a/common/suspend.h
+++ b/common/suspend.h
@@ -3,26 +3,6 @@
3 3
4#include <stdint.h> 4#include <stdint.h>
5#include <stdbool.h> 5#include <stdbool.h>
6#include <avr/sleep.h>
7#include <avr/wdt.h>
8#include <avr/interrupt.h>
9
10
11#define wdt_intr_enable(value) \
12__asm__ __volatile__ ( \
13 "in __tmp_reg__,__SREG__" "\n\t" \
14 "cli" "\n\t" \
15 "wdr" "\n\t" \
16 "sts %0,%1" "\n\t" \
17 "out __SREG__,__tmp_reg__" "\n\t" \
18 "sts %0,%2" "\n\t" \
19 : /* no outputs */ \
20 : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
21 "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
22 "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
23 _BV(WDIE) | (value & 0x07)) ) \
24 : "r0" \
25)
26 6
27 7
28void suspend_power_down(void); 8void 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 = \
18 $(OBJDIR)/./mbed_driver.o \ 18 $(OBJDIR)/./mbed_driver.o \
19 $(OBJDIR)/./main.o 19 $(OBJDIR)/./main.o
20 20
21CONFIG_H = config.h
22
21SYS_OBJECTS = 23SYS_OBJECTS =
22 24
23INCLUDE_PATHS = -I. 25INCLUDE_PATHS = -I.
@@ -25,6 +27,12 @@ INCLUDE_PATHS = -I.
25LIBRARY_PATHS = 27LIBRARY_PATHS =
26LIBRARIES = 28LIBRARIES =
27 29
30# Build Options
31# Comment out to disable
32#BOOTMAGIC_ENABLE = yes
33MOUSEKEY_ENABLE = yes
34
35
28include mbed.mk 36include mbed.mk
29include common.mk 37include common.mk
30include gcc.mk 38include 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 @@
1COMMON_DIR = common 1COMMON_DIR = common
2OBJECTS += \ 2OBJECTS += \
3 $(OBJDIR)/$(COMMON_DIR)/mbed/timer.o \
4 $(OBJDIR)/$(COMMON_DIR)/mbed/xprintf.o \
5 $(OBJDIR)/$(COMMON_DIR)/action.o \ 3 $(OBJDIR)/$(COMMON_DIR)/action.o \
6 $(OBJDIR)/$(COMMON_DIR)/action_tapping.o \ 4 $(OBJDIR)/$(COMMON_DIR)/action_tapping.o \
7 $(OBJDIR)/$(COMMON_DIR)/action_macro.o \ 5 $(OBJDIR)/$(COMMON_DIR)/action_macro.o \
8 $(OBJDIR)/$(COMMON_DIR)/action_layer.o \ 6 $(OBJDIR)/$(COMMON_DIR)/action_layer.o \
9 $(OBJDIR)/$(COMMON_DIR)/action_util.o \ 7 $(OBJDIR)/$(COMMON_DIR)/action_util.o \
10 $(OBJDIR)/$(COMMON_DIR)/host.o \ 8 $(OBJDIR)/$(COMMON_DIR)/host.o \
9 $(OBJDIR)/$(COMMON_DIR)/keymap.o \
10 $(OBJDIR)/$(COMMON_DIR)/keyboard.o \
11 $(OBJDIR)/$(COMMON_DIR)/util.o \
12 $(OBJDIR)/$(COMMON_DIR)/mbed/suspend.o \
13 $(OBJDIR)/$(COMMON_DIR)/mbed/timer.o \
14 $(OBJDIR)/$(COMMON_DIR)/mbed/xprintf.o \
15 $(OBJDIR)/$(COMMON_DIR)/mbed/bootloader.o \
11 16
12INCLUDE_PATHS += \ 17INCLUDE_PATHS += \
13 -I$(TMK_DIR)/$(COMMON_DIR) 18 -I$(TMK_DIR)/$(COMMON_DIR)
14 19
20CC_FLAGS += -include $(CONFIG_H)
21
22
23
24# Option modules
25ifdef BOOTMAGIC_ENABLE
26 $(error Not Supported)
27 OBJECTS += $(OBJDIR)/$(COMMON_DIR)/bootmagic.o
28 OBJECTS += $(OBJDIR)/$(COMMON_DIR)/mbed/eeprom.o
29 OPT_DEFS += -DBOOTMAGIC_ENABLE
30endif
31
32ifdef MOUSEKEY_ENABLE
33 OBJECTS += $(OBJDIR)/$(COMMON_DIR)/mousekey.o
34 OPT_DEFS += -DMOUSEKEY_ENABLE
35 OPT_DEFS += -DMOUSE_ENABLE
36endif
37
38ifdef EXTRAKEY_ENABLE
39 $(error Not Supported)
40 OPT_DEFS += -DEXTRAKEY_ENABLE
41endif
42
43ifdef CONSOLE_ENABLE
44 $(error Not Supported)
45 OPT_DEFS += -DCONSOLE_ENABLE
46else
47 OPT_DEFS += -DNO_PRINT
48 OPT_DEFS += -DNO_DEBUG
49endif
50
51ifdef COMMAND_ENABLE
52 $(error Not Supported)
53 SRC += $(COMMON_DIR)/command.c
54 OPT_DEFS += -DCOMMAND_ENABLE
55endif
56
57ifdef NKRO_ENABLE
58 $(error Not Supported)
59 OPT_DEFS += -DNKRO_ENABLE
60endif
15 61
62ifdef SLEEP_LED_ENABLE
63 $(error Not Supported)
64 SRC += $(COMMON_DIR)/sleep_led.c
65 OPT_DEFS += -DSLEEP_LED_ENABLE
66 OPT_DEFS += -DNO_SUSPEND_POWER_DOWN
67endif
16 68
69ifdef BACKLIGHT_ENABLE
70 $(error Not Supported)
71 SRC += $(COMMON_DIR)/backlight.c
72 OPT_DEFS += -DBACKLIGHT_ENABLE
73endif
17 74
18# $(OBJDIR)/$(COMMON_DIR)/keyboard.o \ 75ifdef KEYMAP_SECTION_ENABLE
19# $(OBJDIR)/$(COMMON_DIR)/keymap.o \ 76 $(error Not Supported)
20# $(OBJDIR)/$(COMMON_DIR)/bootloader.o \ 77 OPT_DEFS += -DKEYMAP_SECTION_ENABLE
21# $(OBJDIR)/$(COMMON_DIR)/suspend.o \ 78 EXTRALDFLAGS = -Wl,-L$(TOP_DIR),-Tldscript_keymap_avr5.x
79endif
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 @@
1#ifndef CONFIG_H
2#define CONFIG_H
3
4#define MATRIX_ROWS 1
5#define MATRIX_COLS 1
6
7#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
10CHKSUM = ~/Dropbox/MBED/tool/lpc-vector-checksum 10CHKSUM = ~/Dropbox/MBED/tool/lpc-vector-checksum
11 11
12CPU = -mcpu=cortex-m0 -mthumb 12CPU = -mcpu=cortex-m0 -mthumb
13CC_FLAGS = $(CPU) -c -g -fno-common -fmessage-length=0 -Wall -fno-exceptions -ffunction-sections -fdata-sections 13
14CC_FLAGS += $(CPU) -c -g -fno-common -fmessage-length=0 -Wall -fno-exceptions -ffunction-sections -fdata-sections
14CC_FLAGS += -MMD -MP 15CC_FLAGS += -MMD -MP
15CC_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 16CC_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
16 17
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 @@
1#include "mbed.h" 1#include "mbed.h"
2#include "HIDKeyboard.h" 2#include "debug.h"
3#include "debug.h" 3#include "timer.h"
4#include "timer.h" 4#include "action.h"
5 5#include "keycode.h"
6/* 6#include "host.h"
7//#define DEBUG 7#include "host_driver.h"
8#ifdef DEBUG 8#include "mbed_driver.h"
9Serial ser(UART_TX, UART_RX); 9
10#define dprintf(fmt, ...) ser.printf(fmt, ## __VA_ARGS__) 10
11#else 11// Button and LEDs of LPC11U35 board
12#define dprintf(fmt, ...) 12DigitalIn isp(P0_1); // ISP button
13#endif 13DigitalOut led_red(P0_20);
14*/ 14DigitalOut led_green(P0_21);
15 15
16 16
17// button and LEDs 17int main(void) {
18DigitalIn isp(P0_1); 18 isp.mode(PullUp);
19DigitalOut led_red(P0_20); 19 led_red = 1;
20DigitalOut led_green(P0_21); 20 led_green = 0;
21 21
22//USBKeyboard 22 timer_init();
23HIDKeyboard keyboard; 23 host_set_driver(&mbed_driver);
24 24
25 25 //debug_enable = true;
26int main(void) { 26 xprintf("mbed_onekey ver.eee:\r\n");
27 //isp.mode(PullUp); 27
28 //led_red = 0; 28
29 //led_green = 0; 29 bool last_isp = isp;
30 debug_enable = true; 30 while (1) {
31 dprintf("HIDKeyboard:\r\n"); 31 //led_green = !led_green;
32 32 if (last_isp == isp) continue;
33 timer_init(); 33 last_isp = isp;
34 xprintf("timer: %i\r\n", timer_read()); 34 if (last_isp == 0) {
35 35 led_red = 0; // on
36 report_keyboard_t report = { 2, 0, 4, }; //a 36 dprintf("timer: %i\r\n", timer_read());
37 report_keyboard_t report_off = { 0 }; 37 register_code(KC_A);
38 38 } else {
39 bool last_isp = isp; 39 led_red = 1; // off
40 uint32_t last_timer; 40 unregister_code(KC_A);
41 while (1) { 41 }
42 //keyboard.mediaControl(KEY_VOLUME_DOWN); 42 }
43 //keyboard.printf("Hello World from Mbed\r\n"); 43}
44 //keyboard.keyCode('s', KEY_CTRL);
45 //keyboard.keyCode(KEY_CAPS_LOCK);
46
47 //led_green = !led_green;
48 //leds = keyboard.lockStatus();
49 //ser.putc(ser.getc());
50
51 if (last_isp == isp) continue;
52 if (isp == 0) {
53 led_red = 0; // on
54 xprintf("timer: %i\r\n", timer_read32());
55 xprintf("diff: %i\r\n", timer_elapsed32(last_timer));
56 //keyboard.sendReport(report);
57 } else {
58 led_red = 1; // off
59 //keyboard.sendReport(report_off);
60 }
61 last_isp = isp;
62 last_timer = timer_read();
63 //led_green = !led_green;
64 //wait(0.5);
65 }
66}
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 @@
1#include "HIDKeyboard.h"
2#include "host.h"
3#include "host_driver.h"
4#include "mbed_driver.h"
5
6HIDKeyboard keyboard;
7
8
9/* Host driver */
10static uint8_t keyboard_leds(void);
11static void send_keyboard(report_keyboard_t *report);
12static void send_mouse(report_mouse_t *report);
13static void send_system(uint16_t data);
14static void send_consumer(uint16_t data);
15
16host_driver_t mbed_driver = {
17 keyboard_leds,
18 send_keyboard,
19 send_mouse,
20 send_system,
21 send_consumer
22};
23
24
25static uint8_t keyboard_leds(void)
26{
27 return 0;
28}
29static void send_keyboard(report_keyboard_t *report)
30{
31 keyboard.sendReport(*report);
32}
33static void send_mouse(report_mouse_t *report)
34{
35}
36static void send_system(uint16_t data)
37{
38}
39static void send_consumer(uint16_t data)
40{
41}
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 @@
1#include "host_driver.h"
2
3extern host_driver_t mbed_driver;