diff options
| -rw-r--r-- | converter/x68k_usb/Makefile | 3 | ||||
| -rw-r--r-- | converter/x68k_usb/config_pjrc.h | 18 | ||||
| -rw-r--r-- | converter/x68k_usb/led.c | 5 | ||||
| -rw-r--r-- | converter/x68k_usb/matrix.c | 13 | ||||
| -rw-r--r-- | protocol/x68k.c | 81 | ||||
| -rw-r--r-- | protocol/x68k.h | 48 |
6 files changed, 13 insertions, 155 deletions
diff --git a/converter/x68k_usb/Makefile b/converter/x68k_usb/Makefile index fd66ed563..948622c7c 100644 --- a/converter/x68k_usb/Makefile +++ b/converter/x68k_usb/Makefile | |||
| @@ -16,8 +16,7 @@ TARGET_DIR = . | |||
| 16 | SRC = keymap.c \ | 16 | SRC = keymap.c \ |
| 17 | matrix.c \ | 17 | matrix.c \ |
| 18 | led.c \ | 18 | led.c \ |
| 19 | protocol/x68k.c | 19 | protocol/serial_uart.c |
| 20 | # protocol/serial_uart.c | ||
| 21 | 20 | ||
| 22 | CONFIG_H = config_pjrc.h | 21 | CONFIG_H = config_pjrc.h |
| 23 | 22 | ||
diff --git a/converter/x68k_usb/config_pjrc.h b/converter/x68k_usb/config_pjrc.h index dd277cff1..c49b4a73e 100644 --- a/converter/x68k_usb/config_pjrc.h +++ b/converter/x68k_usb/config_pjrc.h | |||
| @@ -34,7 +34,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 34 | /* key combination for command */ | 34 | /* key combination for command */ |
| 35 | #define IS_COMMAND() ( \ | 35 | #define IS_COMMAND() ( \ |
| 36 | keyboard_report->mods == (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT)) || \ | 36 | keyboard_report->mods == (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT)) || \ |
| 37 | keyboard_report->mods == (MOD_BIT(KC_LCTRL) | MOD_BIT(KC_RSHIFT)) \ | 37 | keyboard_report->mods == (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI)) || \ |
| 38 | keyboard_report->mods == (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL)) \ | ||
| 38 | ) | 39 | ) |
| 39 | 40 | ||
| 40 | /* legacy keymap support */ | 41 | /* legacy keymap support */ |
| @@ -45,17 +46,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 45 | * asynchronous, 2400baud, 8-data bit, non parity, 1-stop bit, no flow control | 46 | * asynchronous, 2400baud, 8-data bit, non parity, 1-stop bit, no flow control |
| 46 | */ | 47 | */ |
| 47 | #ifdef __AVR_ATmega32U4__ | 48 | #ifdef __AVR_ATmega32U4__ |
| 48 | # define KBD_RX_VECT USART1_RX_vect | ||
| 49 | # define KBD_RX_DATA UDR1 | ||
| 50 | # define KBD_RX_BAUD 2400 | ||
| 51 | # define KBD_RX_UBBR ((F_CPU/(16UL*KBD_RX_BAUD))-1) | ||
| 52 | # define KBD_RX_INIT() do { \ | ||
| 53 | UBRR1L = (uint8_t) KBD_RX_UBBR; \ | ||
| 54 | UBRR1H = (uint8_t) (KBD_RX_UBBR>>8); \ | ||
| 55 | UCSR1B |= (1<<RXCIE1) | (1<<RXEN1) | (1<<TXEN1); \ | ||
| 56 | } while(0) | ||
| 57 | |||
| 58 | |||
| 59 | #define SERIAL_UART_BAUD 2400 | 49 | #define SERIAL_UART_BAUD 2400 |
| 60 | #define SERIAL_UART_DATA UDR1 | 50 | #define SERIAL_UART_DATA UDR1 |
| 61 | #define SERIAL_UART_UBRR ((F_CPU/(16UL*SERIAL_UART_BAUD))-1) | 51 | #define SERIAL_UART_UBRR ((F_CPU/(16UL*SERIAL_UART_BAUD))-1) |
| @@ -66,8 +56,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 66 | UBRR1H = (uint8_t) (SERIAL_UART_UBRR>>8); /* baud rate */ \ | 56 | UBRR1H = (uint8_t) (SERIAL_UART_UBRR>>8); /* baud rate */ \ |
| 67 | UCSR1B = (1<<RXCIE1) | (1<<RXEN1) | /* RX: interrupt, RX: enable */ \ | 57 | UCSR1B = (1<<RXCIE1) | (1<<RXEN1) | /* RX: interrupt, RX: enable */ \ |
| 68 | (1<<TXEN1); /* TX: enable */ \ | 58 | (1<<TXEN1); /* TX: enable */ \ |
| 69 | UCSR1C = (1<<UPM11) | (1<<UPM10) | /* parity: none(00), even(01), odd(11) */ \ | 59 | UCSR1C = (0<<UPM11) | (0<<UPM10) | /* parity: none(00), even(01), odd(11) */ \ |
| 70 | (0<<UCSZ12) | (1<<UCSZ11) | (1<<UCSZ10); /* 8bit-data(011) */ \ | 60 | (0<<UCSZ12) | (1<<UCSZ11) | (1<<UCSZ10); /* data-8bit(011) */ \ |
| 71 | sei(); \ | 61 | sei(); \ |
| 72 | } while(0) | 62 | } while(0) |
| 73 | #else | 63 | #else |
diff --git a/converter/x68k_usb/led.c b/converter/x68k_usb/led.c index a1c1d546e..ccc38699c 100644 --- a/converter/x68k_usb/led.c +++ b/converter/x68k_usb/led.c | |||
| @@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 19 | #include "serial.h" | 19 | #include "serial.h" |
| 20 | #include "led.h" | 20 | #include "led.h" |
| 21 | #include "debug.h" | 21 | #include "debug.h" |
| 22 | #include "x68k.h" | ||
| 23 | 22 | ||
| 24 | 23 | ||
| 25 | void led_set(uint8_t usb_led) | 24 | void led_set(uint8_t usb_led) |
| @@ -35,12 +34,10 @@ void led_set(uint8_t usb_led) | |||
| 35 | * bit 0 かな | 34 | * bit 0 かな |
| 36 | */ | 35 | */ |
| 37 | uint8_t led = 0xFF; | 36 | uint8_t led = 0xFF; |
| 38 | xprintf("usb_led: %02X\n", usb_led); | ||
| 39 | if (usb_led&(1<<USB_LED_NUM_LOCK)) led &= ~(1<<2); | 37 | if (usb_led&(1<<USB_LED_NUM_LOCK)) led &= ~(1<<2); |
| 40 | if (usb_led&(1<<USB_LED_CAPS_LOCK)) led &= ~(1<<3); | 38 | if (usb_led&(1<<USB_LED_CAPS_LOCK)) led &= ~(1<<3); |
| 41 | if (usb_led&(1<<USB_LED_SCROLL_LOCK)) led &= ~(1<<1); | 39 | if (usb_led&(1<<USB_LED_SCROLL_LOCK)) led &= ~(1<<1); |
| 42 | if (usb_led&(1<<USB_LED_COMPOSE)) led &= ~(1<<4); | 40 | if (usb_led&(1<<USB_LED_COMPOSE)) led &= ~(1<<4); |
| 43 | if (usb_led&(1<<USB_LED_KANA)) led &= ~(1<<0); | 41 | if (usb_led&(1<<USB_LED_KANA)) led &= ~(1<<0); |
| 44 | xprintf("led: %02X\n", led); | 42 | serial_send(led); |
| 45 | x68k_send(led); | ||
| 46 | } | 43 | } |
diff --git a/converter/x68k_usb/matrix.c b/converter/x68k_usb/matrix.c index 954e7ef12..2d5a1e116 100644 --- a/converter/x68k_usb/matrix.c +++ b/converter/x68k_usb/matrix.c | |||
| @@ -21,8 +21,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 21 | #include <util/delay.h> | 21 | #include <util/delay.h> |
| 22 | #include "print.h" | 22 | #include "print.h" |
| 23 | #include "util.h" | 23 | #include "util.h" |
| 24 | #include "x68k.h" | 24 | #include "serial.h" |
| 25 | #include "matrix.h" | 25 | #include "matrix.h" |
| 26 | #include "debug.h" | ||
| 26 | 27 | ||
| 27 | 28 | ||
| 28 | /* | 29 | /* |
| @@ -63,7 +64,7 @@ uint8_t matrix_cols(void) | |||
| 63 | 64 | ||
| 64 | void matrix_init(void) | 65 | void matrix_init(void) |
| 65 | { | 66 | { |
| 66 | x68k_init(); | 67 | serial_init(); |
| 67 | 68 | ||
| 68 | // initialize matrix state: all keys off | 69 | // initialize matrix state: all keys off |
| 69 | for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00; | 70 | for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00; |
| @@ -75,13 +76,13 @@ uint8_t matrix_scan(void) | |||
| 75 | { | 76 | { |
| 76 | is_modified = false; | 77 | is_modified = false; |
| 77 | 78 | ||
| 78 | uint8_t code; | 79 | uint16_t code; |
| 79 | code = x68k_recv(); | 80 | code = serial_recv2(); |
| 80 | if (code == 0) { | 81 | if (code == -1) { |
| 81 | return 0; | 82 | return 0; |
| 82 | } | 83 | } |
| 83 | 84 | ||
| 84 | phex(code); print(" "); | 85 | dprintf("%02X\n", code); |
| 85 | if (code&0x80) { | 86 | if (code&0x80) { |
| 86 | // break code | 87 | // break code |
| 87 | if (matrix_is_on(ROW(code), COL(code))) { | 88 | if (matrix_is_on(ROW(code), COL(code))) { |
diff --git a/protocol/x68k.c b/protocol/x68k.c deleted file mode 100644 index b54e3d9a8..000000000 --- a/protocol/x68k.c +++ /dev/null | |||
| @@ -1,81 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012 Jun WAKO <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This software is licensed with a Modified BSD License. | ||
| 5 | All of this is supposed to be Free Software, Open Source, DFSG-free, | ||
| 6 | GPL-compatible, and OK to use in both free and proprietary applications. | ||
| 7 | Additions and corrections to this file are welcome. | ||
| 8 | |||
| 9 | |||
| 10 | Redistribution and use in source and binary forms, with or without | ||
| 11 | modification, are permitted provided that the following conditions are met: | ||
| 12 | |||
| 13 | * Redistributions of source code must retain the above copyright | ||
| 14 | notice, this list of conditions and the following disclaimer. | ||
| 15 | |||
| 16 | * Redistributions in binary form must reproduce the above copyright | ||
| 17 | notice, this list of conditions and the following disclaimer in | ||
| 18 | the documentation and/or other materials provided with the | ||
| 19 | distribution. | ||
| 20 | |||
| 21 | * Neither the name of the copyright holders nor the names of | ||
| 22 | contributors may be used to endorse or promote products derived | ||
| 23 | from this software without specific prior written permission. | ||
| 24 | |||
| 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 26 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 27 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 28 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 29 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 30 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 31 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 32 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 33 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 35 | POSSIBILITY OF SUCH DAMAGE. | ||
| 36 | */ | ||
| 37 | |||
| 38 | #include <stdbool.h> | ||
| 39 | #include <avr/io.h> | ||
| 40 | #include <avr/interrupt.h> | ||
| 41 | #include "x68k.h" | ||
| 42 | |||
| 43 | |||
| 44 | void x68k_init(void) | ||
| 45 | { | ||
| 46 | KBD_RX_INIT(); | ||
| 47 | } | ||
| 48 | |||
| 49 | // RX ring buffer | ||
| 50 | #define RBUF_SIZE 8 | ||
| 51 | static uint8_t rbuf[RBUF_SIZE]; | ||
| 52 | static uint8_t rbuf_head = 0; | ||
| 53 | static uint8_t rbuf_tail = 0; | ||
| 54 | |||
| 55 | uint8_t x68k_recv(void) | ||
| 56 | { | ||
| 57 | uint8_t data = 0; | ||
| 58 | if (rbuf_head == rbuf_tail) { | ||
| 59 | return 0; | ||
| 60 | } | ||
| 61 | |||
| 62 | data = rbuf[rbuf_tail]; | ||
| 63 | rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE; | ||
| 64 | return data; | ||
| 65 | } | ||
| 66 | |||
| 67 | void x68k_send(uint8_t d) | ||
| 68 | { | ||
| 69 | while (!(UCSR1A&(1<<UDRE1))); | ||
| 70 | UDR1 = d; | ||
| 71 | } | ||
| 72 | |||
| 73 | // USART RX complete interrupt | ||
| 74 | ISR(KBD_RX_VECT) | ||
| 75 | { | ||
| 76 | uint8_t next = (rbuf_head + 1) % RBUF_SIZE; | ||
| 77 | if (next != rbuf_tail) { | ||
| 78 | rbuf[rbuf_head] = KBD_RX_DATA; | ||
| 79 | rbuf_head = next; | ||
| 80 | } | ||
| 81 | } | ||
diff --git a/protocol/x68k.h b/protocol/x68k.h deleted file mode 100644 index 0d9c7de80..000000000 --- a/protocol/x68k.h +++ /dev/null | |||
| @@ -1,48 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012 Jun WAKO <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This software is licensed with a Modified BSD License. | ||
| 5 | All of this is supposed to be Free Software, Open Source, DFSG-free, | ||
| 6 | GPL-compatible, and OK to use in both free and proprietary applications. | ||
| 7 | Additions and corrections to this file are welcome. | ||
| 8 | |||
| 9 | |||
| 10 | Redistribution and use in source and binary forms, with or without | ||
| 11 | modification, are permitted provided that the following conditions are met: | ||
| 12 | |||
| 13 | * Redistributions of source code must retain the above copyright | ||
| 14 | notice, this list of conditions and the following disclaimer. | ||
| 15 | |||
| 16 | * Redistributions in binary form must reproduce the above copyright | ||
| 17 | notice, this list of conditions and the following disclaimer in | ||
| 18 | the documentation and/or other materials provided with the | ||
| 19 | distribution. | ||
| 20 | |||
| 21 | * Neither the name of the copyright holders nor the names of | ||
| 22 | contributors may be used to endorse or promote products derived | ||
| 23 | from this software without specific prior written permission. | ||
| 24 | |||
| 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 26 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 27 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 28 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 29 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 30 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 31 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 32 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 33 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 35 | POSSIBILITY OF SUCH DAMAGE. | ||
| 36 | */ | ||
| 37 | |||
| 38 | #ifndef X68K_H | ||
| 39 | #define X68K_H | ||
| 40 | |||
| 41 | /* host role */ | ||
| 42 | void x68k_init(void); | ||
| 43 | uint8_t x68k_recv(void); | ||
| 44 | void x68k_send(uint8_t d); | ||
| 45 | |||
| 46 | /* device role */ | ||
| 47 | |||
| 48 | #endif | ||
