Skip to content

Commit 8fa6fb0

Browse files
committed
Updating to IDF 5.4.
1 parent 9507787 commit 8fa6fb0

18 files changed

+4600
-157
lines changed

builder/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
_windows_env = None
1212

13-
13+
MICROPY_LVGL_VER = "1.0.0"
1414
DO_NOT_SCRUB_BUILD_FOLDER = False
1515

1616

@@ -34,7 +34,7 @@ def revert_files(port):
3434
if port in ('raspberry_pi', 'macOS'):
3535
port = 'unix'
3636

37-
dst_path = f'lib/micropython/ports/{port}'
37+
dst_path = f'lib/micropython'
3838

3939
if not os.path.exists(src_path) or not os.listdir(src_path):
4040
return
@@ -63,7 +63,7 @@ def copy_micropy_updates(port):
6363
port = 'unix'
6464
src_path = f'micropy_updates/{port}'
6565

66-
dst_path = f'lib/micropython/ports/{port}'
66+
dst_path = f'lib/micropython'
6767

6868
def iter_files(s_path, d_path, o_path):
6969
for file in os.listdir(s_path):
@@ -99,7 +99,7 @@ def read_file(port, file):
9999

100100
head, tail = os.path.split(filepath)
101101
save_path = []
102-
while tail != port:
102+
while tail != 'micropython':
103103
save_path.insert(0, tail)
104104
head, tail = os.path.split(head)
105105

builder/esp32.py

Lines changed: 21 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
write_file,
1414
copy_micropy_updates,
1515
revert_files,
16-
scrub_build_folder
16+
scrub_build_folder,
17+
MICROPY_LVGL_VER
1718
)
1819

19-
IDF_VER = '5.2.0'
20+
IDF_VER = '5.4.0'
2021

2122

2223
def get_partition_file_name(otp):
@@ -477,7 +478,6 @@ def esp32_s3_args(extra_args):
477478
dest='oct_flash',
478479
action='store_true'
479480
)
480-
481481
esp_argParser.add_argument(
482482
'--enable_fb_test',
483483
dest='optimum_fb_size',
@@ -997,50 +997,13 @@ def find_esp32_ports(chip):
997997

998998
SDKCONFIG_PATH = f'build/sdkconfig.board'
999999

1000-
MPTHREADPORT_PATH = 'lib/micropython/ports/esp32/mpthreadport.c'
10011000
MPCONFIGPORT_PATH = 'lib/micropython/ports/esp32/mpconfigport.h'
1002-
PANICHANDLER_PATH = 'lib/micropython/ports/esp32/panichandler.c'
10031001
MPHALPORT_PATH = 'lib/micropython/ports/esp32/mphalport.c'
1004-
MAIN_PATH = 'lib/micropython/ports/esp32/main.c'
1005-
10061002

10071003
if not os.path.exists('micropy_updates/originals/esp32'):
10081004
os.makedirs('micropy_updates/originals/esp32')
10091005

10101006

1011-
def update_mpthreadport():
1012-
data = read_file('esp32', MPTHREADPORT_PATH)
1013-
1014-
if '_CORE_ID' not in data:
1015-
data = data.replace('MP_TASK_COREID', '_CORE_ID')
1016-
1017-
new_data = [
1018-
'#if MICROPY_PY_THREAD',
1019-
'',
1020-
'#if (MP_USE_DUAL_CORE && !CONFIG_FREERTOS_UNICORE)',
1021-
' #define _CORE_ID tskNO_AFFINITY',
1022-
'#else',
1023-
' #define _CORE_ID MP_TASK_COREID',
1024-
'#endif',
1025-
''
1026-
]
1027-
1028-
data = data.replace('#if MICROPY_PY_THREAD', '\n'.join(new_data), 1)
1029-
1030-
write_file(MPTHREADPORT_PATH, data)
1031-
1032-
1033-
def update_panic_handler():
1034-
data = read_file('esp32', PANICHANDLER_PATH)
1035-
1036-
if '"MPY version : "' in data:
1037-
beg, end = data.split('"MPY version : "', 1)
1038-
end = end.split('"\\r\\n"', 1)[1]
1039-
data = f'{beg}"LVGL MicroPython \\r\\n"{end}'
1040-
1041-
write_file(PANICHANDLER_PATH, data)
1042-
1043-
10441007
def update_mpconfigboard():
10451008
if custom_board_path is not None:
10461009
return
@@ -1068,10 +1031,6 @@ def update_mpconfigport():
10681031

10691032
if custom_board_path is None:
10701033
repl_data = [
1071-
'#ifndef USB_SERIAL_JTAG_PACKET_SZ_BYTES',
1072-
'#define USB_SERIAL_JTAG_PACKET_SZ_BYTES (64)',
1073-
'#endif',
1074-
'',
10751034
'#ifdef MICROPY_HW_UART_REPL_BAUD',
10761035
'#undef MICROPY_HW_UART_REPL_BAUD',
10771036
'#endif',
@@ -1114,127 +1073,40 @@ def update_mpconfigport():
11141073
1
11151074
)
11161075

1117-
pattern = (
1118-
'#if !(CONFIG_IDF_TARGET_ESP32 && CONFIG_SPIRAM && '
1119-
'CONFIG_SPIRAM_CACHE_WORKAROUND)\n'
1120-
'#define MICROPY_WRAP_MP_BINARY_OP(f) IRAM_ATTR f\n'
1121-
'#endif'
1076+
data = data.replace(
1077+
f'#define MP_USE_DUAL_CORE (1)',
1078+
f'#define MP_USE_DUAL_CORE ({int(dual_core_threads)})'
11221079
)
11231080

1124-
if pattern in data:
1125-
pattern = (
1126-
'#if !(CONFIG_IDF_TARGET_ESP32 && CONFIG_SPIRAM '
1127-
'&& CONFIG_SPIRAM_CACHE_WORKAROUND)\n'
1128-
)
1129-
data = data.replace(
1130-
'#define MICROPY_WRAP_MP_SCHED_EXCEPTION(f) IRAM_ATTR f\n',
1131-
''
1132-
)
1133-
data = data.replace(
1134-
'#define MICROPY_WRAP_MP_SCHED_KEYBOARD_INTERRUPT(f) '
1135-
'IRAM_ATTR f\n',
1136-
''
1137-
)
1138-
data = data.replace(
1139-
pattern,
1140-
pattern + '#define MICROPY_WRAP_MP_SCHED_EXCEPTION(f) IRAM_ATTR f\n'
1141-
)
1081+
data = data.replace(
1082+
f'#define MP_USE_DUAL_CORE (0)',
1083+
f'#define MP_USE_DUAL_CORE ({int(dual_core_threads)})'
1084+
)
11421085

1143-
data = data.replace(
1144-
pattern,
1145-
pattern + '#define MICROPY_WRAP_MP_SCHED_KEYBOARD_INTERRUPT(f) '
1146-
'IRAM_ATTR f\n'
1147-
)
1086+
data = data.replace(
1087+
'#define MICROPY_PY_THREAD_GIL (1)',
1088+
f'#define MICROPY_PY_THREAD_GIL ({int(not dual_core_threads)})'
1089+
)
11481090

1149-
has_dual_core = 'MP_USE_DUAL_CORE' in data
1091+
data = data.replace(
1092+
'#define MICROPY_PY_THREAD_GIL (0)',
1093+
f'#define MICROPY_PY_THREAD_GIL ({int(not dual_core_threads)})'
1094+
)
11501095

1151-
data = data.split('\n')
1096+
data = data.splitlines(keepends=False)
11521097

11531098
for i, line in enumerate(data):
1154-
if has_dual_core and line.startswith('#define MP_USE_DUAL_CORE'):
1155-
data[i] = (
1156-
'#define MP_USE_DUAL_CORE '
1157-
f'({int(dual_core_threads)})'
1158-
)
1159-
continue
1160-
1161-
if line.startswith('#define MICROPY_PY_THREAD_GIL'):
1162-
data[i] = (
1163-
f'#define MICROPY_PY_THREAD_GIL '
1164-
f'({int(not dual_core_threads)})'
1165-
)
1166-
if not has_dual_core:
1167-
data[i] += (
1168-
'\n#define MP_USE_DUAL_CORE '
1169-
f'({int(dual_core_threads)})'
1170-
)
1171-
continue
1172-
11731099
if line.startswith('#define MICROPY_TASK_STACK_SIZE'):
11741100
data[i] = (
11751101
f'#define MICROPY_TASK_STACK_SIZE ({task_stack_size})'
11761102
)
1177-
continue
1103+
break
11781104

11791105
data = '\n'.join(data)
11801106

11811107
write_file(MPCONFIGPORT_PATH, data)
11821108

11831109

1184-
def update_main():
1185-
data = read_file('esp32', MAIN_PATH)
1186-
1187-
rep_data = [
1188-
'#if SOC_LCD_I80_SUPPORTED',
1189-
'#include "../../../../ext_mod/lcd_bus/esp32_include/i80_bus.h"',
1190-
'#endif',
1191-
'',
1192-
'#if SOC_LCD_RGB_SUPPORTED',
1193-
'#include "../../../../ext_mod/lcd_bus/esp32_include/rgb_bus.h"',
1194-
'#endif',
1195-
'',
1196-
'#include "../../../../ext_mod/lcd_bus/esp32_include/spi_bus.h"',
1197-
'#include "../../../../ext_mod/lcd_bus/esp32_include/i2c_bus.h"',
1198-
'#include "../../../../ext_mod/spi3wire/include/spi3wire.h"',
1199-
'#include "../../../../micropy_updates/common/mp_spi_common.h"',
1200-
'',
1201-
'#if MICROPY_BLUETOOTH_NIMBLE'
1202-
]
1203-
1204-
data = data.replace(
1205-
'#if MICROPY_BLUETOOTH_NIMBLE',
1206-
'\n'.join(rep_data),
1207-
1
1208-
)
1209-
1210-
rep_data = [
1211-
'soft_reset_exit:',
1212-
' ',
1213-
'#if SOC_LCD_I80_SUPPORTED',
1214-
' mp_lcd_i80_bus_deinit_all();',
1215-
'#endif',
1216-
' ',
1217-
'#if SOC_LCD_RGB_SUPPORTED',
1218-
' mp_lcd_rgb_bus_deinit_all();',
1219-
'#endif',
1220-
' ',
1221-
' mp_lcd_spi_bus_deinit_all();',
1222-
' ',
1223-
' mp_lcd_i2c_bus_deinit_all();',
1224-
' ',
1225-
' mp_spi3wire_deinit_all();',
1226-
' ',
1227-
' mp_machine_hw_spi_bus_deinit_all();'
1228-
]
1229-
1230-
data = data.replace(
1231-
'soft_reset_exit:',
1232-
'\n'.join(rep_data)
1233-
)
1234-
1235-
write_file(MAIN_PATH, data)
1236-
1237-
12381110
def build_sdkconfig(*args):
12391111
if custom_board_path is not None:
12401112
return
@@ -1367,14 +1239,10 @@ def compile(*args): # NOQA
13671239
partition = Partition(p_size)
13681240
partition.save()
13691241

1370-
update_main()
1371-
update_mpthreadport()
1372-
update_panic_handler()
1242+
copy_micropy_updates('esp32')
13731243
update_mpconfigboard()
13741244
update_mpconfigport()
13751245

1376-
copy_micropy_updates('esp32')
1377-
13781246
try:
13791247
cmd_ = compile_cmd[:]
13801248
cmd_.extend(list(args))
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2017 Nick Moore
7+
* Copyright (c) 2021 Jonathan Hogg
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#include "py/mphal.h"
29+
#include "adc.h"
30+
#include "esp_adc/adc_oneshot.h"
31+
#include "esp_adc/adc_cali_scheme.h"
32+
33+
static esp_err_t ensure_adc_calibration(machine_adc_block_obj_t *self, adc_atten_t atten);
34+
35+
esp_err_t apply_self_adc_channel_atten(const machine_adc_obj_t *self, uint8_t atten) {
36+
adc_oneshot_chan_cfg_t config = {
37+
.atten = atten,
38+
.bitwidth = self->block->bitwidth,
39+
};
40+
esp_err_t ret = adc_oneshot_config_channel(self->block->handle, self->channel_id, &config);
41+
return ret;
42+
}
43+
44+
mp_int_t madcblock_read_helper(machine_adc_block_obj_t *self, adc_channel_t channel_id) {
45+
int reading = 0;
46+
adc_oneshot_read(self->handle, channel_id, &reading);
47+
return reading;
48+
}
49+
50+
/*
51+
During testing, it turned out that the function `adc_cali_raw_to_voltage` does not account for the lower resolution,
52+
instead it expects the full resolution value as an argument, hence the scaling applied here
53+
*/
54+
mp_int_t madcblock_read_uv_helper(machine_adc_block_obj_t *self, adc_channel_t channel_id, adc_atten_t atten) {
55+
int raw = madcblock_read_helper(self, channel_id);
56+
int uv = 0;
57+
58+
check_esp_err(ensure_adc_calibration(self, atten));
59+
check_esp_err(adc_cali_raw_to_voltage(self->calib[atten], (raw << (ADC_WIDTH_MAX - self->bitwidth)), &uv));
60+
return (mp_int_t)uv * 1000;
61+
}
62+
63+
static esp_err_t ensure_adc_calibration(machine_adc_block_obj_t *self, adc_atten_t atten) {
64+
if (self->calib[atten] != NULL) {
65+
return ESP_OK;
66+
}
67+
68+
esp_err_t ret = ESP_OK;
69+
70+
#if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED
71+
adc_cali_curve_fitting_config_t cali_config = {
72+
.unit_id = self->unit_id,
73+
.atten = atten,
74+
.bitwidth = self->bitwidth,
75+
};
76+
ret = adc_cali_create_scheme_curve_fitting(&cali_config, &self->calib[atten]);
77+
#else
78+
adc_cali_line_fitting_config_t cali_config = {
79+
.unit_id = self->unit_id,
80+
.atten = atten,
81+
.bitwidth = self->bitwidth,
82+
};
83+
ret = adc_cali_create_scheme_line_fitting(&cali_config, &self->calib[atten]);
84+
#endif
85+
86+
return ret;
87+
}

0 commit comments

Comments
 (0)