blob: 392f8c749c24036370ef125c13657cbc0b875ad8 [file] [log] [blame]
Damien Georgebc08c882016-12-06 12:20:10 +11001// Options to control how MicroPython is built for this port,
2// overriding defaults in py/mpconfig.h.
3
Jim Mussared8db517f2019-08-09 18:07:50 +10004// Board-specific definitions
5#include "mpconfigboard.h"
6
Damien Georgebc08c882016-12-06 12:20:10 +11007#include <stdint.h>
8#include <alloca.h>
robertb4062892020-08-22 20:56:26 +02009#include "esp_system.h"
Jim Mussared96008ff2019-09-13 23:04:13 +100010
Damien Georgebc08c882016-12-06 12:20:10 +110011// object representation and NLR handling
12#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_A)
13#define MICROPY_NLR_SETJMP (1)
14
15// memory allocation policies
16#define MICROPY_ALLOC_PATH_MAX (128)
17
18// emitters
19#define MICROPY_PERSISTENT_CODE_LOAD (1)
Damien George917f0272019-09-10 13:47:44 +100020#define MICROPY_EMIT_XTENSAWIN (1)
Damien Georgebc08c882016-12-06 12:20:10 +110021
22// compiler configuration
23#define MICROPY_COMP_MODULE_CONST (1)
24#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (1)
25
26// optimisations
27#define MICROPY_OPT_COMPUTED_GOTO (1)
28#define MICROPY_OPT_MPZ_BITWISE (1)
29
30// Python internal features
31#define MICROPY_READER_VFS (1)
32#define MICROPY_ENABLE_GC (1)
33#define MICROPY_ENABLE_FINALISER (1)
34#define MICROPY_STACK_CHECK (1)
35#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
36#define MICROPY_KBD_EXCEPTION (1)
37#define MICROPY_HELPER_REPL (1)
38#define MICROPY_REPL_EMACS_KEYS (1)
39#define MICROPY_REPL_AUTO_INDENT (1)
40#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
41#define MICROPY_ENABLE_SOURCE_LINE (1)
42#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_NORMAL)
43#define MICROPY_WARNINGS (1)
44#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
Damien Georgebc08c882016-12-06 12:20:10 +110045#define MICROPY_CPYTHON_COMPAT (1)
46#define MICROPY_STREAMS_NON_BLOCK (1)
47#define MICROPY_STREAMS_POSIX_API (1)
48#define MICROPY_MODULE_BUILTIN_INIT (1)
49#define MICROPY_MODULE_WEAK_LINKS (1)
50#define MICROPY_MODULE_FROZEN_STR (0)
51#define MICROPY_MODULE_FROZEN_MPY (1)
52#define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool
53#define MICROPY_CAN_OVERRIDE_BUILTINS (1)
Thorsten von Eicken902da052020-11-11 17:46:18 -080054#define MICROPY_USE_INTERNAL_ERRNO (0) // errno.h from xtensa-esp32-elf/sys-include/sys
Damien Georgebc08c882016-12-06 12:20:10 +110055#define MICROPY_USE_INTERNAL_PRINTF (0) // ESP32 SDK requires its own printf
56#define MICROPY_ENABLE_SCHEDULER (1)
57#define MICROPY_SCHEDULER_DEPTH (8)
58#define MICROPY_VFS (1)
Damien Georgebc08c882016-12-06 12:20:10 +110059
60// control over Python builtins
61#define MICROPY_PY_FUNCTION_ATTRS (1)
Damien George93150a02018-06-08 12:23:08 +100062#define MICROPY_PY_DESCRIPTORS (1)
Andrew Leech97108fc2020-10-21 08:54:46 +110063#define MICROPY_PY_DELATTR_SETATTR (1)
Damien Georgebc08c882016-12-06 12:20:10 +110064#define MICROPY_PY_STR_BYTES_CMP_WARN (1)
65#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
66#define MICROPY_PY_BUILTINS_STR_CENTER (1)
67#define MICROPY_PY_BUILTINS_STR_PARTITION (1)
68#define MICROPY_PY_BUILTINS_STR_SPLITLINES (1)
69#define MICROPY_PY_BUILTINS_BYTEARRAY (1)
70#define MICROPY_PY_BUILTINS_MEMORYVIEW (1)
71#define MICROPY_PY_BUILTINS_SET (1)
72#define MICROPY_PY_BUILTINS_SLICE (1)
73#define MICROPY_PY_BUILTINS_SLICE_ATTRS (1)
Nicko van Someren4c939552019-11-16 17:07:11 -070074#define MICROPY_PY_BUILTINS_SLICE_INDICES (1)
Damien Georgebc08c882016-12-06 12:20:10 +110075#define MICROPY_PY_BUILTINS_FROZENSET (1)
76#define MICROPY_PY_BUILTINS_PROPERTY (1)
77#define MICROPY_PY_BUILTINS_RANGE_ATTRS (1)
Damien George20b4b852018-05-22 14:15:20 +100078#define MICROPY_PY_BUILTINS_ROUND_INT (1)
Damien Georgebc08c882016-12-06 12:20:10 +110079#define MICROPY_PY_ALL_SPECIAL_METHODS (1)
80#define MICROPY_PY_BUILTINS_COMPILE (1)
81#define MICROPY_PY_BUILTINS_ENUMERATE (1)
82#define MICROPY_PY_BUILTINS_EXECFILE (1)
83#define MICROPY_PY_BUILTINS_FILTER (1)
84#define MICROPY_PY_BUILTINS_REVERSED (1)
85#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1)
86#define MICROPY_PY_BUILTINS_INPUT (1)
87#define MICROPY_PY_BUILTINS_MIN_MAX (1)
88#define MICROPY_PY_BUILTINS_POW3 (1)
89#define MICROPY_PY_BUILTINS_HELP (1)
90#define MICROPY_PY_BUILTINS_HELP_TEXT esp32_help_text
91#define MICROPY_PY_BUILTINS_HELP_MODULES (1)
92#define MICROPY_PY___FILE__ (1)
93#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
94#define MICROPY_PY_ARRAY (1)
95#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
96#define MICROPY_PY_ATTRTUPLE (1)
97#define MICROPY_PY_COLLECTIONS (1)
Damien George82828342018-02-21 22:55:13 +110098#define MICROPY_PY_COLLECTIONS_DEQUE (1)
Damien Georgebc08c882016-12-06 12:20:10 +110099#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1)
100#define MICROPY_PY_MATH (1)
101#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (1)
stijnaf5c9982019-07-02 10:28:44 +0200102#define MICROPY_PY_MATH_ISCLOSE (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100103#define MICROPY_PY_CMATH (1)
104#define MICROPY_PY_GC (1)
105#define MICROPY_PY_IO (1)
Damien George565f5902018-06-04 16:04:28 +1000106#define MICROPY_PY_IO_IOBASE (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100107#define MICROPY_PY_IO_FILEIO (1)
108#define MICROPY_PY_IO_BYTESIO (1)
109#define MICROPY_PY_IO_BUFFEREDWRITER (1)
110#define MICROPY_PY_STRUCT (1)
111#define MICROPY_PY_SYS (1)
112#define MICROPY_PY_SYS_MAXSIZE (1)
113#define MICROPY_PY_SYS_MODULES (1)
114#define MICROPY_PY_SYS_EXIT (1)
115#define MICROPY_PY_SYS_STDFILES (1)
116#define MICROPY_PY_SYS_STDIO_BUFFER (1)
117#define MICROPY_PY_UERRNO (1)
118#define MICROPY_PY_USELECT (1)
119#define MICROPY_PY_UTIME_MP_HAL (1)
120#define MICROPY_PY_THREAD (1)
121#define MICROPY_PY_THREAD_GIL (1)
122#define MICROPY_PY_THREAD_GIL_VM_DIVISOR (32)
123
124// extended modules
Damien Georgeda2b5fa2021-02-14 01:36:30 +1100125#ifndef MICROPY_PY_BLUETOOTH
126#define MICROPY_PY_BLUETOOTH (1)
127#define MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE (1)
128#define MICROPY_BLUETOOTH_NIMBLE (1)
129#define MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY (1)
130#endif
Damien Georgead004db2020-03-22 23:17:17 +1100131#define MICROPY_PY_UASYNCIO (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100132#define MICROPY_PY_UCTYPES (1)
133#define MICROPY_PY_UZLIB (1)
134#define MICROPY_PY_UJSON (1)
135#define MICROPY_PY_URE (1)
Damien George8f86fbf2018-07-02 15:13:18 +1000136#define MICROPY_PY_URE_SUB (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100137#define MICROPY_PY_UHEAPQ (1)
138#define MICROPY_PY_UTIMEQ (1)
Damien George05014272018-06-12 13:42:43 +1000139#define MICROPY_PY_UHASHLIB (1)
140#define MICROPY_PY_UHASHLIB_SHA1 (1)
141#define MICROPY_PY_UHASHLIB_SHA256 (1)
Damien George82bc4832018-06-27 16:39:26 +1000142#define MICROPY_PY_UCRYPTOLIB (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100143#define MICROPY_PY_UBINASCII (1)
144#define MICROPY_PY_UBINASCII_CRC32 (1)
145#define MICROPY_PY_URANDOM (1)
146#define MICROPY_PY_URANDOM_EXTRA_FUNCS (1)
robertb4062892020-08-22 20:56:26 +0200147#define MICROPY_PY_URANDOM_SEED_INIT_FUNC (esp_random())
Damien George98b05e32018-04-27 23:51:00 +1000148#define MICROPY_PY_OS_DUPTERM (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100149#define MICROPY_PY_MACHINE (1)
150#define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new
151#define MICROPY_PY_MACHINE_PULSE (1)
152#define MICROPY_PY_MACHINE_I2C (1)
153#define MICROPY_PY_MACHINE_SPI (1)
154#define MICROPY_PY_MACHINE_SPI_MSB (0)
155#define MICROPY_PY_MACHINE_SPI_LSB (1)
Nicko van Someren8e3af7d2019-05-04 19:00:35 -0600156#define MICROPY_HW_ENABLE_SDCARD (1)
Damien George58ebeca2018-03-09 17:25:58 +1100157#define MICROPY_HW_SOFTSPI_MIN_DELAY (0)
158#define MICROPY_HW_SOFTSPI_MAX_BAUDRATE (ets_get_cpu_frequency() * 1000000 / 200) // roughly
Damien Georgebc08c882016-12-06 12:20:10 +1100159#define MICROPY_PY_USSL (1)
160#define MICROPY_SSL_MBEDTLS (1)
Damien George1c52d3e2017-10-30 16:19:52 +1100161#define MICROPY_PY_USSL_FINALISER (1)
Yonatan Goldschmidtbc4f8b42019-02-10 22:35:18 +0200162#define MICROPY_PY_UWEBSOCKET (1)
Damien Georgec1d43522018-04-27 23:57:57 +1000163#define MICROPY_PY_WEBREPL (1)
Damien Georgebc08c882016-12-06 12:20:10 +1100164#define MICROPY_PY_FRAMEBUF (1)
Damien Georgec1d43522018-04-27 23:57:57 +1000165#define MICROPY_PY_USOCKET_EVENTS (MICROPY_PY_WEBREPL)
Jim Mussared6a9bd1c2019-10-01 23:47:37 +1000166#define MICROPY_PY_BLUETOOTH_RANDOM_ADDR (1)
Damien George3b6c9112020-05-08 13:54:10 +1000167#define MICROPY_PY_BLUETOOTH_DEFAULT_GAP_NAME ("ESP32")
Damien Georgebc08c882016-12-06 12:20:10 +1100168
169// fatfs configuration
170#define MICROPY_FATFS_ENABLE_LFN (1)
171#define MICROPY_FATFS_RPATH (2)
172#define MICROPY_FATFS_MAX_SS (4096)
Damien Georgeb5f33ac2019-02-25 23:46:17 +1100173#define MICROPY_FATFS_LFN_CODE_PAGE 437 /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
Damien Georgef35aae32018-06-06 12:00:23 +1000174#define mp_type_fileio mp_type_vfs_fat_fileio
175#define mp_type_textio mp_type_vfs_fat_textio
Damien Georgebc08c882016-12-06 12:20:10 +1100176
177// use vfs's functions for import stat and builtin open
178#define mp_import_stat mp_vfs_import_stat
179#define mp_builtin_open mp_vfs_open
180#define mp_builtin_open_obj mp_vfs_open_obj
181
182// extra built in names to add to the global namespace
183#define MICROPY_PORT_BUILTINS \
184 { MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \
185 { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
186
187// extra built in modules to add to the list of known ones
188extern const struct _mp_obj_module_t esp_module;
Eric Poulsenabec47a2018-02-15 07:59:28 -0800189extern const struct _mp_obj_module_t esp32_module;
Damien Georgebc08c882016-12-06 12:20:10 +1100190extern const struct _mp_obj_module_t utime_module;
191extern const struct _mp_obj_module_t uos_module;
192extern const struct _mp_obj_module_t mp_module_usocket;
193extern const struct _mp_obj_module_t mp_module_machine;
194extern const struct _mp_obj_module_t mp_module_network;
195extern const struct _mp_obj_module_t mp_module_onewire;
196
197#define MICROPY_PORT_BUILTIN_MODULES \
198 { MP_OBJ_NEW_QSTR(MP_QSTR_esp), (mp_obj_t)&esp_module }, \
Eric Poulsenabec47a2018-02-15 07:59:28 -0800199 { MP_OBJ_NEW_QSTR(MP_QSTR_esp32), (mp_obj_t)&esp32_module }, \
Damien Georgebc08c882016-12-06 12:20:10 +1100200 { MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&utime_module }, \
201 { MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&uos_module }, \
202 { MP_OBJ_NEW_QSTR(MP_QSTR_usocket), (mp_obj_t)&mp_module_usocket }, \
203 { MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&mp_module_machine }, \
204 { MP_OBJ_NEW_QSTR(MP_QSTR_network), (mp_obj_t)&mp_module_network }, \
205 { MP_OBJ_NEW_QSTR(MP_QSTR__onewire), (mp_obj_t)&mp_module_onewire }, \
Damien Georgebc08c882016-12-06 12:20:10 +1100206
Damien Georgebc08c882016-12-06 12:20:10 +1100207#define MP_STATE_PORT MP_STATE_VM
208
Damien George9ac9aa92019-01-28 16:16:03 +1100209struct _machine_timer_obj_t;
210
Jim Mussared6a9bd1c2019-10-01 23:47:37 +1000211#if MICROPY_BLUETOOTH_NIMBLE
212struct mp_bluetooth_nimble_root_pointers_t;
213#define MICROPY_PORT_ROOT_POINTER_BLUETOOTH_NIMBLE struct _mp_bluetooth_nimble_root_pointers_t *bluetooth_nimble_root_pointers;
214#else
215#define MICROPY_PORT_ROOT_POINTER_BLUETOOTH_NIMBLE
216#endif
217
Damien Georgebc08c882016-12-06 12:20:10 +1100218#define MICROPY_PORT_ROOT_POINTERS \
219 const char *readline_hist[8]; \
220 mp_obj_t machine_pin_irq_handler[40]; \
Damien George9ac9aa92019-01-28 16:16:03 +1100221 struct _machine_timer_obj_t *machine_timer_obj_head; \
Jim Mussared6a9bd1c2019-10-01 23:47:37 +1000222 MICROPY_PORT_ROOT_POINTER_BLUETOOTH_NIMBLE
Damien Georgebc08c882016-12-06 12:20:10 +1100223
224// type definitions for the specific machine
225
Damien George69661f32020-02-27 15:36:53 +1100226#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p)))
Damien George69661f32020-02-27 15:36:53 +1100227void *esp_native_code_commit(void *, size_t, void *);
Damien Georgeb47e1552019-10-06 23:29:40 +1100228#define MP_PLAT_COMMIT_EXEC(buf, len, reloc) esp_native_code_commit(buf, len, reloc)
Damien Georgebc08c882016-12-06 12:20:10 +1100229#define MP_SSIZE_MAX (0x7fffffff)
230
231// Note: these "critical nested" macros do not ensure cross-CPU exclusion,
232// the only disable interrupts on the current CPU. To full manage exclusion
233// one should use portENTER_CRITICAL/portEXIT_CRITICAL instead.
234#include "freertos/FreeRTOS.h"
235#define MICROPY_BEGIN_ATOMIC_SECTION() portENTER_CRITICAL_NESTED()
236#define MICROPY_END_ATOMIC_SECTION(state) portEXIT_CRITICAL_NESTED(state)
237
Damien George999c8b92018-04-27 23:53:45 +1000238#if MICROPY_PY_USOCKET_EVENTS
239#define MICROPY_PY_USOCKET_EVENTS_HANDLER extern void usocket_events_handler(void); usocket_events_handler();
240#else
241#define MICROPY_PY_USOCKET_EVENTS_HANDLER
242#endif
243
Damien Georgebc08c882016-12-06 12:20:10 +1100244#if MICROPY_PY_THREAD
245#define MICROPY_EVENT_POLL_HOOK \
246 do { \
Damien George98a39112020-02-06 01:05:47 +1100247 extern void mp_handle_pending(bool); \
248 mp_handle_pending(true); \
Damien George999c8b92018-04-27 23:53:45 +1000249 MICROPY_PY_USOCKET_EVENTS_HANDLER \
Damien Georgebc08c882016-12-06 12:20:10 +1100250 MP_THREAD_GIL_EXIT(); \
251 MP_THREAD_GIL_ENTER(); \
252 } while (0);
253#else
254#define MICROPY_EVENT_POLL_HOOK \
255 do { \
Damien George98a39112020-02-06 01:05:47 +1100256 extern void mp_handle_pending(bool); \
257 mp_handle_pending(true); \
Damien George999c8b92018-04-27 23:53:45 +1000258 MICROPY_PY_USOCKET_EVENTS_HANDLER \
Damien George69661f32020-02-27 15:36:53 +1100259 asm ("waiti 0"); \
Damien Georgebc08c882016-12-06 12:20:10 +1100260 } while (0);
261#endif
262
Damien Georgef4641b22020-02-07 12:11:22 +1100263// Functions that should go in IRAM
264#define MICROPY_WRAP_MP_KEYBOARD_INTERRUPT(f) IRAM_ATTR f
265
Damien Georgebc08c882016-12-06 12:20:10 +1100266#define UINT_FMT "%u"
267#define INT_FMT "%d"
268
269typedef int32_t mp_int_t; // must be pointer size
270typedef uint32_t mp_uint_t; // must be pointer size
271typedef long mp_off_t;
272// ssize_t, off_t as required by POSIX-signatured functions in stream.h
273#include <sys/types.h>
274
275// board specifics
Damien Georgebc08c882016-12-06 12:20:10 +1100276#define MICROPY_PY_SYS_PLATFORM "esp32"
Damien George2ccf0302019-07-10 15:38:48 +1000277
278#ifndef MICROPY_HW_ENABLE_MDNS_QUERIES
279#define MICROPY_HW_ENABLE_MDNS_QUERIES (1)
280#endif
281
282#ifndef MICROPY_HW_ENABLE_MDNS_RESPONDER
283#define MICROPY_HW_ENABLE_MDNS_RESPONDER (1)
284#endif