cpu/nrf52: fix spi_twi_irq for nrf52805/10/11

These smaller parts have SPI1 mapped to TWI0 (if SPI1 exists at all).
This commit is contained in:
Benjamin Valentin 2020-06-26 15:28:47 +02:00
parent ca2b7e1952
commit ec67798cf0

View File

@ -14,30 +14,30 @@
* @brief Shared IRQ handling between SPI and TWI peripherals on the nRF52
* devices
*
* I2C is called TWI (Two Wire Interface) in the datasheets from Nordic
* I2C is called TWI (Two Wire Interface) in the datasheets from Nordic
*
* @author Koen Zandberg <koen@bergzand.net>
*
* @}
*/
#include "cpu.h"
#include "periph_cpu.h"
/* nRF52811 ISR names */
#if defined(CPU_MODEL_NRF52811XXAA)
#if NRF_SPIM0_BASE != NRF_TWIM0_BASE
#define ISR_SPIM0 isr_spi0
#if defined(NRF_SPIM1)
#define ISR_SPIM1 isr_spi1_twi0
#else
#define ISR_SPIM1 isr_twi0
#endif
/* nRF52832 and nRF52840 ISR names */
#elif (defined(CPU_MODEL_NRF52840XXAA) || defined(CPU_MODEL_NRF52832XXAA))
#else
#define ISR_SPIM0 isr_spi0_twi0
#define ISR_SPIM1 isr_spi1_twi1
#else
#error Unknown nrf52 MCU model
#endif
static spi_twi_irq_cb_t _irq[SPIM_COUNT];
@ -49,9 +49,11 @@ static size_t _spi_dev2num(void *dev)
if (dev == NRF_SPIM0) {
return 0;
}
#ifdef NRF_SPIM1
else if (dev == NRF_SPIM1) {
return 1;
}
#endif
#ifdef NRF_SPIM2
else if (dev == NRF_SPIM2) {
return 2;
@ -70,16 +72,28 @@ static size_t _spi_dev2num(void *dev)
static inline size_t _i2c_dev2num(void *dev)
{
return _spi_dev2num(dev);
if (NRF_SPIM0_BASE == NRF_TWIM0_BASE) {
return _spi_dev2num(dev);
} else {
assert(!IS_ACTIVE(NRF_TWIM1_BASE));
/* if they are not equal (nrf528105/10/11)
TWI0 is mapped to SPI1 */
return 1;
}
}
static const IRQn_Type _isr[] = {
SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn,
#ifdef CPU_MODEL_NRF52811XXAA
#if NRF_SPIM0_BASE == NRF_TWIM0_BASE
SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn,
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn,
#else
SPIM0_SPIS0_SPI0_IRQn,
#if defined(NRF_SPIM1)
TWIM0_TWIS0_TWI0_SPIM1_SPIS1_SPI1_IRQn,
#else
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn,
TWIM0_TWIS0_TWI0_IRQn,
#endif
#endif
#ifdef NRF_SPIM2