Skip to content

Commit

Permalink
[display] Add SH1106 driver inherited from SSD1306
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSaw authored and salkinium committed May 7, 2021
1 parent 3efe013 commit 7d7490d
Show file tree
Hide file tree
Showing 9 changed files with 424 additions and 317 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -580,20 +580,21 @@ you specific needs.
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9548a">PCA9548A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9685">PCA9685</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sh1106">SH1106</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s65">SIEMENS-S65</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s75">SIEMENS-S75</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk6812">SK6812</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk9822">SK9822</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ssd1306">SSD1306</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stusb4500">STUSB4500</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stusb4500">STUSB4500</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sx1276">SX1276</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3414">TCS3414</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3472">TCS3472</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tlc594x">TLC594X</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp102">TMP102</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp175">TMP175</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp175">TMP175</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-touch2046">TOUCH2046</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl53l0">VL53L0</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl6180">VL6180</a></td>
Expand Down
75 changes: 75 additions & 0 deletions src/modm/driver/display/sh1106.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2021, Thomas Sommer
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#pragma once

#include "ssd1306.hpp"

namespace modm
{

/**
* SH1106 is said to be 'compatible' with SSD1306. However there's a relevant
* difference: SH1106 does only support MemoryMode::PAGE. This requires a little
* more extensive writeDisplay() routine. We have to alternate between setting
* Page-address and sending page-data instead of sending the whole buffer at
* once like is for SSD1306 in MemoryMode::HORIZONTAL / MemoryMode::VERTICAL
*
* @ingroup modm_driver_sh1106
*/
template<class I2cMaster, uint8_t Height = 64>
class Sh1106 : public Ssd1306<I2cMaster, Height>
{
public:
Sh1106(uint8_t address = 0x3C) : Ssd1306<I2cMaster, Height>(address) {}

protected:
modm::ResumableResult<void>
startWriteDisplay() override
{
RF_BEGIN();

this->transaction_success = true;

this->commandBuffer[0] = ssd1306::AdressingCommands::HigherColumnStartAddress;
this->commandBuffer[1] = 0x02;

for (page = 0; page < Height / 8; page++)
{
this->commandBuffer[2] = 0xB0 | page;
this->transaction_success &= RF_CALL(this->writeCommands(3));

RF_WAIT_UNTIL(
this->transaction.configureDisplayWrite((uint8_t*)&this->buffer[page], 128));
RF_WAIT_UNTIL(this->startTransaction());
RF_WAIT_WHILE(this->isTransactionRunning());
this->transaction_success &= this->wasTransactionSuccessful();
};

RF_END_RETURN(this->transaction_success);
}

modm::ResumableResult<void>
initializeMemoryMode() override
{
RF_BEGIN();
// Default on Power-up - can be omitted
this->commandBuffer[0] = ssd1306::AdressingCommands::MemoryMode;
this->commandBuffer[1] = ssd1306::MemoryMode::PAGE;
this->transaction_success &= RF_CALL(this->writeCommands(2));
RF_END();
}

private:
size_t page;
};

} // namespace modm
24 changes: 24 additions & 0 deletions src/modm/driver/display/sh1106.lb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2021, Thomas Sommer
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------


def init(module):
module.name = ":driver:sh1106"
module.description = "SH1106 Display"

def prepare(module, options):
module.depends(":driver:ssd1306")
return True

def build(env):
env.outbasepath = "modm/src/modm/driver/display"
env.copy("sh1106.hpp")
Loading

0 comments on commit 7d7490d

Please sign in to comment.