Fix common files for mbed
This commit is contained in:
		
							parent
							
								
									ee70fe59ee
								
							
						
					
					
						commit
						e81c70149e
					
				
					 23 changed files with 323 additions and 110 deletions
				
			
		
							
								
								
									
										10
									
								
								common.mk
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								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 | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,7 +1,29 @@ | |||
| #include "suspend.h" | ||||
| #include <stdbool.h> | ||||
| #include <avr/sleep.h> | ||||
| #include <avr/wdt.h> | ||||
| #include <avr/interrupt.h> | ||||
| #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) | ||||
							
								
								
									
										27
									
								
								common/avr/suspend_avr.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								common/avr/suspend_avr.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,27 @@ | |||
| #ifndef SUSPEND_AVR_H | ||||
| #define SUSPEND_AVR_H | ||||
| 
 | ||||
| #include <stdint.h> | ||||
| #include <stdbool.h> | ||||
| #include <avr/sleep.h> | ||||
| #include <avr/wdt.h> | ||||
| #include <avr/interrupt.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"  \ | ||||
| ) | ||||
| 
 | ||||
| #endif | ||||
|  | @ -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 */ | ||||
|  |  | |||
|  | @ -15,7 +15,6 @@ You should have received a copy of the GNU General Public License | |||
| along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | ||||
| */ | ||||
| #include <stdint.h> | ||||
| #include <util/delay.h> | ||||
| #include "keyboard.h" | ||||
| #include "matrix.h" | ||||
| #include "keymap.h" | ||||
|  |  | |||
|  | @ -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 <http://www.gnu.org/licenses/>.
 | ||||
| */ | ||||
| #include <avr/pgmspace.h> | ||||
| #include "keymap.h" | ||||
| #include "report.h" | ||||
| #include "keycode.h" | ||||
|  |  | |||
							
								
								
									
										4
									
								
								common/mbed/bootloader.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								common/mbed/bootloader.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,4 @@ | |||
| #include "bootloader.h" | ||||
| 
 | ||||
| 
 | ||||
| void bootloader_jump(void) {} | ||||
							
								
								
									
										6
									
								
								common/mbed/suspend.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								common/mbed/suspend.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,6 @@ | |||
| #include <stdbool.h> | ||||
| 
 | ||||
| 
 | ||||
| void suspend_power_down(void) {} | ||||
| bool suspend_wakeup_condition(void) { return true; } | ||||
| void suspend_wakeup_init(void) {} | ||||
							
								
								
									
										46
									
								
								common/mbed/xprintf.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								common/mbed/xprintf.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,46 @@ | |||
| #include <cstdarg> | ||||
| //#include <stdarg.h>
 | ||||
| #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; | ||||
| */ | ||||
| } | ||||
							
								
								
									
										17
									
								
								common/mbed/xprintf.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								common/mbed/xprintf.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||
|  | @ -16,7 +16,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>. | |||
| */ | ||||
| 
 | ||||
| #include <stdint.h> | ||||
| #include <util/delay.h> | ||||
| #include "keycode.h" | ||||
| #include "host.h" | ||||
| #include "timer.h" | ||||
|  |  | |||
|  | @ -52,12 +52,16 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>. | |||
| #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 | ||||
|  |  | |||
							
								
								
									
										11
									
								
								common/progmem.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								common/progmem.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | |||
| #ifndef PROGMEM_H | ||||
| #define PROGMEM_H 1 | ||||
| 
 | ||||
| #if defined(__AVR__) | ||||
| #   include <avr/pgmspace.h> | ||||
| #elif defined(__arm__) | ||||
| #   define PROGMEM | ||||
| #   define pgm_read_byte(p)     *(p) | ||||
| #endif | ||||
| 
 | ||||
| #endif | ||||
|  | @ -3,26 +3,6 @@ | |||
| 
 | ||||
| #include <stdint.h> | ||||
| #include <stdbool.h> | ||||
| #include <avr/sleep.h> | ||||
| #include <avr/wdt.h> | ||||
| #include <avr/interrupt.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); | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -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) | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| #	$(OBJDIR)/$(COMMON_DIR)/keyboard.o \
 | ||||
| #	$(OBJDIR)/$(COMMON_DIR)/keymap.o \
 | ||||
| #	$(OBJDIR)/$(COMMON_DIR)/bootloader.o \
 | ||||
| #	$(OBJDIR)/$(COMMON_DIR)/suspend.o \
 | ||||
| # 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 | ||||
| 
 | ||||
| ifdef KEYMAP_SECTION_ENABLE | ||||
|     $(error Not Supported) | ||||
|     OPT_DEFS += -DKEYMAP_SECTION_ENABLE | ||||
|     EXTRALDFLAGS = -Wl,-L$(TOP_DIR),-Tldscript_keymap_avr5.x | ||||
| endif | ||||
|  |  | |||
							
								
								
									
										7
									
								
								keyboard/mbed_onekey/config.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								keyboard/mbed_onekey/config.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,7 @@ | |||
| #ifndef CONFIG_H | ||||
| #define CONFIG_H | ||||
| 
 | ||||
| #define MATRIX_ROWS 1 | ||||
| #define MATRIX_COLS 1 | ||||
| 
 | ||||
| #endif | ||||
|  | @ -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  | ||||
| 
 | ||||
|  |  | |||
|  | @ -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); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
							
								
								
									
										41
									
								
								keyboard/mbed_onekey/mbed_driver.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								keyboard/mbed_onekey/mbed_driver.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -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) | ||||
| { | ||||
| } | ||||
							
								
								
									
										3
									
								
								keyboard/mbed_onekey/mbed_driver.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								keyboard/mbed_onekey/mbed_driver.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| #include "host_driver.h" | ||||
| 
 | ||||
| extern host_driver_t mbed_driver; | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 tmk
						tmk