mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-14 15:28:05 +11:00
ce10320030
Theoretically, it works. I can access an emulated SD card on it. Will it work on real hardware? I've also made SMS emulation faster. It was unbearably slow for SDC access.
40 lines
812 B
C
40 lines
812 B
C
#include "sms_spi.h"
|
|
|
|
void spi_init(SPI *spi, Tristate *TH, Tristate *TR, EXCH spixfn)
|
|
{
|
|
spi->TH = TH;
|
|
spi->TR = TR;
|
|
spi->lastTH = *TH;
|
|
spi->bitcnt = 0;
|
|
spi->bit = false;
|
|
spi->rx = 0;
|
|
spi->tx = 0xff;
|
|
spi->spixfn = spixfn;
|
|
}
|
|
|
|
byte spi_rd(SPI *spi)
|
|
{
|
|
|
|
return (byte)spi->bit; // return in bit 0
|
|
}
|
|
|
|
void spi_pulse(SPI *spi)
|
|
{
|
|
if (*spi->TH != spi->lastTH) {
|
|
spi->lastTH = *spi->TH;
|
|
if (spi->lastTH == TRI_HIGH) {
|
|
spi->rx <<= 1;
|
|
if (*spi->TR == TRI_HIGH) {
|
|
spi->rx++;
|
|
}
|
|
spi->bit = spi->tx >> 7;
|
|
spi->tx <<= 1;
|
|
spi->bitcnt++;
|
|
if (spi->bitcnt == 8) {
|
|
spi->tx = spi->spixfn(spi->rx);
|
|
spi->bitcnt = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|