Skip to content

Commit def628e

Browse files
committed
[driver] Rename SSD1306 driver to ssd1306.i2c
1 parent a771042 commit def628e

13 files changed

+571
-496
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ your specific needs.
792792
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9685">PCA9685</a></td>
793793
<td align="center"><a href="https://modm.io/reference/module/modm-driver-qmc5883l">QMC5883L</a></td>
794794
</tr><tr>
795-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sh1106">SH1106</a></td>
795+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sh1106-i2c">SH1106-I2C</a></td>
796796
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s65">SIEMENS-S65</a></td>
797797
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s75">SIEMENS-S75</a></td>
798798
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk6812">SK6812</a></td>

src/modm/driver/display/sh1106.hpp renamed to src/modm/driver/display/sh1106_i2c.hpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#pragma once
1313

14-
#include "ssd1306.hpp"
14+
#include "ssd1306_i2c.hpp"
1515

1616
namespace modm
1717
{
@@ -26,10 +26,10 @@ namespace modm
2626
* @ingroup modm_driver_sh1106
2727
*/
2828
template<class I2cMaster, uint8_t Height = 64>
29-
class Sh1106 : public Ssd1306<I2cMaster, Height>
29+
class Sh1106I2c : public Ssd1306I2c<I2cMaster, Height>
3030
{
3131
public:
32-
Sh1106(uint8_t address = 0x3C) : Ssd1306<I2cMaster, Height>(address) {}
32+
Sh1106I2c(uint8_t address = 0x3C) : Ssd1306I2c<I2cMaster, Height>(address) {}
3333

3434
protected:
3535
modm::ResumableResult<void>
@@ -39,13 +39,10 @@ class Sh1106 : public Ssd1306<I2cMaster, Height>
3939

4040
this->transaction_success = true;
4141

42-
this->commandBuffer[0] = ssd1306::AdressingCommands::HigherColumnStartAddress;
43-
this->commandBuffer[1] = 0x02;
44-
4542
for (page = 0; page < Height / 8; page++)
4643
{
47-
this->commandBuffer[2] = 0xB0 | page;
48-
this->transaction_success &= RF_CALL(this->writeCommands(3));
44+
this->commandBuffer[0] = std::to_underlying(ssd1306::AdressingCommands::PageStartAddress) | page;
45+
this->transaction_success &= RF_CALL(this->writeCommands(1));
4946

5047
RF_WAIT_UNTIL(
5148
this->transaction.configureDisplayWrite((uint8_t*)&this->buffer[page], 128));
@@ -62,14 +59,14 @@ class Sh1106 : public Ssd1306<I2cMaster, Height>
6259
{
6360
RF_BEGIN();
6461
// Default on Power-up - can be omitted
65-
this->commandBuffer[0] = ssd1306::AdressingCommands::MemoryMode;
66-
this->commandBuffer[1] = ssd1306::MemoryMode::PAGE;
62+
this->commandBuffer[0] = std::to_underlying(ssd1306::AdressingCommands::MemoryMode);
63+
this->commandBuffer[1] = std::to_underlying(ssd1306::MemoryMode::PAGE);
6764
this->transaction_success &= RF_CALL(this->writeCommands(2));
6865
RF_END();
6966
}
7067

7168
private:
72-
size_t page;
69+
uint8_t page;
7370
};
7471

7572
} // namespace modm

src/modm/driver/display/sh1106.lb renamed to src/modm/driver/display/sh1106_i2c.lb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313

1414
def init(module):
15-
module.name = ":driver:sh1106"
16-
module.description = "SH1106 Display"
15+
module.name = ":driver:sh1106.i2c"
16+
module.description = "SH1106 Display in I2C mode"
1717

1818
def prepare(module, options):
19-
module.depends(":driver:ssd1306")
19+
module.depends(":driver:ssd1306.i2c")
2020
return True
2121

2222
def build(env):
2323
env.outbasepath = "modm/src/modm/driver/display"
24-
env.copy("sh1106.hpp")
24+
env.copy("sh1106_i2c.hpp")

src/modm/driver/display/ssd1306.hpp

Lines changed: 4 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/*
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
53
*
64
* This file is part of the modm project.
75
*
@@ -11,181 +9,6 @@
119
*/
1210
// ----------------------------------------------------------------------------
1311

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

Comments
 (0)