-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for SH1106, improved SSD1306
- Loading branch information
Showing
13 changed files
with
448 additions
and
441 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* 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/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#ifndef MODM_SH1106_HPP | ||
#define MODM_SH1106_HPP | ||
|
||
#include "ssd1306.hpp" | ||
namespace modm | ||
{ | ||
/** | ||
* \brief SH1106 is said to be 'compatible' with SSD1306. However | ||
* there's one relevant difference: SH1106 does only support | ||
* MemoryMode::PAGE. This requires a 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 possible for MemoryMode::VERTICAL or MemoryMode::HORIZONTAL. | ||
*/ | ||
template<class I2cMaster, uint8_t Height = 64> | ||
class Sh1106 : public Ssd1306<I2cMaster, Height> | ||
{ | ||
public: | ||
Sh1106(uint8_t address) : Ssd1306<I2cMaster, Height>(address) {} | ||
|
||
modm::ResumableResult<bool> | ||
writeDisplay() override | ||
{ | ||
RF_BEGIN(); | ||
this->TransactionSuccess = true; | ||
currentPage = 0; | ||
|
||
this->commandBuffer[0] = ssd1306::AdressingCommands::HigherColumnStartAddress; | ||
this->commandBuffer[1] = 0x02; | ||
|
||
while (currentPage < Height / 8) | ||
{ | ||
this->commandBuffer[2] = 0xB0 | currentPage; | ||
this->TransactionSuccess &= RF_CALL(this->writeCommands(3)); | ||
|
||
// TODO Rearrange MonochromeGraphicDisplay::buffer so we do not have to convert | ||
// HACK Transform buffer - very unperformant transitional solution | ||
for (size_t i = 0; i < 128; i++) | ||
pageBuffer[i] = this->buffer[i][currentPage]; | ||
|
||
RF_CALL(startWriteDisplay()); | ||
RF_WAIT_WHILE(this->isTransactionRunning()); | ||
// this->TransactionSuccess &= RF_CALL(this->wasTransactionSuccessful()); | ||
|
||
currentPage++; | ||
} | ||
|
||
RF_END_RETURN(this->TransactionSuccess); | ||
} | ||
|
||
protected: | ||
// TODO Generalize in Ssd1306 so no more override is required | ||
inline modm::ResumableResult<void> | ||
startWriteDisplay() override | ||
{ | ||
RF_BEGIN(); | ||
|
||
RF_WAIT_UNTIL(this->transaction.configureDisplayWrite(pageBuffer, 128) and this->startTransaction()); | ||
|
||
RF_END(); | ||
} | ||
|
||
inline 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->TransactionSuccess &= RF_CALL(this->writeCommands(2)); | ||
RF_END(); | ||
} | ||
|
||
private: | ||
uint8_t pageBuffer[128]; | ||
size_t currentPage; | ||
}; | ||
} // namespace modm | ||
|
||
#endif // MODM_SH1106_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2018, Niklas Hauser | ||
# | ||
# 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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.