diff options
| author | tmk <nobody@nowhere> | 2012-10-21 22:12:36 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2012-10-21 22:12:36 +0900 |
| commit | edce1d19a6af040df994243e7b6b1851e3eccebc (patch) | |
| tree | 3f8d385a39979dcabdefea019e9671503cda8eba | |
| parent | 454f7bc71657020d0574e849dad92a14e71230c4 (diff) | |
| download | qmk_firmware-edce1d19a6af040df994243e7b6b1851e3eccebc.tar.gz qmk_firmware-edce1d19a6af040df994243e7b6b1851e3eccebc.zip | |
Add LED feature to Sun converter
| -rw-r--r-- | common/keyboard.c | 7 | ||||
| -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 |
5 files changed, 74 insertions, 18 deletions
diff --git a/common/keyboard.c b/common/keyboard.c index e973c46d5..b0e0ed793 100644 --- a/common/keyboard.c +++ b/common/keyboard.c | |||
| @@ -555,6 +555,7 @@ void keyboard_init(void) | |||
| 555 | void keyboard_task(void) | 555 | void keyboard_task(void) |
| 556 | { | 556 | { |
| 557 | static matrix_row_t matrix_prev[MATRIX_ROWS]; | 557 | static matrix_row_t matrix_prev[MATRIX_ROWS]; |
| 558 | static uint8_t led_status = 0; | ||
| 558 | matrix_row_t matrix_row = 0; | 559 | matrix_row_t matrix_row = 0; |
| 559 | matrix_row_t matrix_change = 0; | 560 | matrix_row_t matrix_change = 0; |
| 560 | 561 | ||
| @@ -617,6 +618,12 @@ void keyboard_task(void) | |||
| 617 | } | 618 | } |
| 618 | } | 619 | } |
| 619 | 620 | ||
| 621 | // update LED | ||
| 622 | if (led_status != host_keyboard_leds()) { | ||
| 623 | led_status = host_keyboard_leds(); | ||
| 624 | keyboard_set_leds(led_status); | ||
| 625 | } | ||
| 626 | |||
| 620 | return; | 627 | return; |
| 621 | } | 628 | } |
| 622 | 629 | ||
diff --git a/converter/sun_usb/config.h b/converter/sun_usb/config.h index 66961d933..b4f0ff977 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/>. | |||
| 43 | * asynchronous, negative logic, 1200baud, no flow control | 43 | * asynchronous, negative logic, 1200baud, no flow control |
| 44 | * 1-start bit, 8-data bit, non parity, 1-stop bit | 44 | * 1-start bit, 8-data bit, non parity, 1-stop bit |
| 45 | */ | 45 | */ |
| 46 | #define SERIAL_NEGATIVE_LOGIC | ||
| 47 | #define SERIAL_BAUD 1200 | 46 | #define SERIAL_BAUD 1200 |
| 47 | |||
| 48 | #define SERIAL_RXD_DDR DDRD | 48 | #define SERIAL_RXD_DDR DDRD |
| 49 | #define SERIAL_RXD_PORT PORTD | 49 | #define SERIAL_RXD_PORT PORTD |
| 50 | #define SERIAL_RXD_PIN PIND | 50 | #define SERIAL_RXD_PIN PIND |
| @@ -63,5 +63,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 63 | /* clear interrupt flag */ \ | 63 | /* clear interrupt flag */ \ |
| 64 | EIFR = (1<<INTF2); \ | 64 | EIFR = (1<<INTF2); \ |
| 65 | } while (0) | 65 | } while (0) |
| 66 | #define SERIAL_RXD_READ() (~SERIAL_RXD_PIN&(1<<SERIAL_RXD_BIT)) | ||
| 67 | |||
| 68 | #define SERIAL_TXD_DDR DDRD | ||
| 69 | #define SERIAL_TXD_PORT PORTD | ||
| 70 | #define SERIAL_TXD_PIN PIND | ||
| 71 | #define SERIAL_TXD_BIT 3 | ||
| 72 | /* negative logic */ | ||
| 73 | #define SERIAL_TXD_ON() do { SERIAL_TXD_PORT &= ~(1<<SERIAL_TXD_BIT); } while (0) | ||
| 74 | #define SERIAL_TXD_OFF() do { SERIAL_TXD_PORT |= (1<<SERIAL_TXD_BIT); } while (0) | ||
| 75 | #define SERIAL_TXD_INIT() do { \ | ||
| 76 | /* pin configuration: output */ \ | ||
| 77 | SERIAL_TXD_DDR |= (1<<SERIAL_TXD_BIT); \ | ||
| 78 | /* idle */ \ | ||
| 79 | SERIAL_TXD_ON(); \ | ||
| 80 | } while (0) | ||
| 66 | 81 | ||
| 67 | #endif | 82 | #endif |
diff --git a/converter/sun_usb/led.c b/converter/sun_usb/led.c index 5490ec0c6..48c3f1c2b 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/>. | |||
| 16 | */ | 16 | */ |
| 17 | 17 | ||
| 18 | #include "stdint.h" | 18 | #include "stdint.h" |
| 19 | #include "serial.h" | ||
| 19 | #include "led.h" | 20 | #include "led.h" |
| 20 | 21 | ||
| 21 | 22 | ||
| 22 | void led_set(uint8_t usb_led) | 23 | void led_set(uint8_t usb_led) |
| 23 | { | 24 | { |
| 24 | // not supported now | 25 | uint8_t sun_led = 0; |
| 26 | if (usb_led & (1<<USB_LED_NUM_LOCK)) sun_led |= (1<<0); | ||
| 27 | if (usb_led & (1<<USB_LED_COMPOSE)) sun_led |= (1<<1); | ||
| 28 | if (usb_led & (1<<USB_LED_SCROLL_LOCK)) sun_led |= (1<<2); | ||
| 29 | if (usb_led & (1<<USB_LED_CAPS_LOCK)) sun_led |= (1<<3); | ||
| 30 | |||
| 31 | serial_send(0x0E); | ||
| 32 | serial_send(sun_led); | ||
| 25 | } | 33 | } |
diff --git a/protocol/serial.h b/protocol/serial.h index 93b9ee922..bd071bec9 100644 --- a/protocol/serial.h +++ b/protocol/serial.h | |||
| @@ -41,5 +41,6 @@ POSSIBILITY OF SUCH DAMAGE. | |||
| 41 | /* host role */ | 41 | /* host role */ |
| 42 | void serial_init(void); | 42 | void serial_init(void); |
| 43 | uint8_t serial_recv(void); | 43 | uint8_t serial_recv(void); |
| 44 | void serial_send(uint8_t data); | ||
| 44 | 45 | ||
| 45 | #endif | 46 | #endif |
diff --git a/protocol/serial_soft.c b/protocol/serial_soft.c index b7d06b644..beddc353c 100644 --- a/protocol/serial_soft.c +++ b/protocol/serial_soft.c | |||
| @@ -51,9 +51,10 @@ POSSIBILITY OF SUCH DAMAGE. | |||
| 51 | void serial_init(void) | 51 | void serial_init(void) |
| 52 | { | 52 | { |
| 53 | SERIAL_RXD_INIT(); | 53 | SERIAL_RXD_INIT(); |
| 54 | SERIAL_TXD_INIT(); | ||
| 54 | } | 55 | } |
| 55 | 56 | ||
| 56 | // RX ring buffer | 57 | /* RX ring buffer */ |
| 57 | #define RBUF_SIZE 8 | 58 | #define RBUF_SIZE 8 |
| 58 | static uint8_t rbuf[RBUF_SIZE]; | 59 | static uint8_t rbuf[RBUF_SIZE]; |
| 59 | static uint8_t rbuf_head = 0; | 60 | static uint8_t rbuf_head = 0; |
| @@ -71,39 +72,63 @@ uint8_t serial_recv(void) | |||
| 71 | return data; | 72 | return data; |
| 72 | } | 73 | } |
| 73 | 74 | ||
| 74 | //ISR(INT2_vect) | 75 | void serial_send(uint8_t data) |
| 76 | { | ||
| 77 | /* signal state: IDLE: ON, START: OFF, STOP: ON, DATA0: OFF, DATA1: ON */ | ||
| 78 | /* start bit */ | ||
| 79 | SERIAL_TXD_OFF(); | ||
| 80 | _delay_us(WAIT_US); | ||
| 81 | |||
| 82 | #ifdef SERIAL_BIT_ORDER_MSB | ||
| 83 | uint8_t mask = 0x80; | ||
| 84 | #else | ||
| 85 | uint8_t mask = 0x01; | ||
| 86 | #endif | ||
| 87 | while (mask) { | ||
| 88 | if (data&mask) { SERIAL_TXD_ON(); } else { SERIAL_TXD_OFF(); } | ||
| 89 | _delay_us(WAIT_US); | ||
| 90 | |||
| 91 | #ifdef SERIAL_BIT_ORDER_MSB | ||
| 92 | mask >>= 1; | ||
| 93 | #else | ||
| 94 | mask <<= 1; | ||
| 95 | #endif | ||
| 96 | } | ||
| 97 | |||
| 98 | /* stop bit */ | ||
| 99 | SERIAL_TXD_ON(); | ||
| 100 | _delay_us(WAIT_US); | ||
| 101 | } | ||
| 102 | |||
| 103 | /* detect edge of start bit */ | ||
| 75 | ISR(SERIAL_RXD_VECT) | 104 | ISR(SERIAL_RXD_VECT) |
| 76 | { | 105 | { |
| 77 | SERIAL_RXD_INT_ENTER() | 106 | SERIAL_RXD_INT_ENTER() |
| 78 | 107 | ||
| 79 | uint8_t data = 0; | 108 | uint8_t data = 0; |
| 80 | #ifdef SERIAL_BIT_ORDER_MSB | 109 | #ifdef SERIAL_BIT_ORDER_MSB |
| 81 | uint8_t pos = 0x80; | 110 | uint8_t mask = 0x80; |
| 82 | #else | 111 | #else |
| 83 | uint8_t pos = 0x01; | 112 | uint8_t mask = 0x01; |
| 84 | #endif | 113 | #endif |
| 85 | // to center of start bit | 114 | /* to center of start bit */ |
| 86 | _delay_us(WAIT_US/2); | 115 | _delay_us(WAIT_US/2); |
| 87 | do { | 116 | do { |
| 88 | // to center of next bit | 117 | /* to center of next bit */ |
| 89 | _delay_us(WAIT_US); | 118 | _delay_us(WAIT_US); |
| 90 | 119 | ||
| 91 | if (SERIAL_RXD_PIN&(1<<SERIAL_RXD_BIT)) { | 120 | if (SERIAL_RXD_READ()) { |
| 92 | data |= pos; | 121 | data |= mask; |
| 93 | } | 122 | } |
| 94 | #ifdef SERIAL_BIT_ORDER_MSB | 123 | #ifdef SERIAL_BIT_ORDER_MSB |
| 95 | pos >>= 1; | 124 | mask >>= 1; |
| 96 | #else | 125 | #else |
| 97 | pos <<= 1; | 126 | mask <<= 1; |
| 98 | #endif | 127 | #endif |
| 99 | } while (pos); | 128 | } while (mask); |
| 100 | // to center of stop bit | 129 | /* to center of stop bit */ |
| 101 | _delay_us(WAIT_US); | 130 | _delay_us(WAIT_US); |
| 102 | 131 | ||
| 103 | #ifdef SERIAL_NEGATIVE_LOGIC | ||
| 104 | data = ~data; | ||
| 105 | #endif | ||
| 106 | |||
| 107 | uint8_t next = (rbuf_head + 1) % RBUF_SIZE; | 132 | uint8_t next = (rbuf_head + 1) % RBUF_SIZE; |
| 108 | if (next != rbuf_tail) { | 133 | if (next != rbuf_tail) { |
| 109 | rbuf[rbuf_head] = data; | 134 | rbuf[rbuf_head] = data; |
