Skip to content
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

Add DISABLE options to UserSettings.h #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cbl-winston
Copy link

Hello,
This is a nice library! I've been using this library with an ATtiny system, so minimizing memory usage is critical for sure.

My proposed changes make it easier to use the library's configuration options.


In the library's current state, it's necessary to comment out various _ENABLE options in ssd1306_hal/UserSettings.h, since they're basically all enabled by default:

// UserSettings.h

/**
 * Define this macro if platform specific spi interface is implemented in SSD1306 HAL
 * If you use Arduino platform, this macro enables Arduino SPI library module for compilation.
 */
//#define CONFIG_PLATFORM_SPI_ENABLE   // don't need this

/**
 * Defines, whenever ssd1306 library supports unicode.
 * Support of unicode increases RAM and Flasg memory consumption
 */
//#define CONFIG_SSD1306_UNICODE_ENABLE   // don't need this either.

Unfortunately, this forces the user to modify the source code just to use the configuration options. This is rather inconvenient.

My proposal is to wrap the CONFIG_xxxxxx_ENABLE defines with #ifndef SSD1306_xxxxxx_DISABLE conditions, like so:

// UserSettings.h

/**
 * Define SSD1306_PLATFORM_SPI_DISABLE to disable the platform-specific SPI interface
 * implemented in SSD1306 HAL.
 * 
 * If you use Arduino platform, this lets you skip compilation of the SPI library.
 */
#ifndef SSD1306_PLATFORM_SPI_DISABLE
#define CONFIG_PLATFORM_SPI_ENABLE
#endif

/**
 * Define SSD1306_UNICODE_DISABLE to disable this library's unicode support.
 * Unicode support increases RAM and Flash memory consumption.
 */
#ifndef SSD1306_UNICODE_DISABLE
#define CONFIG_SSD1306_UNICODE_ENABLE
#endif

With this change, the various library features can be easily disabled with build flags, like -DSSD1306_UNICODE_DISABLE.


The driving philosophy behind this change is that defines can easily be added at build time, but define statements in the code cannot be undone without changing the source code.

  • My changes won't break existing code.
  • The new "disable" macro names follow the pattern SSD1306_option name_DISABLE to prevent potential clashing.
  • The CONFIG_xxxxxx_ENABLE macros are still used within the library code. Only the way they're defined in UserSettings.h has been changed.
  • I removed the #ifndef CONFIG_ADAFRUIT_GFX_ENABLE line, since it didn't do anything. I left the option commented out, since -DCONFIG_ADAFRUIT_GFX_ENABLE can be passed to enable it.

Thanks for considering- and again, great library.
-- Winston M

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant