From 4aa38e3d86543f486d16dbf552156f96e7e14500 Mon Sep 17 00:00:00 2001 From: Rbb666 Date: Thu, 30 Mar 2023 15:23:55 +0800 Subject: [PATCH] [Infineon]Add slider driver demo --- bsp/Infineon/libraries/HAL_Drivers/drv_gpio.c | 14 ++++----- bsp/Infineon/libraries/HAL_Drivers/drv_pwm.c | 31 +++++++------------ bsp/Infineon/libraries/HAL_Drivers/drv_pwm.h | 17 +++++++--- .../applications/main.c | 2 +- .../psoc6-evaluationkit-062S2/board/Kconfig | 14 ++++++--- .../board/ports/slider_sample.c | 4 +-- 6 files changed, 43 insertions(+), 39 deletions(-) diff --git a/bsp/Infineon/libraries/HAL_Drivers/drv_gpio.c b/bsp/Infineon/libraries/HAL_Drivers/drv_gpio.c index 5f50a370f6..9e8b8a2e8b 100644 --- a/bsp/Infineon/libraries/HAL_Drivers/drv_gpio.c +++ b/bsp/Infineon/libraries/HAL_Drivers/drv_gpio.c @@ -95,7 +95,7 @@ static void irq_callback(void *callback_arg, cyhal_gpio_event_t event) cyhal_gpio_callback_data_t irq_cb_data; -static void ifx_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode) +static void ifx_pin_mode(rt_device_t dev, rt_base_t pin, rt_uint8_t mode) { rt_uint16_t gpio_pin; @@ -132,7 +132,7 @@ static void ifx_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode) } } -static void ifx_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value) +static void ifx_pin_write(rt_device_t dev, rt_base_t pin, rt_uint8_t value) { rt_uint16_t gpio_pin; @@ -148,7 +148,7 @@ static void ifx_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value) cyhal_gpio_write(gpio_pin, value); } -static int ifx_pin_read(rt_device_t dev, rt_base_t pin) +static rt_int8_t ifx_pin_read(struct rt_device *device, rt_base_t pin) { rt_uint16_t gpio_pin; @@ -164,8 +164,8 @@ static int ifx_pin_read(rt_device_t dev, rt_base_t pin) return cyhal_gpio_read(gpio_pin); } -static rt_err_t ifx_pin_attach_irq(struct rt_device *device, rt_int32_t pin, - rt_uint32_t mode, void (*hdr)(void *args), void *args) +static rt_err_t ifx_pin_attach_irq(struct rt_device *device, rt_base_t pin, + rt_uint8_t mode, void (*hdr)(void *args), void *args) { rt_uint16_t gpio_port; rt_uint16_t gpio_pin; @@ -207,7 +207,7 @@ static rt_err_t ifx_pin_attach_irq(struct rt_device *device, rt_int32_t pin, return RT_EOK; } -static rt_err_t ifx_pin_dettach_irq(struct rt_device *device, rt_int32_t pin) +static rt_err_t ifx_pin_dettach_irq(struct rt_device *device, rt_base_t pin) { rt_uint16_t gpio_port; rt_uint16_t gpio_pin; @@ -241,7 +241,7 @@ static rt_err_t ifx_pin_dettach_irq(struct rt_device *device, rt_int32_t pin) } static rt_err_t ifx_pin_irq_enable(struct rt_device *device, rt_base_t pin, - rt_uint32_t enabled) + rt_uint8_t enabled) { rt_uint16_t gpio_port; rt_uint16_t gpio_pin; diff --git a/bsp/Infineon/libraries/HAL_Drivers/drv_pwm.c b/bsp/Infineon/libraries/HAL_Drivers/drv_pwm.c index 534bd65be9..b25e61e9e0 100644 --- a/bsp/Infineon/libraries/HAL_Drivers/drv_pwm.c +++ b/bsp/Infineon/libraries/HAL_Drivers/drv_pwm.c @@ -31,8 +31,8 @@ struct ifx_pwm static struct ifx_pwm ifx_pwm_obj[] = { -#ifdef BSP_USING_PWM0_PORT13 - PWM0_CH3_PORT13_CONFIG, +#ifdef BSP_USING_PWM0_PORT0 + PWM0_CH0_PORT0_CONFIG, #endif #ifdef BSP_USING_PWM0_PORT2 @@ -58,6 +58,10 @@ static struct ifx_pwm ifx_pwm_obj[] = #ifdef BSP_USING_PWM0_PORT12 PWM0_CH7_PORT12_CONFIG, #endif + +#ifdef BSP_USING_PWM0_PORT13 + PWM0_CH3_PORT13_CONFIG, +#endif }; static rt_err_t drv_pwm_enable(cyhal_pwm_t *htim, struct rt_pwm_configuration *configuration, rt_bool_t enable) @@ -165,26 +169,13 @@ static rt_err_t ifx_hw_pwm_init(struct ifx_pwm *device) RT_ASSERT(device != RT_NULL); - /* config pwm channel */ - if (device->channel == 0x03) + if (cyhal_pwm_init_adv(device->pwm_obj, device->gpio, NC, CYHAL_PWM_LEFT_ALIGN, true, 0u, false, RT_NULL) != RT_EOK) { - if (cyhal_pwm_init_adv(device->pwm_obj, device->gpio, NC, CYHAL_PWM_LEFT_ALIGN, true, 0u, false, RT_NULL) != RT_EOK) - { - LOG_E("%s channel3 config failed", device->name); - result = -RT_ERROR; - goto __exit; - } - } - /* config pwm channel */ - if (device->channel == 0x07) - { - if (cyhal_pwm_init_adv(device->pwm_obj, device->gpio, NC, CYHAL_PWM_LEFT_ALIGN, true, 0u, false, RT_NULL) != RT_EOK) - { - LOG_E("%s channel7 config failed", device->name); - result = -RT_ERROR; - goto __exit; - } + LOG_E("%s channel%d config failed", device->name, device->channel); + result = -RT_ERROR; + goto __exit; } + __exit: return result; } diff --git a/bsp/Infineon/libraries/HAL_Drivers/drv_pwm.h b/bsp/Infineon/libraries/HAL_Drivers/drv_pwm.h index 39be7552f3..be5dbee9c9 100644 --- a/bsp/Infineon/libraries/HAL_Drivers/drv_pwm.h +++ b/bsp/Infineon/libraries/HAL_Drivers/drv_pwm.h @@ -22,12 +22,12 @@ extern "C" #define MAX_PERIOD 65535 #ifdef BSP_USING_PWM0 -#ifndef PWM0_CH3_PORT13_CONFIG -#define PWM0_CH3_PORT13_CONFIG \ +#ifndef PWM0_CH0_PORT0_CONFIG +#define PWM0_CH0_PORT0_CONFIG \ { \ .name = "pwm0", \ - .channel = 3, \ - .gpio = GET_PIN(13, 7), \ + .channel = 0, \ + .gpio = GET_PIN(0, 0), \ } #endif /* PWM0_CH7_PORT2_CONFIG */ @@ -84,6 +84,15 @@ extern "C" .gpio = GET_PIN(12, 6), \ } #endif /* PWM0_CH7_PORT12_CONFIG */ + +#ifndef PWM0_CH3_PORT13_CONFIG +#define PWM0_CH3_PORT13_CONFIG \ + { \ + .name = "pwm0", \ + .channel = 3, \ + .gpio = GET_PIN(13, 7), \ + } +#endif /* PWM0_CH3_PORT13_CONFIG */ #endif /* BSP_USING_PWM0 */ #ifdef __cplusplus diff --git a/bsp/Infineon/psoc6-evaluationkit-062S2/applications/main.c b/bsp/Infineon/psoc6-evaluationkit-062S2/applications/main.c index 7b37507c74..b370836071 100644 --- a/bsp/Infineon/psoc6-evaluationkit-062S2/applications/main.c +++ b/bsp/Infineon/psoc6-evaluationkit-062S2/applications/main.c @@ -13,7 +13,7 @@ #include "drv_gpio.h" -#define LED_PIN GET_PIN(0, 0) +#define LED_PIN GET_PIN(0, 1) int main(void) { diff --git a/bsp/Infineon/psoc6-evaluationkit-062S2/board/Kconfig b/bsp/Infineon/psoc6-evaluationkit-062S2/board/Kconfig index cb989c32c6..77e3e6a916 100644 --- a/bsp/Infineon/psoc6-evaluationkit-062S2/board/Kconfig +++ b/bsp/Infineon/psoc6-evaluationkit-062S2/board/Kconfig @@ -60,12 +60,12 @@ menu "On-chip Peripheral Drivers" bool "Enable timer0 output pwm" default n if BSP_USING_PWM0 - menuconfig BSP_USING_PWM0_CH3 - bool "Enable PWM0 channel3" + menuconfig BSP_USING_PWM0_CH0 + bool "Enable PWM0 channel0" default n - if BSP_USING_PWM0_CH3 - config BSP_USING_PWM0_PORT13 - bool "Enable PWM0-PORT13 output pwm" + if BSP_USING_PWM0_CH0 + config BSP_USING_PWM0_PORT0 + bool "Enable PWM0-PORT0 output pwm" default n endif menuconfig BSP_USING_PWM0_CH7 @@ -263,6 +263,10 @@ menu "Board extended module Drivers" config BSP_USING_SLIDER bool "Enable Slider Demo" + select BSP_USING_PWM + select BSP_USING_PWM0 + select BSP_USING_PWM0_CH0 + select BSP_USING_PWM0_PORT0 default n menuconfig BSP_USING_RW007 diff --git a/bsp/Infineon/psoc6-evaluationkit-062S2/board/ports/slider_sample.c b/bsp/Infineon/psoc6-evaluationkit-062S2/board/ports/slider_sample.c index a4599ceaa7..8d4f14b2a2 100644 --- a/bsp/Infineon/psoc6-evaluationkit-062S2/board/ports/slider_sample.c +++ b/bsp/Infineon/psoc6-evaluationkit-062S2/board/ports/slider_sample.c @@ -44,7 +44,7 @@ static rt_thread_t sld_thread = RT_NULL; #error You need enable PWM to use this sample #else #define PWM_DEV_NAME "pwm0" - #define PWM_DEV_CHANNEL 3 + #define PWM_DEV_CHANNEL 0 static struct rt_device_pwm *pwm_dev; #endif @@ -128,7 +128,7 @@ void Slider_Init(void) return; } -#ifdef BSP_USING_PWM0_PORT13 +#ifdef BSP_USING_PWM0_PORT0 /* Initiate PWM*/ pwm_dev = (struct rt_device_pwm *)rt_device_find(PWM_DEV_NAME);