Skip to content

Commit

Permalink
Merge branch 'mitchmitchell-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerclarkmelbourne committed Feb 24, 2019
2 parents e69cf8f + 096facf commit 73ec420
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
18 changes: 17 additions & 1 deletion STM32F1/libraries/SPI/src/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,20 @@ SPIClass::SPIClass(uint32 spi_num)

// Init things specific to each SPI device
// clock divider setup is a bit of hack, and needs to be improved at a later date.
#if BOARD_NR_SPI >= 1
_settings[0].spi_d = SPI1;
_settings[0].clockDivider = determine_baud_rate(_settings[0].spi_d, _settings[0].clock);
_settings[0].spiDmaDev = DMA1;
_settings[0].spiTxDmaChannel = DMA_CH3;
_settings[0].spiRxDmaChannel = DMA_CH2;
#endif
#if BOARD_NR_SPI >= 2
_settings[1].spi_d = SPI2;
_settings[1].clockDivider = determine_baud_rate(_settings[1].spi_d, _settings[1].clock);
_settings[1].spiDmaDev = DMA1;
_settings[1].spiTxDmaChannel = DMA_CH5;
_settings[1].spiRxDmaChannel = DMA_CH4;
#endif
#if BOARD_NR_SPI >= 3
_settings[2].spi_d = SPI3;
_settings[2].clockDivider = determine_baud_rate(_settings[2].spi_d, _settings[2].clock);
Expand Down Expand Up @@ -550,12 +554,16 @@ void SPIClass::onReceive(void(*callback)(void)) {
_currentSetting->receiveCallback = callback;
if (callback){
switch (_currentSetting->spi_d->clk_id) {
#if BOARD_NR_SPI >= 1
case RCC_SPI1:
dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, &SPIClass::_spi1EventCallback);
break;
#endif
#if BOARD_NR_SPI >= 2
case RCC_SPI2:
dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, &SPIClass::_spi2EventCallback);
break;
#endif
#if BOARD_NR_SPI >= 3
case RCC_SPI3:
dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, &SPIClass::_spi3EventCallback);
Expand All @@ -574,12 +582,16 @@ void SPIClass::onTransmit(void(*callback)(void)) {
_currentSetting->transmitCallback = callback;
if (callback){
switch (_currentSetting->spi_d->clk_id) {
#if BOARD_NR_SPI >= 1
case RCC_SPI1:
dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &SPIClass::_spi1EventCallback);
break;
case RCC_SPI2:
#endif
#if BOARD_NR_SPI >= 2
case RCC_SPI2:
dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &SPIClass::_spi2EventCallback);
break;
#endif
#if BOARD_NR_SPI >= 3
case RCC_SPI3:
dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &SPIClass::_spi3EventCallback);
Expand Down Expand Up @@ -682,14 +694,18 @@ uint8 SPIClass::recv(void) {
DMA call back functions, one per port.
*/

#if BOARD_NR_SPI >= 1
void SPIClass::_spi1EventCallback()
{
reinterpret_cast<class SPIClass*>(_spi1_this)->EventCallback();
}
#endif

#if BOARD_NR_SPI >= 2
void SPIClass::_spi2EventCallback() {
reinterpret_cast<class SPIClass*>(_spi2_this)->EventCallback();
}
#endif
#if BOARD_NR_SPI >= 3
void SPIClass::_spi3EventCallback() {
reinterpret_cast<class SPIClass*>(_spi3_this)->EventCallback();
Expand Down
8 changes: 8 additions & 0 deletions STM32F1/libraries/SPI/src/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,12 @@ class SPISettings {
Should move this to within the class once tested out, just for tidyness
*/
static uint8_t ff = 0XFF;
#if BOARD_NR_SPI >= 1
static void (*_spi1_this);
#endif
#if BOARD_NR_SPI >= 2
static void (*_spi2_this);
#endif
#if BOARD_NR_SPI >= 3
static void (*_spi3_this);
#endif
Expand Down Expand Up @@ -411,8 +415,12 @@ class SPIClass {

void EventCallback(void);

#if BOARD_NR_SPI >= 1
static void _spi1EventCallback(void);
#endif
#if BOARD_NR_SPI >= 2
static void _spi2EventCallback(void);
#endif
#if BOARD_NR_SPI >= 3
static void _spi3EventCallback(void);
#endif
Expand Down
4 changes: 4 additions & 0 deletions STM32F4/libraries/SPI/src/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ SPIClass::SPIClass(uint32 spi_num) {
// SPI2: 1 / 0 / 3 - 1 / 0 / 4
// SPI3: 1 / 0 / 0 (2) - 1 / 0 / 5 (7)
/*****************************************************************************/
#if BOARD_NR_SPI >= 1
_settings[0].spi_d = SPI1;
_settings[0].clockDivider = determine_baud_rate(_settings[0].spi_d, _settings[0].clock);
#ifdef SPI_DMA
Expand All @@ -132,6 +133,8 @@ SPIClass::SPIClass(uint32 spi_num) {
_settings[0].spiRxDmaStream = DMA_STREAM0; // alternative: DMA_STREAM2
_settings[0].spiTxDmaStream = DMA_STREAM3; // alternative: DMA_STREAM5
#endif
#endif
#if BOARD_NR_SPI >= 2
_settings[1].spi_d = SPI2;
_settings[1].clockDivider = determine_baud_rate(_settings[1].spi_d, _settings[1].clock);
#ifdef SPI_DMA
Expand All @@ -140,6 +143,7 @@ SPIClass::SPIClass(uint32 spi_num) {
_settings[1].spiRxDmaStream = DMA_STREAM3; // alternative: -
_settings[1].spiTxDmaStream = DMA_STREAM4; // alternative: -
#endif
#endif
#if BOARD_NR_SPI >= 3
_settings[2].spi_d = SPI3;
_settings[2].clockDivider = determine_baud_rate(_settings[2].spi_d, _settings[2].clock);
Expand Down

0 comments on commit 73ec420

Please sign in to comment.