Skip to content

Commit dcf637d

Browse files
yans6666Rbb666
authored andcommitted
[bsp][Infineon]修复psoc6-evaluationkit-062S2调用rt_adc_disable()时报错的问题
1 parent 2cf2161 commit dcf637d

File tree

5 files changed

+241
-21
lines changed

5 files changed

+241
-21
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2025-05-28 RTT the first version
9+
*/
10+
#ifndef __ADC_CONFIG_H__
11+
#define __ADC_CONFIG_H__
12+
13+
#include <rtthread.h>
14+
#include <rtdevice.h>
15+
#include "drv_common.h"
16+
#include "cyhal.h"
17+
#include "cybsp.h"
18+
19+
#ifdef __cplusplus
20+
extern "C"
21+
{
22+
#endif
23+
24+
#if defined(BSP_USING_ADC1) || defined(BSP_USING_ADC2)
25+
26+
cyhal_adc_t adc_obj;
27+
cyhal_adc_channel_t adc_chan_obj;
28+
29+
const cyhal_adc_config_t adc_config = {
30+
.continuous_scanning = false, // Continuous Scanning is disabled
31+
.average_count = 1, // Average count disabled
32+
.vref = CYHAL_ADC_REF_VDDA, // VREF for Single ended channel set to VDDA
33+
.vneg = CYHAL_ADC_VNEG_VSSA, // VNEG for Single ended channel set to VSSA
34+
.resolution = 12u, // 12-bit resolution
35+
.ext_vref = NC, // No connection
36+
.bypass_pin = NC // No connection
37+
};
38+
39+
struct ifx_adc
40+
{
41+
struct rt_adc_device ifx_adc_device;
42+
cyhal_adc_channel_t *adc_ch;
43+
char *name;
44+
};
45+
46+
const cyhal_gpio_t adc_gpio[6] = {P10_0, P10_1, P10_2, P10_3, P10_4, P10_5};
47+
48+
#ifndef ADC1_CONFIG
49+
#define ADC1_CONFIG \
50+
{ \
51+
.adc_ch = &adc_chan_obj, \
52+
.name = "adc1", \
53+
}
54+
#endif
55+
56+
#endif /* defined(BSP_USING_ADC1) || defined(BSP_USING_ADC2) */
57+
58+
#ifdef __cplusplus
59+
}
60+
#endif
61+
62+
#endif /* __ADC_CONFIG_H__ */
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2025-05-28 RTT the first version
9+
*/
10+
#ifndef __DRV_CONFIG_H__
11+
#define __DRV_CONFIG_H__
12+
13+
#include "board.h"
14+
#include <rtthread.h>
15+
16+
#ifdef __cplusplus
17+
extern "C"
18+
{
19+
#endif
20+
21+
#if defined(SOC_CY8C624ALQI_S2D42) || defined(SOC_CY8C6347BZI_BLD53) || defined(SOC_CY8C6247BZI_D54) || defined(SOC_CY8C6244LQI_S4D92)
22+
23+
#ifdef BSP_USING_ADC
24+
#include "cy8c62/adc_config.h"
25+
#endif
26+
27+
#endif /* SOC_CY8C624ALQI_S2D42 */
28+
29+
#if defined(SOC_XMC7100D_F144K4160AA)
30+
31+
#ifdef BSP_USING_ADC
32+
#include "xmc7100/adc_config.h"
33+
#endif
34+
35+
#endif /* SOC_XMC7100D_F144K4160AA */
36+
37+
#if defined(SOC_XMC7200D_E272K8384AA)
38+
39+
#ifdef BSP_USING_ADC
40+
#include "xmc7200/adc_config.h"
41+
#endif
42+
43+
#endif /* SOC_XMC7200D_E272K8384AA */
44+
45+
#ifdef __cplusplus
46+
}
47+
#endif
48+
49+
#endif /* __DRV_CONFIG_H__ */
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2025-05-28 RTT the first version
9+
*/
10+
#ifndef __ADC_CONFIG_H__
11+
#define __ADC_CONFIG_H__
12+
13+
#include <rtthread.h>
14+
#include <rtdevice.h>
15+
#include "drv_common.h"
16+
#include "cyhal.h"
17+
#include "cybsp.h"
18+
19+
#ifdef __cplusplus
20+
extern "C"
21+
{
22+
#endif
23+
24+
#if defined(BSP_USING_ADC1) || defined(BSP_USING_ADC2)
25+
26+
cyhal_adc_t adc_obj;
27+
cyhal_adc_channel_t adc_chan_obj;
28+
29+
const cyhal_adc_config_t adc_config = {
30+
.continuous_scanning = false, // Continuous Scanning is disabled
31+
.average_count = 1, // Average count disabled
32+
.vref = CYHAL_ADC_REF_VDDA, // VREF for Single ended channel set to VDDA
33+
.vneg = CYHAL_ADC_VNEG_VSSA, // VNEG for Single ended channel set to VSSA
34+
.resolution = 12u, // 12-bit resolution
35+
.ext_vref = NC, // No connection
36+
.bypass_pin = NC // No connection
37+
};
38+
39+
struct ifx_adc
40+
{
41+
struct rt_adc_device ifx_adc_device;
42+
cyhal_adc_channel_t *adc_ch;
43+
char *name;
44+
};
45+
46+
const cyhal_gpio_t adc_gpio[8] = {P6_0, P11_0, P11_1, P11_2, P12_4, P13_7, P14_2, P14_3};
47+
48+
#ifndef ADC1_CONFIG
49+
#define ADC1_CONFIG \
50+
{ \
51+
.adc_ch = &adc_chan_obj, \
52+
.name = "adc1", \
53+
}
54+
#endif
55+
56+
#endif /* defined(BSP_USING_ADC1) || defined(BSP_USING_ADC2) */
57+
58+
#ifdef __cplusplus
59+
}
60+
#endif
61+
62+
#endif /* __ADC_CONFIG_H__ */
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2025-05-28 RTT the first version
9+
*/
10+
#ifndef __ADC_CONFIG_H__
11+
#define __ADC_CONFIG_H__
12+
13+
#include <rtthread.h>
14+
#include <rtdevice.h>
15+
#include "drv_common.h"
16+
#include "cyhal.h"
17+
#include "cybsp.h"
18+
19+
#ifdef __cplusplus
20+
extern "C"
21+
{
22+
#endif
23+
24+
#if defined(BSP_USING_ADC1) || defined(BSP_USING_ADC2)
25+
26+
cyhal_adc_t adc_obj;
27+
cyhal_adc_channel_t adc_chan_obj;
28+
29+
const cyhal_adc_config_t adc_config = {
30+
.continuous_scanning = false, // Continuous Scanning is disabled
31+
.average_count = 1, // Average count disabled
32+
.vref = CYHAL_ADC_REF_VDDA, // VREF for Single ended channel set to VDDA
33+
.vneg = CYHAL_ADC_VNEG_VSSA, // VNEG for Single ended channel set to VSSA
34+
.resolution = 12u, // 12-bit resolution
35+
.ext_vref = NC, // No connection
36+
.bypass_pin = NC // No connection
37+
};
38+
39+
struct ifx_adc
40+
{
41+
struct rt_adc_device ifx_adc_device;
42+
cyhal_adc_channel_t *adc_ch;
43+
char *name;
44+
};
45+
46+
const cyhal_gpio_t adc_gpio[8] = {P14_0, P14_1, P14_2, P14_3, P14_4, P14_5, P14_6, P14_7};
47+
48+
#ifndef ADC1_CONFIG
49+
#define ADC1_CONFIG \
50+
{ \
51+
.adc_ch = &adc_chan_obj, \
52+
.name = "adc1", \
53+
}
54+
#endif
55+
56+
#endif /* defined(BSP_USING_ADC1) || defined(BSP_USING_ADC2) */
57+
58+
#ifdef __cplusplus
59+
}
60+
#endif
61+
62+
#endif /* __ADC_CONFIG_H__ */

bsp/Infineon/libraries/HAL_Drivers/drv_adc.c

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,14 @@
77
* Date Author Notes
88
* 2022-07-04 Rbb666 first version
99
*/
10-
#include "drv_common.h"
11-
#include "drv_adc.h"
12-
13-
#include "cyhal.h"
14-
#include "cybsp.h"
10+
#include "drv_config.h"
1511

1612
#if defined(BSP_USING_ADC1) || defined(BSP_USING_ADC2)
1713

1814
/*#define DRV_DEBUG*/
1915
#define LOG_TAG "drv.adc"
2016
#include <drv_log.h>
2117

22-
#define VPLUS_CHANNEL_0 (P10_0)
23-
24-
struct ifx_adc
25-
{
26-
struct rt_adc_device ifx_adc_device;
27-
cyhal_adc_channel_t *adc_ch;
28-
char *name;
29-
};
30-
3118
static struct ifx_adc ifx_adc_obj[] =
3219
{
3320
#ifdef BSP_USING_ADC1
@@ -52,17 +39,15 @@ static rt_err_t ifx_adc_enabled(struct rt_adc_device *device, rt_uint32_t channe
5239

5340
if (enabled)
5441
{
55-
/* Initialize ADC. The ADC block which can connect to pin 10[0] is selected */
56-
result = cyhal_adc_init(&adc_obj, VPLUS_CHANNEL_0, NULL);
42+
result = cyhal_adc_init(&adc_obj, adc_gpio[channel], NULL);
5743

5844
if (result != RT_EOK)
5945
{
6046
LOG_E("ADC initialization failed. Error: %u\n", result);
6147
return -RT_ENOSYS;
6248
}
6349

64-
/* Initialize a channel 0 and configure it to scan P10_0 in single ended mode. */
65-
result = cyhal_adc_channel_init_diff(adc_ch, &adc_obj, VPLUS_CHANNEL_0,
50+
result = cyhal_adc_channel_init_diff(adc_ch, &adc_obj, adc_gpio[channel],
6651
CYHAL_ADC_VNEG, &channel_config);
6752

6853
if (result != RT_EOK)
@@ -76,14 +61,14 @@ static rt_err_t ifx_adc_enabled(struct rt_adc_device *device, rt_uint32_t channe
7661

7762
if (result != RT_EOK)
7863
{
79-
printf("ADC configuration update failed. Error: %u\n", result);
64+
rt_kprintf("ADC configuration update failed. Error: %u\n", result);
8065
return -RT_ENOSYS;
8166
}
8267
}
8368
else
8469
{
85-
cyhal_adc_free(&adc_obj);
8670
cyhal_adc_channel_free(adc_ch);
71+
cyhal_adc_free(&adc_obj);
8772
}
8873

8974
return RT_EOK;
@@ -119,7 +104,7 @@ static int rt_hw_adc_init(void)
119104
/* register ADC device */
120105
if (rt_hw_adc_register(&ifx_adc_obj[i].ifx_adc_device, ifx_adc_obj[i].name, &at_adc_ops, ifx_adc_obj[i].adc_ch) == RT_EOK)
121106
{
122-
LOG_D("%s register success", at32_adc_obj[i].name);
107+
LOG_D("%s register success", ifx_adc_obj[i].name);
123108
}
124109
else
125110
{

0 commit comments

Comments
 (0)