mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-30 22:48:08 +11:00
29 lines
517 B
C
29 lines
517 B
C
|
#include "rc2014_spi.h"
|
||
|
|
||
|
void spi_init(SPI *spi, EXCH spixfn)
|
||
|
{
|
||
|
spi->selected = false;
|
||
|
spi->resp = 0xff;
|
||
|
spi->spixfn = spixfn;
|
||
|
}
|
||
|
|
||
|
// TODO: for now, any nonzero value enables the SPI. To allow
|
||
|
// emulation of systems with multi-devices SPI relay, change
|
||
|
// this.
|
||
|
void spi_ctl_wr(SPI *spi, byte val)
|
||
|
{
|
||
|
spi->selected = val;
|
||
|
}
|
||
|
|
||
|
void spi_wr(SPI *spi, byte val)
|
||
|
{
|
||
|
if (spi->selected) {
|
||
|
spi->resp = spi->spixfn(val);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
byte spi_rd(SPI *spi)
|
||
|
{
|
||
|
return spi->selected ? spi->resp : 0xff;
|
||
|
}
|