diff --git a/.gitignore b/.gitignore index cb2abf5f4..5edbd4b2d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,7 @@ *.dis *.exe -# Packages +# Packages ############ # Logs and Databases diff --git a/.travis.yml b/.travis.yml index 9915cdd00..14d5df0a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,8 @@ before_script: # For teensy build - sudo apt-get install realpath # For coverage testing - - sudo pip install cpp-coveralls + # cpp-coveralls 0.4 conflicts with urllib3 preinstalled in Travis VM + - sudo pip install cpp-coveralls==0.3.12 - gcc --version - arm-none-eabi-gcc --version - python3 --version diff --git a/CHANGELOG.md b/CHANGELOG.md index f30f98b49..2b6764971 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,155 @@ ## [Unreleased](https://github.com/SHA2017-badge/micropython-esp32/tree/HEAD) -[Full Changelog](https://github.com/SHA2017-badge/micropython-esp32/compare/v1.9.1...HEAD) +[Full Changelog](https://github.com/SHA2017-badge/micropython-esp32/compare/sha2...HEAD) + +**Implemented enhancements:** + +- add badge.mpr121\_get\_touch\_info\(\) [\#175](https://github.com/SHA2017-badge/micropython-esp32/pull/175) ([basvs](https://github.com/basvs)) +- Fix msg function as per roosteds request [\#144](https://github.com/SHA2017-badge/micropython-esp32/pull/144) ([rnplus](https://github.com/rnplus)) + +**Fixed bugs:** + +- Launcher reset index switching category [\#140](https://github.com/SHA2017-badge/micropython-esp32/issues/140) +- Compensation for bad battery voltage measurements [\#94](https://github.com/SHA2017-badge/micropython-esp32/issues/94) + +**Closed issues:** + +- Some NVS settings are unreachable [\#209](https://github.com/SHA2017-badge/micropython-esp32/issues/209) +- Flipping the screen doesn't work as expected [\#206](https://github.com/SHA2017-badge/micropython-esp32/issues/206) +- When waking up from touch interrupt, the information about the touch event is lost [\#154](https://github.com/SHA2017-badge/micropython-esp32/issues/154) +- Splash does too many refreshes [\#149](https://github.com/SHA2017-badge/micropython-esp32/issues/149) +- Leaving badge in launcher or installer accidentally drains battery fast [\#148](https://github.com/SHA2017-badge/micropython-esp32/issues/148) +- open\(\) does not allow binary IO [\#146](https://github.com/SHA2017-badge/micropython-esp32/issues/146) +- Lots of ghosting after initial boot & sponsor app [\#137](https://github.com/SHA2017-badge/micropython-esp32/issues/137) +- boot.py not update-able via OTA [\#115](https://github.com/SHA2017-badge/micropython-esp32/issues/115) +- Put peripherals to sleep on deepsleep [\#114](https://github.com/SHA2017-badge/micropython-esp32/issues/114) +- Choose your own \(fancy nick etc\) screensaver [\#110](https://github.com/SHA2017-badge/micropython-esp32/issues/110) +- missing uos.urandom\(n\) in emulator [\#108](https://github.com/SHA2017-badge/micropython-esp32/issues/108) +- If battery is almost empty, nick is not visible anymore [\#96](https://github.com/SHA2017-badge/micropython-esp32/issues/96) +- Battery does not last half a day [\#95](https://github.com/SHA2017-badge/micropython-esp32/issues/95) +- No folders / categories in the launcher and installer [\#91](https://github.com/SHA2017-badge/micropython-esp32/issues/91) +- 'enter' on the OSK should submit the prompt [\#48](https://github.com/SHA2017-badge/micropython-esp32/issues/48) + +**Merged pull requests:** + +- Run applications from bpp and sdcard as well. [\#228](https://github.com/SHA2017-badge/micropython-esp32/pull/228) ([basvs](https://github.com/basvs)) +- add badge.i2c\_read\_reg\(\) and badge.i2c\_write\_reg\(\) [\#226](https://github.com/SHA2017-badge/micropython-esp32/pull/226) ([basvs](https://github.com/basvs)) +- add badge.eink\_png\_info\(filename or bytestring\) [\#225](https://github.com/SHA2017-badge/micropython-esp32/pull/225) ([basvs](https://github.com/basvs)) +- when the splash screen doesn't start, revert to default splash screen. [\#223](https://github.com/SHA2017-badge/micropython-esp32/pull/223) ([basvs](https://github.com/basvs)) +- add justifyTop when drawing text in an ugfx list item. [\#222](https://github.com/SHA2017-badge/micropython-esp32/pull/222) ([basvs](https://github.com/basvs)) +- move tm12x6\_font terminus font to read-only memory. [\#220](https://github.com/SHA2017-badge/micropython-esp32/pull/220) ([basvs](https://github.com/basvs)) +- Remove badge-event-reminder [\#219](https://github.com/SHA2017-badge/micropython-esp32/pull/219) ([basvs](https://github.com/basvs)) +- Add/fixup timezone support [\#218](https://github.com/SHA2017-badge/micropython-esp32/pull/218) ([basvs](https://github.com/basvs)) +- Merge upstream [\#217](https://github.com/SHA2017-badge/micropython-esp32/pull/217) ([basvs](https://github.com/basvs)) +- work around time.time\(\) brokenness [\#215](https://github.com/SHA2017-badge/micropython-esp32/pull/215) ([basvs](https://github.com/basvs)) +- Stop the badge waking up every few tens of seconds [\#213](https://github.com/SHA2017-badge/micropython-esp32/pull/213) ([gavanfantom](https://github.com/gavanfantom)) +- allow chdir to mountpoints \('/', '/sdcard' and '/bpp'\) [\#212](https://github.com/SHA2017-badge/micropython-esp32/pull/212) ([basvs](https://github.com/basvs)) +- Introduce ugfx\_screen\_flipped in the emulator, too [\#211](https://github.com/SHA2017-badge/micropython-esp32/pull/211) ([raboof](https://github.com/raboof)) +- rewrite set\_orientation to use the ugfx\_screen\_flip for rotations \>= … [\#210](https://github.com/SHA2017-badge/micropython-esp32/pull/210) ([basvs](https://github.com/basvs)) +- Added small, simple alternative GUI library \(freedomgfx\), which respects all four freedoms [\#208](https://github.com/SHA2017-badge/micropython-esp32/pull/208) ([chca42](https://github.com/chca42)) +- update event time and room [\#207](https://github.com/SHA2017-badge/micropython-esp32/pull/207) ([basvs](https://github.com/basvs)) +- Safe mode to allow recovery from malware [\#205](https://github.com/SHA2017-badge/micropython-esp32/pull/205) ([gavanfantom](https://github.com/gavanfantom)) +- push sponsors app [\#204](https://github.com/SHA2017-badge/micropython-esp32/pull/204) ([basvs](https://github.com/basvs)) +- soft reboot in raw REPL mode skips boot.py \(for ampy, pyboard\) [\#203](https://github.com/SHA2017-badge/micropython-esp32/pull/203) ([projectgus](https://github.com/projectgus)) +- Read PNG files directly from byte-string. [\#202](https://github.com/SHA2017-badge/micropython-esp32/pull/202) ([basvs](https://github.com/basvs)) +- update esp-idf git hash [\#201](https://github.com/SHA2017-badge/micropython-esp32/pull/201) ([basvs](https://github.com/basvs)) +- fix update all; update next egg if update failed. [\#200](https://github.com/SHA2017-badge/micropython-esp32/pull/200) ([basvs](https://github.com/basvs)) +- add option to stay awake on usb; suppress debug logging [\#199](https://github.com/SHA2017-badge/micropython-esp32/pull/199) ([basvs](https://github.com/basvs)) +- Suppress vfs\_native\_file open file error [\#198](https://github.com/SHA2017-badge/micropython-esp32/pull/198) ([basvs](https://github.com/basvs)) +- fix max open file descriptors in woezel [\#197](https://github.com/SHA2017-badge/micropython-esp32/pull/197) ([basvs](https://github.com/basvs)) +- If a package fails to install, report this to the user. If the reason [\#196](https://github.com/SHA2017-badge/micropython-esp32/pull/196) ([gavanfantom](https://github.com/gavanfantom)) +- Erase the otadata partition when flashing firmware, so that we can be… [\#195](https://github.com/SHA2017-badge/micropython-esp32/pull/195) ([gavanfantom](https://github.com/gavanfantom)) +- Use a timeout on fetching data, and handle failures gracefully. [\#194](https://github.com/SHA2017-badge/micropython-esp32/pull/194) ([gavanfantom](https://github.com/gavanfantom)) +- Use 'with open\(\) as f:' instead of 'f = open\(\)' [\#193](https://github.com/SHA2017-badge/micropython-esp32/pull/193) ([basvs](https://github.com/basvs)) +- Revert "Upy use powerdown mgr" [\#191](https://github.com/SHA2017-badge/micropython-esp32/pull/191) ([basvs](https://github.com/basvs)) +- fix big-endian packing to 8 bytes [\#190](https://github.com/SHA2017-badge/micropython-esp32/pull/190) ([basvs](https://github.com/basvs)) +- Make Jan Henk again. [\#189](https://github.com/SHA2017-badge/micropython-esp32/pull/189) ([ranzbak](https://github.com/ranzbak)) +- Change lipo bat indicator voltages [\#188](https://github.com/SHA2017-badge/micropython-esp32/pull/188) ([Roosted7](https://github.com/Roosted7)) +- Add make flash to makefile [\#187](https://github.com/SHA2017-badge/micropython-esp32/pull/187) ([Roosted7](https://github.com/Roosted7)) +- add experimental temperature sensor and hall sensor. [\#186](https://github.com/SHA2017-badge/micropython-esp32/pull/186) ([basvs](https://github.com/basvs)) +- Add a new optional argument to the draw\(\) function in a service, whic… [\#185](https://github.com/SHA2017-badge/micropython-esp32/pull/185) ([gavanfantom](https://github.com/gavanfantom)) +- Fix redraw loop when idle [\#184](https://github.com/SHA2017-badge/micropython-esp32/pull/184) ([gavanfantom](https://github.com/gavanfantom)) +- Add time to OTA check [\#182](https://github.com/SHA2017-badge/micropython-esp32/pull/182) ([rnplus](https://github.com/rnplus)) +- Allow services to execute a special draw function just before sleeping [\#181](https://github.com/SHA2017-badge/micropython-esp32/pull/181) ([rnplus](https://github.com/rnplus)) +- Exception reporting and post OTA update script [\#180](https://github.com/SHA2017-badge/micropython-esp32/pull/180) ([rnplus](https://github.com/rnplus)) +- add wrapper around badge\_eink\_display\(\) method [\#179](https://github.com/SHA2017-badge/micropython-esp32/pull/179) ([basvs](https://github.com/basvs)) +- New launcher [\#178](https://github.com/SHA2017-badge/micropython-esp32/pull/178) ([rnplus](https://github.com/rnplus)) +- add simple wrapper for low-level bpp flash data [\#177](https://github.com/SHA2017-badge/micropython-esp32/pull/177) ([basvs](https://github.com/basvs)) +- do not re-install the gpio-isr-service. it's already installed. [\#176](https://github.com/SHA2017-badge/micropython-esp32/pull/176) ([basvs](https://github.com/basvs)) +- Add set\_timeout to power management [\#174](https://github.com/SHA2017-badge/micropython-esp32/pull/174) ([rnplus](https://github.com/rnplus)) +- Add update all app to firmware [\#173](https://github.com/SHA2017-badge/micropython-esp32/pull/173) ([rnplus](https://github.com/rnplus)) +- Add power management to launcher [\#172](https://github.com/SHA2017-badge/micropython-esp32/pull/172) ([rnplus](https://github.com/rnplus)) +- Move mount-code to modbadge; add sdcard support [\#171](https://github.com/SHA2017-badge/micropython-esp32/pull/171) ([basvs](https://github.com/basvs)) +- Change led brightness for event reminder and make rtc mandatory again [\#170](https://github.com/SHA2017-badge/micropython-esp32/pull/170) ([rnplus](https://github.com/rnplus)) +- Fixed a couple of small bugs [\#169](https://github.com/SHA2017-badge/micropython-esp32/pull/169) ([rnplus](https://github.com/rnplus)) +- Add some sugar and spice to make things nice [\#168](https://github.com/SHA2017-badge/micropython-esp32/pull/168) ([rnplus](https://github.com/rnplus)) +- Renze cleanup [\#167](https://github.com/SHA2017-badge/micropython-esp32/pull/167) ([rnplus](https://github.com/rnplus)) +- set type after determining type.. [\#166](https://github.com/SHA2017-badge/micropython-esp32/pull/166) ([basvs](https://github.com/basvs)) +- Add nice change by raboof [\#165](https://github.com/SHA2017-badge/micropython-esp32/pull/165) ([rnplus](https://github.com/rnplus)) +- Working services [\#164](https://github.com/SHA2017-badge/micropython-esp32/pull/164) ([rnplus](https://github.com/rnplus)) +- Add some warning notes when using badge.leds\_send\_data\(\) incorrectly [\#163](https://github.com/SHA2017-badge/micropython-esp32/pull/163) ([basvs](https://github.com/basvs)) +- Add optional timestamp argument to easyrtc.string\(\) [\#160](https://github.com/SHA2017-badge/micropython-esp32/pull/160) ([rnplus](https://github.com/rnplus)) +- Upy use powerdown mgr [\#159](https://github.com/SHA2017-badge/micropython-esp32/pull/159) ([Spritetm](https://github.com/Spritetm)) +- Service api v2 [\#158](https://github.com/SHA2017-badge/micropython-esp32/pull/158) ([rnplus](https://github.com/rnplus)) +- Lower loglevel of wifi at runtime [\#157](https://github.com/SHA2017-badge/micropython-esp32/pull/157) ([Roosted7](https://github.com/Roosted7)) +- Fix errors introduced by changing easydraw.msg\(\) function [\#155](https://github.com/SHA2017-badge/micropython-esp32/pull/155) ([rnplus](https://github.com/rnplus)) +- add badge.eink\_deep\_sleep\(\) and badge.eink\_wakeup\(\) [\#153](https://github.com/SHA2017-badge/micropython-esp32/pull/153) ([basvs](https://github.com/basvs)) +- Add more badge\_power hooks. [\#151](https://github.com/SHA2017-badge/micropython-esp32/pull/151) ([basvs](https://github.com/basvs)) +- add badge.GREYSCALE const. [\#150](https://github.com/SHA2017-badge/micropython-esp32/pull/150) ([basvs](https://github.com/basvs)) +- initialize with default eink type. \(as configured in make menuconfig\) [\#145](https://github.com/SHA2017-badge/micropython-esp32/pull/145) ([basvs](https://github.com/basvs)) +- Fix a big bug and a little bit of cleaning [\#143](https://github.com/SHA2017-badge/micropython-esp32/pull/143) ([rnplus](https://github.com/rnplus)) +- Split splash into smaller parts, thereby creating helper files for some functions [\#142](https://github.com/SHA2017-badge/micropython-esp32/pull/142) ([rnplus](https://github.com/rnplus)) +- Makefile improvements [\#141](https://github.com/SHA2017-badge/micropython-esp32/pull/141) ([basvs](https://github.com/basvs)) +- Bugfixes for splash [\#139](https://github.com/SHA2017-badge/micropython-esp32/pull/139) ([rnplus](https://github.com/rnplus)) +- Updated splash code and try to mount bpp [\#138](https://github.com/SHA2017-badge/micropython-esp32/pull/138) ([rnplus](https://github.com/rnplus)) +- Up installer WiFi timeout from 4s to 15s [\#136](https://github.com/SHA2017-badge/micropython-esp32/pull/136) ([niekproductions](https://github.com/niekproductions)) +- Update demo.py [\#135](https://github.com/SHA2017-badge/micropython-esp32/pull/135) ([powermik](https://github.com/powermik)) +- renamed badge\_portexp to badge\_fxl6408 [\#134](https://github.com/SHA2017-badge/micropython-esp32/pull/134) ([basvs](https://github.com/basvs)) +- Pull changes from upstream [\#133](https://github.com/SHA2017-badge/micropython-esp32/pull/133) ([Roosted7](https://github.com/Roosted7)) +- badge\_touch -\> badge\_cpt112s [\#132](https://github.com/SHA2017-badge/micropython-esp32/pull/132) ([basvs](https://github.com/basvs)) +- uos.urandom\(\) bugfix. [\#131](https://github.com/SHA2017-badge/micropython-esp32/pull/131) ([basvs](https://github.com/basvs)) +- Added gfx\_userfs glue to micropython build [\#130](https://github.com/SHA2017-badge/micropython-esp32/pull/130) ([aczid](https://github.com/aczid)) +- Add support for removal of NVS page [\#129](https://github.com/SHA2017-badge/micropython-esp32/pull/129) ([Roosted7](https://github.com/Roosted7)) +- Added a urandom port for Unix build [\#127](https://github.com/SHA2017-badge/micropython-esp32/pull/127) ([aczid](https://github.com/aczid)) + +## [sha2](https://github.com/SHA2017-badge/micropython-esp32/tree/sha2) (2017-07-26) +[Full Changelog](https://github.com/SHA2017-badge/micropython-esp32/compare/sha1...sha2) + +**Implemented enhancements:** + +- Installer rewrite w/ category support [\#120](https://github.com/SHA2017-badge/micropython-esp32/pull/120) ([niekproductions](https://github.com/niekproductions)) +- Launcher UX fixes [\#107](https://github.com/SHA2017-badge/micropython-esp32/pull/107) ([niekproductions](https://github.com/niekproductions)) + +**Closed issues:** + +- Led driver not working properly above Hex 0x7F [\#119](https://github.com/SHA2017-badge/micropython-esp32/issues/119) +- ugfx.init\(\) flashes screen [\#112](https://github.com/SHA2017-badge/micropython-esp32/issues/112) +- rtcmem: check if offset is valid [\#111](https://github.com/SHA2017-badge/micropython-esp32/issues/111) +- 'Flash' button not used [\#99](https://github.com/SHA2017-badge/micropython-esp32/issues/99) +- nvs\_\[get/set\]\_u\[8/16\] not working [\#93](https://github.com/SHA2017-badge/micropython-esp32/issues/93) +- woezel unzip dict size [\#82](https://github.com/SHA2017-badge/micropython-esp32/issues/82) +- Sponsor app not working [\#78](https://github.com/SHA2017-badge/micropython-esp32/issues/78) + +**Merged pull requests:** + +- Consistent UI and updated installer [\#126](https://github.com/SHA2017-badge/micropython-esp32/pull/126) ([Roosted7](https://github.com/Roosted7)) +- use input framework to check for waiting input. [\#125](https://github.com/SHA2017-badge/micropython-esp32/pull/125) ([basvs](https://github.com/basvs)) +- New setup and default name [\#124](https://github.com/SHA2017-badge/micropython-esp32/pull/124) ([Roosted7](https://github.com/Roosted7)) +- support negative offsets in png image loading [\#122](https://github.com/SHA2017-badge/micropython-esp32/pull/122) ([annejan](https://github.com/annejan)) +- cleanup esp-rtcmem code. throw out-of-range exceptions. [\#121](https://github.com/SHA2017-badge/micropython-esp32/pull/121) ([basvs](https://github.com/basvs)) +- Update makefile: faster boot and flash [\#118](https://github.com/SHA2017-badge/micropython-esp32/pull/118) ([Roosted7](https://github.com/Roosted7)) +- Major python code change [\#116](https://github.com/SHA2017-badge/micropython-esp32/pull/116) ([Roosted7](https://github.com/Roosted7)) +- Added extra urandom functions [\#109](https://github.com/SHA2017-badge/micropython-esp32/pull/109) ([aczid](https://github.com/aczid)) +- lower max\_files from 8 to 3. [\#106](https://github.com/SHA2017-badge/micropython-esp32/pull/106) ([basvs](https://github.com/basvs)) +- Remove deprecated led function [\#105](https://github.com/SHA2017-badge/micropython-esp32/pull/105) ([Roosted7](https://github.com/Roosted7)) +- expose badge.nvs\_erase\_key\(\) [\#103](https://github.com/SHA2017-badge/micropython-esp32/pull/103) ([basvs](https://github.com/basvs)) +- Code cleanup of the badge.nvs\_\* code. [\#102](https://github.com/SHA2017-badge/micropython-esp32/pull/102) ([basvs](https://github.com/basvs)) +- Setup.state as u8 and shorter keys [\#101](https://github.com/SHA2017-badge/micropython-esp32/pull/101) ([rnplus](https://github.com/rnplus)) +- report tls error messages instead of crashing. [\#100](https://github.com/SHA2017-badge/micropython-esp32/pull/100) ([basvs](https://github.com/basvs)) + +## [sha1](https://github.com/SHA2017-badge/micropython-esp32/tree/sha1) (2017-07-21) +[Full Changelog](https://github.com/SHA2017-badge/micropython-esp32/compare/v1.9.1...sha1) **Implemented enhancements:** @@ -16,6 +164,12 @@ **Merged pull requests:** +- Zo is ie mooier. [\#88](https://github.com/SHA2017-badge/micropython-esp32/pull/88) ([rnplus](https://github.com/rnplus)) +- About [\#87](https://github.com/SHA2017-badge/micropython-esp32/pull/87) ([rnplus](https://github.com/rnplus)) +- OTA check + Other fixes [\#86](https://github.com/SHA2017-badge/micropython-esp32/pull/86) ([rnplus](https://github.com/rnplus)) +- dump esp heap info. [\#85](https://github.com/SHA2017-badge/micropython-esp32/pull/85) ([basvs](https://github.com/basvs)) +- Basvs ugfx greyscale [\#84](https://github.com/SHA2017-badge/micropython-esp32/pull/84) ([annejan](https://github.com/annejan)) +- Basvs preseed unzip [\#83](https://github.com/SHA2017-badge/micropython-esp32/pull/83) ([annejan](https://github.com/annejan)) - update wifiSetup [\#81](https://github.com/SHA2017-badge/micropython-esp32/pull/81) ([Roosted7](https://github.com/Roosted7)) - Add static wifiSetup module [\#79](https://github.com/SHA2017-badge/micropython-esp32/pull/79) ([Roosted7](https://github.com/Roosted7)) - Remove flashing script from upy dir [\#77](https://github.com/SHA2017-badge/micropython-esp32/pull/77) ([Roosted7](https://github.com/Roosted7)) diff --git a/CODECONVENTIONS.md b/CODECONVENTIONS.md index f9dce71dd..982b95831 100644 --- a/CODECONVENTIONS.md +++ b/CODECONVENTIONS.md @@ -73,7 +73,7 @@ White space: keyword and the opening parenthesis. - Put 1 space after a comma, and 1 space around operators. -Braces: +Braces: - Use braces for all blocks, even no-line and single-line pieces of code. - Put opening braces on the end of the line it belongs to, not on diff --git a/bare-arm/Makefile b/bare-arm/Makefile index cfd427c60..90c13de11 100644 --- a/bare-arm/Makefile +++ b/bare-arm/Makefile @@ -4,12 +4,12 @@ include ../py/mkenv.mk QSTR_DEFS = qstrdefsport.h # include py core make definitions -include ../py/py.mk +include $(TOP)/py/py.mk CROSS_COMPILE = arm-none-eabi- INC += -I. -INC += -I.. +INC += -I$(TOP) INC += -I$(BUILD) CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion @@ -45,4 +45,4 @@ $(BUILD)/firmware.elf: $(OBJ) $(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS) $(Q)$(SIZE) $@ -include ../py/mkrules.mk +include $(TOP)/py/mkrules.mk diff --git a/bare-arm/mpconfigport.h b/bare-arm/mpconfigport.h index 97e866bdb..17f794521 100644 --- a/bare-arm/mpconfigport.h +++ b/bare-arm/mpconfigport.h @@ -1,6 +1,6 @@ #include -// options to control how Micro Python is built +// options to control how MicroPython is built #define MICROPY_QSTR_BYTES_IN_HASH (1) #define MICROPY_ALLOC_PATH_MAX (512) diff --git a/bare-arm/stm32f405.ld b/bare-arm/stm32f405.ld index 345a92d3c..dd688a024 100644 --- a/bare-arm/stm32f405.ld +++ b/bare-arm/stm32f405.ld @@ -11,7 +11,7 @@ MEMORY CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 0x010000 /* 64 KiB */ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x020000 /* 128 KiB */ } - + /* top end of the stack */ _estack = ORIGIN(RAM) + LENGTH(RAM); @@ -30,7 +30,7 @@ SECTIONS . = ALIGN(4); } >FLASH_ISR - + /* The program code and other data goes into FLASH */ .text : { @@ -46,7 +46,7 @@ SECTIONS _etext = .; /* define a global symbol at end of code */ _sidata = _etext; /* This is used by the startup in order to initialize the .data secion */ } >FLASH_TEXT - + /* .ARM.extab : { @@ -60,7 +60,7 @@ SECTIONS __exidx_end = .; } >FLASH */ - + /* This is the initialized data section The program executes knowing that the data is in the RAM but the loader puts the initial values in the FLASH (inidata). @@ -76,7 +76,7 @@ SECTIONS . = ALIGN(4); _edata = .; /* define a global symbol at data end; used by startup code in order to initialise the .data section in RAM */ } >RAM - + /* Uninitialized data section */ .bss : { diff --git a/cc3200/Makefile b/cc3200/Makefile index 663496435..4c8b0b832 100644 --- a/cc3200/Makefile +++ b/cc3200/Makefile @@ -34,7 +34,7 @@ ifeq ($(BTARGET), application) # qstr definitions (must come before including py.mk) QSTR_DEFS = qstrdefsport.h $(BUILD)/pins_qstr.h # include MicroPython make definitions -include ../py/py.mk +include $(TOP)/py/py.mk include application.mk else ifeq ($(BTARGET), bootloader) @@ -45,7 +45,7 @@ endif endif # always include MicroPython make rules -include ../py/mkrules.mk +include $(TOP)/py/mkrules.mk erase: cc3200tool -p $(PORT) format_flash --size $(FLASH_SIZE_$(BOARD)) diff --git a/cc3200/application.lds b/cc3200/application.lds index 22ad1968d..3f5e72f8b 100644 --- a/cc3200/application.lds +++ b/cc3200/application.lds @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -37,7 +37,7 @@ ENTRY(ResetISR) SECTIONS { - /* place the FreeRTOS heap (the micropython stack will live here) */ + /* place the FreeRTOS heap (the MicroPython stack will live here) */ .rtos_heap (NOLOAD) : { . = ALIGN(8); @@ -83,7 +83,7 @@ SECTIONS } > SRAM /* place here functions that are only called during boot up, */ - /* that way, we can re-use this area for the micropython heap */ + /* that way, we can re-use this area for the MicroPython heap */ .boot : { . = ALIGN(8); @@ -93,7 +93,7 @@ SECTIONS _eboot = .; } > SRAM - /* allocate the micropython heap */ + /* allocate the MicroPython heap */ .heap : { . = ALIGN(8); diff --git a/cc3200/application.mk b/cc3200/application.mk index c6b91ed0e..3ac28823a 100644 --- a/cc3200/application.mk +++ b/cc3200/application.mk @@ -1,5 +1,5 @@ APP_INC = -I. -APP_INC += -I.. +APP_INC += -I$(TOP) APP_INC += -Ifatfs/src APP_INC += -Ifatfs/src/drivers APP_INC += -IFreeRTOS @@ -10,7 +10,7 @@ APP_INC += -Ihal APP_INC += -Ihal/inc APP_INC += -Imisc APP_INC += -Imods -APP_INC += -I../drivers/cc3100/inc +APP_INC += -I$(TOP)/drivers/cc3100/inc APP_INC += -Isimplelink APP_INC += -Isimplelink/oslib APP_INC += -Itelnet @@ -18,7 +18,7 @@ APP_INC += -Iutil APP_INC += -Ibootmgr APP_INC += -I$(BUILD) APP_INC += -I$(BUILD)/genhdr -APP_INC += -I../stmhal +APP_INC += -I$(TOP)/stmhal APP_CPPDEFINES = -Dgcc -DTARGET_IS_CC3200 -DSL_FULL -DUSE_FREERTOS diff --git a/cc3200/boards/LAUNCHXL/mpconfigboard.h b/cc3200/boards/LAUNCHXL/mpconfigboard.h index 32ef5290b..b3d766d1e 100644 --- a/cc3200/boards/LAUNCHXL/mpconfigboard.h +++ b/cc3200/boards/LAUNCHXL/mpconfigboard.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/boards/WIPY/mpconfigboard.h b/cc3200/boards/WIPY/mpconfigboard.h index 9f04dbf23..af15cca35 100644 --- a/cc3200/boards/WIPY/mpconfigboard.h +++ b/cc3200/boards/WIPY/mpconfigboard.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/boards/cc3200_prefix.c b/cc3200/boards/cc3200_prefix.c index 971285745..d03efe024 100644 --- a/cc3200/boards/cc3200_prefix.c +++ b/cc3200/boards/cc3200_prefix.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/bootmgr/bootloader.mk b/cc3200/bootmgr/bootloader.mk index ee5236913..b8aa9082c 100644 --- a/cc3200/bootmgr/bootloader.mk +++ b/cc3200/bootmgr/bootloader.mk @@ -4,13 +4,13 @@ BOOT_INC = -Ibootmgr BOOT_INC += -Ibootmgr/sl BOOT_INC += -Ihal BOOT_INC += -Ihal/inc -BOOT_INC += -I../drivers/cc3100/inc +BOOT_INC += -I$(TOP)/drivers/cc3100/inc BOOT_INC += -Imisc BOOT_INC += -Imods BOOT_INC += -Isimplelink BOOT_INC += -Isimplelink/oslib BOOT_INC += -Iutil -BOOT_INC += -I.. +BOOT_INC += -I$(TOP) BOOT_INC += -I. BOOT_INC += -I$(BUILD) diff --git a/cc3200/bootmgr/bootmgr.h b/cc3200/bootmgr/bootmgr.h index 4b314335c..5a370f8c9 100644 --- a/cc3200/bootmgr/bootmgr.h +++ b/cc3200/bootmgr/bootmgr.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef __BOOTMGR_H__ -#define __BOOTMGR_H__ +#ifndef MICROPY_INCLUDED_CC3200_BOOTMGR_BOOTMGR_H +#define MICROPY_INCLUDED_CC3200_BOOTMGR_BOOTMGR_H //**************************************************************************** // @@ -66,4 +65,4 @@ extern void Run(unsigned long); } #endif -#endif //__BOOTMGR_H__ +#endif // MICROPY_INCLUDED_CC3200_BOOTMGR_BOOTMGR_H diff --git a/cc3200/bootmgr/bootmgr.lds b/cc3200/bootmgr/bootmgr.lds index e67fe23ae..9c911a0d0 100644 --- a/cc3200/bootmgr/bootmgr.lds +++ b/cc3200/bootmgr/bootmgr.lds @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/bootmgr/flc.h b/cc3200/bootmgr/flc.h index 4b2aca9ac..8f05bb320 100644 --- a/cc3200/bootmgr/flc.h +++ b/cc3200/bootmgr/flc.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef __FLC_H__ -#define __FLC_H__ +#ifndef MICROPY_INCLUDED_CC3200_BOOTMGR_FLC_H +#define MICROPY_INCLUDED_CC3200_BOOTMGR_FLC_H /****************************************************************************** @@ -93,4 +92,4 @@ typedef struct _sBootInfo_t } #endif -#endif /* __FLC_H__ */ +#endif // MICROPY_INCLUDED_CC3200_BOOTMGR_FLC_H diff --git a/cc3200/bootmgr/main.c b/cc3200/bootmgr/main.c index 0d9ab35f8..cfb8dec21 100644 --- a/cc3200/bootmgr/main.c +++ b/cc3200/bootmgr/main.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/ftp/ftp.c b/cc3200/ftp/ftp.c index 1febe291f..5461f9180 100644 --- a/cc3200/ftp/ftp.c +++ b/cc3200/ftp/ftp.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -335,7 +335,7 @@ void ftp_run (void) { ftp_data.loggin.uservalid = false; ftp_data.loggin.passvalid = false; strcpy (ftp_path, "/"); - ftp_send_reply (220, "Micropython FTP Server"); + ftp_send_reply (220, "MicroPython FTP Server"); break; } } diff --git a/cc3200/ftp/ftp.h b/cc3200/ftp/ftp.h index 13b044dcf..af4c14fa3 100644 --- a/cc3200/ftp/ftp.h +++ b/cc3200/ftp/ftp.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef FTP_H_ -#define FTP_H_ +#ifndef MICROPY_INCLUDED_CC3200_FTP_FTP_H +#define MICROPY_INCLUDED_CC3200_FTP_FTP_H /****************************************************************************** DECLARE EXPORTED FUNCTIONS @@ -36,4 +35,4 @@ extern void ftp_enable (void); extern void ftp_disable (void); extern void ftp_reset (void); -#endif /* FTP_H_ */ +#endif // MICROPY_INCLUDED_CC3200_FTP_FTP_H diff --git a/cc3200/ftp/updater.c b/cc3200/ftp/updater.c index fece70095..5be2c6063 100644 --- a/cc3200/ftp/updater.c +++ b/cc3200/ftp/updater.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/ftp/updater.h b/cc3200/ftp/updater.h index b581d0fc8..51248e4bf 100644 --- a/cc3200/ftp/updater.h +++ b/cc3200/ftp/updater.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,10 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - - -#ifndef UPDATER_H_ -#define UPDATER_H_ +#ifndef MICROPY_INCLUDED_CC3200_FTP_UPDATER_H +#define MICROPY_INCLUDED_CC3200_FTP_UPDATER_H extern void updater_pre_init (void); extern bool updater_check_path (void *path); @@ -35,4 +33,4 @@ extern bool updater_write (uint8_t *buf, uint32_t len); extern void updater_finnish (void); extern bool updater_verify (uint8_t *rbuff, uint8_t *hasbuff); -#endif /* UPDATER_H_ */ +#endif // MICROPY_INCLUDED_CC3200_FTP_UPDATER_H diff --git a/cc3200/hal/cc3200_asm.h b/cc3200/hal/cc3200_asm.h index dcaaf57e1..742c9a6f7 100644 --- a/cc3200/hal/cc3200_asm.h +++ b/cc3200/hal/cc3200_asm.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/hal/cc3200_hal.c b/cc3200/hal/cc3200_hal.c index 5c0e9c30f..b4848e99e 100644 --- a/cc3200/hal/cc3200_hal.c +++ b/cc3200/hal/cc3200_hal.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/hal/cc3200_hal.h b/cc3200/hal/cc3200_hal.h index fcb85b292..71e245eeb 100644 --- a/cc3200/hal/cc3200_hal.h +++ b/cc3200/hal/cc3200_hal.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,9 +24,6 @@ * THE SOFTWARE. */ -#ifndef CC3200_LAUNCHXL_HAL_CC3200_HAL_H_ -#define CC3200_LAUNCHXL_HAL_CC3200_HAL_H_ - #include #include @@ -69,5 +66,3 @@ extern void mp_hal_set_interrupt_char (int c); #define mp_hal_delay_us(usec) UtilsDelay(UTILS_DELAY_US_TO_COUNT(usec)) #define mp_hal_ticks_cpu() (SysTickPeriodGet() - SysTickValueGet()) - -#endif /* CC3200_LAUNCHXL_HAL_CC3200_HAL_H_ */ diff --git a/cc3200/hal/fault_registers.h b/cc3200/hal/fault_registers.h index 739745e92..ade516b9e 100644 --- a/cc3200/hal/fault_registers.h +++ b/cc3200/hal/fault_registers.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/main.c b/cc3200/main.c index 7c6c4b545..e2299e146 100644 --- a/cc3200/main.c +++ b/cc3200/main.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -89,7 +89,7 @@ int main (void) { #ifndef DEBUG OsiTaskHandle mpTaskHandle; #endif - mpTaskHandle = xTaskCreateStatic(TASK_Micropython, "MicroPy", + mpTaskHandle = xTaskCreateStatic(TASK_MicroPython, "MicroPy", MICROPY_TASK_STACK_LEN, NULL, MICROPY_TASK_PRIORITY, mpTaskStack, &mpTaskTCB); ASSERT(mpTaskHandle != NULL); diff --git a/cc3200/misc/FreeRTOSHooks.c b/cc3200/misc/FreeRTOSHooks.c index dac9a9282..c618279b7 100644 --- a/cc3200/misc/FreeRTOSHooks.c +++ b/cc3200/misc/FreeRTOSHooks.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/misc/antenna.c b/cc3200/misc/antenna.c index 0fbf79f0f..afeed85e1 100644 --- a/cc3200/misc/antenna.c +++ b/cc3200/misc/antenna.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/misc/antenna.h b/cc3200/misc/antenna.h index b3b1c6162..c9d845453 100644 --- a/cc3200/misc/antenna.h +++ b/cc3200/misc/antenna.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef _ANTENNA_H_ -#define _ANTENNA_H_ +#ifndef MICROPY_INCLUDED_CC3200_MISC_ANTENNA_H +#define MICROPY_INCLUDED_CC3200_MISC_ANTENNA_H typedef enum { ANTENNA_TYPE_INTERNAL = 0, @@ -35,4 +34,4 @@ typedef enum { extern void antenna_init0 (void); extern void antenna_select (antenna_type_t antenna_type); -#endif /* _ANTENNA_H_ */ +#endif // MICROPY_INCLUDED_CC3200_MISC_ANTENNA_H diff --git a/cc3200/misc/help.c b/cc3200/misc/help.c index cce515898..739303e19 100644 --- a/cc3200/misc/help.c +++ b/cc3200/misc/help.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/misc/mperror.c b/cc3200/misc/mperror.c index 81b853b48..082d940e2 100644 --- a/cc3200/misc/mperror.c +++ b/cc3200/misc/mperror.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/misc/mperror.h b/cc3200/misc/mperror.h index e38d129db..1c3eb6269 100644 --- a/cc3200/misc/mperror.h +++ b/cc3200/misc/mperror.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,9 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef MPERROR_H_ -#define MPERROR_H_ +#ifndef MICROPY_INCLUDED_CC3200_MISC_MPERROR_H +#define MICROPY_INCLUDED_CC3200_MISC_MPERROR_H extern void NORETURN __fatal_error(const char *msg); @@ -39,4 +38,4 @@ void mperror_heartbeat_signal (void); void mperror_enable_heartbeat (bool enable); bool mperror_is_heartbeat_enabled (void); -#endif // MPERROR_H_ +#endif // MICROPY_INCLUDED_CC3200_MISC_MPERROR_H diff --git a/cc3200/misc/mpexception.c b/cc3200/misc/mpexception.c index 068adb70b..72b203fae 100644 --- a/cc3200/misc/mpexception.c +++ b/cc3200/misc/mpexception.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/misc/mpexception.h b/cc3200/misc/mpexception.h index 2f9d1877c..88134857c 100644 --- a/cc3200/misc/mpexception.h +++ b/cc3200/misc/mpexception.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,9 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef MPEXCEPTION_H_ -#define MPEXCEPTION_H_ +#ifndef MICROPY_INCLUDED_CC3200_MISC_MPEXCEPTION_H +#define MICROPY_INCLUDED_CC3200_MISC_MPEXCEPTION_H extern const char mpexception_value_invalid_arguments[]; extern const char mpexception_num_type_invalid_arguments[]; @@ -40,4 +39,4 @@ extern void mpexception_set_interrupt_char (int c); extern void mpexception_nlr_jump (void *o); extern void mpexception_keyboard_nlr_jump (void); -#endif /* MPEXCEPTION_H_ */ +#endif // MICROPY_INCLUDED_CC3200_MISC_MPEXCEPTION_H diff --git a/cc3200/misc/mpirq.c b/cc3200/misc/mpirq.c index 37149089f..321663088 100644 --- a/cc3200/misc/mpirq.c +++ b/cc3200/misc/mpirq.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -143,7 +143,7 @@ void mp_irq_handler (mp_obj_t self_in) { } /******************************************************************************/ -// Micro Python bindings +// MicroPython bindings STATIC mp_obj_t mp_irq_init (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_irq_obj_t *self = pos_args[0]; diff --git a/cc3200/misc/mpirq.h b/cc3200/misc/mpirq.h index 3fd21ee09..35ce66e2d 100644 --- a/cc3200/misc/mpirq.h +++ b/cc3200/misc/mpirq.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef MPIRQ_H_ -#define MPIRQ_H_ +#ifndef MICROPY_INCLUDED_CC3200_MISC_MPIRQ_H +#define MICROPY_INCLUDED_CC3200_MISC_MPIRQ_H /****************************************************************************** DEFINE CONSTANTS @@ -72,4 +71,4 @@ void mp_irq_remove (const mp_obj_t parent); void mp_irq_handler (mp_obj_t self_in); uint mp_irq_translate_priority (uint priority); -#endif /* MPIRQ_H_ */ +#endif // MICROPY_INCLUDED_CC3200_MISC_MPIRQ_H diff --git a/cc3200/mods/modmachine.c b/cc3200/mods/modmachine.c index fd1485607..5f63d0196 100644 --- a/cc3200/mods/modmachine.c +++ b/cc3200/mods/modmachine.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -72,7 +72,7 @@ extern OsiTaskHandle xSimpleLinkSpawnTaskHndl; /// /******************************************************************************/ -// Micro Python bindings; +// MicroPython bindings; STATIC mp_obj_t machine_reset(void) { // disable wlan diff --git a/cc3200/mods/modnetwork.c b/cc3200/mods/modnetwork.c index d44f75aca..249e1be37 100644 --- a/cc3200/mods/modnetwork.c +++ b/cc3200/mods/modnetwork.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/mods/modnetwork.h b/cc3200/mods/modnetwork.h index 8a886c3e4..6ec90a2ba 100644 --- a/cc3200/mods/modnetwork.h +++ b/cc3200/mods/modnetwork.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,9 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef MODNETWORK_H_ -#define MODNETWORK_H_ +#ifndef MICROPY_INCLUDED_CC3200_MODS_MODNETWORK_H +#define MICROPY_INCLUDED_CC3200_MODS_MODNETWORK_H /****************************************************************************** DEFINE CONSTANTS @@ -71,4 +70,4 @@ extern const mod_network_nic_type_t mod_network_nic_type_wlan; ******************************************************************************/ void mod_network_init0(void); -#endif // MODNETWORK_H_ +#endif // MICROPY_INCLUDED_CC3200_MODS_MODNETWORK_H diff --git a/cc3200/mods/modubinascii.c b/cc3200/mods/modubinascii.c index 09f4b1e10..8bc2feacc 100644 --- a/cc3200/mods/modubinascii.c +++ b/cc3200/mods/modubinascii.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -44,7 +44,7 @@ /******************************************************************************/ -// Micro Python bindings +// MicroPython bindings STATIC const mp_map_elem_t mp_module_binascii_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_ubinascii) }, diff --git a/cc3200/mods/modubinascii.h b/cc3200/mods/modubinascii.h index c04b70021..eb9fc4f21 100644 --- a/cc3200/mods/modubinascii.h +++ b/cc3200/mods/modubinascii.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_CC3200_MODS_MODUBINASCII_H +#define MICROPY_INCLUDED_CC3200_MODS_MODUBINASCII_H -#ifndef MODUBINASCII_H_ -#define MODUBINASCII_H_ - -#endif /* MODUBINASCII_H_ */ +#endif // MICROPY_INCLUDED_CC3200_MODS_MODUBINASCII_H diff --git a/cc3200/mods/moduhashlib.c b/cc3200/mods/moduhashlib.c index e1145e4d8..c90c727c2 100644 --- a/cc3200/mods/moduhashlib.c +++ b/cc3200/mods/moduhashlib.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -117,7 +117,7 @@ STATIC mp_obj_t hash_read (mp_obj_t self_in) { } /******************************************************************************/ -// Micro Python bindings +// MicroPython bindings /// \classmethod \constructor([data[, block_size]]) /// initial data must be given if block_size wants to be passed diff --git a/cc3200/mods/moduos.c b/cc3200/mods/moduos.c index ed8879bf3..51dc5834d 100644 --- a/cc3200/mods/moduos.c +++ b/cc3200/mods/moduos.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -78,7 +78,7 @@ void osmount_unmount_all (void) { } /******************************************************************************/ -// Micro Python bindings +// MicroPython bindings // STATIC const qstr os_uname_info_fields[] = { diff --git a/cc3200/mods/moduos.h b/cc3200/mods/moduos.h index 4c8bc9659..f183715c9 100644 --- a/cc3200/mods/moduos.h +++ b/cc3200/mods/moduos.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,9 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef MODUOS_H_ -#define MODUOS_H_ +#ifndef MICROPY_INCLUDED_CC3200_MODS_MODUOS_H +#define MICROPY_INCLUDED_CC3200_MODS_MODUOS_H #include "py/obj.h" @@ -45,4 +44,4 @@ typedef struct _os_term_dup_obj_t { ******************************************************************************/ void osmount_unmount_all (void); -#endif // MODUOS_H_ +#endif // MICROPY_INCLUDED_CC3200_MODS_MODUOS_H diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c index 4e17bbae6..739355360 100644 --- a/cc3200/mods/modusocket.c +++ b/cc3200/mods/modusocket.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/mods/modusocket.h b/cc3200/mods/modusocket.h index 851f8e5be..6e7758662 100644 --- a/cc3200/mods/modusocket.h +++ b/cc3200/mods/modusocket.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef MODUSOCKET_H_ -#define MODUSOCKET_H_ +#ifndef MICROPY_INCLUDED_CC3200_MODS_MODUSOCKET_H +#define MICROPY_INCLUDED_CC3200_MODS_MODUSOCKET_H extern const mp_obj_dict_t socket_locals_dict; extern const mp_stream_p_t socket_stream_p; @@ -36,4 +35,4 @@ extern void modusocket_socket_delete (int16_t sd); extern void modusocket_enter_sleep (void); extern void modusocket_close_all_user_sockets (void); -#endif /* MODUSOCKET_H_ */ +#endif // MICROPY_INCLUDED_CC3200_MODS_MODUSOCKET_H diff --git a/cc3200/mods/modussl.c b/cc3200/mods/modussl.c index 95ecdbce7..808267571 100644 --- a/cc3200/mods/modussl.c +++ b/cc3200/mods/modussl.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -57,7 +57,7 @@ typedef struct _mp_obj_ssl_socket_t { STATIC const mp_obj_type_t ssl_socket_type; /******************************************************************************/ -// Micro Python bindings; SSL class +// MicroPython bindings; SSL class // ssl sockets inherit from normal socket, so we take its // locals and stream methods diff --git a/cc3200/mods/modutime.c b/cc3200/mods/modutime.c index 48fde67e7..428b00f93 100644 --- a/cc3200/mods/modutime.c +++ b/cc3200/mods/modutime.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -51,7 +51,7 @@ /// and for sleeping. /******************************************************************************/ -// Micro Python bindings +// MicroPython bindings /// \function localtime([secs]) /// Convert a time expressed in seconds since Jan 1, 2000 into an 8-tuple which diff --git a/cc3200/mods/modwipy.c b/cc3200/mods/modwipy.c index b4c18d153..21a9cc63b 100644 --- a/cc3200/mods/modwipy.c +++ b/cc3200/mods/modwipy.c @@ -5,7 +5,7 @@ /******************************************************************************/ -// Micro Python bindings +// MicroPython bindings STATIC mp_obj_t mod_wipy_heartbeat (mp_uint_t n_args, const mp_obj_t *args) { if (n_args) { diff --git a/cc3200/mods/modwlan.c b/cc3200/mods/modwlan.c index 68d892364..77f5bd991 100644 --- a/cc3200/mods/modwlan.c +++ b/cc3200/mods/modwlan.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -763,7 +763,7 @@ STATIC bool wlan_scan_result_is_unique (const mp_obj_list_t *nets, _u8 *bssid) { } /******************************************************************************/ -// Micro Python bindings; WLAN class +// MicroPython bindings; WLAN class /// \class WLAN - WiFi driver diff --git a/cc3200/mods/modwlan.h b/cc3200/mods/modwlan.h index 3bfd1fbbf..b806644f5 100644 --- a/cc3200/mods/modwlan.h +++ b/cc3200/mods/modwlan.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef MODWLAN_H_ -#define MODWLAN_H_ +#ifndef MICROPY_INCLUDED_CC3200_MODS_MODWLAN_H +#define MICROPY_INCLUDED_CC3200_MODS_MODWLAN_H /****************************************************************************** DEFINE CONSTANTS @@ -97,4 +96,4 @@ extern bool wlan_is_connected (void); extern void wlan_set_current_time (uint32_t seconds_since_2000); extern void wlan_off_on (void); -#endif /* MODWLAN_H_ */ +#endif // MICROPY_INCLUDED_CC3200_MODS_MODWLAN_H diff --git a/cc3200/mods/pybadc.c b/cc3200/mods/pybadc.c index 696e7650b..0b4f0ba68 100644 --- a/cc3200/mods/pybadc.c +++ b/cc3200/mods/pybadc.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -126,7 +126,7 @@ STATIC void pyb_adc_deinit_all_channels (void) { } /******************************************************************************/ -/* Micro Python bindings : adc object */ +/* MicroPython bindings : adc object */ STATIC void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_adc_obj_t *self = self_in; diff --git a/cc3200/mods/pybadc.h b/cc3200/mods/pybadc.h index b77c4af42..db04b006b 100644 --- a/cc3200/mods/pybadc.h +++ b/cc3200/mods/pybadc.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,10 +24,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef PYBADC_H_ -#define PYBADC_H_ +#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBADC_H +#define MICROPY_INCLUDED_CC3200_MODS_PYBADC_H extern const mp_obj_type_t pyb_adc_type; -#endif /* PYBADC_H_ */ +#endif // MICROPY_INCLUDED_CC3200_MODS_PYBADC_H diff --git a/cc3200/mods/pybi2c.c b/cc3200/mods/pybi2c.c index 9fc97d914..9c62ffdc4 100644 --- a/cc3200/mods/pybi2c.c +++ b/cc3200/mods/pybi2c.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -281,7 +281,7 @@ STATIC void pyb_i2c_readmem_into (mp_arg_val_t *args, vstr_t *vstr) { } /******************************************************************************/ -/* Micro Python bindings */ +/* MicroPython bindings */ /******************************************************************************/ STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_i2c_obj_t *self = self_in; diff --git a/cc3200/mods/pybi2c.h b/cc3200/mods/pybi2c.h index 7adffb2d9..dcc3f0468 100644 --- a/cc3200/mods/pybi2c.h +++ b/cc3200/mods/pybi2c.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,10 +24,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef PYBI2C_H_ -#define PYBI2C_H_ +#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBI2C_H +#define MICROPY_INCLUDED_CC3200_MODS_PYBI2C_H extern const mp_obj_type_t pyb_i2c_type; -#endif // PYBI2C_H_ +#endif // MICROPY_INCLUDED_CC3200_MODS_PYBI2C_H diff --git a/cc3200/mods/pybpin.c b/cc3200/mods/pybpin.c index c2a469117..d59f113eb 100644 --- a/cc3200/mods/pybpin.c +++ b/cc3200/mods/pybpin.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -519,7 +519,7 @@ STATIC void EXTI_Handler(uint port) { /******************************************************************************/ -// Micro Python bindings +// MicroPython bindings STATIC const mp_arg_t pin_init_args[] = { { MP_QSTR_mode, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, diff --git a/cc3200/mods/pybpin.h b/cc3200/mods/pybpin.h index ad02cc777..74f0af2b3 100644 --- a/cc3200/mods/pybpin.h +++ b/cc3200/mods/pybpin.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,9 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef PYBPIN_H_ -#define PYBPIN_H_ +#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBPIN_H +#define MICROPY_INCLUDED_CC3200_MODS_PYBPIN_H enum { PORT_A0 = GPIOA0_BASE, @@ -138,4 +137,4 @@ uint8_t pin_find_peripheral_unit (const mp_obj_t pin, uint8_t fn, uint8_t type); uint8_t pin_find_peripheral_type (const mp_obj_t pin, uint8_t fn, uint8_t unit); int8_t pin_find_af_index (const pin_obj_t* pin, uint8_t fn, uint8_t unit, uint8_t type);; -#endif // PYBPIN_H_ +#endif // MICROPY_INCLUDED_CC3200_MODS_PYBPIN_H diff --git a/cc3200/mods/pybrtc.c b/cc3200/mods/pybrtc.c index 134bd440e..14c4cd419 100644 --- a/cc3200/mods/pybrtc.c +++ b/cc3200/mods/pybrtc.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -278,7 +278,7 @@ STATIC void rtc_msec_add (uint16_t msecs_1, uint32_t *secs, uint16_t *msecs_2) { } /******************************************************************************/ -// Micro Python bindings +// MicroPython bindings STATIC const mp_arg_t pyb_rtc_init_args[] = { { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} }, diff --git a/cc3200/mods/pybrtc.h b/cc3200/mods/pybrtc.h index 5111b78f7..f73de3f5a 100644 --- a/cc3200/mods/pybrtc.h +++ b/cc3200/mods/pybrtc.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,9 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef PYBRTC_H_ -#define PYBRTC_H_ +#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBRTC_H +#define MICROPY_INCLUDED_CC3200_MODS_PYBRTC_H // RTC triggers #define PYB_RTC_ALARM0 (0x01) @@ -56,4 +55,4 @@ extern void pyb_rtc_calc_future_time (uint32_t a_mseconds, uint32_t *f_seconds, extern void pyb_rtc_repeat_alarm (pyb_rtc_obj_t *self); extern void pyb_rtc_disable_alarm (void); -#endif // PYBRTC_H_ +#endif // MICROPY_INCLUDED_CC3200_MODS_PYBRTC_H diff --git a/cc3200/mods/pybsd.c b/cc3200/mods/pybsd.c index 306baea8b..5ba6119b2 100644 --- a/cc3200/mods/pybsd.c +++ b/cc3200/mods/pybsd.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -118,7 +118,7 @@ STATIC mp_obj_t pyb_sd_init_helper (pybsd_obj_t *self, const mp_arg_val_t *args) } /******************************************************************************/ -// Micro Python bindings +// MicroPython bindings // STATIC const mp_arg_t pyb_sd_init_args[] = { diff --git a/cc3200/mods/pybsd.h b/cc3200/mods/pybsd.h index a06df6d8d..af942084d 100644 --- a/cc3200/mods/pybsd.h +++ b/cc3200/mods/pybsd.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef PYBSD_H_ -#define PYBSD_H_ +#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBSD_H +#define MICROPY_INCLUDED_CC3200_MODS_PYBSD_H /****************************************************************************** DEFINE PUBLIC TYPES @@ -41,4 +41,4 @@ typedef struct { extern pybsd_obj_t pybsd_obj; extern const mp_obj_type_t pyb_sd_type; -#endif // PYBSD_H_ +#endif // MICROPY_INCLUDED_CC3200_MODS_PYBSD_H diff --git a/cc3200/mods/pybsleep.c b/cc3200/mods/pybsleep.c index ced7fef85..a7488c5f1 100644 --- a/cc3200/mods/pybsleep.c +++ b/cc3200/mods/pybsleep.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/mods/pybsleep.h b/cc3200/mods/pybsleep.h index d34895ae0..e98636178 100644 --- a/cc3200/mods/pybsleep.h +++ b/cc3200/mods/pybsleep.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef PYBSLEEP_H_ -#define PYBSLEEP_H_ +#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBSLEEP_H +#define MICROPY_INCLUDED_CC3200_MODS_PYBSLEEP_H /****************************************************************************** DEFINE CONSTANTS @@ -70,4 +69,4 @@ void pyb_sleep_deepsleep (void); pybsleep_reset_cause_t pyb_sleep_get_reset_cause (void); pybsleep_wake_reason_t pyb_sleep_get_wake_reason (void); -#endif /* PYBSLEEP_H_ */ +#endif // MICROPY_INCLUDED_CC3200_MODS_PYBSLEEP_H diff --git a/cc3200/mods/pybspi.c b/cc3200/mods/pybspi.c index 3cd384266..9edad579a 100644 --- a/cc3200/mods/pybspi.c +++ b/cc3200/mods/pybspi.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -144,7 +144,7 @@ STATIC void pybspi_transfer (pyb_spi_obj_t *self, const char *txdata, char *rxda } /******************************************************************************/ -/* Micro Python bindings */ +/* MicroPython bindings */ /******************************************************************************/ STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_spi_obj_t *self = self_in; diff --git a/cc3200/mods/pybspi.h b/cc3200/mods/pybspi.h index 48e0edd61..b0fce8870 100644 --- a/cc3200/mods/pybspi.h +++ b/cc3200/mods/pybspi.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,10 +24,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef PYBSPI_H_ -#define PYBSPI_H_ +#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBSPI_H +#define MICROPY_INCLUDED_CC3200_MODS_PYBSPI_H extern const mp_obj_type_t pyb_spi_type; -#endif // PYBSPI_H_ +#endif // MICROPY_INCLUDED_CC3200_MODS_PYBSPI_H diff --git a/cc3200/mods/pybtimer.c b/cc3200/mods/pybtimer.c index d25ac6c2b..1ef9a4a44 100644 --- a/cc3200/mods/pybtimer.c +++ b/cc3200/mods/pybtimer.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -264,7 +264,7 @@ STATIC void timer_channel_init (pyb_timer_channel_obj_t *ch) { } /******************************************************************************/ -/* Micro Python bindings */ +/* MicroPython bindings */ STATIC void pyb_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_timer_obj_t *tim = self_in; diff --git a/cc3200/mods/pybtimer.h b/cc3200/mods/pybtimer.h index 4e9de138d..0af0864ca 100644 --- a/cc3200/mods/pybtimer.h +++ b/cc3200/mods/pybtimer.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,6 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBTIMER_H +#define MICROPY_INCLUDED_CC3200_MODS_PYBTIMER_H /****************************************************************************** DECLARE EXPORTED DATA @@ -35,3 +37,4 @@ extern const mp_obj_type_t pyb_timer_type; ******************************************************************************/ void timer_init0 (void); +#endif // MICROPY_INCLUDED_CC3200_MODS_PYBTIMER_H diff --git a/cc3200/mods/pybuart.c b/cc3200/mods/pybuart.c index 92bb3e46e..626357179 100644 --- a/cc3200/mods/pybuart.c +++ b/cc3200/mods/pybuart.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -27,7 +27,6 @@ #include #include -#include #include #include "py/mpconfig.h" @@ -312,7 +311,7 @@ STATIC int uart_irq_flags (mp_obj_t self_in) { } /******************************************************************************/ -/* Micro Python bindings */ +/* MicroPython bindings */ STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_uart_obj_t *self = self_in; diff --git a/cc3200/mods/pybuart.h b/cc3200/mods/pybuart.h index 19bc93607..d481242f1 100644 --- a/cc3200/mods/pybuart.h +++ b/cc3200/mods/pybuart.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,9 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef PYBUART_H_ -#define PYBUART_H_ +#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBUART_H +#define MICROPY_INCLUDED_CC3200_MODS_PYBUART_H typedef enum { PYB_UART_0 = 0, @@ -43,4 +42,4 @@ int uart_rx_char(pyb_uart_obj_t *uart_obj); bool uart_tx_char(pyb_uart_obj_t *self, int c); bool uart_tx_strn(pyb_uart_obj_t *uart_obj, const char *str, uint len); -#endif // PYBUART_H_ +#endif // MICROPY_INCLUDED_CC3200_MODS_PYBUART_H diff --git a/cc3200/mods/pybwdt.c b/cc3200/mods/pybwdt.c index 76c701ca0..114e7ac96 100644 --- a/cc3200/mods/pybwdt.c +++ b/cc3200/mods/pybwdt.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -87,7 +87,7 @@ void pybwdt_sl_alive (void) { } /******************************************************************************/ -// Micro Python bindings +// MicroPython bindings STATIC const mp_arg_t pyb_wdt_init_args[] = { { MP_QSTR_id, MP_ARG_OBJ, {.u_obj = mp_const_none} }, diff --git a/cc3200/mods/pybwdt.h b/cc3200/mods/pybwdt.h index f87f0a773..275c49435 100644 --- a/cc3200/mods/pybwdt.h +++ b/cc3200/mods/pybwdt.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef PYBWDT_H_ -#define PYBWDT_H_ +#ifndef MICROPY_INCLUDED_CC3200_MODS_PYBWDT_H +#define MICROPY_INCLUDED_CC3200_MODS_PYBWDT_H #include "py/obj.h" @@ -36,4 +35,4 @@ void pybwdt_srv_alive (void); void pybwdt_srv_sleeping (bool state); void pybwdt_sl_alive (void); -#endif /* PYBWDT_H_ */ +#endif // MICROPY_INCLUDED_CC3200_MODS_PYBWDT_H diff --git a/cc3200/mpconfigport.h b/cc3200/mpconfigport.h index 4bd583a4b..dcde9aae0 100644 --- a/cc3200/mpconfigport.h +++ b/cc3200/mpconfigport.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -25,9 +25,6 @@ * THE SOFTWARE. */ -#ifndef __INCLUDED_MPCONFIGPORT_H -#define __INCLUDED_MPCONFIGPORT_H - #include #ifndef BOOTLOADER @@ -35,7 +32,7 @@ #include "semphr.h" #endif -// options to control how Micro Python is built +// options to control how MicroPython is built #define MICROPY_ALLOC_PATH_MAX (128) #define MICROPY_PERSISTENT_CODE_LOAD (1) @@ -235,5 +232,3 @@ typedef long mp_off_t; #define MICROPY_PORT_WLAN_AP_KEY "www.wipy.io" #define MICROPY_PORT_WLAN_AP_SECURITY SL_SEC_TYPE_WPA_WPA2 #define MICROPY_PORT_WLAN_AP_CHANNEL 5 - -#endif // __INCLUDED_MPCONFIGPORT_H diff --git a/cc3200/mptask.c b/cc3200/mptask.c index d446711a2..09be8c441 100644 --- a/cc3200/mptask.c +++ b/cc3200/mptask.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -112,7 +112,7 @@ static const char fresh_boot_py[] = "# boot.py -- run on boot-up\r\n" DECLARE PUBLIC FUNCTIONS ******************************************************************************/ -void TASK_Micropython (void *pvParameters) { +void TASK_MicroPython (void *pvParameters) { // get the top of the stack to initialize the garbage collector uint32_t sp = gc_helper_get_sp(); diff --git a/cc3200/mptask.h b/cc3200/mptask.h index e0d2f0eec..a1c3eb2cb 100644 --- a/cc3200/mptask.h +++ b/cc3200/mptask.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef MPTASK_H_ -#define MPTASK_H_ +#ifndef MICROPY_INCLUDED_CC3200_MPTASK_H +#define MICROPY_INCLUDED_CC3200_MPTASK_H /****************************************************************************** DEFINE CONSTANTS @@ -42,6 +41,6 @@ extern StackType_t mpTaskStack[]; /****************************************************************************** DECLARE PUBLIC FUNCTIONS ******************************************************************************/ -extern void TASK_Micropython (void *pvParameters); +extern void TASK_MicroPython (void *pvParameters); -#endif /* MPTASK_H_ */ +#endif // MICROPY_INCLUDED_CC3200_MPTASK_H diff --git a/cc3200/mpthreadport.h b/cc3200/mpthreadport.h index 2b49232dd..dc9ba9920 100644 --- a/cc3200/mpthreadport.h +++ b/cc3200/mpthreadport.h @@ -23,8 +23,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_CC3200_MPTHREADPORT_H__ -#define __MICROPY_INCLUDED_CC3200_MPTHREADPORT_H__ #ifndef BOOTLOADER #include "FreeRTOS.h" @@ -39,5 +37,3 @@ typedef struct _mp_thread_mutex_t { void mp_thread_init(void); void mp_thread_gc_others(void); - -#endif // __MICROPY_INCLUDED_CC3200_MPTHREADPORT_H__ diff --git a/cc3200/qstrdefsport.h b/cc3200/qstrdefsport.h index 2fc56668c..d5f22d70a 100644 --- a/cc3200/qstrdefsport.h +++ b/cc3200/qstrdefsport.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/serverstask.c b/cc3200/serverstask.c index 6b5899e18..100b8d33b 100644 --- a/cc3200/serverstask.c +++ b/cc3200/serverstask.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/serverstask.h b/cc3200/serverstask.h index 2786ff697..c4533d717 100644 --- a/cc3200/serverstask.h +++ b/cc3200/serverstask.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef SERVERSTASK_H_ -#define SERVERSTASK_H_ +#ifndef MICROPY_INCLUDED_CC3200_SERVERSTASK_H +#define MICROPY_INCLUDED_CC3200_SERVERSTASK_H /****************************************************************************** DEFINE CONSTANTS @@ -73,4 +72,4 @@ extern void server_sleep_sockets (void); extern void servers_set_timeout (uint32_t timeout); extern uint32_t servers_get_timeout (void); -#endif /* SERVERSTASK_H_ */ +#endif // MICROPY_INCLUDED_CC3200_SERVERSTASK_H diff --git a/cc3200/telnet/telnet.c b/cc3200/telnet/telnet.c index 26e45a75f..2f0818f6b 100644 --- a/cc3200/telnet/telnet.c +++ b/cc3200/telnet/telnet.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/telnet/telnet.h b/cc3200/telnet/telnet.h index aa5531394..51c569104 100644 --- a/cc3200/telnet/telnet.h +++ b/cc3200/telnet/telnet.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef TELNET_H_ -#define TELNET_H_ +#ifndef MICROPY_INCLUDED_CC3200_TELNET_TELNET_H +#define MICROPY_INCLUDED_CC3200_TELNET_TELNET_H /****************************************************************************** DECLARE EXPORTED FUNCTIONS @@ -39,4 +38,4 @@ extern void telnet_enable (void); extern void telnet_disable (void); extern void telnet_reset (void); -#endif /* TELNET_H_ */ +#endif // MICROPY_INCLUDED_CC3200_TELNET_TELNET_H diff --git a/cc3200/util/cryptohash.c b/cc3200/util/cryptohash.c index d2d6222ff..909dadc8c 100644 --- a/cc3200/util/cryptohash.c +++ b/cc3200/util/cryptohash.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/util/cryptohash.h b/cc3200/util/cryptohash.h index d9f624d19..15d46b705 100644 --- a/cc3200/util/cryptohash.h +++ b/cc3200/util/cryptohash.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef CRYPTOHASH_H_ -#define CRYPTOHASH_H_ +#ifndef MICROPY_INCLUDED_CC3200_UTIL_CRYPTOHASH_H +#define MICROPY_INCLUDED_CC3200_UTIL_CRYPTOHASH_H /****************************************************************************** DECLARE PUBLIC FUNCTIONS @@ -35,4 +34,4 @@ extern void CRYPTOHASH_SHAMD5Start (uint32_t algo, uint32_t blocklen); extern void CRYPTOHASH_SHAMD5Update (uint8_t *data, uint32_t datalen); extern void CRYPTOHASH_SHAMD5Read (uint8_t *hash); -#endif /* CRYPTOHASH_H_ */ +#endif // MICROPY_INCLUDED_CC3200_UTIL_CRYPTOHASH_H diff --git a/cc3200/util/fifo.c b/cc3200/util/fifo.c index 166f99d98..421f83710 100644 --- a/cc3200/util/fifo.c +++ b/cc3200/util/fifo.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/util/fifo.h b/cc3200/util/fifo.h index c8590f5c2..6ede57e1e 100644 --- a/cc3200/util/fifo.h +++ b/cc3200/util/fifo.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef FIFO_H_ -#define FIFO_H_ +#ifndef MICROPY_INCLUDED_CC3200_UTIL_FIFO_H +#define MICROPY_INCLUDED_CC3200_UTIL_FIFO_H typedef struct { void *pvElements; @@ -47,4 +46,4 @@ extern bool FIFO_IsEmpty (FIFO_t *fifo); extern bool FIFO_IsFull (FIFO_t *fifo); extern void FIFO_Flush (FIFO_t *fifo); -#endif /* FIFO_H_ */ +#endif // MICROPY_INCLUDED_CC3200_UTIL_FIFO_H diff --git a/cc3200/util/gccollect.c b/cc3200/util/gccollect.c index 8963852f7..baee2eeef 100644 --- a/cc3200/util/gccollect.c +++ b/cc3200/util/gccollect.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/util/gccollect.h b/cc3200/util/gccollect.h index 281e84aa8..08d43d283 100644 --- a/cc3200/util/gccollect.h +++ b/cc3200/util/gccollect.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,6 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_CC3200_UTIL_GCCOLLECT_H +#define MICROPY_INCLUDED_CC3200_UTIL_GCCOLLECT_H // variables defining memory layout extern uint32_t _etext; @@ -39,3 +41,5 @@ extern uint32_t _stack; extern uint32_t _estack; void gc_collect(void); + +#endif // MICROPY_INCLUDED_CC3200_UTIL_GCCOLLECT_H diff --git a/cc3200/util/gchelper.h b/cc3200/util/gchelper.h index 1f7d2fece..48e81bc61 100644 --- a/cc3200/util/gchelper.h +++ b/cc3200/util/gchelper.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,11 +24,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef GC_HELPER_H_ -#define GC_HELPER_H_ +#ifndef MICROPY_INCLUDED_CC3200_UTIL_GCHELPER_H +#define MICROPY_INCLUDED_CC3200_UTIL_GCHELPER_H extern mp_uint_t gc_helper_get_sp(void); extern mp_uint_t gc_helper_get_regs_and_sp(mp_uint_t *regs); -#endif /* GC_HELPER_H_ */ +#endif // MICROPY_INCLUDED_CC3200_UTIL_GCHELPER_H diff --git a/cc3200/util/random.c b/cc3200/util/random.c index 54aaa829c..f8e9cdf0c 100644 --- a/cc3200/util/random.c +++ b/cc3200/util/random.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -67,7 +67,7 @@ STATIC uint32_t lfsr (uint32_t input) { } /******************************************************************************/ -// Micro Python bindings; +// MicroPython bindings; STATIC mp_obj_t machine_rng_get(void) { return mp_obj_new_int(rng_get()); diff --git a/cc3200/util/random.h b/cc3200/util/random.h index 67fd1ff85..02cde6b52 100644 --- a/cc3200/util/random.h +++ b/cc3200/util/random.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,13 +23,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef __RANDOM_H -#define __RANDOM_H +#ifndef MICROPY_INCLUDED_CC3200_UTIL_RANDOM_H +#define MICROPY_INCLUDED_CC3200_UTIL_RANDOM_H void rng_init0 (void); uint32_t rng_get (void); MP_DECLARE_CONST_FUN_OBJ_0(machine_rng_get_obj); -#endif // __RANDOM_H +#endif // MICROPY_INCLUDED_CC3200_UTIL_RANDOM_H diff --git a/cc3200/util/sleeprestore.h b/cc3200/util/sleeprestore.h index 51416f0fc..e178f4c2d 100644 --- a/cc3200/util/sleeprestore.h +++ b/cc3200/util/sleeprestore.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,11 +23,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef SLEEPRESTORE_H_ -#define SLEEPRESTORE_H_ +#ifndef MICROPY_INCLUDED_CC3200_UTIL_SLEEPRESTORE_H +#define MICROPY_INCLUDED_CC3200_UTIL_SLEEPRESTORE_H extern void sleep_store(void); extern void sleep_restore(void); -#endif /* SLEEPRESTORE_H_ */ +#endif // MICROPY_INCLUDED_CC3200_UTIL_SLEEPRESTORE_H diff --git a/cc3200/util/socketfifo.c b/cc3200/util/socketfifo.c index eb25f3be3..d0a715048 100644 --- a/cc3200/util/socketfifo.c +++ b/cc3200/util/socketfifo.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/cc3200/util/socketfifo.h b/cc3200/util/socketfifo.h index 69b17658f..e6cf851b1 100644 --- a/cc3200/util/socketfifo.h +++ b/cc3200/util/socketfifo.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef SOCKETFIFO_H_ -#define SOCKETFIFO_H_ +#ifndef MICROPY_INCLUDED_CC3200_UTIL_SOCKETFIFO_H +#define MICROPY_INCLUDED_CC3200_UTIL_SOCKETFIFO_H /*---------------------------------------------------------------------------- ** Imports @@ -60,4 +59,4 @@ extern bool SOCKETFIFO_IsFull (void); extern void SOCKETFIFO_Flush (void); extern unsigned int SOCKETFIFO_Count (void); -#endif /* SOCKETFIFO_H_ */ +#endif // MICROPY_INCLUDED_CC3200_UTIL_SOCKETFIFO_H diff --git a/cc3200/version.h b/cc3200/version.h index c8315d771..fccb95c52 100644 --- a/cc3200/version.h +++ b/cc3200/version.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,10 +23,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef VERSION_H_ -#define VERSION_H_ +#ifndef MICROPY_INCLUDED_CC3200_VERSION_H +#define MICROPY_INCLUDED_CC3200_VERSION_H #define WIPY_SW_VERSION_NUMBER "1.2.0" -#endif /* VERSION_H_ */ +#endif // MICROPY_INCLUDED_CC3200_VERSION_H diff --git a/docs/esp8266/general.rst b/docs/esp8266/general.rst index 6d186fcd2..e23acb469 100644 --- a/docs/esp8266/general.rst +++ b/docs/esp8266/general.rst @@ -122,3 +122,26 @@ Due to limitations of the ESP8266 chip the internal real-time clock (RTC) will overflow every 7:45h. If a long-term working RTC time is required then ``time()`` or ``localtime()`` must be called at least once within 7 hours. MicroPython will then handle the overflow. + +Sockets and WiFi buffers overflow +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Socket instances remain active until they are explicitly closed. This has two +consequences. Firstly they occupy RAM, so an application which opens sockets +without closing them may eventually run out of memory. Secondly not properly +closed socket can cause the low-level part of the vendor WiFi stack to emit +``Lmac`` errors. This occurs if data comes in for a socket and is not +processed in a timely manner. This can overflow the WiFi stack input queue +and lead to a deadlock. The only recovery is by a hard reset. + +The above may also happen after an application terminates and quits to the REPL +for any reason including an exception. Subsequent arrival of data provokes the +failure with the above error message repeatedly issued. So, sockets should be +closed in any case, regardless whether an application terminates successfully +or by an exeption, for example using try/finally:: + + sock = socket(...) + try: + # Use sock + finally: + sock.close() diff --git a/docs/esp8266/tutorial/powerctrl.rst b/docs/esp8266/tutorial/powerctrl.rst index 9e44339c8..3502624ab 100644 --- a/docs/esp8266/tutorial/powerctrl.rst +++ b/docs/esp8266/tutorial/powerctrl.rst @@ -22,7 +22,7 @@ processing power, at the expense of current consumption:: 160000000 You can change to the higher frequency just while your code does the heavy -processing and then change back when its finished. +processing and then change back when it's finished. Deep-sleep mode --------------- diff --git a/docs/library/machine.RTC.rst b/docs/library/machine.RTC.rst index 2a53b9146..95fa2b4ce 100644 --- a/docs/library/machine.RTC.rst +++ b/docs/library/machine.RTC.rst @@ -38,7 +38,7 @@ Methods Resets the RTC to the time of January 1, 2015 and starts running it again. -.. method:: RTC.alarm(id, time, /*, repeat=False) +.. method:: RTC.alarm(id, time, \*, repeat=False) Set the RTC alarm. Time might be either a millisecond value to program the alarm to current time + time_in_ms in the future, or a datetimetuple. If the time passed is in diff --git a/docs/library/pyb.rst b/docs/library/pyb.rst index a8fef9309..799160145 100644 --- a/docs/library/pyb.rst +++ b/docs/library/pyb.rst @@ -21,7 +21,7 @@ Time related functions Returns the number of milliseconds since the board was last reset. - The result is always a micropython smallint (31-bit signed number), so + The result is always a MicroPython smallint (31-bit signed number), so after 2^30 milliseconds (about 12.4 days) this will start to return negative numbers. @@ -33,7 +33,7 @@ Time related functions Returns the number of microseconds since the board was last reset. - The result is always a micropython smallint (31-bit signed number), so + The result is always a MicroPython smallint (31-bit signed number), so after 2^30 microseconds (about 17.8 minutes) this will start to return negative numbers. diff --git a/docs/library/ubinascii.rst b/docs/library/ubinascii.rst index 0664d5b09..192d34514 100644 --- a/docs/library/ubinascii.rst +++ b/docs/library/ubinascii.rst @@ -29,8 +29,12 @@ Functions .. function:: a2b_base64(data) - Convert Base64-encoded data to binary representation. Returns bytes string. + Decode base64-encoded data, ignoring invalid characters in the input. + Conforms to `RFC 2045 s.6.8 `_. + Returns a bytes object. .. function:: b2a_base64(data) - Encode binary data in Base64 format. Returns string. + Encode binary data in base64 format, as in `RFC 3548 + `_. Returns the encoded data + followed by a newline character, as a bytes object. diff --git a/docs/library/usocket.rst b/docs/library/usocket.rst index 70d4f49fc..65e24e266 100644 --- a/docs/library/usocket.rst +++ b/docs/library/usocket.rst @@ -9,12 +9,6 @@ This module provides access to the BSD socket interface. -.. admonition:: Difference to CPython - :class: attention - - CPython used to have a ``socket.error`` exception which is now deprecated, - and is an alias of `OSError`. In MicroPython, use `OSError` directly. - .. admonition:: Difference to CPython :class: attention @@ -27,11 +21,47 @@ This module provides access to the BSD socket interface. Socket address format(s) ------------------------ -The functions below which expect a network address, accept it in the format of -*(ipv4_address, port)*, where *ipv4_address* is a string with dot-notation numeric -IPv4 address, e.g. ``"8.8.8.8"``, and port is integer port number in the range -1-65535. Note the domain names are not accepted as *ipv4_address*, they should be -resolved first using `usocket.getaddrinfo()`. +The native socket address format of the ``usocket`` module is an opaque data type +returned by `getaddrinfo` function, which must be used to resolve textual address +(including numeric addresses):: + + sockaddr = usocket.getaddrinfo('www.micropython.org', 80)[0][-1] + # You must use getaddrinfo() even for numeric addresses + sockaddr = usocket.getaddrinfo('127.0.0.1', 80)[0][-1] + # Now you can use that address + sock.connect(addr) + +Using `getaddrinfo` is the most efficient (both in terms of memory and processing +power) and portable way to work with addresses. + +However, ``socket`` module (note the difference with native MicroPython +``usocket`` module described here) provides CPython-compatible way to specify +addresses using tuples, as described below. Note that depending on a +`MicroPython port`, ``socket`` module can be builtin or need to be +installed from `micropython-lib` (as in the case of `MicroPython Unix port`), +and some ports still accept only numeric addresses in the tuple format, +and require to use `getaddrinfo` function to resolve domain names. + +Summing up: + +* Always use `getaddrinfo` when writing portable applications. +* Tuple addresses described below can be used as a shortcut for + quick hacks and interactive use, if your port supports them. + +Tuple address format for ``socket`` module: + +* IPv4: *(ipv4_address, port)*, where *ipv4_address* is a string with + dot-notation numeric IPv4 address, e.g. ``"8.8.8.8"``, and *port* is and + integer port number in the range 1-65535. Note the domain names are not + accepted as *ipv4_address*, they should be resolved first using + `usocket.getaddrinfo()`. +* IPv6: *(ipv6_address, port, flowinfo, scopeid)*, where *ipv6_address* + is a string with colon-notation numeric IPv6 address, e.g. ``"2001:db8::1"``, + and *port* is an integer port number in the range 1-65535. *flowinfo* + must be 0. *scopeid* is the interface scope identifier for link-local + addresses. Note the domain names are not accepted as *ipv6_address*, + they should be resolved first using `usocket.getaddrinfo()`. Availability + of IPv6 support depends on a `MicroPython port`. Functions --------- @@ -250,3 +280,13 @@ Methods the length of *buf*. Return value: number of bytes written. + +.. exception:: socket.error + + MicroPython does NOT have this exception. + + .. admonition:: Difference to CPython + :class: attention + + CPython used to have a ``socket.error`` exception which is now deprecated, + and is an alias of `OSError`. In MicroPython, use `OSError` directly. diff --git a/docs/pyboard/tutorial/amp_skin.rst b/docs/pyboard/tutorial/amp_skin.rst index 64f139bb7..697637f9d 100644 --- a/docs/pyboard/tutorial/amp_skin.rst +++ b/docs/pyboard/tutorial/amp_skin.rst @@ -69,4 +69,30 @@ Then you can do:: >>> f = wave.open('test.wav') >>> dac.write_timed(f.readframes(f.getnframes()), f.getframerate()) -This should play the WAV file. +This should play the WAV file. Note that this will read the whole file into RAM +so it has to be small enough to fit in it. + +To play larger wave files you will have to use the micro-SD card to store it. +Also the file must be read and sent to the DAC in small chunks that will fit +the RAM limit of the microcontroller. Here is an example function that can +play 8-bit wave files with up to 16kHz sampling:: + + import wave + from pyb import DAC + from pyb import delay + dac = DAC(1) + + def play(filename): + f = wave.open(filename, 'r') + total_frames = f.getnframes() + framerate = f.getframerate() + + for position in range(0, total_frames, framerate): + f.setpos(position) + dac.write_timed(f.readframes(framerate), framerate) + delay(1000) + +This function reads one second worth of data and sends it to DAC. It then waits +one second and moves the file cursor to the new position to read the next second +of data in the next iteration of the for-loop. It plays one second of audio at +a time every one second. diff --git a/docs/reference/glossary.rst b/docs/reference/glossary.rst index 4099ae951..98979afa9 100644 --- a/docs/reference/glossary.rst +++ b/docs/reference/glossary.rst @@ -54,10 +54,10 @@ Glossary separate project `micropython-lib `_ which provides implementations for many modules from CPython's - standard library. However, large subset of these modules required + standard library. However, large subset of these modules require POSIX-like environment (Linux, MacOS, Windows may be partially supported), and thus would work or make sense only with MicroPython - Unix port. Some subset of modules however usable for baremetal ports + Unix port. Some subset of modules is however usable for baremetal ports too. Unlike monolithic :term:`CPython` stdlib, micropython-lib modules @@ -68,7 +68,13 @@ Glossary MicroPython supports different :term:`boards `, RTOSes, and OSes, and can be relatively easily adapted to new systems. MicroPython with support for a particular system is called a - "port" to that system. + "port" to that system. Different ports may have widely different + functionality. This documentation is intended to be a reference + of the generic APIs available across different ports ("MicroPython + core"). Note that some ports may still omit some APIs described + here (e.g. due to resource constraints). Any such differences, + and port-specific extensions beyond MicroPython core functionality, + would be described in the separate port-specific documentation. MicroPython Unix port Unix port is one of the major :term:`MicroPython ports `. diff --git a/drivers/dht/dht.c b/drivers/dht/dht.c index 6bdda44b4..5d92ae39a 100644 --- a/drivers/dht/dht.c +++ b/drivers/dht/dht.c @@ -40,7 +40,7 @@ STATIC mp_obj_t dht_readinto(mp_obj_t pin_in, mp_obj_t buf_in) { mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_WRITE); if (bufinfo.len < 5) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "buffer too small")); + mp_raise_ValueError("buffer too small"); } // issue start command diff --git a/drivers/dht/dht.h b/drivers/dht/dht.h index 20954036d..883e07796 100644 --- a/drivers/dht/dht.h +++ b/drivers/dht/dht.h @@ -1,3 +1,8 @@ +#ifndef MICROPY_INCLUDED_DRIVERS_DHT_DHT_H +#define MICROPY_INCLUDED_DRIVERS_DHT_DHT_H + #include "py/obj.h" MP_DECLARE_CONST_FUN_OBJ_2(dht_readinto_obj); + +#endif // MICROPY_INCLUDED_DRIVERS_DHT_DHT_H diff --git a/drivers/memory/spiflash.h b/drivers/memory/spiflash.h index d2e817450..967352b04 100644 --- a/drivers/memory/spiflash.h +++ b/drivers/memory/spiflash.h @@ -23,7 +23,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - #ifndef MICROPY_INCLUDED_DRIVERS_MEMORY_SPIFLASH_H #define MICROPY_INCLUDED_DRIVERS_MEMORY_SPIFLASH_H diff --git a/drivers/nrf24l01/nrf24l01.py b/drivers/nrf24l01/nrf24l01.py index b45c137c6..7274a7927 100644 --- a/drivers/nrf24l01/nrf24l01.py +++ b/drivers/nrf24l01/nrf24l01.py @@ -1,4 +1,4 @@ -"""NRF24L01 driver for Micro Python +"""NRF24L01 driver for MicroPython """ from micropython import const diff --git a/drivers/sdcard/sdcard.py b/drivers/sdcard/sdcard.py index e749d5376..75a0c501e 100644 --- a/drivers/sdcard/sdcard.py +++ b/drivers/sdcard/sdcard.py @@ -1,5 +1,5 @@ """ -Micro Python driver for SD cards using SPI bus. +MicroPython driver for SD cards using SPI bus. Requires an SPI bus and a CS pin. Provides readblocks and writeblocks methods so the device can be mounted as a filesystem. diff --git a/drivers/wiznet5k/README.md b/drivers/wiznet5k/README.md index 4f907e0b1..88f25a2b8 100644 --- a/drivers/wiznet5k/README.md +++ b/drivers/wiznet5k/README.md @@ -1,6 +1,6 @@ This is the driver for the WIZnet5x00 series of Ethernet controllers. -Adapted for Micro Python. +Adapted for MicroPython. Original source: https://github.com/Wiznet/W5500_EVB/tree/master/ioLibrary Taken on: 30 August 2014 diff --git a/esp32/Makefile b/esp32/Makefile index 8d01d5421..a60f43ad6 100644 --- a/esp32/Makefile +++ b/esp32/Makefile @@ -1,3 +1,13 @@ +ifndef PROJECT_PATH +PROJECT_PATH := $(abspath $(dir $(firstword $(MAKEFILE_LIST)))/../..) +export PROJECT_PATH +endif + +ifndef IDF_PATH +IDF_PATH := $(PROJECT_PATH)/esp-idf +export IDF_PATH +endif + include ../py/mkenv.mk # qstr definitions (must come before including py.mk) @@ -7,7 +17,7 @@ MICROPY_PY_USSL = 0 MICROPY_SSL_AXTLS = 0 MICROPY_FATFS = 0 MICROPY_NATIVEFS = 1 -MICROPY_PY_BTREE = 0 +MICROPY_PY_BTREE = 1 #FROZEN_DIR = scripts FROZEN_MPY_DIR = modules @@ -23,25 +33,9 @@ FLASH_SIZE ?= 16MB CROSS_COMPILE ?= xtensa-esp32-elf- # paths to ESP IDF and its components -ifeq ($(IDF_PATH),) -$(error Please configure the ESPIDF variable) -endif ESPIDF = $(IDF_PATH) ESPCOMP = $(ESPIDF)/components ESPTOOL ?= $(ESPCOMP)/esptool_py/esptool/esptool.py -BADGE = $(IDF_PATH)/.. - -# verify the ESP IDF version -ESPIDF_SUPHASH := 8b274cd5a5d193a82b49aef384c303b105eda700 -ESPIDF_CURHASH := $(shell git -C $(ESPIDF) show -s --pretty=format:'%H') -ifneq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH)) -$(info ** WARNING **) -$(info The git hash of ESP IDF does not match the supported version) -$(info The build may complete and the firmware may work but it is not guaranteed) -$(info ESP IDF path: $(ESPIDF)) -$(info Current git hash: $(ESPIDF_CURHASH)) -$(info Supported git hash: $(ESPIDF_SUPHASH)) -endif # pretty format of ESP IDF version, used internally by the IDF IDF_VER := $(shell git -C $(ESPIDF) describe) @@ -61,65 +55,78 @@ INC += -I../../components/ed25519/include INC += -I../../components/redundancy INC += -I../../components/badge-first-run INC += -I../../components/png +INC += -I../../components/audio_pipeline/include +INC += -I../../components/audio_hal/board +INC += -I../../components/audio_sal/include +INC += -I../../components/audio_stream/include +INC += -I../../components/esp_http_client/include +INC += -I../../components/esp_http_client/lib/include +INC += -I../../components/esp_peripherals/include +INC += -I../../components/esp_peripherals/lib/blufi +INC += -I../../components/tcp_transport/include +INC += -I../../components/esp-adf-libs/esp_codec/include/codec +INC += -I../../components/esp-tls INC += -I../../main INC += -I../../ugfx/src/gdisp/mcufont INC += -I../../ugfx INC += -I../../ugfx/src INC += -I../../ugfx/drivers/gdisp/framebuffer INC += -I$(BUILD) -INC += -I$(ESPCOMP)/bootloader_support/include -INC += -I$(ESPCOMP)/driver/include -INC += -I$(ESPCOMP)/driver/include/driver -INC += -I$(ESPCOMP)/nghttp/port/include -INC += -I$(ESPCOMP)/nghttp/nghttp2/lib/includes -INC += -I$(ESPCOMP)/esp32/include -INC += -I$(ESPCOMP)/soc/esp32/include -INC += -I$(ESPCOMP)/ethernet/include -INC += -I$(ESPCOMP)/expat/include/expat -INC += -I$(ESPCOMP)/expat/port/include -INC += -I$(ESPCOMP)/json/include -INC += -I$(ESPCOMP)/json/port/include -INC += -I$(ESPCOMP)/log/include -INC += -I$(ESPCOMP)/newlib/include -INC += -I$(ESPCOMP)/nvs_flash/include -INC += -I$(ESPCOMP)/freertos/include -INC += -I$(ESPCOMP)/tcpip_adapter/include -INC += -I$(ESPCOMP)/lwip/include/lwip -INC += -I$(ESPCOMP)/lwip/include/lwip/port -INC += -I$(ESPCOMP)/lwip/include/lwip/posix -INC += -I$(ESPCOMP)/mbedtls/include -INC += -I$(ESPCOMP)/mbedtls/port/include -INC += -I$(ESPCOMP)/spi_flash/include -INC += -I$(ESPCOMP)/wear_levelling/include -INC += -I$(ESPCOMP)/wear_levelling/private_include -INC += -I$(ESPCOMP)/vfs/include -INC += -I$(ESPCOMP)/newlib/platform_include -INC += -I$(ESPCOMP)/xtensa-debug-module/include -INC += -I$(ESPCOMP)/wpa_supplicant/include -INC += -I$(ESPCOMP)/wpa_supplicant/port/include -INC += -I$(ESPCOMP)/ethernet/include -INC += -I$(ESPCOMP)/app_trace/include -INC += -I$(ESPCOMP)/freertos/include/freertos -INC += -I$(ESPCOMP)/app_update/include -INC += -I$(ESPCOMP)/bootloader_support/include_priv -INC += -I$(ESPCOMP)/sdmmc/include -INC += -I$(ESPCOMP)/heap/include -INC += -I$(ESPCOMP)/soc/include -INC += -I$(ESPCOMP)/fatfs/src -INC += -I$(ESPCOMP)/vfs/include - -CFLAGS = -std=gnu99 -Os -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -Wall -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H -DESP_PLATFORM $(INC) +INC_ESPCOMP += -I$(ESPCOMP)/bootloader_support/include +INC_ESPCOMP += -I$(ESPCOMP)/driver/include +INC_ESPCOMP += -I$(ESPCOMP)/driver/include/driver +INC_ESPCOMP += -I$(ESPCOMP)/nghttp/port/include +INC_ESPCOMP += -I$(ESPCOMP)/nghttp/nghttp2/lib/includes +INC_ESPCOMP += -I$(ESPCOMP)/esp32/include +INC_ESPCOMP += -I$(ESPCOMP)/soc/esp32/include +INC_ESPCOMP += -I$(ESPCOMP)/smartconfig_ack/include +INC_ESPCOMP += -I$(ESPCOMP)/ethernet/include +INC_ESPCOMP += -I$(ESPCOMP)/expat/include/expat +INC_ESPCOMP += -I$(ESPCOMP)/expat/port/include +INC_ESPCOMP += -I$(ESPCOMP)/json/include +INC_ESPCOMP += -I$(ESPCOMP)/json/port/include +INC_ESPCOMP += -I$(ESPCOMP)/log/include +INC_ESPCOMP += -I$(ESPCOMP)/newlib/include +INC_ESPCOMP += -I$(ESPCOMP)/nvs_flash/include +INC_ESPCOMP += -I$(ESPCOMP)/freertos/include +INC_ESPCOMP += -I$(ESPCOMP)/tcpip_adapter/include +INC_ESPCOMP += -I$(ESPCOMP)/lwip/include/lwip +INC_ESPCOMP += -I$(ESPCOMP)/lwip/include/lwip/port +INC_ESPCOMP += -I$(ESPCOMP)/lwip/include/lwip/posix +INC_ESPCOMP += -I$(ESPCOMP)/mbedtls/mbedtls/include +INC_ESPCOMP += -I$(ESPCOMP)/mbedtls/port/include +INC_ESPCOMP += -I$(ESPCOMP)/spi_flash/include +INC_ESPCOMP += -I$(ESPCOMP)/wear_levelling/include +INC_ESPCOMP += -I$(ESPCOMP)/wear_levelling/private_include +INC_ESPCOMP += -I$(ESPCOMP)/vfs/include +INC_ESPCOMP += -I$(ESPCOMP)/newlib/platform_include +INC_ESPCOMP += -I$(ESPCOMP)/xtensa-debug-module/include +INC_ESPCOMP += -I$(ESPCOMP)/wpa_supplicant/include +INC_ESPCOMP += -I$(ESPCOMP)/wpa_supplicant/port/include +INC_ESPCOMP += -I$(ESPCOMP)/ethernet/include +INC_ESPCOMP += -I$(ESPCOMP)/app_trace/include +INC_ESPCOMP += -I$(ESPCOMP)/freertos/include/freertos +INC_ESPCOMP += -I$(ESPCOMP)/app_update/include +INC_ESPCOMP += -I$(ESPCOMP)/bootloader_support/include_priv +INC_ESPCOMP += -I$(ESPCOMP)/sdmmc/include +INC_ESPCOMP += -I$(ESPCOMP)/heap/include +INC_ESPCOMP += -I$(ESPCOMP)/soc/include +INC_ESPCOMP += -I$(ESPCOMP)/fatfs/src +INC_ESPCOMP += -I$(ESPCOMP)/pthread/include + +CFLAGS_BASE = -std=gnu99 -Os -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -Wall -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H -DESP_PLATFORM +CFLAGS = $(CFLAGS_BASE) $(INC) $(INC_ESPCOMP) CFLAGS += -DIDF_VER=\"$(IDF_VER)\" CFLAGS += $(CFLAGS_MOD) # this is what ESPIDF uses for c++ compilation -CXXFLAGS = -std=gnu++11 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -Wall -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -DESP_PLATFORM $(INC) +CXXFLAGS = -std=gnu++11 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -Wall -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -DESP_PLATFORM $(INC) $(INC_ESPCOMP) LDFLAGS = -nostdlib -Map=$(@:.elf=.map) --cref LDFLAGS += --gc-sections -static -EL LDFLAGS += -u call_user_start_cpu0 -u uxTopUsedPriority LDFLAGS += -u __cxa_guard_dummy # so that implementation of static guards is taken from cxx_guards.o instead of libstdc++.a -LDFLAGS += -L$(ESPCOMP)/esp32/ld -T $(BUILD)/esp32_out.ld -T ./esp32.custom_common.ld -T esp32.rom.ld -T esp32.rom.spiflash.ld -T esp32.peripherals.ld +LDFLAGS += -L$(ESPCOMP)/esp32/ld -T $(BUILD)/esp32_out.ld -T ./esp32.custom_common.ld -T esp32.rom.ld -T esp32.peripherals.ld -T esp32.rom.spiram_incompatible_fns.ld LIBGCC_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name) LIBSTDCXX_FILE_NAME = $(shell $(CXX) $(CXXFLAGS) -print-file-name=libstdc++.a) @@ -156,8 +163,11 @@ SRC_C = \ modnetwork.c \ modsocket.c \ modesp.c \ + modbpp.c \ modbadge.c \ modugfx.c \ + modfreedomgfx.c \ + modfreedomgfx_eink.c \ moduhashlib.c \ machine_rtc.c \ machine_hw_spi.c \ @@ -219,14 +229,14 @@ endif ifeq ($(MICROPY_NATIVEFS), 1) LIB_SRC_C += \ $(ESPCOMP)/fatfs/src/ff.c \ + $(ESPCOMP)/fatfs/src/diskio_wl.c \ $(ESPCOMP)/fatfs/src/diskio_sdmmc.c \ - $(ESPCOMP)/fatfs/src/diskio_spiflash.c \ $(ESPCOMP)/fatfs/src/diskio.c \ $(ESPCOMP)/fatfs/src/vfs_fat_sdmmc.c \ $(ESPCOMP)/fatfs/src/vfs_fat_spiflash.c \ $(ESPCOMP)/fatfs/src/vfs_fat.c \ - $(ESPCOMP)/fatfs/src/option/syscall.c \ - $(ESPCOMP)/fatfs/src/option/unicode.c + $(ESPCOMP)/fatfs/src/ffunicode.c \ + $(ESPCOMP)/fatfs/src/ffsystem.c endif DRIVERS_SRC_C = $(addprefix drivers/,\ @@ -260,7 +270,9 @@ ESPIDF_DRIVER_O = $(addprefix $(ESPCOMP)/driver/,\ spi_common.o \ rtc_module.o \ sdmmc_host.o \ - sdmmc_transaction.o \ + sdmmc_transaction.o \ + sdspi_host.o \ + i2s.o \ ) $(BUILD)/$(ESPCOMP)/esp32/dport_access.o: CFLAGS += -Wno-array-bounds @@ -274,7 +286,6 @@ ESPIDF_ESP32_O = $(addprefix $(ESPCOMP)/esp32/,\ cpu_start.o \ gdbstub.o \ crosscore_int.o \ - deep_sleep.o \ ipc.o \ int_wdt.o \ event_loop.o \ @@ -288,6 +299,20 @@ ESPIDF_ESP32_O = $(addprefix $(ESPCOMP)/esp32/,\ intr_alloc.o \ dport_access.o \ brownout.o \ + fast_crypto_ops.o \ + wifi_init.o \ + wifi_os_adapter.o \ + sleep_modes.o \ + esp_timer.o \ + esp_timer_esp32.o \ + ets_timer_legacy.o \ + esp_err_to_name.o \ + dbg_stubs.o \ + ) + +ESPIDF_PTHREAD_O = $(addprefix $(ESPCOMP)/pthread/,\ + pthread.o \ + pthread_local_storage.o \ ) ESPIDF_HEAP_O = $(addprefix $(ESPCOMP)/heap/,\ @@ -303,6 +328,9 @@ ESPIDF_SOC_O = $(addprefix $(ESPCOMP)/soc/,\ esp32/rtc_pm.o \ esp32/rtc_sleep.o \ esp32/rtc_time.o \ + esp32/rtc_periph.o \ + esp32/spi_periph.o \ + esp32/gpio_periph.o \ esp32/soc_memory_layout.o \ ) @@ -315,6 +343,10 @@ ESPIDF_ETHERNET_O = $(addprefix $(ESPCOMP)/ethernet/,\ emac_main.o \ ) +ESPIDF_SMARTCONFIG_ACK_O = $(addprefix $(ESPCOMP)/smartconfig_ack/,\ + smartconfig_ack.o \ + ) + ESPIDF_APP_TRACE_O = $(addprefix $(ESPCOMP)/app_trace/,\ app_trace.o \ ) @@ -325,6 +357,8 @@ ESPIDF_APP_UPDATE_O = $(addprefix $(ESPCOMP)/app_update/,\ ESPIDF_BOOTLOADER_O = $(addprefix $(ESPCOMP)/bootloader_support/src/,\ esp_image_format.o \ + bootloader_init.o \ + bootloader_utility.o \ bootloader_sha.o \ bootloader_flash.o \ ) @@ -344,12 +378,14 @@ ESPIDF_EXPAT_O = $(addprefix $(ESPCOMP)/expat/,\ # Assembler .S files need only basic flags, and in particular should not have # -Os because that generates subtly different code. +# We also need custom CFLAGS for .c files because FreeRTOS has headers with +# generic names (eg queue.h) which can clash with other files in the port. CFLAGS_ASM = -I$(ESPCOMP)/esp32/include -I$(ESPCOMP)/soc/esp32/include -I$(ESPCOMP)/freertos/include/freertos -I. $(BUILD)/$(ESPCOMP)/freertos/portasm.o: CFLAGS = $(CFLAGS_ASM) $(BUILD)/$(ESPCOMP)/freertos/xtensa_context.o: CFLAGS = $(CFLAGS_ASM) $(BUILD)/$(ESPCOMP)/freertos/xtensa_intr_asm.o: CFLAGS = $(CFLAGS_ASM) $(BUILD)/$(ESPCOMP)/freertos/xtensa_vectors.o: CFLAGS = $(CFLAGS_ASM) -$(BUILD)/$(ESPCOMP)/freertos/%.o: CFLAGS += -I$(ESPCOMP)/freertos/include/freertos +$(BUILD)/$(ESPCOMP)/freertos/%.o: CFLAGS = $(CFLAGS_BASE) -I. $(INC_ESPCOMP) -I$(ESPCOMP)/freertos/include/freertos ESPIDF_FREERTOS_O = $(addprefix $(ESPCOMP)/freertos/,\ croutine.o \ event_groups.o \ @@ -376,8 +412,8 @@ ESPIDF_VFS_O = $(addprefix $(ESPCOMP)/vfs/,\ ) ESPIDF_JSON_O = $(addprefix $(ESPCOMP)/json/,\ - library/cJSON.o \ - port/cJSON_Utils.o \ + cJSON/cJSON.o \ + cJSON/cJSON_Utils.o \ ) ESPIDF_LOG_O = $(addprefix $(ESPCOMP)/log/,\ @@ -399,6 +435,7 @@ ESPIDF_APP_TRACE_O = $(addprefix $(ESPCOMP)/app_trace/,\ ESPIDF_NEWLIB_O = $(addprefix $(ESPCOMP)/newlib/,\ time.o \ + select.o \ syscalls.o \ syscall_table.o \ reent_init.o \ @@ -432,6 +469,7 @@ ESPIDF_NGHTTP_O = $(addprefix $(ESPCOMP)/nghttp/,\ ESPIDF_NVS_FLASH_O = $(addprefix $(ESPCOMP)/nvs_flash/,\ src/nvs_types.o \ + src/nvs_ops.o \ src/nvs_page.o \ src/nvs_item_hash_list.o \ src/nvs_pagemanager.o \ @@ -516,80 +554,82 @@ ESPIDF_LWIP_O = $(addprefix $(ESPCOMP)/lwip/,\ port/freertos/sys_arch.o \ port/netif/wlanif.o \ port/netif/ethernetif.o \ + port/vfs_lwip.o \ ) ESPIDF_MBEDTLS_O = $(addprefix $(ESPCOMP)/mbedtls/,\ - library/entropy.o \ - library/net.o \ - library/pkcs12.o \ - library/ccm.o \ - library/pk.o \ - library/sha1.o \ - library/x509_csr.o \ - library/ssl_cli.o \ - library/ecp.o \ - library/blowfish.o \ - library/x509.o \ - library/ecp_curves.o \ - library/error.o \ - library/ssl_ticket.o \ - library/entropy_poll.o \ - library/cipher.o \ - library/version_features.o \ - library/ripemd160.o \ - library/rsa.o \ - library/md.o \ - library/md_wrap.o \ - library/sha256.o \ - library/dhm.o \ - library/ssl_cache.o \ - library/pkwrite.o \ - library/base64.o \ - library/asn1parse.o \ - library/ssl_tls.o \ - library/hmac_drbg.o \ - library/pem.o \ - library/version.o \ - library/gcm.o \ - library/memory_buffer_alloc.o \ - library/md2.o \ - library/ecdsa.o \ - library/ssl_srv.o \ - library/x509_crt.o \ - library/ecdh.o \ - library/asn1write.o \ - library/md4.o \ - library/debug.o \ - library/x509_create.o \ - library/ecjpake.o \ - library/oid.o \ - library/md5.o \ - library/ssl_ciphersuites.o \ - library/sha512.o \ - library/xtea.o \ - library/aes.o \ - library/cipher_wrap.o \ - library/arc4.o \ - library/bignum.o \ - library/pkparse.o \ - library/padlock.o \ - library/threading.o \ - library/x509_crl.o \ - library/pkcs11.o \ - library/aesni.o \ - library/timing.o \ - library/certs.o \ - library/pkcs5.o \ - library/ssl_cookie.o \ - library/camellia.o \ - library/havege.o \ - library/des.o \ - library/x509write_csr.o \ - library/platform.o \ - library/ctr_drbg.o \ - library/x509write_crt.o \ - library/pk_wrap.o \ - port/net.o \ + mbedtls/library/entropy.o \ + mbedtls/library/pkcs12.o \ + mbedtls/library/ccm.o \ + mbedtls/library/pk.o \ + mbedtls/library/sha1.o \ + mbedtls/library/x509_csr.o \ + mbedtls/library/ssl_cli.o \ + mbedtls/library/ecp.o \ + mbedtls/library/blowfish.o \ + mbedtls/library/x509.o \ + mbedtls/library/ecp_curves.o \ + mbedtls/library/error.o \ + mbedtls/library/ssl_ticket.o \ + mbedtls/library/entropy_poll.o \ + mbedtls/library/cipher.o \ + mbedtls/library/version_features.o \ + mbedtls/library/ripemd160.o \ + mbedtls/library/rsa.o \ + mbedtls/library/rsa_internal.o \ + mbedtls/library/md.o \ + mbedtls/library/md_wrap.o \ + mbedtls/library/sha256.o \ + mbedtls/library/dhm.o \ + mbedtls/library/ssl_cache.o \ + mbedtls/library/pkwrite.o \ + mbedtls/library/base64.o \ + mbedtls/library/asn1parse.o \ + mbedtls/library/ssl_tls.o \ + mbedtls/library/hmac_drbg.o \ + mbedtls/library/pem.o \ + mbedtls/library/version.o \ + mbedtls/library/gcm.o \ + mbedtls/library/memory_buffer_alloc.o \ + mbedtls/library/md2.o \ + mbedtls/library/ecdsa.o \ + mbedtls/library/ssl_srv.o \ + mbedtls/library/x509_crt.o \ + mbedtls/library/ecdh.o \ + mbedtls/library/asn1write.o \ + mbedtls/library/md4.o \ + mbedtls/library/debug.o \ + mbedtls/library/x509_create.o \ + mbedtls/library/ecjpake.o \ + mbedtls/library/oid.o \ + mbedtls/library/md5.o \ + mbedtls/library/ssl_ciphersuites.o \ + mbedtls/library/sha512.o \ + mbedtls/library/xtea.o \ + mbedtls/library/aes.o \ + mbedtls/library/cipher_wrap.o \ + mbedtls/library/arc4.o \ + mbedtls/library/bignum.o \ + mbedtls/library/pkparse.o \ + mbedtls/library/padlock.o \ + mbedtls/library/threading.o \ + mbedtls/library/x509_crl.o \ + mbedtls/library/pkcs11.o \ + mbedtls/library/aesni.o \ + mbedtls/library/timing.o \ + mbedtls/library/certs.o \ + mbedtls/library/pkcs5.o \ + mbedtls/library/ssl_cookie.o \ + mbedtls/library/camellia.o \ + mbedtls/library/havege.o \ + mbedtls/library/des.o \ + mbedtls/library/x509write_csr.o \ + mbedtls/library/platform.o \ + mbedtls/library/platform_util.o \ + mbedtls/library/ctr_drbg.o \ + mbedtls/library/x509write_crt.o \ + mbedtls/library/pk_wrap.o \ + port/net_sockets.o \ port/esp_bignum.o \ port/esp_hardware.o \ port/esp_sha1.o \ @@ -597,7 +637,7 @@ ESPIDF_MBEDTLS_O = $(addprefix $(ESPCOMP)/mbedtls/,\ port/esp_sha512.o \ ) -$(BUILD)/$(ESPCOMP)/wpa_supplicant/%.o: CFLAGS += -DEMBEDDED_SUPP -D__ets__ -Wno-strict-aliasing +$(BUILD)/$(ESPCOMP)/wpa_supplicant/%.o: CFLAGS += -DESPRESSIF_USE -DEMBEDDED_SUPP -D__ets__ -Wno-strict-aliasing ESPIDF_WPA_SUPPLICANT_O = $(addprefix $(ESPCOMP)/wpa_supplicant/,\ src/crypto/aes-internal-enc.o \ src/crypto/sha256-internal.o \ @@ -620,16 +660,44 @@ ESPIDF_WPA_SUPPLICANT_O = $(addprefix $(ESPCOMP)/wpa_supplicant/,\ src/crypto/bignum.o \ src/crypto/crypto_internal-modexp.o \ src/crypto/crypto_internal-cipher.o \ + src/fast_crypto/fast_sha256.o \ + src/fast_crypto/fast_sha256-internal.o \ + src/fast_crypto/fast_aes-wrap.o \ + src/fast_crypto/fast_aes-unwrap.o \ port/os_xtensa.o \ ) +ESPADF_O = $(addprefix $(PROJECT_PATH)/components/,\ + audio_pipeline/audio_pipeline.o \ + audio_pipeline/audio_element.o \ + audio_pipeline/audio_event_iface.o \ + audio_pipeline/ringbuf.o \ + audio_sal/audio_mem.o \ + audio_stream/http_stream.o \ + audio_stream/i2s_stream.o \ + esp_http_client/esp_http_client.o \ + esp_http_client/lib/http_header.o \ + esp_http_client/lib/http_auth.o \ + esp_http_client/lib/http_utils.o \ + tcp_transport/transport.o \ + tcp_transport/transport_ssl.o \ + tcp_transport/transport_tcp.o \ + tcp_transport/transport_utils.o \ + esp-tls/esp_tls.o \ + esp_peripherals/periph_wifi.o \ + esp_peripherals/esp_peripherals.o \ + ) + OBJ_ESPIDF = OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_NEWLIB_O)) OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_DRIVER_O)) OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_ESP32_O)) +OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_PTHREAD_O)) +OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_HEAP_O)) OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_SOC_O)) OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_CXX_O)) OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_ETHERNET_O)) +OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_SMARTCONFIG_ACK_O)) OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_APP_TRACE_O)) OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_EXPAT_O)) OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_FREERTOS_O)) @@ -650,21 +718,21 @@ OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_WPA_SUPPLICANT_O)) OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_APP_UPDATE_O)) OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_BOOTLOADER_O)) OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_SDMMC_O)) -OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_HEAP_O)) +OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPADF_O)) #################### # Badge magic $(BUILD)/components/%.o: -BADGE_COMPONENTS_O = $(addprefix $(BADGE)/components/,\ +BADGE_COMPONENTS_O = $(addprefix $(PROJECT_PATH)/components/,\ badge/badge_base.o \ badge/badge_eink.o \ badge/badge_i2c.o \ badge/badge_leds.o \ badge/badge_mpr121.o \ - badge/badge_portexp.o \ + badge/badge_fxl6408.o \ badge/badge_gpiobutton.o \ - badge/badge_touch.o \ + badge/badge_cpt112s.o \ badge/badge_input.o \ badge/badge_sdcard.o \ badge/badge_vibrator.o \ @@ -680,6 +748,7 @@ BADGE_COMPONENTS_O = $(addprefix $(BADGE)/components/,\ ugfx-glue/gdisp_lld_framebuffer.o \ ugfx-glue/ginput_lld_toggle.o \ ugfx-glue/gfx_mk.o \ + ugfx-glue/gfx_userfs.o \ sha2017/wildcard_sha2017_org.o \ sha2017/sha2017_ota_graphics.o \ sha2017/sha2017_ota.o \ @@ -709,10 +778,7 @@ OBJ_ESPIDF += $(addprefix $(BUILD)/, $(BADGE_COMPONENTS_O)) all: $(BUILD)/firmware.bin -.PHONY: idf-version deploy erase - -idf-version: - $(ECHO) "ESP IDF supported hash: $(ESPIDF_SUPHASH)" +.PHONY: deploy erase $(BUILD)/firmware.bin: $(BUILD)/bootloader.bin $(BUILD)/partitions.bin $(BUILD)/application.bin $(ECHO) "Create $@" @@ -720,7 +786,12 @@ $(BUILD)/firmware.bin: $(BUILD)/bootloader.bin $(BUILD)/partitions.bin $(BUILD)/ deploy: $(BUILD)/firmware.bin $(ECHO) "Writing $^ to the board" - $(Q)$(ESPTOOL) --chip esp32 --port $(PORT) --baud $(BAUD) write_flash -z --flash_mode $(FLASH_MODE) --flash_freq $(FLASH_FREQ) --flash_size $(FLASH_SIZE) 0 $^ + $(Q)$(ESPTOOL) --chip esp32 --port $(PORT) --baud $(BAUD) write_flash -z --flash_mode $(FLASH_MODE) --flash_freq $(FLASH_FREQ) 0x1000 $^ + +flash: $(BUILD)/firmware.bin + $(ECHO) "Writing $^ to the board" + $(Q)$(ESPTOOL) --port $(PORT) --baud $(BAUD) erase_region 0xd000 0x2000 + $(Q)$(ESPTOOL) --port $(PORT) --baud $(BAUD) write_flash 0x10000 build/application.bin erase: $(ECHO) "Erasing flash" @@ -736,11 +807,13 @@ APP_LD_ARGS += $(LDFLAGS_MOD) APP_LD_ARGS += --start-group APP_LD_ARGS += -L$(dir $(LIBGCC_FILE_NAME)) -lgcc APP_LD_ARGS += -L$(dir $(LIBSTDCXX_FILE_NAME)) -lstdc++ +APP_LD_ARGS += -lgcov APP_LD_ARGS += $(ESPCOMP)/newlib/lib/libc.a APP_LD_ARGS += $(ESPCOMP)/newlib/lib/libm.a APP_LD_ARGS += $(ESPCOMP)/esp32/libhal.a +APP_LD_ARGS += $(PROJECT_PATH)/components/esp-adf-libs/esp_codec/lib/libesp_codec.a APP_LD_ARGS += $(BADGE_LIBS) -APP_LD_ARGS += -L$(ESPCOMP)/esp32/lib -lcore -lnet80211 -lphy -lrtc -lpp -lwpa -lsmartconfig -lcoexist +APP_LD_ARGS += -L$(ESPCOMP)/esp32/lib -lcore -lnet80211 -lmesh -lphy -lrtc -lpp -lwpa -lwpa2 -lwps -lsmartconfig -lcoexist APP_LD_ARGS += $(OBJ) APP_LD_ARGS += --end-group @@ -780,15 +853,23 @@ BOOTLOADER_OBJ = $(addprefix $(BUILD)/bootloader/$(ESPCOMP)/,\ bootloader_support/src/bootloader_flash.o \ bootloader_support/src/bootloader_sha.o \ bootloader_support/src/bootloader_random.o \ + bootloader_support/src/bootloader_clock.o \ + bootloader_support/src/bootloader_init.o \ + bootloader_support/src/bootloader_utility.o \ + bootloader_support/src/bootloader_common.o \ bootloader_support/src/secure_boot_signatures.o \ bootloader_support/src/secure_boot.o \ bootloader_support/src/esp_image_format.o \ bootloader_support/src/flash_encrypt.o \ bootloader_support/src/flash_partitions.o \ + bootloader_support/src/flash_qio_mode.o \ log/log.o \ spi_flash/spi_flash_rom_patch.o \ + soc/esp32/cpu_util.o \ soc/esp32/rtc_clk.o \ soc/esp32/rtc_time.o \ + soc/esp32/rtc_init.o \ + soc/esp32/rtc_periph.o \ micro-ecc/micro-ecc/uECC.o \ bootloader/subproject/main/bootloader_start.o \ ) @@ -812,7 +893,8 @@ BOOTLOADER_LDFLAGS += -Wl,-Map=$(@:.elf=.map) -Wl,--cref BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/bootloader/subproject/main/esp32.bootloader.ld BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/bootloader/subproject/main/esp32.bootloader.rom.ld BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp32/ld/esp32.rom.ld -BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp32/ld/esp32.rom.spiflash.ld +BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp32/ld/esp32.rom.spiram_incompatible_fns.ld +BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp32/ld/esp32.peripherals.ld BOOTLOADER_OBJ_DIRS = $(sort $(dir $(BOOTLOADER_OBJ))) $(BOOTLOADER_OBJ): | $(BOOTLOADER_OBJ_DIRS) diff --git a/esp32/esp32.custom_common.ld b/esp32/esp32.custom_common.ld index 363b6b53c..d56dd3e7d 100644 --- a/esp32/esp32.custom_common.ld +++ b/esp32/esp32.custom_common.ld @@ -10,8 +10,8 @@ SECTIONS { . = ALIGN(4); *(.rtc.literal .rtc.text) - *rtc_wake_stub*.o(.literal .text .literal.* .text.*) - } >rtc_iram_seg + *rtc_wake_stub*.*(.literal .text .literal.* .text.*) + } > rtc_iram_seg /* RTC slow memory holds RTC wake stub data/rodata, including from any source file @@ -22,7 +22,7 @@ SECTIONS _rtc_data_start = ABSOLUTE(.); *(.rtc.data) *(.rtc.rodata) - *rtc_wake_stub*.o(.data .rodata .data.* .rodata.* .bss .bss.*) + *rtc_wake_stub*.*(.data .rodata .data.* .rodata.* .bss .bss.*) _rtc_data_end = ABSOLUTE(.); } > rtc_slow_seg @@ -30,11 +30,25 @@ SECTIONS .rtc.bss (NOLOAD) : { _rtc_bss_start = ABSOLUTE(.); - *rtc_wake_stub*.o(.bss .bss.*) - *rtc_wake_stub*.o(COMMON) + *rtc_wake_stub*.*(.bss .bss.*) + *rtc_wake_stub*.*(COMMON) _rtc_bss_end = ABSOLUTE(.); } > rtc_slow_seg + /* This section holds data that should not be initialized at power up + and will be retained during deep sleep. The section located in + RTC SLOW Memory area. User data marked with RTC_NOINIT_ATTR will be placed + into this section. See the file "esp_attr.h" for more information. + */ + .rtc_noinit (NOLOAD): + { + . = ALIGN(4); + _rtc_noinit_start = ABSOLUTE(.); + *(.rtc_noinit .rtc_noinit.*) + . = ALIGN(4) ; + _rtc_noinit_end = ABSOLUTE(.); + } > rtc_slow_seg + /* Send .iram0 code to iram */ .iram0.vectors : { @@ -83,40 +97,63 @@ SECTIONS _iram_text_start = ABSOLUTE(.); *(.iram1 .iram1.*) *freertos/*(.literal .text .literal.* .text.*) + *heap/multi_heap.o(.literal .text .literal.* .text.*) + *heap/multi_heap_poisoning.o(.literal .text .literal.* .text.*) *esp32/panic.o(.literal .text .literal.* .text.*) *esp32/core_dump.o(.literal .text .literal.* .text.*) - *esp32/heap_alloc_caps.o(.literal .text .literal.* .text.*) - *esp32/app_trace.o(.literal .text .literal.* .text.*) + *app_trace/*(.literal .text .literal.* .text.*) + *xtensa-debug-module/eri.o(.literal .text .literal.* .text.*) *libphy.a:(.literal .text .literal.* .text.*) *librtc.a:(.literal .text .literal.* .text.*) *libsoc.a:(.literal .text .literal.* .text.*) *libhal.a:(.literal .text .literal.* .text.*) + *libgcc.a:lib2funcs.o(.literal .text .literal.* .text.*) *spi_flash/spi_flash_rom_patch.o(.literal .text .literal.* .text.*) + *libgcov.a:(.literal .text .literal.* .text.*) *py/scheduler.o*(.literal .text .literal.* .text.*) + INCLUDE esp32.spiram.rom-functions-iram.ld _iram_text_end = ABSOLUTE(.); } > iram0_0_seg - + .dram0.data : { _data_start = ABSOLUTE(.); - KEEP(*(.data)) - KEEP(*(.data.*)) - KEEP(*(.gnu.linkonce.d.*)) - KEEP(*(.data1)) - KEEP(*(.sdata)) - KEEP(*(.sdata.*)) - KEEP(*(.gnu.linkonce.s.*)) - KEEP(*(.sdata2)) - KEEP(*(.sdata2.*)) - KEEP(*(.gnu.linkonce.s2.*)) - KEEP(*(.jcr)) + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + *(.data1) + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s.*) + *(.sdata2) + *(.sdata2.*) + *(.gnu.linkonce.s2.*) + *(.jcr) *(.dram1 .dram1.*) *esp32/panic.o(.rodata .rodata.*) - *esp32/app_trace.o(.rodata .rodata.*) *libphy.a:(.rodata .rodata.*) + *app_trace/*(.rodata .rodata.*) + *libgcov.a:(.rodata .rodata.*) + *heap/multi_heap.o(.rodata .rodata.*) + *heap/multi_heap_poisoning.o(.rodata .rodata.*) + INCLUDE esp32.spiram.rom-functions-dram.ld _data_end = ABSOLUTE(.); . = ALIGN(4); - } >dram0_0_seg + } > dram0_0_seg + + /*This section holds data that should not be initialized at power up. + The section located in Internal SRAM memory region. The macro _NOINIT + can be used as attribute to place data into this section. + See the esp_attr.h file for more information. + */ + .noinit (NOLOAD): + { + . = ALIGN(4); + _noinit_start = ABSOLUTE(.); + *(.noinit .noinit.*) + . = ALIGN(4) ; + _noinit_end = ABSOLUTE(.); + } > dram0_0_seg /* Shared RAM */ .dram0.bss (NOLOAD) : @@ -139,8 +176,9 @@ SECTIONS *(COMMON) . = ALIGN (8); _bss_end = ABSOLUTE(.); + /* The heap starts right after end of this section */ _heap_start = ABSOLUTE(.); - } >dram0_0_seg + } > dram0_0_seg .flash.rodata : { @@ -152,11 +190,13 @@ SECTIONS *(.rodata1) __XT_EXCEPTION_TABLE_ = ABSOLUTE(.); *(.xt_except_table) - *(.gcc_except_table) + *(.gcc_except_table .gcc_except_table.*) *(.gnu.linkonce.e.*) *(.gnu.version_r) - *(.eh_frame) . = (. + 3) & ~ 3; + __eh_frame = ABSOLUTE(.); + KEEP(*(.eh_frame)) + . = (. + 7) & ~ 3; /* C++ constructor and destructor tables, properly ordered: */ __init_array_start = ABSOLUTE(.); KEEP (*crtbegin.o(.ctors)) @@ -184,6 +224,13 @@ SECTIONS *(.gnu.linkonce.lit4.*) _lit4_end = ABSOLUTE(.); . = ALIGN(4); + _thread_local_start = ABSOLUTE(.); + *(.tdata) + *(.tdata.*) + *(.tbss) + *(.tbss.*) + _thread_local_end = ABSOLUTE(.); + . = ALIGN(4); } >drom0_0_seg .flash.text : diff --git a/esp32/machine_adc.c b/esp32/machine_adc.c index 659702ae2..72696e11b 100644 --- a/esp32/machine_adc.c +++ b/esp32/machine_adc.c @@ -81,7 +81,7 @@ STATIC void madc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ STATIC mp_obj_t madc_read(mp_obj_t self_in) { madc_obj_t *self = self_in; - int val = adc1_get_voltage(self->adc1_id); + int val = adc1_get_raw(self->adc1_id); if (val == -1) mp_raise_ValueError("Parameter Error"); return MP_OBJ_NEW_SMALL_INT(val); } diff --git a/esp32/machine_pin.c b/esp32/machine_pin.c index d62d6c1cc..b70bcf1a7 100644 --- a/esp32/machine_pin.c +++ b/esp32/machine_pin.c @@ -92,7 +92,7 @@ STATIC const machine_pin_obj_t machine_pin_obj[] = { STATIC const machine_pin_irq_obj_t machine_pin_irq_object[]; void machine_pins_init(void) { - static bool did_install = false; + static bool did_install = true; // already done in badge_base.c if (!did_install) { gpio_install_isr_service(0); did_install = true; diff --git a/esp32/machine_rtc.c b/esp32/machine_rtc.c index 7bcd7d3ac..a49d5caec 100644 --- a/esp32/machine_rtc.c +++ b/esp32/machine_rtc.c @@ -35,7 +35,6 @@ #include "py/obj.h" #include "py/runtime.h" #include "py/mphal.h" -#include "timeutils.h" #include "modmachine.h" #include "machine_rtc.h" @@ -85,11 +84,10 @@ STATIC mp_obj_t machine_rtc_datetime_helper(mp_uint_t n_args, const mp_obj_t *ar // Get time struct timeval tv; - struct tm tm; - gettimeofday(&tv, NULL); - gmtime_r(&tv.tv_sec, &tm); + struct tm tm; + localtime_r(&tv.tv_sec, &tm); mp_obj_t tuple[8] = { mp_obj_new_int(tm.tm_year + 1900), @@ -108,19 +106,22 @@ STATIC mp_obj_t machine_rtc_datetime_helper(mp_uint_t n_args, const mp_obj_t *ar mp_obj_t *items; mp_obj_get_array_fixed_n(args[1], 8, &items); - struct tm tm; - struct timeval tv; - - tm.tm_year = mp_obj_get_int(items[0]) - 1900; - tm.tm_mon = mp_obj_get_int(items[1]) - 1; - tm.tm_mday = mp_obj_get_int(items[2]); - tm.tm_hour = mp_obj_get_int(items[4]); - tm.tm_min = mp_obj_get_int(items[5]); - tm.tm_sec = mp_obj_get_int(items[6]); - tv.tv_sec = mktime(&tm); - tv.tv_usec = mp_obj_get_int(items[7]); + struct tm tm = { + .tm_year = mp_obj_get_int(items[0]) - 1900, + .tm_mon = mp_obj_get_int(items[1]) - 1, + .tm_mday = mp_obj_get_int(items[2]), + .tm_hour = mp_obj_get_int(items[4]), + .tm_min = mp_obj_get_int(items[5]), + .tm_sec = mp_obj_get_int(items[6]), + .tm_isdst = -1, + }; + time_t t = mktime(&tm); + struct timeval tv = { + .tv_sec = t, + .tv_usec = mp_obj_get_int(items[7]), + }; settimeofday(&tv, NULL); return mp_const_none; diff --git a/esp32/main.c b/esp32/main.c index 1769ddf62..e432f984f 100644 --- a/esp32/main.c +++ b/esp32/main.c @@ -35,6 +35,7 @@ #include "esp_system.h" #include "esp_task.h" #include "soc/cpu.h" +#include "rom/rtc.h" #include "sha2017_ota.h" #include "esprtcmem.h" @@ -46,30 +47,77 @@ #include "py/repl.h" #include "py/gc.h" #include "py/mphal.h" +#include "extmod/vfs.h" #include "lib/mp-readline/readline.h" #include "lib/utils/pyexec.h" #include "uart.h" #include "modmachine.h" #include "mpthreadport.h" #include "bpp_init.h" -#include "badge_portexp.h" #include "badge_pins.h" #include "badge_base.h" #include "badge_first_run.h" #include +#include #include // MicroPython runs as a task under FreeRTOS #define MP_TASK_PRIORITY (ESP_TASK_PRIO_MIN + 1) -#define MP_TASK_STACK_SIZE ( 8 * 1024) +//define MP_TASK_STACK_SIZE ( 8 * 1024) +#define MP_TASK_STACK_SIZE ( 6 * 1024) #define MP_TASK_STACK_LEN (MP_TASK_STACK_SIZE / sizeof(StackType_t)) -#define MP_TASK_HEAP_SIZE (88 * 1024) +//define MP_TASK_HEAP_SIZE (88 * 1024) +#define MP_TASK_HEAP_SIZE (20 * 1024) + +//define BUTTON_SAFE_MODE ((1 << BADGE_BUTTON_A) || (1 << BADGE_BUTTON_B)) +#define BUTTON_SAFE_MODE ((1 << BADGE_BUTTON_START)) STATIC StaticTask_t mp_task_tcb; STATIC StackType_t mp_task_stack[MP_TASK_STACK_LEN] __attribute__((aligned (8))); STATIC uint8_t mp_task_heap[MP_TASK_HEAP_SIZE]; extern uint32_t reset_cause; +extern bool in_safe_mode; + +static const char *import_blacklist[] = { + "/lib/json", + "/lib/os", + "/lib/socket", + "/lib/struct", + "/lib/time", +}; + +mp_import_stat_t +mp_import_stat(const char *path) { + if (in_safe_mode) { + // be more strict in which modules we would like to load + if (strncmp(path, "/lib/", 5) != 0 + && strncmp(path, "/bpp/lib/", 9) != 0 + && strncmp(path, "/sdcard/lib/", 12) != 0) { + return MP_IMPORT_STAT_NO_EXIST; + } + + /* check blacklist */ + int i; + for (i=0; i= cur_offset diff --git a/esp32/modbadge.c b/esp32/modbadge.c index ec0e7df21..00182abf9 100644 --- a/esp32/modbadge.c +++ b/esp32/modbadge.c @@ -32,10 +32,21 @@ #include "modbadge.h" +#include "esp_log.h" +#include "esp_vfs.h" +#include "esp_vfs_fat.h" + +#include "bpp_init.h" + +#include "badge_i2c.h" +#include "badge_mpr121.h" + #include "py/mperrno.h" #include "py/mphal.h" #include "py/runtime.h" +#define TAG "esp32/modbadge" + // INIT STATIC mp_obj_t badge_init_() { @@ -45,15 +56,34 @@ STATIC mp_obj_t badge_init_() { STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_init_obj, badge_init_); /*** nvs access ***/ -static void _nvs_check_namespace_key(const char *namespace, const char *key) { + +static void _nvs_check_namespace(const char *namespace) { if (strlen(namespace) == 0 || strlen(namespace) > 15) { mp_raise_msg(&mp_type_AttributeError, "Invalid namespace"); } +} + +static void _nvs_check_namespace_key(const char *namespace, const char *key) { + _nvs_check_namespace(namespace); + if (strlen(key) == 0 || strlen(key) > 15) { mp_raise_msg(&mp_type_AttributeError, "Invalid key"); } } +STATIC mp_obj_t badge_nvs_erase_all_(mp_obj_t _namespace) { + const char *namespace = mp_obj_str_get_str(_namespace); + _nvs_check_namespace(namespace); + + esp_err_t err = badge_nvs_erase_all(namespace); + if (err != ESP_OK) { + mp_raise_msg(&mp_type_ValueError, "Failed to erase all keys in nvs"); + } + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(badge_nvs_erase_all_obj, badge_nvs_erase_all_); + STATIC mp_obj_t badge_nvs_erase_key_(mp_obj_t _namespace, mp_obj_t _key) { const char *namespace = mp_obj_str_get_str(_namespace); const char *key = mp_obj_str_get_str(_key); @@ -61,7 +91,7 @@ STATIC mp_obj_t badge_nvs_erase_key_(mp_obj_t _namespace, mp_obj_t _key) { esp_err_t err = badge_nvs_erase_key(namespace, key); if (err != ESP_OK) { - mp_raise_msg(&mp_type_ValueError, "Failed to store data in nvs"); + mp_raise_msg(&mp_type_ValueError, "Failed to erase key in nvs"); } return mp_const_none; @@ -184,14 +214,253 @@ STATIC mp_obj_t badge_nvs_set_u16_(mp_obj_t _namespace, mp_obj_t _key, mp_obj_t STATIC MP_DEFINE_CONST_FUN_OBJ_3(badge_nvs_set_u16_obj, badge_nvs_set_u16_); -// EINK +// audio +#define IIS_SCLK 33 +#define IIS_LCLK 12 +#define IIS_DSIN 4 +#define IIS_DOUT -1 + +#include "esp_log.h" +#include "audio_element.h" +#include "audio_pipeline.h" +#include "audio_event_iface.h" +#include "audio_common.h" +#include "http_stream.h" +#include "i2s_stream.h" +#include "mp3_decoder.h" +#include "esp_peripherals.h" +#include "periph_wifi.h" +#include "badge_power.h" + +STATIC mp_obj_t badge_play_mp3_stream(mp_obj_t _url) { + const char *url = mp_obj_str_get_str(_url); + + audio_pipeline_handle_t pipeline; + audio_element_handle_t http_stream_reader, i2s_stream_writer, mp3_decoder; + + ESP_LOGI(TAG, "[ 1 ] Start audio codec chip"); + badge_power_sdcard_enable(); + + ESP_LOGI(TAG, "[2.0] Create audio pipeline for playback"); + audio_pipeline_cfg_t pipeline_cfg = DEFAULT_AUDIO_PIPELINE_CONFIG(); + pipeline = audio_pipeline_init(&pipeline_cfg); + mem_assert(pipeline); + + ESP_LOGI(TAG, "[2.1] Create http stream to read data"); + http_stream_cfg_t http_cfg = HTTP_STREAM_CFG_DEFAULT(); + http_stream_reader = http_stream_init(&http_cfg); + + ESP_LOGI(TAG, "[2.2] Create i2s stream to write data to codec chip"); + i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT(); + + // fixes + i2s_cfg.i2s_config.mode = I2S_MODE_MASTER | I2S_MODE_TX; + i2s_cfg.i2s_config.sample_rate = 48000; + i2s_cfg.i2s_config.use_apll = 0; // too far off + + i2s_cfg.type = AUDIO_STREAM_WRITER; + i2s_stream_writer = i2s_stream_init(&i2s_cfg); + + ESP_LOGI(TAG, "[2.3] Create mp3 decoder to decode mp3 file"); + mp3_decoder_cfg_t mp3_cfg = DEFAULT_MP3_DECODER_CONFIG(); + mp3_decoder = mp3_decoder_init(&mp3_cfg); + + ESP_LOGI(TAG, "[2.4] Register all elements to audio pipeline"); + audio_pipeline_register(pipeline, http_stream_reader, "http"); + audio_pipeline_register(pipeline, mp3_decoder, "mp3"); + audio_pipeline_register(pipeline, i2s_stream_writer, "i2s"); + + ESP_LOGI(TAG, "[2.5] Link it together http_stream-->mp3_decoder-->i2s_stream-->[codec_chip]"); + audio_pipeline_link(pipeline, (const char *[]) {"http", "mp3", "i2s"}, 3); + + ESP_LOGI(TAG, "[2.6] Setup uri (http as http_stream, mp3 as mp3 decoder, and default output is i2s)"); + if (*url == 0) { // empty string; keep as hack to test audio + audio_element_set_uri(http_stream_reader, "https://dl.espressif.com/dl/audio/ff-16b-2c-44100hz.mp3"); + } else { + audio_element_set_uri(http_stream_reader, url); + } + + ESP_LOGI(TAG, "[ 4 ] Setup event listener"); + audio_event_iface_cfg_t evt_cfg = AUDIO_EVENT_IFACE_DEFAULT_CFG(); + audio_event_iface_handle_t evt = audio_event_iface_init(&evt_cfg); + + ESP_LOGI(TAG, "[4.1] Listening event from all elements of pipeline"); + audio_pipeline_set_listener(pipeline, evt); + + ESP_LOGI(TAG, "[ 5 ] Start audio_pipeline"); + audio_pipeline_run(pipeline); + + while (1) { + audio_event_iface_msg_t msg; + esp_err_t ret = audio_event_iface_listen(evt, &msg, portMAX_DELAY); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "[ * ] Event interface error : %d", ret); + continue; + } + + if (msg.source_type == AUDIO_ELEMENT_TYPE_ELEMENT + && msg.source == (void *) mp3_decoder + && msg.cmd == AEL_MSG_CMD_REPORT_MUSIC_INFO) { + audio_element_info_t music_info = {0}; + audio_element_getinfo(mp3_decoder, &music_info); + + ESP_LOGI(TAG, "[ * ] Receive music info from mp3 decoder, sample_rates=%d, bits=%d, ch=%d", + music_info.sample_rates, music_info.bits, music_info.channels); + + audio_element_setinfo(i2s_stream_writer, &music_info); + i2s_stream_set_clk(i2s_stream_writer, music_info.sample_rates, music_info.bits, music_info.channels); + continue; + } + + /* Stop when the last pipeline element (i2s_stream_writer in this case) receives stop event */ + if (msg.source_type == AUDIO_ELEMENT_TYPE_ELEMENT && msg.source == (void *) i2s_stream_writer + && msg.cmd == AEL_MSG_CMD_REPORT_STATUS && (int) msg.data == AEL_STATUS_STATE_STOPPED) { + ESP_LOGW(TAG, "[ * ] Stop event received"); + break; + } + } + + ESP_LOGI(TAG, "[ 6 ] Stop audio_pipeline"); + audio_pipeline_terminate(pipeline); + + /* Terminate the pipeline before removing the listener */ + audio_pipeline_unregister(pipeline, http_stream_reader); + audio_pipeline_unregister(pipeline, i2s_stream_writer); + audio_pipeline_unregister(pipeline, mp3_decoder); + + audio_pipeline_remove_listener(pipeline); + + /* Make sure audio_pipeline_remove_listener & audio_event_iface_remove_listener are called before destroying event_iface */ + audio_event_iface_destroy(evt); + + /* Release all resources */ + audio_pipeline_deinit(pipeline); + audio_element_deinit(http_stream_reader); + audio_element_deinit(i2s_stream_writer); + audio_element_deinit(mp3_decoder); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(badge_play_mp3_stream_obj, badge_play_mp3_stream); + +// I2C (badge_i2c.h) +STATIC mp_obj_t badge_i2c_read_reg_(mp_obj_t _addr, mp_obj_t _reg, mp_obj_t _len) { + int addr = mp_obj_get_int(_addr); + int reg = mp_obj_get_int(_reg); + int len = mp_obj_get_int(_len); + + if (addr < 0 || addr > 127) { + mp_raise_msg(&mp_type_AttributeError, "I2C address out of range"); + } + + if (reg < 0 || reg > 255) { + mp_raise_msg(&mp_type_AttributeError, "I2C register out of range"); + } + + if (len < 0) { + mp_raise_msg(&mp_type_AttributeError, "requested negative amount of bytes"); + } + + vstr_t vstr; + vstr_init_len(&vstr, len); + + esp_err_t res = badge_i2c_read_reg(addr, reg, (uint8_t *) vstr.buf, len); + if (res != ESP_OK) { + mp_raise_OSError(MP_EIO); + } + + return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_3(badge_i2c_read_reg_obj, badge_i2c_read_reg_); + +STATIC mp_obj_t badge_i2c_write_reg_(mp_obj_t _addr, mp_obj_t _reg, mp_obj_t _data) { + int addr = mp_obj_get_int(_addr); + int reg = mp_obj_get_int(_reg); + mp_uint_t data_len; + uint8_t *data = (uint8_t *) mp_obj_str_get_data(_data, &data_len); + + if (addr < 0 || addr > 127) { + mp_raise_msg(&mp_type_AttributeError, "I2C address out of range"); + } + + if (reg < 0 || reg > 255) { + mp_raise_msg(&mp_type_AttributeError, "I2C register out of range"); + } + + bool is_bytes = MP_OBJ_IS_TYPE(_data, &mp_type_bytes); + if (!is_bytes) { + mp_raise_msg(&mp_type_AttributeError, "Data should be a bytestring"); + } + + if (data_len != 1) { + mp_raise_msg(&mp_type_AttributeError, "Data-lengths other than 1 byte are not supported"); + } + + esp_err_t res = badge_i2c_write_reg(addr, reg, data[0]); + if (res != ESP_OK) { + mp_raise_OSError(MP_EIO); + } + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_3(badge_i2c_write_reg_obj, badge_i2c_write_reg_); + + +// Mpr121 (badge_mpr121.h) +#ifdef I2C_MPR121_ADDR +#define store_dict_int(dict, field, contents) mp_obj_dict_store(dict, mp_obj_new_str(field, strlen(field), false), mp_obj_new_int(contents)); +STATIC mp_obj_t badge_mpr121_get_touch_info_(void) { + struct badge_mpr121_touch_info info; + esp_err_t err = badge_mpr121_get_touch_info(&info); + if (err != ESP_OK) { + mp_raise_OSError(MP_EIO); + } + + mp_obj_t list_items[8]; + int i; + for (i=0; i<8; i++) { + list_items[i] = mp_obj_new_dict(0); + + mp_obj_dict_t *dict = MP_OBJ_TO_PTR(list_items[i]); + + store_dict_int(dict, "data", info.data[i]); + store_dict_int(dict, "baseline", info.baseline[i]); + store_dict_int(dict, "touch", info.touch[i]); + store_dict_int(dict, "release", info.release[i]); + } + mp_obj_t list = mp_obj_new_list(8, list_items); + return list; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_mpr121_get_touch_info_obj, badge_mpr121_get_touch_info_); +#endif // I2C_MPR121_ADDR + + +bool RTC_DATA_ATTR in_safe_mode = false; +STATIC mp_obj_t badge_safe_mode() { + return mp_obj_new_bool(in_safe_mode); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_safe_mode_obj, badge_safe_mode); +// E-Ink (badge_eink.h) STATIC mp_obj_t badge_eink_init_() { - badge_eink_init(); + badge_eink_init(BADGE_EINK_DEFAULT); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_eink_init_obj, badge_eink_init_); +STATIC mp_obj_t badge_eink_deep_sleep_() { + badge_eink_deep_sleep(); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_eink_deep_sleep_obj, badge_eink_deep_sleep_); + +STATIC mp_obj_t badge_eink_wakeup_() { + badge_eink_wakeup(); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_eink_wakeup_obj, badge_eink_wakeup_); + + /** #define NUM_PICTURES 7 const uint8_t *pictures[NUM_PICTURES] = { @@ -228,24 +497,49 @@ STATIC mp_obj_t badge_eink_png(mp_obj_t obj_x, mp_obj_t obj_y, mp_obj_t obj_file { int x = mp_obj_get_int(obj_x); int y = mp_obj_get_int(obj_y); - const char* filename = mp_obj_str_get_str(obj_filename); if (x >= BADGE_EINK_WIDTH || y >= BADGE_EINK_HEIGHT) { return mp_const_none; } - struct lib_file_reader *fr = lib_file_new(filename, 1024); - if (fr == NULL) - { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Could not open file '%s'!",filename)); - return mp_const_none; + lib_reader_read_t reader; + void * reader_p; + + bool is_bytes = MP_OBJ_IS_TYPE(obj_filename, &mp_type_bytes); + + if (is_bytes) { + size_t len; + const uint8_t* png_data = (const uint8_t *) mp_obj_str_get_data(obj_filename, &len); + struct lib_mem_reader *mr = lib_mem_new(png_data, len); + if (mr == NULL) + { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "out of memory!")); + return mp_const_none; + } + reader = (lib_reader_read_t) &lib_mem_read; + reader_p = mr; + + } else { + const char* filename = mp_obj_str_get_str(obj_filename); + struct lib_file_reader *fr = lib_file_new(filename, 1024); + if (fr == NULL) + { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Could not open file '%s'!",filename)); + return mp_const_none; + } + reader = (lib_reader_read_t) &lib_file_read; + reader_p = fr; } - struct lib_png_reader *pr = lib_png_new((lib_reader_read_t) &lib_file_read, fr); + struct lib_png_reader *pr = lib_png_new(reader, reader_p); if (pr == NULL) { - lib_file_destroy(fr); + if (is_bytes) { + lib_mem_destroy(reader_p); + } else { + lib_file_destroy(reader_p); + } nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "out of memory.")); return mp_const_none; } @@ -254,20 +548,121 @@ STATIC mp_obj_t badge_eink_png(mp_obj_t obj_x, mp_obj_t obj_y, mp_obj_t obj_file uint32_t dst_min_y = y < 0 ? -y : 0; int res = lib_png_load_image(pr, &badge_eink_fb[y * BADGE_EINK_WIDTH + x], dst_min_x, dst_min_y, BADGE_EINK_WIDTH - x, BADGE_EINK_HEIGHT - y, BADGE_EINK_WIDTH); lib_png_destroy(pr); - lib_file_destroy(fr); + if (is_bytes) { + lib_mem_destroy(reader_p); + } else { + lib_file_destroy(reader_p); + } if (res < 0) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "failed to load image: res = %i", res)); + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "failed to load image: res = %d", res)); } return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_3(badge_eink_png_obj, badge_eink_png); +STATIC mp_obj_t badge_eink_png_info(mp_obj_t obj_filename) +{ + lib_reader_read_t reader; + void * reader_p; + + bool is_bytes = MP_OBJ_IS_TYPE(obj_filename, &mp_type_bytes); + + if (is_bytes) { + size_t len; + const uint8_t* png_data = (const uint8_t *) mp_obj_str_get_data(obj_filename, &len); + struct lib_mem_reader *mr = lib_mem_new(png_data, len); + if (mr == NULL) + { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "out of memory!")); + return mp_const_none; + } + reader = (lib_reader_read_t) &lib_mem_read; + reader_p = mr; + + } else { + const char* filename = mp_obj_str_get_str(obj_filename); + struct lib_file_reader *fr = lib_file_new(filename, 1024); + if (fr == NULL) + { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Could not open file '%s'!",filename)); + return mp_const_none; + } + reader = (lib_reader_read_t) &lib_file_read; + reader_p = fr; + } + + struct lib_png_reader *pr = lib_png_new(reader, reader_p); + if (pr == NULL) + { + if (is_bytes) { + lib_mem_destroy(reader_p); + } else { + lib_file_destroy(reader_p); + } + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "out of memory.")); + return mp_const_none; + } + + int res = lib_png_read_header(pr); + + mp_obj_t tuple[4]; + if (res >= 0) { + tuple[0] = mp_obj_new_int(pr->ihdr.width); + tuple[1] = mp_obj_new_int(pr->ihdr.height); + tuple[2] = mp_obj_new_int(pr->ihdr.bit_depth); + tuple[3] = mp_obj_new_int(pr->ihdr.color_type); + } + + lib_png_destroy(pr); + if (is_bytes) { + lib_mem_destroy(reader_p); + } else { + lib_file_destroy(reader_p); + } + + if (res < 0) + { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "failed to load image: res = %d", res)); + } + + return mp_obj_new_tuple(4, tuple); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(badge_eink_png_info_obj, badge_eink_png_info); + /* END OF PNG READER TEST */ -// Power + +/* Raw frame display */ +STATIC mp_obj_t badge_eink_display_raw(mp_obj_t obj_img, mp_obj_t obj_flags) +{ + bool is_bytes = MP_OBJ_IS_TYPE(obj_img, &mp_type_bytes); + + if (!is_bytes) { + mp_raise_msg(&mp_type_AttributeError, "First argument should be a bytestring"); + } + + // convert the input buffer into a byte array + mp_uint_t len; + uint8_t *buffer = (uint8_t *)mp_obj_str_get_data(obj_img, &len); + + int flags = mp_obj_get_int(obj_flags); + int expect_len = (flags & DISPLAY_FLAG_8BITPIXEL) ? BADGE_EINK_WIDTH*BADGE_EINK_HEIGHT : BADGE_EINK_WIDTH*BADGE_EINK_HEIGHT/8; + if (len != expect_len) { + mp_raise_msg(&mp_type_AttributeError, "First argument has wrong length"); + } + + // display the image directly + badge_eink_display(buffer, flags); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(badge_eink_display_raw_obj, badge_eink_display_raw); + + +// Power (badge_power.h) STATIC mp_obj_t badge_power_init_() { badge_power_init(); @@ -275,37 +670,54 @@ STATIC mp_obj_t badge_power_init_() { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_power_init_obj, badge_power_init_); -#if defined(PORTEXP_PIN_NUM_CHRGSTAT) || defined(MPR121_PIN_NUM_CHRGSTAT) STATIC mp_obj_t battery_charge_status_() { return mp_obj_new_bool(badge_battery_charge_status()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(battery_charge_status_obj, - battery_charge_status_); -#endif +STATIC MP_DEFINE_CONST_FUN_OBJ_0(battery_charge_status_obj, battery_charge_status_); -#ifdef ADC1_CHAN_VBAT_SENSE STATIC mp_obj_t battery_volt_sense_() { return mp_obj_new_int(badge_battery_volt_sense()); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(battery_volt_sense_obj, battery_volt_sense_); -#endif -#ifdef ADC1_CHAN_VUSB_SENSE STATIC mp_obj_t usb_volt_sense_() { return mp_obj_new_int(badge_usb_volt_sense()); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(usb_volt_sense_obj, usb_volt_sense_); -#endif + + +STATIC mp_obj_t badge_power_leds_enable_() { + return mp_obj_new_int(badge_power_leds_enable()); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_power_leds_enable_obj, badge_power_leds_enable_); + +STATIC mp_obj_t badge_power_leds_disable_() { + return mp_obj_new_int(badge_power_leds_disable()); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_power_leds_disable_obj, badge_power_leds_disable_); + + +STATIC mp_obj_t badge_power_sdcard_enable_() { + return mp_obj_new_int(badge_power_sdcard_enable()); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_power_sdcard_enable_obj, badge_power_sdcard_enable_); + +STATIC mp_obj_t badge_power_sdcard_disable_() { + return mp_obj_new_int(badge_power_sdcard_disable()); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_power_sdcard_disable_obj, badge_power_sdcard_disable_); + // LEDs -#if defined(PIN_NUM_LED) || defined(MPR121_PIN_NUM_LEDS) +#if defined(PIN_NUM_LEDS) STATIC mp_obj_t badge_leds_init_() { badge_leds_init(); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_leds_init_obj, badge_leds_init_); + STATIC mp_obj_t badge_leds_enable_() { return mp_obj_new_int(badge_leds_enable()); } @@ -316,12 +728,26 @@ STATIC mp_obj_t badge_leds_disable_() { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_leds_disable_obj, badge_leds_disable_); + STATIC mp_obj_t badge_leds_send_data_(mp_uint_t n_args, const mp_obj_t *args) { - mp_uint_t len = mp_obj_get_int(args[1]); + bool is_bytes = MP_OBJ_IS_TYPE(args[0], &mp_type_bytes); + + if (!is_bytes) { + printf("badge.leds_send_data() used with string object instead of bytestring object.\n"); + } + + mp_uint_t len; uint8_t *leds = (uint8_t *)mp_obj_str_get_data(args[0], &len); + if (n_args > 1) { + mp_uint_t arglen = mp_obj_get_int(args[1]); + if (len != arglen) { + printf("badge.leds_send_data() len mismatch. (%d != %d)\n", len, arglen); + } + } + return mp_obj_new_int(badge_leds_send_data(leds, len)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(badge_leds_send_data_obj, 2,2 ,badge_leds_send_data_); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(badge_leds_send_data_obj, 1,2 ,badge_leds_send_data_); #endif #if defined(PORTEXP_PIN_NUM_VIBRATOR) || defined(MPR121_PIN_NUM_VIBRATOR) @@ -338,15 +764,161 @@ STATIC mp_obj_t badge_vibrator_activate_(mp_uint_t n_args, const mp_obj_t *args) STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(badge_vibrator_activate_obj, 1,1 ,badge_vibrator_activate_); #endif + +// Mounts +static bool root_mounted = false; +static wl_handle_t s_wl_handle = WL_INVALID_HANDLE; +STATIC mp_obj_t badge_mount_root() { + // already mounted? + if (root_mounted) + { + return mp_const_none; + } + + // mount the block device + const esp_vfs_fat_mount_config_t mount_config = { + .max_files = 3, + .format_if_mount_failed = true, + }; + + ESP_LOGI(TAG, "mounting locfd on /"); + esp_err_t err = esp_vfs_fat_spiflash_mount("", "locfd", &mount_config, &s_wl_handle); + + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to mount FATFS (0x%x)", err); + mp_raise_OSError(MP_EIO); + } + + root_mounted = true; + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_mount_root_obj, badge_mount_root); + +static bool sdcard_mounted = false; +STATIC mp_obj_t badge_mount_sdcard() { + // already mounted? + if (sdcard_mounted) + { + return mp_const_none; + } + + badge_power_sdcard_enable(); + + sdmmc_host_t host = SDMMC_HOST_DEFAULT(); + + // To use 1-line SD mode, uncomment the following line: + host.flags = SDMMC_HOST_FLAG_1BIT; + + // This initializes the slot without card detect (CD) and write protect (WP) signals. + // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals. + sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); + + // Options for mounting the filesystem. + // If format_if_mount_failed is set to true, SD card will be partitioned and formatted + // in case when mounting fails. + esp_vfs_fat_sdmmc_mount_config_t mount_config = { + .max_files = 3, + .format_if_mount_failed = false, + }; + + // Use settings defined above to initialize SD card and mount FAT filesystem. + // Note: esp_vfs_fat_sdmmc_mount is an all-in-one convenience function. + // Please check its source code and implement error recovery when developing + // production applications. + sdmmc_card_t* card; + esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card); + if (ret != ESP_OK) { + if (ret == ESP_FAIL) { + ESP_LOGE(TAG, "Failed to mount filesystem. If you want the card to be formatted, set format_if_mount_failed = true."); + } else { + ESP_LOGE(TAG, "Failed to initialize the card (%d). Make sure SD card lines have pull-up resistors in place.", ret); + } + mp_raise_OSError(MP_EIO); + return mp_const_none; + } + + sdcard_mounted = true; + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_mount_sdcard_obj, badge_mount_sdcard); + +STATIC mp_obj_t badge_unmount_sdcard() { + // not mounted? + if (!sdcard_mounted) + { + return mp_const_none; + } + +/* + sdcard_mounted = false; + + // All done, unmount partition and disable SDMMC host peripheral + esp_vfs_fat_sdmmc_unmount(); + ESP_LOGI(TAG, "Card unmounted"); + + badge_power_sdcard_disable(); +*/ + printf("Unmounting the sdcard is not yet supported.\n"); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_unmount_sdcard_obj, badge_unmount_sdcard); + +static bool bpp_mounted = false; +STATIC mp_obj_t badge_mount_bpp() { + // already mounted? + if (bpp_mounted) + { + return mp_const_none; + } + + bpp_mount_ropart(); + + bpp_mounted = true; + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(badge_mount_bpp_obj, badge_mount_bpp); + + // Module globals STATIC const mp_rom_map_elem_t badge_module_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_badge)}, {MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&badge_init_obj)}, + + // I2C + {MP_ROM_QSTR(MP_QSTR_i2c_read_reg), MP_ROM_PTR(&badge_i2c_read_reg_obj)}, + {MP_ROM_QSTR(MP_QSTR_i2c_write_reg), MP_ROM_PTR(&badge_i2c_write_reg_obj)}, + + // audio + {MP_OBJ_NEW_QSTR(MP_QSTR_play_mp3_stream), (mp_obj_t)&badge_play_mp3_stream_obj}, + + // Mpr121 +#ifdef I2C_MPR121_ADDR + {MP_ROM_QSTR(MP_QSTR_mpr121_get_touch_info), MP_ROM_PTR(&badge_mpr121_get_touch_info_obj)}, +#endif // I2C_MPR121_ADDR + + // E-Ink {MP_ROM_QSTR(MP_QSTR_eink_init), MP_ROM_PTR(&badge_eink_init_obj)}, + {MP_ROM_QSTR(MP_QSTR_eink_deep_sleep), MP_ROM_PTR(&badge_eink_deep_sleep_obj)}, + {MP_ROM_QSTR(MP_QSTR_eink_wakeup), MP_ROM_PTR(&badge_eink_wakeup_obj)}, + + // Power {MP_OBJ_NEW_QSTR(MP_QSTR_power_init), (mp_obj_t)&badge_power_init_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_battery_charge_status), (mp_obj_t)&battery_charge_status_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_battery_volt_sense), (mp_obj_t)&battery_volt_sense_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_usb_volt_sense), (mp_obj_t)&usb_volt_sense_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_power_leds_enable), (mp_obj_t)&badge_power_leds_enable_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_power_leds_disable), (mp_obj_t)&badge_power_leds_disable_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_power_sdcard_enable), (mp_obj_t)&badge_power_sdcard_enable_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_power_sdcard_disable), (mp_obj_t)&badge_power_sdcard_disable_obj}, + // NVS + {MP_ROM_QSTR(MP_QSTR_nvs_erase_all), MP_ROM_PTR(&badge_nvs_erase_all_obj)}, {MP_ROM_QSTR(MP_QSTR_nvs_erase_key), MP_ROM_PTR(&badge_nvs_erase_key_obj)}, {MP_ROM_QSTR(MP_QSTR_nvs_get_str), MP_ROM_PTR(&badge_nvs_get_str_obj)}, {MP_ROM_QSTR(MP_QSTR_nvs_set_str), MP_ROM_PTR(&badge_nvs_set_str_obj)}, @@ -355,8 +927,8 @@ STATIC const mp_rom_map_elem_t badge_module_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_nvs_get_u16), MP_ROM_PTR(&badge_nvs_get_u16_obj)}, {MP_ROM_QSTR(MP_QSTR_nvs_set_u16), MP_ROM_PTR(&badge_nvs_set_u16_obj)}, - -#if defined(PIN_NUM_LED) || defined(MPR121_PIN_NUM_LEDS) +#if defined(PIN_NUM_LEDS) + // LEDs {MP_OBJ_NEW_QSTR(MP_QSTR_leds_init), (mp_obj_t)&badge_leds_init_obj}, {MP_OBJ_NEW_QSTR(MP_QSTR_leds_enable), (mp_obj_t)&badge_leds_enable_obj}, {MP_OBJ_NEW_QSTR(MP_QSTR_leds_disable), (mp_obj_t)&badge_leds_disable_obj}, @@ -372,23 +944,21 @@ STATIC const mp_rom_map_elem_t badge_module_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_eink_busy_wait), MP_ROM_PTR(&badge_eink_busy_wait_obj)}, {MP_ROM_QSTR(MP_QSTR_eink_png), MP_ROM_PTR(&badge_eink_png_obj)}, + {MP_ROM_QSTR(MP_QSTR_eink_png_info), MP_ROM_PTR(&badge_eink_png_info_obj)}, + {MP_ROM_QSTR(MP_QSTR_eink_display_raw), MP_ROM_PTR(&badge_eink_display_raw_obj)}, /* - {MP_ROM_QSTR(MP_QSTR_display_picture), - MP_ROM_PTR(&badge_display_picture_obj)}, + {MP_ROM_QSTR(MP_QSTR_display_picture), MP_ROM_PTR(&badge_display_picture_obj)}, */ -#if defined(PORTEXP_PIN_NUM_CHRGSTAT) || defined(MPR121_PIN_NUM_CHRGSTAT) - {MP_OBJ_NEW_QSTR(MP_QSTR_battery_charge_status), - (mp_obj_t)&battery_charge_status_obj}, -#endif -#ifdef ADC1_CHAN_VBAT_SENSE - {MP_OBJ_NEW_QSTR(MP_QSTR_battery_volt_sense), - (mp_obj_t)&battery_volt_sense_obj}, -#endif -#ifdef ADC1_CHAN_VUSB_SENSE - {MP_OBJ_NEW_QSTR(MP_QSTR_usb_volt_sense), (mp_obj_t)&usb_volt_sense_obj}, -#endif + // Mounts + {MP_OBJ_NEW_QSTR(MP_QSTR_mount_root), (mp_obj_t)&badge_mount_root_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_mount_sdcard), (mp_obj_t)&badge_mount_sdcard_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_unmount_sdcard), (mp_obj_t)&badge_unmount_sdcard_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_mount_bpp), (mp_obj_t)&badge_mount_bpp_obj}, + + {MP_OBJ_NEW_QSTR(MP_QSTR_safe_mode), (mp_obj_t)&badge_safe_mode_obj}, + }; STATIC MP_DEFINE_CONST_DICT(badge_module_globals, badge_module_globals_table); diff --git a/esp32/modbadge.h b/esp32/modbadge.h index e677df1df..4cb746fb0 100644 --- a/esp32/modbadge.h +++ b/esp32/modbadge.h @@ -13,6 +13,7 @@ #include "badge_vibrator.h" #include "badge_nvs.h" +#include "mem_reader.h" #include "file_reader.h" #include "png_reader.h" diff --git a/esp32/modbpp.c b/esp32/modbpp.c new file mode 100644 index 000000000..8e7811e8c --- /dev/null +++ b/esp32/modbpp.c @@ -0,0 +1,105 @@ +#include +#include +#include "esp_spi_flash.h" +#include "wear_levelling.h" + +#include "drivers/dht/dht.h" +#include "modesp.h" +#include "py/mperrno.h" +#include "py/mphal.h" +#include "py/runtime.h" + +STATIC wl_handle_t fs_handle = WL_INVALID_HANDLE; +STATIC size_t wl_sect_size = 4096; + +STATIC const esp_partition_t *fs_part = NULL; + +static void bpp_flash_init(void) { + if (fs_handle != WL_INVALID_HANDLE) + return; + + if (fs_part == NULL) { + fs_part = esp_partition_find_first(0x20, 0x17, "remfs"); + if (fs_part == NULL) { + printf("Bpp partition not found.\n"); + mp_raise_OSError(MP_EIO); + } + } + + esp_err_t res = wl_mount(fs_part, &fs_handle); + if (res != ESP_OK) { + printf("Failed to initialize wear-leveling on bpp partition.\n"); + mp_raise_OSError(MP_EIO); + } + + wl_sect_size = wl_sector_size(fs_handle); +} + +STATIC mp_obj_t bpp_flash_read(mp_obj_t offset_in, mp_obj_t buf_in) { + bpp_flash_init(); + mp_int_t offset = mp_obj_get_int(offset_in); + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_WRITE); + + esp_err_t res = wl_read(fs_handle, offset, bufinfo.buf, bufinfo.len); + if (res != ESP_OK) { + mp_raise_OSError(MP_EIO); + } + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(bpp_flash_read_obj, bpp_flash_read); + +STATIC mp_obj_t bpp_flash_write(mp_obj_t offset_in, mp_obj_t buf_in) { + bpp_flash_init(); + mp_int_t offset = mp_obj_get_int(offset_in); + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); + + esp_err_t res = wl_write(fs_handle, offset, bufinfo.buf, bufinfo.len); + if (res != ESP_OK) { + mp_raise_OSError(MP_EIO); + } + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(bpp_flash_write_obj, bpp_flash_write); + +STATIC mp_obj_t bpp_flash_erase(mp_obj_t sector_in) { + bpp_flash_init(); + mp_int_t sector = mp_obj_get_int(sector_in); + + esp_err_t res = wl_erase_range(fs_handle, sector * wl_sect_size, wl_sect_size); + if (res != ESP_OK) { + mp_raise_OSError(MP_EIO); + } + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bpp_flash_erase_obj, bpp_flash_erase); + +STATIC mp_obj_t bpp_flash_size(void) { + bpp_flash_init(); + return mp_obj_new_int_from_uint(fs_part->size); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(bpp_flash_size_obj, bpp_flash_size); + +STATIC mp_obj_t bpp_flash_sec_size() { + bpp_flash_init(); + return mp_obj_new_int_from_uint(wl_sect_size); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(bpp_flash_sec_size_obj, bpp_flash_sec_size); + + +STATIC const mp_rom_map_elem_t bpp_module_globals_table[] = { + {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bpp)}, + + { MP_ROM_QSTR(MP_QSTR_flash_read), MP_ROM_PTR(&bpp_flash_read_obj) }, + { MP_ROM_QSTR(MP_QSTR_flash_write), MP_ROM_PTR(&bpp_flash_write_obj) }, + { MP_ROM_QSTR(MP_QSTR_flash_erase), MP_ROM_PTR(&bpp_flash_erase_obj) }, + { MP_ROM_QSTR(MP_QSTR_flash_size), MP_ROM_PTR(&bpp_flash_size_obj) }, + { MP_ROM_QSTR(MP_QSTR_flash_sec_size), MP_ROM_PTR(&bpp_flash_sec_size_obj) }, +}; + +STATIC MP_DEFINE_CONST_DICT(bpp_module_globals, bpp_module_globals_table); + +const mp_obj_module_t bpp_module = { + .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&bpp_module_globals, +}; diff --git a/esp32/modbpp.h b/esp32/modbpp.h new file mode 100644 index 000000000..ec29539c7 --- /dev/null +++ b/esp32/modbpp.h @@ -0,0 +1,2 @@ +#include "esprtcmem.h" +#include "esp_spi_flash.h" diff --git a/esp32/modesp.c b/esp32/modesp.c index 133e3a10b..93656328d 100644 --- a/esp32/modesp.c +++ b/esp32/modesp.c @@ -49,6 +49,97 @@ #include "sdmmc_cmd.h" #endif +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_task_wdt.h" + +/* esp.temperature_sens_read() */ +extern int temprature_sens_read(); +STATIC mp_obj_t esp_temperature_sens_read() { + return mp_obj_new_int_from_uint(temprature_sens_read()); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_temperature_sens_read_obj, esp_temperature_sens_read); + +/* esp.hall_sens_read() */ +extern int hall_sens_read(); +STATIC mp_obj_t esp_hall_sens_read() { + return mp_obj_new_int_from_uint(hall_sens_read()); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_hall_sens_read_obj, esp_hall_sens_read); + + +/* esp.wdt_start() */ +STATIC mp_obj_t esp_wdt_start(mp_obj_t timeout) { + // reconfigure watchdog + mp_int_t t = mp_obj_get_int(timeout); + esp_err_t res = esp_task_wdt_init(t, true); + if (res != ESP_OK) { + if (res == ESP_ERR_NO_MEM) + mp_raise_msg(&mp_type_MemoryError, "WDT: Out of memory"); + mp_raise_msg(&mp_type_NotImplementedError, "WDT: Unknown error"); + } + + // add current task + res = esp_task_wdt_add(NULL); + if (res != ESP_OK) { + if (res == ESP_ERR_INVALID_ARG) + mp_raise_msg(&mp_type_AttributeError, "WDT: Task is already subscribed"); + if (res == ESP_ERR_NO_MEM) + mp_raise_msg(&mp_type_MemoryError, "WDT: Out of memory"); + if (res == ESP_ERR_INVALID_STATE) + mp_raise_msg(&mp_type_AttributeError, "WDT: Not initialized"); + mp_raise_msg(&mp_type_NotImplementedError, "WDT: Unknown error"); + } + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_wdt_start_obj, esp_wdt_start); + +/* esp.wdt_stop() */ +STATIC mp_obj_t esp_wdt_stop(void) { + // remove current task + esp_err_t res = esp_task_wdt_delete(NULL); + if (res != ESP_OK) { + if (res == ESP_ERR_INVALID_ARG) + mp_raise_msg(&mp_type_AttributeError, "WDT: Task is already unsubscribed"); + if (res == ESP_ERR_INVALID_STATE) + mp_raise_msg(&mp_type_AttributeError, "WDT: Not initialized"); + mp_raise_msg(&mp_type_NotImplementedError, "WDT: Unknown error"); + } + + // reconfigure watchdog to startup-state. +#ifdef CONFIG_TASK_WDT_PANIC + res = esp_task_wdt_init(CONFIG_TASK_WDT_TIMEOUT_S, true); +#elif CONFIG_TASK_WDT + res = esp_task_wdt_init(CONFIG_TASK_WDT_TIMEOUT_S, false); +#endif + if (res != ESP_OK) { + if (res == ESP_ERR_NO_MEM) + mp_raise_msg(&mp_type_MemoryError, "WDT: Out of memory"); + mp_raise_msg(&mp_type_NotImplementedError, "WDT: Unknown error"); + } + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_wdt_stop_obj, esp_wdt_stop); + +/* esp.wdt_reset() */ +STATIC mp_obj_t esp_wdt_reset(void) { + esp_err_t res = esp_task_wdt_reset(); + if (res != ESP_OK) { + if (res == ESP_ERR_NOT_FOUND) + mp_raise_msg(&mp_type_AttributeError, "WDT: Task is not subscribed"); + if (res == ESP_ERR_INVALID_STATE) + mp_raise_msg(&mp_type_AttributeError, "WDT: Not initialized"); + mp_raise_msg(&mp_type_NotImplementedError, "WDT: Unknown error"); + } + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_wdt_reset_obj, esp_wdt_reset); + + +/* flash */ STATIC wl_handle_t fs_handle = WL_INVALID_HANDLE; STATIC size_t wl_sect_size = 4096; @@ -361,6 +452,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_sdcard_sect_size_obj, esp_sdcard_sect_size) STATIC const mp_rom_map_elem_t esp_module_globals_table[] = { {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_esp)}, + { MP_ROM_QSTR(MP_QSTR_temperature_sens_read), MP_ROM_PTR(&esp_temperature_sens_read_obj) }, + { MP_ROM_QSTR(MP_QSTR_hall_sens_read), MP_ROM_PTR(&esp_hall_sens_read_obj) }, + + { MP_ROM_QSTR(MP_QSTR_wdt_start), MP_ROM_PTR(&esp_wdt_start_obj) }, + { MP_ROM_QSTR(MP_QSTR_wdt_stop), MP_ROM_PTR(&esp_wdt_stop_obj) }, + { MP_ROM_QSTR(MP_QSTR_wdt_reset), MP_ROM_PTR(&esp_wdt_reset_obj) }, + { MP_ROM_QSTR(MP_QSTR_flash_read), MP_ROM_PTR(&esp_flash_read_obj) }, { MP_ROM_QSTR(MP_QSTR_flash_write), MP_ROM_PTR(&esp_flash_write_obj) }, { MP_ROM_QSTR(MP_QSTR_flash_erase), MP_ROM_PTR(&esp_flash_erase_obj) }, diff --git a/esp32/modfreedomgfx.c b/esp32/modfreedomgfx.c new file mode 100644 index 000000000..4fdf7f015 --- /dev/null +++ b/esp32/modfreedomgfx.c @@ -0,0 +1,266 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * SHA2017 Badge Firmware https://wiki.sha2017.org/w/Projects:Badge/MicroPython + * + * Based on work by EMF for their TiLDA MK3 badge + * https://github.com/emfcamp/micropython/tree/tilda-master/stmhal + * + * The MIT License (MIT) + * + * Copyright (c) 2015 Paul Sokolovsky + * Copyright (c) 2016 Damien P. George + * Copyright (c) 2017 Anne Jan Brouwer + * Copyright (c) 2017 Christian Carlowitz + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + + +#include "py/mperrno.h" +#include "py/mphal.h" +#include "py/runtime.h" + +#include "py/nlr.h" +#include "py/runtime.h" + +#ifdef UNIX +#include "modfreedomgfx_sdl.h" +#else +#include "modfreedomgfx_eink.h" +#endif + +#define imgSize (BADGE_EINK_WIDTH*BADGE_EINK_HEIGHT) +static uint8_t* img = 0; + +#define PX(x,y,v) \ + if( x>=0 && y>=0 && x < BADGE_EINK_WIDTH && y < BADGE_EINK_HEIGHT) \ + img[((x)+(y)*BADGE_EINK_WIDTH)] = (v) + +#define ABS(x) (((x)<0)?-(x):(x)) + +static void gfx_input_poll(uint32_t btn); + +STATIC mp_obj_t gfx_init(void) { + img = freedomgfxInit(); + memset(img, 0xff, imgSize); + freedomgfxDraw(); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(gfx_init_obj, gfx_init); + +STATIC mp_obj_t gfx_deinit(void) { + freedomgfxDeinit(); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(gfx_deinit_obj, gfx_deinit); + +STATIC mp_obj_t gfx_poll(void) { + uint32_t evt = freedomgfxPoll(); + gfx_input_poll(evt); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(gfx_poll_obj, gfx_poll); + +STATIC mp_obj_t gfx_line(mp_uint_t n_args, const mp_obj_t *args) { + int x0 = mp_obj_get_int(args[0]); + int y0 = mp_obj_get_int(args[1]); + int x1 = mp_obj_get_int(args[2]); + int y1 = mp_obj_get_int(args[3]); + int col = mp_obj_get_int(args[4]); + + PX(x0,y0,col); + + // algorithm: https://de.wikipedia.org/wiki/Bresenham-Algorithmus + int dx = ABS(x1-x0); + int sx = x0 dy) + { + err += dy; + x0 += sx; + } + if (err2 < dx) + { + err += dx; + y0 += sy; + } + } + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gfx_line_obj, 5, 5, gfx_line); + +STATIC mp_obj_t gfx_area(mp_uint_t n_args, const mp_obj_t *args) { + int x0 = mp_obj_get_int(args[0]); + int y0 = mp_obj_get_int(args[1]); + int a = mp_obj_get_int(args[2]); + int b = mp_obj_get_int(args[3]); + int col = mp_obj_get_int(args[4]); + + for(int i = 0; i < a; i++) + { + for(int j = 0; j < b; j++) + PX(x0+i,y0+j,col); + } + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gfx_area_obj, 5, 5, gfx_area); + + +static const uint8_t tm12x6_font[] = { +#include "../share/fonts/Lat2-Terminus12x6.inc" +}; + +STATIC mp_obj_t gfx_string(mp_uint_t n_args, const mp_obj_t *args) { + mp_uint_t len; + const unsigned char *data = (const unsigned char*) mp_obj_str_get_data(args[2], &len); + int x0 = mp_obj_get_int(args[0]); + int y0 = mp_obj_get_int(args[1]); + int col = mp_obj_get_int(args[4]); + + const uint8_t* font = tm12x6_font; + int clen = ((int*)font)[5]; + int cheight = ((int*)font)[6]; + int cwidth = ((int*)font)[7]; + + int xoffs = 0; + while(*data != 0) + { + for(int i = 0; i < cheight; i++) + { + for(int j = 0; j < cwidth; j++) // TODO: only works for single byte rows + { + if( font[4*8+(int)(*data)*clen+i] & (1<<(7-j))) + PX(x0+j+xoffs,y0+i,col); + } + } + data++; + xoffs += cwidth; + + if(*data == '\n') + { + xoffs = 0; + y0 += cheight; + data++; + } + } + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gfx_string_obj, 5, 5, gfx_string); + + +STATIC mp_obj_t gfx_flush(mp_uint_t n_args, const mp_obj_t *args) { + freedomgfxDraw(); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gfx_flush_obj, 0, 1, gfx_flush); + + +// callback system + +STATIC bool button_init_done = false; +STATIC mp_obj_t button_callbacks[1+BADGE_BUTTONS]; + +static void gfx_input_poll(uint32_t btn) +{ + if(button_init_done && btn > 0 && btn <= BADGE_BUTTONS) + { + if(button_callbacks[btn] != mp_const_none) + mp_sched_schedule(button_callbacks[btn], mp_obj_new_bool(0)); + } +} + +STATIC mp_obj_t gfx_input_init(mp_uint_t n_args, const mp_obj_t *args) { + for(size_t i = 0; i <= BADGE_BUTTONS; i++){ + button_callbacks[i] = mp_const_none; + } + button_init_done = true; + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gfx_input_init_obj, 0, 1, gfx_input_init); + +STATIC mp_obj_t gfx_input_attach(mp_uint_t n_args, const mp_obj_t *args) { + int button = mp_obj_get_int(args[0]); + if(button > 0 && button <= BADGE_BUTTONS) + button_callbacks[button] = args[1]; + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gfx_input_attach_obj, 2, 2, gfx_input_attach); + + +// Module globals + +STATIC const mp_rom_map_elem_t freedomgfx_module_globals_table[] = { + {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_freedomgfx)}, + + {MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&gfx_init_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&gfx_deinit_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_poll), (mp_obj_t)&gfx_poll_obj}, + + {MP_OBJ_NEW_QSTR(MP_QSTR_line), (mp_obj_t)&gfx_line_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_area), (mp_obj_t)&gfx_area_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_string), (mp_obj_t)&gfx_string_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_flush), (mp_obj_t)&gfx_flush_obj}, + + {MP_OBJ_NEW_QSTR(MP_QSTR_input_init), (mp_obj_t)&gfx_input_init_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_input_attach), (mp_obj_t)&gfx_input_attach_obj}, + + {MP_OBJ_NEW_QSTR(MP_QSTR_BLACK), MP_OBJ_NEW_SMALL_INT(0x00)}, + {MP_OBJ_NEW_QSTR(MP_QSTR_WHITE), MP_OBJ_NEW_SMALL_INT(0xff)}, + + {MP_OBJ_NEW_QSTR(MP_QSTR_JOY_UP), MP_OBJ_NEW_SMALL_INT(BADGE_BUTTON_UP)}, + {MP_OBJ_NEW_QSTR(MP_QSTR_JOY_DOWN), MP_OBJ_NEW_SMALL_INT(BADGE_BUTTON_DOWN)}, + {MP_OBJ_NEW_QSTR(MP_QSTR_JOY_LEFT), MP_OBJ_NEW_SMALL_INT(BADGE_BUTTON_LEFT)}, + {MP_OBJ_NEW_QSTR(MP_QSTR_JOY_RIGHT), MP_OBJ_NEW_SMALL_INT(BADGE_BUTTON_RIGHT)}, + {MP_OBJ_NEW_QSTR(MP_QSTR_BTN_A), MP_OBJ_NEW_SMALL_INT(BADGE_BUTTON_A)}, + {MP_OBJ_NEW_QSTR(MP_QSTR_BTN_B), MP_OBJ_NEW_SMALL_INT(BADGE_BUTTON_B)}, + {MP_OBJ_NEW_QSTR(MP_QSTR_BTN_SELECT), MP_OBJ_NEW_SMALL_INT(BADGE_BUTTON_SELECT)}, + {MP_OBJ_NEW_QSTR(MP_QSTR_BTN_START), MP_OBJ_NEW_SMALL_INT(BADGE_BUTTON_START)}, + {MP_OBJ_NEW_QSTR(MP_QSTR_BTN_FLASH), MP_OBJ_NEW_SMALL_INT(BADGE_BUTTON_FLASH)}, + +}; + +STATIC MP_DEFINE_CONST_DICT(freedomgfx_module_globals, freedomgfx_module_globals_table); + +const mp_obj_module_t freedomgfx_module = { + .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&freedomgfx_module_globals, +}; + diff --git a/esp32/modfreedomgfx_eink.c b/esp32/modfreedomgfx_eink.c new file mode 100644 index 000000000..0d9fcbcca --- /dev/null +++ b/esp32/modfreedomgfx_eink.c @@ -0,0 +1,59 @@ +/* + * This file is part of the SHA2017 Micro Python fork + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Christian Carlowitz + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "modfreedomgfx_eink.h" +#include +#include +#include + +extern bool ugfx_screen_flipped; + +uint8_t* freedomgfxInit(void) +{ + badge_eink_fb_init(); + return badge_eink_fb; +} + +void freedomgfxDeinit(void) +{ + // +} + +uint32_t freedomgfxPoll(void) +{ + uint32_t btn = badge_input_get_event(0); + return btn; +} + +void freedomgfxDraw() +{ + badge_eink_flags_t flags = DISPLAY_FLAG_FULL_UPDATE | DISPLAY_FLAG_8BITPIXEL; + if(ugfx_screen_flipped) + flags |= DISPLAY_FLAG_ROTATE_180; + badge_eink_display(badge_eink_fb, flags); +} diff --git a/esp32/modfreedomgfx_eink.h b/esp32/modfreedomgfx_eink.h new file mode 100644 index 000000000..4ef8e8be6 --- /dev/null +++ b/esp32/modfreedomgfx_eink.h @@ -0,0 +1,37 @@ +/* + * This file is part of the SHA2017 Micro Python fork + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Christian Carlowitz + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef UNIX_MODFREEDOMGFX_SDL_H_ +#define UNIX_MODFREEDOMGFX_SDL_H_ + +#include + +uint8_t* freedomgfxInit(void); // returns buffer to draw to +void freedomgfxDeinit(void); +uint32_t freedomgfxPoll(void); +void freedomgfxDraw(); + +#endif /* UNIX_MODFREEDOMGFX_SDL_H_ */ diff --git a/esp32/modmachine.c b/esp32/modmachine.c index 09a1dbc7c..f3aa75125 100644 --- a/esp32/modmachine.c +++ b/esp32/modmachine.c @@ -90,21 +90,21 @@ STATIC mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *pos_args, mp_ma mp_int_t expiry = args[ARG_sleep_ms].u_int; if (expiry != 0) { - esp_deep_sleep_enable_timer_wakeup(expiry * 1000); + esp_sleep_enable_timer_wakeup(expiry * 1000); } if (machine_rtc_config.ext0_pin != -1) { - esp_deep_sleep_enable_ext0_wakeup(machine_rtc_config.ext0_pin, machine_rtc_config.ext0_level ? 1 : 0); + esp_sleep_enable_ext0_wakeup(machine_rtc_config.ext0_pin, machine_rtc_config.ext0_level ? 1 : 0); } if (machine_rtc_config.ext1_pins != 0) { - esp_deep_sleep_enable_ext1_wakeup( + esp_sleep_enable_ext1_wakeup( machine_rtc_config.ext1_pins, machine_rtc_config.ext1_level ? ESP_EXT1_WAKEUP_ANY_HIGH : ESP_EXT1_WAKEUP_ALL_LOW); } if (machine_rtc_config.wake_on_touch) { - esp_deep_sleep_enable_touchpad_wakeup(); + esp_sleep_enable_touchpad_wakeup(); } esp_deep_sleep_start(); diff --git a/esp32/modnetwork.c b/esp32/modnetwork.c index 3fdbf3786..88407d6b7 100644 --- a/esp32/modnetwork.c +++ b/esp32/modnetwork.c @@ -60,13 +60,13 @@ NORETURN void _esp_exceptions(esp_err_t e) { mp_raise_msg(&mp_type_OSError, "Wifi Internal Error"); case ESP_ERR_WIFI_SSID: mp_raise_msg(&mp_type_OSError, "Wifi SSID Invalid"); - case ESP_ERR_WIFI_FAIL: + case ESP_FAIL: mp_raise_msg(&mp_type_OSError, "Wifi Internal Failure"); case ESP_ERR_WIFI_IF: mp_raise_msg(&mp_type_OSError, "Wifi Invalid Interface"); case ESP_ERR_WIFI_MAC: mp_raise_msg(&mp_type_OSError, "Wifi Invalid MAC Address"); - case ESP_ERR_WIFI_ARG: + case ESP_ERR_INVALID_ARG: mp_raise_msg(&mp_type_OSError, "Wifi Invalid Argument"); case ESP_ERR_WIFI_MODE: mp_raise_msg(&mp_type_OSError, "Wifi Invalid Mode"); @@ -83,7 +83,7 @@ NORETURN void _esp_exceptions(esp_err_t e) { case ESP_ERR_WIFI_TIMEOUT: mp_raise_OSError(MP_ETIMEDOUT); case ESP_ERR_TCPIP_ADAPTER_NO_MEM: - case ESP_ERR_WIFI_NO_MEM: + case ESP_ERR_NO_MEM: mp_raise_OSError(MP_ENOMEM); default: nlr_raise(mp_obj_new_exception_msg_varg( @@ -188,6 +188,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(get_wlan_obj, 0, 1, get_wlan); STATIC mp_obj_t esp_initialize() { static int initialized = 0; if (!initialized) { + // wifi binary does not listens to compuiler log level, and must be set at runtime + esp_log_level_set("wifi", ESP_LOG_WARN); + ESP_LOGD("modnetwork", "Initializing TCP/IP"); tcpip_adapter_init(); ESP_LOGD("modnetwork", "Initializing Event Loop"); diff --git a/esp32/modugfx.c b/esp32/modugfx.c index 171eb003f..3eea6fd1c 100644 --- a/esp32/modugfx.c +++ b/esp32/modugfx.c @@ -62,6 +62,7 @@ uint8_t target_lut; typedef struct _ugfx_obj_t { mp_obj_base_t base; } ugfx_obj_t; +extern bool ugfx_screen_flipped; static orientation_t get_orientation(int a){ if (a == 90) return GDISP_ROTATE_90; @@ -146,11 +147,19 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(ugfx_get_lut_obj, ugfx_get_lut); STATIC mp_obj_t ugfx_set_orientation(mp_uint_t n_args, const mp_obj_t *args) { if (n_args > 0){ int a = mp_obj_get_int(args[0]); + a %= 360; + if (a >= 180) { + ugfx_screen_flipped = true; + a -= 180; + } gdispSetOrientation(get_orientation(a)); - } - return mp_obj_new_int(gdispGetOrientation()); + int a = gdispGetOrientation(); + if (ugfx_screen_flipped) + a += 180; + a %= 360; + return mp_obj_new_int(a); } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ugfx_set_orientation_obj, 0, 1, ugfx_set_orientation); @@ -181,12 +190,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(ugfx_height_obj, ugfx_height); /// STATIC mp_obj_t ugfx_get_pixel(mp_obj_t x_in, mp_obj_t y_in) { // extract arguments - //ugfx_obj_t *self = args[0]; - //int x = mp_obj_get_int(x_in); - //int y = mp_obj_get_int(y_in); - return mp_obj_new_int(0); - //needs sorting, currently returns somewhat dodgy values - //return mp_obj_new_int(gdispGetPixelColor(x,y)); + int x = mp_obj_get_int(x_in); + int y = mp_obj_get_int(y_in); + + return mp_obj_new_int(gdispGetPixelColor(x,y)); } STATIC MP_DEFINE_CONST_FUN_OBJ_2(ugfx_get_pixel_obj, ugfx_get_pixel); @@ -885,7 +892,10 @@ STATIC mp_obj_t ugfx_demo(mp_obj_t hacking) { #ifdef UNIX mp_hal_delay_ms(EMU_EINK_SCREEN_DELAY_MS); #endif + uint8_t target_lut_backup = target_lut; + target_lut = 0xff; gdispFlush(); + target_lut = target_lut_backup; return mp_const_none; } @@ -1102,12 +1112,14 @@ STATIC const mp_rom_map_elem_t ugfx_module_globals_table[] = { {MP_OBJ_NEW_QSTR(MP_QSTR_LUT_FULL), MP_OBJ_NEW_SMALL_INT(BADGE_EINK_LUT_FULL)}, {MP_OBJ_NEW_QSTR(MP_QSTR_LUT_NORMAL), MP_OBJ_NEW_SMALL_INT(BADGE_EINK_LUT_NORMAL)}, {MP_OBJ_NEW_QSTR(MP_QSTR_LUT_FASTER), MP_OBJ_NEW_SMALL_INT(BADGE_EINK_LUT_FASTER)}, - {MP_OBJ_NEW_QSTR(MP_QSTR_LUT_FASTEST), MP_OBJ_NEW_SMALL_INT(BADGE_EINK_LUT_FASTEST)}, - {MP_OBJ_NEW_QSTR(MP_QSTR_LUT_DEFAULT), MP_OBJ_NEW_SMALL_INT(BADGE_EINK_LUT_DEFAULT)}, - {MP_OBJ_NEW_QSTR(MP_QSTR_LUT_MAX), MP_OBJ_NEW_SMALL_INT(BADGE_EINK_LUT_MAX)}, + {MP_OBJ_NEW_QSTR(MP_QSTR_LUT_FASTEST), MP_OBJ_NEW_SMALL_INT(BADGE_EINK_LUT_FASTEST)}, + {MP_OBJ_NEW_QSTR(MP_QSTR_LUT_DEFAULT), MP_OBJ_NEW_SMALL_INT(BADGE_EINK_LUT_DEFAULT)}, + {MP_OBJ_NEW_QSTR(MP_QSTR_LUT_MAX), MP_OBJ_NEW_SMALL_INT(BADGE_EINK_LUT_MAX)}, + + {MP_OBJ_NEW_QSTR(MP_QSTR_GREYSCALE), MP_OBJ_NEW_SMALL_INT(0xff)}, - {MP_OBJ_NEW_QSTR(MP_QSTR_set_lut), (mp_obj_t)&ugfx_set_lut_obj}, - {MP_OBJ_NEW_QSTR(MP_QSTR_get_lut), (mp_obj_t)&ugfx_get_lut_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_set_lut), (mp_obj_t)&ugfx_set_lut_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_get_lut), (mp_obj_t)&ugfx_get_lut_obj}, {MP_OBJ_NEW_QSTR(MP_QSTR_clear), (mp_obj_t)&ugfx_clear_obj}, {MP_OBJ_NEW_QSTR(MP_QSTR_flush), (mp_obj_t)&ugfx_flush_obj}, @@ -1122,6 +1134,7 @@ STATIC const mp_rom_map_elem_t ugfx_module_globals_table[] = { {MP_OBJ_NEW_QSTR(MP_QSTR_text), (mp_obj_t)&ugfx_text_obj }, {MP_OBJ_NEW_QSTR(MP_QSTR_string_box), (mp_obj_t)&ugfx_string_box_obj}, + {MP_OBJ_NEW_QSTR(MP_QSTR_get_pixel), (mp_obj_t)&ugfx_get_pixel_obj}, {MP_OBJ_NEW_QSTR(MP_QSTR_pixel), (mp_obj_t)&ugfx_pixel_obj}, {MP_OBJ_NEW_QSTR(MP_QSTR_line), (mp_obj_t)&ugfx_line_obj}, {MP_OBJ_NEW_QSTR(MP_QSTR_box), (mp_obj_t)&ugfx_box_obj}, diff --git a/esp32/modules/_boot.py b/esp32/modules/_boot.py index dfff125e7..f92b22543 100644 --- a/esp32/modules/_boot.py +++ b/esp32/modules/_boot.py @@ -1,10 +1,6 @@ -import gc, uos +import badge, gc, uos -try: - uos.mount(uos.VfsNative(True), '/') - open("/boot.py", "r") -except OSError: - import inisetup - vfs = inisetup.setup() +badge.mount_root() +uos.mount(uos.VfsNative(None), '/') gc.collect() diff --git a/esp32/modules/appglue.py b/esp32/modules/appglue.py index 69306bf3b..0067b42ad 100644 --- a/esp32/modules/appglue.py +++ b/esp32/modules/appglue.py @@ -10,7 +10,6 @@ def start_app(app, display = True): ugfx.string(0, 25, "Returning to homescreen...","Roboto_Regular12",ugfx.BLACK) ugfx.flush(ugfx.LUT_FASTER) esp.rtcmem_write_string(app) - badge.eink_busy_wait() deepsleep.reboot() def home(): @@ -21,7 +20,8 @@ def start_ota(): esp.rtcmem_write(1,254) deepsleep.reboot() -def start_bpp(): +def start_bpp(duration): + print("[BPP] Duration = "+str(duration)) esp.rtcmem_write(0,2) esp.rtcmem_write(1,253) deepsleep.reboot() diff --git a/esp32/modules/boot.py b/esp32/modules/boot.py new file mode 100644 index 000000000..20fd742bd --- /dev/null +++ b/esp32/modules/boot.py @@ -0,0 +1,60 @@ +# This file is executed on every boot (including wake-boot from deepsleep) +import badge, machine, esp, ugfx, sys, time +badge.init() +ugfx.init() + +esp.rtcmem_write(0,0) +esp.rtcmem_write(1,0) + +# setup timezone +timezone = badge.nvs_get_str('system', 'timezone', 'CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00') +time.settimezone(timezone) + +if badge.safe_mode(): + splash = 'splash' +else: + splash = badge.nvs_get_str('boot','splash','splash') + +if machine.reset_cause() != machine.DEEPSLEEP_RESET: + print('[BOOT] Cold boot') +else: + print("[BOOT] Wake from sleep") + load_me = esp.rtcmem_read_string() + if load_me: + splash = load_me + print("starting %s" % load_me) + esp.rtcmem_write_string("") + +try: + if not splash=="shell": + if splash.startswith('bpp '): + splash = splash[4:len(splash)] + badge.mount_bpp() + elif splash.startswith('sdcard '): + splash = splash[7:len(splash)] + badge.mount_sdcard() + __import__(splash) + else: + ugfx.clear(ugfx.WHITE) + ugfx.flush(ugfx.LUT_FULL) +except BaseException as e: + sys.print_exception(e) + import easydraw + easydraw.msg("A fatal error occured!","Still Crashing Anyway", True) + easydraw.msg("") + + # if we started the splash screen and it is not the default splash screen, + # then revert to original splash screen. + if splash == badge.nvs_get_str('boot', 'splash', 'splash') and splash != 'splash': + easydraw.msg("Disabling custom splash screen.") + easydraw.msg("") + badge.nvs_erase_key('boot', 'splash') + + easydraw.msg("Guru meditation:") + easydraw.msg(str(e)) + easydraw.msg("") + easydraw.msg("Rebooting in 5 seconds...") + import time + time.sleep(5) + import appglue + appglue.home() diff --git a/esp32/modules/deepsleep.py b/esp32/modules/deepsleep.py index 2eed2379b..eac233e84 100644 --- a/esp32/modules/deepsleep.py +++ b/esp32/modules/deepsleep.py @@ -1,11 +1,13 @@ -import machine +import machine, badge pin = machine.Pin(25) rtc = machine.RTC() rtc.wake_on_ext0(pin = pin, level = 0) def start_sleeping(time=0): + badge.eink_busy_wait() machine.deepsleep(time) def reboot(): + badge.eink_busy_wait() machine.deepsleep(1) diff --git a/esp32/modules/easydraw.py b/esp32/modules/easydraw.py new file mode 100644 index 000000000..13917b2e8 --- /dev/null +++ b/esp32/modules/easydraw.py @@ -0,0 +1,63 @@ +# File: easydraw.py +# Version: 1 +# Description: Wrapper that makes drawing things simple +# License: MIT +# Authors: Renze Nicolai + +import ugfx, badge + +# Functions +def msg(message, title = 'Still Loading Anyway...', reset = False): + """Show a terminal style loading screen with title + + title can be optionaly set when resetting or first call + """ + global messageHistory + + try: + messageHistory + if reset: + raise exception + except: + ugfx.clear(ugfx.WHITE) + ugfx.string(0, 0, title, "PermanentMarker22", ugfx.BLACK) + messageHistory = [] + + if len(messageHistory)<6: + ugfx.string(0, 30 + (len(messageHistory) * 15), message, "Roboto_Regular12", ugfx.BLACK) + messageHistory.append(message) + else: + messageHistory.pop(0) + messageHistory.append(message) + ugfx.area(0,30, 296, 98, ugfx.WHITE) + for i, message in enumerate(messageHistory): + ugfx.string(0, 30 + (i * 15), message, "Roboto_Regular12", ugfx.BLACK) + + ugfx.flush(ugfx.LUT_FASTER) + +def nickname(y = 25, font = "PermanentMarker36", color = ugfx.BLACK): + nick = badge.nvs_get_str("owner", "name", 'Henk de Vries') + ugfx.string_box(0,y,296,38, nick, font, color, ugfx.justifyCenter) + +def battery(on_usb, vBatt, charging): + vMin = badge.nvs_get_u16('batt', 'vmin', 3500) # mV + vMax = badge.nvs_get_u16('batt', 'vmax', 4100) # mV + if charging and on_usb: + try: + badge.eink_png(0,0,'/lib/resources/chrg.png') + except: + ugfx.string(0, 0, "CHRG",'Roboto_Regular12',ugfx.BLACK) + elif on_usb: + try: + badge.eink_png(0,0,'/lib/resources/usb.png') + except: + ugfx.string(0, 0, "USB",'Roboto_Regular12',ugfx.BLACK) + else: + width = round((vBatt-vMin) / (vMax-vMin) * 44) + if width < 0: + width = 0 + elif width > 38: + width = 38 + ugfx.box(2,2,46,18,ugfx.BLACK) + ugfx.box(48,7,2,8,ugfx.BLACK) + ugfx.area(3,3,width,16,ugfx.BLACK) diff --git a/esp32/modules/easyrtc.py b/esp32/modules/easyrtc.py new file mode 100644 index 000000000..757663ead --- /dev/null +++ b/esp32/modules/easyrtc.py @@ -0,0 +1,47 @@ +# File: easyrtc.py +# Version: 1 +# Description: Wrapper that makes using the clock simple +# License: MIT +# Authors: Renze Nicolai + +import machine, time + +# Functions +def string(print_date=False, print_time=True, timestamp = -1): + if timestamp<0: + [year, month, mday, wday, hour, minute, second, microseconds] = machine.RTC().datetime() + else: + [year, month, mday, hour, minute, second, wday, yday] = time.localtime(timestamp) + #mday: day in month, wday: day in week, yday: day in year + monthstr = str(month) + if (month<10): + monthstr = "0"+monthstr + daystr = str(mday) + if (mday<10): + daystr = "0"+daystr + hourstr = str(hour) + if (hour<10): + hourstr = "0"+hourstr + minstr = str(minute) + if (minute<10): + minstr = "0"+minstr + output = "" + if print_date: + output += daystr+"-"+monthstr+"-"+str(year) + if time: + output += " " + if print_time: + output += hourstr+":"+minstr + return output + +def configure(): + import easywifi + import easydraw + import ntp + if not easywifi.status(): + if not easywifi.enable(): + return False + easydraw.msg("Configuring clock...") + ntp.set_NTP_time() + easydraw.msg("Done") + return True diff --git a/esp32/modules/easywifi.py b/esp32/modules/easywifi.py new file mode 100644 index 000000000..d2d24a20b --- /dev/null +++ b/esp32/modules/easywifi.py @@ -0,0 +1,61 @@ +# File: easywifi.py +# Version: 1 +# Description: Wrapper that makes using wifi simple +# License: MIT +# Authors: Renze Nicolai + +import time, network, badge, easydraw + +state = False +failed = False + +def status(): + global state + return state + +def failure(): + global failed + return failed + +def force_enable(): + global state + state = False + global failed + failed = False + enable() + +def enable(showStatus=True): + global failed + global state + if not state: + nw = network.WLAN(network.STA_IF) + if not nw.isconnected(): + nw.active(True) + ssid = badge.nvs_get_str('badge', 'wifi.ssid', 'SHA2017-insecure') + password = badge.nvs_get_str('badge', 'wifi.password') + if showStatus: + easydraw.msg("Connecting to '"+ssid+"'...") + nw.connect(ssid, password) if password else nw.connect(ssid) + timeout = badge.nvs_get_u8('badge', 'wifi.timeout', 40) + while not nw.isconnected(): + time.sleep(0.1) + timeout = timeout - 1 + if (timeout<1): + if showStatus: + easydraw.msg("Error: could not connect!") + disable() + failed = True + return False + state = True + failed = False + if showStatus: + easydraw.msg("Connected!") + return True + +def disable(): + global state + state = False + global failed + failed = False + nw = network.WLAN(network.STA_IF) + nw.active(False) diff --git a/esp32/modules/inisetup.py b/esp32/modules/inisetup.py deleted file mode 100644 index 3cdd0bbb7..000000000 --- a/esp32/modules/inisetup.py +++ /dev/null @@ -1,26 +0,0 @@ -import uos - -def setup(): - print("Performing initial setup") - vfs = uos.VfsNative(True) - with open("/boot.py", "w") as f: - f.write("""\ -# This file is executed on every boot (including wake-boot from deepsleep) -import badge, machine, esp, ugfx -badge.init() -ugfx.init() -esp.rtcmem_write(0,0) -esp.rtcmem_write(1,0) -splash = badge.nvs_get_str('badge','boot.splash','splash') -if machine.reset_cause() != machine.DEEPSLEEP_RESET: - print('[BOOT.PY] Cold boot') -else: - print("[BOOT.PY] Wake from sleep") - load_me = esp.rtcmem_read_string() - if load_me: - splash = load_me - print("starting %s" % load_me) - esp.rtcmem_write_string("") -__import__(splash) -""") - return vfs diff --git a/esp32/modules/installer.py b/esp32/modules/installer.py index 86903ffd3..d4fe12e53 100644 --- a/esp32/modules/installer.py +++ b/esp32/modules/installer.py @@ -1,4 +1,4 @@ -import ugfx, badge, network, gc, time, urequests, appglue +import ugfx, badge, network, gc, time, urequests, appglue, sys # SHA2017 Badge installer # V2 Thomas Roos @@ -29,7 +29,7 @@ def connectWiFi(): draw_msg("Connecting to '"+ssid+"'...") - timeout = badge.nvs_get_u8('splash', 'wifi.timeout', 40) + timeout = 150 while not nw.isconnected(): time.sleep(0.1) timeout = timeout - 1 @@ -50,8 +50,9 @@ def select_category(active): global categories global options index = options.selected_index() - category = categories[index]["slug"] - list_apps(category) + if categories[index]["eggs"] > 0: + category = categories[index]["slug"] + list_apps(category) def list_apps(slug): global options @@ -67,25 +68,34 @@ def list_apps(slug): while options.count() > 0: options.remove_item(0) text.text("Downloading list of eggs...") - ugfx.flush() + ugfx.flush(ugfx.LUT_FULL) try: - f = urequests.get("https://badge.sha2017.org/eggs/category/%s/json" % slug) - packages = f.json() - finally: - f.close() + f = urequests.get("https://badge.sha2017.org/eggs/category/%s/json" % slug, timeout=30) + try: + packages = f.json() + finally: + f.close() + except BaseException as e: + print("[Installer] Failed to download list of eggs:") + sys.print_exception(e) + text.text("Download failed") + ugfx.flush(ugfx.LUT_FULL) + list_categories() + gc.collect() + return for package in packages: options.add_item("%s rev. %s" % (package["name"], package["revision"])) + options.selected_index(0) ugfx.input_attach(ugfx.JOY_UP, show_description) ugfx.input_attach(ugfx.JOY_DOWN, show_description) ugfx.input_attach(ugfx.BTN_A, install_app) - ugfx.input_attach(ugfx.BTN_B, lambda pushed: list_categories() if pushed else 0) - ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app('') if pushed else 0) + ugfx.input_attach(ugfx.BTN_B, lambda pushed: list_categories() if pushed else False) + ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app('') if pushed else False) show_description(True) - ugfx.set_lut(ugfx.LUT_FASTER) gc.collect() def start_categories(pushed): @@ -117,18 +127,31 @@ def install_app(active): ugfx.string(100,55, packages[index]["name"],"PermanentMarker22",ugfx.WHITE) ugfx.flush() + latest = False import woezel selected_app = packages[index]["slug"] - woezel.install(selected_app) + try: + woezel.install(selected_app) + except woezel.LatestInstalledError: + latest = True + except: + ugfx.string(160,85,"Failed","Roboto_BlackItalic24",ugfx.WHITE) + ugfx.flush() + time.sleep(4) + list_categories() + return ugfx.clear(ugfx.WHITE) - ugfx.string(40,25,"Installed:","Roboto_BlackItalic24",ugfx.BLACK) + if latest: + ugfx.string(40,25,"Already installed:","Roboto_BlackItalic24",ugfx.BLACK) + else: + ugfx.string(40,25,"Installed:","Roboto_BlackItalic24",ugfx.BLACK) ugfx.string(100,55, packages[index]["name"],"PermanentMarker22",ugfx.BLACK) ugfx.string(0, 115, "[ A: START | B: BACK ]", "Roboto_Regular12", ugfx.BLACK) ugfx.input_attach(ugfx.BTN_A, start_app) ugfx.input_attach(ugfx.BTN_B, start_categories) - ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app("") if pushed else 0) + ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app("") if pushed else False) ugfx.flush() gc.collect() @@ -144,7 +167,7 @@ def list_categories(): ugfx.input_init() draw_msg('Getting categories') try: - f = urequests.get("https://badge.sha2017.org/eggs/categories/json") + f = urequests.get("https://badge.sha2017.org/eggs/categories/json", timeout=30) categories = f.json() except: draw_msg('Failed!') @@ -158,11 +181,11 @@ def list_categories(): - ugfx.input_attach(ugfx.JOY_UP, lambda pushed: ugfx.flush() if pushed else 0) - ugfx.input_attach(ugfx.JOY_DOWN, lambda pushed: ugfx.flush() if pushed else 0) + ugfx.input_attach(ugfx.JOY_UP, lambda pushed: ugfx.flush() if pushed else False) + ugfx.input_attach(ugfx.JOY_DOWN, lambda pushed: ugfx.flush() if pushed else False) ugfx.input_attach(ugfx.BTN_A, select_category) - ugfx.input_attach(ugfx.BTN_B, lambda pushed: appglue.start_app("launcher", False) if pushed else 0) - ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app("") if pushed else 0) + ugfx.input_attach(ugfx.BTN_B, lambda pushed: appglue.start_app("launcher", False) if pushed else False) + ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app("") if pushed else False) ugfx.clear(ugfx.WHITE) ugfx.flush() @@ -171,11 +194,12 @@ def list_categories(): options.remove_item(0) for category in categories: options.add_item("%s (%d) >" % (category["name"], category["eggs"])) + options.selected_index(0) text.text("Install or update eggs from the hatchery here\n\n\n\n") ugfx.string_box(148,0,148,26, "Hatchery", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) ugfx.line(148, 78, 296, 78, ugfx.BLACK) - ugfx.string_box(148,78,148,18, " A: Open catergory", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) + ugfx.string_box(148,78,148,18, " A: Open category", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.string_box(148,92,148,18, " B: Return to home", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.line(148, 110, 296, 110, ugfx.BLACK) ugfx.string_box(148,110,148,18, " badge.sha2017.org", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) diff --git a/esp32/modules/launcher.py b/esp32/modules/launcher.py index 28bfb9197..2c03692fa 100644 --- a/esp32/modules/launcher.py +++ b/esp32/modules/launcher.py @@ -1,59 +1,115 @@ -import ugfx, badge, sys, uos as os, appglue, version - -ugfx.init() -ugfx.input_init() -ugfx.set_lut(ugfx.LUT_FASTER) -ugfx.clear(ugfx.BLACK) -ugfx.flush() -ugfx.clear(ugfx.WHITE) -ugfx.flush() - -ugfx.string_box(148,0,148,26, "STILL", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) -ugfx.string_box(148,23,148,23, "Hacking", "PermanentMarker22", ugfx.BLACK, ugfx.justifyCenter) -ugfx.string_box(148,48,148,26, "Anyway", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) - -#the line under the text -str_len = ugfx.get_string_width("Hacking","PermanentMarker22") -line_begin = 148 + int((148-str_len)/2) -line_end = str_len+line_begin -ugfx.line(line_begin, 46, line_end, 46, ugfx.BLACK) - -#the cursor past the text -cursor_pos = line_end+5 -ugfx.line(cursor_pos, 22, cursor_pos, 44, ugfx.BLACK) - -# Instructions -ugfx.line(148, 78, 296, 78, ugfx.BLACK) -ugfx.string_box(148,78,148,18, " A: Run", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) -ugfx.string_box(148,78,148,18, " B: Return to home", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyRight) -ugfx.string_box(148,92,148,18, " SELECT: Uninstall", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) -ugfx.line(148, 110, 296, 110, ugfx.BLACK) -ugfx.string_box(148,110,148,18, " " + version.name, "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) - -# ugfx.flush() -options = None -install_path = None - -def populate_it(): - global options - options = ugfx.List(0,0,int(ugfx.width()/2),ugfx.height()) +import ugfx, badge, sys, uos as os, appglue, version, easydraw, virtualtimers, tasks.powermanagement as pm, dialogs, time, ujson, sys - try: - apps = os.listdir('lib') - except OSError: - apps = [] +# Application list - options.add_item('installer') - options.add_item('ota_update') +apps = [] +def add_app(app,information): + global apps + try: + title = information["name"] + except: + title = app + try: + category = information["category"] + except: + category = "" + info = {"file":app,"title":title,"category":category} + apps.append(info) + +def populate_apps(): + global apps + apps = [] + try: + userApps = os.listdir('lib') + except OSError: + userApps = [] + for app in userApps: + add_app(app,read_metadata(app)) + add_app("installer",{"name":"Installer", "category":"system"}) + add_app("setup",{"name":"Set nickname", "category":"system"}) + add_app("update",{"name":"Update apps", "category":"system"}) + add_app("ota_update",{"name":"Update firmware", "category":"system"}) + +# List as shown on screen +currentListTitles = [] +currentListTargets = [] + +def populate_category(category="",system=True): + global apps + global currentListTitles + global currentListTargets + currentListTitles = [] + currentListTargets = [] for app in apps: - options.add_item(app) + if (category=="" or category==app["category"] or (system and app["category"]=="system")) and (not app["category"]=="hidden"): + currentListTitles.append(app["title"]) + currentListTargets.append(app) + +def populate_options(): + global options + options = ugfx.List(0,0,int(ugfx.width()/2),ugfx.height()) + global currentListTitles + for title in currentListTitles: + options.add_item(title) + +# Read app metadata +def read_metadata(app): + try: + install_path = get_install_path() + info_file = "%s/%s/metadata.json" % (install_path, app) + print("Reading "+info_file+"...") + with open(info_file) as f: + information = f.read() + return ujson.loads(information) + except BaseException as e: + print("[ERROR] Can not read metadata for app "+app) + sys.print_exception(e) + information = {"name":app,"description":"","category":"", "author":"","revision":0} + return [app,""] + +# Uninstaller + +def uninstall(): + global options + selected = options.selected_index() + options.destroy() + + global currentListTitles + global currentListTargets + + if currentListTargets[selected]["category"] == "system": + #dialogs.notice("System apps can not be removed!","Can not uninstall '"+currentListTitles[selected]+"'") + easydraw.msg("System apps can not be removed!","Error",True) + time.sleep(2) + start() + return + + def perform_uninstall(ok): + global install_path + if ok: + easydraw.msg("Removing "+currentListTitles[selected]+"...", "Still Uninstalling Anyway...",True) + install_path = get_install_path() + for rm_file in os.listdir("%s/%s" % (install_path, currentListTargets[selected]["file"])): + easydraw.msg("Deleting '"+rm_file+"'...") + os.remove("%s/%s/%s" % (install_path, currentListTargets[selected]["file"], rm_file)) + easydraw.msg("Deleting folder...") + os.rmdir("%s/%s" % (install_path, currentListTargets[selected]["file"])) + easydraw.msg("Uninstall completed!") + start() + + uninstall = dialogs.prompt_boolean('Are you sure you want to remove %s?' % currentListTitles[selected], cb=perform_uninstall) + +# Run app + +def run(): + global options + selected = options.selected_index() + options.destroy() + global currentListTargets + appglue.start_app(currentListTargets[selected]["file"]) -def run_it(pushed): - if (pushed): - selected = options.selected_text() - options.destroy() - appglue.start_app(selected) +# Path def expandhome(s): if "~/" in s: @@ -61,10 +117,6 @@ def expandhome(s): s = s.replace("~/", h + "/") return s -def gohome(pressed): - if(pressed): - appglue.home() - def get_install_path(): global install_path if install_path is None: @@ -73,40 +125,93 @@ def get_install_path(): install_path = expandhome(install_path) return install_path -def uninstall_it(pushed): - if (pushed): - selected = options.selected_text() - if selected == 'installer': - return - if selected == 'ota_update': - return - options.destroy() - - def perform_uninstall(ok): - if ok: - ugfx.clear(ugfx.BLACK) - ugfx.string_box(0, 25, 296, 25,"Uninstalling:","Roboto_BlackItalic24",ugfx.WHITE, ugfx.justifyCenter) - ugfx.string_box(0, 51, 296, 23, selected, "PermanentMarker22", ugfx.WHITE, ugfx.justifyCenter) - ugfx.flush() - install_path = get_install_path() - for rm_file in os.listdir("%s/%s" % (install_path, selected)): - os.remove("%s/%s/%s" % (install_path, selected, rm_file)) - os.rmdir("%s/%s" % (install_path, selected)) - badge.eink_busy_wait() - appglue.start_app('launcher') - - import dialogs - uninstall = dialogs.prompt_boolean('Are you sure you want to remove %s?' % selected, cb=perform_uninstall) - -populate_it() - -ugfx.input_attach(ugfx.BTN_A, run_it) -ugfx.input_attach(ugfx.BTN_SELECT, uninstall_it) - -ugfx.input_attach(ugfx.JOY_UP, lambda pushed: ugfx.flush() if pushed else 0) -ugfx.input_attach(ugfx.JOY_DOWN, lambda pushed: ugfx.flush() if pushed else 0) - -ugfx.input_attach(ugfx.BTN_B, lambda pushed: appglue.start_app("") if pushed else 0) -ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app("") if pushed else 0) - -ugfx.flush(ugfx.LUT_FULL) + +# Actions +def input_a(pressed): + pm.feed() + if pressed: + run() + +def input_b(pressed): + pm.feed() + if pressed: + appglue.home() + +def input_select(pressed): + pm.feed() + if pressed: + uninstall() + +def input_other(pressed): + pm.feed() + if pressed: + ugfx.flush() + +# Power management +def pm_cb(dummy): + appglue.home() + +def init_power_management(): + virtualtimers.activate(1000) # Start scheduler with 1 second ticks + pm.set_timeout(5*60*1000) # Set timeout to 5 minutes + pm.callback(pm_cb) # Go to splash instead of sleep + pm.feed() # Feed the power management task, starts the countdown... + +# Main application +def start(): + ugfx.input_init() + ugfx.set_lut(ugfx.LUT_FASTER) + ugfx.clear(ugfx.WHITE) + + if badge.safe_mode(): + still = "SAFE" + anyway = "Mode" + else: + still = "STILL" + anyway = "Anyway" + + ugfx.string_box(148,0,148,26, still, "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) + ugfx.string_box(148,23,148,23, "Hacking", "PermanentMarker22", ugfx.BLACK, ugfx.justifyCenter) + ugfx.string_box(148,48,148,26, anyway, "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) + + #the line under the text + str_len = ugfx.get_string_width("Hacking","PermanentMarker22") + line_begin = 148 + int((148-str_len)/2) + line_end = str_len+line_begin + ugfx.line(line_begin, 46, line_end, 46, ugfx.BLACK) + + #the cursor past the text + cursor_pos = line_end+5 + ugfx.line(cursor_pos, 22, cursor_pos, 44, ugfx.BLACK) + + # Instructions + ugfx.line(148, 78, 296, 78, ugfx.BLACK) + ugfx.string_box(148,78,148,18, " A: Run", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) + ugfx.string_box(148,78,148,18, " B: Return to home", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyRight) + ugfx.string_box(148,92,148,18, " SELECT: Uninstall", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) + ugfx.line(148, 110, 296, 110, ugfx.BLACK) + ugfx.string_box(148,110,148,18, " " + version.name, "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) + + global options + global install_path + options = None + install_path = None + + ugfx.input_attach(ugfx.BTN_A, input_a) + ugfx.input_attach(ugfx.BTN_B, input_b) + ugfx.input_attach(ugfx.BTN_SELECT, input_select) + ugfx.input_attach(ugfx.JOY_UP, input_other) + ugfx.input_attach(ugfx.JOY_DOWN, input_other) + ugfx.input_attach(ugfx.JOY_LEFT, input_other) + ugfx.input_attach(ugfx.JOY_RIGHT, input_other) + ugfx.input_attach(ugfx.BTN_START, input_other) + + populate_apps() + populate_category() + populate_options() + + # do a greyscale flush on start + ugfx.flush(ugfx.GREYSCALE) + +start() +init_power_management() diff --git a/esp32/modules/ntp.py b/esp32/modules/ntp.py index a906cf012..d0c31ed9d 100644 --- a/esp32/modules/ntp.py +++ b/esp32/modules/ntp.py @@ -1,7 +1,6 @@ ### Description: Update the badge's time via NTP ### License: MIT -import database import socket NTP_DELTA = 2208988800 @@ -43,14 +42,6 @@ def set_NTP_time(): print("Could not set time from NTP") return False - tz = 0 - with database.Database() as db: - tz = db.get("timezone", 200) # default to CEST - - tz_minutes = int(abs(tz) % 100) * (1 if tz >= 0 else -1) - tz_hours = int(tz / 100) - t += (tz_hours * 3600) + (tz_minutes * 60) - tm = time.localtime(t) tm = tm[0:3] + (0,) + tm[3:6] + (0,) diff --git a/esp32/modules/post_ota.py b/esp32/modules/post_ota.py new file mode 100644 index 000000000..857bc6902 --- /dev/null +++ b/esp32/modules/post_ota.py @@ -0,0 +1,23 @@ +import badge, easydraw + +def u0to1(): + easydraw.msg("Applied patch 1") + +def u1to2(): + badge.nvs_set_u8('sponsors', 'shown', 0) + easydraw.msg("Applied patch 2") + +# Read current patch level +lvl = badge.nvs_get_u8('ota', 'fixlvl', 0) + +if lvl<1: + easydraw.msg("Running post OTA scripts...","Still updating anyways...",) + u0to1() + easydraw.msg("Post OTA update completed") + badge.nvs_set_u8('ota', 'fixlvl', 1) + +if lvl<2: + easydraw.msg("Running post OTA scripts...","Still updating anyways...",) + u1to2() + easydraw.msg("Post OTA update completed") + badge.nvs_set_u8('ota', 'fixlvl', 2) diff --git a/esp32/modules/services.py b/esp32/modules/services.py deleted file mode 100644 index 1ba7c367d..000000000 --- a/esp32/modules/services.py +++ /dev/null @@ -1,57 +0,0 @@ -import uos - -# SHA2017 badge services -# Renze Nicolai -# Thomas Roos - -def setup(): - global services - try: - apps = uos.listdir('lib') - except OSError: - print("[SERVICES] Can't setup services: no lib folder!") - return False - found = False - for app in apps: - try: - files = uos.listdir('lib/'+app) - except OSError: - print("[SERVICES] Listing app files for app '"+app+"' failed!") - - for f in files: - if (f=="service.py"): - found = True - print("[SERVICES] Found service "+app+"...") - try: - srv = __import__('lib/'+app+'/service') - services.append(srv) #Add to global list - srv.setup() - except BaseException as msg: - print("Exception in service setup "+app+": ", msg) - break - return found - -def loop(lcnt): - noSleep = False - global services - for srv in services: - try: - if (srv.loop(lcnt)): - noSleep = True - except BaseException as msg: - print("[SERVICES] Service loop exception: ", msg) - return noSleep - -def draw(): - global services - x = 0 - y = 114 - for srv in services: - try: - space_used = srv.draw(x,y) - if (space_used>0): - y = y - abs(space_used) - except BaseException as msg: - print("[SERVICES] Service draw exception: ", msg) - -services = [] diff --git a/esp32/modules/setup.py b/esp32/modules/setup.py index ce1459787..c1e696de4 100644 --- a/esp32/modules/setup.py +++ b/esp32/modules/setup.py @@ -1,8 +1,11 @@ -# SETUP APPLICATION -# v2 by Thomas Roos -# v1 by Renze Nicolai +# File: setup.py +# Version: 3 +# Description: Setup for SHA2017 badge +# License: MIT +# Authors: Renze Nicolai +# Thomas Roos -import ugfx, badge, appglue, dialogs +import ugfx, badge, appglue, dialogs, easydraw, time def asked_nickname(value): if value: @@ -13,16 +16,15 @@ def asked_nickname(value): badge.nvs_set_u8('badge', 'setup.state', newState) # Show the user that we are done - ugfx.clear(ugfx.WHITE) - ugfx.string(0, 0, "Hi, " + value, "PermanentMarker22", ugfx.BLACK) - ugfx.string(0, 25, "Your nick is stored to flash!", "Roboto_Regular12", ugfx.BLACK) - ugfx.flush(ugfx.LUT_FASTER) + easydraw.msg("Hi "+value+"!", 'Your nick has been stored to flash!') + time.sleep(0.5) else: badge.nvs_set_u8('badge', 'setup.state', 2) # Skip the sponsors + badge.nvs_set_u8('sponsors', 'shown', 1) - badge.eink_busy_wait() - appglue.start_app("") + appglue.home() ugfx.init() nickname = badge.nvs_get_str("owner", "name", "") + dialogs.prompt_text("Nickname", nickname, cb=asked_nickname) diff --git a/esp32/modules/shell.py b/esp32/modules/shell.py new file mode 100644 index 000000000..54eafe26a --- /dev/null +++ b/esp32/modules/shell.py @@ -0,0 +1,2 @@ +import appglue +appglue.start_app("shell") diff --git a/esp32/modules/splash.py b/esp32/modules/splash.py index e0e93f37c..fccdaaf27 100644 --- a/esp32/modules/splash.py +++ b/esp32/modules/splash.py @@ -1,243 +1,186 @@ -import ugfx, time, ntp, badge, machine, appglue, deepsleep, network, esp, gc, services - -# SHA2017 badge home screen -# v2 Thomas Roos -# v1 Renze Nicolai - -def set_time_ntp(): - draw_msg("Configuring clock...") - if connectWiFi(): - draw_msg("Setting time over NTP...") - ntp.set_NTP_time() - draw_msg("Time set!") - return True +# File: splash.py +# Version: 6 +# Description: Homescreen for SHA2017 badge +# License: MIT +# Authors: Renze Nicolai +# Thomas Roos + +import ugfx, time, badge, machine, deepsleep, gc +import appglue, virtualtimers +import easydraw, easywifi, easyrtc + +import tasks.powermanagement as pm +import tasks.otacheck as otac +import tasks.resourcescheck as resc +import tasks.sponsorscheck as spoc +import tasks.services as services + +# Graphics + +def draw(mode, goingToSleep=False): + if mode: + # We flush the buffer and wait + ugfx.flush(ugfx.GREYSCALE) else: - draw_msg('RTC not set! :(') - return False - -def draw_msg(msg): - global line_number - try: - line_number - except: - line_number = 0 + # We prepare the screen refresh ugfx.clear(ugfx.WHITE) - ugfx.string(0, 0, 'Still Loading Anyway...', "PermanentMarker22", ugfx.BLACK) - ugfx.set_lut(ugfx.LUT_FASTER) - draw_msg(msg) - else: - ugfx.string(0, 30 + (line_number * 15), msg, "Roboto_Regular12", ugfx.BLACK) - ugfx.flush() - line_number += 1 - -def draw_home(do_BPP): - - vBatt = badge.battery_volt_sense() - vBatt += vDrop - - ugfx.clear(ugfx.WHITE) - - width = round((vBatt-vMin) / (vMax-vMin) * 38) - if width < 0: - width = 0 - elif width > 38: - width = 38 - - ugfx.box(2,2,40,18,ugfx.BLACK) - ugfx.box(42,7,2,8,ugfx.BLACK) - ugfx.area(3,3,width,16,ugfx.BLACK) - - if vBatt > 500: - if badge.battery_charge_status() and badge.usb_volt_sense() > 4000: - bat_status = 'Charging...' + if goingToSleep: + info1 = 'Sleeping...' + info2 = 'Press any key to wake up' else: - bat_status = str(round(vBatt/1000, 2)) + 'v' - else: - bat_status = 'No battery' - - ugfx.string(47, 2, bat_status,'Roboto_Regular18',ugfx.BLACK) - - - if do_BPP: - info = '[ ANY: Wake up ]' - elif OTA_available: - info = '[ SELECT: UPDATE | START: LAUNCHER ]' - ugfx.string(0, 115, 'OTA ready!', 'Roboto_Regular12', ugfx.BLACK) - else: - info = '[ START: LAUNCHER ]' - - l = ugfx.get_string_width(info,"Roboto_Regular12") - ugfx.string(296-l, 115, info, "Roboto_Regular12",ugfx.BLACK) - - ugfx.string(0, 40, nick, "PermanentMarker36", ugfx.BLACK) - services.draw() - - ugfx.flush(ugfx.LUT_FULL) + info1 = 'Press start to open the launcher' + if otac.available(False): + info2 = 'Press select to start OTA update' + else: + info2 = '' + + def disp_string_right(y, s): + l = ugfx.get_string_width(s,"Roboto_Regular12") + ugfx.string(296-l, y, s, "Roboto_Regular12",ugfx.BLACK) + + disp_string_right(0, info1) + disp_string_right(12, info2) + + if badge.safe_mode(): + disp_string_right(92, "Safe Mode - services disabled") + disp_string_right(104, "Sleep disabled - will drain battery quickly") + disp_string_right(116, "Press Reset button to exit") + + easydraw.nickname() + + on_usb = pm.usb_attached() + vBatt = badge.battery_volt_sense() + vBatt += vDrop + charging = badge.battery_charge_status() + + easydraw.battery(on_usb, vBatt, charging) + + if vBatt>500: + ugfx.string(52, 0, str(round(vBatt/1000, 1)) + 'v','Roboto_Regular12',ugfx.BLACK) + +# About + +def splash_about_countdown_reset(): + global splashAboutCountdown + splashAboutCountdown = badge.nvs_get_u8('splash', 'about.amount', 10) + +def splash_about_countdown_trigger(): + global splashAboutCountdown + try: + splashAboutCountdown + except: + splash_about_countdown_reset() - if do_BPP: - badge.eink_busy_wait() - # appglue.start_bpp() ## SHOULD BE THIS!! - deepsleep.start_sleeping() + splashAboutCountdown -= 1 + if splashAboutCountdown<0: + appglue.start_app('magic', False) else: - ugfx.input_attach(ugfx.BTN_SELECT, start_ota) - -def start_ota(pushed): - if pushed: - appglue.start_ota() + print("[SPLASH] Magic in "+str(splashAboutCountdown)+"...") -def press_nothing(pushed): - if pushed: - global loopCount - loopCount = badge.nvs_get_u8('splash', 'timer.amount', 50) +# Button input -def press_start(pushed): - if pushed: +def splash_input_start(pressed): + # Pressing start always starts the launcher + if pressed: appglue.start_app("launcher", False) -def press_a(pushed): - if pushed: - global loopCount - global magic - loopCount = badge.nvs_get_u8('splash', 'timer.amount', 50) - magic += 1 - if magic > 9: - appglue.start_app('magic', False) - else: - print("[SPLASH] Magic in "+str(10-magic)+"...") - -def sleepIfEmpty(vbatt): - global battery_volt_min - if (vbatt > 100) and (vbatt < battery_volt_min): - increment_reboot_counter() - print("[SPLASH] Going to sleep WITHOUT TIME WAKEUP now...") - badge.eink_busy_wait() #Always wait for e-ink - deepsleep.start_sleeping(0) #Sleep until button interrupt occurs - else: - return True +def splash_input_a(pressed): + if pressed: + splash_about_countdown_trigger() + pm.feed() -def splashTimer_callback(tmr): - global loopCount - try: - loopCount - except: - loopCount = badge.nvs_get_u8('splash', 'timer.amount', 50) - draw_home(False) - else: - if loopCount < 1 and badge.usb_volt_sense() < 4500: - draw_home(True) - else: - if not services.loop(loopCount): - loopCount -= 1 - -def disableWiFi(): - nw = network.WLAN(network.STA_IF) - nw.active(False) - -def connectWiFi(): - nw = network.WLAN(network.STA_IF) - if not nw.isconnected(): - nw.active(True) - ssid = badge.nvs_get_str('badge', 'wifi.ssid', 'SHA2017-insecure') - password = badge.nvs_get_str('badge', 'wifi.password') - nw.connect(ssid, password) if password else nw.connect(ssid) - - draw_msg("Connecting to '"+ssid+"'...") - - timeout = badge.nvs_get_u8('splash', 'wifi.timeout', 40) - while not nw.isconnected(): - time.sleep(0.1) - timeout = timeout - 1 - if (timeout<1): - draw_msg("Timeout while connecting!") - disableWiFi() - return False - return True - -def download_ota_info(): - import urequests as requests - draw_msg("Downloading OTA status...") - result = False - try: - data = requests.get("https://badge.sha2017.org/version") - except: - draw_msg("Could not download JSON!") - time.sleep(5) - return False - try: - result = data.json() - except: - data.close() - draw_msg("Could not decode JSON!") - time.sleep(5) - return False - data.close() - return result - -def check_ota_available(): - if connectWiFi(): - json = download_ota_info() - if (json): - import version - if (json["build"] > version.build): - badge.nvs_set_u8('badge','OTA.ready',1) - return True - else: - badge.nvs_set_u8('badge','OTA.ready',0) - return False +def splash_input_select(pressed): + if pressed: + if otac.available(False): + appglue.start_ota() + pm.feed() -def inputInit(): +def splash_input_other(pressed): + if pressed: + pm.feed() + +def splash_input_init(): + print("[SPLASH] Inputs attached") ugfx.input_init() - ugfx.input_attach(ugfx.BTN_START, press_start) - ugfx.input_attach(ugfx.BTN_A, press_a) - ugfx.input_attach(ugfx.BTN_B, press_nothing) - ugfx.input_attach(ugfx.BTN_SELECT, press_nothing) - ugfx.input_attach(ugfx.JOY_UP, press_nothing) - ugfx.input_attach(ugfx.JOY_DOWN, press_nothing) - ugfx.input_attach(ugfx.JOY_LEFT, press_nothing) - ugfx.input_attach(ugfx.JOY_RIGHT, press_nothing) - -def checkFirstBoot(): - setupcompleted = badge.nvs_get_u8('badge', 'setup.state', 0) - if setupcompleted == 0: # First boot (open setup) - print("[SPLASH] Setup not completed. Running setup!") - appglue.start_app("setup") - elif setupcompleted == 1: # Second boot (after setup) - print("[SPLASH] Showing sponsors once...") - badge.nvs_set_u8('badge', 'setup.state', 2) # Only force show sponsors once - appglue.start_app("sponsors") - elif setupcompleted == 2: - badge.nvs_set_u8('badge', 'setup.state', 3) - check_ota_available() - else: # Setup completed - print("[SPLASH] Normal boot.") - -nick = badge.nvs_get_str("owner", "name", 'Jan de Boer') -vMin = badge.nvs_get_u16('splash', 'bat.volt.min', 3600) # mV -vMax = badge.nvs_get_u16('splash', 'bat.volt.max', 4200) # mV -if badge.battery_charge_status() == False and badge.usb_volt_sense() > 4500 and badge.battery_volt_sense() > 2500: + ugfx.input_attach(ugfx.BTN_START, splash_input_start) + ugfx.input_attach(ugfx.BTN_A, splash_input_a) + ugfx.input_attach(ugfx.BTN_B, splash_input_other) + ugfx.input_attach(ugfx.BTN_SELECT, splash_input_select) + ugfx.input_attach(ugfx.JOY_UP, splash_input_other) + ugfx.input_attach(ugfx.JOY_DOWN, splash_input_other) + ugfx.input_attach(ugfx.JOY_LEFT, splash_input_other) + ugfx.input_attach(ugfx.JOY_RIGHT, splash_input_other) + +# Power management + +def onSleep(idleTime): + draw(False, True) + services.force_draw(True) + draw(True, True) + +### PROGRAM + +# Calibrate battery voltage drop +if badge.battery_charge_status() == False and pm.usb_attached() and badge.battery_volt_sense() > 2500: badge.nvs_set_u16('splash', 'bat.volt.drop', 5200 - badge.battery_volt_sense()) # mV print('Set vDrop to: ' + str(4200 - badge.battery_volt_sense())) vDrop = badge.nvs_get_u16('splash', 'bat.volt.drop', 1000) - 1000 # mV -inputInit() -magic = 0 - -checkFirstBoot() - -#If clock on time before 2017 -doOTA = set_time_ntp() if time.time() < 1482192000 else True - -if (machine.reset_cause() != machine.DEEPSLEEP_RESET) and doOTA: - OTA_available = check_ota_available() +splash_input_init() +splash_about_countdown_reset() + +# post ota script +import post_ota + +setupState = badge.nvs_get_u8('badge', 'setup.state', 0) +if setupState == 0: #First boot + print("[SPLASH] First boot (start setup)...") + appglue.start_app("setup") +elif setupState == 1: # Second boot: Show sponsors + print("[SPLASH] Second boot (show sponsors)...") + badge.nvs_set_u8('badge', 'setup.state', 2) + spoc.show(True) +elif setupState == 2: # Third boot: force OTA check + print("[SPLASH] Third boot (force ota check)...") + badge.nvs_set_u8('badge', 'setup.state', 3) + if not easywifi.failure(): + otac.available(True) +else: # Normal boot + print("[SPLASH] Normal boot... ("+str(machine.reset_cause())+")") + if (machine.reset_cause() != machine.DEEPSLEEP_RESET): + print("... from reset: checking for ota update") + if not easywifi.failure(): + otac.available(True) + +# RTC === +if time.time() < 1482192000: + easyrtc.configure() +# ======= + +if not easywifi.failure(): + resc.check() # Check resources +if not easywifi.failure(): + spoc.show(False) # Check sponsors + +if badge.safe_mode(): + draw(False) + services.force_draw() + draw(True) else: - OTA_available = badge.nvs_get_u8('badge','OTA.ready',0) - -ugfx.clear(ugfx.WHITE) -ugfx.flush(ugfx.LUT_FASTER) + have_services = services.setup(draw) # Start services + if not have_services: + draw(False) + services.force_draw() + draw(True) -foundService = services.setup() +easywifi.disable() +gc.collect() -splashTimer = machine.Timer(-1) -splashTimer.init(period=badge.nvs_get_u16('splash', 'timer.period', 100), mode=machine.Timer.PERIODIC, callback=splashTimer_callback) +virtualtimers.activate(25) +pm.callback(onSleep) +pm.feed() -gc.collect() +print("----") +print("WARNING: POWER MANAGEMENT ACTIVE") +print("To use shell type 'import shell' within 5 seconds.") +print("----") diff --git a/esp32/modules/tasks/otacheck.py b/esp32/modules/tasks/otacheck.py new file mode 100644 index 000000000..7d963ac82 --- /dev/null +++ b/esp32/modules/tasks/otacheck.py @@ -0,0 +1,43 @@ +# File: otacheck.py +# Version: 1 +# Description: OTA check module +# License: MIT +# Authors: Renze Nicolai + +import easywifi, easydraw, badge, time + +def download_info(): + import urequests as requests + easydraw.msg("Checking for updates...") + result = False + try: + data = requests.get("https://badge.sha2017.org/version") + except: + easydraw.msg("Error: could not download JSON!") + time.sleep(5) + return False + try: + result = data.json() + except: + data.close() + easydraw.msg("Error: could not decode JSON!") + time.sleep(5) + return False + data.close() + return result + +def available(update=False): + if update: + if not easywifi.status(): + if not easywifi.enable(): + return badge.nvs_get_u8('badge','OTA.ready',0) + + info = download_info() + if info: + import version + if info["build"] > version.build: + badge.nvs_set_u8('badge','OTA.ready',1) + return True + + badge.nvs_set_u8('badge','OTA.ready',0) + return badge.nvs_get_u8('badge','OTA.ready',0) diff --git a/esp32/modules/tasks/powermanagement.py b/esp32/modules/tasks/powermanagement.py new file mode 100644 index 000000000..a15548ac9 --- /dev/null +++ b/esp32/modules/tasks/powermanagement.py @@ -0,0 +1,62 @@ +# File: powermanagement.py +# Version: 2 +# Description: Power management task, puts the badge to sleep when idle +# License: MIT +# Authors: Renze Nicolai + +import virtualtimers, deepsleep, badge, sys + +requestedStandbyTime = 0 +onSleepCallback = None + +userResponseTime = badge.nvs_get_u16('splash', 'urt', 5000) + +def usb_attached(): + return badge.usb_volt_sense() > 4500 + +def pm_task(): + ''' The power management task [internal function] ''' + global requestedStandbyTime + + idleTime = virtualtimers.idle_time() + #print("[Power management] Next task wants to run in "+str(idleTime)+" ms.") + + if idleTime > 30000 and not badge.safe_mode() and not ( usb_attached() and badge.nvs_get_u8('badge', 'usb_stay_awake', 0) != 0 ): + global onSleepCallback + if not onSleepCallback==None: + print("[Power management] Running onSleepCallback...") + try: + onSleepCallback(idleTime) + except BaseException as e: + print("[ERROR] An error occured in the on sleep callback.") + sys.print_exception(e) + + if idleTime>=86400000: # One day + print("[Power management] Sleeping forever...") + deepsleep.start_sleeping() + else: + print("[Power management] Sleeping for "+str(idleTime)+" ms...") + deepsleep.start_sleeping(idleTime) + + global userResponseTime + return userResponseTime + +def feed(): + ''' Start / resets the power management task ''' + global userResponseTime + if not virtualtimers.update(userResponseTime, pm_task): + virtualtimers.new(userResponseTime, pm_task, True) + +def kill(): + ''' Kills the power management task ''' + virtualtimers.delete(pm_task) + +def callback(cb): + ''' Set a callback which is run before sleeping ''' + global onSleepCallback + onSleepCallback = cb + +def set_timeout(t): + ''' Set timeout ''' + global userResponseTime + userResponseTime = t diff --git a/esp32/modules/tasks/resourcescheck.py b/esp32/modules/tasks/resourcescheck.py new file mode 100644 index 000000000..111df1c93 --- /dev/null +++ b/esp32/modules/tasks/resourcescheck.py @@ -0,0 +1,32 @@ +# File: resourcecheck.py +# Version: 1 +# Description: Resources check module +# License: MIT +# Authors: Renze Nicolai + +import easywifi, easydraw, appglue + +def install(): + easydraw.msg("Installing resources...") + if not easywifi.status(): + if not easywifi.enable(): + return False + import woezel + woezel.install("resources") + appglue.home() + +def check(): + needToInstall = True + try: + with open("/lib/resources/version", "r") as f: + version = int(f.read(99)) + print("[RESOURCES] Current version: "+str(version)) + if version>=2: + needToInstall = False + except: + pass + if needToInstall: + print("[RESOURCESH] Update required!") + install() + return True + return False diff --git a/esp32/modules/tasks/services.py b/esp32/modules/tasks/services.py new file mode 100644 index 000000000..77e24d0eb --- /dev/null +++ b/esp32/modules/tasks/services.py @@ -0,0 +1,199 @@ +# File: services.py +# Version: 5 +# API version: 2 +# Description: Background services for SHA2017 badge +# License: MIT +# Authors: Renze Nicolai +# Thomas Roos + +import uos, ujson, easywifi, easyrtc, time, appglue, deepsleep, ugfx, badge, machine, sys, virtualtimers + +services = [] #List containing all the service objects +drawCallbacks = [] #List containing draw functions + +def setup(drawCb=None): + global services + global drawCallbacks + + if drawCb: + print("[SERVICES] Draw callback registered") + global drawCallback + drawCallback = drawCb #This might need a better name... + + # Status of wifi + wifiFailed = False + + #Check if lib folder exists and get application list, else stop + try: + apps = uos.listdir('lib') + except OSError: + return False + + #For each app... + for app in apps: + print("APP: "+app) + try: + #Try to open and read the json description + with open('/lib/'+app+'/service.json') as f: + description = f.read() + description = ujson.loads(description) + except: + print("[SERVICES] No description found for "+app) + continue #Or skip the app + + try: + #Try to open the service itself + with open('/lib/'+app+'/service.py') as f: + f.close() + except: + print("[SERVICES] No script found for "+app) + continue #Or skip the app + + rtcRequired = False # True if RTC should be set before starting service + loopEnabled = False # True if loop callback is requested + drawEnabled = False # True if draw callback is requested + + wifiInSetup = False # True if wifi needed in setup + wifiInLoop = False # True if wifi needed in loop + + try: + if description['apiVersion']!=2: + print("[SERVICES] Service for "+app+" is not compatible with current firmware") + continue #Skip the app + wifiInSetup = description['wifi']['setup'] + wifiInLoop = description['wifi']['setup'] + rtcRequired = description['rtc'] + loopEnabled = description['loop'] + drawEnabled = description['draw'] + except: + print("[SERVICES] Could not parse description of app "+app) + continue #Skip the app + + print("[SERVICES] Found service for "+app) + + # Import the service.py script + try: + srv = __import__('lib/'+app+'/service') + except BaseException as e: + print("[SERVICES] Could not import service of app "+app+": ") + sys.print_exception(e) + continue #Skip the app + + if wifiInSetup or wifiInLoop: + if wifiFailed: + print("[SERVICES] Service of app "+app+" requires wifi and wifi failed so the service has been disabled.") + continue + if not easywifi.status(): + if not easywifi.enable(): + wifiFailed = True + print("[SERVICES] Could not connect to wifi!") + continue # Skip the app + + if rtcRequired and time.time() < 1482192000: + if not wifiFailed: + print("[SERVICES] RTC required, configuring...") + easyrtc.configure() + else: + print("[SERVICES] RTC required but not available. Skipping service.") + continue # Skip the app (because wifi failed and rtc not available) + + try: + srv.setup() + except BaseException as e: + print("[SERVICES] Exception in service setup "+app+":") + sys.print_exception(e) + continue + + if loopEnabled: + try: + virtualtimers.new(1, srv.loop) + except: + print("[SERVICES] Loop requested but not defined in service "+app) + + if drawEnabled and drawCb: + drawCallbacks.append(srv) + + # Add the script to the global service list + services.append(srv) + + handleDraw = False + if len(drawCallbacks)>0 and drawCb: + print("[SERVICES] The service subsystem now handles screen redraws") + handleDraw = True + virtualtimers.new(1, draw_task, True) + return handleDraw + +def draw_task(): + global drawCallback #The function that allows us to hook into our host + global drawCallbacks #The functions of the services + requestedInterval = 99999999 + y = ugfx.height() + + drawCallback(False) # Prepare draw + + deleted = [] + + for i in range(0, len(drawCallbacks)): + rqi = 0 + try: + cb = drawCallbacks[i].draw + try: + [rqi, space_used] = cb(y, False) + except: + [rqi, space_used] = cb(y) + y = y - space_used + except BaseException as e: + print("[SERVICES] Exception in service draw:") + sys.print_exception(e) + deleted.append(cb) + continue + if rqi>0 and rqi=99999999: + print("[SERVICES] No draw interval returned.") + requestedInterval = -1 + + retVal = 0 + + if len(drawCallbacks)>0 and requestedInterval>=0: + print("[SERVICES] New draw requested in "+str(requestedInterval)) + retVal = requestedInterval + drawCallback(True) # Complete draw + return retVal + +def force_draw(goingToSleep=False): + global drawCallbacks + if len(drawCallbacks)>0: + y = ugfx.height() + for srv in drawCallbacks: + try: + if not goingToSleep: + cb = srv.draw + else: + try: + cb = srv.draw_going_to_sleep + except: + cb = srv.draw + try: + [rqi, space_used] = cb(y, True) + except: + [rqi, space_used] = cb(y) + y = y - space_used + except BaseException as e: + print("[SERVICES] Exception in service draw: ") + sys.print_exception(e) diff --git a/esp32/modules/tasks/sponsorscheck.py b/esp32/modules/tasks/sponsorscheck.py new file mode 100644 index 000000000..1aebd6bd1 --- /dev/null +++ b/esp32/modules/tasks/sponsorscheck.py @@ -0,0 +1,40 @@ +# File: sponsorscheck.py +# Version: 1 +# Description: Sponsors check module +# License: MIT +# Authors: Renze Nicolai + +import easywifi, easydraw, appglue, badge + +def install(): + if not easywifi.status(): + if not easywifi.enable(): + return False + print("[SPONSORS] Installing...") + easydraw.msg("Installing sponsors...") + import woezel + woezel.install("sponsors") + easydraw.msg("OK") + +def show(force=False): + if (not badge.nvs_get_u8('sponsors', 'shown', 0)) or force: + needToInstall = True + version = 0 + try: + with open("/lib/sponsors/version", "r") as f: + version = int(f.read(99)) + print("[SPONSORS] Current version: "+str(version)) + except: + print("[SPONSORS] Not installed!") + try: + if version>=16: + needToInstall = False + if needToInstall: + install() + with open("/lib/sponsors/version", "r") as f: + version = int(f.read(99)) + # Now we know for sure that a version of the sponsors app has been installed + badge.nvs_set_u8('sponsors', 'shown', 1) + appglue.start_app("sponsors") + except: + pass diff --git a/esp32/modules/update.py b/esp32/modules/update.py new file mode 100644 index 000000000..4d489a3d4 --- /dev/null +++ b/esp32/modules/update.py @@ -0,0 +1,29 @@ +import ugfx, woezel, easywifi, easydraw, appglue, time, os + +def stop(): + time.sleep(2) + appglue.start_app("launcher") + +easydraw.msg("Welcome!","Still updating anyway...",True) + + +if not easywifi.status(): + if not easywifi.enable(): + stop() + +try: + apps = os.listdir('lib') +except OSError: + easydraw.msg("There are no apps installed.") + stop() + +for app in apps: + easydraw.msg("Updating '"+app+"'...") + try: + woezel.install(app) + easydraw.msg("Done!") + except: + print("failed update. Already newest version?") + +easydraw.msg("All your apps are now up-to-date!") +stop() diff --git a/esp32/modules/version.py b/esp32/modules/version.py index 9459aff13..14f80863c 100644 --- a/esp32/modules/version.py +++ b/esp32/modules/version.py @@ -1,2 +1,2 @@ -build = 2 -name = "Vlijtige Vlinder" +build = 17 +name = "De Vergeten Vallei" diff --git a/esp32/modules/virtualtimers.py b/esp32/modules/virtualtimers.py new file mode 100644 index 000000000..0b216573c --- /dev/null +++ b/esp32/modules/virtualtimers.py @@ -0,0 +1,109 @@ +# File: virtualtimers.py +# Version: 1 +# Description: Uses one hardware timer to simulate timers +# License: MIT +# Authors: Renze Nicolai + +import machine, sys + +scheduler = [] +timer = machine.Timer(0) +period = 0 +debugEnabled = False + +def debug(s): + global debugEnabled + debugEnabled = s + +def new(target, callback, hfpm=False): + ''' Creates new task. Arguments: time until callback is called, callback, hide from power management ''' + global scheduler + item = {"pos":0, "target":target, "cb":callback, "hfpm":hfpm} + scheduler.append(item) + +def idle_time(): + ''' Returns time until next task in ms, ignores tasks hidden from power management ''' + global scheduler + idleTime = 86400000 # One day (causes the badge to sleep forever) + for i in range(0, len(scheduler)): + timeUntilTaskExecution = scheduler[i]['target']-scheduler[i]['pos'] + + global debugEnabled + if debugEnabled: + print("idle time for task "+str(i)+" = "+str(timeUntilTaskExecution)+" - ",scheduler[i]) + + if not scheduler[i]["hfpm"]: + if timeUntilTaskExecution<0: + timeUntilTaskExecution = 0 + if timeUntilTaskExecution scheduler[i]["target"]: + try: + newTarget = scheduler[i]["cb"]() + except BaseException as e: + print("[ERROR] An error occured in a task. Task disabled.") + sys.print_exception(e) + newTarget = -1 + if newTarget > 0: + scheduler[i]["pos"] = 0 + scheduler[i]["target"] = newTarget + else: + scheduler[i]["pos"] = -1 + scheduler[i]["target"] = -1 + + scheduler = list(task for task in scheduler if task["pos"]>=0) diff --git a/esp32/modules/woezel.py b/esp32/modules/woezel.py index 7d5e91e5b..a63c284bc 100644 --- a/esp32/modules/woezel.py +++ b/esp32/modules/woezel.py @@ -148,21 +148,21 @@ def url_open(url): def get_pkg_metadata(name): - f = url_open("https://badge.sha2017.org/eggs/get/%s/json" % name) + f = url_open("https://badge.team/eggs/get/%s/json" % name) try: return json.load(f) finally: f.close() def get_pkg_list(): - f = url_open("https://badge.sha2017.org/eggs/list/json") + f = url_open("https://badge.team/eggs/list/json") try: return json.load(f) finally: f.close() def search_pkg_list(query): - f = url_open("https://badge.sha2017.org/eggs/search/%s/json" % query) + f = url_open("https://badge.team/eggs/search/%s/json" % query) try: return json.load(f) finally: @@ -193,11 +193,11 @@ def install_pkg(pkg_spec, install_path, force_reinstall): verf = "%s%s/version" % (install_path, pkg_spec) if already_installed: try: - fver = open(verf, "r") + with open(verf, "r") as fver: + old_ver = fver.read() except: print("No version file found") else: - old_ver = fver.read(); if old_ver == latest_ver: if not force_reinstall: raise LatestInstalledError("Latest version installed") @@ -205,7 +205,6 @@ def install_pkg(pkg_spec, install_path, force_reinstall): print("Removing previous rev. %s" % old_ver) for rm_file in os.listdir("%s%s" % (install_path, pkg_spec)): os.remove("%s%s/%s" % (install_path, pkg_spec, rm_file)) - fver.close() packages = data["releases"][latest_ver] del data gc.collect() @@ -222,9 +221,8 @@ def install_pkg(pkg_spec, install_path, force_reinstall): f1.close() del f3 del f2 - fver = open(verf, "w") - fver.write(latest_ver) - fver.close() + with open(verf, "w") as fver: + fver.write(latest_ver) del fver gc.collect() return meta @@ -266,6 +264,7 @@ def install(to_install, install_path=None, force_reinstall=False): print("Error installing '{}': {}, packages may be partially installed".format( pkg_spec, e), file=sys.stderr) + raise e def display_pkg(packages): for package in packages: diff --git a/esp32/modutime.c b/esp32/modutime.c index 7b21d974b..2b2c4a49d 100644 --- a/esp32/modutime.c +++ b/esp32/modutime.c @@ -32,7 +32,6 @@ #include #include "extmod/utime_mphal.h" -#include "lib/timeutils/timeutils.h" #include "py/nlr.h" /// \function localtime([secs]) @@ -57,7 +56,7 @@ STATIC mp_obj_t time_localtime(mp_uint_t n_args, const mp_obj_t *args) { } else { tv.tv_sec = mp_obj_get_int(args[0]); } - gmtime_r(&tv.tv_sec, &tm); + localtime_r(&tv.tv_sec, &tm); tuple[0] = mp_obj_new_int(tm.tm_year + 1900); tuple[1] = mp_obj_new_int(tm.tm_mon + 1); tuple[2] = mp_obj_new_int(tm.tm_mday); @@ -84,15 +83,23 @@ STATIC mp_obj_t time_mktime(mp_obj_t tuple) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "mktime needs a tuple of length 8 or 9 (%d given)", len)); } - return mp_obj_new_int_from_uint(timeutils_mktime_epoch(mp_obj_get_int(elem[0]), - mp_obj_get_int(elem[1]), mp_obj_get_int(elem[2]), mp_obj_get_int(elem[3]), - mp_obj_get_int(elem[4]), mp_obj_get_int(elem[5]))); + struct tm tm = { + .tm_year = mp_obj_get_int(elem[0]) - 1900, + .tm_mon = mp_obj_get_int(elem[1]) - 1, + .tm_mday = mp_obj_get_int(elem[2]), + .tm_hour = mp_obj_get_int(elem[3]), + .tm_min = mp_obj_get_int(elem[4]), + .tm_sec = mp_obj_get_int(elem[5]), + .tm_isdst = ((len > 8) ? mp_obj_get_int(elem[8]) : -1), + }; + time_t t = mktime(&tm); + return mp_obj_new_int_from_uint(t); } MP_DEFINE_CONST_FUN_OBJ_1(time_mktime_obj, time_mktime); /// \function time() -/// Returns the number of seconds, as an integer, since 1/1/2000. +/// Returns the number of seconds since the unix epoch. STATIC mp_obj_t time_time(void) { struct timeval tv; gettimeofday(&tv, NULL); @@ -100,11 +107,22 @@ STATIC mp_obj_t time_time(void) { } MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time); +/// \function settimezone(tz) +/// Sets the timezone to tz. +STATIC mp_obj_t time_settimezone(mp_obj_t _timezone) { + const char *timezone = mp_obj_str_get_str(_timezone); + setenv("TZ", timezone, 1); + tzset(); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(time_settimezone_obj, time_settimezone); + STATIC const mp_rom_map_elem_t time_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) }, { MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_localtime_obj) }, { MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&time_mktime_obj) }, { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) }, + { MP_ROM_QSTR(MP_QSTR_settimezone), MP_ROM_PTR(&time_settimezone_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) }, { MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) }, diff --git a/esp32/mpconfigport.h b/esp32/mpconfigport.h index 1b025b339..c6a4c221a 100644 --- a/esp32/mpconfigport.h +++ b/esp32/mpconfigport.h @@ -41,7 +41,7 @@ #define MICROPY_PY_BUILTINS_COMPLEX (1) #define MICROPY_CPYTHON_COMPAT (1) #define MICROPY_STREAMS_NON_BLOCK (1) -#define MICROPY_STREAMS_POSIX_API (0) +#define MICROPY_STREAMS_POSIX_API (1) #define MICROPY_MODULE_BUILTIN_INIT (1) #define MICROPY_MODULE_WEAK_LINKS (1) #define MICROPY_MODULE_FROZEN_STR (0) @@ -141,7 +141,6 @@ #define MICROPY_SSL_MBEDTLS (1) #define MICROPY_PY_WEBSOCKET (0) #define MICROPY_PY_FRAMEBUF (1) -#define MICROPY_PY_BTREE (0) // fatfs configuration #define MICROPY_FATFS_ENABLE_LFN (1) @@ -160,8 +159,7 @@ #define MICROPY_SDMMC_USE_DRIVER (1) #define MICROPY_SDMMC_SHOW_INFO (1) -// use vfs's functions for import stat and builtin open -#define mp_import_stat mp_vfs_import_stat +// use vfs's functions for builtin open #define mp_builtin_open mp_vfs_open #define mp_builtin_open_obj mp_vfs_open_obj @@ -172,25 +170,29 @@ // extra built in modules to add to the list of known ones extern const struct _mp_obj_module_t esp_module; -extern const struct _mp_obj_module_t mp_module_onewire; extern const struct _mp_obj_module_t utime_module; extern const struct _mp_obj_module_t uos_module; extern const struct _mp_obj_module_t mp_module_usocket; extern const struct _mp_obj_module_t mp_module_machine; extern const struct _mp_obj_module_t mp_module_network; extern const struct _mp_obj_module_t badge_module; +extern const struct _mp_obj_module_t bpp_module; extern const struct _mp_obj_module_t ugfx_module; +extern const struct _mp_obj_module_t freedomgfx_module; +extern const struct _mp_obj_module_t mp_module_onewire; #define MICROPY_PORT_BUILTIN_MODULES \ { MP_OBJ_NEW_QSTR(MP_QSTR_esp), (mp_obj_t)&esp_module }, \ - { MP_OBJ_NEW_QSTR(MP_QSTR_onewire), (mp_obj_t)&mp_module_onewire }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&utime_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&uos_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_usocket), (mp_obj_t)&mp_module_usocket }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&mp_module_machine }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_network), (mp_obj_t)&mp_module_network }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_badge), (mp_obj_t)&badge_module }, \ + { MP_OBJ_NEW_QSTR(MP_QSTR_bpp), (mp_obj_t)&bpp_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_ugfx), (mp_obj_t)&ugfx_module }, \ + { MP_OBJ_NEW_QSTR(MP_QSTR_freedomgfx), (mp_obj_t)&freedomgfx_module }, \ + { MP_OBJ_NEW_QSTR(MP_QSTR__onewire), (mp_obj_t)&mp_module_onewire }, \ #define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \ { MP_OBJ_NEW_QSTR(MP_QSTR_binascii), (mp_obj_t)&mp_module_ubinascii }, \ @@ -253,6 +255,8 @@ extern const struct _mp_obj_module_t ugfx_module; typedef int32_t mp_int_t; // must be pointer size typedef uint32_t mp_uint_t; // must be pointer size typedef long mp_off_t; +// ssize_t, off_t as required by POSIX-signatured functions in stream.h +#include // board specifics diff --git a/esp32/qstrdefsport.h b/esp32/qstrdefsport.h index ff6c2cc42..20454dcab 100644 --- a/esp32/qstrdefsport.h +++ b/esp32/qstrdefsport.h @@ -28,3 +28,5 @@ // Entries for sys.path Q(/lib) +Q(/bpp/lib) +Q(/sdcard/lib) diff --git a/esp32/ugfx_widgets.c b/esp32/ugfx_widgets.c index 7055618d5..b48756414 100644 --- a/esp32/ugfx_widgets.c +++ b/esp32/ugfx_widgets.c @@ -299,7 +299,7 @@ STATIC mp_obj_t ugfx_button_make_new(const mp_obj_type_t *type, mp_uint_t n_args // TODO where to keep this reference so we can clean it up afterwards? // Perhaps pass our own structure to gwinButtonCreate? GListener* pl = malloc(sizeof(GListener)); - printf("Created GListener at %x\n", pl); + printf("Created GListener at %p\n", pl); geventListenerInit(pl); pl->callback = ugfx_button_gevent_handler; // TODO do we need to copy this value to make sure it doesn't get freed? @@ -443,11 +443,11 @@ STATIC mp_obj_t ugfx_textbox_cursor_pos(mp_uint_t n_args, const mp_obj_t *args) } else { - const int newPos = mp_obj_get_int(args[1]); - printf("Setting cursor position for widget at %p to %d\n", self, newPos); - ((GTexteditObject*)self->ghTextbox)->cursorPos = newPos; - // Should not be needed to do this explicitly right? - gwinTexteditDefaultDraw(self, NULL); + const int newPos = mp_obj_get_int(args[1]); + printf("Setting cursor position for widget at %p to %d\n", self, newPos); + ((GTexteditObject*)self->ghTextbox)->cursorPos = newPos; + // Should not be needed to do this explicitly right? + gwinTexteditDefaultDraw((GWidgetObject *) self->ghTextbox, NULL); return mp_const_none; } } @@ -459,7 +459,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ugfx_textbox_cursor_pos_obj, 1, 2, ug STATIC mp_obj_t ugfx_textbox_backspace(mp_obj_t self_in) { ugfx_textbox_obj_t *self = self_in; - gwinTexteditBackspace(self->ghTextbox); + gwinTexteditBackspace((GWidgetObject *) self->ghTextbox); return mp_const_none; } @@ -635,7 +635,7 @@ void BWgwinListDefaultDraw(GWidgetObject* gw, void* param) { } } #endif - gdispGFillStringBox(gw->g.display, gw->g.x+x+LST_HORIZ_PAD, gw->g.y+y, iwidth-LST_HORIZ_PAD, iheight, qi2li->text, gw->g.font, text, fill, justifyLeft); + gdispGFillStringBox(gw->g.display, gw->g.x+x+LST_HORIZ_PAD, gw->g.y+y, iwidth-LST_HORIZ_PAD, iheight, qi2li->text, gw->g.font, text, fill, justifyLeft | justifyTop); } // Fill any remaining item space diff --git a/esp8266/Makefile b/esp8266/Makefile index 1c169862e..fce11a7d4 100644 --- a/esp8266/Makefile +++ b/esp8266/Makefile @@ -12,7 +12,7 @@ FROZEN_DIR ?= scripts FROZEN_MPY_DIR ?= modules # include py core make definitions -include ../py/py.mk +include $(TOP)/py/py.mk FWBIN = $(BUILD)/firmware-combined.bin PORT ?= /dev/ttyACM0 @@ -23,8 +23,7 @@ CROSS_COMPILE = xtensa-lx106-elf- ESP_SDK = $(shell $(CC) -print-sysroot)/usr INC += -I. -INC += -I.. -INC += -I../stmhal +INC += -I$(TOP) INC += -I$(BUILD) INC += -I$(ESP_SDK)/include @@ -221,16 +220,16 @@ ota: #$(BUILD)/pins_$(BOARD).o: $(BUILD)/pins_$(BOARD).c # $(call compile_c) -include ../py/mkrules.mk +include $(TOP)/py/mkrules.mk axtls: $(BUILD)/libaxtls.a $(BUILD)/libaxtls.a: - cd ../lib/axtls; cp config/upyconfig config/.config - cd ../lib/axtls; $(MAKE) oldconfig -B - cd ../lib/axtls; $(MAKE) clean - cd ../lib/axtls; $(MAKE) all CC="$(CC)" LD="$(LD)" AR="$(AR)" CFLAGS_EXTRA="$(CFLAGS_XTENSA) -Dabort=abort_ -DRT_MAX_PLAIN_LENGTH=1024 -DRT_EXTRA=4096" - cp ../lib/axtls/_stage/libaxtls.a $@ + cd $(TOP)/lib/axtls; cp config/upyconfig config/.config + cd $(TOP)/lib/axtls; $(MAKE) oldconfig -B + cd $(TOP)/lib/axtls; $(MAKE) clean + cd $(TOP)/lib/axtls; $(MAKE) all CC="$(CC)" LD="$(LD)" AR="$(AR)" CFLAGS_EXTRA="$(CFLAGS_XTENSA) -Dabort=abort_ -DRT_MAX_PLAIN_LENGTH=1024 -DRT_EXTRA=4096" + cp $(TOP)/lib/axtls/_stage/libaxtls.a $@ clean-modules: git clean -f -d modules diff --git a/esp8266/esp_mphal.c b/esp8266/esp_mphal.c index 55f9a5894..61848fd34 100644 --- a/esp8266/esp_mphal.c +++ b/esp8266/esp_mphal.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/esp8266/esp_mphal.h b/esp8266/esp_mphal.h index d783f1f09..913bd70dc 100644 --- a/esp8266/esp_mphal.h +++ b/esp8266/esp_mphal.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,9 +24,6 @@ * THE SOFTWARE. */ -#ifndef _INCLUDED_MPHAL_H_ -#define _INCLUDED_MPHAL_H_ - #include "py/ringbuf.h" #include "lib/utils/interrupt_char.h" #include "xtirq.h" @@ -96,5 +93,3 @@ void mp_hal_pin_open_drain(mp_hal_pin_obj_t pin); void *ets_get_esf_buf_ctlblk(void); int ets_esf_free_bufs(int idx); - -#endif // _INCLUDED_MPHAL_H_ diff --git a/esp8266/espapa102.h b/esp8266/espapa102.h index 82c92025d..dd7c5ab72 100644 --- a/esp8266/espapa102.h +++ b/esp8266/espapa102.h @@ -23,5 +23,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_ESP8266_ESPAPA102_H +#define MICROPY_INCLUDED_ESP8266_ESPAPA102_H void esp_apa102_write(uint8_t clockPin, uint8_t dataPin, uint8_t *pixels, uint32_t numBytes); + +#endif // MICROPY_INCLUDED_ESP8266_ESPAPA102_H diff --git a/esp8266/espneopixel.h b/esp8266/espneopixel.h index 4b20afda5..c444740ff 100644 --- a/esp8266/espneopixel.h +++ b/esp8266/espneopixel.h @@ -1 +1,6 @@ +#ifndef MICROPY_INCLUDED_ESP8266_ESPNEOPIXEL_H +#define MICROPY_INCLUDED_ESP8266_ESPNEOPIXEL_H + void esp_neopixel_write(uint8_t pin, uint8_t *pixels, uint32_t numBytes, bool is800KHz); + +#endif // MICROPY_INCLUDED_ESP8266_ESPNEOPIXEL_H diff --git a/esp8266/esppwm.h b/esp8266/esppwm.h index 242a9a2a6..1ee4a2f55 100644 --- a/esp8266/esppwm.h +++ b/esp8266/esppwm.h @@ -1,5 +1,5 @@ -#ifndef __ESPPWM_H__ -#define __ESPPWM_H__ +#ifndef MICROPY_INCLUDED_ESP8266_ESPPWM_H +#define MICROPY_INCLUDED_ESP8266_ESPPWM_H #include #include @@ -14,4 +14,4 @@ uint16_t pwm_get_freq(uint8_t channel); int pwm_add(uint8_t pin_id, uint32_t pin_mux, uint32_t pin_func); bool pwm_delete(uint8_t channel); -#endif +#endif // MICROPY_INCLUDED_ESP8266_ESPPWM_H diff --git a/esp8266/ets_alt_task.h b/esp8266/ets_alt_task.h index dba0c5fa6..33a9d3a00 100644 --- a/esp8266/ets_alt_task.h +++ b/esp8266/ets_alt_task.h @@ -1,4 +1,9 @@ +#ifndef MICROPY_INCLUDED_ESP8266_ETS_ALT_TASK_H +#define MICROPY_INCLUDED_ESP8266_ETS_ALT_TASK_H + extern int ets_loop_iter_disable; extern uint32_t system_time_high_word; bool ets_loop_iter(void); + +#endif // MICROPY_INCLUDED_ESP8266_ETS_ALT_TASK_H diff --git a/esp8266/etshal.h b/esp8266/etshal.h index 90af63ba2..34787779f 100644 --- a/esp8266/etshal.h +++ b/esp8266/etshal.h @@ -1,5 +1,5 @@ -#ifndef _INCLUDED_ETSHAL_H_ -#define _INCLUDED_ETSHAL_H_ +#ifndef MICROPY_INCLUDED_ESP8266_ETSHAL_H +#define MICROPY_INCLUDED_ESP8266_ETSHAL_H #include @@ -42,4 +42,4 @@ uint32_t SPIRead(uint32_t offset, void *buf, uint32_t len); uint32_t SPIWrite(uint32_t offset, const void *buf, uint32_t len); uint32_t SPIEraseSector(int sector); -#endif // _INCLUDED_ETSHAL_H_ +#endif // MICROPY_INCLUDED_ESP8266_ETSHAL_H diff --git a/esp8266/fatfs_port.c b/esp8266/fatfs_port.c index 02384f605..a8865c817 100644 --- a/esp8266/fatfs_port.c +++ b/esp8266/fatfs_port.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/esp8266/gccollect.c b/esp8266/gccollect.c index 1b9349f57..cd5d4932c 100644 --- a/esp8266/gccollect.c +++ b/esp8266/gccollect.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/esp8266/gccollect.h b/esp8266/gccollect.h index d81cba12c..5735d8a39 100644 --- a/esp8266/gccollect.h +++ b/esp8266/gccollect.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_ESP8266_GCCOLLECT_H +#define MICROPY_INCLUDED_ESP8266_GCCOLLECT_H extern uint32_t _text_start; extern uint32_t _text_end; @@ -39,3 +41,5 @@ extern uint32_t _heap_end; void gc_collect(void); void esp_native_code_gc_collect(void); + +#endif // MICROPY_INCLUDED_ESP8266_GCCOLLECT_H diff --git a/esp8266/hspi.c b/esp8266/hspi.c index 436fb4f6f..554a50460 100644 --- a/esp8266/hspi.c +++ b/esp8266/hspi.c @@ -28,7 +28,7 @@ /* Wrapper to setup HSPI/SPI GPIO pins and default SPI clock spi_no - SPI (0) or HSPI (1) -Not used in Micropython. +Not used in MicroPython. */ void spi_init(uint8_t spi_no) { spi_init_gpio(spi_no, SPI_CLK_USE_DIV); @@ -48,7 +48,7 @@ Configures SPI mode parameters for clock edge and clock polarity. (1) Data is valid on clock trailing edge spi_cpol - (0) Clock is low when inactive (1) Clock is high when inactive -For Micropython this version is different from original. +For MicroPython this version is different from original. */ void spi_mode(uint8_t spi_no, uint8_t spi_cpha, uint8_t spi_cpol) { if (spi_cpol) { @@ -99,7 +99,7 @@ void spi_init_gpio(uint8_t spi_no, uint8_t sysclk_as_spiclk) { // GPIO14 is HSPI CLK pin (Clock) PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, 2); // GPIO15 is HSPI CS pin (Chip Select / Slave Select) - // In Micropython, we are handling CS ourself in drivers. + // In MicroPython, we are handling CS ourself in drivers. // PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, 2); } } diff --git a/esp8266/hspi_register.h b/esp8266/hspi_register.h index 30a5ff588..4dd335b40 100644 --- a/esp8266/hspi_register.h +++ b/esp8266/hspi_register.h @@ -3,7 +3,7 @@ * Modified by David Ogilvy (MetalPhreak) * Based on original file included in SDK 1.0.0 * - * Missing defines from previous SDK versions have + * Missing defines from previous SDK versions have * been added and are noted with comments. The * names of these defines are likely to change. */ diff --git a/esp8266/machine_adc.c b/esp8266/machine_adc.c index f1fb5be31..c8c08695b 100644 --- a/esp8266/machine_adc.c +++ b/esp8266/machine_adc.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -70,8 +70,8 @@ STATIC mp_obj_t pyb_adc_read(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_adc_read_obj, pyb_adc_read); -STATIC const mp_map_elem_t pyb_adc_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&pyb_adc_read_obj } +STATIC const mp_rom_map_elem_t pyb_adc_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&pyb_adc_read_obj) } }; STATIC MP_DEFINE_CONST_DICT(pyb_adc_locals_dict, pyb_adc_locals_dict_table); @@ -79,5 +79,5 @@ const mp_obj_type_t pyb_adc_type = { { &mp_type_type }, .name = MP_QSTR_ADC, .make_new = pyb_adc_make_new, - .locals_dict = (mp_obj_t)&pyb_adc_locals_dict, + .locals_dict = (mp_obj_dict_t*)&pyb_adc_locals_dict, }; diff --git a/esp8266/machine_hspi.c b/esp8266/machine_hspi.c index 1be342b52..eaabbab7e 100644 --- a/esp8266/machine_hspi.c +++ b/esp8266/machine_hspi.c @@ -122,15 +122,13 @@ STATIC void machine_hspi_init(mp_obj_base_t *self_in, size_t n_args, const mp_ob spi_init_gpio(HSPI, SPI_CLK_80MHZ_NODIV); spi_clock(HSPI, 0, 0); } else if (self->baudrate > 40000000L) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "impossible baudrate")); + mp_raise_ValueError("impossible baudrate"); } else { uint32_t divider = 40000000L / self->baudrate; uint16_t prediv = MIN(divider, SPI_CLKDIV_PRE + 1); uint16_t cntdiv = (divider / prediv) * 2; // cntdiv has to be even if (cntdiv > SPI_CLKCNT_N + 1 || cntdiv == 0 || prediv == 0) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "impossible baudrate")); + mp_raise_ValueError("impossible baudrate"); } self->baudrate = 80000000L / (prediv * cntdiv); spi_init_gpio(HSPI, SPI_CLK_USE_DIV); diff --git a/esp8266/machine_pin.c b/esp8266/machine_pin.c index febbc1587..673082065 100644 --- a/esp8266/machine_pin.c +++ b/esp8266/machine_pin.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -125,7 +125,7 @@ void pin_intr_handler(uint32_t status) { pyb_pin_obj_t *mp_obj_get_pin_obj(mp_obj_t pin_in) { if (mp_obj_get_type(pin_in) != &pyb_pin_type) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "expecting a pin")); + mp_raise_ValueError("expecting a pin"); } pyb_pin_obj_t *self = pin_in; return self; @@ -280,7 +280,7 @@ STATIC mp_obj_t pyb_pin_obj_init_helper(pyb_pin_obj_t *self, mp_uint_t n_args, c // only pull-down seems to be supported by the hardware, and // we only expose pull-up behaviour in software if (pull != GPIO_PULL_NONE) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Pin(16) doesn't support pull")); + mp_raise_ValueError("Pin(16) doesn't support pull"); } } else { PIN_FUNC_SELECT(self->periph, self->func); @@ -319,7 +319,7 @@ mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, pin = (pyb_pin_obj_t*)&pyb_pin_obj[wanted_pin]; } if (pin == NULL || pin->base.type == NULL) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid pin")); + mp_raise_ValueError("invalid pin"); } if (n_args > 1 || n_kw > 0) { @@ -426,24 +426,24 @@ STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, i return -1; } -STATIC const mp_map_elem_t pyb_pin_locals_dict_table[] = { +STATIC const mp_rom_map_elem_t pyb_pin_locals_dict_table[] = { // instance methods - { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_pin_init_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_value), (mp_obj_t)&pyb_pin_value_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_off), (mp_obj_t)&pyb_pin_off_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_on), (mp_obj_t)&pyb_pin_on_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_irq), (mp_obj_t)&pyb_pin_irq_obj }, + { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_pin_init_obj) }, + { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pyb_pin_value_obj) }, + { MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&pyb_pin_off_obj) }, + { MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&pyb_pin_on_obj) }, + { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&pyb_pin_irq_obj) }, // class constants - { MP_OBJ_NEW_QSTR(MP_QSTR_IN), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_INPUT) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_OUT), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_OUTPUT) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_OPEN_DRAIN), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_OPEN_DRAIN) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_PULL_UP), MP_OBJ_NEW_SMALL_INT(GPIO_PULL_UP) }, - //{ MP_OBJ_NEW_QSTR(MP_QSTR_PULL_DOWN), MP_OBJ_NEW_SMALL_INT(GPIO_PULL_DOWN) }, - - // IRG triggers, can be or'd together - { MP_OBJ_NEW_QSTR(MP_QSTR_IRQ_RISING), MP_OBJ_NEW_SMALL_INT(GPIO_PIN_INTR_POSEDGE) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_IRQ_FALLING), MP_OBJ_NEW_SMALL_INT(GPIO_PIN_INTR_NEGEDGE) }, + { MP_ROM_QSTR(MP_QSTR_IN), MP_ROM_INT(GPIO_MODE_INPUT) }, + { MP_ROM_QSTR(MP_QSTR_OUT), MP_ROM_INT(GPIO_MODE_OUTPUT) }, + { MP_ROM_QSTR(MP_QSTR_OPEN_DRAIN), MP_ROM_INT(GPIO_MODE_OPEN_DRAIN) }, + { MP_ROM_QSTR(MP_QSTR_PULL_UP), MP_ROM_INT(GPIO_PULL_UP) }, + //{ MP_ROM_QSTR(MP_QSTR_PULL_DOWN), MP_ROM_INT(GPIO_PULL_DOWN) }, + + // IRQ triggers, can be or'd together + { MP_ROM_QSTR(MP_QSTR_IRQ_RISING), MP_ROM_INT(GPIO_PIN_INTR_POSEDGE) }, + { MP_ROM_QSTR(MP_QSTR_IRQ_FALLING), MP_ROM_INT(GPIO_PIN_INTR_NEGEDGE) }, }; STATIC MP_DEFINE_CONST_DICT(pyb_pin_locals_dict, pyb_pin_locals_dict_table); @@ -459,7 +459,7 @@ const mp_obj_type_t pyb_pin_type = { .make_new = mp_pin_make_new, .call = pyb_pin_call, .protocol = &pin_pin_p, - .locals_dict = (mp_obj_t)&pyb_pin_locals_dict, + .locals_dict = (mp_obj_dict_t*)&pyb_pin_locals_dict, }; /******************************************************************************/ diff --git a/esp8266/machine_pwm.c b/esp8266/machine_pwm.c index 5d30f0965..8d73e6bb1 100644 --- a/esp8266/machine_pwm.c +++ b/esp8266/machine_pwm.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/esp8266/machine_rtc.c b/esp8266/machine_rtc.c index b92ce1d5a..c5d04e0cf 100644 --- a/esp8266/machine_rtc.c +++ b/esp8266/machine_rtc.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -183,8 +183,7 @@ STATIC mp_obj_t pyb_rtc_memory(mp_uint_t n_args, const mp_obj_t *args) { mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ); if (bufinfo.len > MEM_USER_MAXLEN) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "buffer too long")); + mp_raise_ValueError("buffer too long"); } len = bufinfo.len; @@ -208,7 +207,7 @@ STATIC mp_obj_t pyb_rtc_alarm(mp_obj_t self_in, mp_obj_t alarm_id, mp_obj_t time // check we want alarm0 if (mp_obj_get_int(alarm_id) != 0) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid alarm")); + mp_raise_ValueError("invalid alarm"); } // set expiry time (in microseconds) @@ -245,7 +244,7 @@ STATIC mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k // check we want alarm0 if (args[ARG_trigger].u_int != 0) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid alarm")); + mp_raise_ValueError("invalid alarm"); } // set the wake value @@ -255,13 +254,13 @@ STATIC mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_irq_obj, 1, pyb_rtc_irq); -STATIC const mp_map_elem_t pyb_rtc_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR_datetime), (mp_obj_t)&pyb_rtc_datetime_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_memory), (mp_obj_t)&pyb_rtc_memory_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_alarm), (mp_obj_t)&pyb_rtc_alarm_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_alarm_left), (mp_obj_t)&pyb_rtc_alarm_left_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_irq), (mp_obj_t)&pyb_rtc_irq_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ALARM0), MP_OBJ_NEW_SMALL_INT(0) }, +STATIC const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_datetime), MP_ROM_PTR(&pyb_rtc_datetime_obj) }, + { MP_ROM_QSTR(MP_QSTR_memory), MP_ROM_PTR(&pyb_rtc_memory_obj) }, + { MP_ROM_QSTR(MP_QSTR_alarm), MP_ROM_PTR(&pyb_rtc_alarm_obj) }, + { MP_ROM_QSTR(MP_QSTR_alarm_left), MP_ROM_PTR(&pyb_rtc_alarm_left_obj) }, + { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&pyb_rtc_irq_obj) }, + { MP_ROM_QSTR(MP_QSTR_ALARM0), MP_ROM_INT(0) }, }; STATIC MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table); @@ -269,5 +268,5 @@ const mp_obj_type_t pyb_rtc_type = { { &mp_type_type }, .name = MP_QSTR_RTC, .make_new = pyb_rtc_make_new, - .locals_dict = (mp_obj_t)&pyb_rtc_locals_dict, + .locals_dict = (mp_obj_dict_t*)&pyb_rtc_locals_dict, }; diff --git a/esp8266/machine_wdt.c b/esp8266/machine_wdt.c index 83b5e8f32..5e23ff782 100644 --- a/esp8266/machine_wdt.c +++ b/esp8266/machine_wdt.c @@ -71,9 +71,9 @@ STATIC mp_obj_t machine_wdt_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_wdt_deinit_obj, machine_wdt_deinit); -STATIC const mp_map_elem_t machine_wdt_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR_feed), (mp_obj_t)&machine_wdt_feed_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&machine_wdt_deinit_obj }, +STATIC const mp_rom_map_elem_t machine_wdt_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_feed), MP_ROM_PTR(&machine_wdt_feed_obj) }, + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_wdt_deinit_obj) }, }; STATIC MP_DEFINE_CONST_DICT(machine_wdt_locals_dict, machine_wdt_locals_dict_table); @@ -81,5 +81,5 @@ const mp_obj_type_t esp_wdt_type = { { &mp_type_type }, .name = MP_QSTR_WDT, .make_new = machine_wdt_make_new, - .locals_dict = (mp_obj_t)&machine_wdt_locals_dict, + .locals_dict = (mp_obj_dict_t*)&machine_wdt_locals_dict, }; diff --git a/esp8266/main.c b/esp8266/main.c index 43b83759e..957198aa0 100644 --- a/esp8266/main.c +++ b/esp8266/main.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/esp8266/modesp.c b/esp8266/modesp.c index 5eaae27d6..6ddca0733 100644 --- a/esp8266/modesp.c +++ b/esp8266/modesp.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -118,7 +118,7 @@ STATIC mp_obj_t esp_flash_write(mp_obj_t offset_in, const mp_obj_t buf_in) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); if (bufinfo.len & 0x3) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "len must be multiple of 4")); + mp_raise_ValueError("len must be multiple of 4"); } SpiFlashOpResult res = spi_flash_write(offset, bufinfo.buf, bufinfo.len); if (res == SPI_FLASH_RESULT_OK) { @@ -347,50 +347,40 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp_set_native_code_location_obj, esp_set_nativ #endif -STATIC const mp_map_elem_t esp_module_globals_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_esp) }, - - { MP_OBJ_NEW_QSTR(MP_QSTR_osdebug), (mp_obj_t)&esp_osdebug_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_sleep_type), (mp_obj_t)&esp_sleep_type_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_deepsleep), (mp_obj_t)&esp_deepsleep_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_flash_id), (mp_obj_t)&esp_flash_id_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_flash_read), (mp_obj_t)&esp_flash_read_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_flash_write), (mp_obj_t)&esp_flash_write_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_flash_erase), (mp_obj_t)&esp_flash_erase_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_flash_size), (mp_obj_t)&esp_flash_size_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_flash_user_start), (mp_obj_t)&esp_flash_user_start_obj }, +STATIC const mp_rom_map_elem_t esp_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_esp) }, + + { MP_ROM_QSTR(MP_QSTR_osdebug), MP_ROM_PTR(&esp_osdebug_obj) }, + { MP_ROM_QSTR(MP_QSTR_sleep_type), MP_ROM_PTR(&esp_sleep_type_obj) }, + { MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&esp_deepsleep_obj) }, + { MP_ROM_QSTR(MP_QSTR_flash_id), MP_ROM_PTR(&esp_flash_id_obj) }, + { MP_ROM_QSTR(MP_QSTR_flash_read), MP_ROM_PTR(&esp_flash_read_obj) }, + { MP_ROM_QSTR(MP_QSTR_flash_write), MP_ROM_PTR(&esp_flash_write_obj) }, + { MP_ROM_QSTR(MP_QSTR_flash_erase), MP_ROM_PTR(&esp_flash_erase_obj) }, + { MP_ROM_QSTR(MP_QSTR_flash_size), MP_ROM_PTR(&esp_flash_size_obj) }, + { MP_ROM_QSTR(MP_QSTR_flash_user_start), MP_ROM_PTR(&esp_flash_user_start_obj) }, #if MICROPY_ESP8266_NEOPIXEL - { MP_OBJ_NEW_QSTR(MP_QSTR_neopixel_write), (mp_obj_t)&esp_neopixel_write_obj }, + { MP_ROM_QSTR(MP_QSTR_neopixel_write), MP_ROM_PTR(&esp_neopixel_write_obj) }, #endif #if MICROPY_ESP8266_APA102 - { MP_OBJ_NEW_QSTR(MP_QSTR_apa102_write), (mp_obj_t)&esp_apa102_write_obj }, + { MP_ROM_QSTR(MP_QSTR_apa102_write), MP_ROM_PTR(&esp_apa102_write_obj) }, #endif - { MP_OBJ_NEW_QSTR(MP_QSTR_dht_readinto), (mp_obj_t)&dht_readinto_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_freemem), (mp_obj_t)&esp_freemem_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_meminfo), (mp_obj_t)&esp_meminfo_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_check_fw), (mp_obj_t)&esp_check_fw_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&pyb_info_obj }, // TODO delete/rename/move elsewhere - { MP_OBJ_NEW_QSTR(MP_QSTR_malloc), (mp_obj_t)&esp_malloc_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_free), (mp_obj_t)&esp_free_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_esf_free_bufs), (mp_obj_t)&esp_esf_free_bufs_obj }, + { MP_ROM_QSTR(MP_QSTR_dht_readinto), MP_ROM_PTR(&dht_readinto_obj) }, + { MP_ROM_QSTR(MP_QSTR_freemem), MP_ROM_PTR(&esp_freemem_obj) }, + { MP_ROM_QSTR(MP_QSTR_meminfo), MP_ROM_PTR(&esp_meminfo_obj) }, + { MP_ROM_QSTR(MP_QSTR_check_fw), MP_ROM_PTR(&esp_check_fw_obj) }, + { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&pyb_info_obj) }, // TODO delete/rename/move elsewhere + { MP_ROM_QSTR(MP_QSTR_malloc), MP_ROM_PTR(&esp_malloc_obj) }, + { MP_ROM_QSTR(MP_QSTR_free), MP_ROM_PTR(&esp_free_obj) }, + { MP_ROM_QSTR(MP_QSTR_esf_free_bufs), MP_ROM_PTR(&esp_esf_free_bufs_obj) }, #if MICROPY_EMIT_XTENSA || MICROPY_EMIT_INLINE_XTENSA - { MP_OBJ_NEW_QSTR(MP_QSTR_set_native_code_location), (mp_obj_t)&esp_set_native_code_location_obj }, + { MP_ROM_QSTR(MP_QSTR_set_native_code_location), MP_ROM_PTR(&esp_set_native_code_location_obj) }, #endif #if MODESP_INCLUDE_CONSTANTS - { MP_OBJ_NEW_QSTR(MP_QSTR_SLEEP_NONE), - MP_OBJ_NEW_SMALL_INT(NONE_SLEEP_T) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_SLEEP_LIGHT), - MP_OBJ_NEW_SMALL_INT(LIGHT_SLEEP_T) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_SLEEP_MODEM), - MP_OBJ_NEW_SMALL_INT(MODEM_SLEEP_T) }, - - { MP_OBJ_NEW_QSTR(MP_QSTR_STA_MODE), - MP_OBJ_NEW_SMALL_INT(STATION_MODE)}, - { MP_OBJ_NEW_QSTR(MP_QSTR_AP_MODE), - MP_OBJ_NEW_SMALL_INT(SOFTAP_MODE)}, - { MP_OBJ_NEW_QSTR(MP_QSTR_STA_AP_MODE), - MP_OBJ_NEW_SMALL_INT(STATIONAP_MODE)}, + { MP_ROM_QSTR(MP_QSTR_SLEEP_NONE), MP_ROM_INT(NONE_SLEEP_T) }, + { MP_ROM_QSTR(MP_QSTR_SLEEP_LIGHT), MP_ROM_INT(LIGHT_SLEEP_T) }, + { MP_ROM_QSTR(MP_QSTR_SLEEP_MODEM), MP_ROM_INT(MODEM_SLEEP_T) }, #endif }; diff --git a/esp8266/modmachine.c b/esp8266/modmachine.c index c26c63396..98bc49558 100644 --- a/esp8266/modmachine.c +++ b/esp8266/modmachine.c @@ -59,8 +59,7 @@ STATIC mp_obj_t machine_freq(mp_uint_t n_args, const mp_obj_t *args) { // set mp_int_t freq = mp_obj_get_int(args[0]) / 1000000; if (freq != 80 && freq != 160) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "frequency can only be either 80Mhz or 160MHz")); + mp_raise_ValueError("frequency can only be either 80Mhz or 160MHz"); } system_update_cpu_freq(freq); return mp_const_none; @@ -193,12 +192,12 @@ STATIC mp_obj_t esp_timer_deinit(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_timer_deinit_obj, esp_timer_deinit); -STATIC const mp_map_elem_t esp_timer_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&esp_timer_deinit_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&esp_timer_init_obj }, -// { MP_OBJ_NEW_QSTR(MP_QSTR_callback), (mp_obj_t)&esp_timer_callback_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ONE_SHOT), MP_OBJ_NEW_SMALL_INT(false) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_PERIODIC), MP_OBJ_NEW_SMALL_INT(true) }, +STATIC const mp_rom_map_elem_t esp_timer_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&esp_timer_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&esp_timer_init_obj) }, +// { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&esp_timer_callback_obj) }, + { MP_ROM_QSTR(MP_QSTR_ONE_SHOT), MP_ROM_INT(false) }, + { MP_ROM_QSTR(MP_QSTR_PERIODIC), MP_ROM_INT(true) }, }; STATIC MP_DEFINE_CONST_DICT(esp_timer_locals_dict, esp_timer_locals_dict_table); @@ -207,7 +206,7 @@ const mp_obj_type_t esp_timer_type = { .name = MP_QSTR_Timer, .print = esp_timer_print, .make_new = esp_timer_make_new, - .locals_dict = (mp_obj_t)&esp_timer_locals_dict, + .locals_dict = (mp_obj_dict_t*)&esp_timer_locals_dict, }; // this bit is unused in the Xtensa PS register diff --git a/esp8266/modmachine.h b/esp8266/modmachine.h index 414aaa85b..eae351f68 100644 --- a/esp8266/modmachine.h +++ b/esp8266/modmachine.h @@ -1,5 +1,5 @@ -#ifndef __MICROPY_INCLUDED_ESP8266_MODPYB_H__ -#define __MICROPY_INCLUDED_ESP8266_MODPYB_H__ +#ifndef MICROPY_INCLUDED_ESP8266_MODMACHINE_H +#define MICROPY_INCLUDED_ESP8266_MODMACHINE_H #include "py/obj.h" @@ -38,4 +38,4 @@ void pyb_rtc_set_us_since_2000(uint64_t nowus); uint64_t pyb_rtc_get_us_since_2000(); void rtc_prepare_deepsleep(uint64_t sleep_us); -#endif // __MICROPY_INCLUDED_ESP8266_MODPYB_H__ +#endif // MICROPY_INCLUDED_ESP8266_MODMACHINE_H diff --git a/esp8266/modnetwork.c b/esp8266/modnetwork.c index eb9d75e28..b893209c6 100644 --- a/esp8266/modnetwork.c +++ b/esp8266/modnetwork.c @@ -1,9 +1,9 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * - * Copyright (c) 2015 Paul Sokolovsky + * Copyright (c) 2015-2016 Paul Sokolovsky * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -275,8 +275,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_ifconfig_obj, 1, 2, esp_ifconfig) STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { if (n_args != 1 && kwargs->used != 0) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, - "either pos or kw args are allowed")); + mp_raise_TypeError("either pos or kw args are allowed"); } wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]); @@ -303,8 +302,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs mp_buffer_info_t bufinfo; mp_get_buffer_raise(kwargs->table[i].value, &bufinfo, MP_BUFFER_READ); if (bufinfo.len != 6) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "invalid buffer length")); + mp_raise_ValueError("invalid buffer length"); } wifi_set_macaddr(self->if_id, bufinfo.buf); break; @@ -374,8 +372,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs // Get config if (n_args != 2) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, - "can query only one param")); + mp_raise_TypeError("can query only one param"); } mp_obj_t val; @@ -422,20 +419,19 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs return val; unknown: - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "unknown config param")); + mp_raise_ValueError("unknown config param"); } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp_config_obj, 1, esp_config); -STATIC const mp_map_elem_t wlan_if_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR_active), (mp_obj_t)&esp_active_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_connect), (mp_obj_t)&esp_connect_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_disconnect), (mp_obj_t)&esp_disconnect_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_status), (mp_obj_t)&esp_status_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_scan), (mp_obj_t)&esp_scan_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_isconnected), (mp_obj_t)&esp_isconnected_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_config), (mp_obj_t)&esp_config_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_ifconfig), (mp_obj_t)&esp_ifconfig_obj }, +STATIC const mp_rom_map_elem_t wlan_if_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&esp_active_obj) }, + { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&esp_connect_obj) }, + { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&esp_disconnect_obj) }, + { MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&esp_status_obj) }, + { MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&esp_scan_obj) }, + { MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&esp_isconnected_obj) }, + { MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&esp_config_obj) }, + { MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&esp_ifconfig_obj) }, }; STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table); @@ -443,7 +439,7 @@ STATIC MP_DEFINE_CONST_DICT(wlan_if_locals_dict, wlan_if_locals_dict_table); const mp_obj_type_t wlan_if_type = { { &mp_type_type }, .name = MP_QSTR_WLAN, - .locals_dict = (mp_obj_t)&wlan_if_locals_dict, + .locals_dict = (mp_obj_dict_t*)&wlan_if_locals_dict, }; STATIC mp_obj_t esp_phy_mode(mp_uint_t n_args, const mp_obj_t *args) { @@ -456,47 +452,31 @@ STATIC mp_obj_t esp_phy_mode(mp_uint_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_phy_mode_obj, 0, 1, esp_phy_mode); -STATIC const mp_map_elem_t mp_module_network_globals_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_network) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_WLAN), (mp_obj_t)&get_wlan_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_phy_mode), (mp_obj_t)&esp_phy_mode_obj }, +STATIC const mp_rom_map_elem_t mp_module_network_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_network) }, + { MP_ROM_QSTR(MP_QSTR_WLAN), MP_ROM_PTR(&get_wlan_obj) }, + { MP_ROM_QSTR(MP_QSTR_phy_mode), MP_ROM_PTR(&esp_phy_mode_obj) }, #if MODNETWORK_INCLUDE_CONSTANTS - { MP_OBJ_NEW_QSTR(MP_QSTR_STA_IF), - MP_OBJ_NEW_SMALL_INT(STATION_IF)}, - { MP_OBJ_NEW_QSTR(MP_QSTR_AP_IF), - MP_OBJ_NEW_SMALL_INT(SOFTAP_IF)}, - - { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_IDLE), - MP_OBJ_NEW_SMALL_INT(STATION_IDLE)}, - { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_CONNECTING), - MP_OBJ_NEW_SMALL_INT(STATION_CONNECTING)}, - { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_WRONG_PASSWORD), - MP_OBJ_NEW_SMALL_INT(STATION_WRONG_PASSWORD)}, - { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_NO_AP_FOUND), - MP_OBJ_NEW_SMALL_INT(STATION_NO_AP_FOUND)}, - { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_CONNECT_FAIL), - MP_OBJ_NEW_SMALL_INT(STATION_CONNECT_FAIL)}, - { MP_OBJ_NEW_QSTR(MP_QSTR_STAT_GOT_IP), - MP_OBJ_NEW_SMALL_INT(STATION_GOT_IP)}, - - { MP_OBJ_NEW_QSTR(MP_QSTR_MODE_11B), - MP_OBJ_NEW_SMALL_INT(PHY_MODE_11B) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_MODE_11G), - MP_OBJ_NEW_SMALL_INT(PHY_MODE_11G) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_MODE_11N), - MP_OBJ_NEW_SMALL_INT(PHY_MODE_11N) }, - - { MP_OBJ_NEW_QSTR(MP_QSTR_AUTH_OPEN), - MP_OBJ_NEW_SMALL_INT(AUTH_OPEN) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_AUTH_WEP), - MP_OBJ_NEW_SMALL_INT(AUTH_WEP) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_AUTH_WPA_PSK), - MP_OBJ_NEW_SMALL_INT(AUTH_WPA_PSK) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_AUTH_WPA2_PSK), - MP_OBJ_NEW_SMALL_INT(AUTH_WPA2_PSK) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_AUTH_WPA_WPA2_PSK), - MP_OBJ_NEW_SMALL_INT(AUTH_WPA_WPA2_PSK) }, + { MP_ROM_QSTR(MP_QSTR_STA_IF), MP_ROM_INT(STATION_IF)}, + { MP_ROM_QSTR(MP_QSTR_AP_IF), MP_ROM_INT(SOFTAP_IF)}, + + { MP_ROM_QSTR(MP_QSTR_STAT_IDLE), MP_ROM_INT(STATION_IDLE)}, + { MP_ROM_QSTR(MP_QSTR_STAT_CONNECTING), MP_ROM_INT(STATION_CONNECTING)}, + { MP_ROM_QSTR(MP_QSTR_STAT_WRONG_PASSWORD), MP_ROM_INT(STATION_WRONG_PASSWORD)}, + { MP_ROM_QSTR(MP_QSTR_STAT_NO_AP_FOUND), MP_ROM_INT(STATION_NO_AP_FOUND)}, + { MP_ROM_QSTR(MP_QSTR_STAT_CONNECT_FAIL), MP_ROM_INT(STATION_CONNECT_FAIL)}, + { MP_ROM_QSTR(MP_QSTR_STAT_GOT_IP), MP_ROM_INT(STATION_GOT_IP)}, + + { MP_ROM_QSTR(MP_QSTR_MODE_11B), MP_ROM_INT(PHY_MODE_11B) }, + { MP_ROM_QSTR(MP_QSTR_MODE_11G), MP_ROM_INT(PHY_MODE_11G) }, + { MP_ROM_QSTR(MP_QSTR_MODE_11N), MP_ROM_INT(PHY_MODE_11N) }, + + { MP_ROM_QSTR(MP_QSTR_AUTH_OPEN), MP_ROM_INT(AUTH_OPEN) }, + { MP_ROM_QSTR(MP_QSTR_AUTH_WEP), MP_ROM_INT(AUTH_WEP) }, + { MP_ROM_QSTR(MP_QSTR_AUTH_WPA_PSK), MP_ROM_INT(AUTH_WPA_PSK) }, + { MP_ROM_QSTR(MP_QSTR_AUTH_WPA2_PSK), MP_ROM_INT(AUTH_WPA2_PSK) }, + { MP_ROM_QSTR(MP_QSTR_AUTH_WPA_WPA2_PSK), MP_ROM_INT(AUTH_WPA_WPA2_PSK) }, #endif }; diff --git a/esp8266/modpyb.c b/esp8266/modpyb.c index 9fe8039bc..e977191ee 100644 --- a/esp8266/modpyb.c +++ b/esp8266/modpyb.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/esp8266/moduos.c b/esp8266/moduos.c index 807d2e18a..d0554096e 100644 --- a/esp8266/moduos.c +++ b/esp8266/moduos.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/esp8266/modutime.c b/esp8266/modutime.c index bdeb3bb45..afb14dfd6 100644 --- a/esp8266/modutime.c +++ b/esp8266/modutime.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/esp8266/mpconfigport.h b/esp8266/mpconfigport.h index f7df43577..bbded43f4 100644 --- a/esp8266/mpconfigport.h +++ b/esp8266/mpconfigport.h @@ -1,6 +1,6 @@ #include -// options to control how Micro Python is built +// options to control how MicroPython is built #define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_C) #define MICROPY_ALLOC_PATH_MAX (128) @@ -162,7 +162,6 @@ extern const struct _mp_obj_module_t mp_module_onewire; #define MICROPY_PORT_BUILTIN_MODULES \ { MP_OBJ_NEW_QSTR(MP_QSTR_esp), (mp_obj_t)&esp_module }, \ - { MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_lwip }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_usocket), (mp_obj_t)&mp_module_lwip }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_network), (mp_obj_t)&network_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&utime_module }, \ @@ -176,6 +175,7 @@ extern const struct _mp_obj_module_t mp_module_onewire; { MP_OBJ_NEW_QSTR(MP_QSTR_json), (mp_obj_t)&mp_module_ujson }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_errno), (mp_obj_t)&mp_module_uerrno }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_select), (mp_obj_t)&mp_module_uselect }, \ + { MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_lwip }, \ #define MP_STATE_PORT MP_STATE_VM diff --git a/esp8266/qstrdefsport.h b/esp8266/qstrdefsport.h index 7610eb33d..8f301a69c 100644 --- a/esp8266/qstrdefsport.h +++ b/esp8266/qstrdefsport.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/esp8266/uart.h b/esp8266/uart.h index f6850c42d..ebcd8b051 100644 --- a/esp8266/uart.h +++ b/esp8266/uart.h @@ -1,5 +1,5 @@ -#ifndef _INCLUDED_UART_H_ -#define _INCLUDED_UART_H_ +#ifndef MICROPY_INCLUDED_ESP8266_UART_H +#define MICROPY_INCLUDED_ESP8266_UART_H #include @@ -103,4 +103,4 @@ void uart_setup(uint8 uart); int uart_rx_any(uint8 uart); int uart_tx_any_room(uint8 uart); -#endif // _INCLUDED_UART_H_ +#endif // MICROPY_INCLUDED_ESP8266_UART_H diff --git a/esp8266/xtirq.h b/esp8266/xtirq.h index 856ff075a..595052fc7 100644 --- a/esp8266/xtirq.h +++ b/esp8266/xtirq.h @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef __MICROPY_INCLUDED_ESP8266_XTIRQ_H__ -#define __MICROPY_INCLUDED_ESP8266_XTIRQ_H__ +#ifndef MICROPY_INCLUDED_ESP8266_XTIRQ_H +#define MICROPY_INCLUDED_ESP8266_XTIRQ_H #include @@ -57,4 +56,4 @@ static inline void enable_irq(uint32_t irq_state) { restore_irq_pri(irq_state); } -#endif // __MICROPY_INCLUDED_ESP8266_XTIRQ_H__ +#endif // MICROPY_INCLUDED_ESP8266_XTIRQ_H diff --git a/examples/embedding/Makefile.upylib b/examples/embedding/Makefile.upylib index 4663ad30a..a9b653517 100644 --- a/examples/embedding/Makefile.upylib +++ b/examples/embedding/Makefile.upylib @@ -55,8 +55,8 @@ CFLAGS += -U _FORTIFY_SOURCE endif # On OSX, 'gcc' is a symlink to clang unless a real gcc is installed. -# The unix port of micropython on OSX must be compiled with clang, -# while cross-compile ports require gcc, so we test here for OSX and +# The unix port of MicroPython on OSX must be compiled with clang, +# while cross-compile ports require gcc, so we test here for OSX and # if necessary override the value of 'CC' set in py/mkenv.mk ifeq ($(UNAME_S),Darwin) CC = clang diff --git a/examples/embedding/hello-embed.c b/examples/embedding/hello-embed.c index e3a484783..3473e5bcd 100644 --- a/examples/embedding/hello-embed.c +++ b/examples/embedding/hello-embed.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/examples/embedding/mpconfigport_minimal.h b/examples/embedding/mpconfigport_minimal.h index 87c87fa97..5b96aa4b0 100644 --- a/examples/embedding/mpconfigport_minimal.h +++ b/examples/embedding/mpconfigport_minimal.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -// options to control how Micro Python is built +// options to control how MicroPython is built #define MICROPY_ALLOC_PATH_MAX (PATH_MAX) #define MICROPY_ENABLE_GC (1) diff --git a/extmod/lwip-include/arch/cc.h b/extmod/lwip-include/arch/cc.h index 0a7907d34..400dc6ec7 100644 --- a/extmod/lwip-include/arch/cc.h +++ b/extmod/lwip-include/arch/cc.h @@ -1,5 +1,5 @@ -#ifndef __CC_H__ -#define __CC_H__ +#ifndef MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_ARCH_CC_H +#define MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_ARCH_CC_H #include @@ -38,4 +38,4 @@ typedef u32_t mem_ptr_t; #define PACK_STRUCT_BEGIN #define PACK_STRUCT_END -#endif /* __ARCH_CC_H__ */ +#endif // MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_ARCH_CC_H diff --git a/extmod/lwip-include/arch/perf.h b/extmod/lwip-include/arch/perf.h index 51710701a..d310fc339 100644 --- a/extmod/lwip-include/arch/perf.h +++ b/extmod/lwip-include/arch/perf.h @@ -1,7 +1,7 @@ -#ifndef __PERF_H__ -#define __PERF_H__ +#ifndef MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_ARCH_PERF_H +#define MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_ARCH_PERF_H #define PERF_START /* null definition */ #define PERF_STOP(x) /* null definition */ -#endif /* __PERF_H__ */ +#endif // MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_ARCH_PERF_H diff --git a/extmod/lwip-include/lwipopts.h b/extmod/lwip-include/lwipopts.h index e4a33b238..2122f30f0 100644 --- a/extmod/lwip-include/lwipopts.h +++ b/extmod/lwip-include/lwipopts.h @@ -1,5 +1,5 @@ -#ifndef __LWIPOPTS_H__ -#define __LWIPOPTS_H__ +#ifndef MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_LWIPOPTS_H +#define MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_LWIPOPTS_H #include #include @@ -32,5 +32,4 @@ typedef uint32_t sys_prot_t; // things like this into a port-provided header file. #define sys_now mp_hal_ticks_ms -#endif - +#endif // MICROPY_INCLUDED_EXTMOD_LWIP_INCLUDE_LWIPOPTS_H diff --git a/extmod/machine_i2c.h b/extmod/machine_i2c.h index d49ff01e4..f5af6656f 100644 --- a/extmod/machine_i2c.h +++ b/extmod/machine_i2c.h @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef __MICROPY_INCLUDED_EXTMOD_MACHINE_I2C_H__ -#define __MICROPY_INCLUDED_EXTMOD_MACHINE_I2C_H__ +#ifndef MICROPY_INCLUDED_EXTMOD_MACHINE_I2C_H +#define MICROPY_INCLUDED_EXTMOD_MACHINE_I2C_H #include "py/obj.h" @@ -54,4 +53,4 @@ extern const mp_obj_dict_t mp_machine_soft_i2c_locals_dict; int mp_machine_soft_i2c_readfrom(mp_obj_base_t *self_in, uint16_t addr, uint8_t *dest, size_t len, bool stop); int mp_machine_soft_i2c_writeto(mp_obj_base_t *self_in, uint16_t addr, const uint8_t *src, size_t len, bool stop); -#endif // __MICROPY_INCLUDED_EXTMOD_MACHINE_I2C_H__ +#endif // MICROPY_INCLUDED_EXTMOD_MACHINE_I2C_H diff --git a/extmod/machine_mem.c b/extmod/machine_mem.c index 88c176803..af987cb7f 100644 --- a/extmod/machine_mem.c +++ b/extmod/machine_mem.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/extmod/machine_mem.h b/extmod/machine_mem.h index fddd7d46c..a48a52c82 100644 --- a/extmod/machine_mem.h +++ b/extmod/machine_mem.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,10 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - - -#ifndef __MICROPY_INCLUDED_EXTMOD_MACHINE_MEM_H__ -#define __MICROPY_INCLUDED_EXTMOD_MACHINE_MEM_H__ +#ifndef MICROPY_INCLUDED_EXTMOD_MACHINE_MEM_H +#define MICROPY_INCLUDED_EXTMOD_MACHINE_MEM_H #include "py/obj.h" @@ -48,4 +46,4 @@ uintptr_t MICROPY_MACHINE_MEM_GET_READ_ADDR(mp_obj_t addr_o, uint align); uintptr_t MICROPY_MACHINE_MEM_GET_WRITE_ADDR(mp_obj_t addr_o, uint align); #endif -#endif // __MICROPY_INCLUDED_EXTMOD_MACHINE_MEM_H__ +#endif // MICROPY_INCLUDED_EXTMOD_MACHINE_MEM_H diff --git a/extmod/machine_pinbase.h b/extmod/machine_pinbase.h index ece3384cc..c96abbc46 100644 --- a/extmod/machine_pinbase.h +++ b/extmod/machine_pinbase.h @@ -23,13 +23,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - - -#ifndef __MICROPY_INCLUDED_EXTMOD_MACHINE_PINBASE_H__ -#define __MICROPY_INCLUDED_EXTMOD_MACHINE_PINBASE_H__ +#ifndef MICROPY_INCLUDED_EXTMOD_MACHINE_PINBASE_H +#define MICROPY_INCLUDED_EXTMOD_MACHINE_PINBASE_H #include "py/obj.h" extern const mp_obj_type_t machine_pinbase_type; -#endif // __MICROPY_INCLUDED_EXTMOD_MACHINE_PINBASE_H__ +#endif // MICROPY_INCLUDED_EXTMOD_MACHINE_PINBASE_H diff --git a/extmod/machine_pulse.h b/extmod/machine_pulse.h index cc1c4eda5..e303dca02 100644 --- a/extmod/machine_pulse.h +++ b/extmod/machine_pulse.h @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef __MICROPY_INCLUDED_EXTMOD_MACHINE_PULSE_H__ -#define __MICROPY_INCLUDED_EXTMOD_MACHINE_PULSE_H__ +#ifndef MICROPY_INCLUDED_EXTMOD_MACHINE_PULSE_H +#define MICROPY_INCLUDED_EXTMOD_MACHINE_PULSE_H #include "py/obj.h" #include "py/mphal.h" @@ -34,4 +33,4 @@ mp_uint_t machine_time_pulse_us(mp_hal_pin_obj_t pin, int pulse_level, mp_uint_t MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_time_pulse_us_obj); -#endif // __MICROPY_INCLUDED_EXTMOD_MACHINE_PULSE_H__ +#endif // MICROPY_INCLUDED_EXTMOD_MACHINE_PULSE_H diff --git a/extmod/machine_signal.c b/extmod/machine_signal.c index d08931296..78d0c3fee 100644 --- a/extmod/machine_signal.c +++ b/extmod/machine_signal.c @@ -96,7 +96,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t if (n_args == 1) { if (n_kw == 0) { } else if (n_kw == 1 && args[1] == MP_OBJ_NEW_QSTR(MP_QSTR_invert)) { - invert = mp_obj_is_true(args[1]); + invert = mp_obj_is_true(args[2]); } else { goto error; } diff --git a/extmod/machine_signal.h b/extmod/machine_signal.h index 7f88cbaa8..df1c3e2e9 100644 --- a/extmod/machine_signal.h +++ b/extmod/machine_signal.h @@ -23,13 +23,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - - -#ifndef __MICROPY_INCLUDED_EXTMOD_MACHINE_SIGNAL_H__ -#define __MICROPY_INCLUDED_EXTMOD_MACHINE_SIGNAL_H__ +#ifndef MICROPY_INCLUDED_EXTMOD_MACHINE_SIGNAL_H +#define MICROPY_INCLUDED_EXTMOD_MACHINE_SIGNAL_H #include "py/obj.h" extern const mp_obj_type_t machine_signal_type; -#endif // __MICROPY_INCLUDED_EXTMOD_MACHINE_SIGNAL_H__ +#endif // MICROPY_INCLUDED_EXTMOD_MACHINE_SIGNAL_H diff --git a/extmod/machine_spi.h b/extmod/machine_spi.h index 88a3e19f4..e24e41eb3 100644 --- a/extmod/machine_spi.h +++ b/extmod/machine_spi.h @@ -23,7 +23,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - #ifndef MICROPY_INCLUDED_EXTMOD_MACHINE_SPI_H #define MICROPY_INCLUDED_EXTMOD_MACHINE_SPI_H diff --git a/extmod/misc.h b/extmod/misc.h index d7ead0654..6c13592c7 100644 --- a/extmod/misc.h +++ b/extmod/misc.h @@ -24,6 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_EXTMOD_MISC_H +#define MICROPY_INCLUDED_EXTMOD_MISC_H // This file contains cumulative declarations for extmod/ . @@ -38,3 +40,5 @@ void mp_uos_deactivate(const char *msg, mp_obj_t exc); #else #define mp_uos_dupterm_tx_strn(s, l) #endif + +#endif // MICROPY_INCLUDED_EXTMOD_MISC_H diff --git a/extmod/modbtree.c b/extmod/modbtree.c index 127dd71a3..229daaf0f 100644 --- a/extmod/modbtree.c +++ b/extmod/modbtree.c @@ -26,7 +26,7 @@ #include #include -#include +#include // for declaration of global errno variable #include #include "py/nlr.h" diff --git a/extmod/modframebuf.c b/extmod/modframebuf.c index 062a63c3b..f4e857129 100644 --- a/extmod/modframebuf.c +++ b/extmod/modframebuf.c @@ -62,10 +62,10 @@ typedef struct _mp_framebuf_p_t { // Functions for MHLSB and MHMSB -STATIC void mono_horiz_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t color) { +STATIC void mono_horiz_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) { size_t index = (x + y * fb->stride) >> 3; int offset = fb->format == FRAMEBUF_MHMSB ? x & 0x07 : 7 - (x & 0x07); - ((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((color != 0) << offset); + ((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset); } STATIC uint32_t mono_horiz_getpixel(const mp_obj_framebuf_t *fb, int x, int y) { @@ -90,10 +90,10 @@ STATIC void mono_horiz_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int // Functions for MVLSB format -STATIC void mvlsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t color) { +STATIC void mvlsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) { size_t index = (y >> 3) * fb->stride + x; uint8_t offset = y & 0x07; - ((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((color != 0) << offset); + ((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset); } STATIC uint32_t mvlsb_getpixel(const mp_obj_framebuf_t *fb, int x, int y) { @@ -114,19 +114,19 @@ STATIC void mvlsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, in // Functions for RGB565 format -STATIC void rgb565_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t color) { - ((uint16_t*)fb->buf)[x + y * fb->stride] = color; +STATIC void rgb565_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) { + ((uint16_t*)fb->buf)[x + y * fb->stride] = col; } STATIC uint32_t rgb565_getpixel(const mp_obj_framebuf_t *fb, int x, int y) { return ((uint16_t*)fb->buf)[x + y * fb->stride]; } -STATIC void rgb565_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t colour) { +STATIC void rgb565_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) { uint16_t *b = &((uint16_t*)fb->buf)[x + y * fb->stride]; while (h--) { for (int ww = w; ww; --ww) { - *b++ = colour; + *b++ = col; } b += fb->stride - w; } @@ -156,7 +156,7 @@ STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, col &= 0x0f; uint8_t *pixel_pair = &((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1]; uint8_t col_shifted_left = col << 4; - uint8_t colored_pixel_pair = col_shifted_left | col; + uint8_t col_pixel_pair = col_shifted_left | col; int pixel_count_till_next_line = (fb->stride - w) >> 1; bool odd_x = (x % 2 == 1); @@ -169,7 +169,7 @@ STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, ww--; } - memset(pixel_pair, colored_pixel_pair, ww >> 1); + memset(pixel_pair, col_pixel_pair, ww >> 1); pixel_pair += ww >> 1; if (ww % 2) { @@ -191,8 +191,8 @@ STATIC mp_framebuf_p_t formats[] = { [FRAMEBUF_MHMSB] = {mono_horiz_setpixel, mono_horiz_getpixel, mono_horiz_fill_rect}, }; -static inline void setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t color) { - formats[fb->format].setpixel(fb, x, y, color); +static inline void setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) { + formats[fb->format].setpixel(fb, x, y, col); } static inline uint32_t getpixel(const mp_obj_framebuf_t *fb, int x, int y) { @@ -237,12 +237,14 @@ STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size switch (o->format) { case FRAMEBUF_MVLSB: case FRAMEBUF_RGB565: - case FRAMEBUF_GS4_HMSB: break; case FRAMEBUF_MHLSB: case FRAMEBUF_MHMSB: o->stride = (o->stride + 7) & ~7; break; + case FRAMEBUF_GS4_HMSB: + o->stride = (o->stride + 1) & ~1; + break; default: mp_raise_ValueError("invalid format"); } @@ -275,9 +277,9 @@ STATIC mp_obj_t framebuf_fill_rect(size_t n_args, const mp_obj_t *args) { mp_int_t y = mp_obj_get_int(args[2]); mp_int_t width = mp_obj_get_int(args[3]); mp_int_t height = mp_obj_get_int(args[4]); - mp_int_t color = mp_obj_get_int(args[5]); + mp_int_t col = mp_obj_get_int(args[5]); - fill_rect(self, x, y, width, height, color); + fill_rect(self, x, y, width, height, col); return mp_const_none; } @@ -442,14 +444,13 @@ STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) { int y1 = MAX(0, -y); int x0end = MIN(self->width, x + source->width); int y0end = MIN(self->height, y + source->height); - uint32_t color; for (; y0 < y0end; ++y0) { int cx1 = x1; for (int cx0 = x0; cx0 < x0end; ++cx0) { - color = getpixel(source, cx1, y1); - if (color != (uint32_t)key) { - setpixel(self, cx0, y0, color); + uint32_t col = getpixel(source, cx1, y1); + if (col != (uint32_t)key) { + setpixel(self, cx0, y0, col); } ++cx1; } @@ -548,7 +549,7 @@ STATIC const mp_obj_type_t mp_type_framebuf = { .name = MP_QSTR_FrameBuffer, .make_new = framebuf_make_new, .buffer_p = { .get_buffer = framebuf_get_buffer }, - .locals_dict = (mp_obj_t)&framebuf_locals_dict, + .locals_dict = (mp_obj_dict_t*)&framebuf_locals_dict, }; // this factory function is provided for backwards compatibility with old FrameBuffer1 class @@ -577,12 +578,12 @@ STATIC const mp_rom_map_elem_t framebuf_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_framebuf) }, { MP_ROM_QSTR(MP_QSTR_FrameBuffer), MP_ROM_PTR(&mp_type_framebuf) }, { MP_ROM_QSTR(MP_QSTR_FrameBuffer1), MP_ROM_PTR(&legacy_framebuffer1_obj) }, - { MP_ROM_QSTR(MP_QSTR_MVLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MVLSB) }, - { MP_ROM_QSTR(MP_QSTR_MONO_VLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MVLSB) }, - { MP_ROM_QSTR(MP_QSTR_RGB565), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_RGB565) }, - { MP_ROM_QSTR(MP_QSTR_GS4_HMSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_GS4_HMSB) }, - { MP_ROM_QSTR(MP_QSTR_MONO_HLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MHLSB) }, - { MP_ROM_QSTR(MP_QSTR_MONO_HMSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MHMSB) }, + { MP_ROM_QSTR(MP_QSTR_MVLSB), MP_ROM_INT(FRAMEBUF_MVLSB) }, + { MP_ROM_QSTR(MP_QSTR_MONO_VLSB), MP_ROM_INT(FRAMEBUF_MVLSB) }, + { MP_ROM_QSTR(MP_QSTR_RGB565), MP_ROM_INT(FRAMEBUF_RGB565) }, + { MP_ROM_QSTR(MP_QSTR_GS4_HMSB), MP_ROM_INT(FRAMEBUF_GS4_HMSB) }, + { MP_ROM_QSTR(MP_QSTR_MONO_HLSB), MP_ROM_INT(FRAMEBUF_MHLSB) }, + { MP_ROM_QSTR(MP_QSTR_MONO_HMSB), MP_ROM_INT(FRAMEBUF_MHMSB) }, }; STATIC MP_DEFINE_CONST_DICT(framebuf_module_globals, framebuf_module_globals_table); diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 01190d200..cc10523e5 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -5,7 +5,7 @@ * * Copyright (c) 2013, 2014 Damien P. George * Copyright (c) 2015 Galen Hazelwood - * Copyright (c) 2015-2016 Paul Sokolovsky + * Copyright (c) 2015-2017 Paul Sokolovsky * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -45,6 +45,7 @@ //#include "lwip/raw.h" #include "lwip/dns.h" #include "lwip/tcp_impl.h" +#include "lwip/igmp.h" #if 0 // print debugging info #define DEBUG_printf DEBUG_printf @@ -52,6 +53,10 @@ #define DEBUG_printf(...) (void)0 #endif +// All socket options should be globally distinct, +// because we ignore option levels for efficiency. +#define IP_ADD_MEMBERSHIP 0x400 + // For compatibilily with older lwIP versions. #ifndef ip_set_option #define ip_set_option(pcb, opt) ((pcb)->so_options |= (opt)) @@ -124,15 +129,15 @@ STATIC mp_obj_t lwip_slip_make_new(mp_obj_t type_in, size_t n_args, size_t n_kw, ip_addr_t iplocal, ipremote; if (!ipaddr_aton(mp_obj_str_get_str(args[1]), &iplocal)) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "not a valid local IP")); + mp_raise_ValueError("not a valid local IP"); } if (!ipaddr_aton(mp_obj_str_get_str(args[2]), &ipremote)) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "not a valid remote IP")); + mp_raise_ValueError("not a valid remote IP"); } struct netif *n = &lwip_slip_obj.lwip_netif; if (netif_add(n, &iplocal, IP_ADDR_BROADCAST, &ipremote, NULL, slipif_init, ip_input) == NULL) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "out of memory")); + mp_raise_ValueError("out of memory"); } netif_set_up(n); netif_set_default(n); @@ -148,8 +153,8 @@ STATIC mp_obj_t lwip_slip_status(mp_obj_t self_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(lwip_slip_status_obj, lwip_slip_status); -STATIC const mp_map_elem_t lwip_slip_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR_status), (mp_obj_t)&lwip_slip_status_obj }, +STATIC const mp_rom_map_elem_t lwip_slip_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&lwip_slip_status_obj) }, }; STATIC MP_DEFINE_CONST_DICT(lwip_slip_locals_dict, lwip_slip_locals_dict_table); @@ -158,7 +163,7 @@ STATIC const mp_obj_type_t lwip_slip_type = { { &mp_type_type }, .name = MP_QSTR_slip, .make_new = lwip_slip_make_new, - .locals_dict = (mp_obj_t)&lwip_slip_locals_dict, + .locals_dict = (mp_obj_dict_t*)&lwip_slip_locals_dict, }; #endif // MICROPY_PY_LWIP_SLIP @@ -1028,7 +1033,7 @@ STATIC mp_obj_t lwip_socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) { break; } case MOD_NETWORK_SOCK_DGRAM: - mp_not_implemented(""); + mp_raise_NotImplementedError(""); break; } @@ -1079,10 +1084,10 @@ STATIC mp_obj_t lwip_socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) { return mp_const_none; } - // Integer options - mp_int_t val = mp_obj_get_int(args[3]); switch (opt) { - case SOF_REUSEADDR: + // level: SOL_SOCKET + case SOF_REUSEADDR: { + mp_int_t val = mp_obj_get_int(args[3]); // Options are common for UDP and TCP pcb's. if (val) { ip_set_option(socket->pcb.tcp, SOF_REUSEADDR); @@ -1090,6 +1095,24 @@ STATIC mp_obj_t lwip_socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) { ip_reset_option(socket->pcb.tcp, SOF_REUSEADDR); } break; + } + + // level: IPPROTO_IP + case IP_ADD_MEMBERSHIP: { + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ); + if (bufinfo.len != sizeof(ip_addr_t) * 2) { + mp_raise_ValueError(NULL); + } + + // POSIX setsockopt has order: group addr, if addr, lwIP has it vice-versa + err_t err = igmp_joingroup((ip_addr_t*)bufinfo.buf + 1, bufinfo.buf); + if (err != ERR_OK) { + mp_raise_OSError(error_lookup_table[-err]); + } + break; + } + default: printf("Warning: lwip.setsockopt() not implemented\n"); } @@ -1160,27 +1183,27 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_ return ret; } -STATIC const mp_map_elem_t lwip_socket_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)&lwip_socket_close_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&lwip_socket_close_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_bind), (mp_obj_t)&lwip_socket_bind_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_listen), (mp_obj_t)&lwip_socket_listen_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_accept), (mp_obj_t)&lwip_socket_accept_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_connect), (mp_obj_t)&lwip_socket_connect_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_send), (mp_obj_t)&lwip_socket_send_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_recv), (mp_obj_t)&lwip_socket_recv_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_sendto), (mp_obj_t)&lwip_socket_sendto_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_recvfrom), (mp_obj_t)&lwip_socket_recvfrom_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_sendall), (mp_obj_t)&lwip_socket_sendall_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_settimeout), (mp_obj_t)&lwip_socket_settimeout_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_setblocking), (mp_obj_t)&lwip_socket_setblocking_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_setsockopt), (mp_obj_t)&lwip_socket_setsockopt_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_makefile), (mp_obj_t)&lwip_socket_makefile_obj }, - - { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_readinto), (mp_obj_t)&mp_stream_readinto_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_readline), (mp_obj_t)&mp_stream_unbuffered_readline_obj}, - { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj }, +STATIC const mp_rom_map_elem_t lwip_socket_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&lwip_socket_close_obj) }, + { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&lwip_socket_close_obj) }, + { MP_ROM_QSTR(MP_QSTR_bind), MP_ROM_PTR(&lwip_socket_bind_obj) }, + { MP_ROM_QSTR(MP_QSTR_listen), MP_ROM_PTR(&lwip_socket_listen_obj) }, + { MP_ROM_QSTR(MP_QSTR_accept), MP_ROM_PTR(&lwip_socket_accept_obj) }, + { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&lwip_socket_connect_obj) }, + { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&lwip_socket_send_obj) }, + { MP_ROM_QSTR(MP_QSTR_recv), MP_ROM_PTR(&lwip_socket_recv_obj) }, + { MP_ROM_QSTR(MP_QSTR_sendto), MP_ROM_PTR(&lwip_socket_sendto_obj) }, + { MP_ROM_QSTR(MP_QSTR_recvfrom), MP_ROM_PTR(&lwip_socket_recvfrom_obj) }, + { MP_ROM_QSTR(MP_QSTR_sendall), MP_ROM_PTR(&lwip_socket_sendall_obj) }, + { MP_ROM_QSTR(MP_QSTR_settimeout), MP_ROM_PTR(&lwip_socket_settimeout_obj) }, + { MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&lwip_socket_setblocking_obj) }, + { MP_ROM_QSTR(MP_QSTR_setsockopt), MP_ROM_PTR(&lwip_socket_setsockopt_obj) }, + { MP_ROM_QSTR(MP_QSTR_makefile), MP_ROM_PTR(&lwip_socket_makefile_obj) }, + + { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, + { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, + { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) }, + { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) }, }; STATIC MP_DEFINE_CONST_DICT(lwip_socket_locals_dict, lwip_socket_locals_dict_table); @@ -1196,7 +1219,7 @@ STATIC const mp_obj_type_t lwip_socket_type = { .print = lwip_socket_print, .make_new = lwip_socket_make_new, .protocol = &lwip_socket_stream_p, - .locals_dict = (mp_obj_t)&lwip_socket_locals_dict, + .locals_dict = (mp_obj_dict_t*)&lwip_socket_locals_dict, }; /******************************************************************************/ @@ -1321,27 +1344,30 @@ MP_DEFINE_CONST_FUN_OBJ_0(lwip_print_pcbs_obj, lwip_print_pcbs); #ifdef MICROPY_PY_LWIP -STATIC const mp_map_elem_t mp_module_lwip_globals_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_lwip) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_reset), (mp_obj_t)&mod_lwip_reset_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_callback), (mp_obj_t)&mod_lwip_callback_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&lwip_getaddrinfo_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_print_pcbs), (mp_obj_t)&lwip_print_pcbs_obj }, +STATIC const mp_rom_map_elem_t mp_module_lwip_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_lwip) }, + { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&mod_lwip_reset_obj) }, + { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&mod_lwip_callback_obj) }, + { MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&lwip_getaddrinfo_obj) }, + { MP_ROM_QSTR(MP_QSTR_print_pcbs), MP_ROM_PTR(&lwip_print_pcbs_obj) }, // objects - { MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&lwip_socket_type }, + { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&lwip_socket_type) }, #ifdef MICROPY_PY_LWIP_SLIP - { MP_OBJ_NEW_QSTR(MP_QSTR_slip), (mp_obj_t)&lwip_slip_type }, + { MP_ROM_QSTR(MP_QSTR_slip), MP_ROM_PTR(&lwip_slip_type) }, #endif // class constants - { MP_OBJ_NEW_QSTR(MP_QSTR_AF_INET), MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_AF_INET) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_AF_INET6), MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_AF_INET6) }, + { MP_ROM_QSTR(MP_QSTR_AF_INET), MP_ROM_INT(MOD_NETWORK_AF_INET) }, + { MP_ROM_QSTR(MP_QSTR_AF_INET6), MP_ROM_INT(MOD_NETWORK_AF_INET6) }, + + { MP_ROM_QSTR(MP_QSTR_SOCK_STREAM), MP_ROM_INT(MOD_NETWORK_SOCK_STREAM) }, + { MP_ROM_QSTR(MP_QSTR_SOCK_DGRAM), MP_ROM_INT(MOD_NETWORK_SOCK_DGRAM) }, + { MP_ROM_QSTR(MP_QSTR_SOCK_RAW), MP_ROM_INT(MOD_NETWORK_SOCK_RAW) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_STREAM), MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_SOCK_STREAM) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_DGRAM), MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_SOCK_DGRAM) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_SOCK_RAW), MP_OBJ_NEW_SMALL_INT(MOD_NETWORK_SOCK_RAW) }, + { MP_ROM_QSTR(MP_QSTR_SOL_SOCKET), MP_ROM_INT(1) }, + { MP_ROM_QSTR(MP_QSTR_SO_REUSEADDR), MP_ROM_INT(SOF_REUSEADDR) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_SOL_SOCKET), MP_OBJ_NEW_SMALL_INT(1) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_SO_REUSEADDR), MP_OBJ_NEW_SMALL_INT(SOF_REUSEADDR) }, + { MP_ROM_QSTR(MP_QSTR_IPPROTO_IP), MP_ROM_INT(0) }, + { MP_ROM_QSTR(MP_QSTR_IP_ADD_MEMBERSHIP), MP_ROM_INT(IP_ADD_MEMBERSHIP) }, }; STATIC MP_DEFINE_CONST_DICT(mp_module_lwip_globals, mp_module_lwip_globals_table); diff --git a/extmod/modonewire.c b/extmod/modonewire.c index 8583cc1c2..53c9456c2 100644 --- a/extmod/modonewire.c +++ b/extmod/modonewire.c @@ -143,15 +143,15 @@ STATIC mp_obj_t onewire_crc8(mp_obj_t data) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(onewire_crc8_obj, onewire_crc8); -STATIC const mp_map_elem_t onewire_module_globals_table[] = { +STATIC const mp_rom_map_elem_t onewire_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_onewire) }, - { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR((mp_obj_t)&onewire_reset_obj) }, - { MP_ROM_QSTR(MP_QSTR_readbit), MP_ROM_PTR((mp_obj_t)&onewire_readbit_obj) }, - { MP_ROM_QSTR(MP_QSTR_readbyte), MP_ROM_PTR((mp_obj_t)&onewire_readbyte_obj) }, - { MP_ROM_QSTR(MP_QSTR_writebit), MP_ROM_PTR((mp_obj_t)&onewire_writebit_obj) }, - { MP_ROM_QSTR(MP_QSTR_writebyte), MP_ROM_PTR((mp_obj_t)&onewire_writebyte_obj) }, - { MP_ROM_QSTR(MP_QSTR_crc8), MP_ROM_PTR((mp_obj_t)&onewire_crc8_obj) }, + { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&onewire_reset_obj) }, + { MP_ROM_QSTR(MP_QSTR_readbit), MP_ROM_PTR(&onewire_readbit_obj) }, + { MP_ROM_QSTR(MP_QSTR_readbyte), MP_ROM_PTR(&onewire_readbyte_obj) }, + { MP_ROM_QSTR(MP_QSTR_writebit), MP_ROM_PTR(&onewire_writebit_obj) }, + { MP_ROM_QSTR(MP_QSTR_writebyte), MP_ROM_PTR(&onewire_writebyte_obj) }, + { MP_ROM_QSTR(MP_QSTR_crc8), MP_ROM_PTR(&onewire_crc8_obj) }, }; STATIC MP_DEFINE_CONST_DICT(onewire_module_globals, onewire_module_globals_table); diff --git a/extmod/modubinascii.c b/extmod/modubinascii.c index cf250d27f..b02d83318 100644 --- a/extmod/modubinascii.c +++ b/extmod/modubinascii.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -105,54 +105,64 @@ mp_obj_t mod_binascii_unhexlify(mp_obj_t data) { } MP_DEFINE_CONST_FUN_OBJ_1(mod_binascii_unhexlify_obj, mod_binascii_unhexlify); +// If ch is a character in the base64 alphabet, and is not a pad character, then +// the corresponding integer between 0 and 63, inclusively, is returned. +// Otherwise, -1 is returned. +static int mod_binascii_sextet(byte ch) { + if (ch >= 'A' && ch <= 'Z') { + return ch - 'A'; + } else if (ch >= 'a' && ch <= 'z') { + return ch - 'a' + 26; + } else if (ch >= '0' && ch <= '9') { + return ch - '0' + 52; + } else if (ch == '+') { + return 62; + } else if (ch == '/') { + return 63; + } else { + return -1; + } +} + mp_obj_t mod_binascii_a2b_base64(mp_obj_t data) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ); - if (bufinfo.len % 4 != 0) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "incorrect padding")); - } + byte *in = bufinfo.buf; vstr_t vstr; - byte *in = bufinfo.buf; - if (bufinfo.len == 0) { - vstr_init_len(&vstr, 0); - } - else { - vstr_init_len(&vstr, ((bufinfo.len / 4) * 3) - ((in[bufinfo.len-1] == '=') ? ((in[bufinfo.len-2] == '=') ? 2 : 1 ) : 0)); - } - byte *out = (byte*)vstr.buf; - for (mp_uint_t i = bufinfo.len; i; i -= 4) { - char hold[4]; - for (int j = 4; j--;) { - if (in[j] >= 'A' && in[j] <= 'Z') { - hold[j] = in[j] - 'A'; - } else if (in[j] >= 'a' && in[j] <= 'z') { - hold[j] = in[j] - 'a' + 26; - } else if (in[j] >= '0' && in[j] <= '9') { - hold[j] = in[j] - '0' + 52; - } else if (in[j] == '+') { - hold[j] = 62; - } else if (in[j] == '/') { - hold[j] = 63; - } else if (in[j] == '=') { - if (j < 2 || i > 4) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "incorrect padding")); - } - hold[j] = 64; - } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid character")); + vstr_init(&vstr, (bufinfo.len / 4) * 3 + 1); // Potentially over-allocate + byte *out = (byte *)vstr.buf; + + uint shift = 0; + int nbits = 0; // Number of meaningful bits in shift + bool hadpad = false; // Had a pad character since last valid character + for (size_t i = 0; i < bufinfo.len; i++) { + if (in[i] == '=') { + if ((nbits == 2) || ((nbits == 4) && hadpad)) { + nbits = 0; + break; } + hadpad = true; } - in += 4; - *out++ = (hold[0]) << 2 | (hold[1]) >> 4; - if (hold[2] != 64) { - *out++ = (hold[1] & 0x0F) << 4 | hold[2] >> 2; - if (hold[3] != 64) { - *out++ = (hold[2] & 0x03) << 6 | hold[3]; - } + int sextet = mod_binascii_sextet(in[i]); + if (sextet == -1) { + continue; + } + hadpad = false; + shift = (shift << 6) | sextet; + nbits += 6; + + if (nbits >= 8) { + nbits -= 8; + out[vstr.len++] = (shift >> nbits) & 0xFF; } } + + if (nbits) { + mp_raise_ValueError("incorrect padding"); + } + return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); } MP_DEFINE_CONST_FUN_OBJ_1(mod_binascii_a2b_base64_obj, mod_binascii_a2b_base64); diff --git a/extmod/modubinascii.h b/extmod/modubinascii.h index 33d0f1cbd..fb3169267 100644 --- a/extmod/modubinascii.h +++ b/extmod/modubinascii.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef MICROPY_EXTMOD_MODUBINASCII -#define MICROPY_EXTMOD_MODUBINASCII +#ifndef MICROPY_INCLUDED_EXTMOD_MODUBINASCII_H +#define MICROPY_INCLUDED_EXTMOD_MODUBINASCII_H extern mp_obj_t mod_binascii_hexlify(size_t n_args, const mp_obj_t *args); extern mp_obj_t mod_binascii_unhexlify(mp_obj_t data); @@ -39,4 +38,4 @@ MP_DECLARE_CONST_FUN_OBJ_1(mod_binascii_a2b_base64_obj); MP_DECLARE_CONST_FUN_OBJ_1(mod_binascii_b2a_base64_obj); MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mod_binascii_crc32_obj); -#endif /* MICROPY_EXTMOD_MODUBINASCII */ +#endif // MICROPY_INCLUDED_EXTMOD_MODUBINASCII_H diff --git a/extmod/moductypes.c b/extmod/moductypes.c index d2d2e85de..dc03f6de5 100644 --- a/extmod/moductypes.c +++ b/extmod/moductypes.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -118,7 +118,7 @@ typedef struct _mp_obj_uctypes_struct_t { } mp_obj_uctypes_struct_t; STATIC NORETURN void syntax_error(void) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "syntax error in uctypes descriptor")); + mp_raise_TypeError("syntax error in uctypes descriptor"); } STATIC mp_obj_t uctypes_struct_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { @@ -215,7 +215,7 @@ STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_ // but scalar structure field is lowered into native Python int, so all // type info is lost. So, we cannot say if it's scalar type description, // or such lowered scalar. - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "Cannot unambiguously get sizeof scalar")); + mp_raise_TypeError("Cannot unambiguously get sizeof scalar"); } syntax_error(); } @@ -281,13 +281,13 @@ STATIC mp_obj_t uctypes_struct_sizeof(mp_obj_t obj_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(uctypes_struct_sizeof_obj, uctypes_struct_sizeof); -STATIC inline mp_obj_t get_unaligned(uint val_type, byte *p, int big_endian) { +static inline mp_obj_t get_unaligned(uint val_type, byte *p, int big_endian) { char struct_type = big_endian ? '>' : '<'; static const char type2char[16] = "BbHhIiQq------fd"; return mp_binary_get_val(struct_type, type2char[val_type], &p); } -STATIC inline void set_unaligned(uint val_type, byte *p, int big_endian, mp_obj_t val) { +static inline void set_unaligned(uint val_type, byte *p, int big_endian, mp_obj_t val) { char struct_type = big_endian ? '>' : '<'; static const char type2char[16] = "BbHhIiQq------fd"; mp_binary_set_val(struct_type, type2char[val_type], val, &p); @@ -393,7 +393,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set // TODO: Support at least OrderedDict in addition if (!MP_OBJ_IS_TYPE(self->desc, &mp_type_dict)) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "struct: no fields")); + mp_raise_TypeError("struct: no fields"); } mp_obj_t deref = mp_obj_dict_get(self->desc, MP_OBJ_NEW_QSTR(attr)); @@ -526,7 +526,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob } else { // load / store if (!MP_OBJ_IS_TYPE(self->desc, &mp_type_tuple)) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "struct: cannot index")); + mp_raise_TypeError("struct: cannot index"); } mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->desc); diff --git a/extmod/moduhashlib.c b/extmod/moduhashlib.c index 13525cc3f..f3beb3939 100644 --- a/extmod/moduhashlib.c +++ b/extmod/moduhashlib.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/extmod/moduheapq.c b/extmod/moduheapq.c index 567ee83da..4a620bad8 100644 --- a/extmod/moduheapq.c +++ b/extmod/moduheapq.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -35,7 +35,7 @@ STATIC mp_obj_list_t *get_heap(mp_obj_t heap_in) { if (!MP_OBJ_IS_TYPE(heap_in, &mp_type_list)) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "heap must be a list")); + mp_raise_TypeError("heap must be a list"); } return MP_OBJ_TO_PTR(heap_in); } diff --git a/extmod/modujson.c b/extmod/modujson.c index f94ec7db8..6c4aa1611 100644 --- a/extmod/modujson.c +++ b/extmod/modujson.c @@ -269,7 +269,7 @@ STATIC mp_obj_t mod_ujson_load(mp_obj_t stream_obj) { return stack_top; fail: - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "syntax error in JSON")); + mp_raise_ValueError("syntax error in JSON"); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_load_obj, mod_ujson_load); diff --git a/extmod/modure.c b/extmod/modure.c index b4c7a364f..2baebdecc 100644 --- a/extmod/modure.c +++ b/extmod/modure.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -156,7 +156,7 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) { mp_obj_t s = mp_obj_new_str_of_type(str_type, (const byte*)subj.begin, caps[0] - subj.begin); mp_obj_list_append(retval, s); if (self->re.sub > 0) { - mp_not_implemented("Splitting with sub-captures"); + mp_raise_NotImplementedError("Splitting with sub-captures"); } subj.begin = caps[1]; if (maxsplit > 0 && --maxsplit == 0) { @@ -200,7 +200,7 @@ STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) { int error = re1_5_compilecode(&o->re, re_str); if (error != 0) { error: - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Error in regex")); + mp_raise_ValueError("Error in regex"); } if (flags & FLAG_DEBUG) { re1_5_dumpcode(&o->re); diff --git a/extmod/moduselect.c b/extmod/moduselect.c index 88dd29a49..a9f25c195 100644 --- a/extmod/moduselect.c +++ b/extmod/moduselect.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -362,10 +362,10 @@ STATIC const mp_rom_map_elem_t mp_module_select_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uselect) }, { MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mp_select_select_obj) }, { MP_ROM_QSTR(MP_QSTR_poll), MP_ROM_PTR(&mp_select_poll_obj) }, - { MP_ROM_QSTR(MP_QSTR_POLLIN), MP_OBJ_NEW_SMALL_INT(MP_STREAM_POLL_RD) }, - { MP_ROM_QSTR(MP_QSTR_POLLOUT), MP_OBJ_NEW_SMALL_INT(MP_STREAM_POLL_WR) }, - { MP_ROM_QSTR(MP_QSTR_POLLERR), MP_OBJ_NEW_SMALL_INT(MP_STREAM_POLL_ERR) }, - { MP_ROM_QSTR(MP_QSTR_POLLHUP), MP_OBJ_NEW_SMALL_INT(MP_STREAM_POLL_HUP) }, + { MP_ROM_QSTR(MP_QSTR_POLLIN), MP_ROM_INT(MP_STREAM_POLL_RD) }, + { MP_ROM_QSTR(MP_QSTR_POLLOUT), MP_ROM_INT(MP_STREAM_POLL_WR) }, + { MP_ROM_QSTR(MP_QSTR_POLLERR), MP_ROM_INT(MP_STREAM_POLL_ERR) }, + { MP_ROM_QSTR(MP_QSTR_POLLHUP), MP_ROM_INT(MP_STREAM_POLL_HUP) }, }; STATIC MP_DEFINE_CONST_DICT(mp_module_select_globals, mp_module_select_globals_table); diff --git a/extmod/modussl_axtls.c b/extmod/modussl_axtls.c index a27f0f1fe..b5d2412d2 100644 --- a/extmod/modussl_axtls.c +++ b/extmod/modussl_axtls.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -26,7 +26,6 @@ #include #include -#include #include "py/nlr.h" #include "py/runtime.h" @@ -102,6 +101,11 @@ STATIC void socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kin STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in); + if (o->ssl_sock == NULL) { + *errcode = EBADF; + return MP_STREAM_ERROR; + } + while (o->bytes_left == 0) { mp_int_t r = ssl_read(o->ssl_sock, &o->buf); if (r == SSL_OK) { @@ -131,6 +135,12 @@ STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errc STATIC mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in); + + if (o->ssl_sock == NULL) { + *errcode = EBADF; + return MP_STREAM_ERROR; + } + mp_int_t r = ssl_write(o->ssl_sock, buf, size); if (r < 0) { *errcode = r; @@ -143,7 +153,7 @@ STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { // Currently supports only blocking mode (void)self_in; if (!mp_obj_is_true(flag_in)) { - mp_not_implemented(""); + mp_raise_NotImplementedError(""); } return mp_const_none; } @@ -151,9 +161,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking); STATIC mp_obj_t socket_close(mp_obj_t self_in) { mp_obj_ssl_socket_t *self = MP_OBJ_TO_PTR(self_in); - ssl_free(self->ssl_sock); - ssl_ctx_free(self->ssl_ctx); - return mp_stream_close(self->sock); + if (self->ssl_sock != NULL) { + ssl_free(self->ssl_sock); + ssl_ctx_free(self->ssl_ctx); + self->ssl_sock = NULL; + return mp_stream_close(self->sock); + } + + return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_close_obj, socket_close); diff --git a/extmod/modussl_mbedtls.c b/extmod/modussl_mbedtls.c index a3f16a04c..09c9fe079 100644 --- a/extmod/modussl_mbedtls.c +++ b/extmod/modussl_mbedtls.c @@ -31,13 +31,14 @@ #include #include #include -#include #include + #include "py/nlr.h" #include "py/runtime.h" #include "py/stream.h" +#include "py/obj.h" // mbedtls_time_t #include "mbedtls/platform.h" @@ -122,21 +123,6 @@ int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) { return out_sz; } -STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { - mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(self_in); - mp_obj_t sock = o->sock; - mp_obj_t dest[3]; - - mp_load_method_maybe(sock, MP_QSTR_setblocking, dest); - if (dest[0] == MP_OBJ_NULL || dest[1] == MP_OBJ_NULL) { - mp_raise_msg(&mp_type_RuntimeError, "wrapped socket must implement setblocking()"); - } - - dest[2] = flag_in; - return mp_call_method_n_kw(1, 0, dest); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking); - STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) { mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t); o->base.type = &ussl_socket_type; @@ -185,9 +171,9 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) { } ret = mbedtls_ssl_config_defaults(&o->conf, - MBEDTLS_SSL_IS_CLIENT, - MBEDTLS_SSL_TRANSPORT_STREAM, - MBEDTLS_SSL_PRESET_DEFAULT); + args->server_side.u_bool ? MBEDTLS_SSL_IS_SERVER : MBEDTLS_SSL_IS_CLIENT, + MBEDTLS_SSL_TRANSPORT_STREAM, + MBEDTLS_SSL_PRESET_DEFAULT); if (ret != 0) { char errstr[256]; mbedtls_strerror(ret, errstr, sizeof(errstr)); @@ -228,7 +214,6 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) { o->sock = sock; - socket_setblocking(o, mp_const_true); mbedtls_ssl_set_bio(&o->ssl, o, _mbedtls_ssl_send, _mbedtls_ssl_recv, NULL); if (args->key.u_obj != MP_OBJ_NULL) { @@ -284,6 +269,16 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) { return o; } +STATIC mp_obj_t mod_ssl_getpeercert(mp_obj_t o_in, mp_obj_t binary_form) { + mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in); + if (!mp_obj_is_true(binary_form)) { + mp_raise_NotImplementedError(NULL); + } + const mbedtls_x509_crt* peer_cert = mbedtls_ssl_get_peer_cert(&o->ssl); + return mp_obj_new_bytes(peer_cert->raw.p, peer_cert->raw.len); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_ssl_getpeercert_obj, mod_ssl_getpeercert); + STATIC void socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_ssl_socket_t *self = MP_OBJ_TO_PTR(self_in); @@ -307,6 +302,9 @@ STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errc if (ret >= 0) { return ret; } + if (ret == MBEDTLS_ERR_SSL_WANT_READ) { + ret = MP_EWOULDBLOCK; + } *errcode = ret; return MP_STREAM_ERROR; } @@ -320,26 +318,34 @@ STATIC mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, in } if (ret == MBEDTLS_ERR_SSL_WANT_WRITE) { - *errcode = EWOULDBLOCK; - return 0; + ret = MP_EWOULDBLOCK; } - *errcode = ret; return MP_STREAM_ERROR; } +STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) { + mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(self_in); + mp_obj_t sock = o->sock; + mp_obj_t dest[3]; + mp_load_method(sock, MP_QSTR_setblocking, dest); + dest[2] = flag_in; + return mp_call_method_n_kw(1, 0, dest); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking); + STATIC mp_obj_t socket_close(mp_obj_t self_in) { mp_obj_ssl_socket_t *self = MP_OBJ_TO_PTR(self_in); + mbedtls_pk_free(&self->pkey); + mbedtls_x509_crt_free(&self->cert); mbedtls_x509_crt_free(&self->cacert); mbedtls_ssl_free(&self->ssl); mbedtls_ssl_config_free(&self->conf); mbedtls_ctr_drbg_free(&self->ctr_drbg); mbedtls_entropy_free(&self->entropy); - mp_obj_t dest[2]; - mp_load_method(self->sock, MP_QSTR_close, dest); - return mp_call_method_n_kw(0, 0, dest); + return mp_stream_close(self->sock); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_close_obj, socket_close); @@ -350,6 +356,7 @@ STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) }, { MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socket_setblocking_obj) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&socket_close_obj) }, + { MP_ROM_QSTR(MP_QSTR_getpeercert), MP_ROM_PTR(&mod_ssl_getpeercert_obj) }, }; STATIC MP_DEFINE_CONST_DICT(ussl_socket_locals_dict, ussl_socket_locals_dict_table); diff --git a/extmod/moduzlib.c b/extmod/moduzlib.c index 6e045c403..b446dba73 100644 --- a/extmod/moduzlib.c +++ b/extmod/moduzlib.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -92,7 +92,7 @@ STATIC mp_obj_t decompio_make_new(const mp_obj_type_t *type, size_t n_args, size dict_opt = uzlib_zlib_parse_header(&o->decomp); if (dict_opt < 0) { header_error: - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "compression header")); + mp_raise_ValueError("compression header"); } dict_sz = 1 << dict_opt; } else { diff --git a/extmod/modwebrepl.c b/extmod/modwebrepl.c index ce3c7dcbd..d618f5370 100644 --- a/extmod/modwebrepl.c +++ b/extmod/modwebrepl.c @@ -27,7 +27,6 @@ #include #include #include -#include #include "py/nlr.h" #include "py/obj.h" @@ -318,11 +317,11 @@ STATIC mp_obj_t webrepl_set_password(mp_obj_t passwd_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(webrepl_set_password_obj, webrepl_set_password); -STATIC const mp_map_elem_t webrepl_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_stream_read_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_readinto), (mp_obj_t)&mp_stream_readinto_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&webrepl_close_obj }, +STATIC const mp_rom_map_elem_t webrepl_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, + { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, + { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) }, + { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&webrepl_close_obj) }, }; STATIC MP_DEFINE_CONST_DICT(webrepl_locals_dict, webrepl_locals_dict_table); @@ -336,13 +335,13 @@ STATIC const mp_obj_type_t webrepl_type = { .name = MP_QSTR__webrepl, .make_new = webrepl_make_new, .protocol = &webrepl_stream_p, - .locals_dict = (mp_obj_t)&webrepl_locals_dict, + .locals_dict = (mp_obj_dict_t*)&webrepl_locals_dict, }; -STATIC const mp_map_elem_t webrepl_module_globals_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR__webrepl) }, - { MP_OBJ_NEW_QSTR(MP_QSTR__webrepl), (mp_obj_t)&webrepl_type }, - { MP_OBJ_NEW_QSTR(MP_QSTR_password), (mp_obj_t)&webrepl_set_password_obj }, +STATIC const mp_rom_map_elem_t webrepl_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__webrepl) }, + { MP_ROM_QSTR(MP_QSTR__webrepl), MP_ROM_PTR(&webrepl_type) }, + { MP_ROM_QSTR(MP_QSTR_password), MP_ROM_PTR(&webrepl_set_password_obj) }, }; STATIC MP_DEFINE_CONST_DICT(webrepl_module_globals, webrepl_module_globals_table); diff --git a/extmod/modwebsocket.c b/extmod/modwebsocket.c index 9e17d6a6d..6c6e32c1a 100644 --- a/extmod/modwebsocket.c +++ b/extmod/modwebsocket.c @@ -27,7 +27,6 @@ #include #include #include -#include #include "py/nlr.h" #include "py/obj.h" @@ -88,7 +87,7 @@ STATIC mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int self->buf_pos += out_sz; self->to_recv -= out_sz; if (self->to_recv != 0) { - *errcode = EAGAIN; + *errcode = MP_EAGAIN; return MP_STREAM_ERROR; } } @@ -267,7 +266,7 @@ STATIC mp_uint_t websocket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t return cur; } default: - *errcode = EINVAL; + *errcode = MP_EINVAL; return MP_STREAM_ERROR; } } diff --git a/extmod/modwebsocket.h b/extmod/modwebsocket.h index 7da147561..2720147df 100644 --- a/extmod/modwebsocket.h +++ b/extmod/modwebsocket.h @@ -1,5 +1,10 @@ +#ifndef MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H +#define MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H + #define FRAME_OPCODE_MASK 0x0f enum { FRAME_CONT, FRAME_TXT, FRAME_BIN, FRAME_CLOSE = 0x8, FRAME_PING, FRAME_PONG }; + +#endif // MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H diff --git a/extmod/uos_dupterm.c b/extmod/uos_dupterm.c index d888099df..29a62ab89 100644 --- a/extmod/uos_dupterm.c +++ b/extmod/uos_dupterm.c @@ -24,7 +24,6 @@ * THE SOFTWARE. */ -#include #include #include "py/mpconfig.h" diff --git a/extmod/utime_mphal.h b/extmod/utime_mphal.h index 644387b67..88a9ed4d3 100644 --- a/extmod/utime_mphal.h +++ b/extmod/utime_mphal.h @@ -24,6 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_EXTMOD_UTIME_MPHAL_H +#define MICROPY_INCLUDED_EXTMOD_UTIME_MPHAL_H #include "py/obj.h" @@ -35,3 +37,5 @@ MP_DECLARE_CONST_FUN_OBJ_0(mp_utime_ticks_us_obj); MP_DECLARE_CONST_FUN_OBJ_0(mp_utime_ticks_cpu_obj); MP_DECLARE_CONST_FUN_OBJ_2(mp_utime_ticks_diff_obj); MP_DECLARE_CONST_FUN_OBJ_2(mp_utime_ticks_add_obj); + +#endif // MICROPY_INCLUDED_EXTMOD_UTIME_MPHAL_H diff --git a/extmod/vfs.h b/extmod/vfs.h index edaeb5349..f2efdbe79 100644 --- a/extmod/vfs.h +++ b/extmod/vfs.h @@ -23,7 +23,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - #ifndef MICROPY_INCLUDED_EXTMOD_VFS_H #define MICROPY_INCLUDED_EXTMOD_VFS_H diff --git a/extmod/vfs_fat.h b/extmod/vfs_fat.h index 6c7c05a9a..443e4eda8 100644 --- a/extmod/vfs_fat.h +++ b/extmod/vfs_fat.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_EXTMOD_VFS_FAT_H +#define MICROPY_INCLUDED_EXTMOD_VFS_FAT_H #include "py/lexer.h" #include "py/obj.h" @@ -58,3 +60,5 @@ mp_obj_t fatfs_builtin_open_self(mp_obj_t self_in, mp_obj_t path, mp_obj_t mode) MP_DECLARE_CONST_FUN_OBJ_KW(mp_builtin_open_obj); mp_obj_t fat_vfs_ilistdir2(struct _fs_user_mount_t *vfs, const char *path, bool is_str_type); + +#endif // MICROPY_INCLUDED_EXTMOD_VFS_FAT_H diff --git a/extmod/vfs_fat_diskio.c b/extmod/vfs_fat_diskio.c index 24c00ffba..ff23c6b0c 100644 --- a/extmod/vfs_fat_diskio.c +++ b/extmod/vfs_fat_diskio.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * Original template for this file comes from: * Low level disk I/O module skeleton for FatFs, (C)ChaN, 2013 diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index edffa37c7..8fb48f01a 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -28,7 +28,6 @@ #if MICROPY_VFS && MICROPY_VFS_FAT #include -#include #include "py/nlr.h" #include "py/runtime.h" diff --git a/extmod/vfs_native.c b/extmod/vfs_native.c index 320096edf..a8dddd98f 100644 --- a/extmod/vfs_native.c +++ b/extmod/vfs_native.c @@ -20,13 +20,12 @@ #include "extmod/vfs_native.h" #include "lib/timeutils/timeutils.h" +#include "bpp_init.h" + #define mp_obj_native_vfs_t fs_user_mount_t static const char *TAG = "vfs_native.c"; -static wl_handle_t s_wl_handle = WL_INVALID_HANDLE; -static bool native_vfs_mounted = false; - /* esp-idf doesn't seem to have a cwd; create one. */ char cwd[MICROPY_ALLOC_PATH_MAX + 1] = { 0 }; @@ -34,6 +33,21 @@ int chdir(const char *path) { struct stat buf; + + // root mount-point is special-case. + if (strcmp(path, "/") == 0) { + cwd[0] = 0; + ESP_LOGD(TAG, "cwd set to '/'"); + return 0; + } + + // other mount-points are special as well. + if (strcmp(path, "/sdcard") == 0 || strcmp(path, "/bpp") == 0) { + strncpy(cwd, path, sizeof(cwd)); + ESP_LOGD(TAG, "cwd set to '%s'", cwd); + return 0; + } + int res = stat(path, &buf); if (res < 0) { return -1; @@ -390,30 +404,6 @@ STATIC mp_obj_t native_vfs_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t m flag_ro ? "true" : "false", flag_mkfs ? "true" : "false"); - /* we do not support mount, but will do an initial mount on first call */ - - // already mounted? - if (native_vfs_mounted) - { - return mp_const_none; - } - - // mount the block device - const esp_vfs_fat_mount_config_t mount_config = { - .max_files = 3, // every open file costs 4236 bytes of heap. - .format_if_mount_failed = true, - }; - - ESP_LOGI(TAG, "mounting locfd on /"); - esp_err_t err = esp_vfs_fat_spiflash_mount("", "locfd", &mount_config, &s_wl_handle); - - if (err != ESP_OK) { - ESP_LOGE(TAG, "Failed to mount FATFS (0x%x)", err); - mp_raise_OSError(MP_EIO); - } - - native_vfs_mounted = true; - return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_3(native_vfs_mount_obj, native_vfs_mount); diff --git a/extmod/vfs_native_file.c b/extmod/vfs_native_file.c index 12b76f846..bc7fdb0e3 100644 --- a/extmod/vfs_native_file.c +++ b/extmod/vfs_native_file.c @@ -137,7 +137,6 @@ STATIC const mp_arg_t file_open_args[] = { STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_arg_val_t *args) { pyb_file_obj_t *o = m_new_obj_with_finaliser(pyb_file_obj_t); - o->base.type = type; const char *fname = mp_obj_str_get_str(args[0].u_obj); const char *mode_s = mp_obj_str_get_str(args[1].u_obj); @@ -181,10 +180,12 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar } } + o->base.type = type; + assert(vfs != NULL); int fd = open(fname, mode_x | mode_rw, 0644); if (fd == -1) { - ESP_LOGE(TAG, "open('%s', '%s'): error %d", fname, mode_s_orig, errno); + ESP_LOGI(TAG, "open('%s', '%s'): error %d", fname, mode_s_orig, errno); m_del_obj(pyb_file_obj_t, o); mp_raise_OSError(errno); } diff --git a/extmod/virtpin.h b/extmod/virtpin.h index 041010350..706affc19 100644 --- a/extmod/virtpin.h +++ b/extmod/virtpin.h @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_EXTMOD_VIRTPIN_H +#define MICROPY_INCLUDED_EXTMOD_VIRTPIN_H #include "py/obj.h" @@ -41,3 +43,5 @@ void mp_virtual_pin_write(mp_obj_t pin, int value); // If a port exposes a Pin object, it's constructor should be like this mp_obj_t mp_pin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); + +#endif // MICROPY_INCLUDED_EXTMOD_VIRTPIN_H diff --git a/lib/libc/string0.c b/lib/libc/string0.c index 1b37169ed..c2f2abd0f 100644 --- a/lib/libc/string0.c +++ b/lib/libc/string0.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/lib/libm/ef_rem_pio2.c b/lib/libm/ef_rem_pio2.c index f7a695e17..ca55243fb 100644 --- a/lib/libm/ef_rem_pio2.c +++ b/lib/libm/ef_rem_pio2.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * These math functions are taken from newlib-nano-2, the newlib/libm/math * directory, available from https://github.com/32bitmicro/newlib-nano-2. diff --git a/lib/libm/erf_lgamma.c b/lib/libm/erf_lgamma.c index a0da86b8d..877816a0c 100644 --- a/lib/libm/erf_lgamma.c +++ b/lib/libm/erf_lgamma.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * These math functions are taken from newlib-nano-2, the newlib/libm/math * directory, available from https://github.com/32bitmicro/newlib-nano-2. diff --git a/lib/libm/fdlibm.h b/lib/libm/fdlibm.h index 529a3975a..ace3b2da2 100644 --- a/lib/libm/fdlibm.h +++ b/lib/libm/fdlibm.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * This file is adapted from from newlib-nano-2, the newlib/libm/common/fdlib.h, * available from https://github.com/32bitmicro/newlib-nano-2. The main change diff --git a/lib/libm/kf_cos.c b/lib/libm/kf_cos.c index f1f883ced..691f9842f 100644 --- a/lib/libm/kf_cos.c +++ b/lib/libm/kf_cos.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * These math functions are taken from newlib-nano-2, the newlib/libm/math * directory, available from https://github.com/32bitmicro/newlib-nano-2. diff --git a/lib/libm/kf_rem_pio2.c b/lib/libm/kf_rem_pio2.c index e267b65f9..c7e947957 100644 --- a/lib/libm/kf_rem_pio2.c +++ b/lib/libm/kf_rem_pio2.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * These math functions are taken from newlib-nano-2, the newlib/libm/math * directory, available from https://github.com/32bitmicro/newlib-nano-2. diff --git a/lib/libm/kf_sin.c b/lib/libm/kf_sin.c index 81390b4eb..07ea99344 100644 --- a/lib/libm/kf_sin.c +++ b/lib/libm/kf_sin.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * These math functions are taken from newlib-nano-2, the newlib/libm/math * directory, available from https://github.com/32bitmicro/newlib-nano-2. diff --git a/lib/libm/kf_tan.c b/lib/libm/kf_tan.c index 68254c682..6da9bd817 100644 --- a/lib/libm/kf_tan.c +++ b/lib/libm/kf_tan.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * These math functions are taken from newlib-nano-2, the newlib/libm/math * directory, available from https://github.com/32bitmicro/newlib-nano-2. diff --git a/lib/libm/math.c b/lib/libm/math.c index d7e27e775..984636627 100644 --- a/lib/libm/math.c +++ b/lib/libm/math.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/lib/libm/sf_cos.c b/lib/libm/sf_cos.c index 33cde50e2..fabb129cd 100644 --- a/lib/libm/sf_cos.c +++ b/lib/libm/sf_cos.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * These math functions are taken from newlib-nano-2, the newlib/libm/math * directory, available from https://github.com/32bitmicro/newlib-nano-2. diff --git a/lib/libm/sf_erf.c b/lib/libm/sf_erf.c index 00ac4baf1..3f0172c6e 100644 --- a/lib/libm/sf_erf.c +++ b/lib/libm/sf_erf.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * These math functions are taken from newlib-nano-2, the newlib/libm/math * directory, available from https://github.com/32bitmicro/newlib-nano-2. diff --git a/lib/libm/sf_frexp.c b/lib/libm/sf_frexp.c index 397373fde..df50fb773 100644 --- a/lib/libm/sf_frexp.c +++ b/lib/libm/sf_frexp.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * These math functions are taken from newlib-nano-2, the newlib/libm/math * directory, available from https://github.com/32bitmicro/newlib-nano-2. diff --git a/lib/libm/sf_ldexp.c b/lib/libm/sf_ldexp.c index a0941df9f..37968d475 100644 --- a/lib/libm/sf_ldexp.c +++ b/lib/libm/sf_ldexp.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * These math functions are taken from newlib-nano-2, the newlib/libm/math * directory, available from https://github.com/32bitmicro/newlib-nano-2. diff --git a/lib/libm/sf_modf.c b/lib/libm/sf_modf.c index 4fcae057a..410db2a37 100644 --- a/lib/libm/sf_modf.c +++ b/lib/libm/sf_modf.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * These math functions are taken from newlib-nano-2, the newlib/libm/common * directory, available from https://github.com/32bitmicro/newlib-nano-2. diff --git a/lib/libm/sf_sin.c b/lib/libm/sf_sin.c index 585ab8d8c..d27050778 100644 --- a/lib/libm/sf_sin.c +++ b/lib/libm/sf_sin.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * These math functions are taken from newlib-nano-2, the newlib/libm/math * directory, available from https://github.com/32bitmicro/newlib-nano-2. diff --git a/lib/libm/sf_tan.c b/lib/libm/sf_tan.c index a9296d8bf..148b16d61 100644 --- a/lib/libm/sf_tan.c +++ b/lib/libm/sf_tan.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * These math functions are taken from newlib-nano-2, the newlib/libm/math * directory, available from https://github.com/32bitmicro/newlib-nano-2. diff --git a/lib/libm/wf_lgamma.c b/lib/libm/wf_lgamma.c index 7d2f42c54..d86ede790 100644 --- a/lib/libm/wf_lgamma.c +++ b/lib/libm/wf_lgamma.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * These math functions are taken from newlib-nano-2, the newlib/libm/math * directory, available from https://github.com/32bitmicro/newlib-nano-2. diff --git a/lib/libm/wf_tgamma.c b/lib/libm/wf_tgamma.c index afd16bf67..64b2488d1 100644 --- a/lib/libm/wf_tgamma.c +++ b/lib/libm/wf_tgamma.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * These math functions are taken from newlib-nano-2, the newlib/libm/math * directory, available from https://github.com/32bitmicro/newlib-nano-2. diff --git a/lib/mp-readline/readline.c b/lib/mp-readline/readline.c index 5b35c8660..9d254d8cf 100644 --- a/lib/mp-readline/readline.c +++ b/lib/mp-readline/readline.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/lib/mp-readline/readline.h b/lib/mp-readline/readline.h index f73934d23..00aa9622a 100644 --- a/lib/mp-readline/readline.h +++ b/lib/mp-readline/readline.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_LIB_MP_READLINE_READLINE_H +#define MICROPY_INCLUDED_LIB_MP_READLINE_READLINE_H #define CHAR_CTRL_A (1) #define CHAR_CTRL_B (2) @@ -42,3 +44,5 @@ void readline_push_history(const char *line); void readline_init(vstr_t *line, const char *prompt); void readline_note_newline(const char *prompt); int readline_process_char(int c); + +#endif // MICROPY_INCLUDED_LIB_MP_READLINE_READLINE_H diff --git a/lib/netutils/netutils.c b/lib/netutils/netutils.c index a2ea31cf3..15e70397c 100644 --- a/lib/netutils/netutils.c +++ b/lib/netutils/netutils.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -31,6 +31,7 @@ #include "py/obj.h" #include "py/nlr.h" +#include "py/runtime.h" #include "lib/netutils/netutils.h" // Takes an array with a raw IPv4 address and returns something like '192.168.0.1'. @@ -80,7 +81,7 @@ void netutils_parse_ipv4_addr(mp_obj_t addr_in, uint8_t *out_ip, netutils_endian } else if (i > 0 && s < s_top && *s == '.') { s++; } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "invalid arguments")); + mp_raise_ValueError("invalid arguments"); } } } diff --git a/lib/netutils/netutils.h b/lib/netutils/netutils.h index 45e021640..4befc90db 100644 --- a/lib/netutils/netutils.h +++ b/lib/netutils/netutils.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,8 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_LIB_NETUTILS_H__ -#define __MICROPY_INCLUDED_LIB_NETUTILS_H__ +#ifndef MICROPY_INCLUDED_LIB_NETUTILS_NETUTILS_H +#define MICROPY_INCLUDED_LIB_NETUTILS_NETUTILS_H #define NETUTILS_IPV4ADDR_BUFSIZE 4 @@ -47,4 +47,4 @@ void netutils_parse_ipv4_addr(mp_obj_t addr_in, uint8_t *out_ip, netutils_endian // puts IP in out_ip (which must take at least IPADDR_BUF_SIZE bytes). mp_uint_t netutils_parse_inet_addr(mp_obj_t addr_in, uint8_t *out_ip, netutils_endian_t endian); -#endif // __MICROPY_INCLUDED_LIB_NETUTILS_H__ +#endif // MICROPY_INCLUDED_LIB_NETUTILS_NETUTILS_H diff --git a/lib/timeutils/timeutils.c b/lib/timeutils/timeutils.c index f1bcd8f3f..d836884b3 100644 --- a/lib/timeutils/timeutils.c +++ b/lib/timeutils/timeutils.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -67,7 +67,7 @@ mp_uint_t timeutils_year_day(mp_uint_t year, mp_uint_t month, mp_uint_t date) { void timeutils_seconds_since_2000_to_struct_time(mp_uint_t t, timeutils_struct_time_t *tm) { // The following algorithm was adapted from musl's __secs_to_tm and adapted - // for differences in Micro Python's timebase. + // for differences in MicroPython's timebase. mp_int_t seconds = t - LEAPOCH; diff --git a/lib/timeutils/timeutils.h b/lib/timeutils/timeutils.h index 773be60c2..1477229b4 100644 --- a/lib/timeutils/timeutils.h +++ b/lib/timeutils/timeutils.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,9 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef __MICROPY_INCLUDED_LIB_TIMEUTILS_H__ -#define __MICROPY_INCLUDED_LIB_TIMEUTILS_H__ +#ifndef MICROPY_INCLUDED_LIB_TIMEUTILS_TIMEUTILS_H +#define MICROPY_INCLUDED_LIB_TIMEUTILS_TIMEUTILS_H typedef int64_t mp_time_t; @@ -63,4 +62,4 @@ mp_time_t timeutils_seconds_since_epoch(mp_uint_t year, mp_uint_t month, mp_time_t timeutils_mktime_epoch(mp_uint_t year, mp_int_t month, mp_int_t mday, mp_int_t hours, mp_int_t minutes, mp_int_t seconds); -#endif // __MICROPY_INCLUDED_LIB_TIMEUTILS_H__ +#endif // MICROPY_INCLUDED_LIB_TIMEUTILS_TIMEUTILS_H diff --git a/lib/utils/interrupt_char.h b/lib/utils/interrupt_char.h index ae0bf57e8..ca50d4d56 100644 --- a/lib/utils/interrupt_char.h +++ b/lib/utils/interrupt_char.h @@ -23,7 +23,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_LIB_UTILS_INTERRUPT_CHAR_H +#define MICROPY_INCLUDED_LIB_UTILS_INTERRUPT_CHAR_H extern int mp_interrupt_char; void mp_hal_set_interrupt_char(int c); void mp_keyboard_interrupt(void); + +#endif // MICROPY_INCLUDED_LIB_UTILS_INTERRUPT_CHAR_H diff --git a/lib/utils/printf.c b/lib/utils/printf.c index 303edfcca..51dfa5b96 100644 --- a/lib/utils/printf.c +++ b/lib/utils/printf.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/lib/utils/pyexec.c b/lib/utils/pyexec.c index 7d0d1cc38..d3500b42b 100644 --- a/lib/utils/pyexec.c +++ b/lib/utils/pyexec.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/lib/utils/pyexec.h b/lib/utils/pyexec.h index 0c7567e27..bc98ba94a 100644 --- a/lib/utils/pyexec.h +++ b/lib/utils/pyexec.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_LIB_UTILS_PYEXEC_H__ -#define __MICROPY_INCLUDED_LIB_UTILS_PYEXEC_H__ +#ifndef MICROPY_INCLUDED_LIB_UTILS_PYEXEC_H +#define MICROPY_INCLUDED_LIB_UTILS_PYEXEC_H typedef enum { PYEXEC_MODE_RAW_REPL, @@ -51,4 +51,4 @@ extern uint8_t pyexec_repl_active; MP_DECLARE_CONST_FUN_OBJ_1(pyb_set_repl_info_obj); -#endif // __MICROPY_INCLUDED_LIB_UTILS_PYEXEC_H__ +#endif // MICROPY_INCLUDED_LIB_UTILS_PYEXEC_H diff --git a/logo/FONT-LICENSE.txt b/logo/FONT-LICENSE.txt index 18ac0379f..69c49d84c 100644 --- a/logo/FONT-LICENSE.txt +++ b/logo/FONT-LICENSE.txt @@ -1,4 +1,4 @@ -The font used for the Micro Python logo is "Exo", +The font used for the MicroPython logo is "Exo", http://www.google.com/fonts/specimen/Exo. Copyright (c) 2013, Natanael Gama (https://plus.google.com/u/0/+NatanaelGama), diff --git a/minimal/Makefile b/minimal/Makefile index d61515797..c95d639af 100644 --- a/minimal/Makefile +++ b/minimal/Makefile @@ -6,39 +6,36 @@ CROSS = 0 QSTR_DEFS = qstrdefsport.h # include py core make definitions -include ../py/py.mk +include $(TOP)/py/py.mk ifeq ($(CROSS), 1) CROSS_COMPILE = arm-none-eabi- endif INC += -I. -INC += -I.. -INC += -I../stmhal +INC += -I$(TOP) INC += -I$(BUILD) ifeq ($(CROSS), 1) -DFU = ../tools/dfu.py -PYDFU = ../tools/pydfu.py +DFU = $(TOP)/tools/dfu.py +PYDFU = $(TOP)/tools/pydfu.py CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion CFLAGS = $(INC) -Wall -Werror -std=c99 -nostdlib $(CFLAGS_CORTEX_M4) $(COPT) +LDFLAGS = -nostdlib -T stm32f405.ld -Map=$@.map --cref --gc-sections else +LD = gcc CFLAGS = -m32 $(INC) -Wall -Werror -std=c99 $(COPT) +LDFLAGS = -m32 -Wl,-Map=$@.map,--cref -Wl,--gc-sections endif -#Debugging/Optimization +# Tune for Debugging or Optimization ifeq ($(DEBUG), 1) CFLAGS += -O0 -ggdb else CFLAGS += -Os -DNDEBUG +CFLAGS += -fdata-sections -ffunction-sections endif -ifeq ($(CROSS), 1) -LDFLAGS = -nostdlib -T stm32f405.ld -Map=$@.map --cref -else -LD = gcc -LDFLAGS = -m32 -Wl,-Map=$@.map,--cref -endif LIBS = SRC_C = \ @@ -60,7 +57,7 @@ endif $(BUILD)/_frozen_mpy.c: frozentest.mpy $(BUILD)/genhdr/qstrdefs.generated.h $(ECHO) "MISC freezing bytecode" - $(Q)../tools/mpy-tool.py -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h -mlongint-impl=none $< > $@ + $(Q)$(TOP)/tools/mpy-tool.py -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h -mlongint-impl=none $< > $@ $(BUILD)/firmware.elf: $(OBJ) $(ECHO) "LINK $@" @@ -90,4 +87,4 @@ run: test: $(BUILD)/firmware.elf $(Q)/bin/echo -e "print('hello world!', list(x+1 for x in range(10)), end='eol\\\\n')\\r\\n\\x04" | $(BUILD)/firmware.elf | tail -n2 | grep "^hello world! \\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\\]eol" -include ../py/mkrules.mk +include $(TOP)/py/mkrules.mk diff --git a/minimal/mpconfigport.h b/minimal/mpconfigport.h index 47fc98429..ce4f8f240 100644 --- a/minimal/mpconfigport.h +++ b/minimal/mpconfigport.h @@ -1,6 +1,6 @@ #include -// options to control how Micro Python is built +// options to control how MicroPython is built // You can disable the built-in MicroPython compiler by setting the following // config option to 0. If you do this then you won't get a REPL prompt, but you diff --git a/minimal/stm32f405.ld b/minimal/stm32f405.ld index b4aeda744..a202294a5 100644 --- a/minimal/stm32f405.ld +++ b/minimal/stm32f405.ld @@ -9,7 +9,7 @@ MEMORY CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 0x010000 /* 64 KiB */ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x020000 /* 128 KiB */ } - + /* top end of the stack */ _estack = ORIGIN(RAM) + LENGTH(RAM); @@ -45,7 +45,7 @@ SECTIONS . = ALIGN(4); _edata = .; /* define a global symbol at data end; used by startup code in order to initialise the .data section in RAM */ } >RAM - + /* Uninitialized data section */ .bss : { diff --git a/mpy-cross/Makefile b/mpy-cross/Makefile index f5b643c6c..5399b5ae7 100644 --- a/mpy-cross/Makefile +++ b/mpy-cross/Makefile @@ -23,10 +23,10 @@ QSTR_DEFS = qstrdefsport.h UNAME_S := $(shell uname -s) # include py core make definitions -include ../py/py.mk +include $(TOP)/py/py.mk INC += -I. -INC += -I.. +INC += -I$(TOP) INC += -I$(BUILD) # compiler settings @@ -44,8 +44,8 @@ COPT = -Os #-DNDEBUG endif # On OSX, 'gcc' is a symlink to clang unless a real gcc is installed. -# The unix port of micropython on OSX must be compiled with clang, -# while cross-compile ports require gcc, so we test here for OSX and +# The unix port of MicroPython on OSX must be compiled with clang, +# while cross-compile ports require gcc, so we test here for OSX and # if necessary override the value of 'CC' set in py/mkenv.mk ifeq ($(UNAME_S),Darwin) CC = clang @@ -71,4 +71,4 @@ endif OBJ = $(PY_O) OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) -include ../py/mkrules.mk +include $(TOP)/py/mkrules.mk diff --git a/mpy-cross/main.c b/mpy-cross/main.c index 4c88c7222..ca8d9633f 100644 --- a/mpy-cross/main.c +++ b/mpy-cross/main.c @@ -28,7 +28,6 @@ #include #include #include -#include #include "py/mpstate.h" #include "py/compile.h" diff --git a/pic16bit/Makefile b/pic16bit/Makefile index 1da444952..ebf4fc2e8 100644 --- a/pic16bit/Makefile +++ b/pic16bit/Makefile @@ -4,7 +4,7 @@ include ../py/mkenv.mk QSTR_DEFS = qstrdefsport.h # include py core make definitions -include ../py/py.mk +include $(TOP)/py/py.mk XC16 = /opt/microchip/xc16/v1.24 CROSS_COMPILE = $(XC16)/bin/xc16- @@ -13,8 +13,7 @@ PARTFAMILY = dsPIC33F PART = 33FJ256GP506 INC += -I. -INC += -I.. -INC += -I../stmhal +INC += -I$(TOP) INC += -I$(BUILD) INC += -I$(XC16)/include INC += -I$(XC16)/support/$(PARTFAMILY)/h @@ -68,4 +67,4 @@ $(BUILD)/firmware.elf: $(OBJ) $(PY_BUILD)/gc.o: CFLAGS += -O1 $(PY_BUILD)/vm.o: CFLAGS += -O1 -include ../py/mkrules.mk +include $(TOP)/py/mkrules.mk diff --git a/pic16bit/board.c b/pic16bit/board.c index 77f059fc7..0321b0ee2 100644 --- a/pic16bit/board.c +++ b/pic16bit/board.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/pic16bit/board.h b/pic16bit/board.h index 0eb022436..f45f87544 100644 --- a/pic16bit/board.h +++ b/pic16bit/board.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PIC16BIT_BOARD_H__ -#define __MICROPY_INCLUDED_PIC16BIT_BOARD_H__ +#ifndef MICROPY_INCLUDED_PIC16BIT_BOARD_H +#define MICROPY_INCLUDED_PIC16BIT_BOARD_H void cpu_init(void); @@ -40,4 +40,4 @@ int uart_rx_any(void); int uart_rx_char(void); void uart_tx_char(int chr); -#endif // __MICROPY_INCLUDED_PIC16BIT_BOARD_H__ +#endif // MICROPY_INCLUDED_PIC16BIT_BOARD_H diff --git a/pic16bit/main.c b/pic16bit/main.c index 343fe86d0..4a61c5ff5 100644 --- a/pic16bit/main.c +++ b/pic16bit/main.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/pic16bit/modpyb.c b/pic16bit/modpyb.c index 326d37f8a..4a608541e 100644 --- a/pic16bit/modpyb.c +++ b/pic16bit/modpyb.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/pic16bit/modpyb.h b/pic16bit/modpyb.h index 6c68cbdfd..ac19fd2f3 100644 --- a/pic16bit/modpyb.h +++ b/pic16bit/modpyb.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,11 +23,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PIC16BIT_MODPYB_H__ -#define __MICROPY_INCLUDED_PIC16BIT_MODPYB_H__ +#ifndef MICROPY_INCLUDED_PIC16BIT_MODPYB_H +#define MICROPY_INCLUDED_PIC16BIT_MODPYB_H extern const mp_obj_type_t pyb_led_type; extern const mp_obj_type_t pyb_switch_type; extern const mp_obj_module_t pyb_module; -#endif // __MICROPY_INCLUDED_PIC16BIT_MODPYB_H__ +#endif // MICROPY_INCLUDED_PIC16BIT_MODPYB_H diff --git a/pic16bit/modpybled.c b/pic16bit/modpybled.c index 797246d13..eb04689aa 100644 --- a/pic16bit/modpybled.c +++ b/pic16bit/modpybled.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/pic16bit/modpybswitch.c b/pic16bit/modpybswitch.c index aa102e821..4af0c9dfc 100644 --- a/pic16bit/modpybswitch.c +++ b/pic16bit/modpybswitch.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/pic16bit/mpconfigport.h b/pic16bit/mpconfigport.h index e4113956b..3cd099c67 100644 --- a/pic16bit/mpconfigport.h +++ b/pic16bit/mpconfigport.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/pic16bit/pic16bit_mphal.c b/pic16bit/pic16bit_mphal.c index 557b1e0da..35955f2d3 100644 --- a/pic16bit/pic16bit_mphal.c +++ b/pic16bit/pic16bit_mphal.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/pic16bit/pic16bit_mphal.h b/pic16bit/pic16bit_mphal.h index a858f7e0f..f5da6cdc8 100644 --- a/pic16bit/pic16bit_mphal.h +++ b/pic16bit/pic16bit_mphal.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,13 +23,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PIC16BIT_PIC16BIT_MPHAL_H__ -#define __MICROPY_INCLUDED_PIC16BIT_PIC16BIT_MPHAL_H__ #include "py/mpstate.h" void mp_hal_init(void); void mp_hal_set_interrupt_char(int c); - -#endif // __MICROPY_INCLUDED_PIC16BIT_PIC16BIT_MPHAL_H__ diff --git a/pic16bit/unistd.h b/pic16bit/unistd.h index cdd9fe061..5b60c8a62 100644 --- a/pic16bit/unistd.h +++ b/pic16bit/unistd.h @@ -1,5 +1,10 @@ +#ifndef MICROPY_INCLUDED_PIC16BIT_UNISTD_H +#define MICROPY_INCLUDED_PIC16BIT_UNISTD_H + // XC16 compiler doesn't seem to have unistd.h file #define SEEK_CUR 1 typedef int ssize_t; + +#endif // MICROPY_INCLUDED_PIC16BIT_UNISTD_H diff --git a/py/argcheck.c b/py/argcheck.c index 9f225345d..0c5c5ca95 100644 --- a/py/argcheck.c +++ b/py/argcheck.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -142,6 +142,6 @@ NORETURN void mp_arg_error_terse_mismatch(void) { #if MICROPY_CPYTHON_COMPAT NORETURN void mp_arg_error_unimpl_kw(void) { - mp_not_implemented("keyword argument(s) not yet implemented - use normal args instead"); + mp_raise_NotImplementedError("keyword argument(s) not yet implemented - use normal args instead"); } #endif diff --git a/py/asmarm.c b/py/asmarm.c index da07680e3..552fdfb34 100644 --- a/py/asmarm.c +++ b/py/asmarm.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -135,7 +135,7 @@ STATIC uint asm_arm_op_orr_reg(uint rd, uint rn, uint rm) { void asm_arm_bkpt(asm_arm_t *as) { // bkpt #0 - emit_al(as, 0x1200070); + emit_al(as, 0x1200070); } // locals: diff --git a/py/asmarm.h b/py/asmarm.h index e273b98d7..a302b1590 100644 --- a/py/asmarm.h +++ b/py/asmarm.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,8 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_ASMARM_H__ -#define __MICROPY_INCLUDED_PY_ASMARM_H__ +#ifndef MICROPY_INCLUDED_PY_ASMARM_H +#define MICROPY_INCLUDED_PY_ASMARM_H #include "py/misc.h" #include "py/asmbase.h" @@ -202,4 +202,4 @@ void asm_arm_bl_ind(asm_arm_t *as, void *fun_ptr, uint fun_id, uint reg_temp); #endif // GENERIC_ASM_API -#endif // __MICROPY_INCLUDED_PY_ASMARM_H__ +#endif // MICROPY_INCLUDED_PY_ASMARM_H diff --git a/py/asmthumb.c b/py/asmthumb.c index 7e92e4de4..4360a6af9 100644 --- a/py/asmthumb.c +++ b/py/asmthumb.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/asmthumb.h b/py/asmthumb.h index 52e663b3b..7070e03ac 100644 --- a/py/asmthumb.h +++ b/py/asmthumb.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_ASMTHUMB_H__ -#define __MICROPY_INCLUDED_PY_ASMTHUMB_H__ +#ifndef MICROPY_INCLUDED_PY_ASMTHUMB_H +#define MICROPY_INCLUDED_PY_ASMTHUMB_H #include "py/misc.h" #include "py/asmbase.h" @@ -318,4 +318,4 @@ void asm_thumb_bl_ind(asm_thumb_t *as, void *fun_ptr, uint fun_id, uint reg_temp #endif // GENERIC_ASM_API -#endif // __MICROPY_INCLUDED_PY_ASMTHUMB_H__ +#endif // MICROPY_INCLUDED_PY_ASMTHUMB_H diff --git a/py/asmx64.c b/py/asmx64.c index cf1a86b3f..aa2a8ec7c 100644 --- a/py/asmx64.c +++ b/py/asmx64.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -344,8 +344,9 @@ STATIC void asm_x64_mov_i32_to_r64(asm_x64_t *as, int src_i32, int dest_r64) { void asm_x64_mov_i64_to_r64(asm_x64_t *as, int64_t src_i64, int dest_r64) { // cpu defaults to i32 to r64 // to mov i64 to r64 need to use REX prefix - assert(dest_r64 < 8); - asm_x64_write_byte_2(as, REX_PREFIX | REX_W, OPCODE_MOV_I64_TO_R64 | dest_r64); + asm_x64_write_byte_2(as, + REX_PREFIX | REX_W | (dest_r64 < 8 ? 0 : REX_B), + OPCODE_MOV_I64_TO_R64 | (dest_r64 & 7)); asm_x64_write_word64(as, src_i64); } diff --git a/py/asmx64.h b/py/asmx64.h index 4499c53c3..425bdf2d3 100644 --- a/py/asmx64.h +++ b/py/asmx64.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_ASMX64_H__ -#define __MICROPY_INCLUDED_PY_ASMX64_H__ +#ifndef MICROPY_INCLUDED_PY_ASMX64_H +#define MICROPY_INCLUDED_PY_ASMX64_H #include "py/mpconfig.h" #include "py/misc.h" @@ -197,4 +197,4 @@ void asm_x64_call_ind(asm_x64_t* as, void* ptr, int temp_r32); #endif // GENERIC_ASM_API -#endif // __MICROPY_INCLUDED_PY_ASMX64_H__ +#endif // MICROPY_INCLUDED_PY_ASMX64_H diff --git a/py/asmx86.c b/py/asmx86.c index dd3ad0224..6a78fbd5e 100644 --- a/py/asmx86.c +++ b/py/asmx86.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/asmx86.h b/py/asmx86.h index 0b44af663..0a00e2e7c 100644 --- a/py/asmx86.h +++ b/py/asmx86.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_ASMX86_H__ -#define __MICROPY_INCLUDED_PY_ASMX86_H__ +#ifndef MICROPY_INCLUDED_PY_ASMX86_H +#define MICROPY_INCLUDED_PY_ASMX86_H #include "py/mpconfig.h" #include "py/misc.h" @@ -195,4 +195,4 @@ void asm_x86_call_ind(asm_x86_t* as, void* ptr, mp_uint_t n_args, int temp_r32); #endif // GENERIC_ASM_API -#endif // __MICROPY_INCLUDED_PY_ASMX86_H__ +#endif // MICROPY_INCLUDED_PY_ASMX86_H diff --git a/py/bc.c b/py/bc.c index 2e481bce7..917eba57d 100644 --- a/py/bc.c +++ b/py/bc.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -35,7 +35,7 @@ #include "py/bc0.h" #include "py/bc.h" -#if 0 // print debugging info +#if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_PRINT (1) #else // don't print debugging info #define DEBUG_PRINT (0) diff --git a/py/bc.h b/py/bc.h index 88045dc55..69e213e42 100644 --- a/py/bc.h +++ b/py/bc.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_BC_H__ -#define __MICROPY_INCLUDED_PY_BC_H__ +#ifndef MICROPY_INCLUDED_PY_BC_H +#define MICROPY_INCLUDED_PY_BC_H #include "py/runtime.h" #include "py/obj.h" @@ -119,4 +119,4 @@ uint mp_opcode_format(const byte *ip, size_t *opcode_size); #endif -#endif // __MICROPY_INCLUDED_PY_BC_H__ +#endif // MICROPY_INCLUDED_PY_BC_H diff --git a/py/bc0.h b/py/bc0.h index b5650abe4..f671c5b5a 100644 --- a/py/bc0.h +++ b/py/bc0.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,10 +23,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_BC0_H__ -#define __MICROPY_INCLUDED_PY_BC0_H__ +#ifndef MICROPY_INCLUDED_PY_BC0_H +#define MICROPY_INCLUDED_PY_BC0_H -// Micro Python byte-codes. +// MicroPython byte-codes. // The comment at the end of the line (if it exists) tells the arguments to the byte-code. #define MP_BC_LOAD_CONST_FALSE (0x10) @@ -116,4 +116,4 @@ #define MP_BC_UNARY_OP_MULTI (0xd0) // + op(7) #define MP_BC_BINARY_OP_MULTI (0xd7) // + op(36) -#endif // __MICROPY_INCLUDED_PY_BC0_H__ +#endif // MICROPY_INCLUDED_PY_BC0_H diff --git a/py/binary.c b/py/binary.c index 4a999b9aa..870a0942b 100644 --- a/py/binary.c +++ b/py/binary.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -303,7 +303,10 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte ** // zero/sign extend if needed if (BYTES_PER_WORD < 8 && size > sizeof(val)) { int c = (is_signed(val_type) && (mp_int_t)val < 0) ? 0xff : 0x00; - memset(p + sizeof(val), c, size - sizeof(val)); + memset(p, c, size); + if (struct_type == '>') { + p += size - sizeof(val); + } } } } diff --git a/py/binary.h b/py/binary.h index 997d878c8..0dae6a29e 100644 --- a/py/binary.h +++ b/py/binary.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,14 +23,15 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_BINARY_H__ -#define __MICROPY_INCLUDED_PY_BINARY_H__ +#ifndef MICROPY_INCLUDED_PY_BINARY_H +#define MICROPY_INCLUDED_PY_BINARY_H #include "py/obj.h" // Use special typecode to differentiate repr() of bytearray vs array.array('B') -// (underlyingly they're same). -#define BYTEARRAY_TYPECODE 0 +// (underlyingly they're same). Can't use 0 here because that's used to detect +// type-specification errors due to end-of-string. +#define BYTEARRAY_TYPECODE 1 size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign); mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index); @@ -41,4 +42,4 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte ** long long mp_binary_get_int(mp_uint_t size, bool is_signed, bool big_endian, const byte *src); void mp_binary_set_int(mp_uint_t val_sz, bool big_endian, byte *dest, mp_uint_t val); -#endif // __MICROPY_INCLUDED_PY_BINARY_H__ +#endif // MICROPY_INCLUDED_PY_BINARY_H diff --git a/py/builtin.h b/py/builtin.h index ec326d037..a637b6e22 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_BUILTIN_H__ -#define __MICROPY_INCLUDED_PY_BUILTIN_H__ +#ifndef MICROPY_INCLUDED_PY_BUILTIN_H +#define MICROPY_INCLUDED_PY_BUILTIN_H #include "py/obj.h" @@ -120,4 +120,4 @@ extern const mp_obj_module_t mp_module_btree; extern const char *MICROPY_PY_BUILTINS_HELP_TEXT; -#endif // __MICROPY_INCLUDED_PY_BUILTIN_H__ +#endif // MICROPY_INCLUDED_PY_BUILTIN_H diff --git a/py/builtinevex.c b/py/builtinevex.c index d9a3833cc..ba8048f70 100644 --- a/py/builtinevex.c +++ b/py/builtinevex.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -113,12 +113,15 @@ STATIC mp_obj_t eval_exec_helper(size_t n_args, const mp_obj_t *args, mp_parse_i // work out the context mp_obj_dict_t *globals = mp_globals_get(); mp_obj_dict_t *locals = mp_locals_get(); - if (n_args > 1) { - globals = MP_OBJ_TO_PTR(args[1]); - if (n_args > 2) { - locals = MP_OBJ_TO_PTR(args[2]); - } else { - locals = globals; + for (size_t i = 1; i < 3 && i < n_args; ++i) { + if (args[i] != mp_const_none) { + if (!MP_OBJ_IS_TYPE(args[i], &mp_type_dict)) { + mp_raise_TypeError(NULL); + } + locals = MP_OBJ_TO_PTR(args[i]); + if (i == 1) { + globals = locals; + } } } diff --git a/py/builtinimport.c b/py/builtinimport.c index e42360c11..34b2c637a 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -37,7 +37,7 @@ #include "py/builtin.h" #include "py/frozenmod.h" -#if 0 // print debugging info +#if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_PRINT (1) #define DEBUG_printf DEBUG_printf #else // don't print debugging info diff --git a/py/compile.c b/py/compile.c index d2e05d0b2..00052e190 100644 --- a/py/compile.c +++ b/py/compile.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -569,7 +569,7 @@ STATIC void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int for (int j = 0; j < this_scope->id_info_len; j++) { id_info_t *id2 = &this_scope->id_info[j]; if (id2->kind == ID_INFO_KIND_FREE && id->qst == id2->qst) { - // in Micro Python we load closures using LOAD_FAST + // in MicroPython we load closures using LOAD_FAST EMIT_LOAD_FAST(id->qst, id->local_num); nfree += 1; } @@ -654,9 +654,9 @@ STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn) if (comp->have_star) { comp->num_dict_params += 1; - // in Micro Python we put the default dict parameters into a dictionary using the bytecode + // in MicroPython we put the default dict parameters into a dictionary using the bytecode if (comp->num_dict_params == 1) { - // in Micro Python we put the default positional parameters into a tuple using the bytecode + // in MicroPython we put the default positional parameters into a tuple using the bytecode // we need to do this here before we start building the map for the default keywords if (comp->num_default_params > 0) { EMIT_ARG(build_tuple, comp->num_default_params); @@ -700,7 +700,7 @@ STATIC void compile_funcdef_lambdef(compiler_t *comp, scope_t *scope, mp_parse_n return; } - // in Micro Python we put the default positional parameters into a tuple using the bytecode + // in MicroPython we put the default positional parameters into a tuple using the bytecode // the default keywords args may have already made the tuple; if not, do it now if (comp->num_default_params > 0 && comp->num_dict_params == 0) { EMIT_ARG(build_tuple, comp->num_default_params); @@ -3275,7 +3275,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind #endif STATIC void scope_compute_things(scope_t *scope) { - // in Micro Python we put the *x parameter after all other parameters (except **y) + // in MicroPython we put the *x parameter after all other parameters (except **y) if (scope->scope_flags & MP_SCOPE_FLAG_VARARGS) { id_info_t *id_param = NULL; for (int i = scope->id_info_len - 1; i >= 0; i--) { @@ -3313,7 +3313,7 @@ STATIC void scope_compute_things(scope_t *scope) { // compute the index of cell vars for (int i = 0; i < scope->id_info_len; i++) { id_info_t *id = &scope->id_info[i]; - // in Micro Python the cells come right after the fast locals + // in MicroPython the cells come right after the fast locals // parameters are not counted here, since they remain at the start // of the locals, even if they are cell vars if (id->kind == ID_INFO_KIND_CELL && !(id->flags & ID_FLAG_IS_PARAM)) { @@ -3333,14 +3333,14 @@ STATIC void scope_compute_things(scope_t *scope) { id_info_t *id2 = &scope->id_info[j]; if (id2->kind == ID_INFO_KIND_FREE && id->qst == id2->qst) { assert(!(id2->flags & ID_FLAG_IS_PARAM)); // free vars should not be params - // in Micro Python the frees come first, before the params + // in MicroPython the frees come first, before the params id2->local_num = num_free; num_free += 1; } } } } - // in Micro Python shift all other locals after the free locals + // in MicroPython shift all other locals after the free locals if (num_free > 0) { for (int i = 0; i < scope->id_info_len; i++) { id_info_t *id = &scope->id_info[i]; diff --git a/py/compile.h b/py/compile.h index 45a98588d..3297e83ae 100644 --- a/py/compile.h +++ b/py/compile.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_COMPILE_H__ -#define __MICROPY_INCLUDED_PY_COMPILE_H__ +#ifndef MICROPY_INCLUDED_PY_COMPILE_H +#define MICROPY_INCLUDED_PY_COMPILE_H #include "py/lexer.h" #include "py/parse.h" @@ -51,4 +51,4 @@ mp_raw_code_t *mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_f // this is implemented in runtime.c mp_obj_t mp_parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t parse_input_kind, mp_obj_dict_t *globals, mp_obj_dict_t *locals); -#endif // __MICROPY_INCLUDED_PY_COMPILE_H__ +#endif // MICROPY_INCLUDED_PY_COMPILE_H diff --git a/py/emit.h b/py/emit.h index 0236a9b8d..2b2c904f6 100644 --- a/py/emit.h +++ b/py/emit.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef __MICROPY_INCLUDED_PY_EMIT_H__ -#define __MICROPY_INCLUDED_PY_EMIT_H__ +#ifndef MICROPY_INCLUDED_PY_EMIT_H +#define MICROPY_INCLUDED_PY_EMIT_H #include "py/lexer.h" #include "py/scope.h" @@ -284,4 +283,4 @@ void mp_emitter_warning(pass_kind_t pass, const char *msg); #define mp_emitter_warning(pass, msg) #endif -#endif // __MICROPY_INCLUDED_PY_EMIT_H__ +#endif // MICROPY_INCLUDED_PY_EMIT_H diff --git a/py/emitbc.c b/py/emitbc.c index 127bf0bf9..677020925 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/emitcommon.c b/py/emitcommon.c index e914431d3..07b1dbb4c 100644 --- a/py/emitcommon.c +++ b/py/emitcommon.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/emitglue.c b/py/emitglue.c index fb7a54926..d2add988f 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -35,7 +35,7 @@ #include "py/runtime0.h" #include "py/bc.h" -#if 0 // print debugging info +#if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_PRINT (1) #define WRITE_CODE (1) #define DEBUG_printf DEBUG_printf diff --git a/py/emitglue.h b/py/emitglue.h index 37c4f1b18..43930333d 100644 --- a/py/emitglue.h +++ b/py/emitglue.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_EMITGLUE_H__ -#define __MICROPY_INCLUDED_PY_EMITGLUE_H__ +#ifndef MICROPY_INCLUDED_PY_EMITGLUE_H +#define MICROPY_INCLUDED_PY_EMITGLUE_H #include "py/obj.h" @@ -74,4 +74,4 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, mp_obj_t def_args, mp_obj_t def_kw_args); mp_obj_t mp_make_closure_from_raw_code(const mp_raw_code_t *rc, mp_uint_t n_closed_over, const mp_obj_t *args); -#endif // __MICROPY_INCLUDED_PY_EMITGLUE_H__ +#endif // MICROPY_INCLUDED_PY_EMITGLUE_H diff --git a/py/emitinlinethumb.c b/py/emitinlinethumb.c index c1a4eac5d..577f65672 100644 --- a/py/emitinlinethumb.c +++ b/py/emitinlinethumb.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/emitnative.c b/py/emitnative.c index 99adc809c..4608cd1e0 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -50,7 +50,7 @@ #include "py/emit.h" #include "py/bc.h" -#if 0 // print debugging info +#if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_PRINT (1) #define DEBUG_printf DEBUG_printf #else // don't print debugging info @@ -824,7 +824,7 @@ STATIC void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, mp_uint_t reg_de break; default: // not handled - mp_not_implemented("conversion to object"); + mp_raise_NotImplementedError("conversion to object"); } } @@ -2158,7 +2158,7 @@ STATIC void emit_native_call_function(emit_t *emit, mp_uint_t n_positional, mp_u break; default: // this can happen when casting a cast: int(int) - mp_not_implemented("casting"); + mp_raise_NotImplementedError("casting"); } } else { assert(vtype_fun == VTYPE_PYOBJ); @@ -2232,12 +2232,12 @@ STATIC void emit_native_raise_varargs(emit_t *emit, mp_uint_t n_args) { STATIC void emit_native_yield_value(emit_t *emit) { // not supported (for now) (void)emit; - mp_not_implemented("native yield"); + mp_raise_NotImplementedError("native yield"); } STATIC void emit_native_yield_from(emit_t *emit) { // not supported (for now) (void)emit; - mp_not_implemented("native yield from"); + mp_raise_NotImplementedError("native yield from"); } STATIC void emit_native_start_except_handler(emit_t *emit) { diff --git a/py/formatfloat.c b/py/formatfloat.c index ea5a07977..4130e8b26 100644 --- a/py/formatfloat.c +++ b/py/formatfloat.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -161,7 +161,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch if (fmt == 'g' && prec == 0) { prec = 1; } - int e, e1; + int e, e1; int dec = 0; char e_sign = '\0'; int num_digits = 0; @@ -209,7 +209,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch e_sign_char = '+'; } } else if (fp_isless1(f)) { - e++; + e++; f *= FPCONST(10.0); } @@ -232,7 +232,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch num_digits = prec; if (num_digits) { - *s++ = '.'; + *s++ = '.'; while (--e && num_digits) { *s++ = '0'; num_digits--; @@ -266,7 +266,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch f *= FPCONST(0.1); } - // If the user specified fixed format (fmt == 'f') and e makes the + // If the user specified fixed format (fmt == 'f') and e makes the // number too big to fit into the available buffer, then we'll // switch to the 'e' format. @@ -327,7 +327,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch if (prec == 0) { prec = 1; } - num_digits = prec; + num_digits = prec; } // Print the digits of the mantissa @@ -365,7 +365,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch if (rs == buf) { break; } - rs--; + rs--; } if (*rs == '0') { // We need to insert a 1 @@ -380,13 +380,13 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch e_sign = '+'; } } else { - e++; + e++; } } else { // Need at extra digit at the end to make room for the leading '1' s++; } - char *ss = s; + char *ss = s; while (ss > rs) { *ss = ss[-1]; ss--; diff --git a/py/formatfloat.h b/py/formatfloat.h index 019603447..9a1643b4d 100644 --- a/py/formatfloat.h +++ b/py/formatfloat.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_FORMATFLOAT_H__ -#define __MICROPY_INCLUDED_PY_FORMATFLOAT_H__ +#ifndef MICROPY_INCLUDED_PY_FORMATFLOAT_H +#define MICROPY_INCLUDED_PY_FORMATFLOAT_H #include "py/mpconfig.h" @@ -32,4 +32,4 @@ int mp_format_float(mp_float_t f, char *buf, size_t bufSize, char fmt, int prec, char sign); #endif -#endif // __MICROPY_INCLUDED_PY_FORMATFLOAT_H__ +#endif // MICROPY_INCLUDED_PY_FORMATFLOAT_H diff --git a/py/frozenmod.c b/py/frozenmod.c index 1eaaf574a..06d4f84c8 100644 --- a/py/frozenmod.c +++ b/py/frozenmod.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/frozenmod.h b/py/frozenmod.h index 7c1299b2c..8cddef681 100644 --- a/py/frozenmod.h +++ b/py/frozenmod.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_FROZENMOD_H__ -#define __MICROPY_INCLUDED_PY_FROZENMOD_H__ +#ifndef MICROPY_INCLUDED_PY_FROZENMOD_H +#define MICROPY_INCLUDED_PY_FROZENMOD_H #include "py/lexer.h" @@ -38,4 +38,4 @@ int mp_find_frozen_module(const char *str, size_t len, void **data); const char *mp_find_frozen_str(const char *str, size_t *len); mp_import_stat_t mp_frozen_stat(const char *str); -#endif // __MICROPY_INCLUDED_PY_FROZENMOD_H__ +#endif // MICROPY_INCLUDED_PY_FROZENMOD_H diff --git a/py/gc.c b/py/gc.c index 937dae44f..3a505e9c7 100644 --- a/py/gc.c +++ b/py/gc.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -35,7 +35,7 @@ #if MICROPY_ENABLE_GC -#if 0 // print debugging info +#if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_PRINT (1) #define DEBUG_printf DEBUG_printf #else // don't print debugging info @@ -536,37 +536,34 @@ void gc_free(void *ptr) { DEBUG_printf("gc_free(%p)\n", ptr); - if (VERIFY_PTR(ptr)) { + if (ptr == NULL) { + GC_EXIT(); + } else { + // get the GC block number corresponding to this pointer + assert(VERIFY_PTR(ptr)); size_t block = BLOCK_FROM_PTR(ptr); - if (ATB_GET_KIND(block) == AT_HEAD) { - #if MICROPY_ENABLE_FINALISER - FTB_CLEAR(block); - #endif - // set the last_free pointer to this block if it's earlier in the heap - if (block / BLOCKS_PER_ATB < MP_STATE_MEM(gc_last_free_atb_index)) { - MP_STATE_MEM(gc_last_free_atb_index) = block / BLOCKS_PER_ATB; - } + assert(ATB_GET_KIND(block) == AT_HEAD); - // free head and all of its tail blocks - do { - ATB_ANY_TO_FREE(block); - block += 1; - } while (ATB_GET_KIND(block) == AT_TAIL); - - GC_EXIT(); + #if MICROPY_ENABLE_FINALISER + FTB_CLEAR(block); + #endif - #if EXTENSIVE_HEAP_PROFILING - gc_dump_alloc_table(); - #endif - } else { - GC_EXIT(); - assert(!"bad free"); + // set the last_free pointer to this block if it's earlier in the heap + if (block / BLOCKS_PER_ATB < MP_STATE_MEM(gc_last_free_atb_index)) { + MP_STATE_MEM(gc_last_free_atb_index) = block / BLOCKS_PER_ATB; } - } else if (ptr != NULL) { - GC_EXIT(); - assert(!"bad free"); - } else { + + // free head and all of its tail blocks + do { + ATB_ANY_TO_FREE(block); + block += 1; + } while (ATB_GET_KIND(block) == AT_TAIL); + GC_EXIT(); + + #if EXTENSIVE_HEAP_PROFILING + gc_dump_alloc_table(); + #endif } } diff --git a/py/gc.h b/py/gc.h index 7d8fe2bf8..739349c1f 100644 --- a/py/gc.h +++ b/py/gc.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_GC_H__ -#define __MICROPY_INCLUDED_PY_GC_H__ +#ifndef MICROPY_INCLUDED_PY_GC_H +#define MICROPY_INCLUDED_PY_GC_H #include @@ -64,4 +64,4 @@ void gc_info(gc_info_t *info); void gc_dump_info(void); void gc_dump_alloc_table(void); -#endif // __MICROPY_INCLUDED_PY_GC_H__ +#endif // MICROPY_INCLUDED_PY_GC_H diff --git a/py/grammar.h b/py/grammar.h index 0b70538d4..6abb1de8c 100644 --- a/py/grammar.h +++ b/py/grammar.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -32,7 +32,7 @@ // # single_input is a single interactive statement; // # file_input is a module or sequence of commands read from an input file; // # eval_input is the input for the eval() functions. -// # NB: compound_stmt in single_input is followed by extra NEWLINE! --> not in Micro Python +// # NB: compound_stmt in single_input is followed by extra NEWLINE! --> not in MicroPython // single_input: NEWLINE | simple_stmt | compound_stmt // file_input: (NEWLINE | stmt)* ENDMARKER // eval_input: testlist NEWLINE* ENDMARKER diff --git a/py/lexer.c b/py/lexer.c index 6e5cc18f4..074d6f356 100644 --- a/py/lexer.c +++ b/py/lexer.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -341,7 +341,7 @@ STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw) { // 3MB of text; even gzip-compressed and with minimal structure, it'll take // roughly half a meg of storage. This form of Unicode escape may be added // later on, but it's definitely not a priority right now. -- CJA 20140607 - mp_not_implemented("unicode name escapes"); + mp_raise_NotImplementedError("unicode name escapes"); break; default: if (c >= '0' && c <= '7') { diff --git a/py/lexer.h b/py/lexer.h index 5d998b352..a29709107 100644 --- a/py/lexer.h +++ b/py/lexer.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_LEXER_H__ -#define __MICROPY_INCLUDED_PY_LEXER_H__ +#ifndef MICROPY_INCLUDED_PY_LEXER_H +#define MICROPY_INCLUDED_PY_LEXER_H #include @@ -32,7 +32,7 @@ #include "py/qstr.h" #include "py/reader.h" -/* lexer.h -- simple tokeniser for Micro Python +/* lexer.h -- simple tokeniser for MicroPython * * Uses (byte) length instead of null termination. * Tokens are the same - UTF-8 with (byte) length. @@ -192,4 +192,4 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename); mp_lexer_t *mp_lexer_new_from_fd(qstr filename, int fd, bool close_fd); #endif -#endif // __MICROPY_INCLUDED_PY_LEXER_H__ +#endif // MICROPY_INCLUDED_PY_LEXER_H diff --git a/py/malloc.c b/py/malloc.c index f48cb8da4..af4ccf2e8 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -32,7 +32,7 @@ #include "py/misc.h" #include "py/mpstate.h" -#if 0 // print debugging info +#if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_printf DEBUG_printf #else // don't print debugging info #define DEBUG_printf(...) (void)0 @@ -46,7 +46,7 @@ #include "py/gc.h" // We redirect standard alloc functions to GC heap - just for the rest of -// this module. In the rest of micropython source, system malloc can be +// this module. In the rest of MicroPython source, system malloc can be // freely accessed - for interfacing with system and 3rd-party libs for // example. On the other hand, some (e.g. bare-metal) ports may use GC // heap as system heap, so, to avoid warnings, we do undef's first. diff --git a/py/map.c b/py/map.c index 50d74f38f..7f3c90059 100644 --- a/py/map.c +++ b/py/map.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/misc.h b/py/misc.h index 5ac0f933a..71425b85e 100644 --- a/py/misc.h +++ b/py/misc.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_MISC_H__ -#define __MICROPY_INCLUDED_PY_MISC_H__ +#ifndef MICROPY_INCLUDED_PY_MISC_H +#define MICROPY_INCLUDED_PY_MISC_H // a mini library of useful types and functions @@ -223,4 +223,4 @@ static inline mp_uint_t count_lead_ones(byte val) { #define MP_FLOAT_EXP_BIAS ((1 << (MP_FLOAT_EXP_BITS - 1)) - 1) #endif // MICROPY_PY_BUILTINS_FLOAT -#endif // __MICROPY_INCLUDED_PY_MISC_H__ +#endif // MICROPY_INCLUDED_PY_MISC_H diff --git a/py/mkrules.mk b/py/mkrules.mk index 00ed27917..de2c92a3f 100644 --- a/py/mkrules.mk +++ b/py/mkrules.mk @@ -6,7 +6,7 @@ endif # This file expects that OBJ contains a list of all of the object files. # The directory portion of each object file is used to locate the source -# and should not contain any ..'s but rather be relative to the top of the +# and should not contain any ..'s but rather be relative to the top of the # tree. # # So for example, py/map.c would have an object file name py/map.o @@ -47,7 +47,7 @@ $(BUILD)/%.o: %.c $(call compile_c) # List all native flags since the current build system doesn't have -# the micropython configuration available. However, these flags are +# the MicroPython configuration available. However, these flags are # needed to extract all qstrings QSTR_GEN_EXTRA_CFLAGS += -DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB -DN_ARM -DN_XTENSA QSTR_GEN_EXTRA_CFLAGS += -I$(BUILD)/tmp @@ -135,7 +135,7 @@ $(PROG): $(OBJ) ifndef DEBUG $(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $(PROG) endif - $(Q)$(SIZE) $(PROG) + $(Q)$(SIZE) $$(find $(BUILD)/build -name "frozen*.o") $(PROG) clean: clean-prog clean-prog: diff --git a/py/modarray.c b/py/modarray.c index 356e48bee..c0cdca928 100644 --- a/py/modarray.c +++ b/py/modarray.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/modbuiltins.c b/py/modbuiltins.c index 8fbf4daeb..1c76b8073 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -540,7 +540,7 @@ STATIC mp_obj_t mp_builtin_sorted(size_t n_args, const mp_obj_t *args, mp_map_t MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_sorted_obj, 1, mp_builtin_sorted); // See mp_load_attr() if making any changes -STATIC inline mp_obj_t mp_load_attr_default(mp_obj_t base, qstr attr, mp_obj_t defval) { +static inline mp_obj_t mp_load_attr_default(mp_obj_t base, qstr attr, mp_obj_t defval) { mp_obj_t dest[2]; // use load_method, raising or not raising exception ((defval == MP_OBJ_NULL) ? mp_load_method : mp_load_method_maybe)(base, attr, dest); diff --git a/py/modcmath.c b/py/modcmath.c index 7ad8f5ad6..627a2cbad 100644 --- a/py/modcmath.c +++ b/py/modcmath.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/modcollections.c b/py/modcollections.c index e610a28d2..1a1560387 100644 --- a/py/modcollections.c +++ b/py/modcollections.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/modgc.c b/py/modgc.c index 24564622e..d45e007eb 100644 --- a/py/modgc.c +++ b/py/modgc.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/modio.c b/py/modio.c index 2d317d022..353a00286 100644 --- a/py/modio.c +++ b/py/modio.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -112,9 +112,9 @@ STATIC mp_obj_t bufwriter_flush(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bufwriter_flush_obj, bufwriter_flush); -STATIC const mp_map_elem_t bufwriter_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR_write), (mp_obj_t)&mp_stream_write_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_flush), (mp_obj_t)&bufwriter_flush_obj }, +STATIC const mp_rom_map_elem_t bufwriter_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) }, + { MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&bufwriter_flush_obj) }, }; STATIC MP_DEFINE_CONST_DICT(bufwriter_locals_dict, bufwriter_locals_dict_table); @@ -127,7 +127,7 @@ STATIC const mp_obj_type_t bufwriter_type = { .name = MP_QSTR_BufferedWriter, .make_new = bufwriter_make_new, .protocol = &bufwriter_stream_p, - .locals_dict = (mp_obj_t)&bufwriter_locals_dict, + .locals_dict = (mp_obj_dict_t*)&bufwriter_locals_dict, }; #endif // MICROPY_PY_IO_BUFFEREDWRITER diff --git a/py/modmath.c b/py/modmath.c index d5d135fc1..c56056a5d 100644 --- a/py/modmath.c +++ b/py/modmath.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/modmicropython.c b/py/modmicropython.c index d76706230..6fa3f9ad2 100644 --- a/py/modmicropython.c +++ b/py/modmicropython.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -72,7 +72,8 @@ mp_obj_t mp_micropython_mem_info(size_t n_args, const mp_obj_t *args) { (mp_uint_t)m_get_total_bytes_allocated(), (mp_uint_t)m_get_current_bytes_allocated(), (mp_uint_t)m_get_peak_bytes_allocated()); #endif #if MICROPY_STACK_CHECK - mp_printf(&mp_plat_print, "stack: " UINT_FMT " out of " INT_FMT "\n", mp_stack_usage(), MP_STATE_THREAD(stack_limit)); + mp_printf(&mp_plat_print, "stack: " UINT_FMT " out of " UINT_FMT "\n", + mp_stack_usage(), (mp_uint_t)MP_STATE_THREAD(stack_limit)); #else mp_printf(&mp_plat_print, "stack: " UINT_FMT "\n", mp_stack_usage()); #endif diff --git a/py/modstruct.c b/py/modstruct.c index 3c99ef1d8..1daa33338 100644 --- a/py/modstruct.c +++ b/py/modstruct.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/modsys.c b/py/modsys.c index b8c427ba8..b7d55fdcc 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -1,9 +1,10 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * * Copyright (c) 2013, 2014 Damien P. George + * Copyright (c) 2014-2017 Paul Sokolovsky * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -31,8 +32,11 @@ #include "py/objtuple.h" #include "py/objstr.h" #include "py/objint.h" +#include "py/objtype.h" #include "py/stream.h" #include "py/smallint.h" +#include "py/runtime0.h" +#include "py/runtime.h" #if MICROPY_PY_SYS @@ -87,7 +91,7 @@ STATIC const mp_rom_obj_tuple_t mp_sys_implementation_obj = { #undef I #ifdef MICROPY_PY_SYS_PLATFORM -/// \constant platform - the platform that Micro Python is running on +/// \constant platform - the platform that MicroPython is running on STATIC const MP_DEFINE_STR_OBJ(platform_obj, MICROPY_PY_SYS_PLATFORM); #endif @@ -143,6 +147,11 @@ STATIC mp_obj_t mp_sys_exc_info(void) { MP_DEFINE_CONST_FUN_OBJ_0(mp_sys_exc_info_obj, mp_sys_exc_info); #endif +STATIC mp_obj_t mp_sys_getsizeof(mp_obj_t obj) { + return mp_unary_op(MP_UNARY_OP_SIZEOF, obj); +} +MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_getsizeof_obj, mp_sys_getsizeof); + STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys) }, @@ -168,7 +177,7 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = { // to not try to compare sys.maxsize to some literal number (as this // number might not fit in available int size), but instead count number // of "one" bits in sys.maxsize. - { MP_ROM_QSTR(MP_QSTR_maxsize), MP_OBJ_NEW_SMALL_INT(MP_SMALL_INT_MAX) }, + { MP_ROM_QSTR(MP_QSTR_maxsize), MP_ROM_INT(MP_SMALL_INT_MAX) }, #else { MP_ROM_QSTR(MP_QSTR_maxsize), MP_ROM_PTR(&mp_maxsize_obj) }, #endif @@ -192,6 +201,9 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = { #if MICROPY_PY_SYS_EXC_INFO { MP_ROM_QSTR(MP_QSTR_exc_info), MP_ROM_PTR(&mp_sys_exc_info_obj) }, #endif + #if MICROPY_PY_SYS_GETSIZEOF + { MP_ROM_QSTR(MP_QSTR_getsizeof), MP_ROM_PTR(&mp_sys_getsizeof_obj) }, + #endif /* * Extensions to CPython diff --git a/py/modthread.c b/py/modthread.c index 1d7602789..bf74128e8 100644 --- a/py/modthread.c +++ b/py/modthread.c @@ -34,7 +34,7 @@ #include "py/mpthread.h" -#if 0 // print debugging info +#if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_PRINT (1) #define DEBUG_printf DEBUG_printf #else // don't print debugging info diff --git a/py/mpconfig.h b/py/mpconfig.h index 32d64828d..dac8a903c 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_MPCONFIG_H__ -#define __MICROPY_INCLUDED_PY_MPCONFIG_H__ +#ifndef MICROPY_INCLUDED_PY_MPCONFIG_H +#define MICROPY_INCLUDED_PY_MPCONFIG_H // This file contains default configuration settings for MicroPython. // You can override any of the options below using mpconfigport.h file @@ -373,6 +373,11 @@ #define MICROPY_DEBUG_PRINTERS (0) #endif +// Whether to enable all debugging outputs (it will be extremely verbose) +#ifndef MICROPY_DEBUG_VERBOSE +#define MICROPY_DEBUG_VERBOSE (0) +#endif + /*****************************************************************************/ /* Optimisations */ @@ -944,6 +949,11 @@ typedef double mp_float_t; #define MICROPY_PY_SYS_EXIT (1) #endif +// Whether to provide "sys.getsizeof" function +#ifndef MICROPY_PY_SYS_GETSIZEOF +#define MICROPY_PY_SYS_GETSIZEOF (0) +#endif + // Whether to provide sys.{stdin,stdout,stderr} objects #ifndef MICROPY_PY_SYS_STDFILES #define MICROPY_PY_SYS_STDFILES (0) @@ -1253,4 +1263,4 @@ typedef double mp_float_t; #define MP_UNLIKELY(x) __builtin_expect((x), 0) #endif -#endif // __MICROPY_INCLUDED_PY_MPCONFIG_H__ +#endif // MICROPY_INCLUDED_PY_MPCONFIG_H diff --git a/py/mperrno.h b/py/mperrno.h index 6ea99ae22..f439f6555 100644 --- a/py/mperrno.h +++ b/py/mperrno.h @@ -23,9 +23,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_PY_MPERRNO_H +#define MICROPY_INCLUDED_PY_MPERRNO_H -#ifndef __MICROPY_INCLUDED_PY_MPERRNO_H__ -#define __MICROPY_INCLUDED_PY_MPERRNO_H__ +#include "py/mpconfig.h" #if MICROPY_USE_INTERNAL_ERRNO @@ -139,7 +140,11 @@ #endif #if MICROPY_PY_UERRNO + +#include "py/obj.h" + qstr mp_errno_to_str(mp_obj_t errno_val); + #endif -#endif // __MICROPY_INCLUDED_PY_MPERRNO_H__ +#endif // MICROPY_INCLUDED_PY_MPERRNO_H diff --git a/py/mphal.h b/py/mphal.h index 8d5654f9e..92de01d08 100644 --- a/py/mphal.h +++ b/py/mphal.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_MPHAL_H__ -#define __MICROPY_INCLUDED_PY_MPHAL_H__ +#ifndef MICROPY_INCLUDED_PY_MPHAL_H +#define MICROPY_INCLUDED_PY_MPHAL_H #include "py/mpconfig.h" @@ -80,4 +80,4 @@ mp_uint_t mp_hal_ticks_cpu(void); #include "extmod/virtpin.h" #endif -#endif // __MICROPY_INCLUDED_PY_MPHAL_H__ +#endif // MICROPY_INCLUDED_PY_MPHAL_H diff --git a/py/mpprint.c b/py/mpprint.c index 0afd8ca3b..6c02d7cef 100644 --- a/py/mpprint.c +++ b/py/mpprint.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/mpprint.h b/py/mpprint.h index 4fc904a20..07462bddc 100644 --- a/py/mpprint.h +++ b/py/mpprint.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_MPPRINT_H__ -#define __MICROPY_INCLUDED_PY_MPPRINT_H__ +#ifndef MICROPY_INCLUDED_PY_MPPRINT_H +#define MICROPY_INCLUDED_PY_MPPRINT_H #include "py/mpconfig.h" @@ -71,4 +71,4 @@ int mp_printf(const mp_print_t *print, const char *fmt, ...); int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args); #endif -#endif // __MICROPY_INCLUDED_PY_MPPRINT_H__ +#endif // MICROPY_INCLUDED_PY_MPPRINT_H diff --git a/py/mpstate.c b/py/mpstate.c index 4fc8bc506..6ce64adfd 100644 --- a/py/mpstate.c +++ b/py/mpstate.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/mpstate.h b/py/mpstate.h index 2b8f29a6a..eca14a9e4 100644 --- a/py/mpstate.h +++ b/py/mpstate.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_MPSTATE_H__ -#define __MICROPY_INCLUDED_PY_MPSTATE_H__ +#ifndef MICROPY_INCLUDED_PY_MPSTATE_H +#define MICROPY_INCLUDED_PY_MPSTATE_H #include @@ -36,7 +36,7 @@ #include "py/objlist.h" #include "py/objexcept.h" -// This file contains structures defining the state of the Micro Python +// This file contains structures defining the state of the MicroPython // memory system, runtime and virtual machine. The state is a global // variable, but in the future it is hoped that the state can become local. @@ -248,4 +248,4 @@ extern mp_state_thread_t *mp_thread_get_state(void); #define MP_STATE_THREAD(x) (mp_state_ctx.thread.x) #endif -#endif // __MICROPY_INCLUDED_PY_MPSTATE_H__ +#endif // MICROPY_INCLUDED_PY_MPSTATE_H diff --git a/py/mpthread.h b/py/mpthread.h index 04d4f1968..602df830c 100644 --- a/py/mpthread.h +++ b/py/mpthread.h @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_MPTHREAD_H__ -#define __MICROPY_INCLUDED_PY_MPTHREAD_H__ +#ifndef MICROPY_INCLUDED_PY_MPTHREAD_H +#define MICROPY_INCLUDED_PY_MPTHREAD_H #include "py/mpconfig.h" @@ -58,4 +58,4 @@ void mp_thread_mutex_unlock(mp_thread_mutex_t *mutex); #define MP_THREAD_GIL_EXIT() #endif -#endif // __MICROPY_INCLUDED_PY_MPTHREAD_H__ +#endif // MICROPY_INCLUDED_PY_MPTHREAD_H diff --git a/py/mpz.c b/py/mpz.c index f5675a291..d300a8e5d 100644 --- a/py/mpz.c +++ b/py/mpz.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -939,10 +939,6 @@ void mpz_set_from_bytes(mpz_t *z, bool big_endian, size_t len, const byte *buf) z->len = mpn_remove_trailing_zeros(z->dig, z->dig + z->len); } -bool mpz_is_zero(const mpz_t *z) { - return z->len == 0; -} - #if 0 these functions are unused @@ -950,10 +946,6 @@ bool mpz_is_pos(const mpz_t *z) { return z->len > 0 && z->neg == 0; } -bool mpz_is_neg(const mpz_t *z) { - return z->len > 0 && z->neg != 0; -} - bool mpz_is_odd(const mpz_t *z) { return z->len > 0 && (z->dig[0] & 1) != 0; } diff --git a/py/mpz.h b/py/mpz.h index 5c8822722..e2d0c30aa 100644 --- a/py/mpz.h +++ b/py/mpz.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_MPZ_H__ -#define __MICROPY_INCLUDED_PY_MPZ_H__ +#ifndef MICROPY_INCLUDED_PY_MPZ_H +#define MICROPY_INCLUDED_PY_MPZ_H #include @@ -111,7 +111,8 @@ void mpz_set_from_float(mpz_t *z, mp_float_t src); size_t mpz_set_from_str(mpz_t *z, const char *str, size_t len, bool neg, unsigned int base); void mpz_set_from_bytes(mpz_t *z, bool big_endian, size_t len, const byte *buf); -bool mpz_is_zero(const mpz_t *z); +static inline bool mpz_is_zero(const mpz_t *z) { return z->len == 0; } +static inline bool mpz_is_neg(const mpz_t *z) { return z->len != 0 && z->neg != 0; } int mpz_cmp(const mpz_t *lhs, const mpz_t *rhs); void mpz_abs_inpl(mpz_t *dest, const mpz_t *z); @@ -139,4 +140,4 @@ mp_float_t mpz_as_float(const mpz_t *z); #endif size_t mpz_as_str_inpl(const mpz_t *z, unsigned int base, const char *prefix, char base_char, char comma, char *str); -#endif // __MICROPY_INCLUDED_PY_MPZ_H__ +#endif // MICROPY_INCLUDED_PY_MPZ_H diff --git a/py/nativeglue.c b/py/nativeglue.c index c75e5ec04..e954234c2 100644 --- a/py/nativeglue.c +++ b/py/nativeglue.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -34,7 +34,7 @@ #include "py/emitglue.h" #include "py/bc.h" -#if 0 // print debugging info +#if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_printf DEBUG_printf #else // don't print debugging info #define DEBUG_printf(...) (void)0 @@ -42,7 +42,7 @@ #if MICROPY_EMIT_NATIVE -// convert a Micro Python object to a valid native value based on type +// convert a MicroPython object to a valid native value based on type mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type) { DEBUG_printf("mp_convert_obj_to_native(%p, " UINT_FMT ")\n", obj, type); switch (type & 0xf) { @@ -66,7 +66,7 @@ mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type) { #if MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM -// convert a native value to a Micro Python object based on type +// convert a native value to a MicroPython object based on type mp_obj_t mp_convert_native_to_obj(mp_uint_t val, mp_uint_t type) { DEBUG_printf("mp_convert_native_to_obj(" UINT_FMT ", " UINT_FMT ")\n", val, type); switch (type & 0xf) { diff --git a/py/nlr.h b/py/nlr.h index 7a71ef34b..63fe392d9 100644 --- a/py/nlr.h +++ b/py/nlr.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_NLR_H__ -#define __MICROPY_INCLUDED_PY_NLR_H__ +#ifndef MICROPY_INCLUDED_PY_NLR_H +#define MICROPY_INCLUDED_PY_NLR_H // non-local return // exception handling, basically a stack of setjmp/longjmp buffers @@ -112,4 +112,4 @@ NORETURN void nlr_jump_fail(void *val); #endif -#endif // __MICROPY_INCLUDED_PY_NLR_H__ +#endif // MICROPY_INCLUDED_PY_NLR_H diff --git a/py/nlrsetjmp.c b/py/nlrsetjmp.c index c3873e0b6..1fb459440 100644 --- a/py/nlrsetjmp.c +++ b/py/nlrsetjmp.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/obj.c b/py/obj.c index 1238b7011..515a95b2e 100644 --- a/py/obj.c +++ b/py/obj.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/obj.h b/py/obj.h index a3c06a261..22bfda0f9 100644 --- a/py/obj.h +++ b/py/obj.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_OBJ_H__ -#define __MICROPY_INCLUDED_PY_OBJ_H__ +#ifndef MICROPY_INCLUDED_PY_OBJ_H +#define MICROPY_INCLUDED_PY_OBJ_H #include "py/mpconfig.h" #include "py/misc.h" @@ -864,4 +864,4 @@ mp_obj_t mp_seq_extract_slice(size_t len, const mp_obj_t *seq, mp_bound_slice_t memmove(((char*)dest) + (beg + slice_len) * (item_sz), ((char*)dest) + (end) * (item_sz), ((dest_len) + (len_adj) - ((beg) + (slice_len))) * (item_sz)); \ memmove(((char*)dest) + (beg) * (item_sz), slice, slice_len * (item_sz)); -#endif // __MICROPY_INCLUDED_PY_OBJ_H__ +#endif // MICROPY_INCLUDED_PY_OBJ_H diff --git a/py/objarray.c b/py/objarray.c index 21479a800..a31c53680 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -288,7 +288,7 @@ STATIC mp_obj_t array_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) // Otherwise, can only look for a scalar numeric value in an array if (MP_OBJ_IS_INT(rhs_in) || mp_obj_is_float(rhs_in)) { - mp_not_implemented(""); + mp_raise_NotImplementedError(""); } return mp_const_false; @@ -378,7 +378,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value } else if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) { mp_bound_slice_t slice; if (!mp_seq_get_fast_slice_indexes(o->len, index_in, &slice)) { - mp_not_implemented("only slices with step=1 (aka None) are supported"); + mp_raise_NotImplementedError("only slices with step=1 (aka None) are supported"); } if (value != MP_OBJ_SENTINEL) { #if MICROPY_PY_ARRAY_SLICE_ASSIGN @@ -409,7 +409,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value src_len = bufinfo.len; src_items = bufinfo.buf; } else { - mp_not_implemented("array/bytes required on right side"); + mp_raise_NotImplementedError("array/bytes required on right side"); } // TODO: check src/dst compat diff --git a/py/objarray.h b/py/objarray.h index 06a2a07ef..038966845 100644 --- a/py/objarray.h +++ b/py/objarray.h @@ -24,9 +24,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef __MICROPY_INCLUDED_PY_OBJARRAY_H__ -#define __MICROPY_INCLUDED_PY_OBJARRAY_H__ +#ifndef MICROPY_INCLUDED_PY_OBJARRAY_H +#define MICROPY_INCLUDED_PY_OBJARRAY_H #include "py/obj.h" @@ -40,4 +39,4 @@ typedef struct _mp_obj_array_t { void *items; } mp_obj_array_t; -#endif // __MICROPY_INCLUDED_PY_OBJARRAY_H__ +#endif // MICROPY_INCLUDED_PY_OBJARRAY_H diff --git a/py/objattrtuple.c b/py/objattrtuple.c index 8c5e79575..3cc298d4e 100644 --- a/py/objattrtuple.c +++ b/py/objattrtuple.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objbool.c b/py/objbool.c index 5bc04bb6f..e5bc3c228 100644 --- a/py/objbool.c +++ b/py/objbool.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objboundmeth.c b/py/objboundmeth.c index 57be6a6cf..890f8b15b 100644 --- a/py/objboundmeth.c +++ b/py/objboundmeth.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objcell.c b/py/objcell.c index 06a88b954..111906412 100644 --- a/py/objcell.c +++ b/py/objcell.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objclosure.c b/py/objclosure.c index 3e12358bb..4eb9eb8b8 100644 --- a/py/objclosure.c +++ b/py/objclosure.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objcomplex.c b/py/objcomplex.c index e4fbed1e8..f945f3560 100644 --- a/py/objcomplex.c +++ b/py/objcomplex.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objdict.c b/py/objdict.c index 23d3008b8..f6357a905 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -105,6 +105,12 @@ STATIC mp_obj_t dict_unary_op(mp_uint_t op, mp_obj_t self_in) { switch (op) { case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->map.used != 0); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->map.used); + #if MICROPY_PY_SYS_GETSIZEOF + case MP_UNARY_OP_SIZEOF: { + size_t sz = sizeof(*self) + sizeof(*self->map.table) * self->map.alloc; + return MP_OBJ_NEW_SMALL_INT(sz); + } + #endif default: return MP_OBJ_NULL; // op not supported } } diff --git a/py/objenumerate.c b/py/objenumerate.c index faae6516c..1a9d30f83 100644 --- a/py/objenumerate.c +++ b/py/objenumerate.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objexcept.c b/py/objexcept.c index 4722aca91..a9fe04094 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objexcept.h b/py/objexcept.h index 3128fded7..f67651a7e 100644 --- a/py/objexcept.h +++ b/py/objexcept.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_OBJEXCEPT_H__ -#define __MICROPY_INCLUDED_PY_OBJEXCEPT_H__ +#ifndef MICROPY_INCLUDED_PY_OBJEXCEPT_H +#define MICROPY_INCLUDED_PY_OBJEXCEPT_H #include "py/obj.h" #include "py/objtuple.h" @@ -37,4 +37,4 @@ typedef struct _mp_obj_exception_t { mp_obj_tuple_t *args; } mp_obj_exception_t; -#endif // __MICROPY_INCLUDED_PY_OBJEXCEPT_H__ +#endif // MICROPY_INCLUDED_PY_OBJEXCEPT_H diff --git a/py/objfilter.c b/py/objfilter.c index a655b8a78..cb965d8c3 100644 --- a/py/objfilter.c +++ b/py/objfilter.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objfloat.c b/py/objfloat.c index d0e616612..15edd810f 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objfun.c b/py/objfun.c index 9f3589124..5606511d8 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -36,7 +36,7 @@ #include "py/bc.h" #include "py/stackctrl.h" -#if 0 // print debugging info +#if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_PRINT (1) #else // don't print debugging info #define DEBUG_PRINT (0) @@ -480,7 +480,7 @@ typedef mp_uint_t (*inline_asm_fun_2_t)(mp_uint_t, mp_uint_t); typedef mp_uint_t (*inline_asm_fun_3_t)(mp_uint_t, mp_uint_t, mp_uint_t); typedef mp_uint_t (*inline_asm_fun_4_t)(mp_uint_t, mp_uint_t, mp_uint_t, mp_uint_t); -// convert a Micro Python object to a sensible value for inline asm +// convert a MicroPython object to a sensible value for inline asm STATIC mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) { // TODO for byte_array, pass pointer to the array if (MP_OBJ_IS_SMALL_INT(obj)) { diff --git a/py/objfun.h b/py/objfun.h index d02fada9b..fbb351626 100644 --- a/py/objfun.h +++ b/py/objfun.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_OBJFUN_H__ -#define __MICROPY_INCLUDED_PY_OBJFUN_H__ +#ifndef MICROPY_INCLUDED_PY_OBJFUN_H +#define MICROPY_INCLUDED_PY_OBJFUN_H #include "py/obj.h" @@ -41,4 +41,4 @@ typedef struct _mp_obj_fun_bc_t { mp_obj_t extra_args[]; } mp_obj_fun_bc_t; -#endif // __MICROPY_INCLUDED_PY_OBJFUN_H__ +#endif // MICROPY_INCLUDED_PY_OBJFUN_H diff --git a/py/objgenerator.c b/py/objgenerator.c index 9d6e636b3..2f39f3a52 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objgenerator.h b/py/objgenerator.h index d1b9be478..80bf9cd86 100644 --- a/py/objgenerator.h +++ b/py/objgenerator.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,12 +23,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_OBJGENERATOR_H__ -#define __MICROPY_INCLUDED_PY_OBJGENERATOR_H__ +#ifndef MICROPY_INCLUDED_PY_OBJGENERATOR_H +#define MICROPY_INCLUDED_PY_OBJGENERATOR_H #include "py/obj.h" #include "py/runtime.h" mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_val, mp_obj_t throw_val, mp_obj_t *ret_val); -#endif // __MICROPY_INCLUDED_PY_OBJGENERATOR_H__ +#endif // MICROPY_INCLUDED_PY_OBJGENERATOR_H diff --git a/py/objgetitemiter.c b/py/objgetitemiter.c index a3c754448..afd6fb22b 100644 --- a/py/objgetitemiter.c +++ b/py/objgetitemiter.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objint.c b/py/objint.c index 2749ec51c..29d889629 100644 --- a/py/objint.c +++ b/py/objint.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objint.h b/py/objint.h index da56c1862..394c23714 100644 --- a/py/objint.h +++ b/py/objint.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_OBJINT_H__ -#define __MICROPY_INCLUDED_PY_OBJINT_H__ +#ifndef MICROPY_INCLUDED_PY_OBJINT_H +#define MICROPY_INCLUDED_PY_OBJINT_H #include "py/mpz.h" #include "py/obj.h" @@ -63,4 +63,4 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in); mp_obj_t mp_obj_int_binary_op_extra_cases(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in); mp_obj_t mp_obj_int_pow3(mp_obj_t base, mp_obj_t exponent, mp_obj_t modulus); -#endif // __MICROPY_INCLUDED_PY_OBJINT_H__ +#endif // MICROPY_INCLUDED_PY_OBJINT_H diff --git a/py/objint_longlong.c b/py/objint_longlong.c index eb80407bc..02c005d2f 100644 --- a/py/objint_longlong.c +++ b/py/objint_longlong.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -191,6 +191,13 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { case MP_BINARY_OP_POWER: case MP_BINARY_OP_INPLACE_POWER: { + if (rhs_val < 0) { + #if MICROPY_PY_BUILTINS_FLOAT + return mp_obj_float_binary_op(op, lhs_val, rhs_in); + #else + mp_raise_ValueError("negative power with no float support"); + #endif + } long long ans = 1; while (rhs_val > 0) { if (rhs_val & 1) { diff --git a/py/objint_mpz.c b/py/objint_mpz.c index d818b6f40..0791a8af2 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -290,6 +290,13 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { case MP_BINARY_OP_POWER: case MP_BINARY_OP_INPLACE_POWER: + if (mpz_is_neg(zrhs)) { + #if MICROPY_PY_BUILTINS_FLOAT + return mp_obj_float_binary_op(op, mpz_as_float(zlhs), rhs_in); + #else + mp_raise_ValueError("negative power with no float support"); + #endif + } mpz_pow_inpl(&res->mpz, zlhs, zrhs); break; diff --git a/py/objlist.c b/py/objlist.c index 45e69c8bc..86d430062 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -104,6 +104,12 @@ STATIC mp_obj_t list_unary_op(mp_uint_t op, mp_obj_t self_in) { switch (op) { case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->len != 0); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->len); + #if MICROPY_PY_SYS_GETSIZEOF + case MP_UNARY_OP_SIZEOF: { + size_t sz = sizeof(*self) + sizeof(mp_obj_t) * self->alloc; + return MP_OBJ_NEW_SMALL_INT(sz); + } + #endif default: return MP_OBJ_NULL; // op not supported } } @@ -156,7 +162,7 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in); mp_bound_slice_t slice; if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice)) { - mp_not_implemented(""); + mp_raise_NotImplementedError(""); } mp_int_t len_adj = slice.start - slice.stop; @@ -196,7 +202,7 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { mp_obj_get_array(value, &value_len, &value_items); mp_bound_slice_t slice_out; if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice_out)) { - mp_not_implemented(""); + mp_raise_NotImplementedError(""); } mp_int_t len_adj = value_len - (slice_out.stop - slice_out.start); //printf("Len adj: %d\n", len_adj); diff --git a/py/objlist.h b/py/objlist.h index 5b2d216fc..28b5495a9 100644 --- a/py/objlist.h +++ b/py/objlist.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_OBJLIST_H__ -#define __MICROPY_INCLUDED_PY_OBJLIST_H__ +#ifndef MICROPY_INCLUDED_PY_OBJLIST_H +#define MICROPY_INCLUDED_PY_OBJLIST_H #include "py/obj.h" @@ -35,4 +35,4 @@ typedef struct _mp_obj_list_t { mp_obj_t *items; } mp_obj_list_t; -#endif // __MICROPY_INCLUDED_PY_OBJLIST_H__ +#endif // MICROPY_INCLUDED_PY_OBJLIST_H diff --git a/py/objmap.c b/py/objmap.c index 111c964fd..908c61507 100644 --- a/py/objmap.c +++ b/py/objmap.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objmodule.c b/py/objmodule.c index 43bb36b98..fc8507c27 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objmodule.h b/py/objmodule.h index 4e6612adc..b5c07dc33 100644 --- a/py/objmodule.h +++ b/py/objmodule.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_OBJMODULE_H__ -#define __MICROPY_INCLUDED_PY_OBJMODULE_H__ +#ifndef MICROPY_INCLUDED_PY_OBJMODULE_H +#define MICROPY_INCLUDED_PY_OBJMODULE_H #include "py/obj.h" @@ -34,4 +34,4 @@ extern const mp_map_t mp_builtin_module_weak_links_map; mp_obj_t mp_module_get(qstr module_name); void mp_module_register(qstr qstr, mp_obj_t module); -#endif // __MICROPY_INCLUDED_PY_OBJMODULE_H__ +#endif // MICROPY_INCLUDED_PY_OBJMODULE_H diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c index 7ec5c2f41..fb9d9f02c 100644 --- a/py/objnamedtuple.c +++ b/py/objnamedtuple.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objnone.c b/py/objnone.c index 5d5b83540..cd7319bec 100644 --- a/py/objnone.c +++ b/py/objnone.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objobject.c b/py/objobject.c index f9a7d17c3..49d2ec62e 100644 --- a/py/objobject.c +++ b/py/objobject.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objproperty.c b/py/objproperty.c index 8189935d2..0934fad05 100644 --- a/py/objproperty.c +++ b/py/objproperty.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objrange.c b/py/objrange.c index 8c4e14f49..33b07a9d4 100644 --- a/py/objrange.c +++ b/py/objrange.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objreversed.c b/py/objreversed.c index fc85e72bf..a596a2fde 100644 --- a/py/objreversed.c +++ b/py/objreversed.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objset.c b/py/objset.c index f74bc74a0..376439b73 100644 --- a/py/objset.c +++ b/py/objset.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objsingleton.c b/py/objsingleton.c index 394c12767..ea72ae38c 100644 --- a/py/objsingleton.c +++ b/py/objsingleton.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objslice.c b/py/objslice.c index 928be6dab..358c44d06 100644 --- a/py/objslice.c +++ b/py/objslice.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objstr.c b/py/objstr.c index cea10770c..d4c038a68 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -347,8 +347,9 @@ mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { rhs_data = bufinfo.buf; rhs_len = bufinfo.len; } else { - // incompatible types - return MP_OBJ_NULL; // op not supported + // LHS is str and RHS has an incompatible type + // (except if operation is EQUAL, but that's handled by mp_obj_equal) + bad_implicit_conversion(rhs_in); } switch (op) { @@ -403,7 +404,7 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) { mp_bound_slice_t slice; if (!mp_seq_get_fast_slice_indexes(self_len, index, &slice)) { - mp_not_implemented("only slices with step=1 (aka None) are supported"); + mp_raise_NotImplementedError("only slices with step=1 (aka None) are supported"); } return mp_obj_new_str_of_type(type, self_data + slice.start, slice.stop - slice.start); } @@ -617,7 +618,7 @@ STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) { mp_int_t idx = splits; if (sep == mp_const_none) { - mp_not_implemented("rsplit(None,n)"); + mp_raise_NotImplementedError("rsplit(None,n)"); } else { size_t sep_len; const char *sep_str = mp_obj_str_get_data(sep, &sep_len); @@ -741,7 +742,7 @@ STATIC mp_obj_t str_endswith(size_t n_args, const mp_obj_t *args) { GET_STR_DATA_LEN(args[0], str, str_len); GET_STR_DATA_LEN(args[1], suffix, suffix_len); if (n_args > 2) { - mp_not_implemented("start/end indices"); + mp_raise_NotImplementedError("start/end indices"); } if (suffix_len > str_len) { @@ -1043,7 +1044,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar arg = key_elem->value; } if (field_name < field_name_top) { - mp_not_implemented("attributes not supported yet"); + mp_raise_NotImplementedError("attributes not supported yet"); } } else { if (*arg_i < 0) { diff --git a/py/objstr.h b/py/objstr.h index e92832d10..3aef8c68e 100644 --- a/py/objstr.h +++ b/py/objstr.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_OBJSTR_H__ -#define __MICROPY_INCLUDED_PY_OBJSTR_H__ +#ifndef MICROPY_INCLUDED_PY_OBJSTR_H +#define MICROPY_INCLUDED_PY_OBJSTR_H #include "py/obj.h" @@ -102,4 +102,4 @@ MP_DECLARE_CONST_FUN_OBJ_1(str_isdigit_obj); MP_DECLARE_CONST_FUN_OBJ_1(str_isupper_obj); MP_DECLARE_CONST_FUN_OBJ_1(str_islower_obj); -#endif // __MICROPY_INCLUDED_PY_OBJSTR_H__ +#endif // MICROPY_INCLUDED_PY_OBJSTR_H diff --git a/py/objstringio.c b/py/objstringio.c index 645c441cb..046d32580 100644 --- a/py/objstringio.c +++ b/py/objstringio.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/objstrunicode.c b/py/objstrunicode.c index d53428586..036f7f3c1 100644 --- a/py/objstrunicode.c +++ b/py/objstrunicode.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -188,7 +188,7 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { mp_obj_t ostart, ostop, ostep; mp_obj_slice_get(index, &ostart, &ostop, &ostep); if (ostep != mp_const_none && ostep != MP_OBJ_NEW_SMALL_INT(1)) { - mp_not_implemented("only slices with step=1 (aka None) are supported"); + mp_raise_NotImplementedError("only slices with step=1 (aka None) are supported"); } const byte *pstart, *pstop; diff --git a/py/objtuple.c b/py/objtuple.c index eaf0e37f4..765edb907 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -148,7 +148,8 @@ mp_obj_t mp_obj_tuple_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { mp_seq_cat(s->items, o->items, o->len, p->items, p->len, mp_obj_t); return MP_OBJ_FROM_PTR(s); } - case MP_BINARY_OP_MULTIPLY: { + case MP_BINARY_OP_MULTIPLY: + case MP_BINARY_OP_INPLACE_MULTIPLY: { mp_int_t n; if (!mp_obj_get_int_maybe(rhs, &n)) { return MP_OBJ_NULL; // op not supported @@ -180,7 +181,7 @@ mp_obj_t mp_obj_tuple_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) { mp_bound_slice_t slice; if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice)) { - mp_not_implemented("only slices with step=1 (aka None) are supported"); + mp_raise_NotImplementedError("only slices with step=1 (aka None) are supported"); } mp_obj_tuple_t *res = MP_OBJ_TO_PTR(mp_obj_new_tuple(slice.stop - slice.start, NULL)); mp_seq_copy(res->items, self->items + slice.start, res->len, mp_obj_t); diff --git a/py/objtuple.h b/py/objtuple.h index 555c3b3c2..05c6490fe 100644 --- a/py/objtuple.h +++ b/py/objtuple.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_OBJTUPLE_H__ -#define __MICROPY_INCLUDED_PY_OBJTUPLE_H__ +#ifndef MICROPY_INCLUDED_PY_OBJTUPLE_H +#define MICROPY_INCLUDED_PY_OBJTUPLE_H #include "py/obj.h" @@ -61,4 +61,4 @@ void mp_obj_attrtuple_print_helper(const mp_print_t *print, const qstr *fields, mp_obj_t mp_obj_new_attrtuple(const qstr *fields, size_t n, const mp_obj_t *items); -#endif // __MICROPY_INCLUDED_PY_OBJTUPLE_H__ +#endif // MICROPY_INCLUDED_PY_OBJTUPLE_H diff --git a/py/objtype.c b/py/objtype.c index 2a119e40f..e1a24da7e 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -35,7 +35,7 @@ #include "py/runtime0.h" #include "py/runtime.h" -#if 0 // print debugging info +#if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_PRINT (1) #define DEBUG_printf DEBUG_printf #else // don't print debugging info @@ -339,11 +339,27 @@ const qstr mp_unary_op_method_name[] = { [MP_UNARY_OP_NEGATIVE] = MP_QSTR___neg__, [MP_UNARY_OP_INVERT] = MP_QSTR___invert__, #endif + #if MICROPY_PY_SYS_GETSIZEOF + [MP_UNARY_OP_SIZEOF] = MP_QSTR_getsizeof, + #endif [MP_UNARY_OP_NOT] = MP_QSTR_, // don't need to implement this, used to make sure array has full size }; STATIC mp_obj_t instance_unary_op(mp_uint_t op, mp_obj_t self_in) { mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); + + #if MICROPY_PY_SYS_GETSIZEOF + if (MP_UNLIKELY(op == MP_UNARY_OP_SIZEOF)) { + // TODO: This doesn't count inherited objects (self->subobj) + const mp_obj_type_t *native_base; + size_t num_native_bases = instance_count_native_bases(mp_obj_get_type(self_in), &native_base); + + size_t sz = sizeof(*self) + sizeof(*self->subobj) * num_native_bases + + sizeof(*self->members.table) * self->members.alloc; + return MP_OBJ_NEW_SMALL_INT(sz); + } + #endif + qstr op_name = mp_unary_op_method_name[op]; /* Still try to lookup native slot if (op_name == 0) { @@ -375,7 +391,7 @@ STATIC mp_obj_t instance_unary_op(mp_uint_t op, mp_obj_t self_in) { if (member[0] == MP_OBJ_NULL) { // https://docs.python.org/3/reference/datamodel.html#object.__hash__ // "User-defined classes have __eq__() and __hash__() methods by default; - // with them, all objects compare unequal (except with themselves) and + // with them, all objects compare unequal (except with themselves) and // x.__hash__() returns an appropriate value such that x == y implies // both that x is y and hash(x) == hash(y)." return MP_OBJ_NEW_SMALL_INT((mp_uint_t)self_in); @@ -917,8 +933,8 @@ const mp_obj_type_t mp_type_type = { }; mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) { - assert(MP_OBJ_IS_TYPE(bases_tuple, &mp_type_tuple)); // Micro Python restriction, for now - assert(MP_OBJ_IS_TYPE(locals_dict, &mp_type_dict)); // Micro Python restriction, for now + assert(MP_OBJ_IS_TYPE(bases_tuple, &mp_type_tuple)); // MicroPython restriction, for now + assert(MP_OBJ_IS_TYPE(locals_dict, &mp_type_dict)); // MicroPython restriction, for now // TODO might need to make a copy of locals_dict; at least that's how CPython does it diff --git a/py/objtype.h b/py/objtype.h index 61efd00c0..52419f3cd 100644 --- a/py/objtype.h +++ b/py/objtype.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_OBJTYPE_H__ -#define __MICROPY_INCLUDED_PY_OBJTYPE_H__ +#ifndef MICROPY_INCLUDED_PY_OBJTYPE_H +#define MICROPY_INCLUDED_PY_OBJTYPE_H #include "py/obj.h" @@ -49,4 +49,4 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons // this needs to be exposed for the above macros to work correctly mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self_in, size_t n_args, size_t n_kw, const mp_obj_t *args); -#endif // __MICROPY_INCLUDED_PY_OBJTYPE_H__ +#endif // MICROPY_INCLUDED_PY_OBJTYPE_H diff --git a/py/objzip.c b/py/objzip.c index 6f72d1595..0183925e3 100644 --- a/py/objzip.c +++ b/py/objzip.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/opmethods.c b/py/opmethods.c index 80a953fb8..1200ba39e 100644 --- a/py/opmethods.c +++ b/py/opmethods.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/parse.c b/py/parse.c index 2f16748a6..e399aac53 100644 --- a/py/parse.c +++ b/py/parse.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/parse.h b/py/parse.h index 769f5a875..9a1a2b4dd 100644 --- a/py/parse.h +++ b/py/parse.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_PARSE_H__ -#define __MICROPY_INCLUDED_PY_PARSE_H__ +#ifndef MICROPY_INCLUDED_PY_PARSE_H +#define MICROPY_INCLUDED_PY_PARSE_H #include #include @@ -104,4 +104,4 @@ typedef struct _mp_parse_t { mp_parse_tree_t mp_parse(struct _mp_lexer_t *lex, mp_parse_input_kind_t input_kind); void mp_parse_tree_clear(mp_parse_tree_t *tree); -#endif // __MICROPY_INCLUDED_PY_PARSE_H__ +#endif // MICROPY_INCLUDED_PY_PARSE_H diff --git a/py/parsenum.c b/py/parsenum.c index 177118843..b62029f7c 100644 --- a/py/parsenum.c +++ b/py/parsenum.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/parsenum.h b/py/parsenum.h index f140cfc85..a5bed731d 100644 --- a/py/parsenum.h +++ b/py/parsenum.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_PARSENUM_H__ -#define __MICROPY_INCLUDED_PY_PARSENUM_H__ +#ifndef MICROPY_INCLUDED_PY_PARSENUM_H +#define MICROPY_INCLUDED_PY_PARSENUM_H #include "py/mpconfig.h" #include "py/lexer.h" @@ -34,4 +34,4 @@ mp_obj_t mp_parse_num_integer(const char *restrict str, size_t len, int base, mp_lexer_t *lex); mp_obj_t mp_parse_num_decimal(const char *str, size_t len, bool allow_imag, bool force_complex, mp_lexer_t *lex); -#endif // __MICROPY_INCLUDED_PY_PARSENUM_H__ +#endif // MICROPY_INCLUDED_PY_PARSENUM_H diff --git a/py/parsenumbase.c b/py/parsenumbase.c index 73a3372f0..ba1059122 100644 --- a/py/parsenumbase.c +++ b/py/parsenumbase.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/parsenumbase.h b/py/parsenumbase.h index 9da9db841..3a525f993 100644 --- a/py/parsenumbase.h +++ b/py/parsenumbase.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,11 +23,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_PARSENUMBASE_H__ -#define __MICROPY_INCLUDED_PY_PARSENUMBASE_H__ +#ifndef MICROPY_INCLUDED_PY_PARSENUMBASE_H +#define MICROPY_INCLUDED_PY_PARSENUMBASE_H #include "py/mpconfig.h" size_t mp_parse_num_base(const char *str, size_t len, int *base); -#endif // __MICROPY_INCLUDED_PY_PARSENUMBASE_H__ +#endif // MICROPY_INCLUDED_PY_PARSENUMBASE_H diff --git a/py/py.mk b/py/py.mk index 30aba446f..fff6a0813 100644 --- a/py/py.mk +++ b/py/py.mk @@ -22,13 +22,13 @@ CFLAGS_MOD += -DFFCONF_H=\"lib/oofatfs/ffconf.h\" ifeq ($(MICROPY_PY_USSL),1) CFLAGS_MOD += -DMICROPY_PY_USSL=1 ifeq ($(MICROPY_SSL_AXTLS),1) -CFLAGS_MOD += -DMICROPY_SSL_AXTLS=1 -I../lib/axtls/ssl -I../lib/axtls/crypto -I../lib/axtls/config +CFLAGS_MOD += -DMICROPY_SSL_AXTLS=1 -I$(TOP)/lib/axtls/ssl -I$(TOP)/lib/axtls/crypto -I$(TOP)/lib/axtls/config LDFLAGS_MOD += -Lbuild -laxtls else ifeq ($(MICROPY_SSL_MBEDTLS),1) # Can be overridden by ports which have "builtin" mbedTLS -MICROPY_SSL_MBEDTLS_INCLUDE ?= ../lib/mbedtls/include +MICROPY_SSL_MBEDTLS_INCLUDE ?= $(TOP)/lib/mbedtls/include CFLAGS_MOD += -DMICROPY_SSL_MBEDTLS=1 -I$(MICROPY_SSL_MBEDTLS_INCLUDE) -LDFLAGS_MOD += -L../lib/mbedtls/library -lmbedx509 -lmbedtls -lmbedcrypto +LDFLAGS_MOD += -L$(TOP)/lib/mbedtls/library -lmbedx509 -lmbedtls -lmbedcrypto endif endif @@ -38,7 +38,7 @@ endif ifeq ($(MICROPY_PY_LWIP),1) LWIP_DIR = lib/lwip/src -INC += -I../lib/lwip/src/include -I../lib/lwip/src/include/ipv4 -I../extmod/lwip-include +INC += -I$(TOP)/lib/lwip/src/include -I$(TOP)/lib/lwip/src/include/ipv4 -I$(TOP)/extmod/lwip-include CFLAGS_MOD += -DMICROPY_PY_LWIP=1 SRC_MOD += extmod/modlwip.c lib/netutils/netutils.c SRC_MOD += $(addprefix $(LWIP_DIR)/,\ @@ -74,8 +74,8 @@ endif ifeq ($(MICROPY_PY_BTREE),1) BTREE_DIR = lib/berkeley-db-1.xx -CFLAGS_MOD += -D__DBINTERFACE_PRIVATE=1 -Dmpool_error=printf -Dabort=abort_ -Dvirt_fd_t=mp_obj_t "-DVIRT_FD_T_HEADER=" -INC += -I../$(BTREE_DIR)/PORT/include +BTREE_DEFS = -D__DBINTERFACE_PRIVATE=1 -Dmpool_error=printf -Dabort=abort_ -Dvirt_fd_t=mp_obj_t "-DVIRT_FD_T_HEADER=" +INC += -I$(TOP)/$(BTREE_DIR)/PORT/include SRC_MOD += extmod/modbtree.c SRC_MOD += $(addprefix $(BTREE_DIR)/,\ btree/bt_close.c \ @@ -95,7 +95,9 @@ mpool/mpool.c \ ) CFLAGS_MOD += -DMICROPY_PY_BTREE=1 # we need to suppress certain warnings to get berkeley-db to compile cleanly -$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter +# and we have separate BTREE_DEFS so the definitions don't interfere with other source code +$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter $(BTREE_DEFS) +$(BUILD)/extmod/modbtree.o: CFLAGS += $(BTREE_DEFS) endif # py object files diff --git a/py/qstr.c b/py/qstr.c index 5aa161064..95c9b6835 100644 --- a/py/qstr.c +++ b/py/qstr.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -36,7 +36,7 @@ // ultimately we will replace this with a static hash table of some kind // also probably need to include the length in the string data, to allow null bytes in the string -#if 0 // print debugging info +#if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_printf DEBUG_printf #else // don't print debugging info #define DEBUG_printf(...) (void)0 diff --git a/py/qstr.h b/py/qstr.h index 8c63fbbc8..e2bdcc351 100644 --- a/py/qstr.h +++ b/py/qstr.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_QSTR_H__ -#define __MICROPY_INCLUDED_PY_QSTR_H__ +#ifndef MICROPY_INCLUDED_PY_QSTR_H +#define MICROPY_INCLUDED_PY_QSTR_H #include "py/mpconfig.h" #include "py/misc.h" @@ -76,4 +76,4 @@ const byte *qstr_data(qstr q, size_t *len); void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, size_t *n_total_bytes); void qstr_dump_data(void); -#endif // __MICROPY_INCLUDED_PY_QSTR_H__ +#endif // MICROPY_INCLUDED_PY_QSTR_H diff --git a/py/qstrdefs.h b/py/qstrdefs.h index 4581e5e1b..9375b9101 100644 --- a/py/qstrdefs.h +++ b/py/qstrdefs.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/reader.c b/py/reader.c index 5df45c495..c4d18d53d 100644 --- a/py/reader.c +++ b/py/reader.c @@ -71,7 +71,6 @@ void mp_reader_new_mem(mp_reader_t *reader, const byte *buf, size_t len, size_t #include #include #include -#include typedef struct _mp_reader_posix_t { bool close_fd; diff --git a/py/repl.c b/py/repl.c index 8e55eb017..7e8922e19 100644 --- a/py/repl.c +++ b/py/repl.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/repl.h b/py/repl.h index 048b0de0f..a7a4136ca 100644 --- a/py/repl.h +++ b/py/repl.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_REPL_H__ -#define __MICROPY_INCLUDED_PY_REPL_H__ +#ifndef MICROPY_INCLUDED_PY_REPL_H +#define MICROPY_INCLUDED_PY_REPL_H #include "py/mpconfig.h" #include "py/misc.h" @@ -35,4 +35,4 @@ bool mp_repl_continue_with_input(const char *input); size_t mp_repl_autocomplete(const char *str, size_t len, const mp_print_t *print, const char **compl_str); #endif -#endif // __MICROPY_INCLUDED_PY_REPL_H__ +#endif // MICROPY_INCLUDED_PY_REPL_H diff --git a/py/ringbuf.h b/py/ringbuf.h index 5e108afad..b41692706 100644 --- a/py/ringbuf.h +++ b/py/ringbuf.h @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_RINGBUF_H__ -#define __MICROPY_INCLUDED_PY_RINGBUF_H__ +#ifndef MICROPY_INCLUDED_PY_RINGBUF_H +#define MICROPY_INCLUDED_PY_RINGBUF_H typedef struct _ringbuf_t { uint8_t *buf; @@ -69,4 +69,4 @@ static inline int ringbuf_put(ringbuf_t *r, uint8_t v) { return 0; } -#endif // __MICROPY_INCLUDED_PY_RINGBUF_H__ +#endif // MICROPY_INCLUDED_PY_RINGBUF_H diff --git a/py/runtime.c b/py/runtime.c index a8a1f73fa..eb1298813 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -44,7 +44,7 @@ #include "py/stackctrl.h" #include "py/gc.h" -#if 0 // print debugging info +#if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_PRINT (1) #define DEBUG_printf DEBUG_printf #define DEBUG_OP_printf(...) DEBUG_printf(__VA_ARGS__) @@ -127,7 +127,7 @@ void mp_deinit(void) { //mp_obj_dict_free(&dict_main); //mp_map_deinit(&MP_STATE_VM(mp_loaded_modules_map)); - // call port specific deinitialization if any + // call port specific deinitialization if any #ifdef MICROPY_PORT_INIT_FUNC MICROPY_PORT_DEINIT_FUNC; #endif @@ -1038,7 +1038,7 @@ void mp_load_method_maybe(mp_obj_t obj, qstr attr, mp_obj_t *dest) { } else if (type->locals_dict != NULL) { // generic method lookup // this is a lookup in the object (ie not class or type) - assert(type->locals_dict->base.type == &mp_type_dict); // Micro Python restriction, for now + assert(type->locals_dict->base.type == &mp_type_dict); // MicroPython restriction, for now mp_map_t *locals_map = &type->locals_dict->map; mp_map_elem_t *elem = mp_map_lookup(locals_map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP); if (elem != NULL) { @@ -1439,6 +1439,6 @@ NORETURN void mp_raise_OSError(int errno_) { nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno_))); } -NORETURN void mp_not_implemented(const char *msg) { +NORETURN void mp_raise_NotImplementedError(const char *msg) { mp_raise_msg(&mp_type_NotImplementedError, msg); } diff --git a/py/runtime.h b/py/runtime.h index d75d23ff1..428e2571c 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_RUNTIME_H__ -#define __MICROPY_INCLUDED_PY_RUNTIME_H__ +#ifndef MICROPY_INCLUDED_PY_RUNTIME_H +#define MICROPY_INCLUDED_PY_RUNTIME_H #include "py/mpstate.h" #include "py/obj.h" @@ -149,8 +149,8 @@ NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg); //NORETURN void nlr_raise_msg_varg(const mp_obj_type_t *exc_type, const char *fmt, ...); NORETURN void mp_raise_ValueError(const char *msg); NORETURN void mp_raise_TypeError(const char *msg); +NORETURN void mp_raise_NotImplementedError(const char *msg); NORETURN void mp_raise_OSError(int errno_); -NORETURN void mp_not_implemented(const char *msg); // Raise NotImplementedError with given message NORETURN void mp_exc_recursion_depth(void); #if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG @@ -178,4 +178,4 @@ void mp_warning(const char *msg, ...); #define mp_warning(msg, ...) #endif -#endif // __MICROPY_INCLUDED_PY_RUNTIME_H__ +#endif // MICROPY_INCLUDED_PY_RUNTIME_H diff --git a/py/runtime0.h b/py/runtime0.h index 720fe6a23..703c950f2 100644 --- a/py/runtime0.h +++ b/py/runtime0.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_RUNTIME0_H__ -#define __MICROPY_INCLUDED_PY_RUNTIME0_H__ +#ifndef MICROPY_INCLUDED_PY_RUNTIME0_H +#define MICROPY_INCLUDED_PY_RUNTIME0_H // These must fit in 8 bits; see scope.h #define MP_SCOPE_FLAG_VARARGS (0x01) @@ -50,6 +50,7 @@ typedef enum { MP_UNARY_OP_NEGATIVE, MP_UNARY_OP_INVERT, MP_UNARY_OP_NOT, + MP_UNARY_OP_SIZEOF, // for sys.getsizeof() } mp_unary_op_t; typedef enum { @@ -151,4 +152,4 @@ typedef enum { extern void *const mp_fun_table[MP_F_NUMBER_OF]; -#endif // __MICROPY_INCLUDED_PY_RUNTIME0_H__ +#endif // MICROPY_INCLUDED_PY_RUNTIME0_H diff --git a/py/runtime_utils.c b/py/runtime_utils.c index e0495495a..56a918064 100644 --- a/py/runtime_utils.c +++ b/py/runtime_utils.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/scope.c b/py/scope.c index 8fe6f960a..1a6ae7b8a 100644 --- a/py/scope.c +++ b/py/scope.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/scope.h b/py/scope.h index 826064d7e..e3b6a57c7 100644 --- a/py/scope.h +++ b/py/scope.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_SCOPE_H__ -#define __MICROPY_INCLUDED_PY_SCOPE_H__ +#ifndef MICROPY_INCLUDED_PY_SCOPE_H +#define MICROPY_INCLUDED_PY_SCOPE_H #include "py/parse.h" #include "py/emitglue.h" @@ -94,4 +94,4 @@ id_info_t *scope_find(scope_t *scope, qstr qstr); id_info_t *scope_find_global(scope_t *scope, qstr qstr); void scope_find_local_and_close_over(scope_t *scope, id_info_t *id, qstr qst); -#endif // __MICROPY_INCLUDED_PY_SCOPE_H__ +#endif // MICROPY_INCLUDED_PY_SCOPE_H diff --git a/py/sequence.c b/py/sequence.c index 32db640dc..0752ee109 100644 --- a/py/sequence.c +++ b/py/sequence.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/showbc.c b/py/showbc.c index 0bccf8427..bb2b084ed 100644 --- a/py/showbc.c +++ b/py/showbc.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/smallint.c b/py/smallint.c index 4c42ee0cc..aa542ca7b 100644 --- a/py/smallint.c +++ b/py/smallint.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/smallint.h b/py/smallint.h index b9686be30..42679a78f 100644 --- a/py/smallint.h +++ b/py/smallint.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_SMALLINT_H__ -#define __MICROPY_INCLUDED_PY_SMALLINT_H__ +#ifndef MICROPY_INCLUDED_PY_SMALLINT_H +#define MICROPY_INCLUDED_PY_SMALLINT_H #include "py/mpconfig.h" #include "py/misc.h" @@ -65,4 +65,4 @@ bool mp_small_int_mul_overflow(mp_int_t x, mp_int_t y); mp_int_t mp_small_int_modulo(mp_int_t dividend, mp_int_t divisor); mp_int_t mp_small_int_floor_divide(mp_int_t num, mp_int_t denom); -#endif // __MICROPY_INCLUDED_PY_SMALLINT_H__ +#endif // MICROPY_INCLUDED_PY_SMALLINT_H diff --git a/py/stackctrl.c b/py/stackctrl.c index 1843e7339..0bcd82f4f 100644 --- a/py/stackctrl.c +++ b/py/stackctrl.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/stackctrl.h b/py/stackctrl.h index e915f5000..ff8da0ab1 100644 --- a/py/stackctrl.h +++ b/py/stackctrl.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_STACKCTRL_H__ -#define __MICROPY_INCLUDED_PY_STACKCTRL_H__ +#ifndef MICROPY_INCLUDED_PY_STACKCTRL_H +#define MICROPY_INCLUDED_PY_STACKCTRL_H #include "py/mpconfig.h" @@ -45,4 +45,4 @@ void mp_stack_check(void); #endif -#endif // __MICROPY_INCLUDED_PY_STACKCTRL_H__ +#endif // MICROPY_INCLUDED_PY_STACKCTRL_H diff --git a/py/stream.c b/py/stream.c index 018609903..5d1868153 100644 --- a/py/stream.c +++ b/py/stream.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/stream.h b/py/stream.h index 01199ab60..401ae313c 100644 --- a/py/stream.h +++ b/py/stream.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_STREAM_H__ -#define __MICROPY_INCLUDED_PY_STREAM_H__ +#ifndef MICROPY_INCLUDED_PY_STREAM_H +#define MICROPY_INCLUDED_PY_STREAM_H #include "py/obj.h" #include "py/mperrno.h" @@ -103,4 +103,4 @@ int mp_stream_posix_fsync(mp_obj_t stream); #define mp_is_nonblocking_error(errno) (0) #endif -#endif // __MICROPY_INCLUDED_PY_STREAM_H__ +#endif // MICROPY_INCLUDED_PY_STREAM_H diff --git a/py/unicode.c b/py/unicode.c index c6f872038..eddb007d5 100644 --- a/py/unicode.c +++ b/py/unicode.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/unicode.h b/py/unicode.h index 89c28ed0e..19487a65a 100644 --- a/py/unicode.h +++ b/py/unicode.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,12 +23,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_PY_UNICODE_H__ -#define __MICROPY_INCLUDED_PY_UNICODE_H__ +#ifndef MICROPY_INCLUDED_PY_UNICODE_H +#define MICROPY_INCLUDED_PY_UNICODE_H #include "py/mpconfig.h" #include "py/misc.h" mp_uint_t utf8_ptr_to_index(const byte *s, const byte *ptr); -#endif // __MICROPY_INCLUDED_PY_UNICODE_H__ +#endif // MICROPY_INCLUDED_PY_UNICODE_H diff --git a/py/vm.c b/py/vm.c index 7451d53b9..c7fc83d04 100644 --- a/py/vm.c +++ b/py/vm.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -162,9 +162,13 @@ mp_vm_return_kind_t mp_execute_bytecode(mp_code_state_t *code_state, volatile mp run_code_state: ; #endif // Pointers which are constant for particular invocation of mp_execute_bytecode() - size_t n_state = mp_decode_uint_value(code_state->fun_bc->bytecode); - mp_obj_t * /*const*/ fastn = &code_state->state[n_state - 1]; - mp_exc_stack_t * /*const*/ exc_stack = (mp_exc_stack_t*)(code_state->state + n_state); + mp_obj_t * /*const*/ fastn; + mp_exc_stack_t * /*const*/ exc_stack; + { + size_t n_state = mp_decode_uint_value(code_state->fun_bc->bytecode); + fastn = &code_state->state[n_state - 1]; + exc_stack = (mp_exc_stack_t*)(code_state->state + n_state); + } // variables that are visible to the exception handler (declared volatile) volatile bool currently_in_except_block = MP_TAGPTR_TAG0(code_state->exc_sp); // 0 or 1, to detect nested exceptions diff --git a/py/vmentrytable.h b/py/vmentrytable.h index dd9789e34..352a6dc31 100644 --- a/py/vmentrytable.h +++ b/py/vmentrytable.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/vstr.c b/py/vstr.c index f41bd2e23..8a00f6c6f 100644 --- a/py/vstr.c +++ b/py/vstr.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/py/warning.c b/py/warning.c index 4cdf3b3f1..46b31ecca 100644 --- a/py/warning.c +++ b/py/warning.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/qemu-arm/Makefile b/qemu-arm/Makefile index 743b6683a..71403cb5e 100644 --- a/qemu-arm/Makefile +++ b/qemu-arm/Makefile @@ -5,14 +5,14 @@ include ../py/mkenv.mk QSTR_DEFS = qstrdefsport.h # include py core make definitions -include ../py/py.mk +include $(TOP)/py/py.mk CROSS_COMPILE = arm-none-eabi- INC += -I. -INC += -I.. +INC += -I$(TOP) INC += -I$(BUILD) -INC += -I../tools/tinytest/ +INC += -I$(TOP)/tools/tinytest/ CFLAGS_CORTEX_M3 = -mthumb -mcpu=cortex-m3 -mfloat-abi=soft CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -std=gnu99 $(CFLAGS_CORTEX_M3) $(COPT) \ @@ -98,10 +98,10 @@ test: $(BUILD)/firmware-test.elf $(BUILD)/test_main.o: $(BUILD)/genhdr/tests.h $(BUILD)/genhdr/tests.h: - $(Q)echo "Generating $@";(cd ../tests; ../tools/tinytest-codegen.py) > $@ + $(Q)echo "Generating $@";(cd $(TOP)/tests; ../tools/tinytest-codegen.py) > $@ $(BUILD)/tinytest.o: - $(Q)$(CC) $(CFLAGS) -DNO_FORKING -o $@ -c ../tools/tinytest/tinytest.c + $(Q)$(CC) $(CFLAGS) -DNO_FORKING -o $@ -c $(TOP)/tools/tinytest/tinytest.c ## `$(LD)` doesn't seem to like `--specs` for some reason, but we can just use `$(CC)` here. $(BUILD)/firmware.elf: $(OBJ_COMMON) $(OBJ_RUN) @@ -112,4 +112,4 @@ $(BUILD)/firmware-test.elf: $(OBJ_COMMON) $(OBJ_TEST) $(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) $(Q)$(SIZE) $@ -include ../py/mkrules.mk +include $(TOP)/py/mkrules.mk diff --git a/qemu-arm/mpconfigport.h b/qemu-arm/mpconfigport.h index ebec027e8..87e537af7 100644 --- a/qemu-arm/mpconfigport.h +++ b/qemu-arm/mpconfigport.h @@ -1,6 +1,6 @@ #include -// options to control how Micro Python is built +// options to control how MicroPython is built #define MICROPY_ALLOC_PATH_MAX (512) #define MICROPY_EMIT_X64 (0) diff --git a/share/fonts/Lat2-Terminus12x6.inc b/share/fonts/Lat2-Terminus12x6.inc new file mode 100644 index 000000000..577ca1aa0 --- /dev/null +++ b/share/fonts/Lat2-Terminus12x6.inc @@ -0,0 +1,833 @@ +// Copying and distribution of this file, with or without modification, +// are permitted in any medium without royalty provided the copyright +// notice and this notice are preserved. This file is offered as-is, +// without any warranty. + + 0x72, 0xb5, 0x4a, 0x86, /* Magic */ + 0x00, 0x00, 0x00, 0x00, /* Version */ + 0x20, 0x00, 0x00, 0x00, /* Header size */ + 0x01, 0x00, 0x00, 0x00, /* Flags */ + 0x00, 0x01, 0x00, 0x00, /* No. of chars */ + 0x0c, 0x00, 0x00, 0x00, /* Char length */ + 0x0c, 0x00, 0x00, 0x00, /* Char width */ + 0x06, 0x00, 0x00, 0x00, /* Char height */ + 0x00, 0x00, 0x00, 0x48, 0x30, 0x48, 0x48, 0x30, + 0x48, 0x00, 0x00, 0x00, /* 0 */ + 0x00, 0x00, 0x20, 0x20, 0x20, 0x00, 0x00, 0x20, + 0x20, 0x20, 0x00, 0x00, /* 1 */ + 0x50, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 2 */ + 0x00, 0x00, 0x78, 0x84, 0xb4, 0xa4, 0xa4, 0xb4, + 0x84, 0x78, 0x00, 0x00, /* 3 */ + 0x00, 0x00, 0x00, 0x20, 0x70, 0xf8, 0x70, 0x20, + 0x00, 0x00, 0x00, 0x00, /* 4 */ + 0x00, 0x00, 0x78, 0x84, 0xb4, 0xac, 0xb4, 0xac, + 0x84, 0x78, 0x00, 0x00, /* 5 */ + 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 6 */ + 0x00, 0x00, 0x00, 0x00, 0x30, 0x78, 0x78, 0x30, + 0x00, 0x00, 0x00, 0x00, /* 7 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x20, 0x20, 0x40, /* 8 */ + 0x10, 0x20, 0x70, 0x88, 0x88, 0x88, 0xf8, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 9 */ + 0x20, 0x50, 0x70, 0x88, 0x88, 0x88, 0xf8, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 10 */ + 0x50, 0x50, 0xf8, 0x80, 0x80, 0xf0, 0x80, 0x80, + 0x80, 0xf8, 0x00, 0x00, /* 11 */ + 0x10, 0x20, 0x70, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x70, 0x00, 0x00, /* 12 */ + 0x20, 0x50, 0x70, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x70, 0x00, 0x00, /* 13 */ + 0x10, 0x20, 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 14 */ + 0x20, 0x50, 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 15 */ + 0x00, 0x00, 0x00, 0x00, 0x88, 0x50, 0x20, 0x50, + 0x88, 0x00, 0x00, 0x00, /* 16 */ + 0x10, 0x20, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 17 */ + 0x10, 0x20, 0x88, 0x88, 0x50, 0x50, 0x20, 0x20, + 0x20, 0x20, 0x00, 0x00, /* 18 */ + 0x00, 0x00, 0x10, 0x20, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x78, 0x08, 0x70, /* 19 */ + 0x00, 0x00, 0x78, 0xa8, 0xa8, 0xa8, 0x68, 0x28, + 0x28, 0x28, 0x00, 0x00, /* 20 */ + 0x00, 0x30, 0x48, 0x20, 0x50, 0x48, 0x28, 0x10, + 0x48, 0x30, 0x00, 0x00, /* 21 */ + 0x50, 0x20, 0x70, 0x88, 0x88, 0x88, 0xf8, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 22 */ + 0x00, 0x00, 0x50, 0x20, 0x70, 0x08, 0x78, 0x88, + 0x88, 0x78, 0x00, 0x00, /* 23 */ + 0x00, 0x00, 0x20, 0x70, 0xf8, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x00, 0x00, /* 24 */ + 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0xf8, + 0x70, 0x20, 0x00, 0x00, /* 25 */ + 0x00, 0x00, 0x00, 0x10, 0x18, 0xfc, 0x18, 0x10, + 0x00, 0x00, 0x00, 0x00, /* 26 */ + 0x00, 0x00, 0x00, 0x20, 0x60, 0xfc, 0x60, 0x20, + 0x00, 0x00, 0x00, 0x00, /* 27 */ + 0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0xf8, 0x88, + 0x88, 0x88, 0x10, 0x0c, /* 28 */ + 0x00, 0x00, 0x00, 0x00, 0x70, 0x08, 0x78, 0x88, + 0x88, 0x78, 0x10, 0x0c, /* 29 */ + 0x10, 0x20, 0x70, 0x88, 0x80, 0x80, 0x80, 0x80, + 0x88, 0x70, 0x00, 0x00, /* 30 */ + 0x00, 0x00, 0x10, 0x20, 0x70, 0x88, 0x80, 0x80, + 0x88, 0x70, 0x00, 0x00, /* 31 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 32 */ + 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x20, 0x20, 0x00, 0x00, /* 33 */ + 0x00, 0x50, 0x50, 0x50, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 34 */ + 0x00, 0x00, 0x50, 0x50, 0xf8, 0x50, 0x50, 0xf8, + 0x50, 0x50, 0x00, 0x00, /* 35 */ + 0x00, 0x00, 0x20, 0x70, 0xa8, 0xa0, 0x70, 0x28, + 0xa8, 0x70, 0x20, 0x00, /* 36 */ + 0x00, 0x00, 0x48, 0xa8, 0x50, 0x10, 0x20, 0x28, + 0x54, 0x48, 0x00, 0x00, /* 37 */ + 0x00, 0x00, 0x20, 0x50, 0x50, 0x20, 0x68, 0x90, + 0x90, 0x68, 0x00, 0x00, /* 38 */ + 0x00, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 39 */ + 0x00, 0x00, 0x10, 0x20, 0x40, 0x40, 0x40, 0x40, + 0x20, 0x10, 0x00, 0x00, /* 40 */ + 0x00, 0x00, 0x40, 0x20, 0x10, 0x10, 0x10, 0x10, + 0x20, 0x40, 0x00, 0x00, /* 41 */ + 0x00, 0x00, 0x00, 0x00, 0x50, 0x20, 0xf8, 0x20, + 0x50, 0x00, 0x00, 0x00, /* 42 */ + 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0xf8, 0x20, + 0x20, 0x00, 0x00, 0x00, /* 43 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x20, 0x40, 0x00, /* 44 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 45 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x20, 0x00, 0x00, /* 46 */ + 0x00, 0x00, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, + 0x40, 0x40, 0x00, 0x00, /* 47 */ + 0x00, 0x00, 0x70, 0x88, 0x98, 0xa8, 0xc8, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 48 */ + 0x00, 0x00, 0x20, 0x60, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x70, 0x00, 0x00, /* 49 */ + 0x00, 0x00, 0x70, 0x88, 0x88, 0x10, 0x20, 0x40, + 0x80, 0xf8, 0x00, 0x00, /* 50 */ + 0x00, 0x00, 0x70, 0x88, 0x08, 0x30, 0x08, 0x08, + 0x88, 0x70, 0x00, 0x00, /* 51 */ + 0x00, 0x00, 0x08, 0x18, 0x28, 0x48, 0x88, 0xf8, + 0x08, 0x08, 0x00, 0x00, /* 52 */ + 0x00, 0x00, 0xf8, 0x80, 0x80, 0xf0, 0x08, 0x08, + 0x88, 0x70, 0x00, 0x00, /* 53 */ + 0x00, 0x00, 0x70, 0x80, 0x80, 0xf0, 0x88, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 54 */ + 0x00, 0x00, 0xf8, 0x08, 0x08, 0x10, 0x10, 0x20, + 0x20, 0x20, 0x00, 0x00, /* 55 */ + 0x00, 0x00, 0x70, 0x88, 0x88, 0x70, 0x88, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 56 */ + 0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0x78, 0x08, + 0x08, 0x70, 0x00, 0x00, /* 57 */ + 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x00, 0x00, + 0x20, 0x20, 0x00, 0x00, /* 58 */ + 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x00, 0x00, + 0x20, 0x20, 0x40, 0x00, /* 59 */ + 0x00, 0x00, 0x00, 0x08, 0x10, 0x20, 0x40, 0x20, + 0x10, 0x08, 0x00, 0x00, /* 60 */ + 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0xf8, + 0x00, 0x00, 0x00, 0x00, /* 61 */ + 0x00, 0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x10, + 0x20, 0x40, 0x00, 0x00, /* 62 */ + 0x00, 0x00, 0x70, 0x88, 0x88, 0x10, 0x20, 0x00, + 0x20, 0x20, 0x00, 0x00, /* 63 */ + 0x00, 0x00, 0x70, 0x88, 0x98, 0xa8, 0xa8, 0x98, + 0x80, 0x78, 0x00, 0x00, /* 64 */ + 0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0xf8, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 65 */ + 0x00, 0x00, 0xf0, 0x88, 0x88, 0xf0, 0x88, 0x88, + 0x88, 0xf0, 0x00, 0x00, /* 66 */ + 0x00, 0x00, 0x70, 0x88, 0x80, 0x80, 0x80, 0x80, + 0x88, 0x70, 0x00, 0x00, /* 67 */ + 0x00, 0x00, 0xe0, 0x90, 0x88, 0x88, 0x88, 0x88, + 0x90, 0xe0, 0x00, 0x00, /* 68 */ + 0x00, 0x00, 0xf8, 0x80, 0x80, 0xf0, 0x80, 0x80, + 0x80, 0xf8, 0x00, 0x00, /* 69 */ + 0x00, 0x00, 0xf8, 0x80, 0x80, 0xf0, 0x80, 0x80, + 0x80, 0x80, 0x00, 0x00, /* 70 */ + 0x00, 0x00, 0x70, 0x88, 0x80, 0x80, 0xb8, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 71 */ + 0x00, 0x00, 0x88, 0x88, 0x88, 0xf8, 0x88, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 72 */ + 0x00, 0x00, 0x70, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x70, 0x00, 0x00, /* 73 */ + 0x00, 0x00, 0x38, 0x10, 0x10, 0x10, 0x10, 0x90, + 0x90, 0x60, 0x00, 0x00, /* 74 */ + 0x00, 0x00, 0x88, 0x90, 0xa0, 0xc0, 0xc0, 0xa0, + 0x90, 0x88, 0x00, 0x00, /* 75 */ + 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0xf8, 0x00, 0x00, /* 76 */ + 0x00, 0x00, 0x88, 0xd8, 0xa8, 0xa8, 0x88, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 77 */ + 0x00, 0x00, 0x88, 0x88, 0xc8, 0xa8, 0x98, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 78 */ + 0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 79 */ + 0x00, 0x00, 0xf0, 0x88, 0x88, 0x88, 0xf0, 0x80, + 0x80, 0x80, 0x00, 0x00, /* 80 */ + 0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, + 0xa8, 0x70, 0x08, 0x00, /* 81 */ + 0x00, 0x00, 0xf0, 0x88, 0x88, 0x88, 0xf0, 0xa0, + 0x90, 0x88, 0x00, 0x00, /* 82 */ + 0x00, 0x00, 0x70, 0x88, 0x80, 0x70, 0x08, 0x08, + 0x88, 0x70, 0x00, 0x00, /* 83 */ + 0x00, 0x00, 0xf8, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x00, 0x00, /* 84 */ + 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 85 */ + 0x00, 0x00, 0x88, 0x88, 0x88, 0x50, 0x50, 0x50, + 0x20, 0x20, 0x00, 0x00, /* 86 */ + 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0xa8, 0xa8, + 0xd8, 0x88, 0x00, 0x00, /* 87 */ + 0x00, 0x00, 0x88, 0x88, 0x50, 0x20, 0x20, 0x50, + 0x88, 0x88, 0x00, 0x00, /* 88 */ + 0x00, 0x00, 0x88, 0x88, 0x50, 0x50, 0x20, 0x20, + 0x20, 0x20, 0x00, 0x00, /* 89 */ + 0x00, 0x00, 0xf8, 0x08, 0x10, 0x20, 0x40, 0x80, + 0x80, 0xf8, 0x00, 0x00, /* 90 */ + 0x00, 0x00, 0x70, 0x40, 0x40, 0x40, 0x40, 0x40, + 0x40, 0x70, 0x00, 0x00, /* 91 */ + 0x00, 0x00, 0x40, 0x40, 0x20, 0x20, 0x10, 0x10, + 0x08, 0x08, 0x00, 0x00, /* 92 */ + 0x00, 0x00, 0x70, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x70, 0x00, 0x00, /* 93 */ + 0x00, 0x20, 0x50, 0x88, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 94 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xf8, 0x00, /* 95 */ + 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 96 */ + 0x00, 0x00, 0x00, 0x00, 0x70, 0x08, 0x78, 0x88, + 0x88, 0x78, 0x00, 0x00, /* 97 */ + 0x00, 0x00, 0x80, 0x80, 0xf0, 0x88, 0x88, 0x88, + 0x88, 0xf0, 0x00, 0x00, /* 98 */ + 0x00, 0x00, 0x00, 0x00, 0x70, 0x88, 0x80, 0x80, + 0x88, 0x70, 0x00, 0x00, /* 99 */ + 0x00, 0x00, 0x08, 0x08, 0x78, 0x88, 0x88, 0x88, + 0x88, 0x78, 0x00, 0x00, /* 100 */ + 0x00, 0x00, 0x00, 0x00, 0x70, 0x88, 0xf8, 0x80, + 0x88, 0x70, 0x00, 0x00, /* 101 */ + 0x00, 0x00, 0x18, 0x20, 0x70, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x00, 0x00, /* 102 */ + 0x00, 0x00, 0x00, 0x00, 0x78, 0x88, 0x88, 0x88, + 0x88, 0x78, 0x08, 0x70, /* 103 */ + 0x00, 0x00, 0x80, 0x80, 0xf0, 0x88, 0x88, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 104 */ + 0x00, 0x20, 0x20, 0x00, 0x60, 0x20, 0x20, 0x20, + 0x20, 0x70, 0x00, 0x00, /* 105 */ + 0x00, 0x08, 0x08, 0x00, 0x18, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x48, 0x30, /* 106 */ + 0x00, 0x00, 0x40, 0x40, 0x48, 0x50, 0x60, 0x60, + 0x50, 0x48, 0x00, 0x00, /* 107 */ + 0x00, 0x00, 0x60, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x70, 0x00, 0x00, /* 108 */ + 0x00, 0x00, 0x00, 0x00, 0xf0, 0xa8, 0xa8, 0xa8, + 0xa8, 0xa8, 0x00, 0x00, /* 109 */ + 0x00, 0x00, 0x00, 0x00, 0xf0, 0x88, 0x88, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 110 */ + 0x00, 0x00, 0x00, 0x00, 0x70, 0x88, 0x88, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 111 */ + 0x00, 0x00, 0x00, 0x00, 0xf0, 0x88, 0x88, 0x88, + 0x88, 0xf0, 0x80, 0x80, /* 112 */ + 0x00, 0x00, 0x00, 0x00, 0x78, 0x88, 0x88, 0x88, + 0x88, 0x78, 0x08, 0x08, /* 113 */ + 0x00, 0x00, 0x00, 0x00, 0xb8, 0xc0, 0x80, 0x80, + 0x80, 0x80, 0x00, 0x00, /* 114 */ + 0x00, 0x00, 0x00, 0x00, 0x78, 0x80, 0x70, 0x08, + 0x08, 0xf0, 0x00, 0x00, /* 115 */ + 0x00, 0x00, 0x20, 0x20, 0x70, 0x20, 0x20, 0x20, + 0x20, 0x18, 0x00, 0x00, /* 116 */ + 0x00, 0x00, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x78, 0x00, 0x00, /* 117 */ + 0x00, 0x00, 0x00, 0x00, 0x88, 0x88, 0x50, 0x50, + 0x20, 0x20, 0x00, 0x00, /* 118 */ + 0x00, 0x00, 0x00, 0x00, 0x88, 0x88, 0xa8, 0xa8, + 0xa8, 0x70, 0x00, 0x00, /* 119 */ + 0x00, 0x00, 0x00, 0x00, 0x88, 0x50, 0x20, 0x20, + 0x50, 0x88, 0x00, 0x00, /* 120 */ + 0x00, 0x00, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x78, 0x08, 0x70, /* 121 */ + 0x00, 0x00, 0x00, 0x00, 0xf8, 0x10, 0x20, 0x40, + 0x80, 0xf8, 0x00, 0x00, /* 122 */ + 0x00, 0x00, 0x18, 0x20, 0x20, 0x40, 0x20, 0x20, + 0x20, 0x18, 0x00, 0x00, /* 123 */ + 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x00, 0x00, /* 124 */ + 0x00, 0x00, 0x60, 0x10, 0x10, 0x08, 0x10, 0x10, + 0x10, 0x60, 0x00, 0x00, /* 125 */ + 0x00, 0x48, 0xa8, 0x90, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 126 */ + 0x50, 0x20, 0x70, 0x88, 0x80, 0x80, 0x80, 0x80, + 0x88, 0x70, 0x00, 0x00, /* 127 */ + 0x00, 0x00, 0x70, 0x88, 0x80, 0x80, 0x80, 0x80, + 0x88, 0x70, 0x20, 0x40, /* 128 */ + 0x00, 0x00, 0x50, 0x50, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x78, 0x00, 0x00, /* 129 */ + 0x00, 0x00, 0x10, 0x20, 0x70, 0x88, 0xf8, 0x80, + 0x88, 0x70, 0x00, 0x00, /* 130 */ + 0x00, 0x00, 0x20, 0x50, 0x70, 0x08, 0x78, 0x88, + 0x88, 0x78, 0x00, 0x00, /* 131 */ + 0x00, 0x00, 0x50, 0x50, 0x70, 0x08, 0x78, 0x88, + 0x88, 0x78, 0x00, 0x00, /* 132 */ + 0x00, 0x00, 0x40, 0x20, 0x70, 0x08, 0x78, 0x88, + 0x88, 0x78, 0x00, 0x00, /* 133 */ + 0x00, 0x00, 0x50, 0x20, 0x70, 0x88, 0x80, 0x80, + 0x88, 0x70, 0x00, 0x00, /* 134 */ + 0x00, 0x00, 0x00, 0x00, 0x70, 0x88, 0x80, 0x80, + 0x88, 0x70, 0x20, 0x40, /* 135 */ + 0x50, 0x20, 0x70, 0x48, 0x44, 0x44, 0x44, 0x44, + 0x48, 0x70, 0x00, 0x00, /* 136 */ + 0x00, 0x00, 0x50, 0x50, 0x70, 0x88, 0xf8, 0x80, + 0x88, 0x70, 0x00, 0x00, /* 137 */ + 0x00, 0x00, 0x40, 0x20, 0x70, 0x88, 0xf8, 0x80, + 0x88, 0x70, 0x00, 0x00, /* 138 */ + 0x50, 0x20, 0x08, 0x08, 0x78, 0x88, 0x88, 0x88, + 0x88, 0x78, 0x00, 0x00, /* 139 */ + 0x00, 0x00, 0x20, 0x50, 0x60, 0x20, 0x20, 0x20, + 0x20, 0x70, 0x00, 0x00, /* 140 */ + 0x00, 0x00, 0x60, 0x50, 0x48, 0xe8, 0x48, 0x48, + 0x50, 0x60, 0x00, 0x00, /* 141 */ + 0x50, 0x50, 0x70, 0x88, 0x88, 0x88, 0xf8, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 142 */ + 0x00, 0x00, 0x08, 0x3c, 0x08, 0x78, 0x88, 0x88, + 0x88, 0x78, 0x00, 0x00, /* 143 */ + 0x10, 0x20, 0xf8, 0x80, 0x80, 0xf0, 0x80, 0x80, + 0x80, 0xf8, 0x00, 0x00, /* 144 */ + 0x00, 0x00, 0xf8, 0x80, 0x80, 0xf0, 0x80, 0x80, + 0x80, 0xf8, 0x10, 0x0c, /* 145 */ + 0x00, 0x00, 0x00, 0x00, 0x70, 0x88, 0xf8, 0x80, + 0x88, 0x70, 0x20, 0x18, /* 146 */ + 0x00, 0x00, 0x20, 0x50, 0x70, 0x88, 0x88, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 147 */ + 0x00, 0x00, 0x50, 0x50, 0x70, 0x88, 0x88, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 148 */ + 0x50, 0x20, 0xf8, 0x80, 0x80, 0xf0, 0x80, 0x80, + 0x80, 0xf8, 0x00, 0x00, /* 149 */ + 0x00, 0x00, 0x50, 0x20, 0x70, 0x88, 0xf8, 0x80, + 0x88, 0x70, 0x00, 0x00, /* 150 */ + 0x20, 0x40, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0xf8, 0x00, 0x00, /* 151 */ + 0x10, 0x20, 0x60, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x70, 0x00, 0x00, /* 152 */ + 0x50, 0x50, 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 153 */ + 0x50, 0x50, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 154 */ + 0x50, 0x20, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0xf8, 0x00, 0x00, /* 155 */ + 0x00, 0x00, 0x30, 0x48, 0x40, 0xf0, 0x40, 0x40, + 0x48, 0xf8, 0x00, 0x00, /* 156 */ + 0x50, 0x20, 0x60, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x70, 0x00, 0x00, /* 157 */ + 0x00, 0x00, 0x40, 0x40, 0x40, 0x60, 0xc0, 0x40, + 0x40, 0x7c, 0x00, 0x00, /* 158 */ + 0x00, 0x00, 0x60, 0x20, 0x20, 0x30, 0x60, 0x20, + 0x20, 0x70, 0x00, 0x00, /* 159 */ + 0x00, 0x00, 0x10, 0x20, 0x70, 0x08, 0x78, 0x88, + 0x88, 0x78, 0x00, 0x00, /* 160 */ + 0x00, 0x00, 0x10, 0x20, 0x60, 0x20, 0x20, 0x20, + 0x20, 0x70, 0x00, 0x00, /* 161 */ + 0x00, 0x00, 0x10, 0x20, 0x70, 0x88, 0x88, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 162 */ + 0x00, 0x00, 0x10, 0x20, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x78, 0x00, 0x00, /* 163 */ + 0x00, 0x00, 0x28, 0x50, 0xf0, 0x88, 0x88, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 164 */ + 0x28, 0x50, 0x88, 0x88, 0xc8, 0xa8, 0x98, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 165 */ + 0x10, 0x20, 0x88, 0x88, 0xc8, 0xa8, 0x98, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 166 */ + 0x00, 0x00, 0x10, 0x20, 0xf0, 0x88, 0x88, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 167 */ + 0x00, 0x00, 0x20, 0x20, 0x00, 0x20, 0x40, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 168 */ + 0x50, 0x20, 0x88, 0x88, 0xc8, 0xa8, 0x98, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 169 */ + 0x00, 0x00, 0x00, 0x00, 0xf8, 0x08, 0x08, 0x08, + 0x00, 0x00, 0x00, 0x00, /* 170 */ + 0x00, 0x00, 0x50, 0x20, 0xf0, 0x88, 0x88, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 171 */ + 0x28, 0x50, 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 172 */ + 0x00, 0x00, 0x20, 0x20, 0x00, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x00, 0x00, /* 173 */ + 0x00, 0x00, 0x00, 0x14, 0x28, 0x50, 0xa0, 0x50, + 0x28, 0x14, 0x00, 0x00, /* 174 */ + 0x00, 0x00, 0x00, 0xa0, 0x50, 0x28, 0x14, 0x28, + 0x50, 0xa0, 0x00, 0x00, /* 175 */ + 0x90, 0x24, 0x90, 0x24, 0x90, 0x24, 0x90, 0x24, + 0x90, 0x24, 0x90, 0x24, /* 176 */ + 0xa8, 0x54, 0xa8, 0x54, 0xa8, 0x54, 0xa8, 0x54, + 0xa8, 0x54, 0xa8, 0x54, /* 177 */ + 0x00, 0x00, 0x28, 0x50, 0x70, 0x88, 0x88, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 178 */ + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, /* 179 */ + 0x20, 0x20, 0x20, 0x20, 0x20, 0xe0, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, /* 180 */ + 0x10, 0x20, 0xf0, 0x88, 0x88, 0x88, 0xf0, 0xa0, + 0x90, 0x88, 0x00, 0x00, /* 181 */ + 0x00, 0x00, 0x10, 0x20, 0xb8, 0xc0, 0x80, 0x80, + 0x80, 0x80, 0x00, 0x00, /* 182 */ + 0x50, 0x20, 0xf0, 0x88, 0x88, 0x88, 0xf0, 0xa0, + 0x90, 0x88, 0x00, 0x00, /* 183 */ + 0x00, 0x00, 0x50, 0x20, 0xb8, 0xc0, 0x80, 0x80, + 0x80, 0x80, 0x00, 0x00, /* 184 */ + 0x10, 0x20, 0x70, 0x88, 0x80, 0x70, 0x08, 0x08, + 0x88, 0x70, 0x00, 0x00, /* 185 */ + 0x00, 0x00, 0x10, 0x20, 0x78, 0x80, 0x70, 0x08, + 0x08, 0xf0, 0x00, 0x00, /* 186 */ + 0x00, 0x00, 0x70, 0x88, 0x80, 0x70, 0x08, 0x08, + 0x88, 0x70, 0x20, 0x40, /* 187 */ + 0x00, 0x00, 0x00, 0x00, 0x78, 0x80, 0x70, 0x08, + 0x08, 0xf0, 0x20, 0x40, /* 188 */ + 0x50, 0x20, 0x70, 0x88, 0x80, 0x70, 0x08, 0x08, + 0x88, 0x70, 0x00, 0x00, /* 189 */ + 0x00, 0x00, 0x50, 0x20, 0x78, 0x80, 0x70, 0x08, + 0x08, 0xf0, 0x00, 0x00, /* 190 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, /* 191 */ + 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 192 */ + 0x20, 0x20, 0x20, 0x20, 0x20, 0xfc, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 193 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, /* 194 */ + 0x20, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, /* 195 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 196 */ + 0x20, 0x20, 0x20, 0x20, 0x20, 0xfc, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, /* 197 */ + 0x00, 0x00, 0xf8, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x30, 0x10, 0x20, /* 198 */ + 0x00, 0x00, 0x20, 0x20, 0x70, 0x20, 0x20, 0x20, + 0x20, 0x18, 0x10, 0x20, /* 199 */ + 0x50, 0x20, 0xf8, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x00, 0x00, /* 200 */ + 0x50, 0x20, 0x20, 0x20, 0x70, 0x20, 0x20, 0x20, + 0x20, 0x18, 0x00, 0x00, /* 201 */ + 0x20, 0x50, 0xa8, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 202 */ + 0x00, 0x00, 0x20, 0x50, 0xa8, 0x88, 0x88, 0x88, + 0x88, 0x78, 0x00, 0x00, /* 203 */ + 0x28, 0x50, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x70, 0x00, 0x00, /* 204 */ + 0x00, 0x00, 0x28, 0x50, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x78, 0x00, 0x00, /* 205 */ + 0x50, 0x50, 0x50, 0x50, 0xdc, 0x00, 0xdc, 0x50, + 0x50, 0x50, 0x50, 0x50, /* 206 */ + 0x10, 0x20, 0xf8, 0x08, 0x10, 0x20, 0x40, 0x80, + 0x80, 0xf8, 0x00, 0x00, /* 207 */ + 0x00, 0x00, 0x10, 0x20, 0xf8, 0x10, 0x20, 0x40, + 0x80, 0xf8, 0x00, 0x00, /* 208 */ + 0x20, 0x20, 0xf8, 0x08, 0x10, 0x20, 0x40, 0x80, + 0x80, 0xf8, 0x00, 0x00, /* 209 */ + 0x00, 0x00, 0x20, 0x20, 0xf8, 0x10, 0x20, 0x40, + 0x80, 0xf8, 0x00, 0x00, /* 210 */ + 0x50, 0x20, 0xf8, 0x08, 0x10, 0x20, 0x40, 0x80, + 0x80, 0xf8, 0x00, 0x00, /* 211 */ + 0x00, 0x00, 0x50, 0x20, 0xf8, 0x10, 0x20, 0x40, + 0x80, 0xf8, 0x00, 0x00, /* 212 */ + 0x00, 0x00, 0x70, 0x88, 0x80, 0x70, 0x08, 0x08, + 0x88, 0x70, 0x20, 0x40, /* 213 */ + 0x00, 0x00, 0x00, 0x00, 0x78, 0x80, 0x70, 0x08, + 0x08, 0xf0, 0x20, 0x40, /* 214 */ + 0x00, 0x00, 0xf8, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x30, 0x10, 0x20, /* 215 */ + 0x20, 0x20, 0x20, 0x20, 0xfc, 0x20, 0xfc, 0x20, + 0x20, 0x20, 0x20, 0x20, /* 216 */ + 0x20, 0x20, 0x20, 0x20, 0x20, 0xe0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 217 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, /* 218 */ + 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, + 0xfc, 0xfc, 0xfc, 0xfc, /* 219 */ + 0x00, 0x00, 0x20, 0x20, 0x70, 0x20, 0x20, 0x20, + 0x20, 0x18, 0x10, 0x20, /* 220 */ + 0x50, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 221 */ + 0x50, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 222 */ + 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 223 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x08, 0x10, 0x0c, /* 224 */ + 0x00, 0x00, 0xe0, 0x90, 0x90, 0xf0, 0x88, 0x88, + 0xc8, 0xb0, 0x00, 0x00, /* 225 */ + 0x28, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 226 */ + 0x00, 0x00, 0x00, 0x00, 0xf8, 0x88, 0x88, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 227 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 228 */ + 0x00, 0x10, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 229 */ + 0x00, 0x00, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, + 0x98, 0xe8, 0x80, 0x80, /* 230 */ + 0x00, 0x20, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 231 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x20, 0x40, 0x00, /* 232 */ + 0x00, 0x28, 0x50, 0x50, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 233 */ + 0x00, 0x50, 0x50, 0xa0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 234 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x50, 0x50, 0xa0, 0x00, /* 235 */ + 0x00, 0x00, 0x20, 0x70, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x00, 0x00, /* 236 */ + 0x00, 0x00, 0x20, 0x70, 0x20, 0x20, 0x20, 0x20, + 0x70, 0x20, 0x00, 0x00, /* 237 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xa8, 0xa8, 0x00, 0x00, /* 238 */ + 0x00, 0x00, 0x44, 0xa8, 0x50, 0x20, 0x40, 0xa8, + 0x54, 0x28, 0x00, 0x00, /* 239 */ + 0x00, 0x00, 0x00, 0x08, 0x10, 0x20, 0x40, 0x20, + 0x10, 0x08, 0x00, 0x00, /* 240 */ + 0x00, 0x00, 0x00, 0x20, 0x20, 0xf8, 0x20, 0x20, + 0x00, 0xf8, 0x00, 0x00, /* 241 */ + 0x00, 0x40, 0x20, 0x10, 0x08, 0x10, 0x20, 0x40, + 0x00, 0xf8, 0x00, 0x00, /* 242 */ + 0x00, 0x10, 0x20, 0x40, 0x80, 0x40, 0x20, 0x10, + 0x00, 0xf8, 0x00, 0x00, /* 243 */ + 0x00, 0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x10, + 0x20, 0x40, 0x00, 0x00, /* 244 */ + 0x00, 0x00, 0x00, 0x38, 0x44, 0xf0, 0x40, 0xf0, + 0x44, 0x38, 0x00, 0x00, /* 245 */ + 0x00, 0x00, 0x00, 0x20, 0x20, 0x00, 0xf8, 0x00, + 0x20, 0x20, 0x00, 0x00, /* 246 */ + 0x00, 0x00, 0x00, 0x00, 0x68, 0xb0, 0x00, 0x68, + 0xb0, 0x00, 0x00, 0x00, /* 247 */ + 0x00, 0x20, 0x50, 0x20, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 248 */ + 0x00, 0x00, 0xf4, 0x5c, 0x54, 0x54, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 249 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 250 */ + 0x00, 0x00, 0x00, 0x08, 0xf8, 0x20, 0x40, 0xf8, + 0x80, 0x00, 0x00, 0x00, /* 251 */ + 0x00, 0x00, 0x94, 0x94, 0xd0, 0xf0, 0xf0, 0xb4, + 0x90, 0x94, 0x00, 0x00, /* 252 */ + 0x40, 0x20, 0x70, 0x88, 0x88, 0x88, 0xf8, 0x88, + 0x88, 0x88, 0x00, 0x00, /* 253 */ + 0x00, 0x00, 0x00, 0x78, 0x78, 0x78, 0x78, 0x78, + 0x00, 0x00, 0x00, 0x00, /* 254 */ + 0x40, 0x20, 0xf8, 0x80, 0x80, 0xf0, 0x80, 0x80, + 0x80, 0xf8, 0x00, 0x00, /* 255 */ + 0xc2, 0xa4, 0xff, + 0xc2, 0xa6, 0xff, + 0xc2, 0xa8, 0xff, + 0xc2, 0xa9, 0xff, + 0xe2, 0x99, 0xa6, 0xe2, 0x97, 0x88, 0xef, + 0xbf, 0xbd, 0xff, + 0xc2, 0xae, 0xff, + 0xc2, 0xb4, 0xff, + 0xe2, 0x80, 0xa2, 0xe2, 0x97, 0x8f, 0xff, + 0xc2, 0xb8, 0xff, + 0xc3, 0x81, 0xff, + 0xc3, 0x82, 0xff, + 0xc3, 0x8b, 0xd0, 0x81, 0xff, + 0xc3, 0x8d, 0xff, + 0xc3, 0x8e, 0xff, + 0xc3, 0x93, 0xff, + 0xc3, 0x94, 0xff, + 0xc3, 0x97, 0xff, + 0xc3, 0x9a, 0xff, + 0xc3, 0x9d, 0xff, + 0xc3, 0xbd, 0xff, + 0xc2, 0xb6, 0xff, + 0xc2, 0xa7, 0xff, + 0xc4, 0x82, 0xd3, 0x90, 0xff, + 0xc4, 0x83, 0xd3, 0x91, 0xff, + 0xe2, 0x86, 0x91, 0xe2, 0x96, 0xb2, 0xe2, + 0x96, 0xb4, 0xff, + 0xe2, 0x86, 0x93, 0xe2, 0x96, 0xbc, 0xe2, + 0x96, 0xbe, 0xff, + 0xe2, 0x86, 0x92, 0xe2, 0x96, 0xb6, 0xe2, + 0x96, 0xb8, 0xff, + 0xe2, 0x86, 0x90, 0xe2, 0x97, 0x80, 0xe2, + 0x97, 0x82, 0xff, + 0xc4, 0x84, 0xff, + 0xc4, 0x85, 0xff, + 0xc4, 0x86, 0xff, + 0xc4, 0x87, 0xff, + 0x20, 0xc2, 0xa0, 0xe2, 0x80, 0x80, 0xe2, + 0x80, 0x81, 0xe2, 0x80, 0x82, 0xe2, 0x80, 0x83, + 0xe2, 0x80, 0x84, 0xe2, 0x80, 0x85, 0xe2, 0x80, + 0x86, 0xe2, 0x80, 0x87, 0xe2, 0x80, 0x88, 0xe2, + 0x80, 0x89, 0xe2, 0x80, 0x8a, 0xff, + 0x21, 0xff, + 0x22, 0xff, + 0x23, 0xff, + 0x24, 0xff, + 0x25, 0xe2, 0x8a, 0x95, 0xff, + 0x26, 0xff, + 0x27, 0xff, + 0x28, 0xff, + 0x29, 0xff, + 0x2a, 0xe2, 0x8a, 0x9b, 0xff, + 0x2b, 0xff, + 0x2c, 0xff, + 0x2d, 0xe2, 0x80, 0x92, 0xe2, 0x80, 0x93, + 0xe2, 0x88, 0x92, 0xc2, 0xad, 0xe2, 0x80, 0x90, + 0xe2, 0x80, 0x91, 0xe2, 0x8a, 0x96, 0xff, + 0x2e, 0xe2, 0x8a, 0x99, 0xff, + 0x2f, 0xe2, 0x8a, 0x98, 0xff, + 0x30, 0xe2, 0x93, 0xaa, 0xff, + 0x31, 0xe2, 0x91, 0xa0, 0xff, + 0x32, 0xe2, 0x91, 0xa1, 0xff, + 0x33, 0xe2, 0x91, 0xa2, 0xff, + 0x34, 0xe2, 0x91, 0xa3, 0xff, + 0x35, 0xe2, 0x91, 0xa4, 0xff, + 0x36, 0xe2, 0x91, 0xa5, 0xff, + 0x37, 0xe2, 0x91, 0xa6, 0xff, + 0x38, 0xe2, 0x91, 0xa7, 0xff, + 0x39, 0xe2, 0x91, 0xa8, 0xff, + 0x3a, 0xff, + 0x3b, 0xff, + 0x3c, 0xff, + 0x3d, 0xe2, 0x8a, 0x9c, 0xff, + 0x3e, 0xff, + 0x3f, 0xff, + 0x40, 0xff, + 0x41, 0xd0, 0x90, 0xce, 0x91, 0xe2, 0x92, + 0xb6, 0xff, + 0x42, 0xd0, 0x92, 0xce, 0x92, 0xe2, 0x92, + 0xb7, 0xff, + 0x43, 0xd0, 0xa1, 0xe2, 0x92, 0xb8, 0xff, + 0x44, 0xe2, 0x92, 0xb9, 0xff, + 0x45, 0xd0, 0x95, 0xce, 0x95, 0xe2, 0x92, + 0xba, 0xff, + 0x46, 0xe2, 0x92, 0xbb, 0xff, + 0x47, 0xe2, 0x92, 0xbc, 0xff, + 0x48, 0xd0, 0x9d, 0xce, 0x97, 0xe2, 0x92, + 0xbd, 0xff, + 0x49, 0xd0, 0x86, 0xce, 0x99, 0xe2, 0x92, + 0xbe, 0xff, + 0x4a, 0xd0, 0x88, 0xe2, 0x92, 0xbf, 0xff, + 0x4b, 0xd0, 0x9a, 0xce, 0x9a, 0xe2, 0x84, + 0xaa, 0xe2, 0x93, 0x80, 0xff, + 0x4c, 0xe2, 0x93, 0x81, 0xff, + 0x4d, 0xd0, 0x9c, 0xce, 0x9c, 0xe2, 0x93, + 0x82, 0xff, + 0x4e, 0xce, 0x9d, 0xe2, 0x93, 0x83, 0xff, + 0x4f, 0xd0, 0x9e, 0xce, 0x9f, 0xe2, 0x93, + 0x84, 0xff, + 0x50, 0xd0, 0xa0, 0xce, 0xa1, 0xe2, 0x93, + 0x85, 0xff, + 0x51, 0xe2, 0x93, 0x86, 0xff, + 0x52, 0xe2, 0x93, 0x87, 0xff, + 0x53, 0xd0, 0x85, 0xe2, 0x93, 0x88, 0xff, + 0x54, 0xd0, 0xa2, 0xce, 0xa4, 0xe2, 0x93, + 0x89, 0xff, + 0x55, 0xe2, 0x93, 0x8a, 0xff, + 0x56, 0xe2, 0x93, 0x8b, 0xff, + 0x57, 0xe2, 0x93, 0x8c, 0xff, + 0x58, 0xd0, 0xa5, 0xce, 0xa7, 0xe2, 0x93, + 0x8d, 0xff, + 0x59, 0xd2, 0xae, 0xe2, 0x93, 0x8e, 0xff, + 0x5a, 0xce, 0x96, 0xe2, 0x93, 0x8f, 0xff, + 0x5b, 0xff, + 0x5c, 0xff, + 0x5d, 0xff, + 0x5e, 0xff, + 0x5f, 0xff, + 0x60, 0xff, + 0x61, 0xd0, 0xb0, 0xe2, 0x93, 0x90, 0xff, + 0x62, 0xe2, 0x93, 0x91, 0xff, + 0x63, 0xd1, 0x81, 0xe2, 0x93, 0x92, 0xff, + 0x64, 0xe2, 0x93, 0x93, 0xff, + 0x65, 0xd0, 0xb5, 0xe2, 0x93, 0x94, 0xff, + 0x66, 0xe2, 0x93, 0x95, 0xff, + 0x67, 0xe2, 0x93, 0x96, 0xff, + 0x68, 0xe2, 0x93, 0x97, 0xff, + 0x69, 0xd1, 0x96, 0xe2, 0x93, 0x98, 0xff, + 0x6a, 0xd1, 0x98, 0xe2, 0x93, 0x99, 0xff, + 0x6b, 0xe2, 0x93, 0x9a, 0xff, + 0x6c, 0xe2, 0x93, 0x9b, 0xff, + 0x6d, 0xe2, 0x93, 0x9c, 0xff, + 0x6e, 0xe2, 0x93, 0x9d, 0xff, + 0x6f, 0xd0, 0xbe, 0xe2, 0x93, 0x9e, 0xff, + 0x70, 0xd1, 0x80, 0xe2, 0x93, 0x9f, 0xff, + 0x71, 0xe2, 0x93, 0xa0, 0xff, + 0x72, 0xe2, 0x93, 0xa1, 0xff, + 0x73, 0xd1, 0x95, 0x73, 0xe2, 0x93, 0xa2, + 0xff, + 0x74, 0xe2, 0x93, 0xa3, 0xff, + 0x75, 0xe2, 0x93, 0xa4, 0xff, + 0x76, 0xe2, 0x93, 0xa5, 0xff, + 0x77, 0xe2, 0x93, 0xa6, 0xff, + 0x78, 0xd1, 0x85, 0xe2, 0x93, 0xa7, 0xff, + 0x79, 0xd1, 0x83, 0xe2, 0x93, 0xa8, 0xff, + 0x7a, 0xe2, 0x93, 0xa9, 0xff, + 0x7b, 0xff, + 0x7c, 0xff, + 0x7d, 0xff, + 0x7e, 0xff, + 0xc4, 0x8c, 0xff, + 0xc3, 0x87, 0xff, + 0xc3, 0xbc, 0xff, + 0xc3, 0xa9, 0xff, + 0xc3, 0xa2, 0xff, + 0xc3, 0xa4, 0xff, + 0xc3, 0xa0, 0xff, + 0xc4, 0x8d, 0xff, + 0xc3, 0xa7, 0xff, + 0xc4, 0x8e, 0xff, + 0xc3, 0xab, 0xd1, 0x91, 0xff, + 0xc3, 0xa8, 0xff, + 0xc4, 0x8f, 0xff, + 0xc3, 0xae, 0xff, + 0xc3, 0x90, 0xc4, 0x90, 0xff, + 0xc3, 0x84, 0xff, + 0xc4, 0x91, 0xff, + 0xc3, 0x89, 0xff, + 0xc4, 0x98, 0xff, + 0xc4, 0x99, 0xff, + 0xc3, 0xb4, 0xff, + 0xc3, 0xb6, 0xff, + 0xc4, 0x9a, 0xff, + 0xc4, 0x9b, 0xff, + 0xc4, 0xb9, 0xff, + 0xc4, 0xba, 0xff, + 0xc3, 0x96, 0xff, + 0xc3, 0x9c, 0xff, + 0xc4, 0xbd, 0xff, + 0xc2, 0xa3, 0xff, + 0xc4, 0xbe, 0xff, + 0xc5, 0x81, 0xff, + 0xc5, 0x82, 0xff, + 0xc3, 0xa1, 0xff, + 0xc3, 0xad, 0xff, + 0xc3, 0xb3, 0xff, + 0xc3, 0xba, 0xff, + 0xc3, 0xb1, 0xff, + 0xc3, 0x91, 0xff, + 0xc5, 0x83, 0xff, + 0xc5, 0x84, 0xff, + 0xc2, 0xbf, 0xff, + 0xc5, 0x87, 0xff, + 0xc2, 0xac, 0xff, + 0xc5, 0x88, 0xff, + 0xc5, 0x90, 0xff, + 0xc2, 0xa1, 0xff, + 0xc2, 0xab, 0xe2, 0x89, 0xaa, 0xff, + 0xc2, 0xbb, 0xe2, 0x89, 0xab, 0xff, + 0xe2, 0x96, 0x91, 0xff, + 0xe2, 0x96, 0x92, 0xff, + 0xc5, 0x91, 0xff, + 0xe2, 0x94, 0x82, 0xe2, 0x94, 0x83, 0xe2, + 0x95, 0xbf, 0xe2, 0x95, 0xbd, 0xe2, 0x95, 0xbb, + 0xe2, 0x95, 0xb7, 0xe2, 0x95, 0xb9, 0xe2, 0x95, + 0xb5, 0xff, + 0xe2, 0x94, 0xa4, 0xe2, 0x94, 0xab, 0xe2, + 0x94, 0xaa, 0xe2, 0x94, 0xa9, 0xe2, 0x94, 0xa8, + 0xe2, 0x94, 0xa7, 0xe2, 0x94, 0xa6, 0xe2, 0x94, + 0xa5, 0xff, + 0xc5, 0x94, 0xff, + 0xc5, 0x95, 0xff, + 0xc5, 0x98, 0xff, + 0xc5, 0x99, 0xff, + 0xc5, 0x9a, 0xff, + 0xc5, 0x9b, 0xff, + 0xc5, 0x9e, 0xff, + 0xc5, 0x9f, 0xff, + 0xc5, 0xa0, 0xff, + 0xc5, 0xa1, 0xff, + 0xe2, 0x94, 0x90, 0xe2, 0x94, 0x93, 0xe2, + 0x94, 0x92, 0xe2, 0x94, 0x91, 0xff, + 0xe2, 0x94, 0x94, 0xe2, 0x94, 0x97, 0xe2, + 0x94, 0x96, 0xe2, 0x94, 0x95, 0xff, + 0xe2, 0x94, 0xb4, 0xe2, 0x94, 0xbb, 0xe2, + 0x94, 0xba, 0xe2, 0x94, 0xb9, 0xe2, 0x94, 0xb8, + 0xe2, 0x94, 0xb7, 0xe2, 0x94, 0xb6, 0xe2, 0x94, + 0xb5, 0xff, + 0xe2, 0x94, 0xac, 0xe2, 0x94, 0xb3, 0xe2, + 0x94, 0xb2, 0xe2, 0x94, 0xb1, 0xe2, 0x94, 0xb0, + 0xe2, 0x94, 0xaf, 0xe2, 0x94, 0xae, 0xe2, 0x94, + 0xad, 0xff, + 0xe2, 0x94, 0x9c, 0xe2, 0x94, 0xa3, 0xe2, + 0x94, 0xa2, 0xe2, 0x94, 0xa1, 0xe2, 0x94, 0xa0, + 0xe2, 0x94, 0x9f, 0xe2, 0x94, 0x9e, 0xe2, 0x94, + 0x9d, 0xff, + 0xe2, 0x94, 0x80, 0xe2, 0x94, 0x81, 0xe2, + 0x95, 0xbe, 0xe2, 0x95, 0xbc, 0xe2, 0x95, 0xba, + 0xe2, 0x95, 0xb6, 0xe2, 0x95, 0xb8, 0xe2, 0x95, + 0xb4, 0xff, + 0xe2, 0x94, 0xbc, 0xe2, 0x95, 0x8b, 0xe2, + 0x95, 0x8a, 0xe2, 0x95, 0x89, 0xe2, 0x95, 0x88, + 0xe2, 0x95, 0x87, 0xe2, 0x95, 0x86, 0xe2, 0x95, + 0x85, 0xe2, 0x95, 0x84, 0xe2, 0x95, 0x83, 0xe2, + 0x95, 0x82, 0xe2, 0x95, 0x81, 0xe2, 0x95, 0x80, + 0xe2, 0x94, 0xbf, 0xe2, 0x94, 0xbe, 0xe2, 0x94, + 0xbd, 0xff, + 0xc5, 0xa2, 0xff, + 0xc5, 0xa3, 0xff, + 0xc5, 0xa4, 0xff, + 0xc5, 0xa5, 0xff, + 0xc5, 0xae, 0xff, + 0xc5, 0xaf, 0xff, + 0xc5, 0xb0, 0xff, + 0xc5, 0xb1, 0xff, + 0xe2, 0x95, 0xac, 0xff, + 0xc5, 0xb9, 0xff, + 0xc5, 0xba, 0xff, + 0xc5, 0xbb, 0xff, + 0xc5, 0xbc, 0xff, + 0xc5, 0xbd, 0xff, + 0xc5, 0xbe, 0xff, + 0xc8, 0x98, 0xff, + 0xc8, 0x99, 0xff, + 0xc8, 0x9a, 0xff, + 0xe2, 0x95, 0xaa, 0xff, + 0xe2, 0x94, 0x98, 0xe2, 0x94, 0x9b, 0xe2, + 0x94, 0x9a, 0xe2, 0x94, 0x99, 0xff, + 0xe2, 0x94, 0x8c, 0xe2, 0x94, 0x8f, 0xe2, + 0x94, 0x8e, 0xe2, 0x94, 0x8d, 0xff, + 0xe2, 0x96, 0x88, 0xff, + 0xc8, 0x9b, 0xff, + 0xcb, 0x87, 0xff, + 0xcb, 0x98, 0xff, + 0xcb, 0x99, 0xff, + 0xcb, 0x9b, 0xff, + 0xc3, 0x9f, 0xff, + 0xcb, 0x9d, 0xff, + 0xcf, 0x80, 0xff, + 0xe2, 0x80, 0x94, 0xe2, 0x80, 0x95, 0xff, + 0xe2, 0x80, 0x98, 0xff, + 0xc2, 0xb5, 0xce, 0xbc, 0xff, + 0xe2, 0x80, 0x99, 0xff, + 0xe2, 0x80, 0x9a, 0xff, + 0xe2, 0x80, 0x9c, 0xff, + 0xe2, 0x80, 0x9d, 0xff, + 0xe2, 0x80, 0x9e, 0xff, + 0xe2, 0x80, 0xa0, 0xff, + 0xe2, 0x80, 0xa1, 0xff, + 0xe2, 0x80, 0xa6, 0xff, + 0xe2, 0x80, 0xb0, 0xff, + 0xe2, 0x80, 0xb9, 0xff, + 0xc2, 0xb1, 0xff, + 0xe2, 0x89, 0xa5, 0xff, + 0xe2, 0x89, 0xa4, 0xff, + 0xe2, 0x80, 0xba, 0xff, + 0xe2, 0x82, 0xac, 0xff, + 0xc3, 0xb7, 0xff, + 0xe2, 0x89, 0x88, 0xff, + 0xc2, 0xb0, 0xff, + 0xe2, 0x84, 0xa2, 0xff, + 0xc2, 0xb7, 0xff, + 0xe2, 0x89, 0xa0, 0xff, + 0xe2, 0x84, 0x96, 0xff, + 0xc3, 0x80, 0xff, + 0xe2, 0x96, 0xa0, 0xe2, 0x96, 0xae, 0xff, + 0xc3, 0x88, 0xff, + diff --git a/stmhal/Makefile b/stmhal/Makefile index ae1db2ae9..8735d84c3 100644 --- a/stmhal/Makefile +++ b/stmhal/Makefile @@ -19,7 +19,7 @@ QSTR_DEFS = qstrdefsport.h $(BUILD)/pins_qstr.h $(BUILD)/modstm_qstr.h FROZEN_MPY_DIR ?= modules # include py core make definitions -include ../py/py.mk +include $(TOP)/py/py.mk LD_DIR=boards CMSIS_DIR=cmsis @@ -27,10 +27,10 @@ HAL_DIR=hal/$(MCU_SERIES) USBDEV_DIR=usbdev #USBHOST_DIR=usbhost FATFS_DIR=lib/oofatfs -DFU=../tools/dfu.py +DFU=$(TOP)/tools/dfu.py # may need to prefix dfu-util with sudo USE_PYDFU ?= 1 -PYDFU ?= ../tools/pydfu.py +PYDFU ?= $(TOP)/tools/pydfu.py DFU_UTIL ?= dfu-util DEVICE=0483:df11 STFLASH ?= st-flash @@ -40,9 +40,9 @@ OPENOCD_CONFIG ?= boards/openocd_stm32f4.cfg CROSS_COMPILE = arm-none-eabi- INC += -I. -INC += -I.. +INC += -I$(TOP) INC += -I$(BUILD) -INC += -I../lib/cmsis/inc +INC += -I$(TOP)/lib/cmsis/inc INC += -I$(CMSIS_DIR)/ INC += -I$(HAL_DIR)/inc INC += -I$(USBDEV_DIR)/core/inc -I$(USBDEV_DIR)/class/inc @@ -406,8 +406,8 @@ GEN_PINS_QSTR = $(BUILD)/pins_qstr.h GEN_PINS_AF_CONST = $(HEADER_BUILD)/pins_af_const.h GEN_PINS_AF_PY = $(BUILD)/pins_af.py -INSERT_USB_IDS = ../tools/insert-usb-ids.py -FILE2H = ../tools/file2h.py +INSERT_USB_IDS = $(TOP)/tools/insert-usb-ids.py +FILE2H = $(TOP)/tools/file2h.py USB_IDS_FILE = usb.h CDCINF_TEMPLATE = pybcdc.inf_template @@ -464,4 +464,4 @@ $(GEN_CDCINF_FILE): $(CDCINF_TEMPLATE) $(INSERT_USB_IDS) $(USB_IDS_FILE) | $(HEA $(ECHO) "Create $@" $(Q)$(PYTHON) $(INSERT_USB_IDS) $(USB_IDS_FILE) $< > $@ -include ../py/mkrules.mk +include $(TOP)/py/mkrules.mk diff --git a/stmhal/accel.c b/stmhal/accel.c index 0e6eaf03d..512a6e313 100644 --- a/stmhal/accel.c +++ b/stmhal/accel.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -102,7 +102,7 @@ STATIC void accel_start(void) { } /******************************************************************************/ -/* Micro Python bindings */ +/* MicroPython bindings */ #define NUM_AXIS (3) #define FILT_DEPTH (4) diff --git a/stmhal/accel.h b/stmhal/accel.h index 10b095f79..fc35f7775 100644 --- a/stmhal/accel.h +++ b/stmhal/accel.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,7 +23,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_ACCEL_H +#define MICROPY_INCLUDED_STMHAL_ACCEL_H extern const mp_obj_type_t pyb_accel_type; void accel_init(void); + +#endif // MICROPY_INCLUDED_STMHAL_ACCEL_H diff --git a/stmhal/adc.c b/stmhal/adc.c index 6485e2ab7..dd59e29c8 100644 --- a/stmhal/adc.c +++ b/stmhal/adc.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -263,7 +263,7 @@ STATIC uint32_t adc_read_channel(ADC_HandleTypeDef *adcHandle) { } /******************************************************************************/ -/* Micro Python bindings : adc object (single channel) */ +/* MicroPython bindings : adc object (single channel) */ STATIC void adc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_obj_adc_t *self = self_in; @@ -596,7 +596,7 @@ float adc_read_core_vref(ADC_HandleTypeDef *adcHandle) { #endif /******************************************************************************/ -/* Micro Python bindings : adc_all object */ +/* MicroPython bindings : adc_all object */ STATIC mp_obj_t adc_all_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check number of arguments diff --git a/stmhal/adc.h b/stmhal/adc.h index ebaccbee3..c90e6b343 100644 --- a/stmhal/adc.h +++ b/stmhal/adc.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_ADC_H +#define MICROPY_INCLUDED_STMHAL_ADC_H extern const mp_obj_type_t pyb_adc_type; extern const mp_obj_type_t pyb_adc_all_type; + +#endif // MICROPY_INCLUDED_STMHAL_ADC_H diff --git a/stmhal/boards/ESPRUINO_PICO/mpconfigboard.h b/stmhal/boards/ESPRUINO_PICO/mpconfigboard.h index e84822957..d065180d8 100644 --- a/stmhal/boards/ESPRUINO_PICO/mpconfigboard.h +++ b/stmhal/boards/ESPRUINO_PICO/mpconfigboard.h @@ -1,6 +1,9 @@ #define MICROPY_HW_BOARD_NAME "Espruino Pico" #define MICROPY_HW_MCU_NAME "STM32F401CD" +#define MICROPY_EMIT_THUMB (0) +#define MICROPY_EMIT_INLINE_THUMB (0) +#define MICROPY_PY_BUILTINS_COMPLEX (0) #define MICROPY_PY_USOCKET (0) #define MICROPY_PY_NETWORK (0) diff --git a/stmhal/boards/ESPRUINO_PICO/mpconfigboard.mk b/stmhal/boards/ESPRUINO_PICO/mpconfigboard.mk index 4c44022c3..d531a594a 100644 --- a/stmhal/boards/ESPRUINO_PICO/mpconfigboard.mk +++ b/stmhal/boards/ESPRUINO_PICO/mpconfigboard.mk @@ -2,3 +2,6 @@ MCU_SERIES = f4 CMSIS_MCU = STM32F401xE AF_FILE = boards/stm32f401_af.csv LD_FILE = boards/stm32f401xd.ld + +# Don't include default frozen modules because MCU is tight on flash space +FROZEN_MPY_DIR ?= diff --git a/stmhal/boards/common.ld b/stmhal/boards/common.ld index fcae1b4c6..e5dea49d0 100644 --- a/stmhal/boards/common.ld +++ b/stmhal/boards/common.ld @@ -27,7 +27,7 @@ SECTIONS . = ALIGN(4); } >FLASH_ISR - + /* The program code and other data goes into FLASH */ .text : { @@ -40,10 +40,10 @@ SECTIONS . = ALIGN(4); _etext = .; /* define a global symbol at end of code */ } >FLASH_TEXT - + /* used by the startup to initialize data */ _sidata = LOADADDR(.data); - + /* This is the initialized data section The program executes knowing that the data is in the RAM but the loader puts the initial values in the FLASH (inidata). @@ -51,13 +51,13 @@ SECTIONS .data : { . = ALIGN(4); - _sdata = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */ + _sdata = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */ *(.data*) /* .data* sections */ . = ALIGN(4); _edata = .; /* define a global symbol at data end; used by startup code in order to initialise the .data section in RAM */ } >RAM AT> FLASH_TEXT - + /* Uninitialized data section */ .bss : { diff --git a/stmhal/boards/stm32f401xd.ld b/stmhal/boards/stm32f401xd.ld index 53aa83d53..415c25849 100644 --- a/stmhal/boards/stm32f401xd.ld +++ b/stmhal/boards/stm32f401xd.ld @@ -15,7 +15,7 @@ MEMORY /* produce a link error if there is not this amount of RAM for these sections */ _minimum_stack_size = 2K; _minimum_heap_size = 16K; - + /* Define tho top end of the stack. The stack is full descending so begins just above last byte of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */ diff --git a/stmhal/boards/stm32f401xe.ld b/stmhal/boards/stm32f401xe.ld index a91eee079..a2e693b49 100644 --- a/stmhal/boards/stm32f401xe.ld +++ b/stmhal/boards/stm32f401xe.ld @@ -15,7 +15,7 @@ MEMORY /* produce a link error if there is not this amount of RAM for these sections */ _minimum_stack_size = 2K; _minimum_heap_size = 16K; - + /* Define tho top end of the stack. The stack is full descending so begins just above last byte of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */ diff --git a/stmhal/boards/stm32f405.ld b/stmhal/boards/stm32f405.ld index 1a256c131..c6107913f 100644 --- a/stmhal/boards/stm32f405.ld +++ b/stmhal/boards/stm32f405.ld @@ -16,7 +16,7 @@ MEMORY /* produce a link error if there is not this amount of RAM for these sections */ _minimum_stack_size = 2K; _minimum_heap_size = 16K; - + /* Define tho top end of the stack. The stack is full descending so begins just above last byte of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */ diff --git a/stmhal/boards/stm32f411.ld b/stmhal/boards/stm32f411.ld index 0b7bcb553..d156e852a 100644 --- a/stmhal/boards/stm32f411.ld +++ b/stmhal/boards/stm32f411.ld @@ -11,11 +11,11 @@ MEMORY FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 0x060000 /* sectors 5,6,7 3*128KiB = 384 KiB */ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x020000 /* 128 KiB */ } - + /* produce a link error if there is not this amount of RAM for these sections */ _minimum_stack_size = 2K; _minimum_heap_size = 16K; - + /* Define tho top end of the stack. The stack is full descending so begins just above last byte of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */ diff --git a/stmhal/boards/stm32f429.ld b/stmhal/boards/stm32f429.ld index 0feb5bd62..f358233a6 100644 --- a/stmhal/boards/stm32f429.ld +++ b/stmhal/boards/stm32f429.ld @@ -4,18 +4,18 @@ /* Specify the memory areas */ MEMORY -{ +{ FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 0x0200000 /* entire flash, 2048 KiB */ FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 0x0004000 /* sector 0, 16 KiB */ FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 0x0088000 /* sectors 5,6,7,8, 4*128KiB = 512 KiB (could increase it more) */ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x0030000 /* 192 KiB */ SDRAM(xrw) : ORIGIN = 0xC0000000, LENGTH = 0x0800000 /* 8 MByte */ } - + /* produce a link error if there is not this amount of RAM for these sections */ _minimum_stack_size = 2K; _minimum_heap_size = 16K; - + /* Define tho top end of the stack. The stack is full descending so begins just above last byte of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */ diff --git a/stmhal/boards/stm32l476xe.ld b/stmhal/boards/stm32l476xe.ld index 114158d8c..bb9895d2a 100644 --- a/stmhal/boards/stm32l476xe.ld +++ b/stmhal/boards/stm32l476xe.ld @@ -4,7 +4,7 @@ /* Specify the memory areas */ MEMORY -{ +{ FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 0x0004000 /* sectors 0-7, 16 KiB */ FLASH_TEXT (rx) : ORIGIN = 0x08004000, LENGTH = 0x005C000 /* sectors 8-191, 368 KiB */ @@ -16,7 +16,7 @@ MEMORY /* produce a link error if there is not this amount of RAM for these sections */ _minimum_stack_size = 2K; _minimum_heap_size = 16K; - + /* Define the top end of the stack. The stack is full descending so begins just above last byte of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */ diff --git a/stmhal/boards/stm32l476xg.ld b/stmhal/boards/stm32l476xg.ld index b9c29d624..684078c43 100644 --- a/stmhal/boards/stm32l476xg.ld +++ b/stmhal/boards/stm32l476xg.ld @@ -4,7 +4,7 @@ /* Specify the memory areas */ MEMORY -{ +{ FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 0x0004000 /* sectors 0-7, 16 KiB */ FLASH_TEXT (rx) : ORIGIN = 0x08004000, LENGTH = 0x007C000 /* sectors 8-255, 496 KiB */ @@ -18,7 +18,7 @@ ENTRY(Reset_Handler) /* produce a link error if there is not this amount of RAM for these sections */ _minimum_stack_size = 2K; _minimum_heap_size = 16K; - + /* Define the top end of the stack. The stack is full descending so begins just above last byte of RAM. Note that EABI requires the stack to be 8-byte aligned for a call. */ diff --git a/stmhal/bufhelper.c b/stmhal/bufhelper.c index ca76e9496..79511969b 100644 --- a/stmhal/bufhelper.c +++ b/stmhal/bufhelper.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/bufhelper.h b/stmhal/bufhelper.h index abdeea6a8..c1967bf43 100644 --- a/stmhal/bufhelper.h +++ b/stmhal/bufhelper.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_BUFHELPER_H +#define MICROPY_INCLUDED_STMHAL_BUFHELPER_H void pyb_buf_get_for_send(mp_obj_t o, mp_buffer_info_t *bufinfo, byte *tmp_data); mp_obj_t pyb_buf_get_for_recv(mp_obj_t o, vstr_t *vstr); + +#endif // MICROPY_INCLUDED_STMHAL_BUFHELPER_H diff --git a/stmhal/can.c b/stmhal/can.c index 6152022b7..9047e78ca 100644 --- a/stmhal/can.c +++ b/stmhal/can.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -262,7 +262,7 @@ STATIC HAL_StatusTypeDef CAN_Transmit(CAN_HandleTypeDef *hcan, uint32_t Timeout) } /******************************************************************************/ -// Micro Python bindings +// MicroPython bindings STATIC void pyb_can_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_can_obj_t *self = self_in; diff --git a/stmhal/can.h b/stmhal/can.h index 4d4b1bb83..860012813 100644 --- a/stmhal/can.h +++ b/stmhal/can.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_CAN_H +#define MICROPY_INCLUDED_STMHAL_CAN_H #define PYB_CAN_1 (1) #define PYB_CAN_2 (2) @@ -32,3 +34,5 @@ extern const mp_obj_type_t pyb_can_type; void can_init0(void); void can_deinit(void); void can_rx_irq_handler(uint can_id, uint fifo_id); + +#endif // MICROPY_INCLUDED_STMHAL_CAN_H diff --git a/stmhal/dac.c b/stmhal/dac.c index 243aa08c3..14bd59b41 100644 --- a/stmhal/dac.c +++ b/stmhal/dac.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -119,12 +119,12 @@ STATIC uint32_t TIMx_Config(mp_obj_t timer) { return DAC_TRIGGER_T8_TRGO; #endif } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Timer does not support DAC triggering")); + mp_raise_ValueError("Timer does not support DAC triggering"); } } /******************************************************************************/ -// Micro Python bindings +// MicroPython bindings typedef enum { DAC_STATE_RESET, diff --git a/stmhal/dac.h b/stmhal/dac.h index ba44158f3..f487f52a9 100644 --- a/stmhal/dac.h +++ b/stmhal/dac.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,7 +23,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_DAC_H +#define MICROPY_INCLUDED_STMHAL_DAC_H void dac_init(void); extern const mp_obj_type_t pyb_dac_type; + +#endif // MICROPY_INCLUDED_STMHAL_DAC_H diff --git a/stmhal/dma.c b/stmhal/dma.c index e43b67e73..df6275d65 100644 --- a/stmhal/dma.c +++ b/stmhal/dma.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/dma.h b/stmhal/dma.h index 57b8f866d..55fb62175 100644 --- a/stmhal/dma.h +++ b/stmhal/dma.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef __MICROPY_INCLUDED_STMHAL_DMA_H__ -#define __MICROPY_INCLUDED_STMHAL_DMA_H__ +#ifndef MICROPY_INCLUDED_STMHAL_DMA_H +#define MICROPY_INCLUDED_STMHAL_DMA_H typedef struct _dma_descr_t dma_descr_t; @@ -101,4 +100,4 @@ void dma_deinit(const dma_descr_t *dma_descr); void dma_invalidate_channel(const dma_descr_t *dma_descr); void dma_idle_handler(int controller); -#endif //__MICROPY_INCLUDED_STMHAL_DMA_H__ +#endif // MICROPY_INCLUDED_STMHAL_DMA_H diff --git a/stmhal/extint.c b/stmhal/extint.c index 70023557f..24a68c2a2 100644 --- a/stmhal/extint.c +++ b/stmhal/extint.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/extint.h b/stmhal/extint.h index b04224c40..846790b9b 100644 --- a/stmhal/extint.h +++ b/stmhal/extint.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_EXTINT_H +#define MICROPY_INCLUDED_STMHAL_EXTINT_H // Vectors 0-15 are for regular pins // Vectors 16-22 are for internal sources. @@ -61,3 +63,5 @@ void extint_swint(uint line); void Handle_EXTI_Irq(uint32_t line); extern const mp_obj_type_t extint_type; + +#endif // MICROPY_INCLUDED_STMHAL_EXTINT_H diff --git a/stmhal/flash.c b/stmhal/flash.c index e374be0e5..bebb3a161 100644 --- a/stmhal/flash.c +++ b/stmhal/flash.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/flash.h b/stmhal/flash.h index 007155ecb..688e70a3c 100644 --- a/stmhal/flash.h +++ b/stmhal/flash.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,7 +23,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_FLASH_H +#define MICROPY_INCLUDED_STMHAL_FLASH_H uint32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size); void flash_erase(uint32_t flash_dest, const uint32_t *src, uint32_t num_word32); void flash_write(uint32_t flash_dest, const uint32_t *src, uint32_t num_word32); + +#endif // MICROPY_INCLUDED_STMHAL_FLASH_H diff --git a/stmhal/font_petme128_8x8.h b/stmhal/font_petme128_8x8.h index 7f928edda..8b0cc9cb0 100644 --- a/stmhal/font_petme128_8x8.h +++ b/stmhal/font_petme128_8x8.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_FONT_PETME128_8X8_H +#define MICROPY_INCLUDED_STMHAL_FONT_PETME128_8X8_H static const uint8_t font_petme128_8x8[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 32= @@ -122,3 +124,5 @@ static const uint8_t font_petme128_8x8[] = { 0x00,0x02,0x03,0x01,0x03,0x02,0x03,0x01, // 126=~ 0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55, // 127 }; + +#endif // MICROPY_INCLUDED_STMHAL_FONT_PETME128_8X8_H diff --git a/stmhal/gccollect.c b/stmhal/gccollect.c index d7223dedc..937fb6f36 100644 --- a/stmhal/gccollect.c +++ b/stmhal/gccollect.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/gccollect.h b/stmhal/gccollect.h index 07797be7e..1b64a51a6 100644 --- a/stmhal/gccollect.h +++ b/stmhal/gccollect.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_GCCOLLECT_H +#define MICROPY_INCLUDED_STMHAL_GCCOLLECT_H // variables defining memory layout // (these probably belong somewhere else...) @@ -37,3 +39,5 @@ extern uint32_t _heap_start; extern uint32_t _heap_end; extern uint32_t _estack; extern uint32_t _ram_end; + +#endif // MICROPY_INCLUDED_STMHAL_GCCOLLECT_H diff --git a/stmhal/hal/l4/inc/stm32l4xx_hal_uart.h b/stmhal/hal/l4/inc/stm32l4xx_hal_uart.h index b890c3d98..52ca6406b 100644 --- a/stmhal/hal/l4/inc/stm32l4xx_hal_uart.h +++ b/stmhal/hal/l4/inc/stm32l4xx_hal_uart.h @@ -1370,7 +1370,7 @@ void UART_AdvFeatureConfig(UART_HandleTypeDef *huart); /** * @} */ -/* Functions added by micropython */ +/* Functions added by MicroPython */ uint32_t HAL_UART_CalcBrr(uint32_t fck, uint32_t baud); #ifdef __cplusplus diff --git a/stmhal/hal/l4/src/stm32l4xx_hal_uart.c b/stmhal/hal/l4/src/stm32l4xx_hal_uart.c index 2b0d76d30..adb3d79ab 100644 --- a/stmhal/hal/l4/src/stm32l4xx_hal_uart.c +++ b/stmhal/hal/l4/src/stm32l4xx_hal_uart.c @@ -2104,7 +2104,7 @@ static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart) /** * @brief Calculate register BRR value without using uint64. - * @note This function is added by the micropython project. + * @note This function is added by the MicroPython project. * @param fck: Input clock frequency to the uart block in Hz. * @param baud: baud rate should be one of {300, 600, 1200, 2400, 4800, 9600, 19200, 57600, 115200}. * @retval BRR value diff --git a/stmhal/help.c b/stmhal/help.c index 83ef7e596..87b2af526 100644 --- a/stmhal/help.c +++ b/stmhal/help.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/i2c.c b/stmhal/i2c.c index d0d877818..48a1e49af 100644 --- a/stmhal/i2c.c +++ b/stmhal/i2c.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -283,7 +283,7 @@ void i2c_init(I2C_HandleTypeDef *i2c) { const pyb_i2c_obj_t *self = &pyb_i2c_obj[i2c_unit - 1]; dma_invalidate_channel(self->tx_dma_descr); dma_invalidate_channel(self->rx_dma_descr); - + if (0) { #if defined(MICROPY_HW_I2C1_SCL) } else if (i2c->Instance == I2C1) { @@ -511,9 +511,9 @@ STATIC HAL_StatusTypeDef i2c_wait_dma_finished(I2C_HandleTypeDef *i2c, uint32_t } /******************************************************************************/ -/* Micro Python bindings */ +/* MicroPython bindings */ -STATIC inline bool in_master_mode(pyb_i2c_obj_t *self) { return self->i2c->Init.OwnAddress1 == PYB_I2C_MASTER_ADDRESS; } +static inline bool in_master_mode(pyb_i2c_obj_t *self) { return self->i2c->Init.OwnAddress1 == PYB_I2C_MASTER_ADDRESS; } STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_i2c_obj_t *self = self_in; @@ -670,7 +670,7 @@ STATIC mp_obj_t pyb_i2c_is_ready(mp_obj_t self_in, mp_obj_t i2c_addr_o) { pyb_i2c_obj_t *self = self_in; if (!in_master_mode(self)) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "I2C must be a master")); + mp_raise_TypeError("I2C must be a master"); } mp_uint_t i2c_addr = mp_obj_get_int(i2c_addr_o) << 1; @@ -693,7 +693,7 @@ STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) { pyb_i2c_obj_t *self = self_in; if (!in_master_mode(self)) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "I2C must be a master")); + mp_raise_TypeError("I2C must be a master"); } mp_obj_t list = mp_obj_new_list(0, NULL); @@ -754,7 +754,7 @@ STATIC mp_obj_t pyb_i2c_send(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_ if (use_dma) { dma_deinit(self->tx_dma_descr); } - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "addr argument required")); + mp_raise_TypeError("addr argument required"); } mp_uint_t i2c_addr = args[1].u_int << 1; if (!use_dma) { @@ -830,7 +830,7 @@ STATIC mp_obj_t pyb_i2c_recv(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_ HAL_StatusTypeDef status; if (in_master_mode(self)) { if (args[1].u_int == PYB_I2C_MASTER_ADDRESS) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "addr argument required")); + mp_raise_TypeError("addr argument required"); } mp_uint_t i2c_addr = args[1].u_int << 1; if (!use_dma) { @@ -897,7 +897,7 @@ STATIC mp_obj_t pyb_i2c_mem_read(mp_uint_t n_args, const mp_obj_t *pos_args, mp_ mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(pyb_i2c_mem_read_allowed_args), pyb_i2c_mem_read_allowed_args, args); if (!in_master_mode(self)) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "I2C must be a master")); + mp_raise_TypeError("I2C must be a master"); } // get the buffer to read into @@ -965,7 +965,7 @@ STATIC mp_obj_t pyb_i2c_mem_write(mp_uint_t n_args, const mp_obj_t *pos_args, mp mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(pyb_i2c_mem_read_allowed_args), pyb_i2c_mem_read_allowed_args, args); if (!in_master_mode(self)) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "I2C must be a master")); + mp_raise_TypeError("I2C must be a master"); } // get the buffer to write from diff --git a/stmhal/i2c.h b/stmhal/i2c.h index fc7a6f613..6affe3973 100644 --- a/stmhal/i2c.h +++ b/stmhal/i2c.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_I2C_H +#define MICROPY_INCLUDED_STMHAL_I2C_H #include "dma.h" @@ -49,3 +51,5 @@ void i2c_init_freq(const pyb_i2c_obj_t *self, mp_int_t freq); uint32_t i2c_get_baudrate(I2C_InitTypeDef *init); void i2c_ev_irq_handler(mp_uint_t i2c_id); void i2c_er_irq_handler(mp_uint_t i2c_id); + +#endif // MICROPY_INCLUDED_STMHAL_I2C_H diff --git a/stmhal/irq.c b/stmhal/irq.c index 44758e11b..d6db8e83d 100644 --- a/stmhal/irq.c +++ b/stmhal/irq.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/irq.h b/stmhal/irq.h index 35187520a..2cf58639e 100644 --- a/stmhal/irq.h +++ b/stmhal/irq.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,7 +23,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - #ifndef MICROPY_INCLUDED_STMHAL_IRQ_H #define MICROPY_INCLUDED_STMHAL_IRQ_H diff --git a/stmhal/lcd.c b/stmhal/lcd.c index cdf9fa0d1..7368193cf 100644 --- a/stmhal/lcd.c +++ b/stmhal/lcd.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/lcd.h b/stmhal/lcd.h index 6a4b004bd..c0d9bd97d 100644 --- a/stmhal/lcd.h +++ b/stmhal/lcd.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,5 +23,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_LCD_H +#define MICROPY_INCLUDED_STMHAL_LCD_H extern const mp_obj_type_t pyb_lcd_type; + +#endif // MICROPY_INCLUDED_STMHAL_LCD_H diff --git a/stmhal/led.c b/stmhal/led.c index 4b9895fc5..030a814dd 100644 --- a/stmhal/led.c +++ b/stmhal/led.c @@ -279,7 +279,7 @@ void led_debug(int n, int delay) { } /******************************************************************************/ -/* Micro Python bindings */ +/* MicroPython bindings */ void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_led_obj_t *self = self_in; diff --git a/stmhal/led.h b/stmhal/led.h index f4cd67336..f1b05d1e2 100644 --- a/stmhal/led.h +++ b/stmhal/led.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_LED_H +#define MICROPY_INCLUDED_STMHAL_LED_H typedef enum { // PYBv3 @@ -48,3 +50,5 @@ void led_toggle(pyb_led_t led); void led_debug(int value, int delay); extern const mp_obj_type_t pyb_led_type; + +#endif // MICROPY_INCLUDED_STMHAL_LED_H diff --git a/stmhal/main.c b/stmhal/main.c index 566c2db07..056c590cd 100644 --- a/stmhal/main.c +++ b/stmhal/main.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -511,7 +511,7 @@ int main(void) { // GC init gc_init(&_heap_start, &_heap_end); - // Micro Python init + // MicroPython init mp_init(); mp_obj_list_init(mp_sys_path, 0); mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script) diff --git a/stmhal/modmachine.c b/stmhal/modmachine.c index c5444ec98..cb7957681 100644 --- a/stmhal/modmachine.c +++ b/stmhal/modmachine.c @@ -258,7 +258,7 @@ STATIC mp_obj_t machine_freq(mp_uint_t n_args, const mp_obj_t *args) { mp_int_t wanted_sysclk = mp_obj_get_int(args[0]) / 1000000; #if defined(MCU_SERIES_L4) - nlr_raise(mp_obj_new_exception_msg(&mp_type_NotImplementedError, "machine.freq set not supported yet")); + mp_raise_NotImplementedError("machine.freq set not supported yet"); #endif // default PLL parameters that give 48MHz on PLL48CK @@ -318,7 +318,7 @@ STATIC mp_obj_t machine_freq(mp_uint_t n_args, const mp_obj_t *args) { goto set_clk; } } - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "can't make valid freq")); + mp_raise_ValueError("can't make valid freq"); } set_clk: diff --git a/stmhal/modmachine.h b/stmhal/modmachine.h index 164c5cfda..ac39f854e 100644 --- a/stmhal/modmachine.h +++ b/stmhal/modmachine.h @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef __MICROPY_INCLUDED_STMHAL_MODMACHINE_H__ -#define __MICROPY_INCLUDED_STMHAL_MODMACHINE_H__ +#ifndef MICROPY_INCLUDED_STMHAL_MODMACHINE_H +#define MICROPY_INCLUDED_STMHAL_MODMACHINE_H #include "py/mpstate.h" #include "py/nlr.h" @@ -41,4 +40,4 @@ MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj); MP_DECLARE_CONST_FUN_OBJ_0(machine_sleep_obj); MP_DECLARE_CONST_FUN_OBJ_0(machine_deepsleep_obj); -#endif // __MICROPY_INCLUDED_STMHAL_MODMACHINE_H__ +#endif // MICROPY_INCLUDED_STMHAL_MODMACHINE_H diff --git a/stmhal/modnetwork.c b/stmhal/modnetwork.c index 09a80ef3c..6b4949a0d 100644 --- a/stmhal/modnetwork.c +++ b/stmhal/modnetwork.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/modnetwork.h b/stmhal/modnetwork.h index d3bc5674d..ecda94da4 100644 --- a/stmhal/modnetwork.h +++ b/stmhal/modnetwork.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_MODNETWORK_H +#define MICROPY_INCLUDED_STMHAL_MODNETWORK_H #define MOD_NETWORK_IPADDR_BUF_SIZE (4) @@ -77,3 +79,5 @@ extern const mod_network_nic_type_t mod_network_nic_type_cc3k; void mod_network_init(void); void mod_network_register_nic(mp_obj_t nic); mp_obj_t mod_network_find_nic(const uint8_t *ip); + +#endif // MICROPY_INCLUDED_STMHAL_MODNETWORK_H diff --git a/stmhal/modnwcc3k.c b/stmhal/modnwcc3k.c index 957d74e6e..a04a2d260 100644 --- a/stmhal/modnwcc3k.c +++ b/stmhal/modnwcc3k.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -412,7 +412,7 @@ STATIC int cc3k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request } /******************************************************************************/ -// Micro Python bindings; CC3K class +// MicroPython bindings; CC3K class typedef struct _cc3k_obj_t { mp_obj_base_t base; diff --git a/stmhal/modnwwiznet5k.c b/stmhal/modnwwiznet5k.c index 4752cdc0b..eb7eb8443 100644 --- a/stmhal/modnwwiznet5k.c +++ b/stmhal/modnwwiznet5k.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -314,7 +314,7 @@ STATIC mp_obj_t wiznet5k_socket_disconnect(mp_obj_t self_in) { #endif /******************************************************************************/ -// Micro Python bindings +// MicroPython bindings /// \classmethod \constructor(spi, pin_cs, pin_rst) /// Create and return a WIZNET5K object. diff --git a/stmhal/modpyb.c b/stmhal/modpyb.c index 7322c6a5b..5dc28e132 100644 --- a/stmhal/modpyb.c +++ b/stmhal/modpyb.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/modstm.c b/stmhal/modstm.c index eabbf08e4..2084c0aa0 100644 --- a/stmhal/modstm.c +++ b/stmhal/modstm.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/moduos.c b/stmhal/moduos.c index ece6019fb..e02f6aefa 100644 --- a/stmhal/moduos.c +++ b/stmhal/moduos.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -121,7 +121,7 @@ STATIC mp_obj_t os_dupterm(mp_uint_t n_args, const mp_obj_t *args) { } else if (mp_obj_get_type(args[0]) == &pyb_uart_type) { MP_STATE_PORT(pyb_stdio_uart) = args[0]; } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "need a UART object")); + mp_raise_ValueError("need a UART object"); } return mp_const_none; } diff --git a/stmhal/modusocket.c b/stmhal/modusocket.c index 081a322ae..e1da53a4b 100644 --- a/stmhal/modusocket.c +++ b/stmhal/modusocket.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/modutime.c b/stmhal/modutime.c index 58c43a55e..fe13f80c0 100644 --- a/stmhal/modutime.c +++ b/stmhal/modutime.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h index 96a330d13..a8ea2f02a 100644 --- a/stmhal/mpconfigport.h +++ b/stmhal/mpconfigport.h @@ -27,10 +27,6 @@ // Options to control how MicroPython is built for this port, // overriding defaults in py/mpconfig.h. -#pragma once -#ifndef __INCLUDED_MPCONFIGPORT_H -#define __INCLUDED_MPCONFIGPORT_H - // board specific definitions #include "mpconfigboard.h" @@ -39,8 +35,12 @@ // emitters #define MICROPY_PERSISTENT_CODE_LOAD (1) +#ifndef MICROPY_EMIT_THUMB #define MICROPY_EMIT_THUMB (1) +#endif +#ifndef MICROPY_EMIT_INLINE_THUMB #define MICROPY_EMIT_INLINE_THUMB (1) +#endif // compiler configuration #define MICROPY_COMP_MODULE_CONST (1) @@ -346,5 +346,3 @@ static inline mp_uint_t disable_irq(void) { #include #define MICROPY_PIN_DEFS_PORT_H "pin_defs_stmhal.h" - -#endif // __INCLUDED_MPCONFIGPORT_H diff --git a/stmhal/mpthreadport.h b/stmhal/mpthreadport.h index 3d8b4ef01..8e2372dcb 100644 --- a/stmhal/mpthreadport.h +++ b/stmhal/mpthreadport.h @@ -23,8 +23,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_STMHAL_MPTHREADPORT_H__ -#define __MICROPY_INCLUDED_STMHAL_MPTHREADPORT_H__ #include "py/mpthread.h" #include "pybthread.h" @@ -53,5 +51,3 @@ static inline int mp_thread_mutex_lock(mp_thread_mutex_t *m, int wait) { static inline void mp_thread_mutex_unlock(mp_thread_mutex_t *m) { pyb_mutex_unlock(m); } - -#endif // __MICROPY_INCLUDED_STMHAL_MPTHREADPORT_H__ diff --git a/stmhal/pendsv.c b/stmhal/pendsv.c index 7b3906f25..00ea12f46 100644 --- a/stmhal/pendsv.c +++ b/stmhal/pendsv.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/pendsv.h b/stmhal/pendsv.h index 77c78d4c1..6a9eb0d79 100644 --- a/stmhal/pendsv.h +++ b/stmhal/pendsv.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_PENDSV_H +#define MICROPY_INCLUDED_STMHAL_PENDSV_H void pendsv_init(void); void pendsv_kbd_intr(void); @@ -30,3 +32,5 @@ void pendsv_kbd_intr(void); // since we play tricks with the stack, the compiler must not generate a // prelude for this function void pendsv_isr_handler(void) __attribute__((naked)); + +#endif // MICROPY_INCLUDED_STMHAL_PENDSV_H diff --git a/stmhal/pin.c b/stmhal/pin.c index f30474e1f..8d4e80022 100644 --- a/stmhal/pin.c +++ b/stmhal/pin.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -120,7 +120,7 @@ const pin_obj_t *pin_find(mp_obj_t user_obj) { pin_obj = mp_call_function_1(MP_STATE_PORT(pin_class_mapper), user_obj); if (pin_obj != mp_const_none) { if (!MP_OBJ_IS_TYPE(pin_obj, &pin_type)) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Pin.mapper didn't return a Pin object")); + mp_raise_ValueError("Pin.mapper didn't return a Pin object"); } if (pin_class_debug) { printf("Pin.mapper maps "); diff --git a/stmhal/pin.h b/stmhal/pin.h index a11b0a0f8..90de79e5c 100644 --- a/stmhal/pin.h +++ b/stmhal/pin.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef __MICROPY_INCLUDED_STMHAL_PIN_H__ -#define __MICROPY_INCLUDED_STMHAL_PIN_H__ +#ifndef MICROPY_INCLUDED_STMHAL_PIN_H +#define MICROPY_INCLUDED_STMHAL_PIN_H // This file requires pin_defs_xxx.h (which has port specific enums and // defines, so we include it here. It should never be included directly @@ -98,4 +97,4 @@ const pin_af_obj_t *pin_find_af(const pin_obj_t *pin, uint8_t fn, uint8_t unit); const pin_af_obj_t *pin_find_af_by_index(const pin_obj_t *pin, mp_uint_t af_idx); const pin_af_obj_t *pin_find_af_by_name(const pin_obj_t *pin, const char *name); -#endif // __MICROPY_INCLUDED_STMHAL_PIN_H__ +#endif // MICROPY_INCLUDED_STMHAL_PIN_H diff --git a/stmhal/pin_defs_stmhal.h b/stmhal/pin_defs_stmhal.h index d6a2ef424..6cf3b1b83 100644 --- a/stmhal/pin_defs_stmhal.h +++ b/stmhal/pin_defs_stmhal.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/pin_named_pins.c b/stmhal/pin_named_pins.c index 9e5f9593b..726da54dd 100644 --- a/stmhal/pin_named_pins.c +++ b/stmhal/pin_named_pins.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -31,22 +31,15 @@ #include "py/mphal.h" #include "pin.h" -STATIC void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { - pin_named_pins_obj_t *self = self_in; - mp_printf(print, "", self->name); -} - const mp_obj_type_t pin_cpu_pins_obj_type = { { &mp_type_type }, .name = MP_QSTR_cpu, - .print = pin_named_pins_obj_print, .locals_dict = (mp_obj_t)&pin_cpu_pins_locals_dict, }; const mp_obj_type_t pin_board_pins_obj_type = { { &mp_type_type }, .name = MP_QSTR_board, - .print = pin_named_pins_obj_print, .locals_dict = (mp_obj_t)&pin_board_pins_locals_dict, }; diff --git a/stmhal/portmodules.h b/stmhal/portmodules.h index 0b460f38c..b575109b8 100644 --- a/stmhal/portmodules.h +++ b/stmhal/portmodules.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_PORTMODULES_H +#define MICROPY_INCLUDED_STMHAL_PORTMODULES_H extern const mp_obj_module_t pyb_module; extern const mp_obj_module_t stm_module; @@ -37,3 +39,5 @@ MP_DECLARE_CONST_FUN_OBJ_1(time_sleep_us_obj); MP_DECLARE_CONST_FUN_OBJ_0(mod_os_sync_obj); MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mod_os_dupterm_obj); + +#endif // MICROPY_INCLUDED_STMHAL_PORTMODULES_H diff --git a/stmhal/pybthread.h b/stmhal/pybthread.h index 6edb2400e..f628f934b 100644 --- a/stmhal/pybthread.h +++ b/stmhal/pybthread.h @@ -23,7 +23,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - #ifndef MICROPY_INCLUDED_STMHAL_PYBTHREAD_H #define MICROPY_INCLUDED_STMHAL_PYBTHREAD_H diff --git a/stmhal/qstrdefsport.h b/stmhal/qstrdefsport.h index 1d83f43bd..31220c5a4 100644 --- a/stmhal/qstrdefsport.h +++ b/stmhal/qstrdefsport.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/rng.c b/stmhal/rng.c index a5a9874d1..c0c5e9aeb 100644 --- a/stmhal/rng.c +++ b/stmhal/rng.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/rng.h b/stmhal/rng.h index ce1833e80..43e49fe72 100644 --- a/stmhal/rng.h +++ b/stmhal/rng.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_RNG_H +#define MICROPY_INCLUDED_STMHAL_RNG_H void rng_init0(void); uint32_t rng_get(void); MP_DECLARE_CONST_FUN_OBJ_0(pyb_rng_get_obj); + +#endif // MICROPY_INCLUDED_STMHAL_RNG_H diff --git a/stmhal/rtc.c b/stmhal/rtc.c index 755684570..6cb6ef047 100644 --- a/stmhal/rtc.c +++ b/stmhal/rtc.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -412,7 +412,7 @@ STATIC void RTC_CalendarConfig(void) { } /******************************************************************************/ -// Micro Python bindings +// MicroPython bindings typedef struct _pyb_rtc_obj_t { mp_obj_base_t base; @@ -575,7 +575,7 @@ mp_obj_t pyb_rtc_wakeup(mp_uint_t n_args, const mp_obj_t *args) { wut -= 0x10000; if (wut > 0x10000) { // wut still too large - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "wakeup value too large")); + mp_raise_ValueError("wakeup value too large"); } } } @@ -685,12 +685,10 @@ mp_obj_t pyb_rtc_calibration(mp_uint_t n_args, const mp_obj_t *args) { } return mp_obj_new_int(cal & 1); } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "calibration value out of range")); + mp_raise_ValueError("calibration value out of range"); } #else - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, - "calibration value out of range")); + mp_raise_ValueError("calibration value out of range"); #endif } if (cal > 0) { diff --git a/stmhal/rtc.h b/stmhal/rtc.h index 69d64c778..09ab2aedf 100644 --- a/stmhal/rtc.h +++ b/stmhal/rtc.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_RTC_H +#define MICROPY_INCLUDED_STMHAL_RTC_H extern RTC_HandleTypeDef RTCHandle; extern const mp_obj_type_t pyb_rtc_type; void rtc_init_start(bool force_init); void rtc_init_finalise(void); + +#endif // MICROPY_INCLUDED_STMHAL_RTC_H diff --git a/stmhal/sdcard.c b/stmhal/sdcard.c index c7ddbbde3..dfa7158a4 100644 --- a/stmhal/sdcard.c +++ b/stmhal/sdcard.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -216,7 +216,7 @@ void sdcard_power_off(void) { if (!sd_handle.Instance) { return; } - HAL_SD_DeInit(&sd_handle); + HAL_SD_DeInit(&sd_handle); sd_handle.Instance = NULL; } @@ -356,7 +356,7 @@ mp_uint_t sdcard_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t n } /******************************************************************************/ -// Micro Python bindings +// MicroPython bindings // // Expose the SD card as an object with the block protocol. diff --git a/stmhal/sdcard.h b/stmhal/sdcard.h index 237e48d8b..8c698fc2f 100644 --- a/stmhal/sdcard.h +++ b/stmhal/sdcard.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_SDCARD_H +#define MICROPY_INCLUDED_STMHAL_SDCARD_H // this is a fixed size and should not be changed #define SDCARD_BLOCK_SIZE (512) @@ -42,3 +44,5 @@ extern const struct _mp_obj_base_t pyb_sdcard_obj; struct _fs_user_mount_t; void sdcard_init_vfs(struct _fs_user_mount_t *vfs, int part); + +#endif // MICROPY_INCLUDED_STMHAL_SDCARD_H diff --git a/stmhal/servo.c b/stmhal/servo.c index 6ea6938ad..fa39587a8 100644 --- a/stmhal/servo.c +++ b/stmhal/servo.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -26,26 +26,30 @@ #include -#include "py/nlr.h" #include "py/runtime.h" +#include "py/mphal.h" +#include "pin.h" +#include "genhdr/pins.h" #include "timer.h" #include "servo.h" -/// \moduleref pyb -/// \class Servo - 3-wire hobby servo driver -/// -/// Servo controls standard hobby servos with 3-wires (ground, power, signal). +#if MICROPY_HW_ENABLE_SERVO -// this servo driver uses hardware PWM to drive servos on PA0, PA1, PA2, PA3 = X1, X2, X3, X4 -// TIM2 and TIM5 have CH1, CH2, CH3, CH4 on PA0-PA3 respectively -// they are both 32-bit counters with 16-bit prescaler -// we use TIM5 +// This file implements the pyb.Servo class which controls standard hobby servo +// motors that have 3-wires (ground, power, signal). +// +// The driver uses hardware PWM to drive servos on pins X1, X2, X3, X4 which are +// assumed to be on PA0, PA1, PA2, PA3 but not necessarily in that order (the +// pins PA0-PA3 are used directly if the X pins are not defined). +// +// TIM2 and TIM5 have CH1-CH4 on PA0-PA3 respectively. They are both 32-bit +// counters with 16-bit prescaler. TIM5 is used by this driver. #define PYB_SERVO_NUM (4) typedef struct _pyb_servo_obj_t { mp_obj_base_t base; - uint8_t servo_id; + const pin_obj_t *pin; uint8_t pulse_min; // units of 10us uint8_t pulse_max; // units of 10us uint8_t pulse_centre; // units of 10us @@ -65,7 +69,6 @@ void servo_init(void) { // reset servo objects for (int i = 0; i < PYB_SERVO_NUM; i++) { pyb_servo_obj[i].base.type = &pyb_servo_type; - pyb_servo_obj[i].servo_id = i + 1; pyb_servo_obj[i].pulse_min = 64; pyb_servo_obj[i].pulse_max = 242; pyb_servo_obj[i].pulse_centre = 150; @@ -75,6 +78,19 @@ void servo_init(void) { pyb_servo_obj[i].pulse_dest = 0; pyb_servo_obj[i].time_left = 0; } + + // assign servo objects to specific pins (must be some permutation of PA0-PA3) + #ifdef pyb_pin_X1 + pyb_servo_obj[0].pin = &pyb_pin_X1; + pyb_servo_obj[1].pin = &pyb_pin_X2; + pyb_servo_obj[2].pin = &pyb_pin_X3; + pyb_servo_obj[3].pin = &pyb_pin_X4; + #else + pyb_servo_obj[0].pin = &pin_A0; + pyb_servo_obj[1].pin = &pin_A1; + pyb_servo_obj[2].pin = &pin_A2; + pyb_servo_obj[3].pin = &pin_A3; + #endif } void servo_timer_irq_callback(void) { @@ -100,12 +116,7 @@ void servo_timer_irq_callback(void) { need_it = true; } // set the pulse width - switch (s->servo_id) { - case 1: TIM5->CCR1 = s->pulse_cur; break; - case 2: TIM5->CCR2 = s->pulse_cur; break; - case 3: TIM5->CCR3 = s->pulse_cur; break; - case 4: TIM5->CCR4 = s->pulse_cur; break; - } + *(&TIM5->CCR1 + s->pin->pin) = s->pulse_cur; } } if (need_it) { @@ -116,24 +127,12 @@ void servo_timer_irq_callback(void) { } STATIC void servo_init_channel(pyb_servo_obj_t *s) { - uint32_t pin; - uint32_t channel; - switch (s->servo_id) { - case 1: pin = GPIO_PIN_0; channel = TIM_CHANNEL_1; break; - case 2: pin = GPIO_PIN_1; channel = TIM_CHANNEL_2; break; - case 3: pin = GPIO_PIN_2; channel = TIM_CHANNEL_3; break; - case 4: pin = GPIO_PIN_3; channel = TIM_CHANNEL_4; break; - default: return; - } + static const uint8_t channel_table[4] = + {TIM_CHANNEL_1, TIM_CHANNEL_2, TIM_CHANNEL_3, TIM_CHANNEL_4}; + uint32_t channel = channel_table[s->pin->pin]; // GPIO configuration - GPIO_InitTypeDef GPIO_InitStructure; - GPIO_InitStructure.Pin = pin; - GPIO_InitStructure.Mode = GPIO_MODE_AF_PP; - GPIO_InitStructure.Speed = GPIO_SPEED_FAST; - GPIO_InitStructure.Pull = GPIO_NOPULL; - GPIO_InitStructure.Alternate = GPIO_AF2_TIM5; - HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); + mp_hal_pin_config(s->pin, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_NONE, GPIO_AF2_TIM5); // PWM mode configuration TIM_OC_InitTypeDef oc_init; @@ -148,7 +147,7 @@ STATIC void servo_init_channel(pyb_servo_obj_t *s) { } /******************************************************************************/ -// Micro Python bindings +// MicroPython bindings STATIC mp_obj_t pyb_servo_set(mp_obj_t port, mp_obj_t value) { int p = mp_obj_get_int(port); @@ -178,7 +177,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(pyb_pwm_set_obj, pyb_pwm_set); STATIC void pyb_servo_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_servo_obj_t *self = self_in; - mp_printf(print, "", self->servo_id, 10 * self->pulse_cur); + mp_printf(print, "", self - &pyb_servo_obj[0] + 1, 10 * self->pulse_cur); } /// \classmethod \constructor(id) @@ -331,3 +330,5 @@ const mp_obj_type_t pyb_servo_type = { .make_new = pyb_servo_make_new, .locals_dict = (mp_obj_dict_t*)&pyb_servo_locals_dict, }; + +#endif // MICROPY_HW_ENABLE_SERVO diff --git a/stmhal/servo.h b/stmhal/servo.h index 0fca8fea1..c602a07da 100644 --- a/stmhal/servo.h +++ b/stmhal/servo.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_SERVO_H +#define MICROPY_INCLUDED_STMHAL_SERVO_H void servo_init(void); void servo_timer_irq_callback(void); @@ -31,3 +33,5 @@ extern const mp_obj_type_t pyb_servo_type; MP_DECLARE_CONST_FUN_OBJ_2(pyb_servo_set_obj); MP_DECLARE_CONST_FUN_OBJ_2(pyb_pwm_set_obj); + +#endif // MICROPY_INCLUDED_STMHAL_SERVO_H diff --git a/stmhal/spi.c b/stmhal/spi.c index b710fc3a7..d25e13f98 100644 --- a/stmhal/spi.c +++ b/stmhal/spi.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -765,7 +765,7 @@ STATIC mp_obj_t pyb_spi_send_recv(mp_uint_t n_args, const mp_obj_t *pos_args, mp // recv argument given mp_get_buffer_raise(args[1].u_obj, &bufinfo_recv, MP_BUFFER_WRITE); if (bufinfo_recv.len != bufinfo_send.len) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "recv must be same length as send")); + mp_raise_ValueError("recv must be same length as send"); } o_ret = args[1].u_obj; } diff --git a/stmhal/spi.h b/stmhal/spi.h index 5686bde64..eda109a7e 100644 --- a/stmhal/spi.h +++ b/stmhal/spi.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_SPI_H +#define MICROPY_INCLUDED_STMHAL_SPI_H extern SPI_HandleTypeDef SPIHandle1; extern SPI_HandleTypeDef SPIHandle2; @@ -37,3 +39,5 @@ extern const mp_obj_type_t machine_hard_spi_type; void spi_init0(void); void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin); SPI_HandleTypeDef *spi_get_handle(mp_obj_t o); + +#endif // MICROPY_INCLUDED_STMHAL_SPI_H diff --git a/stmhal/stm32_it.c b/stmhal/stm32_it.c index 357b6d79d..2111da1ae 100644 --- a/stmhal/stm32_it.c +++ b/stmhal/stm32_it.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * Original template from ST Cube library. See below for header. * diff --git a/stmhal/stm32_it.h b/stmhal/stm32_it.h index a168cda83..b498dee8d 100644 --- a/stmhal/stm32_it.h +++ b/stmhal/stm32_it.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * Original template from ST Cube library. See below for header. * @@ -25,6 +25,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_STM32_IT_H +#define MICROPY_INCLUDED_STMHAL_STM32_IT_H /** ****************************************************************************** @@ -80,3 +82,5 @@ void OTG_FS_IRQHandler(void); #ifdef USE_USB_HS void OTG_HS_IRQHandler(void); #endif + +#endif // MICROPY_INCLUDED_STMHAL_STM32_IT_H diff --git a/stmhal/storage.c b/stmhal/storage.c index 1931cd607..6da1ba95c 100644 --- a/stmhal/storage.c +++ b/stmhal/storage.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/storage.h b/stmhal/storage.h index 4d3de77ed..291e09a9a 100644 --- a/stmhal/storage.h +++ b/stmhal/storage.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_STORAGE_H +#define MICROPY_INCLUDED_STMHAL_STORAGE_H #define FLASH_BLOCK_SIZE (512) @@ -45,3 +47,5 @@ extern const struct _mp_obj_type_t pyb_flash_type; struct _fs_user_mount_t; void pyb_flash_init_vfs(struct _fs_user_mount_t *vfs); + +#endif // MICROPY_INCLUDED_STMHAL_STORAGE_H diff --git a/stmhal/system_stm32.c b/stmhal/system_stm32.c index a63bd3c57..7fc16b148 100644 --- a/stmhal/system_stm32.c +++ b/stmhal/system_stm32.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * Taken from ST Cube library and modified. See below for original header. * diff --git a/stmhal/systick.c b/stmhal/systick.c index 4eac583e2..c07d0fabc 100644 --- a/stmhal/systick.c +++ b/stmhal/systick.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/systick.h b/stmhal/systick.h index 1e7f62335..c1def50c2 100644 --- a/stmhal/systick.h +++ b/stmhal/systick.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_SYSTICK_H +#define MICROPY_INCLUDED_STMHAL_SYSTICK_H void sys_tick_wait_at_least(uint32_t stc, uint32_t delay_ms); bool sys_tick_has_passed(uint32_t stc, uint32_t delay_ms); + +#endif // MICROPY_INCLUDED_STMHAL_SYSTICK_H diff --git a/stmhal/timer.c b/stmhal/timer.c index 7db15f649..938e96597 100644 --- a/stmhal/timer.c +++ b/stmhal/timer.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -216,9 +216,11 @@ TIM_HandleTypeDef *timer_tim6_init(uint freq) { // Interrupt dispatch void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { + #if MICROPY_HW_ENABLE_SERVO if (htim == &TIM5_Handle) { servo_timer_irq_callback(); } + #endif } // Get the frequency (in Hz) of the source clock for the given timer. @@ -245,7 +247,7 @@ uint32_t timer_get_source_freq(uint32_t tim_id) { } /******************************************************************************/ -/* Micro Python bindings */ +/* MicroPython bindings */ STATIC const mp_obj_type_t pyb_timer_channel_type; @@ -276,7 +278,7 @@ STATIC uint32_t compute_prescaler_period_from_freq(pyb_timer_obj_t *self, mp_obj if (freq <= 0) { goto bad_freq; bad_freq: - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "must have positive freq")); + mp_raise_ValueError("must have positive freq"); } period = source_freq / freq; } @@ -427,7 +429,7 @@ STATIC void config_deadtime(pyb_timer_obj_t *self, mp_int_t ticks) { TIM_HandleTypeDef *pyb_timer_get_handle(mp_obj_t timer) { if (mp_obj_get_type(timer) != &pyb_timer_type) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "need a Timer object")); + mp_raise_ValueError("need a Timer object"); } pyb_timer_obj_t *self = timer; return &self->tim; @@ -539,7 +541,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, mp_uint_t n_args, c init->Prescaler = args[1].u_int; init->Period = args[2].u_int; } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "must specify either freq, or prescaler and period")); + mp_raise_TypeError("must specify either freq, or prescaler and period"); } init->CounterMode = args[3].u_int; @@ -889,7 +891,7 @@ STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp mp_obj_t pin_obj = args[2].u_obj; if (pin_obj != mp_const_none) { if (!MP_OBJ_IS_TYPE(pin_obj, &pin_type)) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "pin argument needs to be be a Pin type")); + mp_raise_ValueError("pin argument needs to be be a Pin type"); } const pin_obj_t *pin = pin_obj; const pin_af_obj_t *af = pin_find_af(pin, AF_FN_TIM, self->tim_id); @@ -1147,7 +1149,7 @@ STATIC mp_obj_t pyb_timer_period(mp_uint_t n_args, const mp_obj_t *args) { // Reset the counter to zero. Otherwise, if counter >= period it will // continue counting until it wraps (at either 16 or 32 bits depending // on the timer). - __HAL_TIM_SetCounter(&self->tim, 0); + __HAL_TIM_SetCounter(&self->tim, 0); return mp_const_none; } } @@ -1172,7 +1174,7 @@ STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback) { HAL_TIM_Base_Start_IT(&self->tim); // This will re-enable the IRQ HAL_NVIC_EnableIRQ(self->irqn); } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "callback must be None or a callable object")); + mp_raise_ValueError("callback must be None or a callable object"); } return mp_const_none; } @@ -1329,7 +1331,7 @@ STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback) break; } } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "callback must be None or a callable object")); + mp_raise_ValueError("callback must be None or a callable object"); } return mp_const_none; } diff --git a/stmhal/timer.h b/stmhal/timer.h index a18d7cf10..775accc3d 100644 --- a/stmhal/timer.h +++ b/stmhal/timer.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_TIMER_H +#define MICROPY_INCLUDED_STMHAL_TIMER_H extern TIM_HandleTypeDef TIM5_Handle; @@ -36,3 +38,5 @@ uint32_t timer_get_source_freq(uint32_t tim_id); void timer_irq_handler(uint tim_id); TIM_HandleTypeDef *pyb_timer_get_handle(mp_obj_t timer); + +#endif // MICROPY_INCLUDED_STMHAL_TIMER_H diff --git a/stmhal/uart.c b/stmhal/uart.c index 735c6f168..ddff8b9f2 100644 --- a/stmhal/uart.c +++ b/stmhal/uart.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -509,7 +509,7 @@ void uart_irq_handler(mp_uint_t uart_id) { } /******************************************************************************/ -/* Micro Python bindings */ +/* MicroPython bindings */ STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_uart_obj_t *self = self_in; @@ -656,7 +656,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_uint_t n_args, con self->read_buf_len = args.read_buf_len.u_int + 1; // +1 to adjust for usable length of buffer self->read_buf = m_new(byte, self->read_buf_len << self->char_width); __HAL_UART_ENABLE_IT(&self->uart, UART_IT_RXNE); - HAL_NVIC_SetPriority(self->irqn, IRQ_PRI_UART, IRQ_SUBPRI_UART); + HAL_NVIC_SetPriority(self->irqn, IRQ_PRI_UART, IRQ_SUBPRI_UART); HAL_NVIC_EnableIRQ(self->irqn); } diff --git a/stmhal/uart.h b/stmhal/uart.h index 7fdc59de7..e96b25b5f 100644 --- a/stmhal/uart.h +++ b/stmhal/uart.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_UART_H +#define MICROPY_INCLUDED_STMHAL_UART_H typedef enum { PYB_UART_NONE = 0, @@ -47,3 +49,5 @@ mp_uint_t uart_rx_any(pyb_uart_obj_t *uart_obj); int uart_rx_char(pyb_uart_obj_t *uart_obj); void uart_tx_strn(pyb_uart_obj_t *uart_obj, const char *str, uint len); void uart_tx_strn_cooked(pyb_uart_obj_t *uart_obj, const char *str, uint len); + +#endif // MICROPY_INCLUDED_STMHAL_UART_H diff --git a/stmhal/usb.c b/stmhal/usb.c index f70dea142..e2cbd6745 100644 --- a/stmhal/usb.c +++ b/stmhal/usb.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -169,7 +169,7 @@ void usb_vcp_send_strn_cooked(const char *str, int len) { } /******************************************************************************/ -// Micro Python bindings for USB +// MicroPython bindings for USB /* Philosophy of USB driver and Python API: pyb.usb_mode(...) configures the USB @@ -319,12 +319,12 @@ STATIC mp_obj_t pyb_usb_mode(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_ return mp_const_none; bad_mode: - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "bad USB mode")); + mp_raise_ValueError("bad USB mode"); } MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_mode_obj, 0, pyb_usb_mode); /******************************************************************************/ -// Micro Python bindings for USB VCP +// MicroPython bindings for USB VCP /// \moduleref pyb /// \class USB_VCP - USB virtual comm port @@ -525,7 +525,7 @@ const mp_obj_type_t pyb_usb_vcp_type = { }; /******************************************************************************/ -// Micro Python bindings for USB HID +// MicroPython bindings for USB HID typedef struct _pyb_usb_hid_obj_t { mp_obj_base_t base; @@ -590,7 +590,7 @@ STATIC mp_obj_t pyb_usb_hid_send(mp_obj_t self_in, mp_obj_t report_in) { mp_obj_t *items; mp_obj_get_array(report_in, &bufinfo.len, &items); if (bufinfo.len > sizeof(temp_buf)) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "tuple/list too large for HID report; use bytearray instead")); + mp_raise_ValueError("tuple/list too large for HID report; use bytearray instead"); } for (int i = 0; i < bufinfo.len; i++) { temp_buf[i] = mp_obj_get_int(items[i]); diff --git a/stmhal/usb.h b/stmhal/usb.h index 42e6c76f8..d39f49a6c 100644 --- a/stmhal/usb.h +++ b/stmhal/usb.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_USB_H +#define MICROPY_INCLUDED_STMHAL_USB_H #include "usbd_cdc_msc_hid0.h" @@ -67,3 +69,5 @@ void usb_vcp_send_strn_cooked(const char *str, int len); void pyb_usb_host_init(void); void pyb_usb_host_process(void); uint pyb_usb_host_get_keyboard(void); + +#endif // MICROPY_INCLUDED_STMHAL_USB_H diff --git a/stmhal/usbd_cdc_interface.c b/stmhal/usbd_cdc_interface.c index addcf8c85..3e107d418 100644 --- a/stmhal/usbd_cdc_interface.c +++ b/stmhal/usbd_cdc_interface.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * Taken from ST Cube library and heavily modified. See below for original * copyright header. @@ -23,8 +23,8 @@ * * http://www.st.com/software_license_agreement_liberty_v2 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. @@ -102,52 +102,14 @@ const USBD_CDC_ItfTypeDef USBD_CDC_fops = { * @param None * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL */ -static int8_t CDC_Itf_Init(USBD_HandleTypeDef *pdev) -{ -#if 0 - /*##-1- Configure the UART peripheral ######################################*/ - /* Put the USART peripheral in the Asynchronous mode (UART Mode) */ - /* USART configured as follow: - - Word Length = 8 Bits - - Stop Bit = One Stop bit - - Parity = No parity - - BaudRate = 115200 baud - - Hardware flow control disabled (RTS and CTS signals) */ - UartHandle.Instance = USARTx; - UartHandle.Init.BaudRate = 115200; - UartHandle.Init.WordLength = UART_WORDLENGTH_8B; - UartHandle.Init.StopBits = UART_STOPBITS_1; - UartHandle.Init.Parity = UART_PARITY_NONE; - UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; - UartHandle.Init.Mode = UART_MODE_TX_RX; - - if(HAL_UART_Init(&UartHandle) != HAL_OK) - { - /* Initialization Error */ - Error_Handler(); - } - - /*##-2- Put UART peripheral in IT reception process ########################*/ - /* Any data received will be stored in "UserTxBuffer" buffer */ - if(HAL_UART_Receive_IT(&UartHandle, (uint8_t *)UserTxBuffer, 1) != HAL_OK) - { - /* Transfer error in reception process */ - Error_Handler(); - } - - /*##-3- Configure the TIM Base generation #################################*/ - now done in HAL_MspInit - TIM_Config(); -#endif - - /*##-5- Set Application Buffers ############################################*/ +static int8_t CDC_Itf_Init(USBD_HandleTypeDef *pdev) { USBD_CDC_SetTxBuffer(pdev, UserTxBuffer, 0); USBD_CDC_SetRxBuffer(pdev, cdc_rx_packet_buf); cdc_rx_buf_put = 0; cdc_rx_buf_get = 0; - - return (USBD_OK); + + return USBD_OK; } /** @@ -156,22 +118,14 @@ static int8_t CDC_Itf_Init(USBD_HandleTypeDef *pdev) * @param None * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL */ -static int8_t CDC_Itf_DeInit(void) -{ -#if 0 - /* DeInitialize the UART peripheral */ - if(HAL_UART_DeInit(&UartHandle) != HAL_OK) - { - /* Initialization Error */ - } -#endif - return (USBD_OK); +static int8_t CDC_Itf_DeInit(void) { + return USBD_OK; } /** * @brief CDC_Itf_Control * Manage the CDC class requests - * @param Cmd: Command code + * @param Cmd: Command code * @param Buf: Buffer containing command data (request parameters) * @param Len: Number of data to be sent (in bytes) * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL @@ -210,16 +164,6 @@ static int8_t CDC_Itf_Control(uint8_t cmd, uint8_t* pbuf, uint16_t length) { break; case CDC_GET_LINE_CODING: - #if 0 - pbuf[0] = (uint8_t)(LineCoding.bitrate); - pbuf[1] = (uint8_t)(LineCoding.bitrate >> 8); - pbuf[2] = (uint8_t)(LineCoding.bitrate >> 16); - pbuf[3] = (uint8_t)(LineCoding.bitrate >> 24); - pbuf[4] = LineCoding.format; - pbuf[5] = LineCoding.paritytype; - pbuf[6] = LineCoding.datatype; - #endif - /* Add your code here */ pbuf[0] = (uint8_t)(115200); pbuf[1] = (uint8_t)(115200 >> 8); @@ -318,11 +262,6 @@ void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) { * free to modify it. */ static int8_t CDC_Itf_Receive(USBD_HandleTypeDef *pdev, uint8_t* Buf, uint32_t *Len) { -#if 0 - // this sends the data over the UART using DMA - HAL_UART_Transmit_DMA(&UartHandle, Buf, *Len); -#endif - // copy the incoming data into the circular buffer for (uint8_t *src = Buf, *top = Buf + *Len; src < top; ++src) { if (mp_interrupt_char != -1 && *src == mp_interrupt_char) { diff --git a/stmhal/usbd_cdc_interface.h b/stmhal/usbd_cdc_interface.h index d96861a7e..811a28928 100644 --- a/stmhal/usbd_cdc_interface.h +++ b/stmhal/usbd_cdc_interface.h @@ -1,6 +1,8 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ */ +#ifndef MICROPY_INCLUDED_STMHAL_USBD_CDC_INTERFACE_H +#define MICROPY_INCLUDED_STMHAL_USBD_CDC_INTERFACE_H /** ****************************************************************************** @@ -39,3 +41,5 @@ void USBD_CDC_TxAlways(const uint8_t *buf, uint32_t len); int USBD_CDC_RxNum(void); int USBD_CDC_Rx(uint8_t *buf, uint32_t len, uint32_t timeout); + +#endif // MICROPY_INCLUDED_STMHAL_USBD_CDC_INTERFACE_H diff --git a/stmhal/usbd_conf.c b/stmhal/usbd_conf.c index e2bd6c949..d39144851 100644 --- a/stmhal/usbd_conf.c +++ b/stmhal/usbd_conf.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ */ /** diff --git a/stmhal/usbd_conf.h b/stmhal/usbd_conf.h index b69ba52c2..34ebe27b9 100644 --- a/stmhal/usbd_conf.h +++ b/stmhal/usbd_conf.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ */ /** diff --git a/stmhal/usbd_desc.c b/stmhal/usbd_desc.c index 1ad960b46..09e1608c8 100644 --- a/stmhal/usbd_desc.c +++ b/stmhal/usbd_desc.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ */ /** diff --git a/stmhal/usbd_desc.h b/stmhal/usbd_desc.h index 93e222fc9..05cbbe5b1 100644 --- a/stmhal/usbd_desc.h +++ b/stmhal/usbd_desc.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,7 +23,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_USBD_DESC_H +#define MICROPY_INCLUDED_STMHAL_USBD_DESC_H extern const USBD_DescriptorsTypeDef USBD_Descriptors; void USBD_SetVIDPIDRelease(uint16_t vid, uint16_t pid, uint16_t device_release_num, int cdc_only); + +#endif // MICROPY_INCLUDED_STMHAL_USBD_DESC_H diff --git a/stmhal/usbd_hid_interface.h b/stmhal/usbd_hid_interface.h index fbc874796..b2ff75fa1 100644 --- a/stmhal/usbd_hid_interface.h +++ b/stmhal/usbd_hid_interface.h @@ -1,6 +1,8 @@ /* * This file is part of the MicroPython project, http://micropython.org/ */ +#ifndef MICROPY_INCLUDED_STMHAL_USBD_HID_INTERFACE_H +#define MICROPY_INCLUDED_STMHAL_USBD_HID_INTERFACE_H #include "usbd_cdc_msc_hid.h" @@ -8,3 +10,5 @@ extern const USBD_HID_ItfTypeDef USBD_HID_fops; int USBD_HID_RxNum(void); int USBD_HID_Rx(USBD_HandleTypeDef *pdev, uint8_t *buf, uint32_t len, uint32_t timeout); + +#endif // MICROPY_INCLUDED_STMHAL_USBD_HID_INTERFACE_H diff --git a/stmhal/usbd_msc_storage.c b/stmhal/usbd_msc_storage.c index cec973741..f825c3d70 100644 --- a/stmhal/usbd_msc_storage.c +++ b/stmhal/usbd_msc_storage.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ */ /** @@ -20,13 +20,13 @@ * * http://www.st.com/software_license_agreement_liberty_v2 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * - * Heavily modified by dpgeorge for Micro Python. + * Heavily modified by dpgeorge for MicroPython. * ****************************************************************************** */ @@ -134,13 +134,6 @@ int8_t FLASH_STORAGE_PreventAllowMediumRemoval(uint8_t lun, uint8_t param) { */ int8_t FLASH_STORAGE_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) { storage_read_blocks(buf, blk_addr, blk_len); - /* - for (int i = 0; i < blk_len; i++) { - if (!storage_read_block(buf + i * FLASH_BLOCK_SIZE, blk_addr + i)) { - return -1; - } - } - */ return 0; } @@ -154,13 +147,6 @@ int8_t FLASH_STORAGE_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t */ int8_t FLASH_STORAGE_Write (uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) { storage_write_blocks(buf, blk_addr, blk_len); - /* - for (int i = 0; i < blk_len; i++) { - if (!storage_write_block(buf + i * FLASH_BLOCK_SIZE, blk_addr + i)) { - return -1; - } - } - */ return 0; } @@ -213,20 +199,6 @@ static const int8_t SDCARD_STORAGE_Inquirydata[] = { // 36 bytes * @retval Status */ int8_t SDCARD_STORAGE_Init(uint8_t lun) { - /* -#ifndef USE_STM3210C_EVAL - NVIC_InitTypeDef NVIC_InitStructure; - NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); -#endif - if( SD_Init() != 0) - { - return (-1); - } - */ if (!sdcard_power_on()) { return -1; } @@ -243,20 +215,8 @@ int8_t SDCARD_STORAGE_Init(uint8_t lun) { * @retval Status */ int8_t SDCARD_STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size) { -/* -#ifdef USE_STM3210C_EVAL - SD_CardInfo SDCardInfo; - SD_GetCardInfo(&SDCardInfo); -#else - if(SD_GetStatus() != 0 ) { - return (-1); - } -#endif - */ - *block_size = SDCARD_BLOCK_SIZE; *block_num = sdcard_get_capacity_in_bytes() / SDCARD_BLOCK_SIZE; - return 0; } diff --git a/stmhal/usbd_msc_storage.h b/stmhal/usbd_msc_storage.h index 4a0d28ca8..6cc40d2d6 100644 --- a/stmhal/usbd_msc_storage.h +++ b/stmhal/usbd_msc_storage.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_USBD_MSC_STORAGE_H +#define MICROPY_INCLUDED_STMHAL_USBD_MSC_STORAGE_H extern const USBD_StorageTypeDef USBD_FLASH_STORAGE_fops; extern const USBD_StorageTypeDef USBD_SDCARD_STORAGE_fops; + +#endif // MICROPY_INCLUDED_STMHAL_USBD_MSC_STORAGE_H diff --git a/stmhal/usbdev/class/inc/usbd_cdc_msc_hid0.h b/stmhal/usbdev/class/inc/usbd_cdc_msc_hid0.h index bc9d0d21a..08882bb1a 100644 --- a/stmhal/usbdev/class/inc/usbd_cdc_msc_hid0.h +++ b/stmhal/usbdev/class/inc/usbd_cdc_msc_hid0.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef __MICROPY_INCLUDED_STMHAL_USB_CDC_MSC_HID0_H__ -#define __MICROPY_INCLUDED_STMHAL_USB_CDC_MSC_HID0_H__ +#ifndef MICROPY_INCLUDED_STMHAL_USBDEV_CLASS_INC_USBD_CDC_MSC_HID0_H +#define MICROPY_INCLUDED_STMHAL_USBDEV_CLASS_INC_USBD_CDC_MSC_HID0_H // these are exports for the CDC/MSC/HID interface that are independent // from any other definitions/declarations @@ -49,4 +48,4 @@ typedef struct _USBD_HID_ModeInfoTypeDef { const uint8_t *report_desc; } USBD_HID_ModeInfoTypeDef; -#endif // __MICROPY_INCLUDED_STMHAL_USB_CDC_MSC_HID0_H__ +#endif // MICROPY_INCLUDED_STMHAL_USBDEV_CLASS_INC_USBD_CDC_MSC_HID0_H diff --git a/stmhal/usbdev/class/src/usbd_cdc_msc_hid.c b/stmhal/usbdev/class/src/usbd_cdc_msc_hid.c index e0edf1370..d61073f4d 100644 --- a/stmhal/usbdev/class/src/usbd_cdc_msc_hid.c +++ b/stmhal/usbdev/class/src/usbd_cdc_msc_hid.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/stmhal/usrsw.c b/stmhal/usrsw.c index 63cd440d4..a7721ad77 100644 --- a/stmhal/usrsw.c +++ b/stmhal/usrsw.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -63,7 +63,7 @@ int switch_get(void) { } /******************************************************************************/ -// Micro Python bindings +// MicroPython bindings typedef struct _pyb_switch_obj_t { mp_obj_base_t base; diff --git a/stmhal/usrsw.h b/stmhal/usrsw.h index b6dff2c43..d96e3c281 100644 --- a/stmhal/usrsw.h +++ b/stmhal/usrsw.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_USRSW_H +#define MICROPY_INCLUDED_STMHAL_USRSW_H void switch_init0(void); int switch_get(void); extern const mp_obj_type_t pyb_switch_type; + +#endif // MICROPY_INCLUDED_STMHAL_USRSW_H diff --git a/stmhal/wdt.h b/stmhal/wdt.h index 362d6ef68..0a486f704 100644 --- a/stmhal/wdt.h +++ b/stmhal/wdt.h @@ -23,5 +23,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_STMHAL_WDT_H +#define MICROPY_INCLUDED_STMHAL_WDT_H extern const mp_obj_type_t pyb_wdt_type; + +#endif // MICROPY_INCLUDED_STMHAL_WDT_H diff --git a/teensy/Makefile b/teensy/Makefile index 575e15e54..944e281a4 100644 --- a/teensy/Makefile +++ b/teensy/Makefile @@ -4,7 +4,7 @@ include ../py/mkenv.mk QSTR_DEFS = qstrdefsport.h $(BUILD)/pins_qstr.h # include py core make definitions -include ../py/py.mk +include $(TOP)/py/py.mk # If you set USE_ARDUINO_TOOLCHAIN=1 then this makefile will attempt to use # the toolchain that comes with Teensyduino @@ -30,8 +30,8 @@ CFLAGS_TEENSY = -DF_CPU=96000000 -DUSB_SERIAL -D__MK20DX256__ CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -msoft-float -mfloat-abi=soft -fsingle-precision-constant -Wdouble-promotion $(CFLAGS_TEENSY) INC += -I. -INC += -I.. -INC += -I../stmhal +INC += -I$(TOP) +INC += -I$(TOP)/stmhal INC += -I$(BUILD) INC += -Icore @@ -135,7 +135,7 @@ SRC_C += \ OBJ += $(BUILD)/memzip-files.o -MAKE_MEMZIP = ../lib/memzip/make-memzip.py +MAKE_MEMZIP = $(TOP)/lib/memzip/make-memzip.py ifeq ($(MEMZIP_DIR),) MEMZIP_DIR = memzip_files endif @@ -232,4 +232,4 @@ $(BUILD)/%.pp: $(BUILD)/%.c $(ECHO) "PreProcess $<" $(Q)$(CC) $(CFLAGS) -E -Wp,-C,-dD,-dI -o $@ $< -include ../py/mkrules.mk +include $(TOP)/py/mkrules.mk diff --git a/teensy/README.md b/teensy/README.md index 3e4a75b9e..c586853b5 100644 --- a/teensy/README.md +++ b/teensy/README.md @@ -18,7 +18,7 @@ cd teensy ARDUINO=~/arduino-1.0.5 make ``` -To upload micropython to the Teensy 3.1. +To upload MicroPython to the Teensy 3.1. Press the Program button on the Teensy 3.1 ```bash diff --git a/teensy/hal_ftm.c b/teensy/hal_ftm.c index 28992881b..3c031bf6d 100644 --- a/teensy/hal_ftm.c +++ b/teensy/hal_ftm.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/teensy/hal_ftm.h b/teensy/hal_ftm.h index 3dc15300d..84fae8312 100644 --- a/teensy/hal_ftm.h +++ b/teensy/hal_ftm.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_TEENSY_HAL_FTM_H +#define MICROPY_INCLUDED_TEENSY_HAL_FTM_H #define FTM0 ((FTM_TypeDef *)&FTM0_SC) #define FTM1 ((FTM_TypeDef *)&FTM1_SC) @@ -181,4 +183,4 @@ void HAL_FTM_IC_Start(FTM_HandleTypeDef *hftm, uint32_t channel); void HAL_FTM_IC_Start_IT(FTM_HandleTypeDef *hftm, uint32_t channel); void HAL_FTM_IC_DeInit(FTM_HandleTypeDef *hftm); - +#endif // MICROPY_INCLUDED_TEENSY_HAL_FTM_H diff --git a/teensy/help.c b/teensy/help.c index 3b3916b94..ebe4bed6b 100644 --- a/teensy/help.c +++ b/teensy/help.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/teensy/led.c b/teensy/led.c index c7ac8be1f..c043e4399 100644 --- a/teensy/led.c +++ b/teensy/led.c @@ -81,7 +81,7 @@ void led_toggle(pyb_led_t led) { } /******************************************************************************/ -/* Micro Python bindings */ +/* MicroPython bindings */ void led_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_led_obj_t *self = self_in; diff --git a/teensy/led.h b/teensy/led.h index 7f4ba18f2..5c45166ef 100644 --- a/teensy/led.h +++ b/teensy/led.h @@ -1,3 +1,6 @@ +#ifndef MICROPY_INCLUDED_TEENSY_LED_H +#define MICROPY_INCLUDED_TEENSY_LED_H + typedef enum { PYB_LED_BUILTIN = 1, } pyb_led_t; @@ -7,3 +10,5 @@ void led_state(pyb_led_t led, int state); void led_toggle(pyb_led_t led); extern const mp_obj_type_t pyb_led_type; + +#endif // MICROPY_INCLUDED_TEENSY_LED_H diff --git a/teensy/lexermemzip.h b/teensy/lexermemzip.h index e5d4be5ea..cd7326a43 100644 --- a/teensy/lexermemzip.h +++ b/teensy/lexermemzip.h @@ -1,2 +1,6 @@ +#ifndef MICROPY_INCLUDED_TEENSY_LEXERMEMZIP_H +#define MICROPY_INCLUDED_TEENSY_LEXERMEMZIP_H + mp_lexer_t *mp_lexer_new_from_memzip_file(const char *filename); +#endif // MICROPY_INCLUDED_TEENSY_LEXERMEMZIP_H diff --git a/teensy/main.c b/teensy/main.c index 41bbeb5d9..3edaa28a0 100644 --- a/teensy/main.c +++ b/teensy/main.c @@ -266,7 +266,7 @@ int main(void) { // GC init gc_init(&_heap_start, (void*)HEAP_END); - // Micro Python init + // MicroPython init mp_init(); mp_obj_list_init(mp_sys_path, 0); mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script) diff --git a/teensy/modpyb.c b/teensy/modpyb.c index 9f601e327..deb1f32f9 100644 --- a/teensy/modpyb.c +++ b/teensy/modpyb.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -154,7 +154,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_sync_obj, pyb_sync); /// \function millis() /// Returns the number of milliseconds since the board was last reset. /// -/// The result is always a micropython smallint (31-bit signed number), so +/// The result is always a MicroPython smallint (31-bit signed number), so /// after 2^30 milliseconds (about 12.4 days) this will start to return /// negative numbers. STATIC mp_obj_t pyb_millis(void) { @@ -185,7 +185,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_millis_obj, pyb_elapsed_millis); /// \function micros() /// Returns the number of microseconds since the board was last reset. /// -/// The result is always a micropython smallint (31-bit signed number), so +/// The result is always a MicroPython smallint (31-bit signed number), so /// after 2^30 microseconds (about 17.8 minutes) this will start to return /// negative numbers. STATIC mp_obj_t pyb_micros(void) { diff --git a/teensy/mpconfigport.h b/teensy/mpconfigport.h index de30924d9..69cd69d53 100644 --- a/teensy/mpconfigport.h +++ b/teensy/mpconfigport.h @@ -1,6 +1,6 @@ #include -// options to control how Micro Python is built +// options to control how MicroPython is built #define MICROPY_ALLOC_PATH_MAX (128) #define MICROPY_EMIT_THUMB (1) diff --git a/teensy/reg.h b/teensy/reg.h index 5d1d27443..0da6378ee 100644 --- a/teensy/reg.h +++ b/teensy/reg.h @@ -1,3 +1,6 @@ +#ifndef MICROPY_INCLUDED_TEENSY_REG_H +#define MICROPY_INCLUDED_TEENSY_REG_H + typedef struct { const char *name; mp_uint_t offset; @@ -6,3 +9,5 @@ typedef struct { #define REG_ENTRY(st, name) { #name, offsetof(st, name) } mp_obj_t reg_cmd(void *base, reg_t *reg, mp_uint_t num_reg, uint n_args, const mp_obj_t *args); + +#endif // MICROPY_INCLUDED_TEENSY_REG_H diff --git a/teensy/servo.c b/teensy/servo.c index 6ccdb05e9..262daaeb6 100644 --- a/teensy/servo.c +++ b/teensy/servo.c @@ -217,7 +217,7 @@ mp_obj_t pyb_Servo(void) { self->servo_id++; } m_del_obj(pyb_servo_obj_t, self); - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "No available servo ids")); + mp_raise_ValueError("No available servo ids"); return mp_const_none; } diff --git a/teensy/servo.h b/teensy/servo.h index 5f1c87b69..1ad34353d 100644 --- a/teensy/servo.h +++ b/teensy/servo.h @@ -1,3 +1,6 @@ +#ifndef MICROPY_INCLUDED_TEENSY_SERVO_H +#define MICROPY_INCLUDED_TEENSY_SERVO_H + void servo_init(void); extern const mp_obj_type_t pyb_servo_type; @@ -5,3 +8,4 @@ extern const mp_obj_type_t pyb_servo_type; MP_DECLARE_CONST_FUN_OBJ_2(pyb_servo_set_obj); MP_DECLARE_CONST_FUN_OBJ_2(pyb_pwm_set_obj); +#endif // MICROPY_INCLUDED_TEENSY_SERVO_H diff --git a/teensy/std.h b/teensy/std.h index 42791877a..ef55d22dd 100644 --- a/teensy/std.h +++ b/teensy/std.h @@ -1,3 +1,6 @@ +#ifndef MICROPY_INCLUDED_TEENSY_STD_H +#define MICROPY_INCLUDED_TEENSY_STD_H + typedef unsigned int size_t; void __assert_func(void); @@ -18,3 +21,5 @@ char *strcat(char *dest, const char *src); int printf(const char *fmt, ...); int snprintf(char *str, size_t size, const char *fmt, ...); + +#endif // MICROPY_INCLUDED_TEENSY_STD_H diff --git a/teensy/teensy_hal.c b/teensy/teensy_hal.c index 4fcf99922..439e3380d 100644 --- a/teensy/teensy_hal.c +++ b/teensy/teensy_hal.c @@ -61,5 +61,5 @@ void mp_hal_gpio_clock_enable(GPIO_TypeDef *gpio) { } void extint_register_pin(const void *pin, uint32_t mode, int hard_irq, mp_obj_t callback_obj) { - mp_not_implemented(NULL); + mp_raise_NotImplementedError(NULL); } diff --git a/teensy/timer.c b/teensy/timer.c index 45bcc2b8f..6e578acc1 100644 --- a/teensy/timer.c +++ b/teensy/timer.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -119,7 +119,7 @@ mp_uint_t get_prescaler_shift(mp_int_t prescaler) { } /******************************************************************************/ -/* Micro Python bindings */ +/* MicroPython bindings */ STATIC const mp_obj_type_t pyb_timer_channel_type; @@ -255,7 +255,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, uint n_args, const // set prescaler and period from frequency if (vals[0].u_int == 0) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "can't have 0 frequency")); + mp_raise_ValueError("can't have 0 frequency"); } uint32_t period = MAX(1, F_BUS / vals[0].u_int); @@ -277,7 +277,7 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, uint n_args, const nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "period must be between 0 and 65535, not %d", init->Period)); } } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "must specify either freq, or prescaler and period")); + mp_raise_TypeError("must specify either freq, or prescaler and period"); } init->CounterMode = vals[3].u_int; @@ -498,7 +498,7 @@ STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *args, mp_map mp_obj_t pin_obj = vals[1].u_obj; if (pin_obj != mp_const_none) { if (!MP_OBJ_IS_TYPE(pin_obj, &pin_type)) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "pin argument needs to be be a Pin type")); + mp_raise_ValueError("pin argument needs to be be a Pin type"); } const pin_obj_t *pin = pin_obj; const pin_af_obj_t *af = pin_find_af(pin, AF_FN_FTM, self->tim_id); @@ -668,7 +668,7 @@ STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback) { // start timer, so that it interrupts on overflow HAL_FTM_Base_Start_IT(&self->ftm); } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "callback must be None or a callable object")); + mp_raise_ValueError("callback must be None or a callable object"); } return mp_const_none; } @@ -846,7 +846,7 @@ STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback) break; } } else { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "callback must be None or a callable object")); + mp_raise_ValueError("callback must be None or a callable object"); } return mp_const_none; } diff --git a/teensy/timer.h b/teensy/timer.h index bfa7636f4..75c2e654e 100644 --- a/teensy/timer.h +++ b/teensy/timer.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,8 +23,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_TEENSY_TIMER_H +#define MICROPY_INCLUDED_TEENSY_TIMER_H extern const mp_obj_type_t pyb_timer_type; void timer_init0(void); void timer_deinit(void); + +#endif // MICROPY_INCLUDED_TEENSY_TIMER_H diff --git a/teensy/uart.c b/teensy/uart.c index b4c0a4d5b..3dd2c5051 100644 --- a/teensy/uart.c +++ b/teensy/uart.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -221,7 +221,7 @@ void uart_tx_strn_cooked(pyb_uart_obj_t *uart_obj, const char *str, uint len) { } /******************************************************************************/ -/* Micro Python bindings */ +/* MicroPython bindings */ STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { pyb_uart_obj_t *self = self_in; diff --git a/teensy/usb.h b/teensy/usb.h index 949d7a59c..50fb3ff90 100644 --- a/teensy/usb.h +++ b/teensy/usb.h @@ -1,3 +1,6 @@ +#ifndef MICROPY_INCLUDED_TEENSY_USB_H +#define MICROPY_INCLUDED_TEENSY_USB_H + bool usb_vcp_is_connected(void); bool usb_vcp_is_enabled(void); int usb_vcp_rx_num(void); @@ -5,3 +8,5 @@ int usb_vcp_recv_byte(uint8_t *ptr); void usb_vcp_send_str(const char* str); void usb_vcp_send_strn(const char* str, int len); void usb_vcp_send_strn_cooked(const char *str, int len); + +#endif // MICROPY_INCLUDED_TEENSY_USB_H diff --git a/tests/README b/tests/README index b028cd062..3458f36a8 100644 --- a/tests/README +++ b/tests/README @@ -13,6 +13,6 @@ condition a test. The run-tests script uses small scripts in the feature_check directory to check whether each such feature is present, and skips the relevant tests if not. -When creating new tests, anything that relies on float support should go in the +When creating new tests, anything that relies on float support should go in the float/ subdirectory. Anything that relies on import x, where x is not a built-in module, should go in the import/ subdirectory. diff --git a/tests/basics/builtin_exec.py b/tests/basics/builtin_exec.py new file mode 100644 index 000000000..fd4e65c53 --- /dev/null +++ b/tests/basics/builtin_exec.py @@ -0,0 +1,32 @@ +print(exec("def foo(): return 42")) +print(foo()) + +d = {} +exec("def bar(): return 84", d) +print(d["bar"]()) + +# passing None/dict as args to globals/locals +foo = 11 +exec('print(foo)') +exec('print(foo)', None) +exec('print(foo)', {'foo':3}, None) +exec('print(foo)', None, {'foo':3}) +exec('print(foo)', None, {'bar':3}) +exec('print(foo)', {'bar':3}, locals()) + +try: + exec('print(foo)', {'bar':3}, None) +except NameError: + print('NameError') + +# invalid arg passed to globals +try: + exec('print(1)', 'foo') +except TypeError: + print('TypeError') + +# invalid arg passed to locals +try: + exec('print(1)', None, 123) +except TypeError: + print('TypeError') diff --git a/tests/basics/bytearray_slice_assign.py b/tests/basics/bytearray_slice_assign.py index 48f5938a5..7f7d1d119 100644 --- a/tests/basics/bytearray_slice_assign.py +++ b/tests/basics/bytearray_slice_assign.py @@ -4,7 +4,7 @@ print("SKIP") raise SystemExit -# test slices; only 2 argument version supported by Micro Python at the moment +# test slices; only 2 argument version supported by MicroPython at the moment x = bytearray(range(10)) # Assignment diff --git a/tests/basics/containment.py b/tests/basics/containment.py index bae366113..4c94a9bae 100644 --- a/tests/basics/containment.py +++ b/tests/basics/containment.py @@ -16,6 +16,17 @@ print(haystack, "in", needle, "::", haystack in needle) print(haystack, "not in", needle, "::", haystack not in needle) +# containment of bytes/ints in bytes +print(b'' in b'123') +print(b'0' in b'123', b'1' in b'123') +print(48 in b'123', 49 in b'123') + +# containment of int in str is an error +try: + 1 in '123' +except TypeError: + print('TypeError') + # until here, the tests would work without the 'second attempt' iteration thing. for i in 1, 2: diff --git a/tests/basics/exec1.py b/tests/basics/exec1.py deleted file mode 100644 index 59de5d69a..000000000 --- a/tests/basics/exec1.py +++ /dev/null @@ -1,6 +0,0 @@ -print(exec("def foo(): return 42")) -print(foo()) - -d = {} -exec("def bar(): return 84", d) -print(d["bar"]()) diff --git a/tests/basics/list_slice_assign.py b/tests/basics/list_slice_assign.py index 1ad1ef27c..885615717 100644 --- a/tests/basics/list_slice_assign.py +++ b/tests/basics/list_slice_assign.py @@ -1,4 +1,4 @@ -# test slices; only 2 argument version supported by Micro Python at the moment +# test slices; only 2 argument version supported by MicroPython at the moment x = list(range(10)) # Assignment diff --git a/tests/basics/struct1_intbig.py b/tests/basics/struct1_intbig.py index b1fec527e..380293f36 100644 --- a/tests/basics/struct1_intbig.py +++ b/tests/basics/struct1_intbig.py @@ -12,6 +12,8 @@ print(struct.pack("Q", 1)) print(struct.pack("Q", 2**64 - 1)) print(struct.pack(" 100) + s.close() + + +if __name__ == "__main__": + test(socket.getaddrinfo('micropython.org', 443)[0][-1]) diff --git a/tests/net_hosted/ssl_getpeercert.py.exp b/tests/net_hosted/ssl_getpeercert.py.exp new file mode 100644 index 000000000..ff7ef5adf --- /dev/null +++ b/tests/net_hosted/ssl_getpeercert.py.exp @@ -0,0 +1 @@ + True diff --git a/tests/run-bench-tests b/tests/run-bench-tests index 1e5e7804b..d48b4b7ec 100755 --- a/tests/run-bench-tests +++ b/tests/run-bench-tests @@ -26,7 +26,7 @@ def run_tests(pyb, test_dict): print(base_test + ":") for test_file in tests: - # run Micro Python + # run MicroPython if pyb is None: # run on PC try: diff --git a/tests/run-tests b/tests/run-tests index bd4a1363c..f9c26283d 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -388,7 +388,7 @@ def run_tests(pyb, tests, args, base_path="."): if args.write_exp: continue - # run Micro Python + # run MicroPython output_mupy = run_micropython(pyb, args, test_file) if output_mupy == b'SKIP\n': diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp index 390ff1669..ab638a632 100644 --- a/tests/unix/extra_coverage.py.exp +++ b/tests/unix/extra_coverage.py.exp @@ -25,7 +25,8 @@ ame__ __name__ path argv version version_info implementation platform byteorder maxsize exit stdin stdout -stderr modules exc_info print_exception +stderr modules exc_info getsizeof +print_exception ementation # attrtuple (start=1, stop=2, step=3) diff --git a/tools/codestats.sh b/tools/codestats.sh index c868199e1..5272f3e9c 100755 --- a/tools/codestats.sh +++ b/tools/codestats.sh @@ -28,9 +28,9 @@ bin_stmhal=stmhal/build-PYBV10/firmware.elf bin_barearm_1=bare-arm/build/flash.elf bin_barearm_2=bare-arm/build/firmware.elf bin_minimal=minimal/build/firmware.elf -bin_cc3200_1=cc3200/build/LAUNCHXL/application.axf -bin_cc3200_2=cc3200/build/LAUNCHXL/release/application.axf -bin_cc3200_3=cc3200/build/WIPY/release/application.axf +bin_cc3200_1=cc3200/build/LAUNCHXL/application.axf +bin_cc3200_2=cc3200/build/LAUNCHXL/release/application.axf +bin_cc3200_3=cc3200/build/WIPY/release/application.axf # start at zero size; if build fails reuse previous valid size size_unix="0" diff --git a/tools/gen-cpydiff.py b/tools/gen-cpydiff.py index 86ec816e9..aff5b56e7 100644 --- a/tools/gen-cpydiff.py +++ b/tools/gen-cpydiff.py @@ -33,7 +33,7 @@ import re from collections import namedtuple -# Micropython supports syntax of CPython 3.4 with some features from 3.5, and +# MicroPython supports syntax of CPython 3.4 with some features from 3.5, and # such version should be used to test for differences. If your default python3 # executable is of lower version, you can point MICROPY_CPYTHON3 environment var # to the correct executable. diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 544f90cc8..ded962487 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -239,7 +239,7 @@ def _unpack_qstr(self, ip): def dump(self): # dump children first for rc in self.raw_codes: - rc.freeze() + rc.freeze('') # TODO def freeze(self, parent_name): @@ -331,27 +331,29 @@ def freeze(self, parent_name): # TODO raise FreezeError(self, 'freezing of object %r is not implemented' % (obj,)) - # generate constant table - print('STATIC const mp_rom_obj_t const_table_data_%s[%u] = {' - % (self.escaped_name, len(self.qstrs) + len(self.objs) + len(self.raw_codes))) - for qst in self.qstrs: - print(' MP_ROM_QSTR(%s),' % global_qstrs[qst].qstr_id) - for i in range(len(self.objs)): - if type(self.objs[i]) is float: - print('#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B') - print(' MP_ROM_PTR(&const_obj_%s_%u),' % (self.escaped_name, i)) - print('#elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C') - n = struct.unpack('fd < 0) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "I/O operation on closed file")); + mp_raise_ValueError("I/O operation on closed file"); } } #else diff --git a/unix/gccollect.c b/unix/gccollect.c index 4ec8c2bf5..02f6fc91a 100644 --- a/unix/gccollect.c +++ b/unix/gccollect.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/unix/gfxconf.h b/unix/gfxconf.h index b0add4701..ea5334f37 100644 --- a/unix/gfxconf.h +++ b/unix/gfxconf.h @@ -87,7 +87,7 @@ //#define GDISP_NEED_ARCSECTORS FALSE #define GDISP_NEED_CONVEX_POLYGON TRUE //#define GDISP_NEED_SCROLL FALSE -//#define GDISP_NEED_PIXELREAD FALSE +#define GDISP_NEED_PIXELREAD TRUE #define GDISP_NEED_CONTROL TRUE //#define GDISP_NEED_QUERY FALSE //#define GDISP_NEED_MULTITHREAD FALSE @@ -97,7 +97,7 @@ #define GDISP_NEED_TEXT_WORDWRAP TRUE // #define GDISP_NEED_TEXT_BOXPADLR 1 // #define GDISP_NEED_TEXT_BOXPADTB 1 -// #define GDISP_NEED_ANTIALIAS FALSE +#define GDISP_NEED_ANTIALIAS TRUE #define GDISP_NEED_UTF8 TRUE // #define GDISP_NEED_TEXT_KERNING FALSE // #define GDISP_INCLUDE_FONT_UI1 FALSE diff --git a/unix/input.c b/unix/input.c index 4b10350df..7d60b46cc 100644 --- a/unix/input.c +++ b/unix/input.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/unix/input.h b/unix/input.h index 7cbee33c5..a76b87e64 100644 --- a/unix/input.h +++ b/unix/input.h @@ -1,3 +1,8 @@ +#ifndef MICROPY_INCLUDED_UNIX_INPUT_H +#define MICROPY_INCLUDED_UNIX_INPUT_H + char *prompt(char *p); void prompt_read_history(void); void prompt_write_history(void); + +#endif // MICROPY_INCLUDED_UNIX_INPUT_H diff --git a/unix/main.c b/unix/main.c index 633144c86..e861d7f11 100644 --- a/unix/main.c +++ b/unix/main.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/unix/modbadge.c b/unix/modbadge.c index d7fa25d7a..6d7d344bd 100644 --- a/unix/modbadge.c +++ b/unix/modbadge.c @@ -235,3 +235,5 @@ const mp_obj_module_t mock_badge_module = { .base = {&mp_type_module}, .globals = (mp_obj_dict_t *)&mock_badge_module_globals, }; + +bool ugfx_screen_flipped = false; diff --git a/unix/modffi.c b/unix/modffi.c index 8b392f1c3..9b514371b 100644 --- a/unix/modffi.c +++ b/unix/modffi.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -409,7 +409,7 @@ STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const } error: - nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "Don't know how to pass object to native function")); + mp_raise_TypeError("Don't know how to pass object to native function"); } STATIC const mp_obj_type_t ffifunc_type = { diff --git a/unix/modfreedomgfx.c b/unix/modfreedomgfx.c new file mode 120000 index 000000000..aaa14873d --- /dev/null +++ b/unix/modfreedomgfx.c @@ -0,0 +1 @@ +../esp32/modfreedomgfx.c \ No newline at end of file diff --git a/unix/modfreedomgfx.h b/unix/modfreedomgfx.h new file mode 120000 index 000000000..7f4fd1ff5 --- /dev/null +++ b/unix/modfreedomgfx.h @@ -0,0 +1 @@ +../esp32/modfreedomgfx.h \ No newline at end of file diff --git a/unix/modfreedomgfx_sdl.c b/unix/modfreedomgfx_sdl.c new file mode 100644 index 000000000..464027397 --- /dev/null +++ b/unix/modfreedomgfx_sdl.c @@ -0,0 +1,97 @@ +/* + * This file is part of the SHA2017 Micro Python fork + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Christian Carlowitz + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "modfreedomgfx_sdl.h" +#include +#include +#include +#include + +SDL_Window* win; +SDL_Renderer* ren; +SDL_Texture* tex; + +static uint8_t img[BADGE_EINK_WIDTH*BADGE_EINK_HEIGHT]; + +uint8_t* freedomgfxInit(void) +{ + SDL_Init(SDL_INIT_VIDEO); + win = SDL_CreateWindow("Freedom GFX", 100, 100, BADGE_EINK_WIDTH, BADGE_EINK_HEIGHT, SDL_WINDOW_SHOWN); + ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); + tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_RGB332, SDL_TEXTUREACCESS_STREAMING, BADGE_EINK_WIDTH, BADGE_EINK_HEIGHT); + return img; +} + +void freedomgfxDeinit(void) +{ + SDL_DestroyRenderer(ren); + SDL_DestroyWindow(win); + SDL_Quit(); +} + +uint32_t freedomgfxPoll(void) +{ + SDL_Event evt; + if(SDL_PollEvent(&evt)) + { + if(evt.type == SDL_KEYDOWN) + { + switch(evt.key.keysym.sym) + { + case 'a': + return BADGE_BUTTON_A; + case 'b': + return BADGE_BUTTON_B; + case 's': + return BADGE_BUTTON_START; + case 'S': + return BADGE_BUTTON_SELECT; + case SDLK_UP: + return BADGE_BUTTON_UP; + case SDLK_DOWN: + return BADGE_BUTTON_DOWN; + case SDLK_LEFT: + return BADGE_BUTTON_LEFT; + case SDLK_RIGHT: + return BADGE_BUTTON_RIGHT; + } + } + } + return 0; +} + +void freedomgfxDraw() +{ + uint8_t* px; + int pitch; + SDL_LockTexture(tex,0,(void**)&px,&pitch); + for(int i = 0; i < BADGE_EINK_WIDTH*BADGE_EINK_HEIGHT; i++) + px[i] = img[i]; + SDL_UnlockTexture(tex); + SDL_RenderCopy(ren,tex,0,0); + SDL_RenderPresent(ren); +} + diff --git a/unix/modfreedomgfx_sdl.h b/unix/modfreedomgfx_sdl.h new file mode 100644 index 000000000..fb793c050 --- /dev/null +++ b/unix/modfreedomgfx_sdl.h @@ -0,0 +1,37 @@ +/* + * This file is part of the SHA2017 Micro Python fork + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Christian Carlowitz + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef UNIX_MODFREEDOMGFX_SDL_H_ +#define UNIX_MODFREEDOMGFX_SDL_H_ + +#include + +uint8_t* freedomgfxInit(void); +void freedomgfxDeinit(void); +uint32_t freedomgfxPoll(void); +void freedomgfxDraw(); + +#endif /* UNIX_MODFREEDOMGFX_SDL_H_ */ diff --git a/unix/modjni.c b/unix/modjni.c index 0aeb0601f..df9cd9d67 100644 --- a/unix/modjni.c +++ b/unix/modjni.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -168,9 +168,9 @@ STATIC mp_obj_t jclass_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const return call_method(self->cls, NULL, methods, true, n_args, args); } -STATIC const mp_map_elem_t jclass_locals_dict_table[] = { -// { MP_OBJ_NEW_QSTR(MP_QSTR_get), (mp_obj_t)&ffivar_get_obj }, -// { MP_OBJ_NEW_QSTR(MP_QSTR_set), (mp_obj_t)&ffivar_set_obj }, +STATIC const mp_rom_map_elem_t jclass_locals_dict_table[] = { +// { MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&ffivar_get_obj) }, +// { MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&ffivar_set_obj) }, }; STATIC MP_DEFINE_CONST_DICT(jclass_locals_dict, jclass_locals_dict_table); @@ -181,7 +181,7 @@ STATIC const mp_obj_type_t jclass_type = { .print = jclass_print, .attr = jclass_attr, .call = jclass_call, - .locals_dict = (mp_obj_t)&jclass_locals_dict, + .locals_dict = (mp_obj_dict_t*)&jclass_locals_dict, }; STATIC mp_obj_t new_jclass(jclass jc) { @@ -268,7 +268,7 @@ STATIC mp_obj_t jobject_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) return mp_const_none; } } - mp_not_implemented(""); + mp_raise_NotImplementedError(""); } if (!JJ(IsInstanceOf, self->obj, List_class)) { @@ -331,7 +331,7 @@ STATIC const mp_obj_type_t jobject_type = { .attr = jobject_attr, .subscr = jobject_subscr, .getiter = subscr_getiter, -// .locals_dict = (mp_obj_t)&jobject_locals_dict, +// .locals_dict = (mp_obj_dict_t*)&jobject_locals_dict, }; STATIC mp_obj_t new_jobject(jobject jo) { @@ -578,7 +578,7 @@ STATIC const mp_obj_type_t jmethod_type = { .print = jmethod_print, .call = jmethod_call, // .attr = jobject_attr, -// .locals_dict = (mp_obj_t)&jobject_locals_dict, +// .locals_dict = (mp_obj_dict_t*)&jobject_locals_dict, }; #ifdef __ANDROID__ @@ -707,11 +707,11 @@ STATIC mp_obj_t mod_jni_env() { } MP_DEFINE_CONST_FUN_OBJ_0(mod_jni_env_obj, mod_jni_env); -STATIC const mp_map_elem_t mp_module_jni_globals_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_jni) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_cls), (mp_obj_t)&mod_jni_cls_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_array), (mp_obj_t)&mod_jni_array_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_env), (mp_obj_t)&mod_jni_env_obj }, +STATIC const mp_rom_map_elem_t mp_module_jni_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_jni) }, + { MP_ROM_QSTR(MP_QSTR_cls), MP_ROM_PTR(&mod_jni_cls_obj) }, + { MP_ROM_QSTR(MP_QSTR_array), MP_ROM_PTR(&mod_jni_array_obj) }, + { MP_ROM_QSTR(MP_QSTR_env), MP_ROM_PTR(&mod_jni_env_obj) }, }; STATIC MP_DEFINE_CONST_DICT(mp_module_jni_globals, mp_module_jni_globals_table); diff --git a/unix/modmachine.c b/unix/modmachine.c index 33a3b098e..48dddec0a 100644 --- a/unix/modmachine.c +++ b/unix/modmachine.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/unix/modos.c b/unix/modos.c index a090bc3f7..f096e88f5 100644 --- a/unix/modos.c +++ b/unix/modos.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -25,6 +25,7 @@ * THE SOFTWARE. */ +#include #include #include #include @@ -240,6 +241,17 @@ STATIC mp_obj_t mod_os_errno(size_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_os_errno_obj, 0, 1, mod_os_errno); +STATIC mp_obj_t os_urandom(mp_obj_t num) { + mp_int_t n = mp_obj_get_int(num); + vstr_t vstr; + vstr_init_len(&vstr, n); + FILE *fp = fopen("/dev/urandom", "r"); + fread(vstr.buf, 1, n, fp); + fclose(fp); + return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_urandom_obj, os_urandom); + STATIC const mp_rom_map_elem_t mp_module_os_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uos) }, { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mod_os_errno_obj) }, @@ -253,6 +265,7 @@ STATIC const mp_rom_map_elem_t mp_module_os_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&mod_os_mkdir_obj) }, { MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&mod_os_listdir_obj) }, { MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&mod_os_ilistdir_obj) }, + { MP_ROM_QSTR(MP_QSTR_urandom), MP_ROM_PTR(&os_urandom_obj) }, #if MICROPY_PY_OS_DUPTERM { MP_ROM_QSTR(MP_QSTR_dupterm), MP_ROM_PTR(&mp_uos_dupterm_obj) }, #endif diff --git a/unix/modsocket.c b/unix/modsocket.c index c7be6461e..c612f870d 100644 --- a/unix/modsocket.c +++ b/unix/modsocket.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -391,7 +391,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_htons_obj, mod_socket_htons); STATIC mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) { - assert(MP_OBJ_IS_TYPE(arg, &mp_type_str)); const char *s = mp_obj_str_get_str(arg); struct hostent *h = gethostbyname(s); if (h == NULL) { @@ -441,9 +440,7 @@ STATIC mp_obj_t mod_socket_inet_ntop(mp_obj_t family_in, mp_obj_t binaddr_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_socket_inet_ntop_obj, mod_socket_inet_ntop); STATIC mp_obj_t mod_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) { - // TODO: Implement all args - assert(n_args >= 2 && n_args <= 4); - assert(MP_OBJ_IS_STR(args[0])); + // TODO: Implement 5th and 6th args const char *host = mp_obj_str_get_str(args[0]); const char *serv = NULL; @@ -510,7 +507,7 @@ STATIC mp_obj_t mod_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) { freeaddrinfo(addr_list); return list; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 6, mod_socket_getaddrinfo); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 4, mod_socket_getaddrinfo); STATIC mp_obj_t mod_socket_sockaddr(mp_obj_t sockaddr_in) { mp_buffer_info_t bufinfo; diff --git a/unix/modtermios.c b/unix/modtermios.c index 5e82e772a..fe19aac83 100644 --- a/unix/modtermios.c +++ b/unix/modtermios.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/unix/modtime.c b/unix/modtime.c index 2a6487df2..a74b81f37 100644 --- a/unix/modtime.c +++ b/unix/modtime.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/unix/moduselect.c b/unix/moduselect.c index 37a3a33b2..ba1c195ef 100644 --- a/unix/moduselect.c +++ b/unix/moduselect.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index 03f6646f2..0d99bd5cd 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -// options to control how Micro Python is built +// options to control how MicroPython is built #define MICROPY_ENABLE_SCHEDULER (1) #define MICROPY_ALLOC_PATH_MAX (PATH_MAX) @@ -179,6 +179,7 @@ extern const struct _mp_obj_module_t mp_module_jni; extern const struct _mp_obj_module_t mock_esp_network_module; extern const struct _mp_obj_module_t mock_badge_module; extern const struct _mp_obj_module_t ugfx_module; +extern const struct _mp_obj_module_t freedomgfx_module; #if MICROPY_PY_UOS_VFS #define MICROPY_PY_UOS_VFS_DEF { MP_ROM_QSTR(MP_QSTR_uos_vfs), MP_ROM_PTR(&mp_module_uos_vfs) }, @@ -227,6 +228,7 @@ extern const struct _mp_obj_module_t ugfx_module; MICROPY_PY_USELECT_DEF \ MICROPY_PY_TERMIOS_DEF \ { MP_OBJ_NEW_QSTR(MP_QSTR_ugfx), (mp_obj_t)&ugfx_module }, \ + { MP_OBJ_NEW_QSTR(MP_QSTR_freedomgfx), (mp_obj_t)&freedomgfx_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_network), (mp_obj_t)&mock_esp_network_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_badge), (mp_obj_t)&mock_badge_module }, \ diff --git a/unix/mpconfigport_coverage.h b/unix/mpconfigport_coverage.h index 5fc8d7107..a9e0a38fa 100644 --- a/unix/mpconfigport_coverage.h +++ b/unix/mpconfigport_coverage.h @@ -37,6 +37,7 @@ #define MICROPY_PY_DELATTR_SETATTR (1) #define MICROPY_PY_BUILTINS_HELP (1) #define MICROPY_PY_BUILTINS_HELP_MODULES (1) +#define MICROPY_PY_SYS_GETSIZEOF (1) #define MICROPY_PY_URANDOM_EXTRA_FUNCS (1) #define MICROPY_PY_IO_BUFFEREDWRITER (1) #undef MICROPY_VFS_FAT diff --git a/unix/mpconfigport_fast.h b/unix/mpconfigport_fast.h index b5be9f334..442159eb4 100644 --- a/unix/mpconfigport_fast.h +++ b/unix/mpconfigport_fast.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/unix/mpconfigport_minimal.h b/unix/mpconfigport_minimal.h index b4d9f8143..e37605eab 100644 --- a/unix/mpconfigport_minimal.h +++ b/unix/mpconfigport_minimal.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -// options to control how Micro Python is built +// options to control how MicroPython is built #define MICROPY_ALLOC_QSTR_CHUNK_INIT (64) #define MICROPY_ALLOC_PARSE_RULE_INIT (8) diff --git a/unix/mphalport.h b/unix/mphalport.h index cf227872f..ff7a51567 100644 --- a/unix/mphalport.h +++ b/unix/mphalport.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/unix/mpthreadport.h b/unix/mpthreadport.h index 51cf8d786..b158ed5bc 100644 --- a/unix/mpthreadport.h +++ b/unix/mpthreadport.h @@ -23,8 +23,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef __MICROPY_INCLUDED_UNIX_MPTHREADPORT_H__ -#define __MICROPY_INCLUDED_UNIX_MPTHREADPORT_H__ #include @@ -32,5 +30,3 @@ typedef pthread_mutex_t mp_thread_mutex_t; void mp_thread_init(void); void mp_thread_gc_others(void); - -#endif // __MICROPY_INCLUDED_UNIX_MPTHREADPORT_H__ diff --git a/unix/qstrdefsport.h b/unix/qstrdefsport.h index 8ab2db58f..ebfaa6cca 100644 --- a/unix/qstrdefsport.h +++ b/unix/qstrdefsport.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/unix/unix_mphal.c b/unix/unix_mphal.c index 800484498..02cdbea11 100644 --- a/unix/unix_mphal.c +++ b/unix/unix_mphal.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/windows/Makefile b/windows/Makefile index 72c97381b..a39d34826 100644 --- a/windows/Makefile +++ b/windows/Makefile @@ -8,10 +8,10 @@ PROG = micropython.exe QSTR_DEFS = ../unix/qstrdefsport.h # include py core make definitions -include ../py/py.mk +include $(TOP)/py/py.mk INC += -I. -INC += -I.. +INC += -I$(TOP) INC += -I$(BUILD) # compiler settings @@ -62,4 +62,4 @@ SRC_QSTR += $(SRC_C) # SRC_QSTR SRC_QSTR_AUTO_DEPS += -include ../py/mkrules.mk +include $(TOP)/py/mkrules.mk diff --git a/windows/fmode.h b/windows/fmode.h index 23d6d3d54..c661c84d0 100644 --- a/windows/fmode.h +++ b/windows/fmode.h @@ -23,9 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ - -#ifndef __MICROPY_INCLUDED_WINDOWS_FMODE_H__ -#define __MICROPY_INCLUDED_WINDOWS_FMODE_H__ +#ifndef MICROPY_INCLUDED_WINDOWS_FMODE_H +#define MICROPY_INCLUDED_WINDOWS_FMODE_H // Treat files opened by open() as binary. No line ending translation is done. void set_fmode_binary(void); @@ -35,4 +34,4 @@ void set_fmode_binary(void); // When writing to the file \n will be converted into \r\n. void set_fmode_text(void); -#endif +#endif // MICROPY_INCLUDED_WINDOWS_FMODE_H diff --git a/windows/init.c b/windows/init.c index 669092347..09fa10417 100644 --- a/windows/init.c +++ b/windows/init.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/windows/init.h b/windows/init.h index 69e577689..c6fddb257 100644 --- a/windows/init.h +++ b/windows/init.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_WINDOWS_INIT_H +#define MICROPY_INCLUDED_WINDOWS_INIT_H void init(void); void deinit(void); + +#endif // MICROPY_INCLUDED_WINDOWS_INIT_H diff --git a/windows/mpconfigport.h b/windows/mpconfigport.h index f2f6cbd32..c4e6ba131 100644 --- a/windows/mpconfigport.h +++ b/windows/mpconfigport.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -// options to control how Micro Python is built +// options to control how MicroPython is built // Linking with GNU readline (MICROPY_USE_READLINE == 2) causes binary to be licensed under GPL #ifndef MICROPY_USE_READLINE diff --git a/windows/msvc/dirent.h b/windows/msvc/dirent.h index 6172913ee..fca06785a 100644 --- a/windows/msvc/dirent.h +++ b/windows/msvc/dirent.h @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_WINDOWS_MSVC_DIRENT_H +#define MICROPY_INCLUDED_WINDOWS_MSVC_DIRENT_H // dirent.h implementation for msvc @@ -42,3 +44,5 @@ typedef struct dirent { DIR *opendir(const char *name); int closedir(DIR *dir); struct dirent *readdir(DIR *dir); + +#endif // MICROPY_INCLUDED_WINDOWS_MSVC_DIRENT_H diff --git a/windows/msvc/gettimeofday.c b/windows/msvc/gettimeofday.c index 363d59d7b..5f816df70 100644 --- a/windows/msvc/gettimeofday.c +++ b/windows/msvc/gettimeofday.c @@ -1,5 +1,5 @@ /* -* This file is part of the Micro Python project, http://micropython.org/ +* This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -43,7 +43,7 @@ int gettimeofday(struct timeval *tp, struct timezone *tz) { // to microseconds ft.tm /= 10; - + // convert to unix format // number of microseconds intervals between the 1st january 1601 and the 1st january 1970 (369 years + 89 leap days) const unsigned __int64 deltaEpoch = 11644473600000000ull; diff --git a/windows/msvc/sys/time.h b/windows/msvc/sys/time.h index 96bca1ccb..7c95d409e 100644 --- a/windows/msvc/sys/time.h +++ b/windows/msvc/sys/time.h @@ -1,5 +1,5 @@ /* -* This file is part of the Micro Python project, http://micropython.org/ +* This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_WINDOWS_MSVC_SYS_TIME_H +#define MICROPY_INCLUDED_WINDOWS_MSVC_SYS_TIME_H // Get the definitions for timeval etc #include + +#endif // MICROPY_INCLUDED_WINDOWS_MSVC_SYS_TIME_H diff --git a/windows/msvc/unistd.h b/windows/msvc/unistd.h index add10c884..1a1629be4 100644 --- a/windows/msvc/unistd.h +++ b/windows/msvc/unistd.h @@ -1,5 +1,5 @@ /* -* This file is part of the Micro Python project, http://micropython.org/ +* This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_WINDOWS_MSVC_UNISTD_H +#define MICROPY_INCLUDED_WINDOWS_MSVC_UNISTD_H // There's no unistd.h, but this is the equivalent #include @@ -38,3 +40,5 @@ #define SEEK_CUR 1 #define SEEK_END 2 #define SEEK_SET 0 + +#endif // MICROPY_INCLUDED_WINDOWS_MSVC_UNISTD_H diff --git a/windows/realpath.c b/windows/realpath.c index c0ed6b84d..ac9adf812 100644 --- a/windows/realpath.c +++ b/windows/realpath.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/windows/realpath.h b/windows/realpath.h index 6f0a29a7e..869fe80fa 100644 --- a/windows/realpath.h +++ b/windows/realpath.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,5 +23,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_WINDOWS_REALPATH_H +#define MICROPY_INCLUDED_WINDOWS_REALPATH_H extern char *realpath(const char *path, char *resolved_path); + +#endif // MICROPY_INCLUDED_WINDOWS_REALPATH_H diff --git a/windows/sleep.c b/windows/sleep.c index 214d6d622..6043ec7b7 100644 --- a/windows/sleep.c +++ b/windows/sleep.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -31,7 +31,7 @@ HANDLE waitTimer = NULL; void init_sleep(void) { - waitTimer = CreateWaitableTimer(NULL, TRUE, NULL); + waitTimer = CreateWaitableTimer(NULL, TRUE, NULL); } void deinit_sleep(void) { diff --git a/windows/sleep.h b/windows/sleep.h index 09ad4afdc..430ec3a43 100644 --- a/windows/sleep.h +++ b/windows/sleep.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * @@ -23,6 +23,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#ifndef MICROPY_INCLUDED_WINDOWS_SLEEP_H +#define MICROPY_INCLUDED_WINDOWS_SLEEP_H void init_sleep(void); void deinit_sleep(void); @@ -30,3 +32,5 @@ void msec_sleep(double msec); #ifdef _MSC_VER int usleep(__int64 usec); #endif + +#endif // MICROPY_INCLUDED_WINDOWS_SLEEP_H diff --git a/windows/windows_mphal.c b/windows/windows_mphal.c index a73140e54..153b04423 100644 --- a/windows/windows_mphal.c +++ b/windows/windows_mphal.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/windows/windows_mphal.h b/windows/windows_mphal.h index 854e14a7a..5a93d4e18 100644 --- a/windows/windows_mphal.h +++ b/windows/windows_mphal.h @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/zephyr/Makefile b/zephyr/Makefile index c1337adf0..5840cc47e 100644 --- a/zephyr/Makefile +++ b/zephyr/Makefile @@ -17,6 +17,9 @@ OUTDIR_PREFIX = $(BOARD) MICROPY_HEAP_SIZE = 16384 FROZEN_DIR = scripts +# Default target +all: + # Zephyr (generated) config files - must be defined before include below Z_EXPORTS = outdir/$(OUTDIR_PREFIX)/Makefile.export ifneq ($(MAKECMDGOALS), clean) @@ -24,10 +27,10 @@ include $(Z_EXPORTS) endif include ../py/mkenv.mk -include ../py/py.mk +include $(TOP)/py/py.mk INC += -I. -INC += -I.. +INC += -I$(TOP) INC += -I$(BUILD) INC += -I$(ZEPHYR_BASE)/net/ip INC += -I$(ZEPHYR_BASE)/net/ip/contiki @@ -56,7 +59,7 @@ OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) CFLAGS = $(KBUILD_CFLAGS) $(NOSTDINC_FLAGS) $(ZEPHYRINCLUDE) \ -std=gnu99 -fomit-frame-pointer -DNDEBUG -DMICROPY_HEAP_SIZE=$(MICROPY_HEAP_SIZE) $(CFLAGS_EXTRA) $(INC) -include ../py/mkrules.mk +include $(TOP)/py/mkrules.mk # We use single target here ($(Z_EXPORTS)) for simplicity, but actually # number of things get generated here: 'initconfig' generates C header for @@ -99,4 +102,4 @@ prj_$(BOARD)_merged.conf: prj_base.conf prj_$(BOARD).conf $(PYTHON) makeprj.py prj_base.conf prj_$(BOARD).conf $@ test: - cd ../tests && ./run-tests --target minimal --device "execpty:make -C ../zephyr run BOARD=$(BOARD) QEMU_PTY=1" + cd $(TOP)/tests && ./run-tests --target minimal --device "execpty:make -C ../zephyr run BOARD=$(BOARD) QEMU_PTY=1" diff --git a/zephyr/machine_pin.c b/zephyr/machine_pin.c index 38971399c..c3722926a 100644 --- a/zephyr/machine_pin.c +++ b/zephyr/machine_pin.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/zephyr/modmachine.h b/zephyr/modmachine.h index 596c59b17..84e4d10a8 100644 --- a/zephyr/modmachine.h +++ b/zephyr/modmachine.h @@ -1,5 +1,5 @@ -#ifndef __MICROPY_INCLUDED_ZEPHYR_MODMACHINE_H__ -#define __MICROPY_INCLUDED_ZEPHYR_MODMACHINE_H__ +#ifndef MICROPY_INCLUDED_ZEPHYR_MODMACHINE_H +#define MICROPY_INCLUDED_ZEPHYR_MODMACHINE_H #include "py/obj.h" @@ -13,4 +13,4 @@ typedef struct _machine_pin_obj_t { uint32_t pin; } machine_pin_obj_t; -#endif // __MICROPY_INCLUDED_ZEPHYR_MODMACHINE_H__ +#endif // MICROPY_INCLUDED_ZEPHYR_MODMACHINE_H diff --git a/zephyr/modusocket.c b/zephyr/modusocket.c index cec0eec7c..9319f4f98 100644 --- a/zephyr/modusocket.c +++ b/zephyr/modusocket.c @@ -37,6 +37,9 @@ #include #include #include +#ifdef CONFIG_NET_SOCKETS +#include +#endif #define DEBUG_PRINT 0 #if DEBUG_PRINT // print debugging info @@ -47,11 +50,7 @@ typedef struct _socket_obj_t { mp_obj_base_t base; - struct net_context *ctx; - union { - struct k_fifo recv_q; - struct k_fifo accept_q; - }; + int ctx; #define STATE_NEW 0 #define STATE_CONNECTING 1 @@ -62,42 +61,13 @@ typedef struct _socket_obj_t { STATIC const mp_obj_type_t socket_type; -// k_fifo extended API - -static inline void *_k_fifo_peek_head(struct k_fifo *fifo) -{ -#if KERNEL_VERSION_NUMBER < 0x010763 /* 1.7.99 */ - return sys_slist_peek_head(&fifo->data_q); -#else - return sys_slist_peek_head(&fifo->_queue.data_q); -#endif -} - -static inline void *_k_fifo_peek_tail(struct k_fifo *fifo) -{ -#if KERNEL_VERSION_NUMBER < 0x010763 /* 1.7.99 */ - return sys_slist_peek_tail(&fifo->data_q); -#else - return sys_slist_peek_tail(&fifo->_queue.data_q); -#endif -} - -static inline void _k_fifo_wait_non_empty(struct k_fifo *fifo, int32_t timeout) -{ - struct k_poll_event events[] = { - K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_FIFO_DATA_AVAILABLE, K_POLL_MODE_NOTIFY_ONLY, fifo), - }; - - k_poll(events, MP_ARRAY_SIZE(events), timeout); - DEBUG_printf("poll res: %d\n", events[0].state); -} - // Helper functions #define RAISE_ERRNO(x) { int _err = x; if (_err < 0) mp_raise_OSError(-_err); } +#define RAISE_SOCK_ERRNO(x) { if ((int)(x) == -1) mp_raise_OSError(errno); } STATIC void socket_check_closed(socket_obj_t *socket) { - if (socket->ctx == NULL) { + if (socket->ctx == -1) { // already closed mp_raise_OSError(EBADF); } @@ -109,7 +79,7 @@ STATIC void parse_inet_addr(socket_obj_t *socket, mp_obj_t addr_in, struct socka mp_obj_t *addr_items; mp_obj_get_array_fixed_n(addr_in, 2, &addr_items); - sockaddr_in->sin_family = net_context_get_family(socket->ctx); + sockaddr_in->sin_family = net_context_get_family((void*)socket->ctx); RAISE_ERRNO(net_addr_pton(sockaddr_in->sin_family, mp_obj_str_get_str(addr_items[0]), &sockaddr_in->sin_addr)); sockaddr_in->sin_port = htons(mp_obj_get_int(addr_items[1])); } @@ -118,8 +88,8 @@ STATIC mp_obj_t format_inet_addr(struct sockaddr *addr, mp_obj_t port) { // We employ the fact that port and address offsets are the same for IPv4 & IPv6 struct sockaddr_in6 *sockaddr_in6 = (struct sockaddr_in6*)addr; char buf[40]; - net_addr_ntop(addr->family, &sockaddr_in6->sin6_addr, buf, sizeof(buf)); - mp_obj_tuple_t *tuple = mp_obj_new_tuple(addr->family == AF_INET ? 2 : 4, NULL); + net_addr_ntop(addr->sa_family, &sockaddr_in6->sin6_addr, buf, sizeof(buf)); + mp_obj_tuple_t *tuple = mp_obj_new_tuple(addr->sa_family == AF_INET ? 2 : 4, NULL); tuple->items[0] = mp_obj_new_str(buf, strlen(buf), false); // We employ the fact that port offset is the same for IPv4 & IPv6 @@ -127,7 +97,7 @@ STATIC mp_obj_t format_inet_addr(struct sockaddr *addr, mp_obj_t port) { //tuple->items[1] = mp_obj_new_int(ntohs(((struct sockaddr_in*)addr)->sin_port)); tuple->items[1] = port; - if (addr->family == AF_INET6) { + if (addr->sa_family == AF_INET6) { tuple->items[2] = MP_OBJ_NEW_SMALL_INT(0); // flow_info tuple->items[3] = MP_OBJ_NEW_SMALL_INT(sockaddr_in6->sin6_scope_id); } @@ -135,78 +105,9 @@ STATIC mp_obj_t format_inet_addr(struct sockaddr *addr, mp_obj_t port) { return MP_OBJ_FROM_PTR(tuple); } -// Copy data from Zephyr net_buf chain into linear buffer. -// We don't use net_pkt_read(), because it's weird (e.g., we'd like to -// free processed data fragment ASAP, while net_pkt_read() holds onto -// the whole fragment chain to do its deeds, and that's minor comparing -// to the fact that it copies data byte by byte). -static char *net_pkt_gather(struct net_pkt *pkt, char *to, unsigned max_len) { - struct net_buf *tmp = pkt->frags; - - while (tmp && max_len) { - unsigned len = tmp->len; - if (len > max_len) { - len = max_len; - } - memcpy(to, tmp->data, len); - to += len; - max_len -= len; - tmp = net_pkt_frag_del(pkt, NULL, tmp); - } - - return to; -} - -// Callback for incoming packets. -static void sock_received_cb(struct net_context *context, struct net_pkt *pkt, int status, void *user_data) { - socket_obj_t *socket = (socket_obj_t*)user_data; - DEBUG_printf("recv cb: context: %p, status: %d, pkt: %p", context, status, pkt); - if (pkt) { - DEBUG_printf(" (appdatalen=%d), token: %p", pkt->appdatalen, net_pkt_token(pkt)); - } - DEBUG_printf("\n"); - #if DEBUG_PRINT > 1 - net_pkt_print_frags(pkt); - #endif - - // if net_buf == NULL, EOF - if (pkt == NULL) { - struct net_pkt *last_pkt = _k_fifo_peek_tail(&socket->recv_q); - if (last_pkt == NULL) { - socket->state = STATE_PEER_CLOSED; - k_fifo_cancel_wait(&socket->recv_q); - DEBUG_printf("Marked socket %p as peer-closed\n", socket); - } else { - // We abuse "buf_sent" flag to store EOF flag - net_pkt_set_sent(last_pkt, true); - DEBUG_printf("Set EOF flag on %p\n", last_pkt); - } - return; - } - - // Make sure that "EOF flag" is not set - net_pkt_set_sent(pkt, false); - - // We don't care about packet header, so get rid of it asap - unsigned header_len = net_pkt_appdata(pkt) - pkt->frags->data; - net_buf_pull(pkt->frags, header_len); - - k_fifo_put(&socket->recv_q, pkt); -} - -// Callback for incoming connections. -static void sock_accepted_cb(struct net_context *new_ctx, struct sockaddr *addr, socklen_t addrlen, int status, void *user_data) { - socket_obj_t *socket = (socket_obj_t*)user_data; - DEBUG_printf("accept cb: context: %p, status: %d, new ctx: %p\n", socket->ctx, status, new_ctx); - DEBUG_printf("new_ctx ref_cnt: %d\n", new_ctx->refcount); - - k_fifo_put(&socket->accept_q, new_ctx); -} - socket_obj_t *socket_new(void) { socket_obj_t *socket = m_new_obj_with_finaliser(socket_obj_t); socket->base.type = (mp_obj_t)&socket_type; - k_fifo_init(&socket->recv_q); socket->state = STATE_NEW; return socket; } @@ -215,10 +116,10 @@ socket_obj_t *socket_new(void) { STATIC void socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { socket_obj_t *self = self_in; - if (self->ctx == NULL) { + if (self->ctx == -1) { mp_printf(print, ""); } else { - struct net_context *ctx = self->ctx; + struct net_context *ctx = (void*)self->ctx; mp_printf(print, "", ctx, net_context_get_type(ctx)); } } @@ -249,7 +150,8 @@ STATIC mp_obj_t socket_make_new(const mp_obj_type_t *type, size_t n_args, size_t } } - RAISE_ERRNO(net_context_get(family, socktype, proto, &socket->ctx)); + socket->ctx = zsock_socket(family, socktype, proto); + RAISE_SOCK_ERRNO(socket->ctx); return MP_OBJ_FROM_PTR(socket); } @@ -261,14 +163,9 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { struct sockaddr sockaddr; parse_inet_addr(socket, addr_in, &sockaddr); - RAISE_ERRNO(net_context_bind(socket->ctx, &sockaddr, sizeof(sockaddr))); - // For DGRAM socket, we expect to receive packets after call to bind(), - // but for STREAM socket, next expected operation is listen(), which - // doesn't work if recv callback is set. - if (net_context_get_type(socket->ctx) == SOCK_DGRAM) { - DEBUG_printf("Setting recv cb after bind\n"); - RAISE_ERRNO(net_context_recv(socket->ctx, sock_received_cb, K_NO_WAIT, socket)); - } + int res = zsock_bind(socket->ctx, &sockaddr, sizeof(sockaddr)); + RAISE_SOCK_ERRNO(res); + return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); @@ -280,9 +177,9 @@ STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) { struct sockaddr sockaddr; parse_inet_addr(socket, addr_in, &sockaddr); - RAISE_ERRNO(net_context_connect(socket->ctx, &sockaddr, sizeof(sockaddr), NULL, K_FOREVER, NULL)); - DEBUG_printf("Setting recv cb after connect()\n"); - RAISE_ERRNO(net_context_recv(socket->ctx, sock_received_cb, K_NO_WAIT, socket)); + int res = zsock_connect(socket->ctx, &sockaddr, sizeof(sockaddr)); + RAISE_SOCK_ERRNO(res); + return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect); @@ -292,8 +189,9 @@ STATIC mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog_in) { socket_check_closed(socket); mp_int_t backlog = mp_obj_get_int(backlog_in); - RAISE_ERRNO(net_context_listen(socket->ctx, backlog)); - RAISE_ERRNO(net_context_accept(socket->ctx, sock_accepted_cb, K_NO_WAIT, socket)); + int res = zsock_listen(socket->ctx, backlog); + RAISE_SOCK_ERRNO(res); + return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_listen_obj, socket_listen); @@ -302,14 +200,12 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) { socket_obj_t *socket = self_in; socket_check_closed(socket); - struct net_context *ctx = k_fifo_get(&socket->accept_q, K_FOREVER); - // Was overwritten by fifo - ctx->refcount = 1; + struct sockaddr sockaddr; + socklen_t addrlen = sizeof(sockaddr); + int ctx = zsock_accept(socket->ctx, &sockaddr, &addrlen); socket_obj_t *socket2 = socket_new(); socket2->ctx = ctx; - DEBUG_printf("Setting recv cb after accept()\n"); - RAISE_ERRNO(net_context_recv(ctx, sock_received_cb, K_NO_WAIT, socket2)); mp_obj_tuple_t *client = mp_obj_new_tuple(2, NULL); client->items[0] = MP_OBJ_FROM_PTR(socket2); @@ -322,28 +218,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept); STATIC mp_uint_t sock_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { socket_obj_t *socket = self_in; - if (socket->ctx == NULL) { + if (socket->ctx == -1) { // already closed *errcode = EBADF; return MP_STREAM_ERROR; } - struct net_pkt *send_pkt = net_pkt_get_tx(socket->ctx, K_FOREVER); - - unsigned len = net_if_get_mtu(net_context_get_iface(socket->ctx)); - // Arbitrary value to account for protocol headers - len -= 64; - if (len > size) { - len = size; - } - - // TODO: Return value of 0 is a hard case (as we wait forever, should - // not happen). - len = net_pkt_append(send_pkt, len, buf, K_FOREVER); - - int err = net_context_send(send_pkt, /*cb*/NULL, K_FOREVER, NULL, NULL); - if (err < 0) { - *errcode = -err; + ssize_t len = zsock_send(socket->ctx, buf, size, 0); + if (len == -1) { + *errcode = errno; return MP_STREAM_ERROR; } @@ -364,81 +247,16 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_send_obj, socket_send); STATIC mp_uint_t sock_read(mp_obj_t self_in, void *buf, mp_uint_t max_len, int *errcode) { socket_obj_t *socket = self_in; - if (socket->ctx == NULL) { + if (socket->ctx == -1) { // already closed *errcode = EBADF; return MP_STREAM_ERROR; } - enum net_sock_type sock_type = net_context_get_type(socket->ctx); - unsigned recv_len; - - if (sock_type == SOCK_DGRAM) { - - struct net_pkt *pkt = k_fifo_get(&socket->recv_q, K_FOREVER); - - recv_len = net_pkt_appdatalen(pkt); - DEBUG_printf("recv: pkt=%p, appdatalen: %d\n", pkt, recv_len); - - if (recv_len > max_len) { - recv_len = max_len; - } - - net_pkt_gather(pkt, buf, recv_len); - net_pkt_unref(pkt); - - } else if (sock_type == SOCK_STREAM) { - - do { - - if (socket->state == STATE_PEER_CLOSED) { - return 0; - } - - _k_fifo_wait_non_empty(&socket->recv_q, K_FOREVER); - struct net_pkt *pkt = _k_fifo_peek_head(&socket->recv_q); - if (pkt == NULL) { - DEBUG_printf("TCP recv: NULL return from fifo\n"); - continue; - } - - DEBUG_printf("TCP recv: cur_pkt: %p\n", pkt); - - struct net_buf *frag = pkt->frags; - if (frag == NULL) { - printf("net_pkt has empty fragments on start!\n"); - assert(0); - } - - unsigned frag_len = frag->len; - recv_len = frag_len; - if (recv_len > max_len) { - recv_len = max_len; - } - DEBUG_printf("%d data bytes in head frag, going to read %d\n", frag_len, recv_len); - - memcpy(buf, frag->data, recv_len); - - if (recv_len != frag_len) { - net_buf_pull(frag, recv_len); - } else { - frag = net_pkt_frag_del(pkt, NULL, frag); - if (frag == NULL) { - DEBUG_printf("Finished processing pkt %p\n", pkt); - // Drop head packet from queue - k_fifo_get(&socket->recv_q, K_NO_WAIT); - - // If "sent" flag was set, it's last packet and we reached EOF - if (net_pkt_sent(pkt)) { - socket->state = STATE_PEER_CLOSED; - } - net_pkt_unref(pkt); - } - } - // Keep repeating while we're getting empty fragments - // Zephyr IP stack appears to have fed empty net_buf's with empty - // frags for various TCP control packets - in previous versions. - } while (recv_len == 0); + ssize_t recv_len = zsock_recv(socket->ctx, buf, max_len, 0); + if (recv_len == -1) { + *errcode = errno; + return MP_STREAM_ERROR; } return recv_len; @@ -483,9 +301,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_makefile_obj, 1, 3, socket_mak STATIC mp_obj_t socket_close(mp_obj_t self_in) { socket_obj_t *socket = self_in; - if (socket->ctx != NULL) { - RAISE_ERRNO(net_context_put(socket->ctx)); - socket->ctx = NULL; + if (socket->ctx != -1) { + int res = zsock_close(socket->ctx); + RAISE_SOCK_ERRNO(res); + socket->ctx = -1; } return mp_const_none; } diff --git a/zephyr/modutime.c b/zephyr/modutime.c index 0c268046a..a5d32fe66 100644 --- a/zephyr/modutime.c +++ b/zephyr/modutime.c @@ -1,5 +1,5 @@ /* - * This file is part of the Micro Python project, http://micropython.org/ + * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) * diff --git a/zephyr/modzephyr.c b/zephyr/modzephyr.c index 4bac5c970..265fc882d 100644 --- a/zephyr/modzephyr.c +++ b/zephyr/modzephyr.c @@ -28,6 +28,7 @@ #if MICROPY_PY_ZEPHYR #include +#include #include "py/runtime.h" @@ -36,9 +37,38 @@ STATIC mp_obj_t mod_is_preempt_thread(void) { } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_is_preempt_thread_obj, mod_is_preempt_thread); +STATIC mp_obj_t mod_current_tid(void) { + return MP_OBJ_NEW_SMALL_INT(k_current_get()); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_current_tid_obj, mod_current_tid); + +STATIC mp_obj_t mod_stacks_analyze(void) { + k_call_stacks_analyze(); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_stacks_analyze_obj, mod_stacks_analyze); + +#ifdef CONFIG_NET_SHELL + +//int net_shell_cmd_iface(int argc, char *argv[]); + +STATIC mp_obj_t mod_shell_net_iface(void) { + net_shell_cmd_iface(0, NULL); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_shell_net_iface_obj, mod_shell_net_iface); + +#endif // CONFIG_NET_SHELL + STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_zephyr) }, { MP_ROM_QSTR(MP_QSTR_is_preempt_thread), MP_ROM_PTR(&mod_is_preempt_thread_obj) }, + { MP_ROM_QSTR(MP_QSTR_current_tid), MP_ROM_PTR(&mod_current_tid_obj) }, + { MP_ROM_QSTR(MP_QSTR_stacks_analyze), MP_ROM_PTR(&mod_stacks_analyze_obj) }, + + #ifdef CONFIG_NET_SHELL + { MP_ROM_QSTR(MP_QSTR_shell_net_iface), MP_ROM_PTR(&mod_shell_net_iface_obj) }, + #endif }; STATIC MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table); diff --git a/zephyr/mpconfigport.h b/zephyr/mpconfigport.h index 2f2526779..b4677f3ed 100644 --- a/zephyr/mpconfigport.h +++ b/zephyr/mpconfigport.h @@ -98,9 +98,6 @@ typedef int mp_int_t; // must be pointer size typedef unsigned mp_uint_t; // must be pointer size - -typedef void *machine_ptr_t; // must be of pointer size -typedef const void *machine_const_ptr_t; // must be of pointer size typedef long mp_off_t; #define MP_STATE_PORT MP_STATE_VM diff --git a/zephyr/mpconfigport_minimal.h b/zephyr/mpconfigport_minimal.h index 772335c0a..f0e57d756 100644 --- a/zephyr/mpconfigport_minimal.h +++ b/zephyr/mpconfigport_minimal.h @@ -80,9 +80,6 @@ typedef int mp_int_t; // must be pointer size typedef unsigned mp_uint_t; // must be pointer size - -typedef void *machine_ptr_t; // must be of pointer size -typedef const void *machine_const_ptr_t; // must be of pointer size typedef long mp_off_t; #define MP_STATE_PORT MP_STATE_VM diff --git a/zephyr/prj_96b_carbon.conf b/zephyr/prj_96b_carbon.conf index 3e41e2532..40b57e69c 100644 --- a/zephyr/prj_96b_carbon.conf +++ b/zephyr/prj_96b_carbon.conf @@ -1,2 +1,2 @@ # TODO: Enable networking -CONFIG_NETWORKING=n +CONFIG_NETWORKING=y diff --git a/zephyr/prj_base.conf b/zephyr/prj_base.conf index 4346f20bf..c3ba2812f 100644 --- a/zephyr/prj_base.conf +++ b/zephyr/prj_base.conf @@ -14,6 +14,7 @@ CONFIG_NET_IPV4=y CONFIG_NET_IPV6=y CONFIG_NET_UDP=y CONFIG_NET_TCP=y +CONFIG_NET_SOCKETS=y CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_NET_NBUF_RX_COUNT=5 @@ -23,9 +24,17 @@ CONFIG_DNS_RESOLVER_ADDITIONAL_QUERIES=2 CONFIG_DNS_SERVER_IP_ADDRESSES=y CONFIG_DNS_SERVER1="192.0.2.2" +# Diagnostics and debugging + +# Required for zephyr.stack_analyze() +CONFIG_INIT_STACKS=y + # Required for usocket.pkt_get_info() CONFIG_NET_BUF_POOL_USAGE=y +# Required for usocket.shell_*() +#CONFIG_NET_SHELL=y + # Uncomment to enable "INFO" level net_buf logging #CONFIG_NET_LOG=y #CONFIG_NET_DEBUG_NET_BUF=y pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy