[Infineon]Add slider driver demo

This commit is contained in:
Rbb666 2023-03-30 15:23:55 +08:00 committed by guo
parent 8552d061c2
commit 4aa38e3d86
6 changed files with 43 additions and 39 deletions

View File

@ -95,7 +95,7 @@ static void irq_callback(void *callback_arg, cyhal_gpio_event_t event)
cyhal_gpio_callback_data_t irq_cb_data; 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; 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; 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); 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; 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); return cyhal_gpio_read(gpio_pin);
} }
static rt_err_t ifx_pin_attach_irq(struct rt_device *device, rt_int32_t pin, static rt_err_t ifx_pin_attach_irq(struct rt_device *device, rt_base_t pin,
rt_uint32_t mode, void (*hdr)(void *args), void *args) rt_uint8_t mode, void (*hdr)(void *args), void *args)
{ {
rt_uint16_t gpio_port; rt_uint16_t gpio_port;
rt_uint16_t gpio_pin; 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; 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_port;
rt_uint16_t gpio_pin; 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, 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_port;
rt_uint16_t gpio_pin; rt_uint16_t gpio_pin;

View File

@ -31,8 +31,8 @@ struct ifx_pwm
static struct ifx_pwm ifx_pwm_obj[] = static struct ifx_pwm ifx_pwm_obj[] =
{ {
#ifdef BSP_USING_PWM0_PORT13 #ifdef BSP_USING_PWM0_PORT0
PWM0_CH3_PORT13_CONFIG, PWM0_CH0_PORT0_CONFIG,
#endif #endif
#ifdef BSP_USING_PWM0_PORT2 #ifdef BSP_USING_PWM0_PORT2
@ -58,6 +58,10 @@ static struct ifx_pwm ifx_pwm_obj[] =
#ifdef BSP_USING_PWM0_PORT12 #ifdef BSP_USING_PWM0_PORT12
PWM0_CH7_PORT12_CONFIG, PWM0_CH7_PORT12_CONFIG,
#endif #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) 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); RT_ASSERT(device != RT_NULL);
/* config pwm channel */ if (cyhal_pwm_init_adv(device->pwm_obj, device->gpio, NC, CYHAL_PWM_LEFT_ALIGN, true, 0u, false, RT_NULL) != RT_EOK)
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) LOG_E("%s channel%d config failed", device->name, device->channel);
{ result = -RT_ERROR;
LOG_E("%s channel3 config failed", device->name); goto __exit;
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;
}
} }
__exit: __exit:
return result; return result;
} }

View File

@ -22,12 +22,12 @@ extern "C"
#define MAX_PERIOD 65535 #define MAX_PERIOD 65535
#ifdef BSP_USING_PWM0 #ifdef BSP_USING_PWM0
#ifndef PWM0_CH3_PORT13_CONFIG #ifndef PWM0_CH0_PORT0_CONFIG
#define PWM0_CH3_PORT13_CONFIG \ #define PWM0_CH0_PORT0_CONFIG \
{ \ { \
.name = "pwm0", \ .name = "pwm0", \
.channel = 3, \ .channel = 0, \
.gpio = GET_PIN(13, 7), \ .gpio = GET_PIN(0, 0), \
} }
#endif /* PWM0_CH7_PORT2_CONFIG */ #endif /* PWM0_CH7_PORT2_CONFIG */
@ -84,6 +84,15 @@ extern "C"
.gpio = GET_PIN(12, 6), \ .gpio = GET_PIN(12, 6), \
} }
#endif /* PWM0_CH7_PORT12_CONFIG */ #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 */ #endif /* BSP_USING_PWM0 */
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -13,7 +13,7 @@
#include "drv_gpio.h" #include "drv_gpio.h"
#define LED_PIN GET_PIN(0, 0) #define LED_PIN GET_PIN(0, 1)
int main(void) int main(void)
{ {

View File

@ -60,12 +60,12 @@ menu "On-chip Peripheral Drivers"
bool "Enable timer0 output pwm" bool "Enable timer0 output pwm"
default n default n
if BSP_USING_PWM0 if BSP_USING_PWM0
menuconfig BSP_USING_PWM0_CH3 menuconfig BSP_USING_PWM0_CH0
bool "Enable PWM0 channel3" bool "Enable PWM0 channel0"
default n default n
if BSP_USING_PWM0_CH3 if BSP_USING_PWM0_CH0
config BSP_USING_PWM0_PORT13 config BSP_USING_PWM0_PORT0
bool "Enable PWM0-PORT13 output pwm" bool "Enable PWM0-PORT0 output pwm"
default n default n
endif endif
menuconfig BSP_USING_PWM0_CH7 menuconfig BSP_USING_PWM0_CH7
@ -263,6 +263,10 @@ menu "Board extended module Drivers"
config BSP_USING_SLIDER config BSP_USING_SLIDER
bool "Enable Slider Demo" bool "Enable Slider Demo"
select BSP_USING_PWM
select BSP_USING_PWM0
select BSP_USING_PWM0_CH0
select BSP_USING_PWM0_PORT0
default n default n
menuconfig BSP_USING_RW007 menuconfig BSP_USING_RW007

View File

@ -44,7 +44,7 @@ static rt_thread_t sld_thread = RT_NULL;
#error You need enable PWM to use this sample #error You need enable PWM to use this sample
#else #else
#define PWM_DEV_NAME "pwm0" #define PWM_DEV_NAME "pwm0"
#define PWM_DEV_CHANNEL 3 #define PWM_DEV_CHANNEL 0
static struct rt_device_pwm *pwm_dev; static struct rt_device_pwm *pwm_dev;
#endif #endif
@ -128,7 +128,7 @@ void Slider_Init(void)
return; return;
} }
#ifdef BSP_USING_PWM0_PORT13 #ifdef BSP_USING_PWM0_PORT0
/* Initiate PWM*/ /* Initiate PWM*/
pwm_dev = (struct rt_device_pwm *)rt_device_find(PWM_DEV_NAME); pwm_dev = (struct rt_device_pwm *)rt_device_find(PWM_DEV_NAME);