|
@ -31,7 +31,7 @@ namespace FTDI { |
|
|
SPISettings SPI::spi_settings(SPI_FREQUENCY, MSBFIRST, SPI_MODE0); |
|
|
SPISettings SPI::spi_settings(SPI_FREQUENCY, MSBFIRST, SPI_MODE0); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
void SPI::spi_init (void) { |
|
|
void SPI::spi_init(void) { |
|
|
SET_OUTPUT(CLCD_MOD_RESET); // Module Reset (a.k.a. PD, not SPI)
|
|
|
SET_OUTPUT(CLCD_MOD_RESET); // Module Reset (a.k.a. PD, not SPI)
|
|
|
WRITE(CLCD_MOD_RESET, 0); // start with module in power-down
|
|
|
WRITE(CLCD_MOD_RESET, 0); // start with module in power-down
|
|
|
|
|
|
|
|
@ -63,20 +63,11 @@ namespace FTDI { |
|
|
uint8_t k; |
|
|
uint8_t k; |
|
|
|
|
|
|
|
|
noInterrupts(); |
|
|
noInterrupts(); |
|
|
for(k = 0; k <8; k++) { // Output and Read each bit of spiOutByte and spiInByte
|
|
|
for (k = 0; k < 8; k++) { // Output and Read each bit of spiOutByte and spiInByte
|
|
|
if (spiOutByte & spiIndex) { // Output MOSI Bit
|
|
|
WRITE(CLCD_SOFT_SPI_MOSI, (spiOutByte & spiIndex) ? 1 : 0); // Output MOSI Bit
|
|
|
WRITE(CLCD_SOFT_SPI_MOSI, 1); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
WRITE(CLCD_SOFT_SPI_MOSI, 0); |
|
|
|
|
|
} |
|
|
|
|
|
WRITE(CLCD_SOFT_SPI_SCLK, 1); // Pulse Clock
|
|
|
WRITE(CLCD_SOFT_SPI_SCLK, 1); // Pulse Clock
|
|
|
WRITE(CLCD_SOFT_SPI_SCLK, 0); |
|
|
WRITE(CLCD_SOFT_SPI_SCLK, 0); |
|
|
|
|
|
if (READ(CLCD_SOFT_SPI_MISO)) spiInByte |= spiIndex; |
|
|
if (READ(CLCD_SOFT_SPI_MISO)) { |
|
|
|
|
|
spiInByte |= spiIndex; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
spiIndex >>= 1; |
|
|
spiIndex >>= 1; |
|
|
} |
|
|
} |
|
|
interrupts(); |
|
|
interrupts(); |
|
@ -86,20 +77,13 @@ namespace FTDI { |
|
|
|
|
|
|
|
|
#ifdef CLCD_USE_SOFT_SPI |
|
|
#ifdef CLCD_USE_SOFT_SPI |
|
|
void SPI::_soft_spi_send (uint8_t spiOutByte) { |
|
|
void SPI::_soft_spi_send (uint8_t spiOutByte) { |
|
|
uint8_t spiIndex = 0x80; |
|
|
uint8_t k, spiIndex = 0x80; |
|
|
uint8_t k; |
|
|
|
|
|
|
|
|
|
|
|
noInterrupts(); |
|
|
noInterrupts(); |
|
|
for(k = 0; k <8; k++) { // Output each bit of spiOutByte
|
|
|
for (k = 0; k < 8; k++) { // Output each bit of spiOutByte
|
|
|
if (spiOutByte & spiIndex) { // Output MOSI Bit
|
|
|
WRITE(CLCD_SOFT_SPI_MOSI, (spiOutByte & spiIndex) ? 1 : 0); // Output MOSI Bit
|
|
|
WRITE(CLCD_SOFT_SPI_MOSI, 1); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
WRITE(CLCD_SOFT_SPI_MOSI, 0); |
|
|
|
|
|
} |
|
|
|
|
|
WRITE(CLCD_SOFT_SPI_SCLK, 1); // Pulse Clock
|
|
|
WRITE(CLCD_SOFT_SPI_SCLK, 1); // Pulse Clock
|
|
|
WRITE(CLCD_SOFT_SPI_SCLK, 0); |
|
|
WRITE(CLCD_SOFT_SPI_SCLK, 0); |
|
|
|
|
|
|
|
|
spiIndex >>= 1; |
|
|
spiIndex >>= 1; |
|
|
} |
|
|
} |
|
|
interrupts(); |
|
|
interrupts(); |
|
@ -122,7 +106,7 @@ namespace FTDI { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// CLCD SPI - Chip Select
|
|
|
// CLCD SPI - Chip Select
|
|
|
void SPI::spi_ftdi_select (void) { |
|
|
void SPI::spi_ftdi_select(void) { |
|
|
#ifndef CLCD_USE_SOFT_SPI |
|
|
#ifndef CLCD_USE_SOFT_SPI |
|
|
::SPI.beginTransaction(spi_settings); |
|
|
::SPI.beginTransaction(spi_settings); |
|
|
#endif |
|
|
#endif |
|
@ -131,7 +115,7 @@ namespace FTDI { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// CLCD SPI - Chip Deselect
|
|
|
// CLCD SPI - Chip Deselect
|
|
|
void SPI::spi_ftdi_deselect (void) { |
|
|
void SPI::spi_ftdi_deselect(void) { |
|
|
WRITE(CLCD_SPI_CS, 1); |
|
|
WRITE(CLCD_SPI_CS, 1); |
|
|
#ifndef CLCD_USE_SOFT_SPI |
|
|
#ifndef CLCD_USE_SOFT_SPI |
|
|
::SPI.endTransaction(); |
|
|
::SPI.endTransaction(); |
|
@ -158,7 +142,7 @@ namespace FTDI { |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
// Not really a SPI signal...
|
|
|
// Not really a SPI signal...
|
|
|
void SPI::ftdi_reset (void) { |
|
|
void SPI::ftdi_reset(void) { |
|
|
WRITE(CLCD_MOD_RESET, 0); |
|
|
WRITE(CLCD_MOD_RESET, 0); |
|
|
delay(6); /* minimum time for power-down is 5ms */ |
|
|
delay(6); /* minimum time for power-down is 5ms */ |
|
|
WRITE(CLCD_MOD_RESET, 1); |
|
|
WRITE(CLCD_MOD_RESET, 1); |
|
@ -166,8 +150,7 @@ namespace FTDI { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Not really a SPI signal...
|
|
|
// Not really a SPI signal...
|
|
|
void SPI::test_pulse(void) |
|
|
void SPI::test_pulse(void) { |
|
|
{ |
|
|
|
|
|
#ifdef CLCD_AUX_0 |
|
|
#ifdef CLCD_AUX_0 |
|
|
WRITE(CLCD_AUX_0, 1); |
|
|
WRITE(CLCD_AUX_0, 1); |
|
|
delayMicroseconds(10); |
|
|
delayMicroseconds(10); |
|
|