Skip to content

Commit

Permalink
boards/common/gd32v: cleanup default I2C and SPI config
Browse files Browse the repository at this point in the history
This commit includes the following cleanups:
- The macros `I2C_DEV_1_USED` and `SPI_DEV_1_USED` are now used with the values 0 and 1. This allows to enable but also to disable the second interface even if the board definition enables it by default.
- The second I2C device `I2C_DEV(1)` and the second SPI device `SPI_DEV(1)` are now disabled by default.
- The second SPI device `SPI_DEV(1)` now uses PB5 as default CS signal instead of PA4 to keep PA4 free for ADC or DAC even if `SPI_DEV(1)` is used, for example for the TFT display.
  • Loading branch information
gschorcht committed Aug 6, 2023
1 parent 4591ceb commit ba29a5e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
13 changes: 10 additions & 3 deletions boards/common/gd32v/include/cfg_i2c_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ extern "C" {
*/

/**
* @brief Enable the second I2C device `I2C_DEV(1)` by default
* @brief Disable the second I2C device `I2C_DEV(1)` by default
*
* The second I2C device `I2C_DEV(1)` is only defined if `I2C_DEV_1_USED`
* is set to 1 by the board.
* This allows to use the default configuration with one or two I2C devices
* depending on whether other peripherals are enabled that would collide with
* the I2C devices.
*/
#ifndef I2C_DEV_1_USED
#define I2C_DEV_1_USED
#define I2C_DEV_1_USED 0
#endif

/**
Expand All @@ -46,7 +51,7 @@ extern "C" {
* The default I2C device configuration allows to define up to two I2C devices
* `I2C_DEV(0)` and `I2C_DEV(1)`. `I2C_DEV(0)` is always defined if the I2C
* peripheral is enabled by the module `periph_spi`. The second I2C device
* `I2C_DEV(1)` is only defined if `I2C_DEV_1_USED` is defined by the board.
* `I2C_DEV(1)` is only defined if `I2C_DEV_1_USED` is set to 1 by the board.
* This allows to use the default configuration with one or two I2C devices
* depending on whether other peripherals are enabled that would collide with
* the I2C devices.
Expand All @@ -60,6 +65,7 @@ static const i2c_conf_t i2c_config[] = {
.rcu_mask = RCU_APB1EN_I2C0EN_Msk,
.irqn = I2C0_EV_IRQn,
},
#if I2C_DEV_1_USED
{
.dev = I2C1,
.speed = I2C_SPEED_NORMAL,
Expand All @@ -68,6 +74,7 @@ static const i2c_conf_t i2c_config[] = {
.rcu_mask = RCU_APB1EN_I2C1EN_Msk,
.irqn = I2C1_EV_IRQn,
}
#endif
};

#define I2C_NUMOF ARRAY_SIZE(i2c_config)
Expand Down
17 changes: 11 additions & 6 deletions boards/common/gd32v/include/cfg_spi_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ extern "C" {
*/

/**
* @brief Enable the second SPI device `SPI_DEV(1)` by default
* @brief Disable the second SPI device `SPI_DEV(1)` by default
*
* The second SPI device `SPI_DEV(1)` is only defined if `SPI_DEV_1_USED`
* is set to 1 by the board.
* This allows to use the default configuration with one or two SPI devices
* depending on whether other peripherals are enabled that would collide with
* the SPI devices.
*/
#ifndef SPI_DEV_1_USED
#define SPI_DEV_1_USED
#define SPI_DEV_1_USED 0
#endif

/**
Expand All @@ -57,7 +62,7 @@ extern "C" {
* the default CS signal is connected to an unused hardware.
*/
#ifndef SPI_DEV_1_CS
#define SPI_DEV_1_CS GPIO_PIN(PORT_A, 4)
#define SPI_DEV_1_CS GPIO_PIN(PORT_B, 5)
#endif

/**
Expand All @@ -66,7 +71,7 @@ extern "C" {
* The default SPI device configuration allows to define up to two SPI devices
* `SPI_DEV(0)` and `SPI_DEV(1)`. `SPI_DEV(0)` is always defined if the SPI
* peripheral is enabled by the module `periph_spi`. The second SPI device
* `SPI_DEV(1)` is only defined if `SPI_DEV_1_USED` is defined by the board.
* `SPI_DEV(1)` is only defined if `SPI_DEV_1_USED` is set to 1 by the board.
* This allows to use the default configuration with one or two SPI devices
* depending on whether other peripherals are enabled that would collide with
* the SPI devices.
Expand All @@ -81,11 +86,11 @@ static const spi_conf_t spi_config[] = {
.rcumask = RCU_APB1EN_SPI1EN_Msk,
.apbbus = APB1,
},
#ifdef SPI_DEV_1_USED
#if SPI_DEV_1_USED
{
.dev = SPI0,
.mosi_pin = GPIO_PIN(PORT_A, 7),
.miso_pin = GPIO_PIN(PORT_A, 6),
.m iso_pin = GPIO_PIN(PORT_A, 6),
.sclk_pin = GPIO_PIN(PORT_A, 5),
.cs_pin = SPI_DEV_1_CS,
.rcumask = RCU_APB2EN_SPI0EN_Msk,
Expand Down

0 comments on commit ba29a5e

Please sign in to comment.