From daf232794ed3b094b5c2f98fc656f3cf1a3a67a4 Mon Sep 17 00:00:00 2001 From: tmk Date: Thu, 19 Jun 2014 16:13:35 +0900 Subject: [PATCH] Port ps2_usb to mbed --- common/progmem.h | 1 + protocol.mk | 1 + protocol/ps2.h | 65 ++++-------------------------------- protocol/ps2_busywait.c | 16 +++++---- protocol/ps2_io.h | 15 +++++++++ protocol/ps2_io_avr.c | 74 +++++++++++++++++++++++++++++++++++++++++ protocol/ps2_io_mbed.c | 60 +++++++++++++++++++++++++++++++++ tool/mbed/common.mk | 42 +++++++++++------------ 8 files changed, 189 insertions(+), 85 deletions(-) create mode 100644 protocol/ps2_io.h create mode 100644 protocol/ps2_io_avr.c create mode 100644 protocol/ps2_io_mbed.c diff --git a/common/progmem.h b/common/progmem.h index 09aeb8b7..199b1bed 100644 --- a/common/progmem.h +++ b/common/progmem.h @@ -6,6 +6,7 @@ #elif defined(__arm__) # define PROGMEM # define pgm_read_byte(p) *(p) +# define pgm_read_word(p) *(p) #endif #endif diff --git a/protocol.mk b/protocol.mk index 7f561e62..ca435ba4 100644 --- a/protocol.mk +++ b/protocol.mk @@ -9,6 +9,7 @@ endif ifdef PS2_USE_BUSYWAIT SRC += protocol/ps2_busywait.c + SRC += protocol/ps2_io_avr.c OPT_DEFS += -DPS2_USE_BUSYWAIT endif diff --git a/protocol/ps2.h b/protocol/ps2.h index 483eea72..acde679c 100644 --- a/protocol/ps2.h +++ b/protocol/ps2.h @@ -39,8 +39,9 @@ POSSIBILITY OF SUCH DAMAGE. #define PS2_H #include -#include -#include +#include "wait.h" +#include "ps2_io.h" +#include "print.h" /* * Primitive PS/2 Library for AVR @@ -92,79 +93,27 @@ uint8_t ps2_host_recv(void); void ps2_host_set_led(uint8_t usb_led); -/* Check port settings for clock and data line */ -#if !(defined(PS2_CLOCK_PORT) && \ - defined(PS2_CLOCK_PIN) && \ - defined(PS2_CLOCK_DDR) && \ - defined(PS2_CLOCK_BIT)) -# error "PS/2 clock port setting is required in config.h" -#endif - -#if !(defined(PS2_DATA_PORT) && \ - defined(PS2_DATA_PIN) && \ - defined(PS2_DATA_DDR) && \ - defined(PS2_DATA_BIT)) -# error "PS/2 data port setting is required in config.h" -#endif - /*-------------------------------------------------------------------- * static functions *------------------------------------------------------------------*/ -static inline void clock_lo(void) -{ - PS2_CLOCK_PORT &= ~(1< -#include +#include "wait.h" #include "ps2.h" +#include "ps2_io.h" #include "debug.h" @@ -58,8 +59,11 @@ uint8_t ps2_error = PS2_ERR_NONE; void ps2_host_init(void) { + clock_init(); + data_init(); + // POR(150-2000ms) plus BAT(300-500ms) may take 2.5sec([3]p.20) - _delay_ms(2500); + wait_ms(2500); inhibit(); } @@ -71,7 +75,7 @@ uint8_t ps2_host_send(uint8_t data) /* terminate a transmission if we have */ inhibit(); - _delay_us(100); // 100us [4]p.13, [5]p.50 + wait_us(100); // 100us [4]p.13, [5]p.50 /* 'Request to Send' and Start bit */ data_lo(); @@ -80,7 +84,7 @@ uint8_t ps2_host_send(uint8_t data) /* Data bit */ for (uint8_t i = 0; i < 8; i++) { - _delay_us(15); + wait_us(15); if (data&(1< +#include + +/* Check port settings for clock and data line */ +#if !(defined(PS2_CLOCK_PORT) && \ + defined(PS2_CLOCK_PIN) && \ + defined(PS2_CLOCK_DDR) && \ + defined(PS2_CLOCK_BIT)) +# error "PS/2 clock port setting is required in config.h" +#endif + +#if !(defined(PS2_DATA_PORT) && \ + defined(PS2_DATA_PIN) && \ + defined(PS2_DATA_DDR) && \ + defined(PS2_DATA_BIT)) +# error "PS/2 data port setting is required in config.h" +#endif + + +/* + * Clock + */ +void clock_init(void) +{ +} + +void clock_lo(void) +{ + PS2_CLOCK_PORT &= ~(1< +#include "ps2_io.h" +#include "gpio_api.h" + + +static gpio_t clock; +static gpio_t data; + +/* + * Clock + */ +void clock_init(void) +{ + gpio_init(&clock, P0_9); + gpio_mode(&clock, OpenDrain|PullNone); +} + +void clock_lo(void) +{ + gpio_dir(&clock, PIN_OUTPUT); + gpio_write(&clock, 0); +} +void clock_hi(void) +{ + gpio_dir(&clock, PIN_OUTPUT); + gpio_write(&clock, 1); +} + +bool clock_in(void) +{ + gpio_dir(&clock, PIN_INPUT); + return gpio_read(&clock); +} + +/* + * Data + */ +void data_init(void) +{ + gpio_init(&data, P0_8); + gpio_mode(&data, OpenDrain|PullNone); +} + +void data_lo(void) +{ + gpio_dir(&data, PIN_OUTPUT); + gpio_write(&data, 0); +} + +void data_hi(void) +{ + gpio_dir(&data, PIN_OUTPUT); + gpio_write(&data, 1); +} + +bool data_in(void) +{ + gpio_dir(&data, PIN_INPUT); + return gpio_read(&data); +} diff --git a/tool/mbed/common.mk b/tool/mbed/common.mk index 1bd7d6ed..93a927a3 100644 --- a/tool/mbed/common.mk +++ b/tool/mbed/common.mk @@ -1,21 +1,21 @@ -COMMON_DIR = common OBJECTS += \ - $(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 \ + $(OBJDIR)/common/action.o \ + $(OBJDIR)/common/action_tapping.o \ + $(OBJDIR)/common/action_macro.o \ + $(OBJDIR)/common/action_layer.o \ + $(OBJDIR)/common/action_util.o \ + $(OBJDIR)/common/host.o \ + $(OBJDIR)/common/keymap.o \ + $(OBJDIR)/common/keyboard.o \ + $(OBJDIR)/common/util.o \ + $(OBJDIR)/common/mbed/suspend.o \ + $(OBJDIR)/common/mbed/timer.o \ + $(OBJDIR)/common/mbed/xprintf.o \ + $(OBJDIR)/common/mbed/bootloader.o \ INCLUDE_PATHS += \ - -I$(TMK_DIR)/$(COMMON_DIR) + -I$(TMK_DIR)/common \ + -I$(TMK_DIR)/protocol CC_FLAGS += -include $(CONFIG_H) @@ -24,13 +24,13 @@ 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 + OBJECTS += $(OBJDIR)/common/bootmagic.o + OBJECTS += $(OBJDIR)/common/mbed/eeprom.o OPT_DEFS += -DBOOTMAGIC_ENABLE endif ifdef MOUSEKEY_ENABLE - OBJECTS += $(OBJDIR)/$(COMMON_DIR)/mousekey.o + OBJECTS += $(OBJDIR)/common/mousekey.o OPT_DEFS += -DMOUSEKEY_ENABLE OPT_DEFS += -DMOUSE_ENABLE endif @@ -50,7 +50,7 @@ endif ifdef COMMAND_ENABLE $(error Not Supported) - SRC += $(COMMON_DIR)/command.c + SRC += common/command.c OPT_DEFS += -DCOMMAND_ENABLE endif @@ -61,14 +61,14 @@ endif ifdef SLEEP_LED_ENABLE $(error Not Supported) - SRC += $(COMMON_DIR)/sleep_led.c + SRC += common/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 + SRC += common/backlight.c OPT_DEFS += -DBACKLIGHT_ENABLE endif