diff --git a/src/BAGpio.h b/src/BAGpio.h index b038c3d..aae92f2 100644 --- a/src/BAGpio.h +++ b/src/BAGpio.h @@ -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 diff --git a/src/peripherals/BAGpio.cpp b/src/peripherals/BAGpio.cpp index 6f15e0e..8e30809 100644 --- a/src/peripherals/BAGpio.cpp +++ b/src/peripherals/BAGpio.cpp @@ -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) diff --git a/src/peripherals/BASpiMemory.cpp b/src/peripherals/BASpiMemory.cpp index 1c9e702..290a5b6 100644 --- a/src/peripherals/BASpiMemory.cpp +++ b/src/peripherals/BASpiMemory.cpp @@ -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;