diff --git a/src/modm/architecture/interface/i2c_device.hpp b/src/modm/architecture/interface/i2c_device.hpp index 6442b42328..e405bc5514 100644 --- a/src/modm/architecture/interface/i2c_device.hpp +++ b/src/modm/architecture/interface/i2c_device.hpp @@ -40,7 +40,7 @@ namespace modm * @author Niklas Hauser * @ingroup modm_architecture_i2c_device */ -template < class I2cMaster, uint8_t NestingLevels = 10, class Transaction = I2cWriteReadTransaction > +template < class I2cMaster, uint8_t NestingLevels = 10, class Transaction = I2cWriteReadTransaction > class I2cDevice : protected modm::NestedResumable< NestingLevels + 1 > { public: diff --git a/src/modm/architecture/interface/i2c_transaction.hpp b/src/modm/architecture/interface/i2c_transaction.hpp index 719822f5b0..dea09877ed 100644 --- a/src/modm/architecture/interface/i2c_transaction.hpp +++ b/src/modm/architecture/interface/i2c_transaction.hpp @@ -238,6 +238,7 @@ class I2cTransaction : public ::modm::I2c * @author Niklas Hauser * @ingroup modm_architecture_i2c */ +template class I2cWriteReadTransaction : public I2cTransaction { public: @@ -406,6 +407,7 @@ class I2cWriteReadTransaction : public I2cTransaction * @author Niklas Hauser * @ingroup modm_architecture_i2c */ +template class I2cWriteTransaction : public I2cTransaction { public: @@ -481,6 +483,7 @@ class I2cWriteTransaction : public I2cTransaction * @author Niklas Hauser * @ingroup modm_architecture_i2c */ +template class I2cReadTransaction : public I2cTransaction { public: diff --git a/src/modm/driver/display/ssd1306.hpp b/src/modm/driver/display/ssd1306.hpp index e62881d154..5b52540980 100644 --- a/src/modm/driver/display/ssd1306.hpp +++ b/src/modm/driver/display/ssd1306.hpp @@ -11,15 +11,21 @@ */ // ---------------------------------------------------------------------------- +#pragma once #ifndef MODM_SSD1306_HPP #define MODM_SSD1306_HPP #include #include #include -#include -#include "ssd1306_register.hpp" +#include +#include +#include + +#include "ssd1306_defines.hpp" + +using namespace modm::graphic; namespace modm { @@ -50,16 +56,9 @@ struct ssd1306 : public ssd1306_register // LeftBottom = VerticalAndHorizontalScrollLeft, }; - enum class - DisplayMode : uint8_t - { - Normal = NormalDisplay, - Inverted = InvertedDisplay - }; - public: /// @cond - class Ssd1306_I2cWriteTransaction : public modm::I2cWriteTransaction + class Ssd1306_I2cWriteTransaction : public modm::I2cWriteTransaction { public: Ssd1306_I2cWriteTransaction(uint8_t address); @@ -94,15 +93,19 @@ struct ssd1306 : public ssd1306_register * @author Thomas Sommer * @ingroup modm_driver_ssd1306 */ -template +template class Ssd1306 : public ssd1306, - public MonochromeGraphicDisplayVertical<128, Height>, + public graphic::Display, public I2cDevice { - static_assert((Height == 64) or (Height == 32), "Display height must be either 32 or 64 pixel!"); + static_assert((H == 64) or (H == 32), "Display height must be either 32 or 64 pixel!"); +public: + using ColorType = Monochrome; + using Buffer = graphic::Buffer; -public: - Ssd1306(uint8_t address = 0x3C); + Ssd1306(uint8_t address = 0x3C) + : Display(true), I2cDevice(address) + {} /// Pings the display bool inline pingBlocking() @@ -112,10 +115,6 @@ class Ssd1306 : public ssd1306, bool inline initializeBlocking() { return RF_CALL_BLOCKING(initialize()); } - /// Update the display with the content of the RAM buffer. - void - update() override - { RF_CALL_BLOCKING(startWriteDisplay()); } /// Use this method to synchronize writing to the displays buffer /// to avoid tearing. @@ -128,16 +127,8 @@ class Ssd1306 : public ssd1306, modm::ResumableResult initialize(); - // starts a frame transfer and waits for completion - virtual modm::ResumableResult - writeDisplay(); - modm::ResumableResult - setDisplayMode(DisplayMode mode = DisplayMode::Normal) - { - commandBuffer[0] = mode; - return writeCommands(1); - } + set(ssd1306_register::Toggle toggle, bool state); modm::ResumableResult setContrast(uint8_t contrast = 0xCE) @@ -148,13 +139,13 @@ class Ssd1306 : public ssd1306, } /** - * \param orientation glcd::Orientation::Landscape0 or glcd::Orientation::Landscape180 + * @param orientation display::Orientation::Landscape0 or display::Orientation::Landscape180 */ modm::ResumableResult - setOrientation(glcd::Orientation orientation); + setOrientation(graphic::Orientation orientation); modm::ResumableResult - configureScroll(uint8_t origin, uint8_t size, ScrollDirection direction, ScrollStep steps); + configureScroll(uint8_t placement, uint8_t size, ScrollDirection direction, ScrollStep steps); modm::ResumableResult enableScroll() @@ -170,16 +161,46 @@ class Ssd1306 : public ssd1306, return writeCommands(1); } + // TODO Abstract these write(...) cause is common to all I2c Displays! + // Write BufferInterface + // Caution: placement.y rounds to multiples of 8 + modm::ResumableResult + write(BufferInterface &buffer, Point placement = {0, 0}) { + RF_BEGIN(); + RF_END_RETURN_CALL(writeImage(ImageAccessor(&buffer, placement))); + } + + // Write Flash Image + modm::ResumableResult + write(const uint8_t *addr, Point placement = {0, 0}) { + RF_BEGIN(); + RF_END_RETURN_CALL(writeImage(ImageAccessor(addr, placement))); + } + + // Clear whole screen with color + modm::ResumableResult + clear(Monochrome color = 0); + protected: + virtual modm::ResumableResult + updateClipping(); + + // Write monochrome Image + template class Accessor> + modm::ResumableResult + writeImage(ImageAccessor accessor); + modm::ResumableResult writeCommands(std::size_t length); - virtual modm::ResumableResult + /** + * MemoryMode::HORIZONTAL and MemoryMode::VERTICAL have the best performance + * because the whole buffer is send in one transaction. + */ + virtual modm::ResumableResult initializeMemoryMode(); - virtual modm::ResumableResult - startWriteDisplay(); - + // Static variables for resumable functions uint8_t commandBuffer[7]; bool transaction_success; };