-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.cpp
78 lines (61 loc) · 2.52 KB
/
controller.cpp
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
71
72
73
74
75
76
77
78
#include <stdio.h>
#include <controller.hpp>
#include <display.hpp>
#include "boards/display_factory.hpp"
#include "esp_log.h"
#include "esp_lvgl_port.h"
static const char* TAG = "display-controller";
namespace LVGLDisplay {
esp_err_t Controller::initialise() {
ESP_LOGI(TAG, "Initialize LVGL library");
if(_display.error()) {
return _display.error();
}
lvgl_port_display_cfg_t disp_cfg = {.io_handle = _display.io_handle(),
.panel_handle = _display.panel_handle(),
.buffer_size = _display.buffer_size(),
.double_buffer = _display.double_buffer(),
.hres = _display.hres(),
.vres = _display.vres(),
.monochrome = _display.monochrome(),
.rotation =
{
.swap_xy = _display.swap_xy(),
.mirror_x = _display.mirror_x(),
.mirror_y = _display.mirror_y(),
},
.flags = {
.buff_dma = _display.dma(),
.buff_spiram = _display.spi_ram(),
}};
lvgl_port_cfg_t lvgl_cfg = {
.task_priority = CONFIG_LVGL_DISPLAY_TASK_PRIORITY,
.task_stack = CONFIG_LVGL_DISPLAY_TASK_STACK,
.task_affinity = CONFIG_LVGL_DISPLAY_TASK_AFFINITY,
.task_max_sleep_ms = CONFIG_LVGL_DISPLAY_TASK_MAX_SLEEP,
.timer_period_ms = CONFIG_LVGL_DISPLAY_TIMER_PERIOD,
};
esp_err_t err = lvgl_port_init(&lvgl_cfg);
if(err != ESP_OK) {
return err;
}
auto disp = lvgl_port_add_disp(&disp_cfg);
_display.display(disp);
return err;
}
esp_err_t Controller::backlight(const bool enable) {
if(_display.error()) {
return _display.error();
}
return _display.backlight(enable);
}
Controller& Controller::instance() {
static Controller _instance;
return _instance;
}
Controller::Controller() : _display(DisplayFactory::active_display()) {}
Lock::Lock() { lvgl_port_lock(0); }
void Lock::acquire() { lvgl_port_lock(0); }
void Lock::release() { lvgl_port_unlock(); }
Lock::~Lock() { lvgl_port_unlock(); }
}; // namespace LVGLDisplay