@@ -120,16 +120,20 @@ SPIClass::SPIClass(uint32 spi_num)
120
120
121
121
// Init things specific to each SPI device
122
122
// clock divider setup is a bit of hack, and needs to be improved at a later date.
123
+ #if BOARD_NR_SPI >= 1
123
124
_settings[0 ].spi_d = SPI1;
124
125
_settings[0 ].clockDivider = determine_baud_rate (_settings[0 ].spi_d , _settings[0 ].clock );
125
126
_settings[0 ].spiDmaDev = DMA1;
126
127
_settings[0 ].spiTxDmaChannel = DMA_CH3;
127
128
_settings[0 ].spiRxDmaChannel = DMA_CH2;
129
+ #endif
130
+ #if BOARD_NR_SPI >= 2
128
131
_settings[1 ].spi_d = SPI2;
129
132
_settings[1 ].clockDivider = determine_baud_rate (_settings[1 ].spi_d , _settings[1 ].clock );
130
133
_settings[1 ].spiDmaDev = DMA1;
131
134
_settings[1 ].spiTxDmaChannel = DMA_CH5;
132
135
_settings[1 ].spiRxDmaChannel = DMA_CH4;
136
+ #endif
133
137
#if BOARD_NR_SPI >= 3
134
138
_settings[2 ].spi_d = SPI3;
135
139
_settings[2 ].clockDivider = determine_baud_rate (_settings[2 ].spi_d , _settings[2 ].clock );
@@ -550,12 +554,16 @@ void SPIClass::onReceive(void(*callback)(void)) {
550
554
_currentSetting->receiveCallback = callback;
551
555
if (callback){
552
556
switch (_currentSetting->spi_d ->clk_id ) {
557
+ #if BOARD_NR_SPI >= 1
553
558
case RCC_SPI1:
554
559
dma_attach_interrupt (_currentSetting->spiDmaDev , _currentSetting->spiRxDmaChannel , &SPIClass::_spi1EventCallback);
555
560
break ;
561
+ #endif
562
+ #if BOARD_NR_SPI >= 2
556
563
case RCC_SPI2:
557
564
dma_attach_interrupt (_currentSetting->spiDmaDev , _currentSetting->spiRxDmaChannel , &SPIClass::_spi2EventCallback);
558
565
break ;
566
+ #endif
559
567
#if BOARD_NR_SPI >= 3
560
568
case RCC_SPI3:
561
569
dma_attach_interrupt (_currentSetting->spiDmaDev , _currentSetting->spiRxDmaChannel , &SPIClass::_spi3EventCallback);
@@ -574,12 +582,16 @@ void SPIClass::onTransmit(void(*callback)(void)) {
574
582
_currentSetting->transmitCallback = callback;
575
583
if (callback){
576
584
switch (_currentSetting->spi_d ->clk_id ) {
585
+ #if BOARD_NR_SPI >= 1
577
586
case RCC_SPI1:
578
587
dma_attach_interrupt (_currentSetting->spiDmaDev , _currentSetting->spiTxDmaChannel , &SPIClass::_spi1EventCallback);
579
588
break ;
580
- case RCC_SPI2:
589
+ #endif
590
+ #if BOARD_NR_SPI >= 2
591
+ case RCC_SPI2:
581
592
dma_attach_interrupt (_currentSetting->spiDmaDev , _currentSetting->spiTxDmaChannel , &SPIClass::_spi2EventCallback);
582
593
break ;
594
+ #endif
583
595
#if BOARD_NR_SPI >= 3
584
596
case RCC_SPI3:
585
597
dma_attach_interrupt (_currentSetting->spiDmaDev , _currentSetting->spiTxDmaChannel , &SPIClass::_spi3EventCallback);
@@ -682,14 +694,18 @@ uint8 SPIClass::recv(void) {
682
694
DMA call back functions, one per port.
683
695
*/
684
696
697
+ #if BOARD_NR_SPI >= 1
685
698
void SPIClass::_spi1EventCallback ()
686
699
{
687
700
reinterpret_cast <class SPIClass *>(_spi1_this)->EventCallback ();
688
701
}
702
+ #endif
689
703
704
+ #if BOARD_NR_SPI >= 2
690
705
void SPIClass::_spi2EventCallback () {
691
706
reinterpret_cast <class SPIClass *>(_spi2_this)->EventCallback ();
692
707
}
708
+ #endif
693
709
#if BOARD_NR_SPI >= 3
694
710
void SPIClass::_spi3EventCallback () {
695
711
reinterpret_cast <class SPIClass *>(_spi3_this)->EventCallback ();
0 commit comments