From 4ceffbf06aa599dca424200280c1044026e6119f Mon Sep 17 00:00:00 2001 From: Yuqiang Wang Date: Mon, 1 Apr 2024 08:31:27 +0800 Subject: [PATCH] [bsp][renesas] rtduino supports the soft spi switch to pwm function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.修改drv_gpio.c:R_IOPORT_Open()函数只需执行一次,修改位置为init时执行 2.默认HMI-Board使能rtduino后支持soft spi,通过switch_pwm可切换为pwm功能 --- bsp/renesas/libraries/HAL_Drivers/drv_gpio.c | 19 ++++++++------- .../rtduino/arduino_pinout/pins_arduino.c | 24 ++++++++++++++++++- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/bsp/renesas/libraries/HAL_Drivers/drv_gpio.c b/bsp/renesas/libraries/HAL_Drivers/drv_gpio.c index 6dc7df3d8b..bd223df0e6 100644 --- a/bsp/renesas/libraries/HAL_Drivers/drv_gpio.c +++ b/bsp/renesas/libraries/HAL_Drivers/drv_gpio.c @@ -114,14 +114,6 @@ static void ra_pin_map_init(void) static void ra_pin_mode(rt_device_t dev, rt_base_t pin, rt_uint8_t mode) { fsp_err_t err; - /* Initialize the IOPORT module and configure the pins */ - err = R_IOPORT_Open(&g_ioport_ctrl, &g_bsp_pin_cfg); - - if (err != FSP_SUCCESS) - { - LOG_E("GPIO open failed"); - return; - } switch (mode) { @@ -335,6 +327,17 @@ int rt_hw_pin_init(void) ra_irq_tab_init(); ra_pin_map_init(); #endif + + fsp_err_t err; + /* Initialize the IOPORT module and configure the pins */ + err = R_IOPORT_Open(&g_ioport_ctrl, &g_bsp_pin_cfg); + + if (err != FSP_SUCCESS) + { + LOG_E("GPIO open failed"); + return -1; + } + return rt_device_pin_register("pin", &_ra_pin_ops, RT_NULL); } diff --git a/bsp/renesas/ra6m3-hmi-board/board/rtduino/arduino_pinout/pins_arduino.c b/bsp/renesas/ra6m3-hmi-board/board/rtduino/arduino_pinout/pins_arduino.c index 55988b14b0..30cd79201a 100644 --- a/bsp/renesas/ra6m3-hmi-board/board/rtduino/arduino_pinout/pins_arduino.c +++ b/bsp/renesas/ra6m3-hmi-board/board/rtduino/arduino_pinout/pins_arduino.c @@ -46,4 +46,26 @@ const pin_map_t pin_map_table[]= {A3, BSP_IO_PORT_00_PIN_03, "adc0", 7}, /* ADC */ {A4, BSP_IO_PORT_05_PIN_08, "adc0", 20}, /* ADC */ {A5, BSP_IO_PORT_00_PIN_14, "adc0", 5} /* ADC */ -}; \ No newline at end of file +}; + +static ioport_instance_ctrl_t g_pwm_ioport_ctrl; +static const ioport_pin_cfg_t g_pwm_pin_cfg_data[] = { + { + .pin = BSP_IO_PORT_05_PIN_12, + .pin_cfg = ((uint32_t) IOPORT_CFG_PERIPHERAL_PIN | (uint32_t) IOPORT_PERIPHERAL_GPT1) + }, +}; + +static const ioport_cfg_t g_pwm_pin_cfg = { + .number_of_pins = sizeof(g_pwm_pin_cfg_data)/sizeof(ioport_pin_cfg_t), + .p_pin_cfg_data = &g_pwm_pin_cfg_data[0], +}; + +void switchToPWM(const char *device_name) +{ + if(!rt_strcmp(device_name, "pwm0")) + { + R_IOPORT_Open(&g_pwm_ioport_ctrl, &g_pwm_pin_cfg); + LOG_I("D11 will switch from SPI to PWM"); + } +}