Skip to content

Commit 5c377fb

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

File tree

9 files changed

+305
-251
lines changed

9 files changed

+305
-251
lines changed

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] = uint8_t(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] = uint8_t(ssd1306::AdressingCommands::MemoryMode);
63+
this->commandBuffer[1] = uint8_t(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: 3 additions & 180 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) 2021, 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
12+
#warning "DEPRECATE 2023q4: Use 'ssd1306_i2c.hpp' instead!"
1613

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
14+
#include "ssd1306_i2c.hpp"

src/modm/driver/display/ssd1306_register.hpp renamed to src/modm/driver/display/ssd1306_common.hpp

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,26 @@
1111

1212
#pragma once
1313

14+
#include <cstdint>
15+
1416
namespace modm
1517
{
1618

1719
/// @ingroup modm_driver_ssd1306
1820
struct ssd1306_register
1921
{
2022
protected:
21-
enum Transfer : uint8_t
23+
enum class
24+
Transfer : uint8_t
2225
{
2326
COMMAND_BURST = 0x00,
2427
DATA_BURST = 0x40,
2528
COMMAND = 0x80,
2629
DATA = 0xC0
2730
};
2831

29-
enum FundamentalCommands : uint8_t
32+
enum class
33+
FundamentalCommands : uint8_t
3034
{
3135
ContrastControl = 0x81, // Range 1-255
3236
EntireDisplayResumeToRam = 0xA4,
@@ -37,7 +41,8 @@ struct ssd1306_register
3741
DisplayOn = 0xAF,
3842
};
3943

40-
enum AdressingCommands : uint8_t
44+
enum class
45+
AdressingCommands : uint8_t
4146
{
4247
MemoryMode = 0x20, // enum MemoryMode
4348
// HORIZONTAL and VERTICAL addressing only
@@ -49,7 +54,8 @@ struct ssd1306_register
4954
HigherColumnStartAddress = 0x10,
5055
};
5156

52-
enum HardwareConfigCommands : uint8_t
57+
enum class
58+
HardwareConfigCommands : uint8_t
5359
{
5460
DisplayStartLine = 0x40,
5561
SegmentRemap0 = 0xA0,
@@ -61,7 +67,8 @@ struct ssd1306_register
6167
ComPinsOrder = 0xDA, // enum ComPinsOrder
6268
};
6369

64-
enum ScrollingCommands : uint8_t
70+
enum class
71+
ScrollingCommands : uint8_t
6572
{
6673
HorizontalScrollRight = 0x26,
6774
HorizontalScrollLeft = 0x27,
@@ -72,14 +79,16 @@ struct ssd1306_register
7279
EnableScroll = 0x2F,
7380
};
7481

75-
enum MemoryMode : uint8_t
82+
enum class
83+
MemoryMode : uint8_t
7684
{
7785
HORIZONTAL = 0,
7886
VERTICAL = 1,
7987
PAGE = 2
8088
};
8189

82-
enum TimingAndDrivingCommands : uint8_t
90+
enum class
91+
TimingAndDrivingCommands : uint8_t
8392
{
8493
ChargePump = 0x8D, // enum ChargePump
8594
DisplayClockDivideRatio = 0xD5, // [7:4] Frequency [3:0] Prescaler
@@ -88,13 +97,50 @@ struct ssd1306_register
8897
Nop = 0xE3
8998
};
9099

91-
enum ChargePump : uint8_t
100+
public:
101+
enum class
102+
ChargePump : uint8_t
92103
{
93-
DISABLE = 0x00,
104+
DISABLE = 0x10,
94105
V7_5 = 0x14,
95106
V8_5 = 0x94,
96107
V9 = 0x95,
97108
};
98109
};
99110

111+
/// @ingroup modm_driver_ssd1306
112+
struct ssd1306 : public ssd1306_register
113+
{
114+
public:
115+
enum class
116+
ScrollStep : uint8_t
117+
{
118+
Frames2 = 0b111,
119+
Frames3 = 0b100,
120+
Frames4 = 0b101,
121+
Frames5 = 0b000,
122+
Frames25 = 0b110,
123+
Frames64 = 0b001,
124+
Frames128 = 0b010,
125+
Frames256 = 0b011
126+
};
127+
128+
enum class
129+
ScrollDirection : uint8_t
130+
{
131+
Right = uint8_t(ScrollingCommands::HorizontalScrollRight),
132+
Left = uint8_t(ScrollingCommands::HorizontalScrollLeft),
133+
// RightBottom = ScrollingCommands::VerticalAndHorizontalScrollRight,
134+
// LeftBottom = ScrollingCommands::VerticalAndHorizontalScrollLeft,
135+
};
136+
137+
enum class
138+
DisplayMode : uint8_t
139+
{
140+
Normal = uint8_t(FundamentalCommands::NormalDisplay),
141+
Inverted = uint8_t(FundamentalCommands::InvertedDisplay),
142+
};
143+
144+
};
145+
100146
} // namespace modm

0 commit comments

Comments
 (0)