From 3bd12b6379a8d372fecdc4e11234a8c87fb458a8 Mon Sep 17 00:00:00 2001 From: Lorandil <70488869+Lorandil@users.noreply.github.com> Date: Sun, 7 Jul 2024 16:59:31 +0200 Subject: [PATCH 1/2] Alternate init method to reduce flash footprint by ~52 bytes The standard init method fills the screen with zero bytes. If this behaviour is not required, removing the call to fillscreen() saves ~52 bytes of valuable flash memory ;) --- ssd1306xled.cpp | 14 ++++++++++++++ ssd1306xled.h | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/ssd1306xled.cpp b/ssd1306xled.cpp index 1727c25..b070b1a 100644 --- a/ssd1306xled.cpp +++ b/ssd1306xled.cpp @@ -165,6 +165,20 @@ void SSD1306Device::ssd1306_init(void) ssd1306_fillscreen(0); } +// A shorter init saves 52 flash bytes (if zeroed screen is not required) +// The code of 'ssd1306_init()' is replicated to allow the linker to drop the unused method during linkage. +void SSD1306Device::ssd1306_tiny_init(void) +{ + begin(); + ssd1306_send_command_start(); + for (uint8_t i = 0; i < sizeof (ssd1306_init_sequence); i++) { + ssd1306_send_byte(pgm_read_byte(&ssd1306_init_sequence[i])); + } + ssd1306_send_command_stop(); + // save 52 bytes :) + //ssd1306_fillscreen(0); +} + void SSD1306Device::ssd1306_send_command_start(void) { I2CStop(); I2CStart(SSD1306_SA, 0); diff --git a/ssd1306xled.h b/ssd1306xled.h index 46833cd..e8a4d83 100644 --- a/ssd1306xled.h +++ b/ssd1306xled.h @@ -19,6 +19,9 @@ #ifndef SSD1306XLED_H #define SSD1306XLED_H +#define _SSD1306XLED_TINY_INIT_SUPPORTED_ + + // ---------------------------------------------------------------------------- // -----(+)---------------> // Vcc, Pin 1 on SSD1306 Board @@ -73,6 +76,7 @@ class SSD1306Device public: SSD1306Device(void); void ssd1306_init(void); + void ssd1306_tiny_init(void); void ssd1306_send_data_start(void); void ssd1306_send_data_stop(void); From 31ea214439c91aca715feff0d1964f80e90ee52c Mon Sep 17 00:00:00 2001 From: Lorandil <70488869+Lorandil@users.noreply.github.com> Date: Sun, 7 Jul 2024 17:14:04 +0200 Subject: [PATCH 2/2] updated documentation --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 4f7f9ff..0fca791 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ void run() { - Library functions - `void ssd1306_init(void)`: initializes the screen + - `void ssd1306_tiny_init(void)`: initializes the screen without filling the screen with '0' - `void ssd1306_send_data_start(void)`: put the communication with a screen in data mode - `void ssd1306_send_data_stop(void)`: stops the communication - `void ssd1306_send_byte(uint8_t byte)`: send data byte to screen @@ -65,6 +66,8 @@ This code is mainly written by Neven Boyanov, Tinusar team. I replaced their I2C ### Versions - v0.0.1 (March 08, 2020) - initial release +- v0.0.2 (July 07, 2024) + - added 'ssd1306_tiny_init()' to save flash memory if an initial screen fill is not required (~52 bytes shorter)