Mirror of CollapseOS
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.

29 line
517B

  1. #include "rc2014_spi.h"
  2. void spi_init(SPI *spi, EXCH spixfn)
  3. {
  4. spi->selected = false;
  5. spi->resp = 0xff;
  6. spi->spixfn = spixfn;
  7. }
  8. // TODO: for now, any nonzero value enables the SPI. To allow
  9. // emulation of systems with multi-devices SPI relay, change
  10. // this.
  11. void spi_ctl_wr(SPI *spi, byte val)
  12. {
  13. spi->selected = val;
  14. }
  15. void spi_wr(SPI *spi, byte val)
  16. {
  17. if (spi->selected) {
  18. spi->resp = spi->spixfn(val);
  19. }
  20. }
  21. byte spi_rd(SPI *spi)
  22. {
  23. return spi->selected ? spi->resp : 0xff;
  24. }