Skip to content

Commit

Permalink
Merge pull request RIOT-OS#9698 from smlng/pr/cc2538/spi
Browse files Browse the repository at this point in the history
cpu/cc2538: refine periph/spi implementation
  • Loading branch information
PeterKietzmann authored Aug 10, 2018
2 parents feb3912 + d9c9c94 commit 25a487e
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 163 deletions.
10 changes: 5 additions & 5 deletions boards/cc2538dk/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ static const i2c_conf_t i2c_config[] = {
*/
static const spi_conf_t spi_config[] = {
{
.dev = SSI0,
.mosi_pin = GPIO_PA4,
.miso_pin = GPIO_PA5,
.sck_pin = GPIO_PA2,
.cs_pin = GPIO_PD0
.num = 0,
.mosi_pin = GPIO_PIN(0, 4),
.miso_pin = GPIO_PIN(0, 5),
.sck_pin = GPIO_PIN(0, 2),
.cs_pin = GPIO_PIN(3, 0)
}
};

Expand Down
10 changes: 5 additions & 5 deletions boards/openmote-b/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ static const i2c_conf_t i2c_config[] = {
*/
static const spi_conf_t spi_config[] = {
{
.dev = SSI0,
.mosi_pin = GPIO_PA5,
.miso_pin = GPIO_PA4,
.sck_pin = GPIO_PA2,
.cs_pin = GPIO_PA3,
.num = 0,
.mosi_pin = GPIO_PIN(0, 5),
.miso_pin = GPIO_PIN(0, 4),
.sck_pin = GPIO_PIN(0, 2),
.cs_pin = GPIO_PIN(0, 3)
},
};

Expand Down
10 changes: 5 additions & 5 deletions boards/openmote-cc2538/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ static const i2c_conf_t i2c_config[] = {
*/
static const spi_conf_t spi_config[] = {
{
.dev = SSI0,
.mosi_pin = GPIO_PA5,
.miso_pin = GPIO_PA4,
.sck_pin = GPIO_PA2,
.cs_pin = GPIO_PA3,
.num = 0,
.mosi_pin = GPIO_PIN(0, 5),
.miso_pin = GPIO_PIN(0, 4),
.sck_pin = GPIO_PIN(0, 2),
.cs_pin = GPIO_PIN(0, 3)
},
};

Expand Down
18 changes: 9 additions & 9 deletions boards/remote-pa/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ static const i2c_conf_t i2c_config[] = {
*/
static const spi_conf_t spi_config[] = {
{
.dev = SSI0,
.mosi_pin = GPIO_PD0,
.miso_pin = GPIO_PC4,
.sck_pin = GPIO_PD1,
.cs_pin = GPIO_PD3
.num = 0,
.mosi_pin = GPIO_PIN(3, 0),
.miso_pin = GPIO_PIN(2, 4),
.sck_pin = GPIO_PIN(3, 1),
.cs_pin = GPIO_PIN(3, 3)
},
{
.dev = SSI1,
.mosi_pin = GPIO_PC7,
.miso_pin = GPIO_PA4,
.sck_pin = GPIO_PB5,
.num = 1,
.mosi_pin = GPIO_PIN(2, 7),
.miso_pin = GPIO_PIN(0, 4),
.sck_pin = GPIO_PIN(1 ,5),
.cs_pin = GPIO_UNDEF
}
};
Expand Down
20 changes: 10 additions & 10 deletions boards/remote-reva/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ static const i2c_conf_t i2c_config[] = {
*/
static const spi_conf_t spi_config[] = {
{
.dev = SSI0,
.mosi_pin = GPIO_PB1,
.miso_pin = GPIO_PB3,
.sck_pin = GPIO_PB2,
.cs_pin = GPIO_PB5
.num = 0,
.mosi_pin = GPIO_PIN(1, 1),
.miso_pin = GPIO_PIN(1, 3),
.sck_pin = GPIO_PIN(1, 2),
.cs_pin = GPIO_PIN(1, 5)
},
{
.dev = SSI1,
.mosi_pin = GPIO_PC5,
.miso_pin = GPIO_PC6,
.sck_pin = GPIO_PC4,
.cs_pin = GPIO_PA7
.num = 1,
.mosi_pin = GPIO_PIN(2, 5),
.miso_pin = GPIO_PIN(2, 6),
.sck_pin = GPIO_PIN(2, 4),
.cs_pin = GPIO_PIN(0, 7)
}
};

Expand Down
20 changes: 10 additions & 10 deletions boards/remote-revb/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ static const i2c_conf_t i2c_config[] = {
*/
static const spi_conf_t spi_config[] = {
{
.dev = SSI0,
.mosi_pin = GPIO_PB1,
.miso_pin = GPIO_PB3,
.sck_pin = GPIO_PB2,
.cs_pin = GPIO_PB5
.num = 0,
.mosi_pin = GPIO_PIN(1, 1),
.miso_pin = GPIO_PIN(1, 3),
.sck_pin = GPIO_PIN(1, 2),
.cs_pin = GPIO_PIN(1, 5)
},
{
.dev = SSI1,
.mosi_pin = GPIO_PC5,
.miso_pin = GPIO_PC6,
.sck_pin = GPIO_PC4,
.cs_pin = GPIO_PA7
.num = 1,
.mosi_pin = GPIO_PIN(2, 5),
.miso_pin = GPIO_PIN(2, 6),
.sck_pin = GPIO_PIN(2, 4),
.cs_pin = GPIO_PIN(0, 7)
}
};
#define SPI_NUMOF (sizeof(spi_config) / sizeof(spi_config[0]))
Expand Down
94 changes: 17 additions & 77 deletions cpu/cc2538/include/cc2538_ssi.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @brief CC2538 SSI interface
*
* @author Ian Martin <[email protected]>
* @author Sebastian Meiling <[email protected]>
*/

#ifndef CC2538_SSI_H
Expand All @@ -29,92 +30,31 @@ extern "C" {
* @brief SSI component registers
*/
typedef struct {
union {
cc2538_reg_t CR0; /**< SSI Control Register 0 */
struct {
cc2538_reg_t DSS : 4; /**< SSI data size select */
cc2538_reg_t FRF : 2; /**< SSI frame format select */
cc2538_reg_t SPO : 1; /**< SSI serial clock polarity */
cc2538_reg_t SPH : 1; /**< SSI serial clock phase */
cc2538_reg_t SCR : 8; /**< SSI serial clock rate */
cc2538_reg_t RESERVED : 16; /**< Reserved bits */
} CR0bits;
};

union {
cc2538_reg_t CR1; /**< SSI Control Register 1 */
struct {
cc2538_reg_t LBM : 1; /**< SSI loop-back mode */
cc2538_reg_t SSE : 1; /**< SSI synchronous serial port enable */
cc2538_reg_t MS : 1; /**< SSI master and slave select */
cc2538_reg_t SOD : 1; /**< SSI slave mode output disable */
cc2538_reg_t RESERVED : 28; /**< Reserved bits */
} CR1bits;
};

cc2538_reg_t DR; /**< SSI Data register */

union {
cc2538_reg_t SR; /**< SSI FIFO/busy Status Register */
struct {
cc2538_reg_t TFE : 1; /**< SSI transmit FIFO empty */
cc2538_reg_t TNF : 1; /**< SSI transmit FIFO not full */
cc2538_reg_t RNE : 1; /**< SSI receive FIFO not empty */
cc2538_reg_t RFF : 1; /**< SSI receive FIFO full */
cc2538_reg_t BSY : 1; /**< SSI busy bit */
cc2538_reg_t RESERVED : 27; /**< Reserved bits */
} SRbits;
};
cc2538_reg_t CPSR; /**< SSI Clock Register */
cc2538_reg_t IM; /**< SSI Interrupt Mask register */
cc2538_reg_t RIS; /**< SSI Raw Interrupt Status register */
cc2538_reg_t MIS; /**< SSI Masked Interrupt Status register */
cc2538_reg_t ICR; /**< SSI Interrupt Clear Register */
cc2538_reg_t DMACTL; /**< SSI uDMA Control Register. */
cc2538_reg_t CC; /**< SSI clock configuration */
cc2538_reg_t CR0; /**< SSI Control Register 0 */
cc2538_reg_t CR1; /**< SSI Control Register 1 */
cc2538_reg_t DR; /**< SSI Data register */
cc2538_reg_t SR; /**< SSI FIFO/busy Status Register */
cc2538_reg_t CPSR; /**< SSI Clock Register */
cc2538_reg_t IM; /**< SSI Interrupt Mask register */
cc2538_reg_t RIS; /**< SSI Raw Interrupt Status register */
cc2538_reg_t MIS; /**< SSI Masked Interrupt Status register */
cc2538_reg_t ICR; /**< SSI Interrupt Clear Register */
cc2538_reg_t DMACTL; /**< SSI uDMA Control Register. */
cc2538_reg_t CC; /**< SSI clock configuration */
} cc2538_ssi_t;

#define SSI0 ( (cc2538_ssi_t*)0x40008000 ) /**< SSI0 Instance */
#define SSI1 ( (cc2538_ssi_t*)0x40009000 ) /**< SSI1 Instance */

/**
* @brief Define CR0 register bitfields
* @{
*/
#define SSI_CR0_DSS(x) ((x - 1) << 0)
#define SSI_CR0_SPO (1 << 6)
#define SSI_CR0_SPH (1 << 7)
/** @} */

/**
* @brief Define CR1 register bitfields
* @{
*/
#define SSI_CR1_LBM (1 << 0)
#define SSI_CR1_SSE (1 << 1)
#define SSI_CR1_MS (1 << 2)
#define SSI_CR1_SOD (1 << 3)
/** @} */

/**
* @brief Define SR register bitfields
* @{
* @brief Set CR0 data size (bits)
*/
#define SSI_SR_TFE (1 << 0)
#define SSI_SR_TNF (1 << 1)
#define SSI_SR_RNE (1 << 2)
#define SSI_SR_RFF (1 << 3)
#define SSI_SR_BSY (1 << 4)
/** @} */
#define SSI_CR0_DSS(x) (x - 1)

/**
* @brief Define CC register bitfields
* @{
*/
#define SSI_SS_PIOSC (1 << 0)
#define SSI_SS_DSEN (1 << 2)
#define SSI_SS_SYSDIV (0)
#define SSI_SS_IODIV (SSI_SS_PIOSC)
#define SSI_CC_CS_SYSDIV (0x0)
#define SSI_CC_CS_IODIV (0x1)
#define SSI_CC_CS_DSEN (0x4)
/** @} */

#ifdef __cplusplus
Expand Down
7 changes: 6 additions & 1 deletion cpu/cc2538/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <stdio.h>

#include "cpu.h"
#include "vendor/hw_ssi.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -60,6 +61,10 @@ typedef uint32_t gpio_t;
*/
#define GPIO_UNDEF (0xffffffff)

/**
* @brief Custom value to indicate unused parameter in gpio_init_mux
*/
#define GPIO_MUX_NONE (0xff)
/**
* @brief Define a custom GPIO_PIN macro
*
Expand Down Expand Up @@ -217,7 +222,7 @@ static const spi_clk_conf_t spi_clk_config[] = {
* @{
*/
typedef struct {
cc2538_ssi_t *dev; /**< SSI device */
uint8_t num; /**< number of SSI device, i.e. 0 or 1 */
gpio_t mosi_pin; /**< pin used for MOSI */
gpio_t miso_pin; /**< pin used for MISO */
gpio_t sck_pin; /**< pin used for SCK */
Expand Down
6 changes: 3 additions & 3 deletions cpu/cc2538/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,13 @@ void gpio_init_mux(gpio_t pin, uint8_t over, uint8_t sel, uint8_t func)
{
assert(pin != GPIO_UNDEF);
/* configure pin function and multiplexing */
if (over != MODE_NOTSUP) {
if (over != GPIO_MUX_NONE) {
IOC->OVER[_pp_num(pin)] = over;
}
if (sel != MODE_NOTSUP) {
if (sel != GPIO_MUX_NONE) {
IOC->SEL[_pp_num(pin)] = sel;
}
if (func != MODE_NOTSUP) {
if (func != GPIO_MUX_NONE) {
IOC->PINS[func] = _pp_num(pin);
}
/* enable alternative function mode */
Expand Down
Loading

0 comments on commit 25a487e

Please sign in to comment.