123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- #ifndef PS2_H
- #define PS2_H
- #include <stdbool.h>
- #include "wait.h"
- #include "ps2_io.h"
- #include "print.h"
- #define PS2_ACK 0xFA
- #define PS2_RESEND 0xFE
- #define PS2_SET_LED 0xED
- #define PS2_ERR_NONE 0
- #define PS2_ERR_STARTBIT1 1
- #define PS2_ERR_STARTBIT2 2
- #define PS2_ERR_STARTBIT3 3
- #define PS2_ERR_PARITY 0x10
- #define PS2_ERR_NODATA 0x20
- #define PS2_LED_SCROLL_LOCK 0
- #define PS2_LED_NUM_LOCK 1
- #define PS2_LED_CAPS_LOCK 2
- extern uint8_t ps2_error;
- void ps2_host_init(void);
- uint8_t ps2_host_send(uint8_t data);
- uint8_t ps2_host_recv_response(void);
- uint8_t ps2_host_recv(void);
- void ps2_host_set_led(uint8_t usb_led);
- static inline uint16_t wait_clock_lo(uint16_t us)
- {
- while (clock_in() && us) { asm(""); wait_us(1); us--; }
- return us;
- }
- static inline uint16_t wait_clock_hi(uint16_t us)
- {
- while (!clock_in() && us) { asm(""); wait_us(1); us--; }
- return us;
- }
- static inline uint16_t wait_data_lo(uint16_t us)
- {
- while (data_in() && us) { asm(""); wait_us(1); us--; }
- return us;
- }
- static inline uint16_t wait_data_hi(uint16_t us)
- {
- while (!data_in() && us) { asm(""); wait_us(1); us--; }
- return us;
- }
- static inline void idle(void)
- {
- clock_hi();
- data_hi();
- }
- static inline void inhibit(void)
- {
- clock_lo();
- data_hi();
- }
- #endif
|