stm32: use macros from board.h to pass configuration to common board logic, not structs

This commit is contained in:
Matias Nitsche 2020-05-11 12:59:57 -03:00 committed by Alin Jerpelea
parent 944ed5ae0a
commit 64987db9e1
7 changed files with 33 additions and 64 deletions

View File

@ -35,12 +35,6 @@
* Public Types * Public Types
****************************************************************************/ ****************************************************************************/
struct board_nrf24l01_config_s
{
uint32_t ce_pincfg; /* CE pin config */
uint32_t irq_pincfg; /* IRQ pin config */
};
/**************************************************************************** /****************************************************************************
* Public Data * Public Data
****************************************************************************/ ****************************************************************************/
@ -68,7 +62,6 @@ extern "C"
* Initialize the NRF24L01 wireless module * Initialize the NRF24L01 wireless module
* *
* Input Parameters: * Input Parameters:
* cfg - Instance configuration data
* busno - The SPI bus number * busno - The SPI bus number
* *
* Returned Value: * Returned Value:
@ -76,8 +69,7 @@ extern "C"
* *
****************************************************************************/ ****************************************************************************/
int board_nrf24l01_initialize(FAR struct board_nrf24l01_config_s *cfg, int board_nrf24l01_initialize(int busno);
int busno);
#undef EXTERN #undef EXTERN
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -35,13 +35,6 @@
* Public Types * 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 * Public Data
****************************************************************************/ ****************************************************************************/
@ -66,7 +59,6 @@ extern "C"
* Name: board_tone_initialize * Name: board_tone_initialize
* *
* Input Parameters: * Input Parameters:
* cfg - Configuration for the driver
* devno - The device number, used to build the device path as /dev/toneN * devno - The device number, used to build the device path as /dev/toneN
* *
* Description: * 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 #undef EXTERN
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -83,8 +83,6 @@ static FAR struct nrf24l01_config_s nrf_cfg =
static xcpt_t g_isr; static xcpt_t g_isr;
static FAR void *g_arg; static FAR void *g_arg;
struct board_nrf24l01_config_s g_cfg;
/**************************************************************************** /****************************************************************************
* Public Data * Public Data
****************************************************************************/ ****************************************************************************/
@ -98,14 +96,14 @@ static int nrf24l01_irq_attach(xcpt_t isr, FAR void *arg)
wlinfo("Attach IRQ\n"); wlinfo("Attach IRQ\n");
g_isr = isr; g_isr = isr;
g_arg = arg; 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; return OK;
} }
static void nrf24l01_chip_enable(bool enable) static void nrf24l01_chip_enable(bool enable)
{ {
wlinfo("CE:%d\n", 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 * Initialize the NRF24L01 wireless module
* *
* Input Parameters: * Input Parameters:
* cfg - Instance configuration data
* busno - The SPI bus number * busno - The SPI bus number
* *
* Returned Value: * 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 board_nrf24l01_initialize(int busno)
int busno)
{ {
FAR struct spi_dev_s *spidev; FAR struct spi_dev_s *spidev;
int result; int result;
DEBUGASSERT(cfg);
memcpy(&g_cfg, cfg, sizeof(g_cfg));
/* Setup CE & IRQ line IOs */ /* Setup CE & IRQ line IOs */
stm32_configgpio(g_cfg.ce_pincfg); stm32_configgpio(BOARD_NRF24L01_GPIO_CE);
stm32_configgpio(g_cfg.irq_pincfg); stm32_configgpio(BOARD_NRF24L01_GPIO_IRQ);
/* Init SPI bus */ /* Init SPI bus */

View File

@ -71,7 +71,6 @@
* Name: board_tone_initialize * Name: board_tone_initialize
* *
* Input Parameters: * Input Parameters:
* cfg - Configuration for the driver
* devno - The device number, used to build the device path as /dev/toneN * devno - The device number, used to build the device path as /dev/toneN
* *
* Description: * 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; static bool initialized = false;
struct pwm_lowerhalf_s *tone; 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 */ /* 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) if (!tone)
{ {
auderr("Failed to get the STM32 PWM lower half to AUDIO TONE\n"); 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 */ /* Initialize ONESHOT Timer */
oneshot = oneshot_initialize(cfg->oneshot_timer, oneshot = oneshot_initialize(BOARD_TONE_ONESHOT_TIM,
cfg->oneshot_timer_resolution); BOARD_TONE_ONESHOT_TIM_RES);
if (!oneshot) if (!oneshot)
{ {
auderr("Failed to initialize ONESHOT Timer!\n"); auderr("Failed to initialize ONESHOT Timer!\n");

View File

@ -194,4 +194,24 @@
#define RGBLED_BPWMTIMER 4 #define RGBLED_BPWMTIMER 4
#define RGBLED_BPWMCHANNEL 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 */ #endif /* __BOARDS_ARM_STM32_STM32F103_MINIMUM_INCLUDE_BOARD_H */

View File

@ -155,23 +155,6 @@
* Private Data * 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 * Public Functions
****************************************************************************/ ****************************************************************************/
@ -303,7 +286,7 @@ int stm32_bringup(void)
#ifdef CONFIG_AUDIO_TONE #ifdef CONFIG_AUDIO_TONE
/* Configure and initialize the tone generator. */ /* Configure and initialize the tone generator. */
ret = board_tone_initialize(&g_tone_cfg, 0); ret = board_tone_initialize(0);
if (ret < 0) if (ret < 0)
{ {
syslog(LOG_ERR, "ERROR: stm32_tone_setup() failed: %d\n", ret); syslog(LOG_ERR, "ERROR: stm32_tone_setup() failed: %d\n", ret);
@ -460,7 +443,7 @@ int stm32_bringup(void)
#if defined(CONFIG_WL_NRF24L01) #if defined(CONFIG_WL_NRF24L01)
/* Initialize the NRF24L01 wireless module */ /* Initialize the NRF24L01 wireless module */
ret = board_nrf24l01_initialize(&g_nrf24l01_cfg, 1); ret = board_nrf24l01_initialize(1);
if (ret < 0) if (ret < 0)
{ {
syslog(LOG_ERR, "ERROR: board_nrf24l01_initialize failed: %d\n", ret); syslog(LOG_ERR, "ERROR: board_nrf24l01_initialize failed: %d\n", ret);

View File

@ -190,15 +190,6 @@
/* nRF24 Configuration */ /* 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 */ /* MCP2515 IRQ line: PB.0 */
#define GPIO_MCP2515_IRQ (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_PORTB|GPIO_PIN0) #define GPIO_MCP2515_IRQ (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_PORTB|GPIO_PIN0)