diff --git a/component.mk b/component.mk index 04ec95dd..fe53b74f 100644 --- a/component.mk +++ b/component.mk @@ -13,6 +13,7 @@ COMPONENT_SRCDIRS := ./src \ ./src/v2/lcd/lcdttgo \ ./src/v2/lcd/pcd8544 \ ./src/v2/lcd/ssd1306 \ + ./src/v2/lcd/ssd1306b \ ./src/v2/lcd/sh1107 \ ./src/v2/lcd/sh1106 \ ./src/v2/lcd/ssd1325 \ diff --git a/src/lcd_hal/pico/platform.cpp b/src/lcd_hal/pico/platform.cpp index 7068688d..962b5530 100644 --- a/src/lcd_hal/pico/platform.cpp +++ b/src/lcd_hal/pico/platform.cpp @@ -67,4 +67,8 @@ uint8_t lcd_pgmReadByte(const void *ptr) return *(static_cast(ptr)); } +uint32_t lcd_millis(void) +{ + return to_ms_since_boot(get_absolute_time()); +} #endif diff --git a/src/lcdgfx.h b/src/lcdgfx.h index 93c0f063..e6a07efa 100644 --- a/src/lcdgfx.h +++ b/src/lcdgfx.h @@ -41,6 +41,7 @@ #include "v2/lcd/sh1106/lcd_sh1106.h" #include "v2/lcd/sh1107/lcd_sh1107.h" #include "v2/lcd/ssd1306/lcd_ssd1306.h" +#include "v2/lcd/ssd1306b/lcd_ssd1306b.h" #include "v2/lcd/ssd1325/lcd_ssd1325.h" #include "v2/lcd/ssd1327/lcd_ssd1327.h" #include "v2/lcd/ssd1331/lcd_ssd1331.h" diff --git a/src/v2/lcd/ssd1306b/lcd_ssd1306b.cpp b/src/v2/lcd/ssd1306b/lcd_ssd1306b.cpp new file mode 100644 index 00000000..abe7f1a6 --- /dev/null +++ b/src/v2/lcd/ssd1306b/lcd_ssd1306b.cpp @@ -0,0 +1,117 @@ +/* + MIT License + + Copyright 2019-2022 (C) Alexey Dynda + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +/* !!! THIS FILE IS AUTO GENERATED !!! */ +#include "lcd_ssd1306b.h" +#include "lcd_hal/io.h" +#ifdef SDL_EMULATION +#include "sdl_core.h" +#endif +void DisplaySSD1306B_64x32_SPI::begin() +{ + m_spi.begin(); + DisplaySSD1306B_64x32::begin(); +} + +void DisplaySSD1306B_64x32_SPI::end() +{ + DisplaySSD1306B_64x32::end(); + m_spi.end(); +} +void DisplaySSD1306B_64x32_I2C::begin() +{ + m_i2c.begin(); + DisplaySSD1306B_64x32::begin(); +} + +void DisplaySSD1306B_64x32_I2C::end() +{ + DisplaySSD1306B_64x32::end(); + m_i2c.end(); +} +void DisplaySSD1306B_64x48_SPI::begin() +{ + m_spi.begin(); + DisplaySSD1306B_64x48::begin(); +} + +void DisplaySSD1306B_64x48_SPI::end() +{ + DisplaySSD1306B_64x48::end(); + m_spi.end(); +} +void DisplaySSD1306B_64x48_I2C::begin() +{ + m_i2c.begin(); + DisplaySSD1306B_64x48::begin(); +} + +void DisplaySSD1306B_64x48_I2C::end() +{ + DisplaySSD1306B_64x48::end(); + m_i2c.end(); +} +void DisplaySSD1306B_128x32_SPI::begin() +{ + m_spi.begin(); + DisplaySSD1306B_128x32::begin(); +} + +void DisplaySSD1306B_128x32_SPI::end() +{ + DisplaySSD1306B_128x32::end(); + m_spi.end(); +} +void DisplaySSD1306B_128x32_I2C::begin() +{ + m_i2c.begin(); + DisplaySSD1306B_128x32::begin(); +} + +void DisplaySSD1306B_128x32_I2C::end() +{ + DisplaySSD1306B_128x32::end(); + m_i2c.end(); +} +void DisplaySSD1306B_128x64_SPI::begin() +{ + m_spi.begin(); + DisplaySSD1306B_128x64::begin(); +} + +void DisplaySSD1306B_128x64_SPI::end() +{ + DisplaySSD1306B_128x64::end(); + m_spi.end(); +} +void DisplaySSD1306B_128x64_I2C::begin() +{ + m_i2c.begin(); + DisplaySSD1306B_128x64::begin(); +} + +void DisplaySSD1306B_128x64_I2C::end() +{ + DisplaySSD1306B_128x64::end(); + m_i2c.end(); +} diff --git a/src/v2/lcd/ssd1306b/lcd_ssd1306b.h b/src/v2/lcd/ssd1306b/lcd_ssd1306b.h new file mode 100644 index 00000000..492831b3 --- /dev/null +++ b/src/v2/lcd/ssd1306b/lcd_ssd1306b.h @@ -0,0 +1,1130 @@ +/* + MIT License + + Copyright 2019-2022 (C) Alexey Dynda + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +/* !!! THIS FILE IS AUTO GENERATED !!! */ +/** + * @file lcd_ssd1306b.h support for LCD SSD1306B display + */ + +#pragma once + +#include "lcd_hal/io.h" +#include "v2/lcd/lcd_common.h" +#include "v2/lcd/base/display.h" + +/** + * @ingroup LCD_INTERFACE_API_V2 + * @{ + */ + +/** + * Class implements interface functions to SSD1306B displays + */ +template class InterfaceSSD1306B: public I +{ +public: + /** + * Creates instance of interface to LCD display. + * + * @param base Reference to base class, which represents Display + * @param dc Data/command control pin number, for i2c communication should be -1 + * @param data variable argument list, accepted by platform interface (PlatformI2c, PlatformSpi) + */ + template + InterfaceSSD1306B(NanoDisplayBase> &base, int8_t dc, Args &&... data) + : I(data...) + , m_dc(dc) + , m_base(base) + { + } + + /** + * @brief Sets block in RAM of lcd display controller to write data to. + * + * Sets block in RAM of lcd display controller to write data to. + * For SSD1306B it uses horizontal addressing mode, while for + * sh1106 the function uses page addressing mode. + * Width can be specified as 0, thus the library will set the right boundary to + * region of RAM block to the right column of the display. + * @param x - column (left region) + * @param y - row (top region) + * @param w - width of the block in pixels to control + * + * @warning - this function initiates session (i2c or spi) and does not close it. + * To close session, please, call endBlock(). + */ + void startBlock(lcduint_t x, lcduint_t y, lcduint_t w); + + /** + * Switches to the start of next RAM page for the block, specified by + * startBlock(). + * For SSD1306B it does nothing, while for sh1106 the function moves cursor to + * next page. + */ + void nextBlock(); + + /** + * Closes data send operation to lcd display. + */ + void endBlock(); + + /** + * Enables either data or command mode on SPI bus + * @param mode 1 to enable data mode, or 0 to enable command mode + */ + void setDataMode(uint8_t mode); + + /** + * Starts communication with LCD display in command mode. + * To stop communication use m_intf.end(). + */ + void commandStart(); + + /** + * Sets start line in gdram to start display content with + * + * @param line start line in range 0 - 63 + */ + void setStartLine(uint8_t line); + + /** + * returns start line in gdram. + */ + uint8_t getStartLine(); + + /** + * Switches display to normal mode. This feature is specific + * for SSD1306B based controllers. + */ + void normalMode(); + + /** + * Switches display to normal mode. This feature is specific + * for SSD1306B based controllers. + */ + void invertMode(); + + /** + * Set display contrast, ie light intensity + * @param contrast - contrast value to see, refer to SSD1306B datasheet + */ + void setContrast(uint8_t contrast); + + /** + * Turns off display + */ + void displayOff(); + + /** + * Turns on display + */ + void displayOn(); + + /** + * @brief performs horizontal flip + * + * Performs horizontal flip. If you need to turn display by 180 degree, + * please use both flipHorizontal() and flipVertical(). + * + * @param mode - 0 to disable horizontal flip + * 1 to enable horizontal flip + */ + void flipHorizontal(uint8_t mode); + + /** + * @brief performs vertical flip + * + * Performs vertical flip. If you need to turn display by 180 degree, + * please use both flipHorizontal() and flipVertical(). + * + * @param mode - 0 to disable vertical flip + * 1 to enable vertical flip + */ + void flipVertical(uint8_t mode); + +private: + int8_t m_dc = -1; ///< data/command pin for SPI, -1 for i2c + NanoDisplayBase> &m_base; ///< basic lcd display support interface + uint8_t m_startLine = 0; +}; +/** + * Class implements basic functions for 1-bit mode of SSD1306B-based displays + */ +template class DisplaySSD1306B: public NanoDisplayOps, I> +{ +public: + /** + * Creates instance of SSD1306B controller class for 1-bit mode + * + * @param intf interface to use + * @param rstPin pin to use as HW reset pin for LCD display + */ + DisplaySSD1306B(I &intf, int8_t rstPin) + : NanoDisplayOps, I>(intf) + , m_rstPin(rstPin) + { + } + +protected: + int8_t m_rstPin; ///< indicates hardware reset pin used, -1 if it is not required + + /** + * Basic SSD1306B initialization + */ + void begin() override; + + /** + * Basic SSD1306B deinitialization + */ + void end() override; +}; + +/** + * Class implements basic functions for 1-bit mode of SSD1306B-based displays + */ +template class DisplaySSD1306B_64x32: public DisplaySSD1306B +{ +public: + /** + * Creates instance of SSD1306B 64x32 controller class for 1-bit mode + * + * @param intf interface to use + * @param rstPin pin to use as HW reset pin for LCD display + */ + DisplaySSD1306B_64x32(I &intf, int8_t rstPin) + : DisplaySSD1306B(intf, rstPin) + { + } + +protected: + /** + * Basic SSD1306B 64x32 initialization + */ + void begin() override; + + /** + * Basic SSD1306B deinitialization + */ + void end() override; +}; +/** + * Class implements SSD1306B 64x32 lcd display in 1 bit mode over SPI + */ +class DisplaySSD1306B_64x32_SPI: public DisplaySSD1306B_64x32> +{ +public: + /** + * @brief Inits 64x32 lcd display over spi (based on SSD1306B controller): 1-bit mode. + * + * Inits 64x32 lcd display over spi (based on SSD1306B controller): 1-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param config platform spi configuration. Please refer to SPlatformSpiConfig. + */ + explicit DisplaySSD1306B_64x32_SPI(int8_t rstPin, const SPlatformSpiConfig &config = {-1, {-1}, -1, 0, -1, -1}) + : DisplaySSD1306B_64x32(m_spi, rstPin) + , m_spi(*this, config.dc, + SPlatformSpiConfig{ + config.busId, {config.cs}, config.dc, config.frequency ?: 10000000, config.scl, config.sda}) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override; + + /** + * Closes connection to display + */ + void end() override; + +private: + InterfaceSSD1306B m_spi; +}; + +/** + * Template class implements SSD1306B 64x32 lcd display in 1 bit mode over custom SPI implementation + * (user-defined spi implementation). I - user custom spi class + */ +template class DisplaySSD1306B_64x32_CustomSPI: public DisplaySSD1306B_64x32> +{ +public: + /** + * @brief Inits 64x32 lcd display over spi (based on SSD1306B controller): 1-bit mode. + * + * Inits 64x32 lcd display over spi (based on SSD1306B controller): 1-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param dcPin pin to use as data/command control pin + * @param data variable argument list for custom user spi interface. + */ + template + DisplaySSD1306B_64x32_CustomSPI(int8_t rstPin, int8_t dcPin, Args &&... data) + : DisplaySSD1306B_64x32>(m_spi, rstPin) + , m_spi(*this, dcPin, data...) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override + { + m_spi.begin(); + DisplaySSD1306B_64x32>::begin(); + } + + /** + * Closes connection to display + */ + void end() override + { + DisplaySSD1306B_64x32>::end(); + m_spi.end(); + } + +private: + InterfaceSSD1306B m_spi; +}; +/** + * Class implements SSD1306B 64x32 lcd display in 1 bit mode over I2C + */ +class DisplaySSD1306B_64x32_I2C: public DisplaySSD1306B_64x32> +{ +public: + /** + * @brief Inits 64x32 lcd display over i2c (based on SSD1306B controller): 1-bit mode. + * + * Inits 64x32 lcd display over i2c (based on SSD1306B controller): 1-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param config platform i2c configuration. Please refer to SPlatformI2cConfig. + */ + explicit DisplaySSD1306B_64x32_I2C(int8_t rstPin, const SPlatformI2cConfig &config = {-1, 0x3C, -1, -1, 0}) + : DisplaySSD1306B_64x32(m_i2c, rstPin) + , m_i2c(*this, -1, + SPlatformI2cConfig{config.busId, static_cast(config.addr ?: 0x3C), config.scl, config.sda, + config.frequency ?: 400000}) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override; + + /** + * Closes connection to display + */ + void end() override; + +private: + InterfaceSSD1306B m_i2c; +}; + +/** + * Template class implements SSD1306B 64x32 lcd display in 1 bit mode over custom I2C implementation + * (user-defined i2c implementation). I - user custom i2c class + */ +template class DisplaySSD1306B_64x32_CustomI2C: public DisplaySSD1306B_64x32> +{ +public: + /** + * @brief Inits 64x32 lcd display over i2c (based on SSD1306B controller): 1-bit mode. + * + * Inits 64x32 lcd display over i2c (based on SSD1306B controller): 1-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param data variable argument list for custom user i2c interface. + */ + template + DisplaySSD1306B_64x32_CustomI2C(int8_t rstPin, Args &&... data) + : DisplaySSD1306B_64x32>(m_i2c, rstPin) + , m_i2c(*this, -1, data...) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override + { + m_i2c.begin(); + DisplaySSD1306B_64x32>::begin(); + } + + /** + * Closes connection to display + */ + void end() override + { + DisplaySSD1306B_64x32>::end(); + m_i2c.end(); + } + +private: + InterfaceSSD1306B m_i2c; +}; +/** + * Template class implements SSD1306B 64x32 lcd display in 1 bit mode over custom interface implementation + * (user-defined interface implementation). I - user custom interface class. + * This class allows to use display over 6800 and 8080 parallel interfaces + */ +template class DisplaySSD1306B_64x32_Custom: public DisplaySSD1306B_64x32> +{ +public: + /** + * @brief Inits 64x32 lcd display over custom interface (based on SSD1306B controller): 1-bit mode. + * + * Inits 64x32 lcd display over custom interface (based on SSD1306B controller): 1-bit mode + * User-defined interface `I` will receive frequency (uint32_t) as first argument, and user additional args, + * specified as data variable argument list. + * + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param dcPin pin to use as data/command control pin (-1 if not used) + * @param frequency frequency in HZ, or 0 if to use default display frequency + * @param data variable argument list for custom user interface. + */ + template + DisplaySSD1306B_64x32_Custom(int8_t rstPin, int8_t dcPin, uint32_t frequency, Args &&... data) + : DisplaySSD1306B_64x32>(m_custom, rstPin) + , m_custom(*this, dcPin, frequency = frequency ? frequency : 3000000, data...) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override + { + m_custom.begin(); + DisplaySSD1306B_64x32>::begin(); + } + + /** + * Closes connection to display + */ + void end() override + { + DisplaySSD1306B_64x32>::end(); + m_custom.end(); + } + +private: + InterfaceSSD1306B m_custom; +}; +/** + * Class implements basic functions for 1-bit mode of SSD1306B-based displays + */ +template class DisplaySSD1306B_64x48: public DisplaySSD1306B +{ +public: + /** + * Creates instance of SSD1306B 64x48 controller class for 1-bit mode + * + * @param intf interface to use + * @param rstPin pin to use as HW reset pin for LCD display + */ + DisplaySSD1306B_64x48(I &intf, int8_t rstPin) + : DisplaySSD1306B(intf, rstPin) + { + } + +protected: + /** + * Basic SSD1306B 64x48 initialization + */ + void begin() override; + + /** + * Basic SSD1306B deinitialization + */ + void end() override; +}; +/** + * Class implements SSD1306B 64x48 lcd display in 1 bit mode over SPI + */ +class DisplaySSD1306B_64x48_SPI: public DisplaySSD1306B_64x48> +{ +public: + /** + * @brief Inits 64x48 lcd display over spi (based on SSD1306B controller): 1-bit mode. + * + * Inits 64x48 lcd display over spi (based on SSD1306B controller): 1-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param config platform spi configuration. Please refer to SPlatformSpiConfig. + */ + explicit DisplaySSD1306B_64x48_SPI(int8_t rstPin, const SPlatformSpiConfig &config = {-1, {-1}, -1, 0, -1, -1}) + : DisplaySSD1306B_64x48(m_spi, rstPin) + , m_spi(*this, config.dc, + SPlatformSpiConfig{ + config.busId, {config.cs}, config.dc, config.frequency ?: 10000000, config.scl, config.sda}) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override; + + /** + * Closes connection to display + */ + void end() override; + +private: + InterfaceSSD1306B m_spi; +}; + +/** + * Template class implements SSD1306B 64x48 lcd display in 1 bit mode over custom SPI implementation + * (user-defined spi implementation). I - user custom spi class + */ +template class DisplaySSD1306B_64x48_CustomSPI: public DisplaySSD1306B_64x48> +{ +public: + /** + * @brief Inits 64x48 lcd display over spi (based on SSD1306B controller): 1-bit mode. + * + * Inits 64x48 lcd display over spi (based on SSD1306B controller): 1-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param dcPin pin to use as data/command control pin + * @param data variable argument list for custom user spi interface. + */ + template + DisplaySSD1306B_64x48_CustomSPI(int8_t rstPin, int8_t dcPin, Args &&... data) + : DisplaySSD1306B_64x48>(m_spi, rstPin) + , m_spi(*this, dcPin, data...) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override + { + m_spi.begin(); + DisplaySSD1306B_64x48>::begin(); + } + + /** + * Closes connection to display + */ + void end() override + { + DisplaySSD1306B_64x48>::end(); + m_spi.end(); + } + +private: + InterfaceSSD1306B m_spi; +}; +/** + * Class implements SSD1306B 64x48 lcd display in 1 bit mode over I2C + */ +class DisplaySSD1306B_64x48_I2C: public DisplaySSD1306B_64x48> +{ +public: + /** + * @brief Inits 64x48 lcd display over i2c (based on SSD1306B controller): 1-bit mode. + * + * Inits 64x48 lcd display over i2c (based on SSD1306B controller): 1-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param config platform i2c configuration. Please refer to SPlatformI2cConfig. + */ + explicit DisplaySSD1306B_64x48_I2C(int8_t rstPin, const SPlatformI2cConfig &config = {-1, 0x3C, -1, -1, 0}) + : DisplaySSD1306B_64x48(m_i2c, rstPin) + , m_i2c(*this, -1, + SPlatformI2cConfig{config.busId, static_cast(config.addr ?: 0x3C), config.scl, config.sda, + config.frequency ?: 400000}) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override; + + /** + * Closes connection to display + */ + void end() override; + +private: + InterfaceSSD1306B m_i2c; +}; + +/** + * Template class implements SSD1306B 64x48 lcd display in 1 bit mode over custom I2C implementation + * (user-defined i2c implementation). I - user custom i2c class + */ +template class DisplaySSD1306B_64x48_CustomI2C: public DisplaySSD1306B_64x48> +{ +public: + /** + * @brief Inits 64x48 lcd display over i2c (based on SSD1306B controller): 1-bit mode. + * + * Inits 64x48 lcd display over i2c (based on SSD1306B controller): 1-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param data variable argument list for custom user i2c interface. + */ + template + DisplaySSD1306B_64x48_CustomI2C(int8_t rstPin, Args &&... data) + : DisplaySSD1306B_64x48>(m_i2c, rstPin) + , m_i2c(*this, -1, data...) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override + { + m_i2c.begin(); + DisplaySSD1306B_64x48>::begin(); + } + + /** + * Closes connection to display + */ + void end() override + { + DisplaySSD1306B_64x48>::end(); + m_i2c.end(); + } + +private: + InterfaceSSD1306B m_i2c; +}; +/** + * Template class implements SSD1306B 64x48 lcd display in 1 bit mode over custom interface implementation + * (user-defined interface implementation). I - user custom interface class. + * This class allows to use display over 6800 and 8080 parallel interfaces + */ +template class DisplaySSD1306B_64x48_Custom: public DisplaySSD1306B_64x48> +{ +public: + /** + * @brief Inits 64x48 lcd display over custom interface (based on SSD1306B controller): 1-bit mode. + * + * Inits 64x48 lcd display over custom interface (based on SSD1306B controller): 1-bit mode + * User-defined interface `I` will receive frequency (uint32_t) as first argument, and user additional args, + * specified as data variable argument list. + * + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param dcPin pin to use as data/command control pin (-1 if not used) + * @param frequency frequency in HZ, or 0 if to use default display frequency + * @param data variable argument list for custom user interface. + */ + template + DisplaySSD1306B_64x48_Custom(int8_t rstPin, int8_t dcPin, uint32_t frequency, Args &&... data) + : DisplaySSD1306B_64x48>(m_custom, rstPin) + , m_custom(*this, dcPin, frequency = frequency ? frequency : 3000000, data...) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override + { + m_custom.begin(); + DisplaySSD1306B_64x48>::begin(); + } + + /** + * Closes connection to display + */ + void end() override + { + DisplaySSD1306B_64x48>::end(); + m_custom.end(); + } + +private: + InterfaceSSD1306B m_custom; +}; +/** + * Class implements basic functions for 1-bit mode of SSD1306B-based displays + */ +template class DisplaySSD1306B_128x32: public DisplaySSD1306B +{ +public: + /** + * Creates instance of SSD1306B 128x32 controller class for 1-bit mode + * + * @param intf interface to use + * @param rstPin pin to use as HW reset pin for LCD display + */ + DisplaySSD1306B_128x32(I &intf, int8_t rstPin) + : DisplaySSD1306B(intf, rstPin) + { + } + +protected: + /** + * Basic SSD1306B 128x32 initialization + */ + void begin() override; + + /** + * Basic SSD1306B deinitialization + */ + void end() override; +}; +/** + * Class implements SSD1306B 128x32 lcd display in 1 bit mode over SPI + */ +class DisplaySSD1306B_128x32_SPI: public DisplaySSD1306B_128x32> +{ +public: + /** + * @brief Inits 128x32 lcd display over spi (based on SSD1306B controller): 1-bit mode. + * + * Inits 128x32 lcd display over spi (based on SSD1306B controller): 1-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param config platform spi configuration. Please refer to SPlatformSpiConfig. + */ + explicit DisplaySSD1306B_128x32_SPI(int8_t rstPin, const SPlatformSpiConfig &config = {-1, {-1}, -1, 0, -1, -1}) + : DisplaySSD1306B_128x32(m_spi, rstPin) + , m_spi(*this, config.dc, + SPlatformSpiConfig{ + config.busId, {config.cs}, config.dc, config.frequency ?: 10000000, config.scl, config.sda}) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override; + + /** + * Closes connection to display + */ + void end() override; + +private: + InterfaceSSD1306B m_spi; +}; + +/** + * Template class implements SSD1306B 128x32 lcd display in 1 bit mode over custom SPI implementation + * (user-defined spi implementation). I - user custom spi class + */ +template class DisplaySSD1306B_128x32_CustomSPI: public DisplaySSD1306B_128x32> +{ +public: + /** + * @brief Inits 128x32 lcd display over spi (based on SSD1306B controller): 1-bit mode. + * + * Inits 128x32 lcd display over spi (based on SSD1306B controller): 1-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param dcPin pin to use as data/command control pin + * @param data variable argument list for custom user spi interface. + */ + template + DisplaySSD1306B_128x32_CustomSPI(int8_t rstPin, int8_t dcPin, Args &&... data) + : DisplaySSD1306B_128x32>(m_spi, rstPin) + , m_spi(*this, dcPin, data...) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override + { + m_spi.begin(); + DisplaySSD1306B_128x32>::begin(); + } + + /** + * Closes connection to display + */ + void end() override + { + DisplaySSD1306B_128x32>::end(); + m_spi.end(); + } + +private: + InterfaceSSD1306B m_spi; +}; +/** + * Class implements SSD1306B 128x32 lcd display in 1 bit mode over I2C + */ +class DisplaySSD1306B_128x32_I2C: public DisplaySSD1306B_128x32> +{ +public: + /** + * @brief Inits 128x32 lcd display over i2c (based on SSD1306B controller): 1-bit mode. + * + * Inits 128x32 lcd display over i2c (based on SSD1306B controller): 1-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param config platform i2c configuration. Please refer to SPlatformI2cConfig. + */ + explicit DisplaySSD1306B_128x32_I2C(int8_t rstPin, const SPlatformI2cConfig &config = {-1, 0x3C, -1, -1, 0}) + : DisplaySSD1306B_128x32(m_i2c, rstPin) + , m_i2c(*this, -1, + SPlatformI2cConfig{config.busId, static_cast(config.addr ?: 0x3C), config.scl, config.sda, + config.frequency ?: 400000}) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override; + + /** + * Closes connection to display + */ + void end() override; + +private: + InterfaceSSD1306B m_i2c; +}; + +/** + * Template class implements SSD1306B 128x32 lcd display in 1 bit mode over custom I2C implementation + * (user-defined i2c implementation). I - user custom i2c class + */ +template class DisplaySSD1306B_128x32_CustomI2C: public DisplaySSD1306B_128x32> +{ +public: + /** + * @brief Inits 128x32 lcd display over i2c (based on SSD1306B controller): 1-bit mode. + * + * Inits 128x32 lcd display over i2c (based on SSD1306B controller): 1-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param data variable argument list for custom user i2c interface. + */ + template + DisplaySSD1306B_128x32_CustomI2C(int8_t rstPin, Args &&... data) + : DisplaySSD1306B_128x32>(m_i2c, rstPin) + , m_i2c(*this, -1, data...) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override + { + m_i2c.begin(); + DisplaySSD1306B_128x32>::begin(); + } + + /** + * Closes connection to display + */ + void end() override + { + DisplaySSD1306B_128x32>::end(); + m_i2c.end(); + } + +private: + InterfaceSSD1306B m_i2c; +}; +/** + * Template class implements SSD1306B 128x32 lcd display in 1 bit mode over custom interface implementation + * (user-defined interface implementation). I - user custom interface class. + * This class allows to use display over 6800 and 8080 parallel interfaces + */ +template class DisplaySSD1306B_128x32_Custom: public DisplaySSD1306B_128x32> +{ +public: + /** + * @brief Inits 128x32 lcd display over custom interface (based on SSD1306B controller): 1-bit mode. + * + * Inits 128x32 lcd display over custom interface (based on SSD1306B controller): 1-bit mode + * User-defined interface `I` will receive frequency (uint32_t) as first argument, and user additional args, + * specified as data variable argument list. + * + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param dcPin pin to use as data/command control pin (-1 if not used) + * @param frequency frequency in HZ, or 0 if to use default display frequency + * @param data variable argument list for custom user interface. + */ + template + DisplaySSD1306B_128x32_Custom(int8_t rstPin, int8_t dcPin, uint32_t frequency, Args &&... data) + : DisplaySSD1306B_128x32>(m_custom, rstPin) + , m_custom(*this, dcPin, frequency = frequency ? frequency : 3000000, data...) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override + { + m_custom.begin(); + DisplaySSD1306B_128x32>::begin(); + } + + /** + * Closes connection to display + */ + void end() override + { + DisplaySSD1306B_128x32>::end(); + m_custom.end(); + } + +private: + InterfaceSSD1306B m_custom; +}; +/** + * Class implements basic functions for 1-bit mode of SSD1306B-based displays + */ +template class DisplaySSD1306B_128x64: public DisplaySSD1306B +{ +public: + /** + * Creates instance of SSD1306B 128x64 controller class for 1-bit mode + * + * @param intf interface to use + * @param rstPin pin to use as HW reset pin for LCD display + */ + DisplaySSD1306B_128x64(I &intf, int8_t rstPin) + : DisplaySSD1306B(intf, rstPin) + { + } + +protected: + /** + * Basic SSD1306B 128x64 initialization + */ + void begin() override; + + /** + * Basic SSD1306B deinitialization + */ + void end() override; +}; +/** + * Class implements SSD1306B 128x64 lcd display in 1 bit mode over SPI + */ +class DisplaySSD1306B_128x64_SPI: public DisplaySSD1306B_128x64> +{ +public: + /** + * @brief Inits 128x64 lcd display over spi (based on SSD1306B controller): 1-bit mode. + * + * Inits 128x64 lcd display over spi (based on SSD1306B controller): 1-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param config platform spi configuration. Please refer to SPlatformSpiConfig. + */ + explicit DisplaySSD1306B_128x64_SPI(int8_t rstPin, const SPlatformSpiConfig &config = {-1, {-1}, -1, 0, -1, -1}) + : DisplaySSD1306B_128x64(m_spi, rstPin) + , m_spi(*this, config.dc, + SPlatformSpiConfig{ + config.busId, {config.cs}, config.dc, config.frequency ?: 10000000, config.scl, config.sda}) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override; + + /** + * Closes connection to display + */ + void end() override; + +private: + InterfaceSSD1306B m_spi; +}; + +/** + * Template class implements SSD1306B 128x64 lcd display in 1 bit mode over custom SPI implementation + * (user-defined spi implementation). I - user custom spi class + */ +template class DisplaySSD1306B_128x64_CustomSPI: public DisplaySSD1306B_128x64> +{ +public: + /** + * @brief Inits 128x64 lcd display over spi (based on SSD1306B controller): 1-bit mode. + * + * Inits 128x64 lcd display over spi (based on SSD1306B controller): 1-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param dcPin pin to use as data/command control pin + * @param data variable argument list for custom user spi interface. + */ + template + DisplaySSD1306B_128x64_CustomSPI(int8_t rstPin, int8_t dcPin, Args &&... data) + : DisplaySSD1306B_128x64>(m_spi, rstPin) + , m_spi(*this, dcPin, data...) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override + { + m_spi.begin(); + DisplaySSD1306B_128x64>::begin(); + } + + /** + * Closes connection to display + */ + void end() override + { + DisplaySSD1306B_128x64>::end(); + m_spi.end(); + } + +private: + InterfaceSSD1306B m_spi; +}; +/** + * Class implements SSD1306B 128x64 lcd display in 1 bit mode over I2C + */ +class DisplaySSD1306B_128x64_I2C: public DisplaySSD1306B_128x64> +{ +public: + /** + * @brief Inits 128x64 lcd display over i2c (based on SSD1306B controller): 1-bit mode. + * + * Inits 128x64 lcd display over i2c (based on SSD1306B controller): 1-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param config platform i2c configuration. Please refer to SPlatformI2cConfig. + */ + explicit DisplaySSD1306B_128x64_I2C(int8_t rstPin, const SPlatformI2cConfig &config = {-1, 0x3C, -1, -1, 0}) + : DisplaySSD1306B_128x64(m_i2c, rstPin) + , m_i2c(*this, -1, + SPlatformI2cConfig{config.busId, static_cast(config.addr ?: 0x3C), config.scl, config.sda, + config.frequency ?: 400000}) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override; + + /** + * Closes connection to display + */ + void end() override; + +private: + InterfaceSSD1306B m_i2c; +}; + +/** + * Template class implements SSD1306B 128x64 lcd display in 1 bit mode over custom I2C implementation + * (user-defined i2c implementation). I - user custom i2c class + */ +template class DisplaySSD1306B_128x64_CustomI2C: public DisplaySSD1306B_128x64> +{ +public: + /** + * @brief Inits 128x64 lcd display over i2c (based on SSD1306B controller): 1-bit mode. + * + * Inits 128x64 lcd display over i2c (based on SSD1306B controller): 1-bit mode + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param data variable argument list for custom user i2c interface. + */ + template + DisplaySSD1306B_128x64_CustomI2C(int8_t rstPin, Args &&... data) + : DisplaySSD1306B_128x64>(m_i2c, rstPin) + , m_i2c(*this, -1, data...) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override + { + m_i2c.begin(); + DisplaySSD1306B_128x64>::begin(); + } + + /** + * Closes connection to display + */ + void end() override + { + DisplaySSD1306B_128x64>::end(); + m_i2c.end(); + } + +private: + InterfaceSSD1306B m_i2c; +}; +/** + * Template class implements SSD1306B 128x64 lcd display in 1 bit mode over custom interface implementation + * (user-defined interface implementation). I - user custom interface class. + * This class allows to use display over 6800 and 8080 parallel interfaces + */ +template class DisplaySSD1306B_128x64_Custom: public DisplaySSD1306B_128x64> +{ +public: + /** + * @brief Inits 128x64 lcd display over custom interface (based on SSD1306B controller): 1-bit mode. + * + * Inits 128x64 lcd display over custom interface (based on SSD1306B controller): 1-bit mode + * User-defined interface `I` will receive frequency (uint32_t) as first argument, and user additional args, + * specified as data variable argument list. + * + * @param rstPin pin controlling LCD reset (-1 if not used) + * @param dcPin pin to use as data/command control pin (-1 if not used) + * @param frequency frequency in HZ, or 0 if to use default display frequency + * @param data variable argument list for custom user interface. + */ + template + DisplaySSD1306B_128x64_Custom(int8_t rstPin, int8_t dcPin, uint32_t frequency, Args &&... data) + : DisplaySSD1306B_128x64>(m_custom, rstPin) + , m_custom(*this, dcPin, frequency = frequency ? frequency : 3000000, data...) + { + } + + /** + * Initializes SSD1306B lcd in 1-bit mode + */ + void begin() override + { + m_custom.begin(); + DisplaySSD1306B_128x64>::begin(); + } + + /** + * Closes connection to display + */ + void end() override + { + DisplaySSD1306B_128x64>::end(); + m_custom.end(); + } + +private: + InterfaceSSD1306B m_custom; +}; +#include "lcd_ssd1306b.inl" + +/** + * @} + */ diff --git a/src/v2/lcd/ssd1306b/lcd_ssd1306b.inl b/src/v2/lcd/ssd1306b/lcd_ssd1306b.inl new file mode 100644 index 00000000..95dcc7f1 --- /dev/null +++ b/src/v2/lcd/ssd1306b/lcd_ssd1306b.inl @@ -0,0 +1,337 @@ +/* + MIT License + + Copyright 2019-2022 (C) Alexey Dynda + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +/* !!! THIS FILE IS AUTO GENERATED !!! */ +#include "lcd_hal/io.h" +#ifdef SDL_EMULATION +#include "sdl_core.h" +#endif +#include "nano_gfx_types.h" + +#ifndef CMD_ARG +#define CMD_ARG 0xFF +#endif + +template void InterfaceSSD1306B::startBlock(lcduint_t x, lcduint_t y, lcduint_t w) +{ + commandStart(); + this->send(0x21); // column addr + this->send(x); + this->send(w ? (x + w - 1) : (m_base.width() - 1)); + this->send(0x22); // page addr + this->send(y); + this->send((m_base.height() >> 3) - 1); + if ( m_dc >= 0 ) + { + setDataMode(1); + } + else + { + this->stop(); + this->start(); + this->send(0x40); + } +} + +template void InterfaceSSD1306B::nextBlock() +{ + +} + +template void InterfaceSSD1306B::endBlock() +{ + this->stop(); +} + +template void InterfaceSSD1306B::setDataMode(uint8_t mode) +{ + if ( m_dc >= 0 ) + { + lcd_gpioWrite(m_dc, mode ? LCD_HIGH : LCD_LOW); + } +} + +template void InterfaceSSD1306B::commandStart() +{ + this->start(); + if ( m_dc >= 0 ) + setDataMode(0); + else + this->send(0x00); +} + +template void InterfaceSSD1306B::setStartLine(uint8_t line) +{ + m_startLine = line; + commandStart(); + this->send( 0x40 | (line & 0x3F) ); // start line + this->stop(); +} + +template uint8_t InterfaceSSD1306B::getStartLine() +{ + return m_startLine; +} + +template void InterfaceSSD1306B::normalMode() +{ + commandStart(); + this->send(0xA6); // Normal display + this->stop(); +} + +template void InterfaceSSD1306B::invertMode() +{ + commandStart(); + this->send(0xA7); // Invert display + this->stop(); +} + +template void InterfaceSSD1306B::setContrast(uint8_t contrast) +{ + commandStart(); + this->send(0x81); // set contrast + this->send(contrast); + this->stop(); +} + +template void InterfaceSSD1306B::displayOff() +{ + commandStart(); + this->send(0xAE); // display off + this->stop(); +} + +template void InterfaceSSD1306B::displayOn() +{ + commandStart(); + this->send(0xAF); // display on + this->stop(); +} + +template void InterfaceSSD1306B::flipHorizontal(uint8_t mode) +{ + commandStart(); + this->send( 0xA0 | (mode ? 0x00: 0x01 ) ); // seg remap + this->stop(); +} + +template void InterfaceSSD1306B::flipVertical(uint8_t mode) +{ + commandStart(); + this->send( mode ? 0xC0 : 0xC8 ); + this->stop(); +} + + +//////////////////////////////////////////////////////////////////////////////// +// SSD1306B basic 1-bit implementation +//////////////////////////////////////////////////////////////////////////////// + +template void DisplaySSD1306B::begin() +{ +} + +template void DisplaySSD1306B::end() +{ +} + +static const PROGMEM uint8_t s_SSD1306B_lcd64x32_initData[] = { +#ifdef SDL_EMULATION + SDL_LCD_SSD1306B, 0x00, + 0x00, 0x00, +#endif + 0xAE, 0x00, // display off + 0x20, 0x00, // Page horizontal Addressing mode + 0xC8, // Scan from 127 to 0 (Reverse scan) + 0x40| 0x00, // First line to start scanning from + 0x81, 0xFF, // contast value to 0xFF for maximum brightness + 0xA0| 0x01, // Use reverse mapping. 0x00 - is normal mapping + 0xA6, // Normal display + 0xA8, 63, // Reset to default MUX. See datasheet + 0xD3, 0x00, // no offset + 0xD5, 0x80, // set to default ratio/osc frequency + 0xD9, 0xF1, // switch precharge to 0x22 // 0xF1 + 0xDA, 0x12, // set divide ratio + 0xDB, 0x30, // vcom deselect to 0x30 + 0x8D, 0x95, // Enable charge pump 9V + 0xAD, 0x30, // Internal Iref setting 30uA + 0xA4, // Display resume + 0xAF, // Display on +}; + +//////////////////////////////////////////////////////////////////////////////// +// SSD1306B basic 1-bit implementation +//////////////////////////////////////////////////////////////////////////////// + +template void DisplaySSD1306B_64x32::begin() +{ + ssd1306_resetController2(this->m_rstPin, 10); + this->m_w = 64; + this->m_h = 32; + // Give LCD some time to initialize. Refer to SSD1306B datasheet + lcd_delay(0); + _configureSpiDisplayCmdModeOnly(this->m_intf, + s_SSD1306B_lcd64x32_initData, + sizeof(s_SSD1306B_lcd64x32_initData)); + +} + +template void DisplaySSD1306B_64x32::end() +{ +} + +static const PROGMEM uint8_t s_SSD1306B_lcd64x48_initData[] = { +#ifdef SDL_EMULATION + SDL_LCD_SSD1306B, 0x00, + 0x00, 0x00, +#endif + 0xAE, 0x00, // display off + 0x20, 0x00, // Page horizontal Addressing mode + 0xC8, // Scan from 127 to 0 (Reverse scan) + 0x40| 0x00, // First line to start scanning from + 0x81, 0xFF, // contast value to 0xFF for maximum brightness + 0xA0| 0x01, // Use reverse mapping. 0x00 - is normal mapping + 0xA6, // Normal display + 0xA8, 63, // Reset to default MUX. See datasheet + 0xD3, 0x00, // no offset + 0xD5, 0x80, // set to default ratio/osc frequency + 0xD9, 0xF1, // switch precharge to 0x22 // 0xF1 + 0xDA, 0x12, // set divide ratio + 0xDB, 0x30, // vcom deselect to 0x30 + 0x8D, 0x95, // Enable charge pump 9V + 0xAD, 0x30, // Internal Iref setting 30uA + 0xA4, // Display resume + 0xAF, // Display on +}; + +//////////////////////////////////////////////////////////////////////////////// +// SSD1306B basic 1-bit implementation +//////////////////////////////////////////////////////////////////////////////// + +template void DisplaySSD1306B_64x48::begin() +{ + ssd1306_resetController2(this->m_rstPin, 10); + this->m_w = 64; + this->m_h = 48; + // Give LCD some time to initialize. Refer to SSD1306B datasheet + lcd_delay(0); + _configureSpiDisplayCmdModeOnly(this->m_intf, + s_SSD1306B_lcd64x48_initData, + sizeof(s_SSD1306B_lcd64x48_initData)); + +} + +template void DisplaySSD1306B_64x48::end() +{ +} + +static const PROGMEM uint8_t s_SSD1306B_lcd128x32_initData[] = { +#ifdef SDL_EMULATION + SDL_LCD_SSD1306B, 0x00, + 0x00, 0x00, +#endif + 0xAE, 0x00, // display off + 0x20, 0x00, // Page horizontal Addressing mode + 0xC8, // Scan from 127 to 0 (Reverse scan) + 0x40| 0x00, // First line to start scanning from + 0x81, 0xFF, // contast value to 0xFF for maximum brightness + 0xA0| 0x01, // Use reverse mapping. 0x00 - is normal mapping + 0xA6, // Normal display + 0xA8, 63, // Reset to default MUX. See datasheet + 0xD3, 0x00, // no offset + 0xD5, 0x80, // set to default ratio/osc frequency + 0xD9, 0xF1, // switch precharge to 0x22 // 0xF1 + 0xDA, 0x12, // set divide ratio + 0xDB, 0x30, // vcom deselect to 0x30 + 0x8D, 0x95, // Enable charge pump 9V + 0xAD, 0x30, // Internal Iref setting 30uA + 0xA4, // Display resume + 0xAF, // Display on +}; + +//////////////////////////////////////////////////////////////////////////////// +// SSD1306B basic 1-bit implementation +//////////////////////////////////////////////////////////////////////////////// + +template void DisplaySSD1306B_128x32::begin() +{ + ssd1306_resetController2(this->m_rstPin, 10); + this->m_w = 128; + this->m_h = 32; + // Give LCD some time to initialize. Refer to SSD1306B datasheet + lcd_delay(0); + _configureSpiDisplayCmdModeOnly(this->m_intf, + s_SSD1306B_lcd128x32_initData, + sizeof(s_SSD1306B_lcd128x32_initData)); + +} + +template void DisplaySSD1306B_128x32::end() +{ +} + +static const PROGMEM uint8_t s_SSD1306B_lcd128x64_initData[] = { +#ifdef SDL_EMULATION + SDL_LCD_SSD1306B, 0x00, + 0x00, 0x00, +#endif + 0xAE, 0x00, // display off + 0x20, 0x00, // Page horizontal Addressing mode + 0xC8, // Scan from 127 to 0 (Reverse scan) + 0x40| 0x00, // First line to start scanning from + 0x81, 0xFF, // contast value to 0xFF for maximum brightness + 0xA0| 0x01, // Use reverse mapping. 0x00 - is normal mapping + 0xA6, // Normal display + 0xA8, 63, // Reset to default MUX. See datasheet + 0xD3, 0x00, // no offset + 0xD5, 0x80, // set to default ratio/osc frequency + 0xD9, 0xF1, // switch precharge to 0x22 // 0xF1 + 0xDA, 0x12, // set divide ratio + 0xDB, 0x30, // vcom deselect to 0x30 + 0x8D, 0x95, // Enable charge pump 9V + 0xAD, 0x30, // Internal Iref setting 30uA + 0xA4, // Display resume + 0xAF, // Display on +}; + +//////////////////////////////////////////////////////////////////////////////// +// SSD1306B basic 1-bit implementation +//////////////////////////////////////////////////////////////////////////////// + +template void DisplaySSD1306B_128x64::begin() +{ + ssd1306_resetController2(this->m_rstPin, 10); + this->m_w = 128; + this->m_h = 64; + // Give LCD some time to initialize. Refer to SSD1306B datasheet + lcd_delay(0); + _configureSpiDisplayCmdModeOnly(this->m_intf, + s_SSD1306B_lcd128x64_initData, + sizeof(s_SSD1306B_lcd128x64_initData)); + +} + +template void DisplaySSD1306B_128x64::end() +{ +} diff --git a/tools/templates/lcd/ssd1306b/fields/Interface~CONTROLLER~ b/tools/templates/lcd/ssd1306b/fields/Interface~CONTROLLER~ new file mode 100644 index 00000000..24a4138c --- /dev/null +++ b/tools/templates/lcd/ssd1306b/fields/Interface~CONTROLLER~ @@ -0,0 +1,4 @@ +private: + int8_t m_dc = -1; ///< data/command pin for SPI, -1 for i2c + NanoDisplayBase> &m_base; ///< basic lcd display support interface + uint8_t m_startLine = 0; diff --git a/tools/templates/lcd/ssd1306b/functions/displayOff/code b/tools/templates/lcd/ssd1306b/functions/displayOff/code new file mode 100644 index 00000000..9874ca87 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/displayOff/code @@ -0,0 +1,3 @@ + commandStart(); + this->send(0xAE); // display off + this->stop(); diff --git a/tools/templates/lcd/ssd1306b/functions/displayOff/decl b/tools/templates/lcd/ssd1306b/functions/displayOff/decl new file mode 100644 index 00000000..cbab1f6b --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/displayOff/decl @@ -0,0 +1 @@ +void diff --git a/tools/templates/lcd/ssd1306b/functions/displayOff/doc b/tools/templates/lcd/ssd1306b/functions/displayOff/doc new file mode 100644 index 00000000..6abc0f30 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/displayOff/doc @@ -0,0 +1,3 @@ + /** + * Turns off display + */ diff --git a/tools/templates/lcd/ssd1306b/functions/displayOn/code b/tools/templates/lcd/ssd1306b/functions/displayOn/code new file mode 100644 index 00000000..4690c675 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/displayOn/code @@ -0,0 +1,3 @@ + commandStart(); + this->send(0xAF); // display on + this->stop(); diff --git a/tools/templates/lcd/ssd1306b/functions/displayOn/decl b/tools/templates/lcd/ssd1306b/functions/displayOn/decl new file mode 100644 index 00000000..cbab1f6b --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/displayOn/decl @@ -0,0 +1 @@ +void diff --git a/tools/templates/lcd/ssd1306b/functions/displayOn/doc b/tools/templates/lcd/ssd1306b/functions/displayOn/doc new file mode 100644 index 00000000..2853f50a --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/displayOn/doc @@ -0,0 +1,3 @@ + /** + * Turns on display + */ diff --git a/tools/templates/lcd/ssd1306b/functions/flipHorizontal/code b/tools/templates/lcd/ssd1306b/functions/flipHorizontal/code new file mode 100644 index 00000000..66da45b3 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/flipHorizontal/code @@ -0,0 +1,3 @@ + commandStart(); + this->send( 0xA0 | (mode ? 0x00: 0x01 ) ); // seg remap + this->stop(); diff --git a/tools/templates/lcd/ssd1306b/functions/flipHorizontal/decl b/tools/templates/lcd/ssd1306b/functions/flipHorizontal/decl new file mode 100644 index 00000000..1b0e282b --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/flipHorizontal/decl @@ -0,0 +1,2 @@ +void +uint8_t mode diff --git a/tools/templates/lcd/ssd1306b/functions/flipHorizontal/doc b/tools/templates/lcd/ssd1306b/functions/flipHorizontal/doc new file mode 100644 index 00000000..01629640 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/flipHorizontal/doc @@ -0,0 +1,9 @@ + /** + * @brief performs horizontal flip + * + * Performs horizontal flip. If you need to turn display by 180 degree, + * please use both flipHorizontal() and flipVertical(). + * + * @param mode - 0 to disable horizontal flip + * 1 to enable horizontal flip + */ diff --git a/tools/templates/lcd/ssd1306b/functions/flipVertical/code b/tools/templates/lcd/ssd1306b/functions/flipVertical/code new file mode 100644 index 00000000..7c37b1fe --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/flipVertical/code @@ -0,0 +1,3 @@ + commandStart(); + this->send( mode ? 0xC0 : 0xC8 ); + this->stop(); diff --git a/tools/templates/lcd/ssd1306b/functions/flipVertical/decl b/tools/templates/lcd/ssd1306b/functions/flipVertical/decl new file mode 100644 index 00000000..1b0e282b --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/flipVertical/decl @@ -0,0 +1,2 @@ +void +uint8_t mode diff --git a/tools/templates/lcd/ssd1306b/functions/flipVertical/doc b/tools/templates/lcd/ssd1306b/functions/flipVertical/doc new file mode 100644 index 00000000..08027113 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/flipVertical/doc @@ -0,0 +1,9 @@ + /** + * @brief performs vertical flip + * + * Performs vertical flip. If you need to turn display by 180 degree, + * please use both flipHorizontal() and flipVertical(). + * + * @param mode - 0 to disable vertical flip + * 1 to enable vertical flip + */ diff --git a/tools/templates/lcd/ssd1306b/functions/getStartLine/code b/tools/templates/lcd/ssd1306b/functions/getStartLine/code new file mode 100644 index 00000000..a66d8811 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/getStartLine/code @@ -0,0 +1 @@ + return m_startLine; diff --git a/tools/templates/lcd/ssd1306b/functions/getStartLine/decl b/tools/templates/lcd/ssd1306b/functions/getStartLine/decl new file mode 100644 index 00000000..0e38a17e --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/getStartLine/decl @@ -0,0 +1 @@ +uint8_t diff --git a/tools/templates/lcd/ssd1306b/functions/getStartLine/doc b/tools/templates/lcd/ssd1306b/functions/getStartLine/doc new file mode 100644 index 00000000..02de9a33 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/getStartLine/doc @@ -0,0 +1,3 @@ + /** + * returns start line in gdram. + */ diff --git a/tools/templates/lcd/ssd1306b/functions/invertMode/code b/tools/templates/lcd/ssd1306b/functions/invertMode/code new file mode 100644 index 00000000..c62e10c4 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/invertMode/code @@ -0,0 +1,3 @@ + commandStart(); + this->send(0xA7); // Invert display + this->stop(); diff --git a/tools/templates/lcd/ssd1306b/functions/invertMode/decl b/tools/templates/lcd/ssd1306b/functions/invertMode/decl new file mode 100644 index 00000000..cbab1f6b --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/invertMode/decl @@ -0,0 +1 @@ +void diff --git a/tools/templates/lcd/ssd1306b/functions/invertMode/doc b/tools/templates/lcd/ssd1306b/functions/invertMode/doc new file mode 100644 index 00000000..801c24f2 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/invertMode/doc @@ -0,0 +1,4 @@ + /** + * Switches display to normal mode. This feature is specific + * for ~CONTROLLER~ based controllers. + */ diff --git a/tools/templates/lcd/ssd1306b/functions/normalMode/code b/tools/templates/lcd/ssd1306b/functions/normalMode/code new file mode 100644 index 00000000..a02afa7c --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/normalMode/code @@ -0,0 +1,3 @@ + commandStart(); + this->send(0xA6); // Normal display + this->stop(); diff --git a/tools/templates/lcd/ssd1306b/functions/normalMode/decl b/tools/templates/lcd/ssd1306b/functions/normalMode/decl new file mode 100644 index 00000000..cbab1f6b --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/normalMode/decl @@ -0,0 +1 @@ +void diff --git a/tools/templates/lcd/ssd1306b/functions/normalMode/doc b/tools/templates/lcd/ssd1306b/functions/normalMode/doc new file mode 100644 index 00000000..801c24f2 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/normalMode/doc @@ -0,0 +1,4 @@ + /** + * Switches display to normal mode. This feature is specific + * for ~CONTROLLER~ based controllers. + */ diff --git a/tools/templates/lcd/ssd1306b/functions/setContrast/code b/tools/templates/lcd/ssd1306b/functions/setContrast/code new file mode 100644 index 00000000..85dba8a3 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/setContrast/code @@ -0,0 +1,4 @@ + commandStart(); + this->send(0x81); // set contrast + this->send(contrast); + this->stop(); diff --git a/tools/templates/lcd/ssd1306b/functions/setContrast/decl b/tools/templates/lcd/ssd1306b/functions/setContrast/decl new file mode 100644 index 00000000..cffd9070 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/setContrast/decl @@ -0,0 +1,2 @@ +void +uint8_t contrast diff --git a/tools/templates/lcd/ssd1306b/functions/setContrast/doc b/tools/templates/lcd/ssd1306b/functions/setContrast/doc new file mode 100644 index 00000000..8d6f3dfd --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/setContrast/doc @@ -0,0 +1,4 @@ + /** + * Set display contrast, ie light intensity + * @param contrast - contrast value to see, refer to ~CONTROLLER~ datasheet + */ diff --git a/tools/templates/lcd/ssd1306b/functions/setStartLine/code b/tools/templates/lcd/ssd1306b/functions/setStartLine/code new file mode 100644 index 00000000..f796aa14 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/setStartLine/code @@ -0,0 +1,4 @@ + m_startLine = line; + commandStart(); + this->send( 0x40 | (line & 0x3F) ); // start line + this->stop(); diff --git a/tools/templates/lcd/ssd1306b/functions/setStartLine/decl b/tools/templates/lcd/ssd1306b/functions/setStartLine/decl new file mode 100644 index 00000000..834dc1f9 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/setStartLine/decl @@ -0,0 +1,2 @@ +void +uint8_t line diff --git a/tools/templates/lcd/ssd1306b/functions/setStartLine/doc b/tools/templates/lcd/ssd1306b/functions/setStartLine/doc new file mode 100644 index 00000000..a61332a1 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/setStartLine/doc @@ -0,0 +1,5 @@ + /** + * Sets start line in gdram to start display content with + * + * @param line start line in range 0 - 63 + */ diff --git a/tools/templates/lcd/ssd1306b/functions/startBlock/code b/tools/templates/lcd/ssd1306b/functions/startBlock/code new file mode 100644 index 00000000..6f0194b3 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/functions/startBlock/code @@ -0,0 +1,17 @@ + commandStart(); + this->send(0x21); // column addr + this->send(x); + this->send(w ? (x + w - 1) : (m_base.width() - 1)); + this->send(0x22); // page addr + this->send(y); + this->send((m_base.height() >> 3) - 1); + if ( m_dc >= 0 ) + { + setDataMode(1); + } + else + { + this->stop(); + this->start(); + this->send(0x40); + } diff --git a/tools/templates/lcd/ssd1306b/ssd1306b.json b/tools/templates/lcd/ssd1306b/ssd1306b.json new file mode 100644 index 00000000..b8695093 --- /dev/null +++ b/tools/templates/lcd/ssd1306b/ssd1306b.json @@ -0,0 +1,152 @@ +{ + "ssd1306b": + { + "options": + { + "no_bits_in_name": true, + "config_func": "_configureSpiDisplayCmdModeOnly", + "args_in_cmd_mode": true, + "row_div": 8, + "reset_duration": 10, + "reset_delay": 0 + }, + "interfaces": + { + "spi": + { + "frequency": 10000000 + }, + "i2c": + { + "frequency": 400000, + "addr": "0x3C" + }, + "custom": + { + "frequency": 3000000 + } + }, + "functions": + { + "interface_list": ["setStartLine", "getStartLine", + "normalMode", "invertMode", "setContrast", + "displayOff", "displayOn", + "flipHorizontal", "flipVertical" ] + }, + "bits": + { + "1": + { + "64x32": + { + "init": + [ + "#ifdef SDL_EMULATION", + " SDL_LCD_SSD1306B, 0x00,", + " 0x00, 0x00,", + "#endif", + " 0xAE, 0x00, // display off", + " 0x20, 0x00, // Page horizontal Addressing mode", + " 0xC8, // Scan from 127 to 0 (Reverse scan)", + " 0x40| 0x00, // First line to start scanning from", + " 0x81, 0xFF, // contast value to 0xFF for maximum brightness", + " 0xA0| 0x01, // Use reverse mapping. 0x00 - is normal mapping", + " 0xA6, // Normal display", + " 0xA8, 63, // Reset to default MUX. See datasheet", + " 0xD3, 0x00, // no offset", + " 0xD5, 0x80, // set to default ratio/osc frequency", + " 0xD9, 0xF1, // switch precharge to 0x22 // 0xF1", + " 0xDA, 0x12, // set divide ratio", + " 0xDB, 0x30, // vcom deselect to 0x30", + " 0x8D, 0x95, // Enable charge pump 9V", + " 0xAD, 0x30, // Internal Iref setting 30uA", + " 0xA4, // Display resume", + " 0xAF, // Display on" + ] + }, + "64x48": + { + "init": + [ + "#ifdef SDL_EMULATION", + " SDL_LCD_SSD1306B, 0x00,", + " 0x00, 0x00,", + "#endif", + " 0xAE, 0x00, // display off", + " 0x20, 0x00, // Page horizontal Addressing mode", + " 0xC8, // Scan from 127 to 0 (Reverse scan)", + " 0x40| 0x00, // First line to start scanning from", + " 0x81, 0xFF, // contast value to 0xFF for maximum brightness", + " 0xA0| 0x01, // Use reverse mapping. 0x00 - is normal mapping", + " 0xA6, // Normal display", + " 0xA8, 63, // Reset to default MUX. See datasheet", + " 0xD3, 0x00, // no offset", + " 0xD5, 0x80, // set to default ratio/osc frequency", + " 0xD9, 0xF1, // switch precharge to 0x22 // 0xF1", + " 0xDA, 0x12, // set divide ratio", + " 0xDB, 0x30, // vcom deselect to 0x30", + " 0x8D, 0x95, // Enable charge pump 9V", + " 0xAD, 0x30, // Internal Iref setting 30uA", + " 0xA4, // Display resume", + " 0xAF, // Display on" + ] + }, + "128x32": + { + "init": + [ + "#ifdef SDL_EMULATION", + " SDL_LCD_SSD1306B, 0x00,", + " 0x00, 0x00,", + "#endif", + " 0xAE, 0x00, // display off", + " 0x20, 0x00, // Page horizontal Addressing mode", + " 0xC8, // Scan from 127 to 0 (Reverse scan)", + " 0x40| 0x00, // First line to start scanning from", + " 0x81, 0xFF, // contast value to 0xFF for maximum brightness", + " 0xA0| 0x01, // Use reverse mapping. 0x00 - is normal mapping", + " 0xA6, // Normal display", + " 0xA8, 63, // Reset to default MUX. See datasheet", + " 0xD3, 0x00, // no offset", + " 0xD5, 0x80, // set to default ratio/osc frequency", + " 0xD9, 0xF1, // switch precharge to 0x22 // 0xF1", + " 0xDA, 0x12, // set divide ratio", + " 0xDB, 0x30, // vcom deselect to 0x30", + " 0x8D, 0x95, // Enable charge pump 9V", + " 0xAD, 0x30, // Internal Iref setting 30uA", + " 0xA4, // Display resume", + " 0xAF, // Display on" + ] + }, + "128x64": + { + "init": + [ + "#ifdef SDL_EMULATION", + " SDL_LCD_SSD1306B, 0x00,", + " 0x00, 0x00,", + "#endif", + " 0xAE, 0x00, // display off", + " 0x20, 0x00, // Page horizontal Addressing mode", + " 0xC8, // Scan from 127 to 0 (Reverse scan)", + " 0x40| 0x00, // First line to start scanning from", + " 0x81, 0xFF, // contast value to 0xFF for maximum brightness", + " 0xA0| 0x01, // Use reverse mapping. 0x00 - is normal mapping", + " 0xA6, // Normal display", + " 0xA8, 63, // Reset to default MUX. See datasheet", + " 0xD3, 0x00, // no offset", + " 0xD5, 0x80, // set to default ratio/osc frequency", + " 0xD9, 0xF1, // switch precharge to 0x22 // 0xF1", + " 0xDA, 0x12, // set divide ratio", + " 0xDB, 0x30, // vcom deselect to 0x30", + " 0x8D, 0x95, // Enable charge pump 9V", + " 0xAD, 0x30, // Internal Iref setting 30uA", + " 0xA4, // Display resume", + " 0xAF, // Display on" + ] + } + } + } + } +} +