diff options
| -rw-r--r-- | common/progmem.h | 1 | ||||
| -rw-r--r-- | converter/ps2_usb/Makefile.mbed | 44 | ||||
| -rw-r--r-- | converter/ps2_usb/config_mbed.h | 60 | ||||
| -rw-r--r-- | converter/ps2_usb/keymap_common.c | 3 | ||||
| -rw-r--r-- | converter/ps2_usb/keymap_common.h | 1 | ||||
| -rw-r--r-- | converter/ps2_usb/main.cpp | 46 | ||||
| -rw-r--r-- | converter/ps2_usb/matrix.c | 3 | ||||
| -rw-r--r-- | keyboard/mbed_onekey/Makefile | 2 | ||||
| -rw-r--r-- | protocol.mk | 1 | ||||
| -rw-r--r-- | protocol/ps2.h | 65 | ||||
| -rw-r--r-- | protocol/ps2_busywait.c | 16 | ||||
| -rw-r--r-- | protocol/ps2_io.h | 15 | ||||
| -rw-r--r-- | protocol/ps2_io_avr.c | 74 | ||||
| -rw-r--r-- | protocol/ps2_io_mbed.c | 60 | ||||
| -rw-r--r-- | tool/mbed/common.mk | 42 |
15 files changed, 343 insertions, 90 deletions
diff --git a/common/progmem.h b/common/progmem.h index 09aeb8b7c..199b1bedf 100644 --- a/common/progmem.h +++ b/common/progmem.h | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #elif defined(__arm__) | 6 | #elif defined(__arm__) |
| 7 | # define PROGMEM | 7 | # define PROGMEM |
| 8 | # define pgm_read_byte(p) *(p) | 8 | # define pgm_read_byte(p) *(p) |
| 9 | # define pgm_read_word(p) *(p) | ||
| 9 | #endif | 10 | #endif |
| 10 | 11 | ||
| 11 | #endif | 12 | #endif |
diff --git a/converter/ps2_usb/Makefile.mbed b/converter/ps2_usb/Makefile.mbed new file mode 100644 index 000000000..631f270f7 --- /dev/null +++ b/converter/ps2_usb/Makefile.mbed | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | PROJECT = ps2_usb | ||
| 2 | |||
| 3 | TMK_DIR = ../.. | ||
| 4 | MBED_DIR = $(TMK_DIR)/mbed-sdk | ||
| 5 | |||
| 6 | #VPATH += $(MBED_DIR):$(TMK_DIR) | ||
| 7 | vpath %.s .:$(MBED_DIR):$(TMK_DIR) | ||
| 8 | vpath %.c .:$(MBED_DIR):$(TMK_DIR) | ||
| 9 | vpath %.cpp .:$(MBED_DIR):$(TMK_DIR) | ||
| 10 | |||
| 11 | OBJDIR = ./build | ||
| 12 | |||
| 13 | OBJECTS = \ | ||
| 14 | $(OBJDIR)/protocol/ps2_busywait.o \ | ||
| 15 | $(OBJDIR)/protocol/ps2_io_mbed.o \ | ||
| 16 | $(OBJDIR)/./keymap_common.o \ | ||
| 17 | $(OBJDIR)/./matrix.o \ | ||
| 18 | $(OBJDIR)/./led.o \ | ||
| 19 | $(OBJDIR)/./main.o | ||
| 20 | |||
| 21 | ifdef KEYMAP | ||
| 22 | OBJECTS := $(OBJDIR)/keymap_$(KEYMAP).o $(OBJECTS) | ||
| 23 | else | ||
| 24 | OBJECTS := $(OBJDIR)/keymap_plain.o $(OBJECTS) | ||
| 25 | endif | ||
| 26 | |||
| 27 | CONFIG_H = config_mbed.h | ||
| 28 | |||
| 29 | SYS_OBJECTS = | ||
| 30 | |||
| 31 | INCLUDE_PATHS = -I. | ||
| 32 | |||
| 33 | LIBRARY_PATHS = | ||
| 34 | LIBRARIES = | ||
| 35 | |||
| 36 | # Build Options | ||
| 37 | # Comment out to disable | ||
| 38 | #BOOTMAGIC_ENABLE = yes | ||
| 39 | MOUSEKEY_ENABLE = yes | ||
| 40 | |||
| 41 | |||
| 42 | include $(TMK_DIR)/tool/mbed/mbed.mk | ||
| 43 | include $(TMK_DIR)/tool/mbed/common.mk | ||
| 44 | include $(TMK_DIR)/tool/mbed/gcc.mk | ||
diff --git a/converter/ps2_usb/config_mbed.h b/converter/ps2_usb/config_mbed.h new file mode 100644 index 000000000..5819763e6 --- /dev/null +++ b/converter/ps2_usb/config_mbed.h | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #ifndef CONFIG_MBED_H | ||
| 19 | #define CONFIG_MBED_H | ||
| 20 | |||
| 21 | |||
| 22 | #if 0 | ||
| 23 | // duplicated name against mbed USBDeivce | ||
| 24 | #define VENDOR_ID 0xFEED | ||
| 25 | #define PRODUCT_ID 0x6512 | ||
| 26 | #endif | ||
| 27 | #define DEVICE_VER 0x0001 | ||
| 28 | #define MANUFACTURER t.m.k. | ||
| 29 | #define PRODUCT PS/2 keyboard converter | ||
| 30 | #define DESCRIPTION convert PS/2 keyboard to USB | ||
| 31 | |||
| 32 | |||
| 33 | /* matrix size */ | ||
| 34 | #define MATRIX_ROWS 32 // keycode bit: 3-0 | ||
| 35 | #define MATRIX_COLS 8 // keycode bit: 6-4 | ||
| 36 | |||
| 37 | |||
| 38 | /* key combination for command */ | ||
| 39 | #define IS_COMMAND() ( \ | ||
| 40 | keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) || \ | ||
| 41 | keyboard_report->mods == (MOD_BIT(KC_LCTRL) | MOD_BIT(KC_RSHIFT)) \ | ||
| 42 | ) | ||
| 43 | |||
| 44 | |||
| 45 | /* | ||
| 46 | * PS/2 Busywait | ||
| 47 | */ | ||
| 48 | #ifdef PS2_USE_BUSYWAIT | ||
| 49 | # define PS2_CLOCK_PORT PORTD | ||
| 50 | # define PS2_CLOCK_PIN PIND | ||
| 51 | # define PS2_CLOCK_DDR DDRD | ||
| 52 | # define PS2_CLOCK_BIT 5 | ||
| 53 | # define PS2_DATA_PORT PORTD | ||
| 54 | # define PS2_DATA_PIN PIND | ||
| 55 | # define PS2_DATA_DDR DDRD | ||
| 56 | # define PS2_DATA_BIT 2 | ||
| 57 | #endif | ||
| 58 | |||
| 59 | |||
| 60 | #endif | ||
diff --git a/converter/ps2_usb/keymap_common.c b/converter/ps2_usb/keymap_common.c index 241d2e33b..e344fb416 100644 --- a/converter/ps2_usb/keymap_common.c +++ b/converter/ps2_usb/keymap_common.c | |||
| @@ -15,10 +15,11 @@ You should have received a copy of the GNU General Public License | |||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ | 16 | */ |
| 17 | #include "keymap_common.h" | 17 | #include "keymap_common.h" |
| 18 | #include "progmem.h" | ||
| 18 | 19 | ||
| 19 | 20 | ||
| 20 | /* translates key to keycode */ | 21 | /* translates key to keycode */ |
| 21 | uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) | 22 | uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key) |
| 22 | { | 23 | { |
| 23 | return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); | 24 | return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); |
| 24 | } | 25 | } |
diff --git a/converter/ps2_usb/keymap_common.h b/converter/ps2_usb/keymap_common.h index 216a8dc02..d783e01de 100644 --- a/converter/ps2_usb/keymap_common.h +++ b/converter/ps2_usb/keymap_common.h | |||
| @@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 19 | 19 | ||
| 20 | #include <stdint.h> | 20 | #include <stdint.h> |
| 21 | #include <stdbool.h> | 21 | #include <stdbool.h> |
| 22 | #include <avr/pgmspace.h> | ||
| 23 | #include "keycode.h" | 22 | #include "keycode.h" |
| 24 | #include "action.h" | 23 | #include "action.h" |
| 25 | #include "action_macro.h" | 24 | #include "action_macro.h" |
diff --git a/converter/ps2_usb/main.cpp b/converter/ps2_usb/main.cpp new file mode 100644 index 000000000..860af149a --- /dev/null +++ b/converter/ps2_usb/main.cpp | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | #include "mbed.h" | ||
| 2 | #include "debug.h" | ||
| 3 | #include "timer.h" | ||
| 4 | #include "action.h" | ||
| 5 | #include "keycode.h" | ||
| 6 | #include "host.h" | ||
| 7 | #include "host_driver.h" | ||
| 8 | #include "mbed_driver.h" | ||
| 9 | |||
| 10 | |||
| 11 | // Button and LEDs of LPC11U35 board | ||
| 12 | DigitalIn isp(P0_1); // ISP button | ||
| 13 | DigitalOut led_red(P0_20); | ||
| 14 | DigitalOut led_green(P0_21); | ||
| 15 | |||
| 16 | |||
| 17 | int main(void) { | ||
| 18 | isp.mode(PullUp); | ||
| 19 | led_red = 1; | ||
| 20 | led_green = 0; | ||
| 21 | |||
| 22 | timer_init(); | ||
| 23 | host_set_driver(&mbed_driver); | ||
| 24 | keyboard_init(); | ||
| 25 | |||
| 26 | //debug_enable = true; | ||
| 27 | xprintf("mbed_onekey ver.eee:\r\n"); | ||
| 28 | |||
| 29 | |||
| 30 | bool last_isp = isp; | ||
| 31 | while (1) { | ||
| 32 | keyboard_task(); | ||
| 33 | |||
| 34 | //led_green = !led_green; | ||
| 35 | if (last_isp == isp) continue; | ||
| 36 | last_isp = isp; | ||
| 37 | if (last_isp == 0) { | ||
| 38 | led_red = 0; // on | ||
| 39 | dprintf("timer: %i\r\n", timer_read()); | ||
| 40 | //register_code(KC_A); | ||
| 41 | } else { | ||
| 42 | led_red = 1; // off | ||
| 43 | //unregister_code(KC_A); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } | ||
diff --git a/converter/ps2_usb/matrix.c b/converter/ps2_usb/matrix.c index 45344c0f7..45cf2a4a9 100644 --- a/converter/ps2_usb/matrix.c +++ b/converter/ps2_usb/matrix.c | |||
| @@ -17,8 +17,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 17 | 17 | ||
| 18 | #include <stdint.h> | 18 | #include <stdint.h> |
| 19 | #include <stdbool.h> | 19 | #include <stdbool.h> |
| 20 | #include <avr/io.h> | ||
| 21 | #include <util/delay.h> | ||
| 22 | #include "action.h" | 20 | #include "action.h" |
| 23 | #include "print.h" | 21 | #include "print.h" |
| 24 | #include "util.h" | 22 | #include "util.h" |
| @@ -189,6 +187,7 @@ uint8_t matrix_scan(void) | |||
| 189 | } | 187 | } |
| 190 | 188 | ||
| 191 | uint8_t code = ps2_host_recv(); | 189 | uint8_t code = ps2_host_recv(); |
| 190 | if (code) xprintf("%i\r\n", code); | ||
| 192 | if (!ps2_error) { | 191 | if (!ps2_error) { |
| 193 | switch (state) { | 192 | switch (state) { |
| 194 | case INIT: | 193 | case INIT: |
diff --git a/keyboard/mbed_onekey/Makefile b/keyboard/mbed_onekey/Makefile index d0d1148ce..2f7399ba0 100644 --- a/keyboard/mbed_onekey/Makefile +++ b/keyboard/mbed_onekey/Makefile | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | PROJECT = mbed_onekey | 1 | PROJECT = mbed_onekey |
| 2 | 2 | ||
| 3 | TMK_DIR = ../.. | 3 | TMK_DIR = ../.. |
| 4 | MBED_DIR = ./mbed-sdk | 4 | MBED_DIR = $(TMK_DIR)/mbed-sdk |
| 5 | 5 | ||
| 6 | #VPATH += $(MBED_DIR):$(TMK_DIR) | 6 | #VPATH += $(MBED_DIR):$(TMK_DIR) |
| 7 | vpath %.s .:$(MBED_DIR):$(TMK_DIR) | 7 | vpath %.s .:$(MBED_DIR):$(TMK_DIR) |
diff --git a/protocol.mk b/protocol.mk index 7f561e62d..ca435ba43 100644 --- a/protocol.mk +++ b/protocol.mk | |||
| @@ -9,6 +9,7 @@ endif | |||
| 9 | 9 | ||
| 10 | ifdef PS2_USE_BUSYWAIT | 10 | ifdef PS2_USE_BUSYWAIT |
| 11 | SRC += protocol/ps2_busywait.c | 11 | SRC += protocol/ps2_busywait.c |
| 12 | SRC += protocol/ps2_io_avr.c | ||
| 12 | OPT_DEFS += -DPS2_USE_BUSYWAIT | 13 | OPT_DEFS += -DPS2_USE_BUSYWAIT |
| 13 | endif | 14 | endif |
| 14 | 15 | ||
diff --git a/protocol/ps2.h b/protocol/ps2.h index 483eea720..acde679cf 100644 --- a/protocol/ps2.h +++ b/protocol/ps2.h | |||
| @@ -39,8 +39,9 @@ POSSIBILITY OF SUCH DAMAGE. | |||
| 39 | #define PS2_H | 39 | #define PS2_H |
| 40 | 40 | ||
| 41 | #include <stdbool.h> | 41 | #include <stdbool.h> |
| 42 | #include <util/delay.h> | 42 | #include "wait.h" |
| 43 | #include <avr/io.h> | 43 | #include "ps2_io.h" |
| 44 | #include "print.h" | ||
| 44 | 45 | ||
| 45 | /* | 46 | /* |
| 46 | * Primitive PS/2 Library for AVR | 47 | * Primitive PS/2 Library for AVR |
| @@ -92,79 +93,27 @@ uint8_t ps2_host_recv(void); | |||
| 92 | void ps2_host_set_led(uint8_t usb_led); | 93 | void ps2_host_set_led(uint8_t usb_led); |
| 93 | 94 | ||
| 94 | 95 | ||
| 95 | /* Check port settings for clock and data line */ | ||
| 96 | #if !(defined(PS2_CLOCK_PORT) && \ | ||
| 97 | defined(PS2_CLOCK_PIN) && \ | ||
| 98 | defined(PS2_CLOCK_DDR) && \ | ||
| 99 | defined(PS2_CLOCK_BIT)) | ||
| 100 | # error "PS/2 clock port setting is required in config.h" | ||
| 101 | #endif | ||
| 102 | |||
| 103 | #if !(defined(PS2_DATA_PORT) && \ | ||
| 104 | defined(PS2_DATA_PIN) && \ | ||
| 105 | defined(PS2_DATA_DDR) && \ | ||
| 106 | defined(PS2_DATA_BIT)) | ||
| 107 | # error "PS/2 data port setting is required in config.h" | ||
| 108 | #endif | ||
| 109 | |||
| 110 | /*-------------------------------------------------------------------- | 96 | /*-------------------------------------------------------------------- |
| 111 | * static functions | 97 | * static functions |
| 112 | *------------------------------------------------------------------*/ | 98 | *------------------------------------------------------------------*/ |
| 113 | static inline void clock_lo(void) | ||
| 114 | { | ||
| 115 | PS2_CLOCK_PORT &= ~(1<<PS2_CLOCK_BIT); | ||
| 116 | PS2_CLOCK_DDR |= (1<<PS2_CLOCK_BIT); | ||
| 117 | } | ||
| 118 | static inline void clock_hi(void) | ||
| 119 | { | ||
| 120 | /* input with pull up */ | ||
| 121 | PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT); | ||
| 122 | PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT); | ||
| 123 | } | ||
| 124 | static inline bool clock_in(void) | ||
| 125 | { | ||
| 126 | PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT); | ||
| 127 | PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT); | ||
| 128 | _delay_us(1); | ||
| 129 | return PS2_CLOCK_PIN&(1<<PS2_CLOCK_BIT); | ||
| 130 | } | ||
| 131 | static inline void data_lo(void) | ||
| 132 | { | ||
| 133 | PS2_DATA_PORT &= ~(1<<PS2_DATA_BIT); | ||
| 134 | PS2_DATA_DDR |= (1<<PS2_DATA_BIT); | ||
| 135 | } | ||
| 136 | static inline void data_hi(void) | ||
| 137 | { | ||
| 138 | /* input with pull up */ | ||
| 139 | PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT); | ||
| 140 | PS2_DATA_PORT |= (1<<PS2_DATA_BIT); | ||
| 141 | } | ||
| 142 | static inline bool data_in(void) | ||
| 143 | { | ||
| 144 | PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT); | ||
| 145 | PS2_DATA_PORT |= (1<<PS2_DATA_BIT); | ||
| 146 | _delay_us(1); | ||
| 147 | return PS2_DATA_PIN&(1<<PS2_DATA_BIT); | ||
| 148 | } | ||
| 149 | |||
| 150 | static inline uint16_t wait_clock_lo(uint16_t us) | 99 | static inline uint16_t wait_clock_lo(uint16_t us) |
| 151 | { | 100 | { |
| 152 | while (clock_in() && us) { asm(""); _delay_us(1); us--; } | 101 | while (clock_in() && us) { asm(""); wait_us(1); us--; } |
| 153 | return us; | 102 | return us; |
| 154 | } | 103 | } |
| 155 | static inline uint16_t wait_clock_hi(uint16_t us) | 104 | static inline uint16_t wait_clock_hi(uint16_t us) |
| 156 | { | 105 | { |
| 157 | while (!clock_in() && us) { asm(""); _delay_us(1); us--; } | 106 | while (!clock_in() && us) { asm(""); wait_us(1); us--; } |
| 158 | return us; | 107 | return us; |
| 159 | } | 108 | } |
| 160 | static inline uint16_t wait_data_lo(uint16_t us) | 109 | static inline uint16_t wait_data_lo(uint16_t us) |
| 161 | { | 110 | { |
| 162 | while (data_in() && us) { asm(""); _delay_us(1); us--; } | 111 | while (data_in() && us) { asm(""); wait_us(1); us--; } |
| 163 | return us; | 112 | return us; |
| 164 | } | 113 | } |
| 165 | static inline uint16_t wait_data_hi(uint16_t us) | 114 | static inline uint16_t wait_data_hi(uint16_t us) |
| 166 | { | 115 | { |
| 167 | while (!data_in() && us) { asm(""); _delay_us(1); us--; } | 116 | while (!data_in() && us) { asm(""); wait_us(1); us--; } |
| 168 | return us; | 117 | return us; |
| 169 | } | 118 | } |
| 170 | 119 | ||
diff --git a/protocol/ps2_busywait.c b/protocol/ps2_busywait.c index 05dd7b27e..a64933219 100644 --- a/protocol/ps2_busywait.c +++ b/protocol/ps2_busywait.c | |||
| @@ -40,8 +40,9 @@ POSSIBILITY OF SUCH DAMAGE. | |||
| 40 | */ | 40 | */ |
| 41 | 41 | ||
| 42 | #include <stdbool.h> | 42 | #include <stdbool.h> |
| 43 | #include <util/delay.h> | 43 | #include "wait.h" |
| 44 | #include "ps2.h" | 44 | #include "ps2.h" |
| 45 | #include "ps2_io.h" | ||
| 45 | #include "debug.h" | 46 | #include "debug.h" |
| 46 | 47 | ||
| 47 | 48 | ||
| @@ -58,8 +59,11 @@ uint8_t ps2_error = PS2_ERR_NONE; | |||
| 58 | 59 | ||
| 59 | void ps2_host_init(void) | 60 | void ps2_host_init(void) |
| 60 | { | 61 | { |
| 62 | clock_init(); | ||
| 63 | data_init(); | ||
| 64 | |||
| 61 | // POR(150-2000ms) plus BAT(300-500ms) may take 2.5sec([3]p.20) | 65 | // POR(150-2000ms) plus BAT(300-500ms) may take 2.5sec([3]p.20) |
| 62 | _delay_ms(2500); | 66 | wait_ms(2500); |
| 63 | 67 | ||
| 64 | inhibit(); | 68 | inhibit(); |
| 65 | } | 69 | } |
| @@ -71,7 +75,7 @@ uint8_t ps2_host_send(uint8_t data) | |||
| 71 | 75 | ||
| 72 | /* terminate a transmission if we have */ | 76 | /* terminate a transmission if we have */ |
| 73 | inhibit(); | 77 | inhibit(); |
| 74 | _delay_us(100); // 100us [4]p.13, [5]p.50 | 78 | wait_us(100); // 100us [4]p.13, [5]p.50 |
| 75 | 79 | ||
| 76 | /* 'Request to Send' and Start bit */ | 80 | /* 'Request to Send' and Start bit */ |
| 77 | data_lo(); | 81 | data_lo(); |
| @@ -80,7 +84,7 @@ uint8_t ps2_host_send(uint8_t data) | |||
| 80 | 84 | ||
| 81 | /* Data bit */ | 85 | /* Data bit */ |
| 82 | for (uint8_t i = 0; i < 8; i++) { | 86 | for (uint8_t i = 0; i < 8; i++) { |
| 83 | _delay_us(15); | 87 | wait_us(15); |
| 84 | if (data&(1<<i)) { | 88 | if (data&(1<<i)) { |
| 85 | parity = !parity; | 89 | parity = !parity; |
| 86 | data_hi(); | 90 | data_hi(); |
| @@ -92,13 +96,13 @@ uint8_t ps2_host_send(uint8_t data) | |||
| 92 | } | 96 | } |
| 93 | 97 | ||
| 94 | /* Parity bit */ | 98 | /* Parity bit */ |
| 95 | _delay_us(15); | 99 | wait_us(15); |
| 96 | if (parity) { data_hi(); } else { data_lo(); } | 100 | if (parity) { data_hi(); } else { data_lo(); } |
| 97 | WAIT(clock_hi, 50, 4); | 101 | WAIT(clock_hi, 50, 4); |
| 98 | WAIT(clock_lo, 50, 5); | 102 | WAIT(clock_lo, 50, 5); |
| 99 | 103 | ||
| 100 | /* Stop bit */ | 104 | /* Stop bit */ |
| 101 | _delay_us(15); | 105 | wait_us(15); |
| 102 | data_hi(); | 106 | data_hi(); |
| 103 | 107 | ||
| 104 | /* Ack */ | 108 | /* Ack */ |
diff --git a/protocol/ps2_io.h b/protocol/ps2_io.h new file mode 100644 index 000000000..a46a358e7 --- /dev/null +++ b/protocol/ps2_io.h | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | #ifndef PS2_IO_H | ||
| 2 | #define PS2_IO_H | ||
| 3 | |||
| 4 | |||
| 5 | void clock_init(void); | ||
| 6 | void clock_lo(void); | ||
| 7 | void clock_hi(void); | ||
| 8 | bool clock_in(void); | ||
| 9 | |||
| 10 | void data_init(void); | ||
| 11 | void data_lo(void); | ||
| 12 | void data_hi(void); | ||
| 13 | bool data_in(void); | ||
| 14 | |||
| 15 | #endif | ||
diff --git a/protocol/ps2_io_avr.c b/protocol/ps2_io_avr.c new file mode 100644 index 000000000..be13d6696 --- /dev/null +++ b/protocol/ps2_io_avr.c | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | #include <stdbool.h> | ||
| 2 | #include <util/delay.h> | ||
| 3 | |||
| 4 | /* Check port settings for clock and data line */ | ||
| 5 | #if !(defined(PS2_CLOCK_PORT) && \ | ||
| 6 | defined(PS2_CLOCK_PIN) && \ | ||
| 7 | defined(PS2_CLOCK_DDR) && \ | ||
| 8 | defined(PS2_CLOCK_BIT)) | ||
| 9 | # error "PS/2 clock port setting is required in config.h" | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #if !(defined(PS2_DATA_PORT) && \ | ||
| 13 | defined(PS2_DATA_PIN) && \ | ||
| 14 | defined(PS2_DATA_DDR) && \ | ||
| 15 | defined(PS2_DATA_BIT)) | ||
| 16 | # error "PS/2 data port setting is required in config.h" | ||
| 17 | #endif | ||
| 18 | |||
| 19 | |||
| 20 | /* | ||
| 21 | * Clock | ||
| 22 | */ | ||
| 23 | void clock_init(void) | ||
| 24 | { | ||
| 25 | } | ||
| 26 | |||
| 27 | void clock_lo(void) | ||
| 28 | { | ||
| 29 | PS2_CLOCK_PORT &= ~(1<<PS2_CLOCK_BIT); | ||
| 30 | PS2_CLOCK_DDR |= (1<<PS2_CLOCK_BIT); | ||
| 31 | } | ||
| 32 | |||
| 33 | void clock_hi(void) | ||
| 34 | { | ||
| 35 | /* input with pull up */ | ||
| 36 | PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT); | ||
| 37 | PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT); | ||
| 38 | } | ||
| 39 | |||
| 40 | bool clock_in(void) | ||
| 41 | { | ||
| 42 | PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT); | ||
| 43 | PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT); | ||
| 44 | _delay_us(1); | ||
| 45 | return PS2_CLOCK_PIN&(1<<PS2_CLOCK_BIT); | ||
| 46 | } | ||
| 47 | |||
| 48 | /* | ||
| 49 | * Data | ||
| 50 | */ | ||
| 51 | void data_init(void) | ||
| 52 | { | ||
| 53 | } | ||
| 54 | |||
| 55 | void data_lo(void) | ||
| 56 | { | ||
| 57 | PS2_DATA_PORT &= ~(1<<PS2_DATA_BIT); | ||
| 58 | PS2_DATA_DDR |= (1<<PS2_DATA_BIT); | ||
| 59 | } | ||
| 60 | |||
| 61 | void data_hi(void) | ||
| 62 | { | ||
| 63 | /* input with pull up */ | ||
| 64 | PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT); | ||
| 65 | PS2_DATA_PORT |= (1<<PS2_DATA_BIT); | ||
| 66 | } | ||
| 67 | |||
| 68 | bool data_in(void) | ||
| 69 | { | ||
| 70 | PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT); | ||
| 71 | PS2_DATA_PORT |= (1<<PS2_DATA_BIT); | ||
| 72 | _delay_us(1); | ||
| 73 | return PS2_DATA_PIN&(1<<PS2_DATA_BIT); | ||
| 74 | } | ||
diff --git a/protocol/ps2_io_mbed.c b/protocol/ps2_io_mbed.c new file mode 100644 index 000000000..83bdcef7f --- /dev/null +++ b/protocol/ps2_io_mbed.c | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | #include <stdbool.h> | ||
| 2 | #include "ps2_io.h" | ||
| 3 | #include "gpio_api.h" | ||
| 4 | |||
| 5 | |||
| 6 | static gpio_t clock; | ||
| 7 | static gpio_t data; | ||
| 8 | |||
| 9 | /* | ||
| 10 | * Clock | ||
| 11 | */ | ||
| 12 | void clock_init(void) | ||
| 13 | { | ||
| 14 | gpio_init(&clock, P0_9); | ||
| 15 | gpio_mode(&clock, OpenDrain|PullNone); | ||
| 16 | } | ||
| 17 | |||
| 18 | void clock_lo(void) | ||
| 19 | { | ||
| 20 | gpio_dir(&clock, PIN_OUTPUT); | ||
| 21 | gpio_write(&clock, 0); | ||
| 22 | } | ||
| 23 | void clock_hi(void) | ||
| 24 | { | ||
| 25 | gpio_dir(&clock, PIN_OUTPUT); | ||
| 26 | gpio_write(&clock, 1); | ||
| 27 | } | ||
| 28 | |||
| 29 | bool clock_in(void) | ||
| 30 | { | ||
| 31 | gpio_dir(&clock, PIN_INPUT); | ||
| 32 | return gpio_read(&clock); | ||
| 33 | } | ||
| 34 | |||
| 35 | /* | ||
| 36 | * Data | ||
| 37 | */ | ||
| 38 | void data_init(void) | ||
| 39 | { | ||
| 40 | gpio_init(&data, P0_8); | ||
| 41 | gpio_mode(&data, OpenDrain|PullNone); | ||
| 42 | } | ||
| 43 | |||
| 44 | void data_lo(void) | ||
| 45 | { | ||
| 46 | gpio_dir(&data, PIN_OUTPUT); | ||
| 47 | gpio_write(&data, 0); | ||
| 48 | } | ||
| 49 | |||
| 50 | void data_hi(void) | ||
| 51 | { | ||
| 52 | gpio_dir(&data, PIN_OUTPUT); | ||
| 53 | gpio_write(&data, 1); | ||
| 54 | } | ||
| 55 | |||
| 56 | bool data_in(void) | ||
| 57 | { | ||
| 58 | gpio_dir(&data, PIN_INPUT); | ||
| 59 | return gpio_read(&data); | ||
| 60 | } | ||
diff --git a/tool/mbed/common.mk b/tool/mbed/common.mk index 1bd7d6edb..93a927a3e 100644 --- a/tool/mbed/common.mk +++ b/tool/mbed/common.mk | |||
| @@ -1,21 +1,21 @@ | |||
| 1 | COMMON_DIR = common | ||
| 2 | OBJECTS += \ | 1 | OBJECTS += \ |
| 3 | $(OBJDIR)/$(COMMON_DIR)/action.o \ | 2 | $(OBJDIR)/common/action.o \ |
| 4 | $(OBJDIR)/$(COMMON_DIR)/action_tapping.o \ | 3 | $(OBJDIR)/common/action_tapping.o \ |
| 5 | $(OBJDIR)/$(COMMON_DIR)/action_macro.o \ | 4 | $(OBJDIR)/common/action_macro.o \ |
| 6 | $(OBJDIR)/$(COMMON_DIR)/action_layer.o \ | 5 | $(OBJDIR)/common/action_layer.o \ |
| 7 | $(OBJDIR)/$(COMMON_DIR)/action_util.o \ | 6 | $(OBJDIR)/common/action_util.o \ |
| 8 | $(OBJDIR)/$(COMMON_DIR)/host.o \ | 7 | $(OBJDIR)/common/host.o \ |
| 9 | $(OBJDIR)/$(COMMON_DIR)/keymap.o \ | 8 | $(OBJDIR)/common/keymap.o \ |
| 10 | $(OBJDIR)/$(COMMON_DIR)/keyboard.o \ | 9 | $(OBJDIR)/common/keyboard.o \ |
| 11 | $(OBJDIR)/$(COMMON_DIR)/util.o \ | 10 | $(OBJDIR)/common/util.o \ |
| 12 | $(OBJDIR)/$(COMMON_DIR)/mbed/suspend.o \ | 11 | $(OBJDIR)/common/mbed/suspend.o \ |
| 13 | $(OBJDIR)/$(COMMON_DIR)/mbed/timer.o \ | 12 | $(OBJDIR)/common/mbed/timer.o \ |
| 14 | $(OBJDIR)/$(COMMON_DIR)/mbed/xprintf.o \ | 13 | $(OBJDIR)/common/mbed/xprintf.o \ |
| 15 | $(OBJDIR)/$(COMMON_DIR)/mbed/bootloader.o \ | 14 | $(OBJDIR)/common/mbed/bootloader.o \ |
| 16 | 15 | ||
| 17 | INCLUDE_PATHS += \ | 16 | INCLUDE_PATHS += \ |
| 18 | -I$(TMK_DIR)/$(COMMON_DIR) | 17 | -I$(TMK_DIR)/common \ |
| 18 | -I$(TMK_DIR)/protocol | ||
| 19 | 19 | ||
| 20 | CC_FLAGS += -include $(CONFIG_H) | 20 | CC_FLAGS += -include $(CONFIG_H) |
| 21 | 21 | ||
| @@ -24,13 +24,13 @@ CC_FLAGS += -include $(CONFIG_H) | |||
| 24 | # Option modules | 24 | # Option modules |
| 25 | ifdef BOOTMAGIC_ENABLE | 25 | ifdef BOOTMAGIC_ENABLE |
| 26 | $(error Not Supported) | 26 | $(error Not Supported) |
| 27 | OBJECTS += $(OBJDIR)/$(COMMON_DIR)/bootmagic.o | 27 | OBJECTS += $(OBJDIR)/common/bootmagic.o |
| 28 | OBJECTS += $(OBJDIR)/$(COMMON_DIR)/mbed/eeprom.o | 28 | OBJECTS += $(OBJDIR)/common/mbed/eeprom.o |
| 29 | OPT_DEFS += -DBOOTMAGIC_ENABLE | 29 | OPT_DEFS += -DBOOTMAGIC_ENABLE |
| 30 | endif | 30 | endif |
| 31 | 31 | ||
| 32 | ifdef MOUSEKEY_ENABLE | 32 | ifdef MOUSEKEY_ENABLE |
| 33 | OBJECTS += $(OBJDIR)/$(COMMON_DIR)/mousekey.o | 33 | OBJECTS += $(OBJDIR)/common/mousekey.o |
| 34 | OPT_DEFS += -DMOUSEKEY_ENABLE | 34 | OPT_DEFS += -DMOUSEKEY_ENABLE |
| 35 | OPT_DEFS += -DMOUSE_ENABLE | 35 | OPT_DEFS += -DMOUSE_ENABLE |
| 36 | endif | 36 | endif |
| @@ -50,7 +50,7 @@ endif | |||
| 50 | 50 | ||
| 51 | ifdef COMMAND_ENABLE | 51 | ifdef COMMAND_ENABLE |
| 52 | $(error Not Supported) | 52 | $(error Not Supported) |
| 53 | SRC += $(COMMON_DIR)/command.c | 53 | SRC += common/command.c |
| 54 | OPT_DEFS += -DCOMMAND_ENABLE | 54 | OPT_DEFS += -DCOMMAND_ENABLE |
| 55 | endif | 55 | endif |
| 56 | 56 | ||
| @@ -61,14 +61,14 @@ endif | |||
| 61 | 61 | ||
| 62 | ifdef SLEEP_LED_ENABLE | 62 | ifdef SLEEP_LED_ENABLE |
| 63 | $(error Not Supported) | 63 | $(error Not Supported) |
| 64 | SRC += $(COMMON_DIR)/sleep_led.c | 64 | SRC += common/sleep_led.c |
| 65 | OPT_DEFS += -DSLEEP_LED_ENABLE | 65 | OPT_DEFS += -DSLEEP_LED_ENABLE |
| 66 | OPT_DEFS += -DNO_SUSPEND_POWER_DOWN | 66 | OPT_DEFS += -DNO_SUSPEND_POWER_DOWN |
| 67 | endif | 67 | endif |
| 68 | 68 | ||
| 69 | ifdef BACKLIGHT_ENABLE | 69 | ifdef BACKLIGHT_ENABLE |
| 70 | $(error Not Supported) | 70 | $(error Not Supported) |
| 71 | SRC += $(COMMON_DIR)/backlight.c | 71 | SRC += common/backlight.c |
| 72 | OPT_DEFS += -DBACKLIGHT_ENABLE | 72 | OPT_DEFS += -DBACKLIGHT_ENABLE |
| 73 | endif | 73 | endif |
| 74 | 74 | ||
