summaryrefslogtreecommitdiff
path: root/src/drivers/include/display.hpp
blob: 2d6e9cd6de8e366054d84afebef5b7d6f489c2d2 (plain)
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
64
65
66
67
#pragma once

#include <cstdint>
#include "display-init.hpp"
#include "driver/spi_master.h"
#include "gpio-expander.hpp"
#include "lvgl/lvgl.h"
#include "result.hpp"

namespace gay_ipod {

/*
 * Display driver for LVGL.
 */
class Display {
 public:
  enum Error {};
  static auto create(GpioExpander* expander,
                     const displays::InitialisationData& init_data)
      -> cpp::result<std::unique_ptr<Display>, Error>;

  Display(GpioExpander* gpio, spi_device_handle_t handle);
  ~Display();

  void WriteData();

  void Flush(lv_disp_drv_t* disp_drv,
             const lv_area_t* area,
             lv_color_t* color_map);

  void IRAM_ATTR PostTransaction(const spi_transaction_t& transaction);

  void ServiceTransactions();

 private:
  GpioExpander* gpio_;
  spi_device_handle_t handle_;

  lv_disp_draw_buf_t buffers_;
  lv_disp_drv_t driver_;
  lv_disp_t* display_ = nullptr;

  enum TransactionType {
    COMMAND = 0,
    DATA = 1,
  };

  enum TransactionFlags {
    LVGL_FLUSH = 1,
  };

  void SendInitialisationSequence(const uint8_t* data);

  void SendCommandWithData(uint8_t command,
                           const uint8_t* data,
                           size_t length,
                           uintptr_t flags = 0);

  void SendCmd(const uint8_t* data, size_t length, uintptr_t flags = 0);
  void SendData(const uint8_t* data, size_t length, uintptr_t flags = 0);
  void SendTransaction(TransactionType type,
                       const uint8_t* data,
                       size_t length,
                       uintptr_t flags = 0);
};

}  // namespace gay_ipod