Skip to content

Commit

Permalink
ports/esp32: Use capability defines to configure features.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Leech <andrew@alelec. net>
  • Loading branch information
pi-anl committed Sep 4, 2024
1 parent 3c95b2e commit a0ae5e2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 35 deletions.
46 changes: 22 additions & 24 deletions ports/esp32/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,29 @@
#define DEFAULT_VREF 1100

void madcblock_bits_helper(machine_adc_block_obj_t *self, mp_int_t bits) {
switch (bits) {
#if CONFIG_IDF_TARGET_ESP32
case 9:
self->width = ADC_WIDTH_BIT_9;
break;
case 10:
self->width = ADC_WIDTH_BIT_10;
break;
case 11:
self->width = ADC_WIDTH_BIT_11;
break;
#endif
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6
case 12:
self->width = ADC_WIDTH_BIT_12;
break;
#endif
#if CONFIG_IDF_TARGET_ESP32S2
case 13:
self->width = ADC_WIDTH_BIT_13;
break;
#endif
default:
mp_raise_ValueError(MP_ERROR_TEXT("invalid bits"));
if (bits >= SOC_ADC_RTC_MIN_BITWIDTH && bits <= SOC_ADC_RTC_MIN_BITWIDTH) {
switch (bits) {
case 9:
self->width = ADC_BITWIDTH_9;
break;
case 10:
self->width = ADC_BITWIDTH_10;
break;
case 11:
self->width = ADC_BITWIDTH_11;
break;
case 12:
self->width = ADC_BITWIDTH_12;
break;
case 13:
self->width = ADC_BITWIDTH_13;
break;
default:
}
} else {
mp_raise_ValueError(MP_ERROR_TEXT("invalid bits"));
}

self->bits = bits;

if (self->unit_id == ADC_UNIT_1) {
Expand Down
6 changes: 3 additions & 3 deletions ports/esp32/machine_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define ADCBLOCK1 (&madcblock_obj[0])
#define ADCBLOCK2 (&madcblock_obj[1])

#if CONFIG_IDF_TARGET_ESP32
#if SOC_ADC_RTC_MIN_BITWIDTH <= 9 && SOC_ADC_RTC_MIN_BITWIDTH >= 11
#define MICROPY_PY_MACHINE_ADC_CLASS_CONSTANTS_WIDTH_9_10_11 \
{ MP_ROM_QSTR(MP_QSTR_WIDTH_9BIT), MP_ROM_INT(9) }, \
{ MP_ROM_QSTR(MP_QSTR_WIDTH_10BIT), MP_ROM_INT(10) }, \
Expand All @@ -44,14 +44,14 @@
#define MICROPY_PY_MACHINE_ADC_CLASS_CONSTANTS_WIDTH_9_10_11
#endif

#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3
#if SOC_ADC_RTC_MIN_BITWIDTH <= 12 && SOC_ADC_RTC_MIN_BITWIDTH >= 12
#define MICROPY_PY_MACHINE_ADC_CLASS_CONSTANTS_WIDTH_12 \
{ MP_ROM_QSTR(MP_QSTR_WIDTH_12BIT), MP_ROM_INT(12) },
#else
#define MICROPY_PY_MACHINE_ADC_CLASS_CONSTANTS_WIDTH_12
#endif

#if CONFIG_IDF_TARGET_ESP32S2
#if SOC_ADC_RTC_MIN_BITWIDTH <= 13 && SOC_ADC_RTC_MIN_BITWIDTH >= 13
#define MICROPY_PY_MACHINE_ADC_CLASS_CONSTANTS_WIDTH_13 \
{ MP_ROM_QSTR(MP_QSTR_WIDTH_13BIT), MP_ROM_INT(13) },
#else
Expand Down
9 changes: 2 additions & 7 deletions ports/esp32/machine_adc_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,8 @@
#include "driver/adc.h"

machine_adc_block_obj_t madcblock_obj[] = {
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C6
{{&machine_adc_block_type}, ADC_UNIT_1, 12, -1, {0}},
{{&machine_adc_block_type}, ADC_UNIT_2, 12, -1, {0}},
#elif CONFIG_IDF_TARGET_ESP32S2
{{&machine_adc_block_type}, ADC_UNIT_1, 13, -1, {0}},
{{&machine_adc_block_type}, ADC_UNIT_2, 13, -1, {0}},
#endif
{{&machine_adc_block_type}, ADC_UNIT_1, SOC_ADC_RTC_MAX_BITWIDTH, -1, {0}},
{{&machine_adc_block_type}, ADC_UNIT_2, SOC_ADC_RTC_MAX_BITWIDTH, -1, {0}},
};

static void mp_machine_adc_block_print(const mp_print_t *print, machine_adc_block_obj_t *self) {
Expand Down
2 changes: 1 addition & 1 deletion ports/esp32/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#define MICROPY_PY_MACHINE_SDCARD_ENTRY
#endif

#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
#if SOC_TOUCH_SENSOR_SUPPORTED
#define MICROPY_PY_MACHINE_TOUCH_PAD_ENTRY { MP_ROM_QSTR(MP_QSTR_TouchPad), MP_ROM_PTR(&machine_touchpad_type) },
#else
#define MICROPY_PY_MACHINE_TOUCH_PAD_ENTRY
Expand Down

0 comments on commit a0ae5e2

Please sign in to comment.