|
1 | 1 | /* |
2 | | - * Copyright (c) 2014, 2016-2017, Sascha Schade |
3 | | - * Copyright (c) 2014-2016, 2018, Niklas Hauser |
4 | | - * Copyright (c) 2021, Thomas Sommer |
| 2 | + * Copyright (c) 2023, Raphael Lehmann |
5 | 3 | * |
6 | 4 | * This file is part of the modm project. |
7 | 5 | * |
|
11 | 9 | */ |
12 | 10 | // ---------------------------------------------------------------------------- |
13 | 11 |
|
14 | | -#ifndef MODM_SSD1306_HPP |
15 | | -#define MODM_SSD1306_HPP |
16 | | - |
17 | | -#include <modm/architecture/interface/i2c_device.hpp> |
18 | | -#include <modm/architecture/utils.hpp> |
19 | | -#include <modm/processing/timer.hpp> |
20 | | -#include <modm/ui/display/monochrome_graphic_display_vertical.hpp> |
21 | | - |
22 | | -#include "ssd1306_register.hpp" |
23 | | - |
24 | | -namespace modm |
25 | | -{ |
26 | | - |
27 | | -/// @ingroup modm_driver_ssd1306 |
28 | | -struct ssd1306 : public ssd1306_register |
29 | | -{ |
30 | | -public: |
31 | | - enum class |
32 | | - ScrollStep : uint8_t |
33 | | - { |
34 | | - Frames2 = 0b111, |
35 | | - Frames3 = 0b100, |
36 | | - Frames4 = 0b101, |
37 | | - Frames5 = 0b000, |
38 | | - Frames25 = 0b110, |
39 | | - Frames64 = 0b001, |
40 | | - Frames128 = 0b010, |
41 | | - Frames256 = 0b011 |
42 | | - }; |
43 | | - |
44 | | - enum class |
45 | | - ScrollDirection : uint8_t |
46 | | - { |
47 | | - Right = HorizontalScrollRight, |
48 | | - Left = HorizontalScrollLeft, |
49 | | - // RightBottom = VerticalAndHorizontalScrollRight, |
50 | | - // LeftBottom = VerticalAndHorizontalScrollLeft, |
51 | | - }; |
52 | | - |
53 | | - enum class |
54 | | - DisplayMode : uint8_t |
55 | | - { |
56 | | - Normal = NormalDisplay, |
57 | | - Inverted = InvertedDisplay |
58 | | - }; |
59 | | - |
60 | | -public: |
61 | | - /// @cond |
62 | | - class Ssd1306_I2cWriteTransaction : public modm::I2cWriteTransaction |
63 | | - { |
64 | | - public: |
65 | | - Ssd1306_I2cWriteTransaction(uint8_t address); |
66 | | - |
67 | | - bool |
68 | | - configureDisplayWrite(const uint8_t *buffer, std::size_t size); |
69 | | - |
70 | | - protected: |
71 | | - virtual Writing |
72 | | - writing() override; |
73 | | - |
74 | | - virtual void |
75 | | - detaching(modm::I2c::DetachCause cause) override; |
76 | | - |
77 | | - inline bool |
78 | | - isWritable() |
79 | | - { return !transfer_active; } |
80 | | - |
81 | | - private: |
82 | | - uint8_t transfer_type; |
83 | | - bool transfer_active; |
84 | | - }; |
85 | | - /// @endcond |
86 | | -}; // struct ssd1306 |
87 | | - |
88 | | -/** |
89 | | - * Driver for SSD1306 based OLED-displays using I2C. |
90 | | - * This display is only rated to be driven with 400kHz, which limits |
91 | | - * the frame rate to about 40Hz. |
92 | | - * |
93 | | - * @author Niklas Hauser |
94 | | - * @author Thomas Sommer |
95 | | - * @ingroup modm_driver_ssd1306 |
96 | | - */ |
97 | | -template<class I2cMaster, uint8_t Height = 64> |
98 | | -class Ssd1306 : public ssd1306, |
99 | | - public MonochromeGraphicDisplayVertical<128, Height>, |
100 | | - public I2cDevice<I2cMaster, 3, ssd1306::Ssd1306_I2cWriteTransaction> |
101 | | -{ |
102 | | - static_assert((Height == 64) or (Height == 32), "Display height must be either 32 or 64 pixel!"); |
103 | | - |
104 | | -public: |
105 | | - Ssd1306(uint8_t address = 0x3C); |
106 | | - |
107 | | - /// Pings the display |
108 | | - bool inline pingBlocking() |
109 | | - { return RF_CALL_BLOCKING(this->ping()); } |
110 | | - |
111 | | - /// initializes for 3V3 with charge-pump |
112 | | - bool inline initializeBlocking() |
113 | | - { return RF_CALL_BLOCKING(initialize()); } |
114 | | - |
115 | | - /// Update the display with the content of the RAM buffer. |
116 | | - void |
117 | | - update() override |
118 | | - { RF_CALL_BLOCKING(startWriteDisplay()); } |
119 | | - |
120 | | - /// Use this method to synchronize writing to the displays buffer |
121 | | - /// to avoid tearing. |
122 | | - /// @return `true` if the frame buffer is not being copied to the display |
123 | | - bool isWritable() |
124 | | - { return this->transaction.isWriteable(); } |
125 | | - |
126 | | - // MARK: - TASKS |
127 | | - /// initializes for 3V3 with charge-pump asynchronously |
128 | | - modm::ResumableResult<bool> |
129 | | - initialize(); |
130 | | - |
131 | | - // starts a frame transfer and waits for completion |
132 | | - virtual modm::ResumableResult<bool> |
133 | | - writeDisplay(); |
134 | | - |
135 | | - modm::ResumableResult<bool> |
136 | | - setDisplayMode(DisplayMode mode = DisplayMode::Normal) |
137 | | - { |
138 | | - commandBuffer[0] = mode; |
139 | | - return writeCommands(1); |
140 | | - } |
141 | | - |
142 | | - modm::ResumableResult<bool> |
143 | | - setContrast(uint8_t contrast = 0xCE) |
144 | | - { |
145 | | - commandBuffer[0] = FundamentalCommands::ContrastControl; |
146 | | - commandBuffer[1] = contrast; |
147 | | - return writeCommands(2); |
148 | | - } |
149 | | - |
150 | | - /** |
151 | | - * \param orientation glcd::Orientation::Landscape0 or glcd::Orientation::Landscape180 |
152 | | - */ |
153 | | - modm::ResumableResult<bool> |
154 | | - setOrientation(glcd::Orientation orientation); |
155 | | - |
156 | | - modm::ResumableResult<bool> |
157 | | - configureScroll(uint8_t origin, uint8_t size, ScrollDirection direction, ScrollStep steps); |
158 | | - |
159 | | - modm::ResumableResult<bool> |
160 | | - enableScroll() |
161 | | - { |
162 | | - commandBuffer[0] = ScrollingCommands::EnableScroll; |
163 | | - return writeCommands(1); |
164 | | - } |
165 | | - |
166 | | - modm::ResumableResult<bool> |
167 | | - disableScroll() |
168 | | - { |
169 | | - commandBuffer[0] = ScrollingCommands::DisableScroll; |
170 | | - return writeCommands(1); |
171 | | - } |
172 | | - |
173 | | -protected: |
174 | | - modm::ResumableResult<bool> |
175 | | - writeCommands(std::size_t length); |
176 | | - |
177 | | - virtual modm::ResumableResult<void> |
178 | | - initializeMemoryMode(); |
179 | | - |
180 | | - virtual modm::ResumableResult<void> |
181 | | - startWriteDisplay(); |
182 | | - |
183 | | - uint8_t commandBuffer[7]; |
184 | | - bool transaction_success; |
185 | | -}; |
186 | | - |
187 | | -} // namespace modm |
188 | | - |
189 | | -#include "ssd1306_impl.hpp" |
190 | | - |
191 | | -#endif // MODM_SSD1306_HPP |
| 12 | +// DEPRECATE 2024q4 |
| 13 | +#warning "Use 'ssd1306_i2c.hpp' instead!" |
| 14 | +#include "ssd1306_i2c.hpp" |
0 commit comments