diff options
author | tmk <nobody@nowhere> | 2012-10-21 22:37:50 +0900 |
---|---|---|
committer | tmk <nobody@nowhere> | 2012-10-21 22:37:50 +0900 |
commit | 0ffd4ae3a9470e4efe41880db27a6ae77ccf1ce2 (patch) | |
tree | e6e99419ce37e0922ebf7e419e93cfd13d93e25f | |
parent | 454f7bc71657020d0574e849dad92a14e71230c4 (diff) | |
parent | f291c2279eb9f656ed2a2e3152bab155470c4ef9 (diff) | |
download | qmk_firmware-0ffd4ae3a9470e4efe41880db27a6ae77ccf1ce2.tar.gz qmk_firmware-0ffd4ae3a9470e4efe41880db27a6ae77ccf1ce2.zip |
Merge branch 'sun'
-rw-r--r-- | common/keyboard.c | 7 | ||||
-rw-r--r-- | converter/sun_usb/Makefile | 1 | ||||
-rw-r--r-- | converter/sun_usb/command_extra.c | 43 | ||||
-rw-r--r-- | converter/sun_usb/config.h | 17 | ||||
-rw-r--r-- | converter/sun_usb/led.c | 10 | ||||
-rw-r--r-- | protocol/serial.h | 1 | ||||
-rw-r--r-- | protocol/serial_soft.c | 57 |
7 files changed, 118 insertions, 18 deletions
diff --git a/common/keyboard.c b/common/keyboard.c index e973c46d5b..b0e0ed7935 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -555,6 +555,7 @@ void keyboard_init(void) void keyboard_task(void) { static matrix_row_t matrix_prev[MATRIX_ROWS]; + static uint8_t led_status = 0; matrix_row_t matrix_row = 0; matrix_row_t matrix_change = 0; @@ -617,6 +618,12 @@ void keyboard_task(void) } } + // update LED + if (led_status != host_keyboard_leds()) { + led_status = host_keyboard_leds(); + keyboard_set_leds(led_status); + } + return; } diff --git a/converter/sun_usb/Makefile b/converter/sun_usb/Makefile index 4c79a8d278..c6e8390cc9 100644 --- a/converter/sun_usb/Makefile +++ b/converter/sun_usb/Makefile @@ -11,6 +11,7 @@ TARGET_DIR = . SRC = keymap.c \ matrix.c \ led.c \ + command_extra.c \ protocol/serial_soft.c CONFIG_H = config.h diff --git a/converter/sun_usb/command_extra.c b/converter/sun_usb/command_extra.c new file mode 100644 index 0000000000..50389467ea --- /dev/null +++ b/converter/sun_usb/command_extra.c @@ -0,0 +1,43 @@ +#include "stdbool.h" +#include "stdint.h" +#include "keycode.h" +#include "serial.h" +#include "print.h" +#include "command.h" + +bool command_extra(uint8_t code) +{ + switch (code) { + case KC_H: + case KC_SLASH: /* ? */ + print("\n\n----- Sun converter Help -----\n"); + print("UP: Bell On\n"); + print("DOWN: Bell Off\n"); + print("LEFT: Click On\n"); + print("RIGHT: Click Off\n"); + return false; + case KC_UP: + print("Bell On\n"); + serial_send(0x02); + break; + case KC_DOWN: + print("Bell Off\n"); + serial_send(0x03); + break; + case KC_LEFT: + print("Click On\n"); + serial_send(0x0A); + break; + case KC_RIGHT: + print("Click Off\n"); + serial_send(0x0B); + break; + case KC_NUMLOCK: + print("layout\n"); + serial_send(0x0F); + break; + default: + return false; + } + return true; +} diff --git a/converter/sun_usb/config.h b/converter/sun_usb/config.h index 66961d9330..b4f0ff977a 100644 --- a/converter/sun_usb/config.h +++ b/converter/sun_usb/config.h @@ -43,8 +43,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. * asynchronous, negative logic, 1200baud, no flow control * 1-start bit, 8-data bit, non parity, 1-stop bit */ -#define SERIAL_NEGATIVE_LOGIC #define SERIAL_BAUD 1200 + #define SERIAL_RXD_DDR DDRD #define SERIAL_RXD_PORT PORTD #define SERIAL_RXD_PIN PIND @@ -63,5 +63,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. /* clear interrupt flag */ \ EIFR = (1<<INTF2); \ } while (0) +#define SERIAL_RXD_READ() (~SERIAL_RXD_PIN&(1<<SERIAL_RXD_BIT)) + +#define SERIAL_TXD_DDR DDRD +#define SERIAL_TXD_PORT PORTD +#define SERIAL_TXD_PIN PIND +#define SERIAL_TXD_BIT 3 +/* negative logic */ +#define SERIAL_TXD_ON() do { SERIAL_TXD_PORT &= ~(1<<SERIAL_TXD_BIT); } while (0) +#define SERIAL_TXD_OFF() do { SERIAL_TXD_PORT |= (1<<SERIAL_TXD_BIT); } while (0) +#define SERIAL_TXD_INIT() do { \ + /* pin configuration: output */ \ + SERIAL_TXD_DDR |= (1<<SERIAL_TXD_BIT); \ + /* idle */ \ + SERIAL_TXD_ON(); \ +} while (0) #endif diff --git a/converter/sun_usb/led.c b/converter/sun_usb/led.c index 5490ec0c62..48c3f1c2b2 100644 --- a/converter/sun_usb/led.c +++ b/converter/sun_usb/led.c @@ -16,10 +16,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "stdint.h" +#include "serial.h" #include "led.h" void led_set(uint8_t usb_led) { - // not supported now + uint8_t sun_led = 0; + if (usb_led & (1<<USB_LED_NUM_LOCK)) sun_led |= (1<<0); + if (usb_led & (1<<USB_LED_COMPOSE)) sun_led |= (1<<1); + if (usb_led & (1<<USB_LED_SCROLL_LOCK)) sun_led |= (1<<2); + if (usb_led & (1<<USB_LED_CAPS_LOCK)) sun_led |= (1<<3); + + serial_send(0x0E); + serial_send(sun_led); } diff --git a/protocol/serial.h b/protocol/serial.h index 93b9ee9225..bd071bec92 100644 --- a/protocol/serial.h +++ b/protocol/serial.h @@ -41,5 +41,6 @@ POSSIBILITY OF SUCH DAMAGE. /* host role */ void serial_init(void); uint8_t serial_recv(void); +void serial_send(uint8_t data); #endif diff --git a/protocol/serial_soft.c b/protocol/serial_soft.c index b7d06b644e..beddc353c0 100644 --- a/protocol/serial_soft.c +++ b/protocol/serial_soft.c @@ -51,9 +51,10 @@ POSSIBILITY OF SUCH DAMAGE. void serial_init(void) { SERIAL_RXD_INIT(); + SERIAL_TXD_INIT(); } -// RX ring buffer +/* RX ring buffer */ #define RBUF_SIZE 8 static uint8_t rbuf[RBUF_SIZE]; static uint8_t rbuf_head = 0; @@ -71,39 +72,63 @@ uint8_t serial_recv(void) return data; } -//ISR(INT2_vect) +void serial_send(uint8_t data) +{ + /* signal state: IDLE: ON, START: OFF, STOP: ON, DATA0: OFF, DATA1: ON */ + /* start bit */ + SERIAL_TXD_OFF(); + _delay_us(WAIT_US); + +#ifdef SERIAL_BIT_ORDER_MSB + uint8_t mask = 0x80; +#else + uint8_t mask = 0x01; +#endif + while (mask) { + if (data&mask) { SERIAL_TXD_ON(); } else { SERIAL_TXD_OFF(); } + _delay_us(WAIT_US); + +#ifdef SERIAL_BIT_ORDER_MSB + mask >>= 1; +#else + mask <<= 1; +#endif + } + + /* stop bit */ + SERIAL_TXD_ON(); + _delay_us(WAIT_US); +} + +/* detect edge of start bit */ ISR(SERIAL_RXD_VECT) { SERIAL_RXD_INT_ENTER() uint8_t data = 0; #ifdef SERIAL_BIT_ORDER_MSB - uint8_t pos = 0x80; + uint8_t mask = 0x80; #else - uint8_t pos = 0x01; + uint8_t mask = 0x01; #endif - // to center of start bit + /* to center of start bit */ _delay_us(WAIT_US/2); do { - // to center of next bit + /* to center of next bit */ _delay_us(WAIT_US); - if (SERIAL_RXD_PIN&(1<<SERIAL_RXD_BIT)) { - data |= pos; + if (SERIAL_RXD_READ()) { + data |= mask; } #ifdef SERIAL_BIT_ORDER_MSB - pos >>= 1; + mask >>= 1; #else - pos <<= 1; + mask <<= 1; #endif - } while (pos); - // to center of stop bit + } while (mask); + /* to center of stop bit */ _delay_us(WAIT_US); -#ifdef SERIAL_NEGATIVE_LOGIC - data = ~data; -#endif - uint8_t next = (rbuf_head + 1) % RBUF_SIZE; if (next != rbuf_tail) { rbuf[rbuf_head] = data; |