Skip to content

Commit

Permalink
ports/psoc6: Fixing connect function, adding deinit and fixed tests.
Browse files Browse the repository at this point in the history
Signed-off-by: NikhitaR-IFX <Nikhita.Rajasekhar@infineon.com>
  • Loading branch information
NikhitaR-IFX committed Jul 31, 2023
1 parent 388a5e3 commit f699b34
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ports/psoc6/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ extern void machine_init(void);
extern void machine_deinit(void);
extern void network_init(void);
extern void network_deinit(void);
extern void adcblock_deinit(void);

void mpy_task(void *arg);

Expand Down Expand Up @@ -170,6 +171,7 @@ void mpy_task(void *arg) {

// Deinitialize modules
machine_deinit();
adcblock_deinit();
#if MICROPY_PY_NETWORK
mod_network_deinit();
network_deinit();
Expand Down
17 changes: 16 additions & 1 deletion ports/psoc6/modules/machine/machine_adcblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ machine_adcblock_obj_t *adc_block_init_helper(uint8_t adc_id, uint8_t bits) {

// No existing adc_block for given id. Create new one.
if (adc_block == NULL) {
printf("\nHERE\n");
adc_block = _create_and_init_new_adc_block(adc_id, bits);
}

Expand Down Expand Up @@ -214,8 +215,14 @@ STATIC mp_obj_t machine_adcblock_connect(size_t n_pos_args, const mp_obj_t *pos_
channel = _get_adc_channel_number_for_pin(pin);
}
} else if (n_pos_args == 3) {
machine_pin_obj_t *adc_pin_obj = MP_OBJ_TO_PTR(pos_args[1]);
channel = mp_obj_get_int(pos_args[1]);
uint32_t exp_pin = _get_adc_pin_number_for_channel(channel);

machine_pin_obj_t *adc_pin_obj = MP_OBJ_TO_PTR(pos_args[2]);
pin = adc_pin_obj->pin_addr;
if (exp_pin != pin) {
mp_raise_TypeError(MP_ERROR_TEXT("Wrong pin specified for the mentioned channel"));
}
} else {
mp_raise_TypeError(MP_ERROR_TEXT("Too many positional args"));
}
Expand All @@ -229,6 +236,14 @@ STATIC mp_obj_t machine_adcblock_connect(size_t n_pos_args, const mp_obj_t *pos_
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_adcblock_connect_obj, 2, machine_adcblock_connect);

void adcblock_deinit(void) {

for (uint8_t i = 0; i < MAX_BLOCKS; i++) {
cyhal_adc_free(&adc_block[i]->adc_block_obj);
adc_block[i] = NULL;
}

}

STATIC const mp_rom_map_elem_t machine_adcblock_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&machine_adcblock_connect_obj) },
Expand Down
1 change: 1 addition & 0 deletions ports/psoc6/modules/machine/machine_adcblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ typedef struct
uint32_t pin;
}adc_block_channel_pin_map_t;

void adcblock_deinit(void);
#endif // MICROPY_INCLUDED_MACHINE_ADCBLOCK_H
8 changes: 3 additions & 5 deletions tests/psoc6/adcblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"""
from machine import Pin, ADCBlock

print("ADCBlock tests")

pin = Pin("P10_0")
pin = Pin("P10_3")

# Negative tests
try:
Expand All @@ -21,11 +19,11 @@
adcBlock = ADCBlock(0)

try:
adcPin = adcBlock.connect(1, pin)
adcPin = adcBlock.connect(0, pin)
except:
print("TypeError: Wrong pin specified for the mentioned channel")


adcPin = adcBlock.connect(0, pin)
adcPin = adcBlock.connect(3, pin)

print(adcPin.read_uv() > 0)

0 comments on commit f699b34

Please sign in to comment.