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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

xt_io_avr.c 829B

12345678910111213141516171819202122232425262728293031323334
  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(XT_CLOCK_PORT) && \
  6. defined(XT_CLOCK_PIN) && \
  7. defined(XT_CLOCK_DDR) && \
  8. defined(XT_CLOCK_BIT))
  9. # error "XT clock port setting is required in config.h"
  10. #endif
  11. #if !(defined(XT_DATA_PORT) && \
  12. defined(XT_DATA_PIN) && \
  13. defined(XT_DATA_DDR) && \
  14. defined(XT_DATA_BIT))
  15. # error "XT data port setting is required in config.h"
  16. #endif
  17. bool clock_in(void)
  18. {
  19. XT_CLOCK_DDR &= ~(1<<XT_CLOCK_BIT);
  20. XT_CLOCK_PORT |= (1<<XT_CLOCK_BIT);
  21. _delay_us(1);
  22. return XT_CLOCK_PIN&(1<<XT_CLOCK_BIT);
  23. }
  24. bool data_in(void)
  25. {
  26. XT_DATA_DDR &= ~(1<<XT_DATA_BIT);
  27. XT_DATA_PORT |= (1<<XT_DATA_BIT);
  28. _delay_us(1);
  29. return XT_DATA_PIN&(1<<XT_DATA_BIT);
  30. }