Fix startup PIN config issues with GPIO and DMA SPI

pull/17/head
Blackaddr 3 years ago
parent d91f04f293
commit 37b500b686
  1. 4
      src/BAGpio.h
  2. 14
      src/peripherals/BAGpio.cpp
  3. 68
      src/peripherals/BASpiMemory.cpp

@ -39,6 +39,10 @@ public:
BAGpio(); BAGpio();
virtual ~BAGpio(); virtual ~BAGpio();
/// resets the configuration of the GPIO pins. Call this after to call the
/// hardware config macro. E.g. TGA_PRO_REVB();
void begin();
/// Set the direction of the specified GPIO pin. /// Set the direction of the specified GPIO pin.
/// @param gpioId Specify a GPIO pin such as GPIO::GPIO0 /// @param gpioId Specify a GPIO pin such as GPIO::GPIO0
/// @param specify direction as INPUT or OUTPUT which are Arduino constants /// @param specify direction as INPUT or OUTPUT which are Arduino constants

@ -24,6 +24,15 @@
namespace BALibrary { namespace BALibrary {
BAGpio::BAGpio() BAGpio::BAGpio()
{
begin();
}
BAGpio::~BAGpio()
{
}
void BAGpio::begin()
{ {
// Set all GPIOs to input // Set all GPIOs to input
pinMode(GPIO0, INPUT); pinMode(GPIO0, INPUT);
@ -40,11 +49,6 @@ BAGpio::BAGpio()
// Set the LED to ouput // Set the LED to ouput
pinMode(USR_LED_ID, OUTPUT); pinMode(USR_LED_ID, OUTPUT);
clearLed(); // turn off the LED clearLed(); // turn off the LED
}
BAGpio::~BAGpio()
{
} }
void BAGpio::setGPIODirection(GPIO gpioId, int direction) void BAGpio::setGPIODirection(GPIO gpioId, int direction)

@ -364,52 +364,15 @@ void BASpiMemory::m_rawRead16(size_t address, uint16_t *dest, size_t numWords)
BASpiMemoryDMA::BASpiMemoryDMA(SpiDeviceId memDeviceId) BASpiMemoryDMA::BASpiMemoryDMA(SpiDeviceId memDeviceId)
: BASpiMemory(memDeviceId) : BASpiMemory(memDeviceId)
{ {
int cs; m_memDeviceId = memDeviceId;
switch (memDeviceId) { m_settings = {20000000, MSBFIRST, SPI_MODE0};
case SpiDeviceId::SPI_DEVICE0 :
cs = SPI0_CS_PIN;
m_cs = new ActiveLowChipSelect(cs, m_settings);
break;
#if defined(__MK66FX1M0__)
case SpiDeviceId::SPI_DEVICE1 :
cs = SPI1_CS_PIN;
m_cs = new ActiveLowChipSelect1(cs, m_settings);
break;
#endif
default :
cs = SPI0_CS_PIN;
}
// add 4 bytes to buffer for SPI CMD and 3 bytes of address
m_txCommandBuffer = new uint8_t[CMD_ADDRESS_SIZE];
m_rxCommandBuffer = new uint8_t[CMD_ADDRESS_SIZE];
m_txTransfer = new DmaSpi::Transfer[2];
m_rxTransfer = new DmaSpi::Transfer[2];
} }
BASpiMemoryDMA::BASpiMemoryDMA(SpiDeviceId memDeviceId, uint32_t speedHz) BASpiMemoryDMA::BASpiMemoryDMA(SpiDeviceId memDeviceId, uint32_t speedHz)
: BASpiMemory(memDeviceId, speedHz) : BASpiMemory(memDeviceId, speedHz)
{ {
int cs; m_memDeviceId = memDeviceId;
switch (memDeviceId) { m_settings = {20000000, MSBFIRST, SPI_MODE0};
case SpiDeviceId::SPI_DEVICE0 :
cs = SPI0_CS_PIN;
m_cs = new ActiveLowChipSelect(cs, m_settings);
break;
#if defined(__MK66FX1M0__)
case SpiDeviceId::SPI_DEVICE1 :
cs = SPI1_CS_PIN;
m_cs = new ActiveLowChipSelect1(cs, m_settings);
break;
#endif
default :
cs = SPI0_CS_PIN;
}
m_txCommandBuffer = new uint8_t[CMD_ADDRESS_SIZE];
m_rxCommandBuffer = new uint8_t[CMD_ADDRESS_SIZE];
m_txTransfer = new DmaSpi::Transfer[2];
m_rxTransfer = new DmaSpi::Transfer[2];
} }
BASpiMemoryDMA::~BASpiMemoryDMA() BASpiMemoryDMA::~BASpiMemoryDMA()
@ -431,6 +394,29 @@ void BASpiMemoryDMA::m_setSpiCmdAddr(int command, size_t address, uint8_t *dest)
void BASpiMemoryDMA::begin(void) void BASpiMemoryDMA::begin(void)
{ {
int cs;
switch (m_memDeviceId) {
case SpiDeviceId::SPI_DEVICE0 :
cs = SPI0_CS_PIN;
m_cs = new ActiveLowChipSelect(cs, m_settings);
break;
#if defined(__MK66FX1M0__)
case SpiDeviceId::SPI_DEVICE1 :
cs = SPI1_CS_PIN;
m_cs = new ActiveLowChipSelect1(cs, m_settings);
break;
#endif
default :
cs = SPI0_CS_PIN;
}
// add 4 bytes to buffer for SPI CMD and 3 bytes of address
m_txCommandBuffer = new uint8_t[CMD_ADDRESS_SIZE];
m_rxCommandBuffer = new uint8_t[CMD_ADDRESS_SIZE];
m_txTransfer = new DmaSpi::Transfer[2];
m_rxTransfer = new DmaSpi::Transfer[2];
switch (m_memDeviceId) { switch (m_memDeviceId) {
case SpiDeviceId::SPI_DEVICE0 : case SpiDeviceId::SPI_DEVICE0 :
m_csPin = SPI0_CS_PIN; m_csPin = SPI0_CS_PIN;

Loading…
Cancel
Save