aboutsummaryrefslogtreecommitdiff
path: root/protocol/serial_soft.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-02-22 15:48:35 +0900
committertmk <nobody@nowhere>2013-02-22 15:48:35 +0900
commiteb776c1b7918f320b717cedfd8957f55e53c5adf (patch)
tree3eb6f3bbe629008b8286960894400b5caefc59b6 /protocol/serial_soft.c
parentf68c5bf0d30dc1300c71dabc63d2c2970f7337c9 (diff)
downloadqmk_firmware-eb776c1b7918f320b717cedfd8957f55e53c5adf.tar.gz
qmk_firmware-eb776c1b7918f320b717cedfd8957f55e53c5adf.zip
Quick Fix: read scan code from PC98
Diffstat (limited to 'protocol/serial_soft.c')
-rw-r--r--protocol/serial_soft.c42
1 files changed, 34 insertions, 8 deletions
diff --git a/protocol/serial_soft.c b/protocol/serial_soft.c
index e0661c3aa..47b1e4571 100644
--- a/protocol/serial_soft.c
+++ b/protocol/serial_soft.c
@@ -48,6 +48,23 @@ POSSIBILITY OF SUCH DAMAGE.
48 48
49#define WAIT_US (1000000/SERIAL_BAUD) 49#define WAIT_US (1000000/SERIAL_BAUD)
50 50
51#if 1
52#define WAIT_TICK (1000000/SERIAL_BAUD)
53#define WAIT4(tick) _delay_us(tick)
54#else
55#define WAIT_TICK ((16000000/SERIAL_BAUD)/4 - 5)
56static inline void WAIT4(uint8_t tick)
57{
58 __asm__ __volatile__ (
59 "1: dec %0" "\n\t"
60 "nop" "\n\t"
61 "brne 1b"
62 :
63 : "r" (tick)
64 );
65}
66#endif
67
51void serial_init(void) 68void serial_init(void)
52{ 69{
53 SERIAL_RXD_INIT(); 70 SERIAL_RXD_INIT();
@@ -60,6 +77,7 @@ static uint8_t rbuf[RBUF_SIZE];
60static uint8_t rbuf_head = 0; 77static uint8_t rbuf_head = 0;
61static uint8_t rbuf_tail = 0; 78static uint8_t rbuf_tail = 0;
62 79
80
63uint8_t serial_recv(void) 81uint8_t serial_recv(void)
64{ 82{
65 uint8_t data = 0; 83 uint8_t data = 0;
@@ -103,6 +121,7 @@ void serial_send(uint8_t data)
103/* detect edge of start bit */ 121/* detect edge of start bit */
104ISR(SERIAL_RXD_VECT) 122ISR(SERIAL_RXD_VECT)
105{ 123{
124PORTD ^= 1<<7;
106 SERIAL_RXD_INT_ENTER() 125 SERIAL_RXD_INT_ENTER()
107 126
108 uint8_t data = 0; 127 uint8_t data = 0;
@@ -120,11 +139,15 @@ ISR(SERIAL_RXD_VECT)
120#endif 139#endif
121 140
122 /* to center of start bit */ 141 /* to center of start bit */
123 _delay_us(WAIT_US/2); 142 //_delay_us(WAIT_US/2);
143 WAIT4(WAIT_TICK/2);
144PORTD ^= 1<<7;
124 do { 145 do {
125 /* to center of next bit */ 146 /* to center of next bit */
126 _delay_us(WAIT_US); 147 //_delay_us(WAIT_US);
148 WAIT4(WAIT_TICK);
127 149
150PORTD ^= 1<<7;
128 if (SERIAL_RXD_READ()) { 151 if (SERIAL_RXD_READ()) {
129 data |= mask; 152 data |= mask;
130 parity ^= 1; 153 parity ^= 1;
@@ -137,19 +160,22 @@ ISR(SERIAL_RXD_VECT)
137 } while (mask); 160 } while (mask);
138 161
139 /* to center of parity bit */ 162 /* to center of parity bit */
140 _delay_us(WAIT_US); 163 //_delay_us(WAIT_US);
141 parity ^= SERIAL_RXD_READ(); 164 WAIT4(WAIT_TICK);
165 if (SERIAL_RXD_READ()) { parity ^= 1; }
166PORTD ^= 1<<7;
142 167
143 /* to center of stop bit */ 168 /* to center of stop bit */
144 _delay_us(WAIT_US); 169 //_delay_us(WAIT_US);
145 _delay_us(WAIT_US/2); 170 WAIT4(WAIT_TICK);
146 171
147 parity = 1;
148 uint8_t next = (rbuf_head + 1) % RBUF_SIZE; 172 uint8_t next = (rbuf_head + 1) % RBUF_SIZE;
149 if (parity && next != rbuf_tail) { 173 //if (parity && next != rbuf_tail) {
174 if (next != rbuf_tail) {
150 rbuf[rbuf_head] = data; 175 rbuf[rbuf_head] = data;
151 rbuf_head = next; 176 rbuf_head = next;
152 } 177 }
153 178
154 SERIAL_RXD_INT_EXIT(); 179 SERIAL_RXD_INT_EXIT();
180PORTD ^= 1<<7;
155} 181}