51 #define SPI0_CLK_PORT (-1)
54 #define SPI0_CLK_PIN (-1)
56 #if SPI0_CLK_PORT >= 0 && SPI0_CLK_PIN < 0 || \
57 SPI0_CLK_PORT < 0 && SPI0_CLK_PIN >= 0
58 #error Both SPI0_CLK_PORT and SPI0_CLK_PIN must be valid or invalid
62 #define SPI0_TX_PORT (-1)
65 #define SPI0_TX_PIN (-1)
67 #if SPI0_TX_PORT >= 0 && SPI0_TX_PIN < 0 || \
68 SPI0_TX_PORT < 0 && SPI0_TX_PIN >= 0
69 #error Both SPI0_TX_PORT and SPI0_TX_PIN must be valid or invalid
73 #define SPI0_RX_PORT (-1)
76 #define SPI0_RX_PIN (-1)
78 #if SPI0_RX_PORT >= 0 && SPI0_RX_PIN < 0 || \
79 SPI0_RX_PORT < 0 && SPI0_RX_PIN >= 0
80 #error Both SPI0_RX_PORT and SPI0_RX_PIN must be valid or invalid
88 #if SPI0_CLK_PORT >= 0 || SPI0_TX_PORT >= 0 || SPI0_RX_PORT >= 0
90 #if SPI0_CLK_PORT < 0 || SPI0_TX_PORT < 0 || SPI0_RX_PORT < 0
91 #error Some SPI0 pad definitions are invalid
93 #define SPI0_PADS_VALID
98 #define SPI1_CLK_PORT (-1)
101 #define SPI1_CLK_PIN (-1)
103 #if SPI1_CLK_PORT >= 0 && SPI1_CLK_PIN < 0 || \
104 SPI1_CLK_PORT < 0 && SPI1_CLK_PIN >= 0
105 #error Both SPI1_CLK_PORT and SPI1_CLK_PIN must be valid or invalid
109 #define SPI1_TX_PORT (-1)
112 #define SPI1_TX_PIN (-1)
114 #if SPI1_TX_PORT >= 0 && SPI1_TX_PIN < 0 || \
115 SPI1_TX_PORT < 0 && SPI1_TX_PIN >= 0
116 #error Both SPI1_TX_PORT and SPI1_TX_PIN must be valid or invalid
120 #define SPI1_RX_PORT (-1)
123 #define SPI1_RX_PIN (-1)
125 #if SPI1_RX_PORT >= 0 && SPI1_RX_PIN < 0 || \
126 SPI1_RX_PORT < 0 && SPI1_RX_PIN >= 0
127 #error Both SPI1_RX_PORT and SPI1_RX_PIN must be valid or invalid
131 #if SPI1_CLK_PORT >= 0 || SPI1_TX_PORT >= 0 || SPI1_RX_PORT >= 0
133 #if SPI1_CLK_PORT < 0 || SPI1_TX_PORT < 0 || SPI1_RX_PORT < 0
134 #error Some SPI1 pad definitions are invalid
136 #define SPI1_PADS_VALID
139 #ifdef SPI_DEFAULT_INSTANCE
140 #if SPI_DEFAULT_INSTANCE == 0
141 #ifndef SPI0_PADS_VALID
142 #error SPI_DEFAULT_INSTANCE is set to SPI0, but its pads are not valid
144 #elif SPI_DEFAULT_INSTANCE == 1
145 #ifndef SPI1_PADS_VALID
146 #error SPI_DEFAULT_INSTANCE is set to SPI1, but its pads are not valid
151 #if (SPI0_CPRS_CPSDVSR & 1) == 1 || SPI0_CPRS_CPSDVSR < 2 || SPI0_CPRS_CPSDVSR > 254
152 #error SPI0_CPRS_CPSDVSR must be an even number between 2 and 254
155 #if (SPI1_CPRS_CPSDVSR & 1) == 1 || SPI1_CPRS_CPSDVSR < 2 || SPI1_CPRS_CPSDVSR > 254
156 #error SPI1_CPRS_CPSDVSR must be an even number between 2 and 254
166 uint32_t ioc_ssirxd_ssi;
167 uint32_t ioc_pxx_sel_ssi_clkout;
168 uint32_t ioc_pxx_sel_ssi_txd;
169 uint8_t ssi_cprs_cpsdvsr;
175 static const spi_regs_t spi_regs[SSI_INSTANCE_COUNT] = {
179 .ioc_pxx_sel_ssi_clkout = IOC_PXX_SEL_SSI0_CLKOUT,
180 .ioc_pxx_sel_ssi_txd = IOC_PXX_SEL_SSI0_TXD,
181 .ssi_cprs_cpsdvsr = SPI0_CPRS_CPSDVSR,
182 .clk = { SPI0_CLK_PORT, SPI0_CLK_PIN },
183 .tx = { SPI0_TX_PORT, SPI0_TX_PIN },
184 .rx = { SPI0_RX_PORT, SPI0_RX_PIN }
188 .ioc_pxx_sel_ssi_clkout = IOC_PXX_SEL_SSI1_CLKOUT,
189 .ioc_pxx_sel_ssi_txd = IOC_PXX_SEL_SSI1_TXD,
190 .ssi_cprs_cpsdvsr = SPI1_CPRS_CPSDVSR,
191 .clk = { SPI1_CLK_PORT, SPI1_CLK_PIN },
192 .tx = { SPI1_TX_PORT, SPI1_TX_PIN },
193 .rx = { SPI1_RX_PORT, SPI1_RX_PIN }
198 #ifdef SPI_DEFAULT_INSTANCE
209 const spi_regs_t *regs;
211 if(spi >= SSI_INSTANCE_COUNT) {
215 regs = &spi_regs[spi];
217 if(regs->clk.port < 0) {
230 REG(regs->base +
SSI_CC) = 0;
235 regs->ioc_pxx_sel_ssi_clkout);
238 regs->ioc_pxx_sel_ssi_txd);
239 REG(regs->ioc_ssirxd_ssi) = (regs->rx.port * 8) + regs->rx.pin;
257 REG(regs->base +
SSI_CPSR) = regs->ssi_cprs_cpsdvsr;
275 if(spi >= SSI_INSTANCE_COUNT) {
284 if(spi >= SSI_INSTANCE_COUNT) {
292 uint32_t frame_format,
293 uint32_t clock_polarity,
294 uint32_t clock_phase,
297 const spi_regs_t *regs;
299 if(spi >= SSI_INSTANCE_COUNT) {
303 regs = &spi_regs[spi];
309 REG(regs->base +
SSI_CR0) = clock_phase |
#define SSI_CC
Clock configuration.
#define GPIO_PIN_MASK(PIN)
Converts a pin number to a pin mask.
#define SSI_CR0
Control register 0.
Header file with register manipulation macro definitions.
#define SSI_CPSR
Clock divider.
#define IOC_OVERRIDE_PUE
Pull Up Enable.
#define IOC_OVERRIDE_DIS
Override Disabled.
Header file for the cc2538 SPI driver, including macros for the implementation of the low-level SPI p...
void spix_set_mode(uint8_t spi, uint32_t frame_format, uint32_t clock_polarity, uint32_t clock_phase, uint32_t data_size)
Configure the SPI data and clock polarity and the data size for the instance given.
#define SYS_CTRL_RCGCSSI
SSI[1:0] clocks - active mode.
#define IOC_OVERRIDE_OE
Output Enable.
void spix_init(uint8_t spi)
Initialize the SPI bus for the instance given.
void ioc_set_sel(uint8_t port, uint8_t pin, uint8_t sel)
Function select for Port:Pin.
#define SSI0_BASE
Base address for SSI0.
#define GPIO_SET_PIN(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE high.
#define SSI_CR0_SPH
Serial clock phase (H)
void spix_cs_init(uint8_t port, uint8_t pin)
Configure a GPIO to be the chip select pin.
#define SSI1_BASE
Base address for SSI1.
#define GPIO_SET_OUTPUT(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to output.
#define IOC_SSIRXD_SSI0
SSI0 RX.
#define SSI_CR0_SPO
Serial clock phase (O)
Header file with declarations for the I/O Control module.
#define GPIO_SOFTWARE_CONTROL(PORT_BASE, PIN_MASK)
Configure the pin to be software controlled with PIN_MASK of port with PORT_BASE. ...
#define GPIO_PORT_TO_BASE(PORT)
Converts a port number to the port base address.
Header file for the cc2538 System Control driver.
#define SSI_CR1_SSE
Synchronous serial port enable.
Header file for the cc2538 Synchronous Serial Interface.
#define SSI_CR1
Control register 1.
#define IOC_SSIRXD_SSI1
SSI1 RX.
void spix_disable(uint8_t spi)
Disables the SPI peripheral for the instance given.
#define GPIO_PERIPHERAL_CONTROL(PORT_BASE, PIN_MASK)
Configure the pin to be under peripheral control with PIN_MASK of port with PORT_BASE.
void ioc_set_over(uint8_t port, uint8_t pin, uint8_t over)
Set Port:Pin override function.
void spix_enable(uint8_t spi)
Enables the SPI peripheral for the instance given.