Skip to content

Commit 4aa38e3

Browse files
Rbb666Guozhanxin
authored andcommitted
[Infineon]Add slider driver demo
1 parent 8552d06 commit 4aa38e3

6 files changed

Lines changed: 43 additions & 39 deletions

File tree

bsp/Infineon/libraries/HAL_Drivers/drv_gpio.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void irq_callback(void *callback_arg, cyhal_gpio_event_t event)
9595

9696
cyhal_gpio_callback_data_t irq_cb_data;
9797

98-
static void ifx_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
98+
static void ifx_pin_mode(rt_device_t dev, rt_base_t pin, rt_uint8_t mode)
9999
{
100100
rt_uint16_t gpio_pin;
101101

@@ -132,7 +132,7 @@ static void ifx_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
132132
}
133133
}
134134

135-
static void ifx_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value)
135+
static void ifx_pin_write(rt_device_t dev, rt_base_t pin, rt_uint8_t value)
136136
{
137137
rt_uint16_t gpio_pin;
138138

@@ -148,7 +148,7 @@ static void ifx_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value)
148148
cyhal_gpio_write(gpio_pin, value);
149149
}
150150

151-
static int ifx_pin_read(rt_device_t dev, rt_base_t pin)
151+
static rt_int8_t ifx_pin_read(struct rt_device *device, rt_base_t pin)
152152
{
153153
rt_uint16_t gpio_pin;
154154

@@ -164,8 +164,8 @@ static int ifx_pin_read(rt_device_t dev, rt_base_t pin)
164164
return cyhal_gpio_read(gpio_pin);
165165
}
166166

167-
static rt_err_t ifx_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
168-
rt_uint32_t mode, void (*hdr)(void *args), void *args)
167+
static rt_err_t ifx_pin_attach_irq(struct rt_device *device, rt_base_t pin,
168+
rt_uint8_t mode, void (*hdr)(void *args), void *args)
169169
{
170170
rt_uint16_t gpio_port;
171171
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,
207207
return RT_EOK;
208208
}
209209

210-
static rt_err_t ifx_pin_dettach_irq(struct rt_device *device, rt_int32_t pin)
210+
static rt_err_t ifx_pin_dettach_irq(struct rt_device *device, rt_base_t pin)
211211
{
212212
rt_uint16_t gpio_port;
213213
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)
241241
}
242242

243243
static rt_err_t ifx_pin_irq_enable(struct rt_device *device, rt_base_t pin,
244-
rt_uint32_t enabled)
244+
rt_uint8_t enabled)
245245
{
246246
rt_uint16_t gpio_port;
247247
rt_uint16_t gpio_pin;

bsp/Infineon/libraries/HAL_Drivers/drv_pwm.c

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ struct ifx_pwm
3131

3232
static struct ifx_pwm ifx_pwm_obj[] =
3333
{
34-
#ifdef BSP_USING_PWM0_PORT13
35-
PWM0_CH3_PORT13_CONFIG,
34+
#ifdef BSP_USING_PWM0_PORT0
35+
PWM0_CH0_PORT0_CONFIG,
3636
#endif
3737

3838
#ifdef BSP_USING_PWM0_PORT2
@@ -58,6 +58,10 @@ static struct ifx_pwm ifx_pwm_obj[] =
5858
#ifdef BSP_USING_PWM0_PORT12
5959
PWM0_CH7_PORT12_CONFIG,
6060
#endif
61+
62+
#ifdef BSP_USING_PWM0_PORT13
63+
PWM0_CH3_PORT13_CONFIG,
64+
#endif
6165
};
6266

6367
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)
165169

166170
RT_ASSERT(device != RT_NULL);
167171

168-
/* config pwm channel */
169-
if (device->channel == 0x03)
172+
if (cyhal_pwm_init_adv(device->pwm_obj, device->gpio, NC, CYHAL_PWM_LEFT_ALIGN, true, 0u, false, RT_NULL) != RT_EOK)
170173
{
171-
if (cyhal_pwm_init_adv(device->pwm_obj, device->gpio, NC, CYHAL_PWM_LEFT_ALIGN, true, 0u, false, RT_NULL) != RT_EOK)
172-
{
173-
LOG_E("%s channel3 config failed", device->name);
174-
result = -RT_ERROR;
175-
goto __exit;
176-
}
177-
}
178-
/* config pwm channel */
179-
if (device->channel == 0x07)
180-
{
181-
if (cyhal_pwm_init_adv(device->pwm_obj, device->gpio, NC, CYHAL_PWM_LEFT_ALIGN, true, 0u, false, RT_NULL) != RT_EOK)
182-
{
183-
LOG_E("%s channel7 config failed", device->name);
184-
result = -RT_ERROR;
185-
goto __exit;
186-
}
174+
LOG_E("%s channel%d config failed", device->name, device->channel);
175+
result = -RT_ERROR;
176+
goto __exit;
187177
}
178+
188179
__exit:
189180
return result;
190181
}

bsp/Infineon/libraries/HAL_Drivers/drv_pwm.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ extern "C"
2222
#define MAX_PERIOD 65535
2323

2424
#ifdef BSP_USING_PWM0
25-
#ifndef PWM0_CH3_PORT13_CONFIG
26-
#define PWM0_CH3_PORT13_CONFIG \
25+
#ifndef PWM0_CH0_PORT0_CONFIG
26+
#define PWM0_CH0_PORT0_CONFIG \
2727
{ \
2828
.name = "pwm0", \
29-
.channel = 3, \
30-
.gpio = GET_PIN(13, 7), \
29+
.channel = 0, \
30+
.gpio = GET_PIN(0, 0), \
3131
}
3232
#endif /* PWM0_CH7_PORT2_CONFIG */
3333

@@ -84,6 +84,15 @@ extern "C"
8484
.gpio = GET_PIN(12, 6), \
8585
}
8686
#endif /* PWM0_CH7_PORT12_CONFIG */
87+
88+
#ifndef PWM0_CH3_PORT13_CONFIG
89+
#define PWM0_CH3_PORT13_CONFIG \
90+
{ \
91+
.name = "pwm0", \
92+
.channel = 3, \
93+
.gpio = GET_PIN(13, 7), \
94+
}
95+
#endif /* PWM0_CH3_PORT13_CONFIG */
8796
#endif /* BSP_USING_PWM0 */
8897

8998
#ifdef __cplusplus

bsp/Infineon/psoc6-evaluationkit-062S2/applications/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include "drv_gpio.h"
1515

16-
#define LED_PIN GET_PIN(0, 0)
16+
#define LED_PIN GET_PIN(0, 1)
1717

1818
int main(void)
1919
{

bsp/Infineon/psoc6-evaluationkit-062S2/board/Kconfig

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ menu "On-chip Peripheral Drivers"
6060
bool "Enable timer0 output pwm"
6161
default n
6262
if BSP_USING_PWM0
63-
menuconfig BSP_USING_PWM0_CH3
64-
bool "Enable PWM0 channel3"
63+
menuconfig BSP_USING_PWM0_CH0
64+
bool "Enable PWM0 channel0"
6565
default n
66-
if BSP_USING_PWM0_CH3
67-
config BSP_USING_PWM0_PORT13
68-
bool "Enable PWM0-PORT13 output pwm"
66+
if BSP_USING_PWM0_CH0
67+
config BSP_USING_PWM0_PORT0
68+
bool "Enable PWM0-PORT0 output pwm"
6969
default n
7070
endif
7171
menuconfig BSP_USING_PWM0_CH7
@@ -263,6 +263,10 @@ menu "Board extended module Drivers"
263263

264264
config BSP_USING_SLIDER
265265
bool "Enable Slider Demo"
266+
select BSP_USING_PWM
267+
select BSP_USING_PWM0
268+
select BSP_USING_PWM0_CH0
269+
select BSP_USING_PWM0_PORT0
266270
default n
267271

268272
menuconfig BSP_USING_RW007

bsp/Infineon/psoc6-evaluationkit-062S2/board/ports/slider_sample.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static rt_thread_t sld_thread = RT_NULL;
4444
#error You need enable PWM to use this sample
4545
#else
4646
#define PWM_DEV_NAME "pwm0"
47-
#define PWM_DEV_CHANNEL 3
47+
#define PWM_DEV_CHANNEL 0
4848
static struct rt_device_pwm *pwm_dev;
4949
#endif
5050

@@ -128,7 +128,7 @@ void Slider_Init(void)
128128
return;
129129
}
130130

131-
#ifdef BSP_USING_PWM0_PORT13
131+
#ifdef BSP_USING_PWM0_PORT0
132132
/* Initiate PWM*/
133133
pwm_dev = (struct rt_device_pwm *)rt_device_find(PWM_DEV_NAME);
134134

0 commit comments

Comments
 (0)