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-
3118static 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