mpconfigport.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2015 Glenn Ruben Bakke
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #ifndef NRF5_MPCONFIGPORT_H__
  27. #define NRF5_MPCONFIGPORT_H__
  28. #include <mpconfigboard.h>
  29. // options to control how MicroPython is built
  30. #ifndef MICROPY_VFS
  31. #define MICROPY_VFS (0)
  32. #endif
  33. #define MICROPY_VFS_FAT (MICROPY_VFS)
  34. #define MICROPY_ALLOC_PATH_MAX (512)
  35. #define MICROPY_PERSISTENT_CODE_LOAD (0)
  36. #define MICROPY_EMIT_THUMB (0)
  37. #define MICROPY_EMIT_INLINE_THUMB (0)
  38. #define MICROPY_COMP_MODULE_CONST (0)
  39. #define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
  40. #define MICROPY_READER_VFS (MICROPY_VFS)
  41. #define MICROPY_ENABLE_GC (1)
  42. #define MICROPY_ENABLE_FINALISER (1)
  43. #define MICROPY_STACK_CHECK (1)
  44. #define MICROPY_HELPER_REPL (1)
  45. #define MICROPY_REPL_EMACS_KEYS (0)
  46. #define MICROPY_REPL_AUTO_INDENT (1)
  47. #define MICROPY_KBD_EXCEPTION (0)
  48. #define MICROPY_ENABLE_SOURCE_LINE (0)
  49. #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
  50. #if NRF51
  51. #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
  52. #else
  53. #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
  54. #endif
  55. #if NRF51
  56. #define MICROPY_ALLOC_GC_STACK_SIZE (32)
  57. #endif
  58. #define MICROPY_OPT_COMPUTED_GOTO (0)
  59. #define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0)
  60. #define MICROPY_OPT_MPZ_BITWISE (0)
  61. // fatfs configuration used in ffconf.h
  62. #define MICROPY_FATFS_ENABLE_LFN (1)
  63. #define MICROPY_FATFS_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
  64. #define MICROPY_FATFS_USE_LABEL (1)
  65. #define MICROPY_FATFS_RPATH (2)
  66. #define MICROPY_FATFS_MULTI_PARTITION (1)
  67. // TODO these should be generic, not bound to fatfs
  68. #define mp_type_fileio fatfs_type_fileio
  69. #define mp_type_textio fatfs_type_textio
  70. // use vfs's functions for import stat and builtin open
  71. #if MICROPY_VFS
  72. #define mp_import_stat mp_vfs_import_stat
  73. #define mp_builtin_open mp_vfs_open
  74. #define mp_builtin_open_obj mp_vfs_open_obj
  75. #endif
  76. // Enable micro:bit filesystem by default.
  77. #ifndef MICROPY_MBFS
  78. #define MICROPY_MBFS (1)
  79. #endif
  80. #define MICROPY_STREAMS_NON_BLOCK (1)
  81. #define MICROPY_MODULE_WEAK_LINKS (1)
  82. #define MICROPY_CAN_OVERRIDE_BUILTINS (1)
  83. #define MICROPY_USE_INTERNAL_ERRNO (1)
  84. #define MICROPY_PY_FUNCTION_ATTRS (1)
  85. #define MICROPY_PY_BUILTINS_STR_UNICODE (0)
  86. #define MICROPY_PY_BUILTINS_STR_CENTER (0)
  87. #define MICROPY_PY_BUILTINS_STR_PARTITION (0)
  88. #define MICROPY_PY_BUILTINS_STR_SPLITLINES (0)
  89. #define MICROPY_PY_BUILTINS_MEMORYVIEW (1)
  90. #define MICROPY_PY_BUILTINS_FROZENSET (1)
  91. #define MICROPY_PY_BUILTINS_EXECFILE (0)
  92. #define MICROPY_PY_BUILTINS_COMPILE (1)
  93. #define MICROPY_PY_BUILTINS_HELP (1)
  94. #define MICROPY_PY_BUILTINS_HELP_TEXT nrf5_help_text
  95. #define MICROPY_PY_BUILTINS_HELP_MODULES (1)
  96. #define MICROPY_MODULE_BUILTIN_INIT (1)
  97. #define MICROPY_PY_ALL_SPECIAL_METHODS (0)
  98. #define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
  99. #define MICROPY_PY_ARRAY_SLICE_ASSIGN (0)
  100. #define MICROPY_PY_BUILTINS_SLICE_ATTRS (0)
  101. #define MICROPY_PY_SYS_EXIT (1)
  102. #define MICROPY_PY_SYS_MAXSIZE (1)
  103. #define MICROPY_PY_SYS_STDFILES (0)
  104. #define MICROPY_PY_SYS_STDIO_BUFFER (0)
  105. #define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
  106. #define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (0)
  107. #define MICROPY_PY_CMATH (0)
  108. #define MICROPY_PY_IO (0)
  109. #define MICROPY_PY_IO_FILEIO (0)
  110. #define MICROPY_PY_UERRNO (0)
  111. #define MICROPY_PY_UBINASCII (0)
  112. #define MICROPY_PY_URANDOM (0)
  113. #define MICROPY_PY_URANDOM_EXTRA_FUNCS (0)
  114. #define MICROPY_PY_UCTYPES (0)
  115. #define MICROPY_PY_UZLIB (0)
  116. #define MICROPY_PY_UJSON (0)
  117. #define MICROPY_PY_URE (0)
  118. #define MICROPY_PY_UHEAPQ (0)
  119. #define MICROPY_PY_UHASHLIB (0)
  120. #define MICROPY_PY_UTIME_MP_HAL (1)
  121. #define MICROPY_PY_MACHINE (1)
  122. #define MICROPY_PY_MACHINE_PULSE (0)
  123. #define MICROPY_PY_MACHINE_I2C_MAKE_NEW machine_hard_i2c_make_new
  124. #define MICROPY_PY_MACHINE_SPI (0)
  125. #define MICROPY_PY_MACHINE_SPI_MIN_DELAY (0)
  126. #define MICROPY_PY_FRAMEBUF (0)
  127. #ifndef MICROPY_HW_LED_COUNT
  128. #define MICROPY_HW_LED_COUNT (0)
  129. #endif
  130. #ifndef MICROPY_HW_LED_PULLUP
  131. #define MICROPY_HW_LED_PULLUP (0)
  132. #endif
  133. #ifndef MICROPY_PY_MUSIC
  134. #define MICROPY_PY_MUSIC (0)
  135. #endif
  136. #ifndef MICROPY_PY_MACHINE_ADC
  137. #define MICROPY_PY_MACHINE_ADC (0)
  138. #endif
  139. #ifndef MICROPY_PY_MACHINE_I2C
  140. #define MICROPY_PY_MACHINE_I2C (0)
  141. #endif
  142. #ifndef MICROPY_PY_MACHINE_HW_SPI
  143. #define MICROPY_PY_MACHINE_HW_SPI (1)
  144. #endif
  145. #ifndef MICROPY_PY_MACHINE_HW_PWM
  146. #define MICROPY_PY_MACHINE_HW_PWM (0)
  147. #endif
  148. #ifndef MICROPY_PY_MACHINE_SOFT_PWM
  149. #define MICROPY_PY_MACHINE_SOFT_PWM (0)
  150. #endif
  151. #ifndef MICROPY_PY_MACHINE_TIMER
  152. #define MICROPY_PY_MACHINE_TIMER (0)
  153. #endif
  154. #ifndef MICROPY_PY_MACHINE_RTCOUNTER
  155. #define MICROPY_PY_MACHINE_RTCOUNTER (0)
  156. #endif
  157. #ifndef MICROPY_PY_RANDOM_HW_RNG
  158. #define MICROPY_PY_RANDOM_HW_RNG (0)
  159. #endif
  160. #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
  161. #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0)
  162. // if sdk is in use, import configuration
  163. #if BLUETOOTH_SD
  164. #include "bluetooth_conf.h"
  165. #endif
  166. #ifndef MICROPY_PY_UBLUEPY
  167. #define MICROPY_PY_UBLUEPY (0)
  168. #endif
  169. #ifndef MICROPY_PY_BLE_NUS
  170. #define MICROPY_PY_BLE_NUS (0)
  171. #endif
  172. // type definitions for the specific machine
  173. #define BYTES_PER_WORD (4)
  174. #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1))
  175. #define MP_SSIZE_MAX (0x7fffffff)
  176. #define UINT_FMT "%u"
  177. #define INT_FMT "%d"
  178. #define HEX2_FMT "%02x"
  179. typedef int mp_int_t; // must be pointer size
  180. typedef unsigned int mp_uint_t; // must be pointer size
  181. typedef long mp_off_t;
  182. // extra built in modules to add to the list of known ones
  183. extern const struct _mp_obj_module_t board_module;
  184. extern const struct _mp_obj_module_t machine_module;
  185. extern const struct _mp_obj_module_t mp_module_utime;
  186. extern const struct _mp_obj_module_t mp_module_uos;
  187. extern const struct _mp_obj_module_t mp_module_ubluepy;
  188. extern const struct _mp_obj_module_t music_module;
  189. extern const struct _mp_obj_module_t random_module;
  190. #if MICROPY_PY_UBLUEPY
  191. #define UBLUEPY_MODULE { MP_ROM_QSTR(MP_QSTR_ubluepy), MP_ROM_PTR(&mp_module_ubluepy) },
  192. #else
  193. #define UBLUEPY_MODULE
  194. #endif
  195. #if MICROPY_PY_MUSIC
  196. #define MUSIC_MODULE { MP_ROM_QSTR(MP_QSTR_music), MP_ROM_PTR(&music_module) },
  197. #else
  198. #define MUSIC_MODULE
  199. #endif
  200. #if MICROPY_PY_RANDOM_HW_RNG
  201. #define RANDOM_MODULE { MP_ROM_QSTR(MP_QSTR_random), MP_ROM_PTR(&random_module) },
  202. #else
  203. #define RANDOM_MODULE
  204. #endif
  205. #if BOARD_SPECIFIC_MODULES
  206. #include "boardmodules.h"
  207. #define MICROPY_BOARD_BUILTINS BOARD_MODULES
  208. #else
  209. #define MICROPY_BOARD_BUILTINS
  210. #endif // BOARD_SPECIFIC_MODULES
  211. #if BLUETOOTH_SD
  212. #if MICROPY_PY_BLE
  213. extern const struct _mp_obj_module_t ble_module;
  214. #define BLE_MODULE { MP_ROM_QSTR(MP_QSTR_ble), MP_ROM_PTR(&ble_module) },
  215. #else
  216. #define BLE_MODULE
  217. #endif
  218. #define MICROPY_PORT_BUILTIN_MODULES \
  219. { MP_ROM_QSTR(MP_QSTR_board), MP_ROM_PTR(&board_module) }, \
  220. { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&machine_module) }, \
  221. { MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&mp_module_utime) }, \
  222. { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mp_module_utime) }, \
  223. { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_uos) }, \
  224. BLE_MODULE \
  225. MUSIC_MODULE \
  226. UBLUEPY_MODULE \
  227. RANDOM_MODULE \
  228. MICROPY_BOARD_BUILTINS \
  229. #else
  230. extern const struct _mp_obj_module_t ble_module;
  231. #define MICROPY_PORT_BUILTIN_MODULES \
  232. { MP_ROM_QSTR(MP_QSTR_board), MP_ROM_PTR(&board_module) }, \
  233. { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&machine_module) }, \
  234. { MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&mp_module_utime) }, \
  235. { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_uos) }, \
  236. MUSIC_MODULE \
  237. RANDOM_MODULE \
  238. MICROPY_BOARD_BUILTINS \
  239. #endif // BLUETOOTH_SD
  240. #define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
  241. { MP_ROM_QSTR(MP_QSTR_os), MP_ROM_PTR(&mp_module_uos) }, \
  242. { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mp_module_utime) }, \
  243. // extra built in names to add to the global namespace
  244. #define MICROPY_PORT_BUILTINS \
  245. { MP_ROM_QSTR(MP_QSTR_help), MP_ROM_PTR(&mp_builtin_help_obj) }, \
  246. { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, \
  247. // extra constants
  248. #define MICROPY_PORT_CONSTANTS \
  249. { MP_ROM_QSTR(MP_QSTR_board), MP_ROM_PTR(&board_module) }, \
  250. { MP_ROM_QSTR(MP_QSTR_machine), MP_ROM_PTR(&machine_module) }, \
  251. BLE_MODULE \
  252. #define MP_STATE_PORT MP_STATE_VM
  253. #if MICROPY_PY_MUSIC
  254. #define ROOT_POINTERS_MUSIC \
  255. struct _music_data_t *music_data;
  256. #else
  257. #define ROOT_POINTERS_MUSIC
  258. #endif
  259. #if MICROPY_PY_MACHINE_SOFT_PWM
  260. #define ROOT_POINTERS_SOFTPWM \
  261. const struct _pwm_events *pwm_active_events; \
  262. const struct _pwm_events *pwm_pending_events;
  263. #else
  264. #define ROOT_POINTERS_SOFTPWM
  265. #endif
  266. #if defined(NRF52840_XXAA)
  267. #define NUM_OF_PINS 48
  268. #else
  269. #define NUM_OF_PINS 32
  270. #endif
  271. #define MICROPY_PORT_ROOT_POINTERS \
  272. const char *readline_hist[8]; \
  273. mp_obj_t pin_class_mapper; \
  274. mp_obj_t pin_class_map_dict; \
  275. mp_obj_t pin_irq_handlers[NUM_OF_PINS]; \
  276. \
  277. /* stdio is repeated on this UART object if it's not null */ \
  278. struct _machine_hard_uart_obj_t *board_stdio_uart; \
  279. \
  280. ROOT_POINTERS_MUSIC \
  281. ROOT_POINTERS_SOFTPWM \
  282. \
  283. /* micro:bit root pointers */ \
  284. void *async_data[2]; \
  285. #define MP_PLAT_PRINT_STRN(str, len) mp_hal_stdout_tx_strn_cooked(str, len)
  286. // We need to provide a declaration/definition of alloca()
  287. #include <alloca.h>
  288. #define MICROPY_PIN_DEFS_PORT_H "pin_defs_nrf5.h"
  289. #endif