diff options
Diffstat (limited to 'tmk_core/protocol/ps2_busywait.c')
-rw-r--r-- | tmk_core/protocol/ps2_busywait.c | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/tmk_core/protocol/ps2_busywait.c b/tmk_core/protocol/ps2_busywait.c index a64933219e..983194eea8 100644 --- a/tmk_core/protocol/ps2_busywait.c +++ b/tmk_core/protocol/ps2_busywait.c @@ -45,20 +45,17 @@ POSSIBILITY OF SUCH DAMAGE. #include "ps2_io.h" #include "debug.h" - -#define WAIT(stat, us, err) do { \ - if (!wait_##stat(us)) { \ - ps2_error = err; \ - goto ERROR; \ - } \ -} while (0) - +#define WAIT(stat, us, err) \ + do { \ + if (!wait_##stat(us)) { \ + ps2_error = err; \ + goto ERROR; \ + } \ + } while (0) uint8_t ps2_error = PS2_ERR_NONE; - -void ps2_host_init(void) -{ +void ps2_host_init(void) { clock_init(); data_init(); @@ -68,24 +65,23 @@ void ps2_host_init(void) inhibit(); } -uint8_t ps2_host_send(uint8_t data) -{ +uint8_t ps2_host_send(uint8_t data) { bool parity = true; - ps2_error = PS2_ERR_NONE; + ps2_error = PS2_ERR_NONE; /* terminate a transmission if we have */ inhibit(); - wait_us(100); // 100us [4]p.13, [5]p.50 + wait_us(100); // 100us [4]p.13, [5]p.50 /* 'Request to Send' and Start bit */ data_lo(); clock_hi(); - WAIT(clock_lo, 10000, 10); // 10ms [5]p.50 + WAIT(clock_lo, 10000, 10); // 10ms [5]p.50 /* Data bit */ for (uint8_t i = 0; i < 8; i++) { wait_us(15); - if (data&(1<<i)) { + if (data & (1 << i)) { parity = !parity; data_hi(); } else { @@ -97,7 +93,11 @@ uint8_t ps2_host_send(uint8_t data) /* Parity bit */ wait_us(15); - if (parity) { data_hi(); } else { data_lo(); } + if (parity) { + data_hi(); + } else { + data_lo(); + } WAIT(clock_hi, 50, 4); WAIT(clock_lo, 50, 5); @@ -121,30 +121,29 @@ ERROR: } /* receive data when host want else inhibit communication */ -uint8_t ps2_host_recv_response(void) -{ +uint8_t ps2_host_recv_response(void) { // Command may take 25ms/20ms at most([5]p.46, [3]p.21) // 250 * 100us(wait for start bit in ps2_host_recv) uint8_t data = 0; - uint8_t try = 250; + uint8_t try + = 250; do { data = ps2_host_recv(); - } while (try-- && ps2_error); + } while (try --&&ps2_error); return data; } /* called after start bit comes */ -uint8_t ps2_host_recv(void) -{ - uint8_t data = 0; - bool parity = true; - ps2_error = PS2_ERR_NONE; +uint8_t ps2_host_recv(void) { + uint8_t data = 0; + bool parity = true; + ps2_error = PS2_ERR_NONE; /* release lines(idle state) */ idle(); /* start bit [1] */ - WAIT(clock_lo, 100, 1); // TODO: this is enough? + WAIT(clock_lo, 100, 1); // TODO: this is enough? WAIT(data_lo, 1, 2); WAIT(clock_hi, 50, 3); @@ -153,7 +152,7 @@ uint8_t ps2_host_recv(void) WAIT(clock_lo, 50, 4); if (data_in()) { parity = !parity; - data |= (1<<i); + data |= (1 << i); } WAIT(clock_hi, 50, 5); } @@ -182,8 +181,7 @@ ERROR: } /* send LED state to keyboard */ -void ps2_host_set_led(uint8_t led) -{ +void ps2_host_set_led(uint8_t led) { ps2_host_send(0xED); ps2_host_send(led); } |