~aleteoryx/muditaos

ref: 44cc7f000da8571076074f0aec4d978a85a913a7 muditaos/module-services/service-eink/EinkDisplay.hpp -rw-r--r-- 2.2 KiB
44cc7f00 — Tomasz Rybarski [BH-1444] Vertical layouts font distance 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <gui/Common.hpp>

#include <EinkIncludes.hpp>
#include "Common.hpp"

#include <cstdint>
#include <memory>
#include "drivers/lpspi/DriverLPSPI.hpp"
#include "EinkSentinel.hpp"

namespace service::eink
{
    /**
     * Specifies the Eink display.
     * Responsible for handling low-level Eink display operations, e.g. switching power modes, updating, refreshing,
     * etc.
     */
    class EinkDisplay
    {
      public:
        explicit EinkDisplay(::gui::Size screenSize);
        ~EinkDisplay() noexcept;

        EinkStatus_e resetAndInit();
        EinkStatus_e update(std::uint8_t *displayBuffer);
        EinkStatus_e refresh(EinkDisplayTimingsMode_e refreshMode);
        void dither();
        void powerOn();
        void powerOff();
        void shutdown();
        void wipeOut();

        EinkStatus_e setWaveform(EinkWaveforms_e mode, std::int32_t temperature);
        void setMode(EinkDisplayColorMode_e mode) noexcept;

        std::int32_t getLastTemperature() const noexcept;
        ::gui::Size getSize() const noexcept;

        [[nodiscard]] auto getDevice() const noexcept -> std::shared_ptr<devices::Device>;
        void setEinkSentinel(std::shared_ptr<EinkSentinel> sentinel);

      private:
        static unsigned int toWaveformTemperatureOffset(std::int32_t temperature) noexcept;
        static unsigned int toWaveformOffset(unsigned short LUTbank, unsigned int temperatureOffset) noexcept;
        static unsigned int toWaveformOffset(EinkWaveforms_e mode, unsigned int temperatureOffset);
        bool isNewWaveformNeeded(EinkWaveforms_e newMode, int32_t newTemperature) const;
        void resetWaveformSettings();

        EinkBpp_e getCurrentBitsPerPixelFormat() const noexcept;
        static constexpr ::gui::Point pointTopLeft{0, 0};
        const ::gui::Size size;
        EinkWaveformSettings_t currentWaveform;
        EinkDisplayColorMode_e displayMode;

        std::shared_ptr<drivers::DriverLPSPI> driverLPSPI;
        std::shared_ptr<EinkSentinel> eInkSentinel;
    };
} // namespace service::eink