New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tweaking main scripts and lib #42
Conversation
- Remove old code for faster parsing. (Exists in git history if needed).
- Only import what is used. - Reformat `freq(X_000_000)` to clarify MHz.
- Replace `time.sleep()` with `machine.lightsleep()`, for small power saving; reduces `time` imports. - Fix `reset()` at end of ‘main.py’.
- Remove extra setting of FPS. No noticeable difference for user.
- Actually remove the `time` import. - Make sure `lightsleep` is available when needed.
- Remove printing `audioSetting`. - Comment out `gc` debugging stats for now (delete in future?).
- Make import overclock consistent 250 MHz (as used in `thumby.py`) - Do not overclock in `main.py`.
- Remove commented out code. - Format `freq(X_000_000)` to clarify MHz.
- Only import what is required.
- Only import necessary functions from `os` and `gc`. - Reinstate garbage collection (thanks @fuglaro).
- Reduce imports from `sys`.
- Fix typo for import of gc.
- Revert use of `machine.lightsleep` for welll tested `time.sleep_ms`. Power saving would be small. (Thanks @fuglaro).
- Run at 133MHz base speed on startup; no need to underclock to 125MHz. - Not overclocking for stability.
- Change copyright / legal date for international audience, and to distinguish between code edit dates. - Add `# -Emulation edition` to the emu files, for clarity while editing. - Sync changes back to the emulator lib copies.
- Add date of last update to main.py and menu.py; Matches lib files and helps debugging.
- Fix hot patching in `play.js` emulator. (Thanks @fuglaro).
- Remove debug print of config from `main.py`. - Remove debug print from `thumbyGraphics.py`.
- Remove HWID and do minimum required to display splash screen. - Avoids duplicate code in `thumbyHardware.py` (HWID is already determined by thumby lib, executed from menu.py). - Remove import of `machine.Timer` - unused.
- Use `if else` statement; Can only be one connection or the other.
- Group blocks of code for easier understanding: init screen, then set brightness.
- Conditionally import `I2C` if needed. - Remove unused `Timer` import
- Remove debug code. … last one… I hope!
- Copy across recent tweaks to emulator lib files. - Update Changelog.
- Only import the `SSD1306_SPI` class by default. - Conditionally import `SSD1306_I2C` if required.
Looking awesome. I love these changes. I can do some more testing of the newer stuff tomorrow. |
- Change ‘low’ brightness to `1`, as `0` is too dim on newer OLED models (thanks agovtman) . - Make the default brightness setting consistently `mid`in all places.
- Restore Thumby frequency back to 125MHz when launching a game. (~6% underclock). - Do faster import for `mem32()` and `soft_reset()` during startup, rather than at launch time. - Precalculate watchdog timer scratch register `0x4005800C` (readability). - Bonus: uniquely name `gc_collect()`.
- Remove unused `micropython const` from `ssd1306.py`. - Minimize `os` imports for `thumbySaves.py`.
Note for testing: |
- Fix detecting later revisions of the PCB (HWID=2) in `main.py` (thanks @fuglaro). - Avoid importing `ssd1306.SSD1306_I2C` unless necessary. - Update `thumbyGraphics` to set pins to `PULL_DOWN’ earlier.
- Sync the emulator to replace the `mem32` string (thanks @fuglaro).
- Remove unused `tick_us` import and `start` timer variable. - Remove font setting (it is the default already). - Remove unused banner bitmap. - Restore faster scrolling of the splashscreen (thanks @fuglaro).
- Combine 2 `machine` imports for `thumbyHardware.py`.
- Small improvements to text of some comment lines.
- Use the correct `thumby.reset()` at the end of file for menu.py (`machine.reset()` is no longer imported). - Note: This is redundant code; it will never execute. It is kept to indicate intent/ current practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep the WDT scratch address as a named constant? It's unclear to me how this improves readability, and the code only needs to run once on-startup, so lookup overhead shouldn't be a problem here. Other than that, everything looks good!
@masonova1 - |
I'm honestly fine with less words. If somebody wants the exposition, they would need to go back to the definition to see what it means anyways. If somebody complains, we'll bring it back. We'll get this merged soon. |
The
main.py
andmenu.py
should be lean. 🗜💪Small tweaks to clean things up. Mainly trimming unused imports.
Tested and looks ok. (Thanks @fuglaro for extensive review and testing).
Speed
Benchmarked with
ticks_ms
:main.py
boot reduced from ~754ms to ~246ms (now takes ~1/3rd of the time!).menu.py
up to main loop, reduced from ~1766ms to ~1581ms.Memory
Memory savings using
print(gc.mem_free())
:Vanilla
Before GC: mem_free=81376
After GC: mem_free=122112
This PR
Before GC: mem_free=84288 (+2,912 bytes free) ~2.8kb!!
After GC: mem_free=122144 (+32 bytes free) - the GC was managing to remove all the unused imports pretty well.