|
@@ -7,11 +7,7 @@
|
|
|
* Date Author Notes
|
|
|
* 2022-07-04 Rbb666 first version
|
|
|
*/
|
|
|
-#include "drv_common.h"
|
|
|
-#include "drv_adc.h"
|
|
|
-
|
|
|
-#include "cyhal.h"
|
|
|
-#include "cybsp.h"
|
|
|
+#include "drv_config.h"
|
|
|
|
|
|
#if defined(BSP_USING_ADC1) || defined(BSP_USING_ADC2)
|
|
|
|
|
@@ -19,15 +15,6 @@
|
|
|
#define LOG_TAG "drv.adc"
|
|
|
#include <drv_log.h>
|
|
|
|
|
|
-#define VPLUS_CHANNEL_0 (P10_0)
|
|
|
-
|
|
|
-struct ifx_adc
|
|
|
-{
|
|
|
- struct rt_adc_device ifx_adc_device;
|
|
|
- cyhal_adc_channel_t *adc_ch;
|
|
|
- char *name;
|
|
|
-};
|
|
|
-
|
|
|
static struct ifx_adc ifx_adc_obj[] =
|
|
|
{
|
|
|
#ifdef BSP_USING_ADC1
|
|
@@ -52,8 +39,7 @@ static rt_err_t ifx_adc_enabled(struct rt_adc_device *device, rt_uint32_t channe
|
|
|
|
|
|
if (enabled)
|
|
|
{
|
|
|
- /* Initialize ADC. The ADC block which can connect to pin 10[0] is selected */
|
|
|
- result = cyhal_adc_init(&adc_obj, VPLUS_CHANNEL_0, NULL);
|
|
|
+ result = cyhal_adc_init(&adc_obj, adc_gpio[channel], NULL);
|
|
|
|
|
|
if (result != RT_EOK)
|
|
|
{
|
|
@@ -61,8 +47,7 @@ static rt_err_t ifx_adc_enabled(struct rt_adc_device *device, rt_uint32_t channe
|
|
|
return -RT_ENOSYS;
|
|
|
}
|
|
|
|
|
|
- /* Initialize a channel 0 and configure it to scan P10_0 in single ended mode. */
|
|
|
- result = cyhal_adc_channel_init_diff(adc_ch, &adc_obj, VPLUS_CHANNEL_0,
|
|
|
+ result = cyhal_adc_channel_init_diff(adc_ch, &adc_obj, adc_gpio[channel],
|
|
|
CYHAL_ADC_VNEG, &channel_config);
|
|
|
|
|
|
if (result != RT_EOK)
|
|
@@ -76,14 +61,14 @@ static rt_err_t ifx_adc_enabled(struct rt_adc_device *device, rt_uint32_t channe
|
|
|
|
|
|
if (result != RT_EOK)
|
|
|
{
|
|
|
- printf("ADC configuration update failed. Error: %u\n", result);
|
|
|
+ rt_kprintf("ADC configuration update failed. Error: %u\n", result);
|
|
|
return -RT_ENOSYS;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- cyhal_adc_free(&adc_obj);
|
|
|
cyhal_adc_channel_free(adc_ch);
|
|
|
+ cyhal_adc_free(&adc_obj);
|
|
|
}
|
|
|
|
|
|
return RT_EOK;
|
|
@@ -119,7 +104,7 @@ static int rt_hw_adc_init(void)
|
|
|
/* register ADC device */
|
|
|
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)
|
|
|
{
|
|
|
- LOG_D("%s register success", at32_adc_obj[i].name);
|
|
|
+ LOG_D("%s register success", ifx_adc_obj[i].name);
|
|
|
}
|
|
|
else
|
|
|
{
|