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

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