diff options
author | tmk <hasu@tmk-kbd.com> | 2015-04-10 01:32:04 +0900 |
---|---|---|
committer | tmk <hasu@tmk-kbd.com> | 2015-04-10 01:32:04 +0900 |
commit | 1a02ebcc612e9a9c0d87e02295c7258de3a70ccc (patch) | |
tree | e517f3c70bb2d542797e57d13e9023c84af230fb /tmk_core/protocol/ibm4704.h | |
parent | 6746e37088ce8ba03529c1226bd216705edb2b1f (diff) | |
parent | a074364c3731d66b56d988c8a6c960a83ea0e0a1 (diff) |
Merge commit 'a074364c3731d66b56d988c8a6c960a83ea0e0a1' as 'tmk_core'
Diffstat (limited to 'tmk_core/protocol/ibm4704.h')
-rw-r--r-- | tmk_core/protocol/ibm4704.h | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/tmk_core/protocol/ibm4704.h b/tmk_core/protocol/ibm4704.h new file mode 100644 index 0000000000..618cce6be0 --- /dev/null +++ b/tmk_core/protocol/ibm4704.h @@ -0,0 +1,110 @@ +/* +Copyright 2014 Jun WAKO <wakojun@gmail.com> +*/ +#ifndef IBM4704_H +#define IBM4704_H + +#define IBM4704_ERR_NONE 0 +#define IBM4704_ERR_PARITY 0x70 + + +void ibm4704_init(void); +uint8_t ibm4704_send(uint8_t data); +uint8_t ibm4704_recv_response(void); +uint8_t ibm4704_recv(void); + + +/* Check pin configuration */ +#if !(defined(IBM4704_CLOCK_PORT) && \ + defined(IBM4704_CLOCK_PIN) && \ + defined(IBM4704_CLOCK_DDR) && \ + defined(IBM4704_CLOCK_BIT)) +# error "ibm4704 clock pin configuration is required in config.h" +#endif + +#if !(defined(IBM4704_DATA_PORT) && \ + defined(IBM4704_DATA_PIN) && \ + defined(IBM4704_DATA_DDR) && \ + defined(IBM4704_DATA_BIT)) +# error "ibm4704 data pin configuration is required in config.h" +#endif + + +/*-------------------------------------------------------------------- + * static functions + *------------------------------------------------------------------*/ +static inline void clock_lo(void) +{ + IBM4704_CLOCK_PORT &= ~(1<<IBM4704_CLOCK_BIT); + IBM4704_CLOCK_DDR |= (1<<IBM4704_CLOCK_BIT); +} +static inline void clock_hi(void) +{ + /* input with pull up */ + IBM4704_CLOCK_DDR &= ~(1<<IBM4704_CLOCK_BIT); + IBM4704_CLOCK_PORT |= (1<<IBM4704_CLOCK_BIT); +} +static inline bool clock_in(void) +{ + IBM4704_CLOCK_DDR &= ~(1<<IBM4704_CLOCK_BIT); + IBM4704_CLOCK_PORT |= (1<<IBM4704_CLOCK_BIT); + _delay_us(1); + return IBM4704_CLOCK_PIN&(1<<IBM4704_CLOCK_BIT); +} +static inline void data_lo(void) +{ + IBM4704_DATA_PORT &= ~(1<<IBM4704_DATA_BIT); + IBM4704_DATA_DDR |= (1<<IBM4704_DATA_BIT); +} +static inline void data_hi(void) +{ + /* input with pull up */ + IBM4704_DATA_DDR &= ~(1<<IBM4704_DATA_BIT); + IBM4704_DATA_PORT |= (1<<IBM4704_DATA_BIT); +} +static inline bool data_in(void) +{ + IBM4704_DATA_DDR &= ~(1<<IBM4704_DATA_BIT); + IBM4704_DATA_PORT |= (1<<IBM4704_DATA_BIT); + _delay_us(1); + return IBM4704_DATA_PIN&(1<<IBM4704_DATA_BIT); +} + +static inline uint16_t wait_clock_lo(uint16_t us) +{ + while (clock_in() && us) { asm(""); _delay_us(1); us--; } + return us; +} +static inline uint16_t wait_clock_hi(uint16_t us) +{ + while (!clock_in() && us) { asm(""); _delay_us(1); us--; } + return us; +} +static inline uint16_t wait_data_lo(uint16_t us) +{ + while (data_in() && us) { asm(""); _delay_us(1); us--; } + return us; +} +static inline uint16_t wait_data_hi(uint16_t us) +{ + while (!data_in() && us) { asm(""); _delay_us(1); us--; } + return us; +} + +/* idle state that device can send */ +static inline void idle(void) +{ + clock_hi(); + data_hi(); +} + +/* inhibit device to send + * keyboard checks Data line on start bit(Data:hi) and it stops sending if Data line is low. + */ +static inline void inhibit(void) +{ + clock_hi(); + data_lo(); +} + +#endif |