Mirror of CollapseOS
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

31 строка
1.0KB

  1. #include "emul.h"
  2. /* This emulates a SPI device being connected directly on a controller port.
  3. TH and TR control CLK and DI, input bit 0 (BTN_UP) is DO.
  4. This device has to "pulse" frequently so that it checks whether there's
  5. been a change in CLK.
  6. We have a bit of a challenge here with regards to an important limitation
  7. of the SMS: only 2 pins can be set as output. Without the ability to
  8. programatically select the SPI slave, we have to keep it selected at all
  9. times. This makes us vulnerable to going out of sync. This is a known
  10. limitation, the user will have to re-insert the SD card when that happens.
  11. */
  12. typedef struct {
  13. Tristate *TH; // CLK
  14. Tristate *TR; // DI
  15. Tristate lastTH; // value of TH on last pulse
  16. byte bitcnt; // current xchange bit count
  17. bool bit; // bit to return in spi_rd()
  18. byte rx;
  19. byte tx;
  20. EXCH spixfn;
  21. } SPI;
  22. void spi_init(SPI *spi, Tristate *TH, Tristate *TR, EXCH spixfn);
  23. byte spi_rd(SPI *spi); // for sms_ports' portX_rd
  24. void spi_pulse(SPI *spi);