-
Notifications
You must be signed in to change notification settings - Fork 70
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
Optimise BasicMode::clear RAM usage and optimize size of Ssd1306::char_to_bitmap #195
Optimise BasicMode::clear RAM usage and optimize size of Ssd1306::char_to_bitmap #195
Conversation
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.
Hey, thanks for the improvements! The memory size reductions are impressive. I left a few questions on your clear()
changes.
I also want to test this PR on some hardware before merging but I'm travelling for this week. I hope you don't mind the delay.
src/mode/mod.rs
Outdated
for _ in 0..dim.0 * dim.1 { | ||
self.draw(&[0; 8])?; | ||
} |
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.
I've got a couple of questions here. I hope you don't mind a short list:
- Because you're sending 8 bytes in a row, shouldn't this be
0..(dim.0 * dim.1) / 8
? - Could we increase the slice size to 64 or 128 bytes? This will still save a decent amount of memory but will reduce the overhead of doing the CS pin setup, etc.
- To add to (1.), I think you might need a further
/ 8
because the display's dimensions are in pixels, but a page is 8 bytes tall.
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.
Thanks for the quick reply! Yes, it all does make sense, I'll address comments later today.
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.
Addressed the comments you provided. Also, I realised that the addressing mode must be set and restored, so did that too.
@jamwaffles No problemo! Although I saved some space, I still can't squeeze my program into atmega168 - bme680 driver is a resource hog (making a small weather station with a screen). So I'll try to switch to a STM32 MCU, I can test this change there too later this week. I also have ESP8266 at hand, but I've never used it with Rust, so not sure if I can quickly check it. |
LOL, I've just noticed that all the first and last bytes of each glyph in the font are zeros, so I just made the data array smaller by another 500 bytes. It is a bit clunky, but the font is hardcoded (and quite nice), so I don't think it is a problem. -3.5Kb total on atmega. |
Tested on NUCLEO-F446ZE and ATMega168 with 128x64 and 128x32, all work fine. |
Got rid of extra-sized arrays in |
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.
Thanks very much for testing the different display sizes - that's saved me some time :). I've left a couple of inline suggestions which make the code a bit cleaner. Let me know what you think.
'~' => [0x00, 0x02, 0x01, 0x02, 0x01, 0x00, 0x00, 0x00], | ||
_ => [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], | ||
} | ||
const CHARS: [[u8; 6]; 95] = [ |
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.
Nice optimisation! In hindsight it was silly to store a pile of extra zeros but thanks for the fix!
Co-authored-by: James Waples <[email protected]>
Co-authored-by: James Waples <[email protected]>
Co-authored-by: James Waples <[email protected]>
Thanks for the review. I accepted all your suggestions, a newbie in Rust, so make simple mistakes. Also, the merge conflict should be resolved now. |
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.
Hey, sorry for the review delay. I've got one more nit that hopefully doesn't fail the tests any more, then this is good for merge. Thanks for your patience!
Co-authored-by: James Waples <[email protected]>
@jamwaffles checked and committed your changes. Thanks for spending so much time on this one! |
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.
Looks good! Thanks again for your patience :)
This is released in v0.8.3. |
FYI I'm firmly opposed to e309b41 as it means I'll have to duplicate the whole command table for the async interface. |
Hi! Thank you for helping out with SSD1306 development! Please:
master
if you're not already up to dateCHANGELOG.md
entry in the Unreleased section under the appropriate heading (Added, Fixed, Changed, etc)rustfmt
on the project withcargo fmt --all
- CI will not pass without this stepPR description
This PR fixes issues with small AVRs:
match
. Saves around 3.5Kb of compiled code on AVR ATMega-s. Didn't test on other architectures, but pretty sure it will save some size too.AVR size difference
Before:
After:
STM32 (thumbv7em) size difference
Before:
After: