You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by je...@apache.org on 2020/05/14 06:33:08 UTC
[incubator-nuttx] 08/23: stm32: use macros from board.h to pass
configuration to common board logic, not structs
This is an automated email from the ASF dual-hosted git repository.
jerpelea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 64987db9e1b33e041ebf2f50884dd587a5415b16
Author: Matias Nitsche <mn...@dc.uba.ar>
AuthorDate: Mon May 11 12:59:57 2020 -0300
stm32: use macros from board.h to pass configuration to common board logic, not structs
---
boards/arm/stm32/common/include/stm32_nrf24l01.h | 10 +---------
boards/arm/stm32/common/include/stm32_tone.h | 10 +---------
boards/arm/stm32/common/src/stm32_nrf24l01.c | 18 +++++-------------
boards/arm/stm32/common/src/stm32_tone.c | 9 ++++-----
boards/arm/stm32/stm32f103-minimum/include/board.h | 20 ++++++++++++++++++++
.../arm/stm32/stm32f103-minimum/src/stm32_bringup.c | 21 ++-------------------
.../stm32/stm32f103-minimum/src/stm32f103_minimum.h | 9 ---------
7 files changed, 33 insertions(+), 64 deletions(-)
diff --git a/boards/arm/stm32/common/include/stm32_nrf24l01.h b/boards/arm/stm32/common/include/stm32_nrf24l01.h
index 76fcd1f..0c13529 100644
--- a/boards/arm/stm32/common/include/stm32_nrf24l01.h
+++ b/boards/arm/stm32/common/include/stm32_nrf24l01.h
@@ -35,12 +35,6 @@
* Public Types
****************************************************************************/
-struct board_nrf24l01_config_s
-{
- uint32_t ce_pincfg; /* CE pin config */
- uint32_t irq_pincfg; /* IRQ pin config */
-};
-
/****************************************************************************
* Public Data
****************************************************************************/
@@ -68,7 +62,6 @@ extern "C"
* Initialize the NRF24L01 wireless module
*
* Input Parameters:
- * cfg - Instance configuration data
* busno - The SPI bus number
*
* Returned Value:
@@ -76,8 +69,7 @@ extern "C"
*
****************************************************************************/
-int board_nrf24l01_initialize(FAR struct board_nrf24l01_config_s *cfg,
- int busno);
+int board_nrf24l01_initialize(int busno);
#undef EXTERN
#ifdef __cplusplus
diff --git a/boards/arm/stm32/common/include/stm32_tone.h b/boards/arm/stm32/common/include/stm32_tone.h
index 517db85..d28fff0 100644
--- a/boards/arm/stm32/common/include/stm32_tone.h
+++ b/boards/arm/stm32/common/include/stm32_tone.h
@@ -35,13 +35,6 @@
* Public Types
****************************************************************************/
-struct board_tone_config_s
-{
- int pwm_timer; /* PWM timer number for tone generation */
- int oneshot_timer; /* Oneshot timer for note intervals */
- int oneshot_timer_resolution; /* Oneshot timer resolution in us */
-};
-
/****************************************************************************
* Public Data
****************************************************************************/
@@ -66,7 +59,6 @@ extern "C"
* Name: board_tone_initialize
*
* Input Parameters:
- * cfg - Configuration for the driver
* devno - The device number, used to build the device path as /dev/toneN
*
* Description:
@@ -74,7 +66,7 @@ extern "C"
*
****************************************************************************/
-int board_tone_initialize(FAR struct board_tone_config_s *cfg, int devno);
+int board_tone_initialize(int devno);
#undef EXTERN
#ifdef __cplusplus
diff --git a/boards/arm/stm32/common/src/stm32_nrf24l01.c b/boards/arm/stm32/common/src/stm32_nrf24l01.c
index 66cbe86..196bcdd 100644
--- a/boards/arm/stm32/common/src/stm32_nrf24l01.c
+++ b/boards/arm/stm32/common/src/stm32_nrf24l01.c
@@ -83,8 +83,6 @@ static FAR struct nrf24l01_config_s nrf_cfg =
static xcpt_t g_isr;
static FAR void *g_arg;
-struct board_nrf24l01_config_s g_cfg;
-
/****************************************************************************
* Public Data
****************************************************************************/
@@ -98,14 +96,14 @@ static int nrf24l01_irq_attach(xcpt_t isr, FAR void *arg)
wlinfo("Attach IRQ\n");
g_isr = isr;
g_arg = arg;
- stm32_gpiosetevent(g_cfg.irq_pincfg, false, true, false, g_isr, g_arg);
+ stm32_gpiosetevent(BOARD_NRF24L01_GPIO_IRQ, false, true, false, g_isr, g_arg);
return OK;
}
static void nrf24l01_chip_enable(bool enable)
{
wlinfo("CE:%d\n", enable);
- stm32_gpiowrite(g_cfg.ce_pincfg, enable);
+ stm32_gpiowrite(BOARD_NRF24L01_GPIO_CE, enable);
}
/****************************************************************************
@@ -119,7 +117,6 @@ static void nrf24l01_chip_enable(bool enable)
* Initialize the NRF24L01 wireless module
*
* Input Parameters:
- * cfg - Instance configuration data
* busno - The SPI bus number
*
* Returned Value:
@@ -127,20 +124,15 @@ static void nrf24l01_chip_enable(bool enable)
*
****************************************************************************/
-int board_nrf24l01_initialize(FAR struct board_nrf24l01_config_s *cfg,
- int busno)
+int board_nrf24l01_initialize(int busno)
{
FAR struct spi_dev_s *spidev;
int result;
- DEBUGASSERT(cfg);
-
- memcpy(&g_cfg, cfg, sizeof(g_cfg));
-
/* Setup CE & IRQ line IOs */
- stm32_configgpio(g_cfg.ce_pincfg);
- stm32_configgpio(g_cfg.irq_pincfg);
+ stm32_configgpio(BOARD_NRF24L01_GPIO_CE);
+ stm32_configgpio(BOARD_NRF24L01_GPIO_IRQ);
/* Init SPI bus */
diff --git a/boards/arm/stm32/common/src/stm32_tone.c b/boards/arm/stm32/common/src/stm32_tone.c
index 67ba874..9327f90 100644
--- a/boards/arm/stm32/common/src/stm32_tone.c
+++ b/boards/arm/stm32/common/src/stm32_tone.c
@@ -71,7 +71,6 @@
* Name: board_tone_initialize
*
* Input Parameters:
- * cfg - Configuration for the driver
* devno - The device number, used to build the device path as /dev/toneN
*
* Description:
@@ -79,7 +78,7 @@
*
****************************************************************************/
-int board_tone_initialize(FAR struct board_tone_config_s *cfg, int devno)
+int board_tone_initialize(int devno)
{
static bool initialized = false;
struct pwm_lowerhalf_s *tone;
@@ -93,7 +92,7 @@ int board_tone_initialize(FAR struct board_tone_config_s *cfg, int devno)
{
/* Call stm32_pwminitialize() to get an instance of the PWM interface */
- tone = stm32_pwminitialize(cfg->pwm_timer);
+ tone = stm32_pwminitialize(BOARD_TONE_PWM_TIM);
if (!tone)
{
auderr("Failed to get the STM32 PWM lower half to AUDIO TONE\n");
@@ -106,8 +105,8 @@ int board_tone_initialize(FAR struct board_tone_config_s *cfg, int devno)
/* Initialize ONESHOT Timer */
- oneshot = oneshot_initialize(cfg->oneshot_timer,
- cfg->oneshot_timer_resolution);
+ oneshot = oneshot_initialize(BOARD_TONE_ONESHOT_TIM,
+ BOARD_TONE_ONESHOT_TIM_RES);
if (!oneshot)
{
auderr("Failed to initialize ONESHOT Timer!\n");
diff --git a/boards/arm/stm32/stm32f103-minimum/include/board.h b/boards/arm/stm32/stm32f103-minimum/include/board.h
index 0fec651..c19f46e 100644
--- a/boards/arm/stm32/stm32f103-minimum/include/board.h
+++ b/boards/arm/stm32/stm32f103-minimum/include/board.h
@@ -194,4 +194,24 @@
#define RGBLED_BPWMTIMER 4
#define RGBLED_BPWMCHANNEL 4
+/* Tone Driver **************************************************************/
+
+#define BOARD_TONE_PWM_TIM 2 /* PWM timer for tone generation */
+#define BOARD_TONE_ONESHOT_TIM 3 /* Oneshot timer for note timings */
+#define BOARD_TONE_ONESHOT_TIM_RES 10 /* Oneshot timer resolution (us) */
+
+/* NRF24L01 Driver **********************************************************/
+
+/* Chip enable: PB.1 */
+
+#define GPIO_NRF24L01_CE (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
+ GPIO_OUTPUT_CLEAR|GPIO_PORTB|GPIO_PIN1)
+
+/* IRQ line: PA.0 */
+
+#define GPIO_NRF24L01_IRQ (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_PORTA|GPIO_PIN0)
+
+#define BOARD_NRF24L01_GPIO_CE GPIO_NRF24L01_CE
+#define BOARD_NRF24L01_GPIO_IRQ GPIO_NRF24L01_IRQ
+
#endif /* __BOARDS_ARM_STM32_STM32F103_MINIMUM_INCLUDE_BOARD_H */
diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c b/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c
index ebaa47d..82c4725 100644
--- a/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c
+++ b/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c
@@ -155,23 +155,6 @@
* Private Data
****************************************************************************/
-#ifdef CONFIG_AUDIO_TONE
-struct board_tone_config_s g_tone_cfg =
-{
- .pwm_timer = 2,
- .oneshot_timer = 3,
- .oneshot_timer_resolution = 10
-};
-#endif
-
-#ifdef CONFIG_WL_NRF24L01
-struct board_nrf24l01_config_s g_nrf24l01_cfg =
-{
- .ce_pincfg = GPIO_NRF24L01_CE,
- .irq_pincfg = GPIO_NRF24L01_IRQ
-};
-#endif
-
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -303,7 +286,7 @@ int stm32_bringup(void)
#ifdef CONFIG_AUDIO_TONE
/* Configure and initialize the tone generator. */
- ret = board_tone_initialize(&g_tone_cfg, 0);
+ ret = board_tone_initialize(0);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_tone_setup() failed: %d\n", ret);
@@ -460,7 +443,7 @@ int stm32_bringup(void)
#if defined(CONFIG_WL_NRF24L01)
/* Initialize the NRF24L01 wireless module */
- ret = board_nrf24l01_initialize(&g_nrf24l01_cfg, 1);
+ ret = board_nrf24l01_initialize(1);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: board_nrf24l01_initialize failed: %d\n", ret);
diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32f103_minimum.h b/boards/arm/stm32/stm32f103-minimum/src/stm32f103_minimum.h
index b9a07d3..f4dbf04 100644
--- a/boards/arm/stm32/stm32f103-minimum/src/stm32f103_minimum.h
+++ b/boards/arm/stm32/stm32f103-minimum/src/stm32f103_minimum.h
@@ -190,15 +190,6 @@
/* nRF24 Configuration */
-/* NRF24L01 chip enable: PB.1 */
-
-#define GPIO_NRF24L01_CE (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
- GPIO_OUTPUT_CLEAR|GPIO_PORTB|GPIO_PIN1)
-
-/* NRF24L01 IRQ line: PA.0 */
-
-#define GPIO_NRF24L01_IRQ (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_PORTA|GPIO_PIN0)
-
/* MCP2515 IRQ line: PB.0 */
#define GPIO_MCP2515_IRQ (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_PORTB|GPIO_PIN0)