Skip to content

Commit

Permalink
ports/psoc6/modules/machine/machine_adc: Allocaed channel in ADC block.
Browse files Browse the repository at this point in the history
Signed-off-by: enriquezgarc <enriquezgarcia.external@infineon.com>
  • Loading branch information
jaenrig-ifx authored and NikhitaR-IFX committed Jul 31, 2023
1 parent 9fae006 commit dd2cd4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ports/psoc6/modules/machine/machine_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
extern int16_t get_adc_block_id(uint32_t pin);
extern machine_adc_obj_t *adc_block_get_pin_adc_obj(machine_adcblock_obj_t *adc_block, uint32_t pin);
extern machine_adcblock_obj_t *adc_block_init_helper(uint8_t adc_id, uint8_t bits);
extern machine_adc_obj_t *adc_block_allocate_new_pin(machine_adcblock_obj_t *adc_block, uint32_t pin);

/******************************************************************************/
// MicroPython bindings for machine.ADC
Expand All @@ -28,7 +29,7 @@ const mp_obj_type_t machine_adc_type;

static inline machine_adc_obj_t *adc_init_new(machine_adcblock_obj_t *adc_block, uint32_t pin, uint32_t sampling_time) {

machine_adc_obj_t *o = mp_obj_malloc(machine_adc_obj_t, &machine_adc_type);
machine_adc_obj_t *o = adc_block_allocate_new_pin(adc_block, pin);
const cyhal_adc_channel_config_t channel_config =
{
.enable_averaging = false,
Expand Down
8 changes: 8 additions & 0 deletions ports/psoc6/modules/machine/machine_adcblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "modmachine.h"

#include "machine_adcblock.h"
#include "machine_adc.h"
#include "pins.h"

extern machine_adc_obj_t *adc_init_helper(uint32_t sampling_time, uint32_t pin);
Expand Down Expand Up @@ -108,6 +109,13 @@ machine_adc_obj_t *adc_block_get_channel_obj(machine_adcblock_obj_t *adc_block,
return adc_block->channel[channel];
}

machine_adc_obj_t *adc_block_allocate_new_pin(machine_adcblock_obj_t *adc_block, uint32_t pin) {
int16_t adc_channel_no = get_adc_channel_number(pin);
adc_block->channel[adc_channel_no] = mp_obj_malloc(machine_adc_obj_t, &machine_adc_type);

return adc_block->channel[adc_channel_no];
}

machine_adc_obj_t *adc_block_get_pin_adc_obj(machine_adcblock_obj_t *adc_block, uint32_t pin) {

int16_t adc_channel_no = get_adc_channel_number(pin);
Expand Down

0 comments on commit dd2cd4a

Please sign in to comment.