Skip to content

Commit 7d7490d

Browse files
TomSawsalkinium
authored andcommitted
[display] Add SH1106 driver inherited from SSD1306
1 parent 3efe013 commit 7d7490d

File tree

9 files changed

+424
-317
lines changed

9 files changed

+424
-317
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,20 +580,21 @@ you specific needs.
580580
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9548a">PCA9548A</a></td>
581581
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9685">PCA9685</a></td>
582582
</tr><tr>
583+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sh1106">SH1106</a></td>
583584
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s65">SIEMENS-S65</a></td>
584585
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s75">SIEMENS-S75</a></td>
585586
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk6812">SK6812</a></td>
586587
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk9822">SK9822</a></td>
587588
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ssd1306">SSD1306</a></td>
588-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stusb4500">STUSB4500</a></td>
589589
</tr><tr>
590+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stusb4500">STUSB4500</a></td>
590591
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sx1276">SX1276</a></td>
591592
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3414">TCS3414</a></td>
592593
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3472">TCS3472</a></td>
593594
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tlc594x">TLC594X</a></td>
594595
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp102">TMP102</a></td>
595-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp175">TMP175</a></td>
596596
</tr><tr>
597+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp175">TMP175</a></td>
597598
<td align="center"><a href="https://modm.io/reference/module/modm-driver-touch2046">TOUCH2046</a></td>
598599
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl53l0">VL53L0</a></td>
599600
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl6180">VL6180</a></td>

src/modm/driver/display/sh1106.hpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) 2021, Thomas Sommer
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
// ----------------------------------------------------------------------------
11+
12+
#pragma once
13+
14+
#include "ssd1306.hpp"
15+
16+
namespace modm
17+
{
18+
19+
/**
20+
* SH1106 is said to be 'compatible' with SSD1306. However there's a relevant
21+
* difference: SH1106 does only support MemoryMode::PAGE. This requires a little
22+
* more extensive writeDisplay() routine. We have to alternate between setting
23+
* Page-address and sending page-data instead of sending the whole buffer at
24+
* once like is for SSD1306 in MemoryMode::HORIZONTAL / MemoryMode::VERTICAL
25+
*
26+
* @ingroup modm_driver_sh1106
27+
*/
28+
template<class I2cMaster, uint8_t Height = 64>
29+
class Sh1106 : public Ssd1306<I2cMaster, Height>
30+
{
31+
public:
32+
Sh1106(uint8_t address = 0x3C) : Ssd1306<I2cMaster, Height>(address) {}
33+
34+
protected:
35+
modm::ResumableResult<void>
36+
startWriteDisplay() override
37+
{
38+
RF_BEGIN();
39+
40+
this->transaction_success = true;
41+
42+
this->commandBuffer[0] = ssd1306::AdressingCommands::HigherColumnStartAddress;
43+
this->commandBuffer[1] = 0x02;
44+
45+
for (page = 0; page < Height / 8; page++)
46+
{
47+
this->commandBuffer[2] = 0xB0 | page;
48+
this->transaction_success &= RF_CALL(this->writeCommands(3));
49+
50+
RF_WAIT_UNTIL(
51+
this->transaction.configureDisplayWrite((uint8_t*)&this->buffer[page], 128));
52+
RF_WAIT_UNTIL(this->startTransaction());
53+
RF_WAIT_WHILE(this->isTransactionRunning());
54+
this->transaction_success &= this->wasTransactionSuccessful();
55+
};
56+
57+
RF_END_RETURN(this->transaction_success);
58+
}
59+
60+
modm::ResumableResult<void>
61+
initializeMemoryMode() override
62+
{
63+
RF_BEGIN();
64+
// Default on Power-up - can be omitted
65+
this->commandBuffer[0] = ssd1306::AdressingCommands::MemoryMode;
66+
this->commandBuffer[1] = ssd1306::MemoryMode::PAGE;
67+
this->transaction_success &= RF_CALL(this->writeCommands(2));
68+
RF_END();
69+
}
70+
71+
private:
72+
size_t page;
73+
};
74+
75+
} // namespace modm

src/modm/driver/display/sh1106.lb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2021, Thomas Sommer
5+
#
6+
# This file is part of the modm project.
7+
#
8+
# This Source Code Form is subject to the terms of the Mozilla Public
9+
# License, v. 2.0. If a copy of the MPL was not distributed with this
10+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
11+
# -----------------------------------------------------------------------------
12+
13+
14+
def init(module):
15+
module.name = ":driver:sh1106"
16+
module.description = "SH1106 Display"
17+
18+
def prepare(module, options):
19+
module.depends(":driver:ssd1306")
20+
return True
21+
22+
def build(env):
23+
env.outbasepath = "modm/src/modm/driver/display"
24+
env.copy("sh1106.hpp")

0 commit comments

Comments
 (0)