1111 */
1212// ----------------------------------------------------------------------------
1313
14+ #pragma once
1415#ifndef MODM_SSD1306_HPP
1516#define MODM_SSD1306_HPP
1617
1718#include < modm/architecture/interface/i2c_device.hpp>
1819#include < modm/architecture/utils.hpp>
1920#include < modm/processing/timer.hpp>
20- #include < modm/ui/display/monochrome_graphic_display_vertical.hpp>
2121
22- #include " ssd1306_register.hpp"
22+ #include < modm/ui/graphic/display.hpp>
23+ #include < modm/ui/graphic/buffer.hpp>
24+ #include < modm/ui/color/gray.hpp>
25+
26+ #include " ssd1306_defines.hpp"
27+
28+ using namespace modm ::graphic;
2329
2430namespace modm
2531{
@@ -50,16 +56,9 @@ struct ssd1306 : public ssd1306_register
5056 // LeftBottom = VerticalAndHorizontalScrollLeft,
5157 };
5258
53- enum class
54- DisplayMode : uint8_t
55- {
56- Normal = NormalDisplay,
57- Inverted = InvertedDisplay
58- };
59-
6059public:
6160 // / @cond
62- class Ssd1306_I2cWriteTransaction : public modm ::I2cWriteTransaction
61+ class Ssd1306_I2cWriteTransaction : public modm ::I2cWriteTransaction< uint8_t >
6362 {
6463 public:
6564 Ssd1306_I2cWriteTransaction (uint8_t address);
@@ -94,15 +93,19 @@ struct ssd1306 : public ssd1306_register
9493 * @author Thomas Sommer
9594 * @ingroup modm_driver_ssd1306
9695 */
97- template <class I2cMaster , uint8_t Height = 64 >
96+ template <class I2cMaster , uint16_t H = 64 >
9897class Ssd1306 : public ssd1306 ,
99- public MonochromeGraphicDisplayVertical< 128 , Height >,
98+ public graphic::Display<Monochrome, Size( 128 , H), false >,
10099 public I2cDevice<I2cMaster, 3 , ssd1306::Ssd1306_I2cWriteTransaction>
101100{
102- static_assert ((Height == 64 ) or (Height == 32 ), " Display height must be either 32 or 64 pixel!" );
101+ static_assert ((H == 64 ) or (H == 32 ), " Display height must be either 32 or 64 pixel!" );
102+ public:
103+ using ColorType = Monochrome;
104+ using Buffer = graphic::Buffer<ColorType, Size(128 , H)>;
103105
104- public:
105- Ssd1306 (uint8_t address = 0x3C );
106+ Ssd1306 (uint8_t address = 0x3C )
107+ : Display<Monochrome, Size(128 , H), false >(true ), I2cDevice<I2cMaster, 3 , ssd1306::Ssd1306_I2cWriteTransaction>(address)
108+ {}
106109
107110 // / Pings the display
108111 bool inline pingBlocking ()
@@ -112,10 +115,6 @@ class Ssd1306 : public ssd1306,
112115 bool inline initializeBlocking ()
113116 { return RF_CALL_BLOCKING (initialize ()); }
114117
115- // / Update the display with the content of the RAM buffer.
116- void
117- update () override
118- { RF_CALL_BLOCKING (startWriteDisplay ()); }
119118
120119 // / Use this method to synchronize writing to the displays buffer
121120 // / to avoid tearing.
@@ -128,16 +127,8 @@ class Ssd1306 : public ssd1306,
128127 modm::ResumableResult<bool >
129128 initialize ();
130129
131- // starts a frame transfer and waits for completion
132- virtual modm::ResumableResult<bool >
133- writeDisplay ();
134-
135130 modm::ResumableResult<bool >
136- setDisplayMode (DisplayMode mode = DisplayMode::Normal)
137- {
138- commandBuffer[0 ] = mode;
139- return writeCommands (1 );
140- }
131+ set (ssd1306_register::Toggle toggle, bool state);
141132
142133 modm::ResumableResult<bool >
143134 setContrast (uint8_t contrast = 0xCE )
@@ -148,13 +139,13 @@ class Ssd1306 : public ssd1306,
148139 }
149140
150141 /* *
151- * \ param orientation glcd ::Orientation::Landscape0 or glcd ::Orientation::Landscape180
142+ * @ param orientation display ::Orientation::Landscape0 or display ::Orientation::Landscape180
152143 */
153144 modm::ResumableResult<bool >
154- setOrientation (glcd ::Orientation orientation);
145+ setOrientation (graphic ::Orientation orientation);
155146
156147 modm::ResumableResult<bool >
157- configureScroll (uint8_t origin , uint8_t size, ScrollDirection direction, ScrollStep steps);
148+ configureScroll (uint8_t placement , uint8_t size, ScrollDirection direction, ScrollStep steps);
158149
159150 modm::ResumableResult<bool >
160151 enableScroll ()
@@ -170,16 +161,46 @@ class Ssd1306 : public ssd1306,
170161 return writeCommands (1 );
171162 }
172163
164+ // TODO Abstract these write(...) cause is common to all I2c Displays!
165+ // Write BufferInterface
166+ // Caution: placement.y rounds to multiples of 8
167+ modm::ResumableResult<bool >
168+ write (BufferInterface<Monochrome> &buffer, Point placement = {0 , 0 }) {
169+ RF_BEGIN ();
170+ RF_END_RETURN_CALL (writeImage (ImageAccessor<Monochrome, modm::accessor::Ram>(&buffer, placement)));
171+ }
172+
173+ // Write Flash Image
174+ modm::ResumableResult<bool >
175+ write (const uint8_t *addr, Point placement = {0 , 0 }) {
176+ RF_BEGIN ();
177+ RF_END_RETURN_CALL (writeImage (ImageAccessor<Monochrome, modm::accessor::Flash>(addr, placement)));
178+ }
179+
180+ // Clear whole screen with color
181+ modm::ResumableResult<bool >
182+ clear (Monochrome color = 0 );
183+
173184protected:
185+ virtual modm::ResumableResult<bool >
186+ updateClipping ();
187+
188+ // Write monochrome Image
189+ template <template <typename > class Accessor >
190+ modm::ResumableResult<bool >
191+ writeImage (ImageAccessor<Monochrome, Accessor> accessor);
192+
174193 modm::ResumableResult<bool >
175194 writeCommands (std::size_t length);
176195
177- virtual modm::ResumableResult<void >
196+ /* *
197+ * MemoryMode::HORIZONTAL and MemoryMode::VERTICAL have the best performance
198+ * because the whole buffer is send in one transaction.
199+ */
200+ virtual modm::ResumableResult<bool >
178201 initializeMemoryMode ();
179202
180- virtual modm::ResumableResult<void >
181- startWriteDisplay ();
182-
203+ // Static variables for resumable functions
183204 uint8_t commandBuffer[7 ];
184205 bool transaction_success;
185206};
0 commit comments