X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=ps2.c;h=6d76538fe4c0b7fb01e1bba26a00d25c9c669eb1;hb=2b8cd88ab142068eed0a3f230a3de79deb567536;hp=a388b7489203de15abca5580826c6adb16d506f1;hpb=1f5cd6d7dcbd18f2b647631600df13a0f6d64d25;p=max%2Ftmk_keyboard.git diff --git a/ps2.c b/ps2.c index a388b748..6d76538f 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<