From 04f351b80279c55dfc6c8028f95eab7e01d50c84 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 7 Feb 2011 14:59:07 +0900 Subject: PS/2 library receives data partially by interrupt --- ps2.c | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 146 insertions(+), 35 deletions(-) (limited to 'ps2.c') diff --git a/ps2.c b/ps2.c index dd5b24129..f7aaf96e3 100644 --- a/ps2.c +++ b/ps2.c @@ -1,5 +1,5 @@ /* -Copyright (c) 2010 Jun WAKO +Copyright (c) 2010,2011 Jun WAKO This software is licensed with a Modified BSD License. All of this is supposed to be Free Software, Open Source, DFSG-free, @@ -36,12 +36,13 @@ POSSIBILITY OF SUCH DAMAGE. */ #include #include +#include #include #include "ps2.h" -#include "print.h" #include "debug.h" +static uint8_t recv_data(void); static inline void clock_lo(void); static inline void clock_hi(void); static inline bool clock_in(void); @@ -52,6 +53,8 @@ static inline uint16_t wait_clock_lo(uint16_t us); static inline uint16_t wait_clock_hi(uint16_t us); static inline uint16_t wait_data_lo(uint16_t us); static inline uint16_t wait_data_hi(uint16_t us); +static inline void idle(void); +static inline void inhibit(void); /* @@ -79,38 +82,38 @@ http://www.mcamafia.de/pdf/ibm_hitrc07.pdf } \ } while (0) -#define WAIT_NORETRY(stat, us, err) do { \ - if (!wait_##stat(us)) { \ - ps2_error = err; \ - return 0; \ - } \ -} while (0) - uint8_t ps2_error = PS2_ERR_NONE; void ps2_host_init(void) { - /* inhibit */ - clock_lo(); - data_hi(); +#ifdef PS2_INT_ENABLE + PS2_INT_ENABLE(); + idle(); +#else + inhibit(); +#endif } uint8_t ps2_host_send(uint8_t data) { - bool parity = true; + bool parity; +RETRY: + parity = true; ps2_error = 0; - /* request to send */ - clock_lo(); + /* terminate a transmission if we have */ + inhibit(); _delay_us(100); + /* start bit [1] */ data_lo(); clock_hi(); WAIT(clock_lo, 15000, 1); /* data [2-9] */ for (uint8_t i = 0; i < 8; i++) { + _delay_us(15); if (data&(1<