Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ps2_io_avr.c 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include <stdbool.h>
  2. #include <util/delay.h>
  3. /* Check port settings for clock and data line */
  4. #if !(defined(PS2_CLOCK_PORT) && \
  5. defined(PS2_CLOCK_PIN) && \
  6. defined(PS2_CLOCK_DDR) && \
  7. defined(PS2_CLOCK_BIT))
  8. # error "PS/2 clock port setting is required in config.h"
  9. #endif
  10. #if !(defined(PS2_DATA_PORT) && \
  11. defined(PS2_DATA_PIN) && \
  12. defined(PS2_DATA_DDR) && \
  13. defined(PS2_DATA_BIT))
  14. # error "PS/2 data port setting is required in config.h"
  15. #endif
  16. /*
  17. * Clock
  18. */
  19. void clock_init(void)
  20. {
  21. }
  22. void clock_lo(void)
  23. {
  24. PS2_CLOCK_PORT &= ~(1<<PS2_CLOCK_BIT);
  25. PS2_CLOCK_DDR |= (1<<PS2_CLOCK_BIT);
  26. }
  27. void clock_hi(void)
  28. {
  29. /* input with pull up */
  30. PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT);
  31. PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT);
  32. }
  33. bool clock_in(void)
  34. {
  35. PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT);
  36. PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT);
  37. _delay_us(1);
  38. return PS2_CLOCK_PIN&(1<<PS2_CLOCK_BIT);
  39. }
  40. /*
  41. * Data
  42. */
  43. void data_init(void)
  44. {
  45. }
  46. void data_lo(void)
  47. {
  48. PS2_DATA_PORT &= ~(1<<PS2_DATA_BIT);
  49. PS2_DATA_DDR |= (1<<PS2_DATA_BIT);
  50. }
  51. void data_hi(void)
  52. {
  53. /* input with pull up */
  54. PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT);
  55. PS2_DATA_PORT |= (1<<PS2_DATA_BIT);
  56. }
  57. bool data_in(void)
  58. {
  59. PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT);
  60. PS2_DATA_PORT |= (1<<PS2_DATA_BIT);
  61. _delay_us(1);
  62. return PS2_DATA_PIN&(1<<PS2_DATA_BIT);
  63. }