|
| 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 |
0 commit comments