Skip to content

Commit

Permalink
Merge pull request #7 from Lorandil/master
Browse files Browse the repository at this point in the history
added 'ssd1306_tiny_init()' to save flash memory if an initial screen fill is not required (~52 bytes shorter)
  • Loading branch information
tejashwikalptaru authored Jul 11, 2024
2 parents 5ffcf1c + 31ea214 commit dc621d2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)



14 changes: 14 additions & 0 deletions ssd1306xled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions ssd1306xled.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#ifndef SSD1306XLED_H
#define SSD1306XLED_H

#define _SSD1306XLED_TINY_INIT_SUPPORTED_


// ----------------------------------------------------------------------------

// -----(+)---------------> // Vcc, Pin 1 on SSD1306 Board
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit dc621d2

Please sign in to comment.