From 4fc94e839f1d4ced242d4e29c21800d9037eb007 Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Wed, 12 Jul 2023 13:20:46 +0530 Subject: [PATCH] ports/psoc6: Removing additional driver layer. Signed-off-by: NikhitaR-IFX --- ports/psoc6/Makefile | 1 - ports/psoc6/drivers/machine/psoc6_adc.c | 47 ------------------- ports/psoc6/drivers/machine/psoc6_adc.h | 21 --------- ports/psoc6/modules/machine/machine_adc.c | 13 +++-- .../psoc6/modules/machine/machine_adcblock.c | 3 -- .../psoc6/modules/machine/machine_adcblock.h | 2 +- 6 files changed, 9 insertions(+), 78 deletions(-) delete mode 100644 ports/psoc6/drivers/machine/psoc6_adc.c delete mode 100644 ports/psoc6/drivers/machine/psoc6_adc.h diff --git a/ports/psoc6/Makefile b/ports/psoc6/Makefile index 3b75d086c5a8..674efa51d844 100644 --- a/ports/psoc6/Makefile +++ b/ports/psoc6/Makefile @@ -129,7 +129,6 @@ DRIVERS_SRC_C += $(addprefix drivers/,\ machine/psoc6_i2c.c \ machine/psoc6_pwm.c \ machine/psoc6_system.c \ - machine/psoc6_adc.c \ ) MOD_SRC_C += $(addprefix modules/,\ diff --git a/ports/psoc6/drivers/machine/psoc6_adc.c b/ports/psoc6/drivers/machine/psoc6_adc.c deleted file mode 100644 index 8c8e6594ba8b..000000000000 --- a/ports/psoc6/drivers/machine/psoc6_adc.c +++ /dev/null @@ -1,47 +0,0 @@ -/* CYHAL ADC functions */ - -// std includes -#include -#include - -// port-specific includes -#include "psoc6_adc.h" - -#define VPLUS_CHANNEL_0 (P10_0) -#define MICRO_TO_MILLI_CONV_RATIO 1000u - -cy_rslt_t adc_init(cyhal_adc_t *adc_obj, cyhal_gpio_t pin, const cyhal_clock_t *clk) { - return cyhal_adc_init(adc_obj, pin, NULL); -} - -cy_rslt_t adc_ch_init(cyhal_adc_channel_t *adc_ch_obj, cyhal_adc_t *adc_obj, cyhal_gpio_t vplus, cyhal_gpio_t vminus, const cyhal_adc_channel_config_t *cfg) { - /* ADC channel configuration */ - cy_rslt_t rslt; - rslt = cyhal_adc_channel_init_diff(adc_ch_obj, adc_obj, VPLUS_CHANNEL_0, - CYHAL_ADC_VNEG, cfg); - /* Initialize a channel 0 and configure it to scan the channel 0 input pin in single ended mode. */ - return rslt; - -} - -cy_rslt_t adc_configure(cyhal_adc_t *adc_obj, const cyhal_adc_config_t *adc_config) { - return cyhal_adc_configure(adc_obj, adc_config); -} - -uint16_t adc_read_u16(const cyhal_adc_channel_t *obj) { - return cyhal_adc_read_u16(obj); -} - -int32_t adc_read(const cyhal_adc_channel_t *obj) { - return cyhal_adc_read(obj); - -} - -int32_t adc_read_uv(const cyhal_adc_channel_t *adc_ch_obj) { - return cyhal_adc_read_uv(adc_ch_obj) / MICRO_TO_MILLI_CONV_RATIO; -} - - -cy_rslt_t adc_set_sample_rate(cyhal_adc_t *obj, uint32_t desired_sample_rate_hz, uint32_t *achieved_sample_rate_hz) { - return cyhal_adc_set_sample_rate(obj, desired_sample_rate_hz, achieved_sample_rate_hz); -} diff --git a/ports/psoc6/drivers/machine/psoc6_adc.h b/ports/psoc6/drivers/machine/psoc6_adc.h deleted file mode 100644 index a217ded1fef4..000000000000 --- a/ports/psoc6/drivers/machine/psoc6_adc.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef MICROPY_INCLUDED_PSOC6_ADC_H -#define MICROPY_INCLUDED_PSOC6_ADC_H - -// cy includes -#include "cybsp.h" -#include "cyhal.h" -#include "cy_pdl.h" - -// std includes -#include - -cy_rslt_t adc_init(cyhal_adc_t *obj, cyhal_gpio_t pin, const cyhal_clock_t *clk); -cy_rslt_t adc_ch_init(cyhal_adc_channel_t *adc_ch_obj, cyhal_adc_t *adc_obj, cyhal_gpio_t vplus, cyhal_gpio_t vminus, const cyhal_adc_channel_config_t *cfg); - -uint16_t adc_read_u16(const cyhal_adc_channel_t *obj); - -int32_t adc_read(const cyhal_adc_channel_t *obj); - -int32_t adc_read_uv(const cyhal_adc_channel_t *obj); - -#endif // MICROPY_INCLUDED_PSOC6_ADC_H diff --git a/ports/psoc6/modules/machine/machine_adc.c b/ports/psoc6/modules/machine/machine_adc.c index ccc93f25d6d4..adcdc6d1bea3 100644 --- a/ports/psoc6/modules/machine/machine_adc.c +++ b/ports/psoc6/modules/machine/machine_adc.c @@ -5,10 +5,13 @@ // port-specific includes #include "modmachine.h" -#include "drivers/machine/psoc6_adc.h" #include "pins.h" #include "machine_adc.h" +#include "cybsp.h" +#include "cyhal.h" +#include "cy_pdl.h" + #define DEFAULT_ADC_ACQ_NS 1000 #define IS_GPIO_VALID_ADC_PIN(gpio) ((gpio == CYHAL_NC_PIN_VALUE) || ((gpio >= 80) && (gpio <= 87))) @@ -38,7 +41,7 @@ machine_adc_obj_t *adc_init_helper(uint32_t sampling_time, uint32_t pin, uint8_t } // Initialize the ADC block (required only once per execution) if (!adc_init_flag) { - adc_init(&adc_obj, pin, NULL); + cyhal_adc_init(&adc_obj, pin, NULL); adc_init_flag = true; } @@ -51,7 +54,7 @@ machine_adc_obj_t *adc_init_helper(uint32_t sampling_time, uint32_t pin, uint8_t }; // Initialize channel - adc_ch_init(&adc_channel_obj, &adc_obj, pin, CYHAL_NC_PIN_VALUE, &channel_config); + cyhal_adc_channel_init_diff(&adc_channel_obj, &adc_obj, pin, CYHAL_ADC_VNEG, &channel_config); // Create ADC Object machine_adc_obj_t *o = mp_obj_malloc(machine_adc_obj_t, &machine_adc_type); @@ -106,14 +109,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_adc_block_obj, machine_adc_block); // read_u16() STATIC mp_obj_t machine_adc_read_u16(mp_obj_t self_in) { machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in); - return MP_OBJ_NEW_SMALL_INT(adc_read_u16(&self->block->adc_chan_obj)); + return MP_OBJ_NEW_SMALL_INT(cyhal_adc_read_u16(&self->block->adc_chan_obj)); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_adc_read_u16_obj, machine_adc_read_u16); // read_uv STATIC mp_obj_t machine_adc_read_uv(mp_obj_t self_in) { machine_adc_obj_t *self = MP_OBJ_TO_PTR(self_in); - return MP_OBJ_NEW_SMALL_INT(adc_read_uv(&self->block->adc_chan_obj)); + return MP_OBJ_NEW_SMALL_INT(cyhal_adc_read_uv(&self->block->adc_chan_obj)); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_adc_read_uv_obj, machine_adc_read_uv); diff --git a/ports/psoc6/modules/machine/machine_adcblock.c b/ports/psoc6/modules/machine/machine_adcblock.c index a8ba52f0e7a6..2390cc3ab079 100644 --- a/ports/psoc6/modules/machine/machine_adcblock.c +++ b/ports/psoc6/modules/machine/machine_adcblock.c @@ -63,8 +63,6 @@ STATIC mp_obj_t machine_adcblock_connect(size_t n_pos_args, const mp_obj_t *pos_ if (mp_obj_is_int(pos_args[1])) { channel = mp_obj_get_int(pos_args[1]); if (channel <= 7) { - // adc_pin - // self->ch = mp_obj_get_int(pos_args[1]); self->adc_pin = ch_pin_obj[channel].pin; } } @@ -75,7 +73,6 @@ STATIC mp_obj_t machine_adcblock_connect(size_t n_pos_args, const mp_obj_t *pos_ for (int i = 0; i < MP_ARRAY_SIZE(ch_pin_obj); i++) { if (ch_pin_obj[i].pin == adc_pin_obj->pin_addr) { - // self->ch = ch_pin_obj[i].ch; self->adc_pin = adc_pin_obj->pin_addr; } } diff --git a/ports/psoc6/modules/machine/machine_adcblock.h b/ports/psoc6/modules/machine/machine_adcblock.h index bea8c83b9a12..761c904c5a6b 100644 --- a/ports/psoc6/modules/machine/machine_adcblock.h +++ b/ports/psoc6/modules/machine/machine_adcblock.h @@ -1,7 +1,7 @@ #ifndef MICROPY_INCLUDED_MACHINE_ADCBLOCK_H #define MICROPY_INCLUDED_MACHINE_ADCBLOCK_H -#include "drivers/machine/psoc6_adc.h" +// #include "drivers/machine/psoc6_adc.h" #define DEFAULT_ADC_BITS 12 typedef struct _machine_adcblock_obj_t {