forked from lovyan03/LovyanGFX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathM5AtomDisplay.hpp
139 lines (126 loc) · 4.13 KB
/
M5AtomDisplay.hpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#pragma once
#if defined ( ESP_PLATFORM )
#include <sdkconfig.h>
#include <soc/efuse_reg.h>
#define LGFX_USE_V1
#include <LovyanGFX.hpp>
#include <lgfx/v1/panel/Panel_M5HDMI.hpp>
#ifndef M5ATOMDISPLAY_LOGICAL_WIDTH
#define M5ATOMDISPLAY_LOGICAL_WIDTH 1280
#endif
#ifndef M5ATOMDISPLAY_LOGICAL_HEIGHT
#define M5ATOMDISPLAY_LOGICAL_HEIGHT 720
#endif
#ifndef M5ATOMDISPLAY_REFRESH_RATE
#define M5ATOMDISPLAY_REFRESH_RATE 0.0f
#endif
#ifndef M5ATOMDISPLAY_OUTPUT_WIDTH
#define M5ATOMDISPLAY_OUTPUT_WIDTH 0
#endif
#ifndef M5ATOMDISPLAY_OUTPUT_HEIGHT
#define M5ATOMDISPLAY_OUTPUT_HEIGHT 0
#endif
#ifndef M5ATOMDISPLAY_SCALE_W
#define M5ATOMDISPLAY_SCALE_W 0
#endif
#ifndef M5ATOMDISPLAY_SCALE_H
#define M5ATOMDISPLAY_SCALE_H 0
#endif
class M5AtomDisplay : public lgfx::LGFX_Device
{
lgfx::Panel_M5HDMI _panel_instance;
lgfx::Bus_SPI _bus_instance;
public:
M5AtomDisplay( uint16_t logical_width = M5ATOMDISPLAY_LOGICAL_WIDTH
, uint16_t logical_height = M5ATOMDISPLAY_LOGICAL_HEIGHT
, float refresh_rate = M5ATOMDISPLAY_REFRESH_RATE
, uint16_t output_width = M5ATOMDISPLAY_OUTPUT_WIDTH
, uint16_t output_height = M5ATOMDISPLAY_OUTPUT_HEIGHT
, uint_fast8_t scale_w = M5ATOMDISPLAY_SCALE_W
, uint_fast8_t scale_h = M5ATOMDISPLAY_SCALE_H
)
{
#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32)
static constexpr int i2c_port = 1;
static constexpr int i2c_sda = 25;
static constexpr int i2c_scl = 21;
static constexpr int spi_cs = 33;
static constexpr int spi_mosi = 19;
static constexpr int spi_miso = 22;
int spi_sclk = (lgfx::get_pkg_ver() == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4)
? 23 // for ATOM Lite / Matrix
: 5 // for ATOM PSRAM
;
{
auto cfg = _bus_instance.config();
cfg.freq_write = 80000000;
cfg.freq_read = 20000000;
cfg.spi_host = VSPI_HOST;
cfg.spi_mode = 3;
cfg.dma_channel = 1;
cfg.use_lock = true;
cfg.pin_mosi = spi_mosi;
cfg.pin_miso = spi_miso;
cfg.pin_sclk = spi_sclk;
cfg.spi_3wire = false;
_bus_instance.config(cfg);
_panel_instance.setBus(&_bus_instance);
}
{
auto cfg = _panel_instance.config_transmitter();
cfg.freq_read = 400000;
cfg.freq_write = 400000;
cfg.pin_scl = i2c_scl;
cfg.pin_sda = i2c_sda;
cfg.i2c_port = i2c_port;
cfg.i2c_addr = 0x39;
cfg.prefix_cmd = 0x00;
cfg.prefix_data = 0x00;
cfg.prefix_len = 0;
_panel_instance.config_transmitter(cfg);
}
{
auto cfg = _panel_instance.config();
cfg.offset_rotation = 3;
cfg.pin_cs = spi_cs;
cfg.readable = false;
cfg.bus_shared = false;
_panel_instance.config(cfg);
_panel_instance.setRotation(1);
}
#endif
lgfx::Panel_M5HDMI::config_resolution_t cfg_reso;
cfg_reso.logical_width = logical_width;
cfg_reso.logical_height = logical_height;
cfg_reso.refresh_rate = refresh_rate;
cfg_reso.output_width = output_width;
cfg_reso.output_height = output_height;
cfg_reso.scale_w = scale_w;
cfg_reso.scale_h = scale_h;
_panel_instance.config_resolution(cfg_reso);
setPanel(&_panel_instance);
_board = lgfx::board_t::board_M5AtomDisplay;
}
bool setResolution( uint16_t logical_width = M5ATOMDISPLAY_LOGICAL_WIDTH
, uint16_t logical_height = M5ATOMDISPLAY_LOGICAL_HEIGHT
, float refresh_rate = M5ATOMDISPLAY_REFRESH_RATE
, uint16_t output_width = M5ATOMDISPLAY_OUTPUT_WIDTH
, uint16_t output_height = M5ATOMDISPLAY_OUTPUT_HEIGHT
, uint_fast8_t scale_w = M5ATOMDISPLAY_SCALE_W
, uint_fast8_t scale_h = M5ATOMDISPLAY_SCALE_H
)
{
bool res = _panel_instance.setResolution
( logical_width
, logical_height
, refresh_rate
, output_width
, output_height
, scale_w
, scale_h
);
setRotation(getRotation());
return res;
}
};
#endif