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.

55 lines
1.1 KiB

  1. #include <stdbool.h>
  2. #include "ps2_io.h"
  3. #include "gpio.h"
  4. #include "wait.h"
  5. /* Check port settings for clock and data line */
  6. #if !(defined(PS2_CLOCK_PIN))
  7. # error "PS/2 clock setting is required in config.h"
  8. #endif
  9. #if !(defined(PS2_DATA_PIN))
  10. # error "PS/2 data setting is required in config.h"
  11. #endif
  12. /*
  13. * Clock
  14. */
  15. void clock_init(void) {}
  16. void clock_lo(void) {
  17. // Transition from input with pull-up to output low via Hi-Z instead of output high
  18. writePinLow(PS2_CLOCK_PIN);
  19. setPinOutput(PS2_CLOCK_PIN);
  20. }
  21. void clock_hi(void) {
  22. setPinInputHigh(PS2_CLOCK_PIN);
  23. }
  24. bool clock_in(void) {
  25. setPinInputHigh(PS2_CLOCK_PIN);
  26. wait_us(1);
  27. return readPin(PS2_CLOCK_PIN);
  28. }
  29. /*
  30. * Data
  31. */
  32. void data_init(void) {}
  33. void data_lo(void) {
  34. // Transition from input with pull-up to output low via Hi-Z instead of output high
  35. writePinLow(PS2_DATA_PIN);
  36. setPinOutput(PS2_DATA_PIN);
  37. }
  38. void data_hi(void) {
  39. setPinInputHigh(PS2_DATA_PIN);
  40. }
  41. bool data_in(void) {
  42. setPinInputHigh(PS2_DATA_PIN);
  43. wait_us(1);
  44. return readPin(PS2_DATA_PIN);
  45. }