diff options
| author | tmk <nobody@nowhere> | 2014-02-10 06:43:43 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2014-02-10 06:46:43 +0900 |
| commit | 54a06c2520f6de4b33558b2203d6706a988d291c (patch) | |
| tree | 4cf5d47ecd90f6825c95197156605722b68847d3 /protocol | |
| parent | c4efadf68a5b1853f253dd9f28afb54c26bff796 (diff) | |
| download | qmk_firmware-54a06c2520f6de4b33558b2203d6706a988d291c.tar.gz qmk_firmware-54a06c2520f6de4b33558b2203d6706a988d291c.zip | |
Change error no and clean debug code
Diffstat (limited to 'protocol')
| -rw-r--r-- | protocol/ibm4704.c | 41 | ||||
| -rw-r--r-- | protocol/ibm4704.h | 1 |
2 files changed, 17 insertions, 25 deletions
diff --git a/protocol/ibm4704.c b/protocol/ibm4704.c index 26441ed52..d3fbcc541 100644 --- a/protocol/ibm4704.c +++ b/protocol/ibm4704.c | |||
| @@ -20,13 +20,7 @@ uint8_t ibm4704_error = 0; | |||
| 20 | 20 | ||
| 21 | void ibm4704_init(void) | 21 | void ibm4704_init(void) |
| 22 | { | 22 | { |
| 23 | // POR | ||
| 24 | //_delay_ms(2500); | ||
| 25 | //while ( 0xA3 != ibm4704_recv() ) ; | ||
| 26 | |||
| 27 | inhibit(); | 23 | inhibit(); |
| 28 | DDRD |= 1<<3; | ||
| 29 | PORTD &= ~(1<<3); | ||
| 30 | } | 24 | } |
| 31 | 25 | ||
| 32 | uint8_t ibm4704_send(uint8_t data) | 26 | uint8_t ibm4704_send(uint8_t data) |
| @@ -37,44 +31,43 @@ uint8_t ibm4704_send(uint8_t data) | |||
| 37 | /* Request to send */ | 31 | /* Request to send */ |
| 38 | idle(); | 32 | idle(); |
| 39 | clock_lo(); | 33 | clock_lo(); |
| 40 | PIND |= 1<<3; | ||
| 41 | 34 | ||
| 42 | /* wait for Start bit(Clock:lo/Data:hi) */ | 35 | /* wait for Start bit(Clock:lo/Data:hi) */ |
| 43 | WAIT(data_hi, 300, 0x30); | 36 | WAIT(data_hi, 300, 0x30); |
| 44 | 37 | ||
| 45 | /* Data bit */ | 38 | /* Data bit */ |
| 46 | for (uint8_t i = 0; i < 8; i++) { | 39 | for (uint8_t i = 0; i < 8; i++) { |
| 47 | WAIT(clock_hi, 100, 0x31); | 40 | WAIT(clock_hi, 100, 0x40+i); |
| 48 | //_delay_us(5); | 41 | //_delay_us(5); |
| 49 | PIND |= 1<<3; | ||
| 50 | if (data&(1<<i)) { | 42 | if (data&(1<<i)) { |
| 51 | parity = !parity; | 43 | parity = !parity; |
| 52 | data_hi(); | 44 | data_hi(); |
| 53 | } else { | 45 | } else { |
| 54 | data_lo(); | 46 | data_lo(); |
| 55 | } | 47 | } |
| 56 | WAIT(clock_lo, 100, 0x32); | 48 | WAIT(clock_lo, 100, 0x48+i); |
| 57 | } | 49 | } |
| 58 | 50 | ||
| 59 | /* Parity bit */ | 51 | /* Parity bit */ |
| 60 | WAIT(clock_hi, 100, 4); | 52 | WAIT(clock_hi, 100, 0x34); |
| 61 | PIND |= 1<<3; | ||
| 62 | if (parity) { data_hi(); } else { data_lo(); } | 53 | if (parity) { data_hi(); } else { data_lo(); } |
| 63 | WAIT(clock_lo, 100, 5); | 54 | WAIT(clock_lo, 100, 0x35); |
| 64 | 55 | ||
| 65 | /* Stop bit */ | 56 | /* Stop bit */ |
| 66 | WAIT(clock_hi, 100, 4); | 57 | WAIT(clock_hi, 100, 0x34); |
| 67 | data_hi(); | 58 | data_hi(); |
| 68 | 59 | ||
| 69 | /* End */ | 60 | /* End */ |
| 70 | WAIT(data_lo, 100, 6); | 61 | WAIT(data_lo, 100, 0x36); |
| 71 | 62 | ||
| 72 | inhibit(); | 63 | inhibit(); |
| 73 | _delay_us(200); // wait to recover clock to hi | 64 | _delay_us(200); // wait to recover clock to hi |
| 74 | return 0; | 65 | return 0; |
| 75 | ERROR: | 66 | ERROR: |
| 76 | inhibit(); | 67 | inhibit(); |
| 77 | xprintf("x%02X ", ibm4704_error); | 68 | if (ibm4704_error >= 0x30) { |
| 69 | xprintf("x%02X ", ibm4704_error); | ||
| 70 | } | ||
| 78 | _delay_us(200); // wait to recover clock to hi | 71 | _delay_us(200); // wait to recover clock to hi |
| 79 | return -1; | 72 | return -1; |
| 80 | } | 73 | } |
| @@ -110,10 +103,10 @@ uint8_t ibm4704_recv(void) | |||
| 110 | _delay_us(5); // wait for line settles | 103 | _delay_us(5); // wait for line settles |
| 111 | 104 | ||
| 112 | /* start bit */ | 105 | /* start bit */ |
| 113 | WAIT(clock_lo, 100, 1); // wait for keyboard to send | 106 | WAIT(clock_lo, 100, 0x11); // wait for keyboard to send |
| 114 | WAIT(data_hi, 100, 2); // can be delayed that long | 107 | WAIT(data_hi, 100, 0x12); // can be delayed that long |
| 115 | 108 | ||
| 116 | WAIT(clock_hi, 100, 3); // first rising edge which can take longer | 109 | WAIT(clock_hi, 100, 0x13); // first rising edge which can take longer |
| 117 | /* data */ | 110 | /* data */ |
| 118 | for (uint8_t i = 0; i < 8; i++) { | 111 | for (uint8_t i = 0; i < 8; i++) { |
| 119 | WAIT(clock_hi, 100, 0x20+i); | 112 | WAIT(clock_hi, 100, 0x20+i); |
| @@ -126,22 +119,22 @@ uint8_t ibm4704_recv(void) | |||
| 126 | } | 119 | } |
| 127 | 120 | ||
| 128 | /* parity */ | 121 | /* parity */ |
| 129 | WAIT(clock_hi, 100, 7); | 122 | WAIT(clock_hi, 100, 0x17); |
| 130 | if (data_in() != parity) { | 123 | if (data_in() != parity) { |
| 131 | ibm4704_error = IBM4704_ERR_PARITY; | 124 | ibm4704_error = IBM4704_ERR_PARITY; |
| 132 | goto ERROR; | 125 | goto ERROR; |
| 133 | } | 126 | } |
| 134 | WAIT(clock_lo, 150, 8); | 127 | WAIT(clock_lo, 150, 0x18); |
| 135 | 128 | ||
| 136 | /* stop bit */ | 129 | /* stop bit */ |
| 137 | WAIT(clock_hi, 100, 9); | 130 | WAIT(clock_hi, 100, 0x19); |
| 138 | WAIT(data_lo, 1, 9); | 131 | WAIT(data_lo, 1, 0x19); |
| 139 | 132 | ||
| 140 | inhibit(); | 133 | inhibit(); |
| 141 | _delay_us(200); // wait to recover clock to hi | 134 | _delay_us(200); // wait to recover clock to hi |
| 142 | return data; | 135 | return data; |
| 143 | ERROR: | 136 | ERROR: |
| 144 | if (ibm4704_error > 2) { | 137 | if (ibm4704_error > 0x12) { |
| 145 | xprintf("x%02X ", ibm4704_error); | 138 | xprintf("x%02X ", ibm4704_error); |
| 146 | } | 139 | } |
| 147 | inhibit(); | 140 | inhibit(); |
diff --git a/protocol/ibm4704.h b/protocol/ibm4704.h index ff8a5b771..618cce6be 100644 --- a/protocol/ibm4704.h +++ b/protocol/ibm4704.h | |||
| @@ -5,7 +5,6 @@ Copyright 2014 Jun WAKO <wakojun@gmail.com> | |||
| 5 | #define IBM4704_H | 5 | #define IBM4704_H |
| 6 | 6 | ||
| 7 | #define IBM4704_ERR_NONE 0 | 7 | #define IBM4704_ERR_NONE 0 |
| 8 | #define IBM4704_ERR_STARTBIT 1 | ||
| 9 | #define IBM4704_ERR_PARITY 0x70 | 8 | #define IBM4704_ERR_PARITY 0x70 |
| 10 | 9 | ||
| 11 | 10 | ||
