rust-embedded-community / ssd1306

SSD1306 OLED driver
Apache License 2.0
299 stars 68 forks source link

Optimise BasicMode::clear RAM usage and optimize size of Ssd1306::char_to_bitmap #195

Closed alexey-medvedchikov closed 11 months ago

alexey-medvedchikov commented 1 year ago

Hi! Thank you for helping out with SSD1306 development! Please:

PR description

This PR fixes issues with small AVRs:

AVR size difference

Before:

text    data     bss     dec     hex filename
   0    8446       0    8446    20fe object.hex

After:

text    data     bss     dec     hex filename
   0    4988       0    4988    137c object.hex

STM32 (thumbv7em) size difference

Before:

verified 7212 bytes

After:

verified 6392 bytes
alexey-medvedchikov commented 1 year ago

@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.

alexey-medvedchikov commented 1 year ago

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.

alexey-medvedchikov commented 1 year ago

Tested on NUCLEO-F446ZE and ATMega168 with 128x64 and 128x32, all work fine.

alexey-medvedchikov commented 1 year ago

Got rid of extra-sized arrays in Command::send, cuts 80 bytes on Cortex-M4 and 260 bytes on ATMega168.

alexey-medvedchikov commented 1 year ago

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.

alexey-medvedchikov commented 11 months ago

@jamwaffles checked and committed your changes. Thanks for spending so much time on this one!

jamwaffles commented 11 months ago

This is released in v0.8.3. cargo update should pull in the changes.

bugadani commented 11 months ago

FYI I'm firmly opposed to https://github.com/jamwaffles/ssd1306/pull/195/commits/e309b41027e4219a17ba28200034eddcff25da77 as it means I'll have to duplicate the whole command table for the async interface.