8000 ports/esp32: Use capability defines to configure features. · micropython/micropython@980cc14 · GitHub
[go: up one dir, main page]

Skip to content

Commit 980cc14

Browse files
committed
ports/esp32: Use capability defines to configure features.
Signed-off-by: Andrew Leech <andrew@alelec.net>
1 parent 406bccc commit 980cc14

File tree

7 files changed

+48
-42
lines changed

7 files changed

+48
-42
lines changed

ports/esp32/adc.c

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,27 @@
3333
#define DEFAULT_VREF 1100
3434

3535
void madcblock_bits_helper(machine_adc_block_obj_t *self, mp_int_t bits) {
36-
switch (bits) {
37-
#if CONFIG_IDF_TARGET_ESP32
38-
case 9:
39-
self->width = ADC_WIDTH_BIT_9;
40-
break;
41-
case 10:
42-
self->width = ADC_WIDTH_BIT_10;
43-
break;
44-
case 11:
45-
self->width = ADC_WIDTH_BIT_11;
46-
break;
47-
#endif
48-
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3
49-
case 12:
50-
self->width = ADC_WIDTH_BIT_12;
51-
break;
52-
#endif
53-
#if CONFIG_IDF_TARGET_ESP32S2
54-
case 13:
55-
self->width = ADC_WIDTH_BIT_13;
56-
break;
57-
#endif
58-
default:
59-
mp_raise_ValueError(MP_ERROR_TEXT("invalid bits"));
36+
if (bits >= SOC_ADC_RTC_MIN_BITWIDTH && bits <= SOC_ADC_RTC_MAX_BITWIDTH) {
37+
switch (bits) {
38+
case 9:
39+
self->width = ADC_BITWIDTH_9;
40+
break;
41+
case 10:
42+
self->width = ADC_BITWIDTH_10;
43+
break;
44+
case 11:
45+
self->width = ADC_BITWIDTH_11;
46+
break;
47+
case 12:
48+
self->width = ADC_BITWIDTH_12;
49+
break;
50+
case 13:
51+
self->width = ADC_BITWIDTH_13;
52+
break;
53+
default:
54+
}
55+
} else {
56+
mp_raise_ValueError(MP_ERROR_TEXT("invalid bits"));
6057
}
6158
self->bits = bits;
6259

ports/esp32/machine_adc.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#define ADCBLOCK1 (&madcblock_obj[0])
3636
#define ADCBLOCK2 (&madcblock_obj[1])
3737

38-
#if CONFIG_IDF_TARGET_ESP32
38+
#if SOC_ADC_RTC_MIN_BITWIDTH <= 9 && SOC_ADC_RTC_MAX_BITWIDTH >= 11
3939
#define MICROPY_PY_MACHINE_ADC_CLASS_CONSTANTS_WIDTH_9_10_11 \
4040
{ MP_ROM_QSTR(MP_QSTR_WIDTH_9BIT), MP_ROM_INT(9) }, \
4141
{ MP_ROM_QSTR(MP_QSTR_WIDTH_10BIT), MP_ROM_INT(10) }, \
@@ -44,14 +44,14 @@
4444
#define MICROPY_PY_MACHINE_ADC_CLASS_CONSTANTS_WIDTH_9_10_11
4545
#endif
4646

47-
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3
47+
#if SOC_ADC_RTC_MIN_BITWIDTH <= 12 && SOC_ADC_RTC_MAX_BITWIDTH >= 12
4848
#define MICROPY_PY_MACHINE_ADC_CLASS_CONSTANTS_WIDTH_12 \
4949
{ MP_ROM_QSTR(MP_QSTR_WIDTH_12BIT), MP_ROM_INT(12) },
5050
#else
5151
#define MICROPY_PY_MACHINE_ADC_CLASS_CONSTANTS_WIDTH_12
5252
#endif
5353

54-
#if CONFIG_IDF_TARGET_ESP32S2
54+
#if SOC_ADC_RTC_MIN_BITWIDTH <= 13 && SOC_ADC_RTC_MAX_BITWIDTH >= 13
5555
#define MICROPY_PY_MACHINE_ADC_CLASS_CONSTANTS_WIDTH_13 \
5656
{ MP_ROM_QSTR(MP_QSTR_WIDTH_13BIT), MP_ROM_INT(13) },
5757
#else
@@ -87,13 +87,21 @@ static const machine_adc_obj_t madc_obj[] = {
8787
{{&machine_adc_type}, ADCBLOCK2, ADC_CHANNEL_7, GPIO_NUM_27},
8888
{{&machine_adc_type}, ADCBLOCK2, ADC_CHANNEL_8, GPIO_NUM_25},
8989
{{&machine_adc_type}, ADCBLOCK2, ADC_CHANNEL_9, GPIO_NUM_26},
90-
#elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
90+
#elif CONFIG_IDF_TARGET_ESP32C3
9191
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_0, GPIO_NUM_0},
9292
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_1, GPIO_NUM_1},
9393
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_2, GPIO_NUM_2},
9494
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_3, GPIO_NUM_3},
9595
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_4, GPIO_NUM_4},
9696
{{&machine_adc_type}, ADCBLOCK2, ADC_CHANNEL_0, GPIO_NUM_5},
97+
#elif CONFIG_IDF_TARGET_ESP32C6
98+
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_0, GPIO_NUM_0},
99+
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_1, GPIO_NUM_1},
100+
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_2, GPIO_NUM_2},
101+
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_3, GPIO_NUM_3},
102+
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_4, GPIO_NUM_4},
103+
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_5, GPIO_NUM_5},
104+
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_6, GPIO_NUM_6},
97105
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
98106
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_0, GPIO_NUM_1},
99107
{{&machine_adc_type}, ADCBLOCK1, ADC_CHANNEL_1, GPIO_NUM_2},

ports/esp32/machine_adc_block.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@
3232
#include "driver/adc.h"
3333

3434
machine_adc_block_obj_t madcblock_obj[] = {
35-
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3
36-
{{&machine_adc_block_type}, ADC_UNIT_1, 12, -1, {0}},
37-
{{&machine_adc_block_type}, ADC_UNIT_2, 12, -1, {0}},
38-
#elif CONFIG_IDF_TARGET_ESP32S2
39-
{{&machine_adc_block_type}, ADC_UNIT_1, 13, -1, {0}},
40-
{{&machine_adc_block_type}, ADC_UNIT_2, 13, -1, {0}},
35+
{{&machine_adc_block_type}, ADC_UNIT_1, SOC_ADC_RTC_MAX_BITWIDTH, -1, {0}},
36+
#if SOC_ADC_PERIPH_NUM > 1
37+
{{&machine_adc_block_type}, ADC_UNIT_2, SOC_ADC_RTC_MAX_BITWIDTH, -1, {0}},
4138
#endif
4239
};
4340

ports/esp32/machine_bitstream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
// This is a translation of the cycle counter implementation in ports/stm32/machine_bitstream.c.
4343
static void IRAM_ATTR machine_bitstream_high_low_bitbang(mp_hal_pin_obj_t pin, uint32_t *timing_ns, const uint8_t *buf, size_t len) {
4444
uint32_t pin_mask, gpio_reg_set, gpio_reg_clear;
45-
#if !CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
45+
#if SOC_GPIO_PIN_COUNT > 32
4646
if (pin >= 32) {
4747
pin_mask = 1 << (pin - 32);
4848
gpio_reg_set = GPIO_OUT1_W1TS_REG;

ports/esp32/machine_i2c.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
#endif
5050
#endif
5151

52-
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32S3
52+
#if SOC_I2C_SUPPORT_XTAL
5353
#define I2C_SCLK_FREQ XTAL_CLK_FREQ
54-
#elif CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
54+
#elif SOC_I2C_SUPPORT_APB
5555
#define I2C_SCLK_FREQ APB_CLK_FREQ
5656
#else
5757
#error "unsupported I2C for ESP32 SoC variant"

ports/esp32/machine_pin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#include "modesp32.h"
4444
#include "genhdr/pins.h"
4545

46-
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
46+
#if SOC_USB_SERIAL_JTAG_SUPPORTED
4747
#include "soc/usb_serial_jtag_reg.h"
4848
#endif
4949

ports/esp32/modmachine.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#define MICROPY_PY_MACHINE_SDCARD_ENTRY
4646
#endif
4747

48-
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
48+
#if SOC_TOUCH_SENSOR_SUPPORTED
4949
#define MICROPY_PY_MACHINE_TOUCH_PAD_ENTRY { MP_ROM_QSTR(MP_QSTR_TouchPad), MP_ROM_PTR(&machine_touchpad_type) },
5050
#else
5151
#define MICROPY_PY_MACHINE_TOUCH_PAD_ENTRY
@@ -147,30 +147,34 @@ static void machine_sleep_helper(wake_type_t wake_type, size_t n_args, const mp_
147147
esp_sleep_enable_timer_wakeup(((uint64_t)expiry) * 1000);
148148
}
149149

150-
#if !(CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6)
151-
150+
#if SOC_PM_SUPPORT_EXT0_WAKEUP
152151
if (machine_rtc_config.ext0_pin != -1 && (machine_rtc_config.ext0_wake_types & wake_type)) {
153152
esp_sleep_enable_ext0_wakeup(machine_rtc_config.ext0_pin, machine_rtc_config.ext0_level ? 1 : 0);
154153
}
154+
#endif
155155

156+
#if SOC_PM_SUPPORT_EXT1_WAKEUP
156157
if (machine_rtc_config.ext1_pins != 0) {
157158
esp_sleep_enable_ext1_wakeup(
158159
machine_rtc_config.ext1_pins,
159160
machine_rtc_config.ext1_level ? ESP_EXT1_WAKEUP_ANY_HIGH : ESP_EXT1_WAKEUP_ALL_LOW);
160161
}
162+
#endif
161163

164+
#if SOC_TOUCH_SENSOR_SUPPORTED
162165
if (machine_rtc_config.wake_on_touch) {
163166
if (esp_sleep_enable_touchpad_wakeup() != ESP_OK) {
164167
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("esp_sleep_enable_touchpad_wakeup() failed"));
165168
}
166169
}
170+
#endif
167171

172+
#if SOC_ULP_SUPPORTED
168173
if (machine_rtc_config.wake_on_ulp) {
169174
if (esp_sleep_enable_ulp_wakeup() != ESP_OK) {
170175
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("esp_sleep_enable_ulp_wakeup() failed"));
171176
}
172177
}
173-
174178
#endif
175179

176180
switch (wake_type) {

0 commit comments

Comments
 (0)
0