Fix startup PIN config issues with GPIO and DMA SPI

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

@ -38,6 +38,10 @@ public:
/// Construct a GPIO object for controlling the various GPIO and user pins
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.
/// @param gpioId Specify a GPIO pin such as GPIO::GPIO0

@ -24,6 +24,15 @@
namespace BALibrary {
BAGpio::BAGpio()
{
begin();
}
BAGpio::~BAGpio()
{
}
void BAGpio::begin()
{
// Set all GPIOs to input
pinMode(GPIO0, INPUT);
@ -40,11 +49,6 @@ BAGpio::BAGpio()
// Set the LED to ouput
pinMode(USR_LED_ID, OUTPUT);
clearLed(); // turn off the LED
}
BAGpio::~BAGpio()
{
}
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)
: BASpiMemory(memDeviceId)
{
int cs;
switch (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];
m_memDeviceId = memDeviceId;
m_settings = {20000000, MSBFIRST, SPI_MODE0};
}
BASpiMemoryDMA::BASpiMemoryDMA(SpiDeviceId memDeviceId, uint32_t speedHz)
: BASpiMemory(memDeviceId, speedHz)
{
int cs;
switch (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;
}
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];
m_memDeviceId = memDeviceId;
m_settings = {20000000, MSBFIRST, SPI_MODE0};
}
BASpiMemoryDMA::~BASpiMemoryDMA()
@ -431,6 +394,29 @@ void BASpiMemoryDMA::m_setSpiCmdAddr(int command, size_t address, uint8_t *dest)
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) {
case SpiDeviceId::SPI_DEVICE0 :
m_csPin = SPI0_CS_PIN;

Loading…
Cancel
Save