summaryrefslogtreecommitdiff
path: root/src/drivers/include/display.hpp
blob: 5f6d6f58ddda6c3e5af59b25b538f35dc70938c1 (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
68
69
70
#pragma once

#include <cstdint>

#include "driver/spi_master.h"
#include "lvgl/lvgl.h"
#include "result.hpp"

#include "display_init.hpp"
#include "gpio_expander.hpp"
#include "sys/_stdint.h"

namespace drivers {

/*
 * 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,
                       uint32_t flags = 0);
};

}  // namespace drivers