Skip to content

Commit

Permalink
Merge pull request #9347 from smlng/pr/cc2538/i2c
Browse files Browse the repository at this point in the history
cpu/cc2538: adapt periph to new I2C API
  • Loading branch information
dylad committed Jul 11, 2018
2 parents baf47a5 + 0dea2d1 commit 8cc8b0c
Show file tree
Hide file tree
Showing 8 changed files with 315 additions and 599 deletions.
18 changes: 6 additions & 12 deletions boards/cc2538dk/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,17 @@ static const uart_conf_t uart_config[] = {
* @name I2C configuration
* @{
*/
#define I2C_NUMOF 1
#define I2C_0_EN 1
#define I2C_IRQ_PRIO 1

/* I2C 0 device configuration */
#define I2C_0_DEV 0
#define I2C_0_IRQ I2C_IRQn
#define I2C_0_IRQ_HANDLER isr_i2c
#define I2C_0_SCL_PIN GPIO_PA2 /* SPI_SCK on the SmartRF06 baseboard */
#define I2C_0_SDA_PIN GPIO_PA4 /* SPI_MOSI on the SmartRF06 baseboard */

static const i2c_conf_t i2c_config[I2C_NUMOF] = {
static const i2c_conf_t i2c_config[] = {
{
.scl_pin = GPIO_PA2, /* SPI_SCK on the SmartRF06 baseboard */
.sda_pin = GPIO_PA4, /* SPI_MOSI on the SmartRF06 baseboard */
.speed = I2C_SPEED_FAST, /**< bus speed */
.scl_pin = GPIO_PIN(0, 2), /**< GPIO_PA2, SPI_SCK on SmartRF06 */
.sda_pin = GPIO_PIN(0, 4) /**< GPIO_PA4, SPI_MOSI on SmartRF06 */
},
};

#define I2C_NUMOF (sizeof(i2c_config) / sizeof(i2c_config[0]))
/** @} */

/**
Expand Down
18 changes: 6 additions & 12 deletions boards/openmote-cc2538/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,17 @@ static const uart_conf_t uart_config[] = {
* @name I2C configuration
* @{
*/
#define I2C_NUMOF 1
#define I2C_0_EN 1
#define I2C_IRQ_PRIO 1

/* I2C 0 device configuration */
#define I2C_0_DEV 0
#define I2C_0_IRQ I2C_IRQn
#define I2C_0_IRQ_HANDLER isr_i2c
#define I2C_0_SCL_PIN GPIO_PB3 /* OpenBattery */
#define I2C_0_SDA_PIN GPIO_PB4 /* OpenBattery */

static const i2c_conf_t i2c_config[I2C_NUMOF] = {
static const i2c_conf_t i2c_config[] = {
{
.scl_pin = GPIO_PB3, /* OpenBattery */
.sda_pin = GPIO_PB4, /* OpenBattery */
.speed = I2C_SPEED_FAST, /**< bus speed */
.scl_pin = GPIO_PIN(1, 3), /**< GPIO_PB3, OpenBattery */
.sda_pin = GPIO_PIN(1, 4) /**< GPIO_PB4, OpenBattery */
},
};

#define I2C_NUMOF (sizeof(i2c_config) / sizeof(i2c_config[0]))
/** @} */

/**
Expand Down
18 changes: 6 additions & 12 deletions boards/remote-pa/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,17 @@
* @name I2C configuration
* @{
*/
#define I2C_NUMOF 1
#define I2C_0_EN 1
#define I2C_IRQ_PRIO 1

/* I2C 0 device configuration */
#define I2C_0_DEV 0
#define I2C_0_IRQ I2C_IRQn
#define I2C_0_IRQ_HANDLER isr_i2c
#define I2C_0_SCL_PIN GPIO_PB1
#define I2C_0_SDA_PIN GPIO_PB0

static const i2c_conf_t i2c_config[I2C_NUMOF] = {
static const i2c_conf_t i2c_config[] = {
{
.scl_pin = I2C_0_SCL_PIN,
.sda_pin = I2C_0_SDA_PIN,
.speed = I2C_SPEED_FAST, /**< bus speed */
.scl_pin = GPIO_PIN(1, 1), /**< GPIO_PB1 */
.sda_pin = GPIO_PIN(1, 0) /**< GPIO_PB0 */
},
};

#define I2C_NUMOF (sizeof(i2c_config) / sizeof(i2c_config[0]))
/** @} */

/**
Expand Down
18 changes: 6 additions & 12 deletions boards/remote-reva/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,17 @@
* @name I2C configuration
* @{
*/
#define I2C_NUMOF 1
#define I2C_0_EN 1
#define I2C_IRQ_PRIO 1

/* I2C 0 device configuration */
#define I2C_0_DEV 0
#define I2C_0_IRQ I2C_IRQn
#define I2C_0_IRQ_HANDLER isr_i2c
#define I2C_0_SCL_PIN GPIO_PC3
#define I2C_0_SDA_PIN GPIO_PC2

static const i2c_conf_t i2c_config[I2C_NUMOF] = {
static const i2c_conf_t i2c_config[] = {
{
.scl_pin = I2C_0_SCL_PIN,
.sda_pin = I2C_0_SDA_PIN,
.speed = I2C_SPEED_FAST, /**< bus speed */
.scl_pin = GPIO_PIN(2, 3), /**< GPIO_PC3 */
.sda_pin = GPIO_PIN(2, 2) /**< GPIO_PC2 */
},
};

#define I2C_NUMOF (sizeof(i2c_config) / sizeof(i2c_config[0]))
/** @} */

/**
Expand Down
18 changes: 6 additions & 12 deletions boards/remote-revb/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,17 @@
* @name I2C configuration
* @{
*/
#define I2C_NUMOF 1
#define I2C_0_EN 1
#define I2C_IRQ_PRIO 1

/* I2C 0 device configuration */
#define I2C_0_DEV 0
#define I2C_0_IRQ I2C_IRQn
#define I2C_0_IRQ_HANDLER isr_i2c
#define I2C_0_SCL_PIN GPIO_PC3
#define I2C_0_SDA_PIN GPIO_PC2

static const i2c_conf_t i2c_config[I2C_NUMOF] = {
static const i2c_conf_t i2c_config[] = {
{
.scl_pin = I2C_0_SCL_PIN,
.sda_pin = I2C_0_SDA_PIN,
.speed = I2C_SPEED_FAST, /**< bus speed */
.scl_pin = GPIO_PIN(2, 3), /**< GPIO_PC3 */
.sda_pin = GPIO_PIN(2, 2) /**< GPIO_PC2 */
},
};

#define I2C_NUMOF (sizeof(i2c_config) / sizeof(i2c_config[0]))
/** @} */

/**
Expand Down
34 changes: 34 additions & 0 deletions cpu/cc2538/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,44 @@ typedef uint32_t gpio_t;
*/
void gpio_init_af(gpio_t pin, uint8_t sel, uint8_t over);

/**
* @brief Configure an alternate function for the given pin
*
* @param[in] pin gpio pin
* @param[in] over Override pin configuration
* @param[in] sel Set peripheral function for pin (output)
* @param[in] func Set pin for peripheral function (input)
*/
void gpio_init_mux(gpio_t pin, uint8_t over, uint8_t sel, uint8_t func);

/**
* @name Use shared I2C functions
* @{
*/
#define PERIPH_I2C_NEED_READ_REG
#define PERIPH_I2C_NEED_READ_REGS
#define PERIPH_I2C_NEED_WRITE_REG
#define PERIPH_I2C_NEED_WRITE_REGS
/** @} */

/**
* @name Override I2C clock speed values
* @{
*/
#define HAVE_I2C_SPEED_T
typedef enum {
I2C_SPEED_LOW = 0x01, /**< not supported */
I2C_SPEED_NORMAL = 100000U, /**< normal mode: ~100kbit/s */
I2C_SPEED_FAST = 400000U, /**< fast mode: ~400kbit/s */
I2C_SPEED_FAST_PLUS = 0x02, /**< not supported */
I2C_SPEED_HIGH = 0x03, /**< not supported */
} i2c_speed_t;
/** @} */
/**
* @brief I2C configuration options
*/
typedef struct {
i2c_speed_t speed; /**< baudrate used for the bus */
gpio_t scl_pin; /**< pin used for SCL */
gpio_t sda_pin; /**< pin used for SDA */
} i2c_conf_t;
Expand Down
17 changes: 17 additions & 0 deletions cpu/cc2538/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,20 @@ void gpio_init_af(gpio_t pin, uint8_t sel, uint8_t over)
/* enable alternative function mode */
gpio(pin)->AFSEL |= _pin_mask(pin);
}

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) {
IOC->OVER[_pp_num(pin)] = over;
}
if (sel != MODE_NOTSUP) {
IOC->SEL[_pp_num(pin)] = sel;
}
if (func != MODE_NOTSUP) {
IOC->PINS[func] = _pp_num(pin);
}
/* enable alternative function mode */
gpio(pin)->AFSEL |= _pin_mask(pin);
}
Loading

0 comments on commit 8cc8b0c

Please sign in to comment.