-
Notifications
You must be signed in to change notification settings - Fork 221
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
Maybe I was doing something wrong, or my board is not working correctly, but the ADC seems to be inverted: if I input GND then it reads 4095, if I input 3.3v then it reads 0.
esp32/machine_adc.c
Outdated
mp_arg_check_num(n_args, n_kw, 1, 1, true); | ||
gpio_num_t pin_id = machine_pin_get_id(args[0]); | ||
const madc_obj_t *self = NULL; | ||
for (int i=0; i<MP_ARRAY_SIZE(madc_obj); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note coding style: spaces around binary operators (eg i = 0
, i < MP_ARRAY_SIZE
).
esp32/machine_adc.c
Outdated
|
||
STATIC mp_obj_t madc_width(mp_obj_t self_in, mp_obj_t width_in) { | ||
// XXX This should be a classmethod, as there's only one width | ||
// across all ADC channels. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make this a classmethod you can wrap it in MP_DEFINE_CONST_CLASSMETHOD_OBJ; see py/objdict.c dict_fromkeys for how it's done.
esp32/machine_adc.c
Outdated
{ MP_ROM_QSTR(MP_QSTR_WIDTH_9Bit), MP_ROM_INT(ADC_WIDTH_9Bit) }, | ||
{ MP_ROM_QSTR(MP_QSTR_WIDTH_10Bit), MP_ROM_INT(ADC_WIDTH_10Bit) }, | ||
{ MP_ROM_QSTR(MP_QSTR_WIDTH_11Bit), MP_ROM_INT(ADC_WIDTH_11Bit) }, | ||
{ MP_ROM_QSTR(MP_QSTR_WIDTH_12Bit), MP_ROM_INT(ADC_WIDTH_12Bit) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be inclined to make these constants fully upper-case, eg WIDTH_12BIT
.
OK, just pushed fixes for all the above, thanks for the feedback. The ADC readings thing happens if you don't set a bit width on the ADC, it defaults to that weird behaviour because it isn't initialized properly yet (see comments in esp_idf/components/driver/rtc_module.c:adc1_config_width() ) This is sufficiently annoying that I've just added a line to set the width to 12 bits the first time a machine.ADC() is initialized. |
We also lose ugfx.print_funts() which was somehow broken. See micropython#23
This provides support for machine.TouchPad, machine.ADC and machine.DAC classes, like so:
I haven't included IRQ handling for TouchPad or Pin, I'll put that in as a separate PR later.