Skip to content

Commit 34293be

Browse files
committed
add RCA Unit examle
1 parent 8186caa commit 34293be

File tree

2 files changed

+53448
-0
lines changed

2 files changed

+53448
-0
lines changed

examples/Unit/RCA/RCA.ino

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
#define LGFX_USE_V1
2+
#include <M5Unified.h>
3+
4+
#include "wav_unsigned_8bit_click.cpp"
5+
6+
class LGFX : public lgfx::LGFX_Device {
7+
public:
8+
lgfx::Panel_CVBS _panel_instance;
9+
10+
LGFX(void) {
11+
{
12+
auto cfg = _panel_instance.config();
13+
14+
cfg.memory_width = 240;
15+
cfg.memory_height = 180;
16+
cfg.panel_width = 240;
17+
cfg.panel_height = 180;
18+
cfg.offset_x = 0;
19+
cfg.offset_y = 0;
20+
_panel_instance.config(cfg);
21+
}
22+
{
23+
auto cfg = _panel_instance.config_detail();
24+
25+
// cfg.signal_type = cfg.signal_type_t::NTSC_J;
26+
// cfg.signal_type = cfg.signal_type_t::PAL;
27+
// cfg.signal_type = cfg.signal_type_t::PAL_M;
28+
cfg.signal_type = cfg.signal_type_t::PAL_N;
29+
30+
cfg.pin_dac = 25;
31+
cfg.use_psram = 0;
32+
cfg.output_level = 128;
33+
cfg.chroma_level = 128;
34+
_panel_instance.config_detail(cfg);
35+
}
36+
37+
setPanel(&_panel_instance);
38+
}
39+
};
40+
41+
LGFX gfx_rca;
42+
43+
static constexpr int color_list[3] = {TFT_RED, TFT_GREEN, TFT_BLUE};
44+
static int color_index = 0;
45+
static unsigned long last_clear_time = 0;
46+
static bool is_pin_25 = true;
47+
48+
void play_wav(void*) {
49+
while (true) {
50+
M5.Speaker.playWav(sunrise_anna_single_left, sizeof(sunrise_anna_single_left), ~0u, 0,
51+
true);
52+
delay(3000);
53+
M5.Speaker.stop(0);
54+
delay(500);
55+
56+
M5.Speaker.playWav(sunrise_anna_single_right, sizeof(sunrise_anna_single_right), ~0u, 1,
57+
true);
58+
delay(3000);
59+
M5.Speaker.stop(1);
60+
delay(500);
61+
}
62+
}
63+
64+
void setup(void) {
65+
auto cfg = M5.config();
66+
cfg.external_spk = true;
67+
cfg.internal_spk = false;
68+
69+
M5.begin();
70+
71+
M5.Display.clear(TFT_BLACK);
72+
M5.Display.setFont(&DejaVu24);
73+
M5.Display.setTextColor(TFT_WHITE, TFT_BLACK);
74+
M5.Display.drawCenterString("M5 RCA Module :)", 160, 20);
75+
76+
M5.Display.drawCenterString("Using Pin 25", 160, 120);
77+
M5.Display.drawString("Pin 25", 25, 210);
78+
M5.Display.drawString("Pin 26", 220, 210);
79+
80+
// if (M5.getBoard() == m5gfx::boards::board_M5StackCore2) {
81+
// {
82+
// auto spk_cfg = M5.Speaker.config();
83+
// spk_cfg.i2s_port = I2S_NUM_1;
84+
// spk_cfg.sample_rate = 96000;
85+
//
86+
// spk_cfg.pin_data_out = 2;
87+
// spk_cfg.pin_bck = 19;
88+
// spk_cfg.pin_ws = 0; // LRCK
89+
//
90+
// spk_cfg.stereo = true;
91+
// spk_cfg.buzzer = false;
92+
// spk_cfg.use_dac = false;
93+
// spk_cfg.magnification = 16;
94+
// M5.Speaker.config(spk_cfg);
95+
// }
96+
// }
97+
// else
98+
// {
99+
// auto spk_cfg = M5.Speaker.config();
100+
// spk_cfg.i2s_port = I2S_NUM_1;
101+
// spk_cfg.sample_rate = 96000;
102+
//
103+
// spk_cfg.pin_data_out = 15;
104+
// spk_cfg.pin_bck = 13;
105+
// spk_cfg.pin_ws = 0; // LRCK
106+
//
107+
// spk_cfg.stereo = true;
108+
// spk_cfg.buzzer = false;
109+
// spk_cfg.use_dac = false;
110+
// spk_cfg.magnification = 16;
111+
// M5.Speaker.config(spk_cfg);
112+
// }
113+
114+
115+
// M5.Speaker.begin();
116+
// M5.Speaker.setVolume(128);
117+
// M5.Speaker.setChannelVolume(0, 255);
118+
// M5.Speaker.setChannelVolume(1, 255);
119+
120+
gfx_rca.init();
121+
gfx_rca.setFont(&DejaVu24);
122+
123+
// xTaskCreatePinnedToCore(play_wav, "play_wav", 8192, NULL, 1, NULL, 1);
124+
125+
pinMode(16, OUTPUT);
126+
pinMode(17, OUTPUT);
127+
}
128+
129+
int blink_flag = 0;
130+
void loop(void) {
131+
M5.update();
132+
133+
if ((millis() - last_clear_time) > 1000) {
134+
last_clear_time = millis();
135+
136+
color_index++;
137+
if (color_index > 2) {
138+
color_index = 0;
139+
}
140+
141+
gfx_rca.clear(color_list[color_index]);
142+
gfx_rca.setTextColor(TFT_WHITE, color_list[color_index]);
143+
gfx_rca.drawCenterString("M5 RCA Module :)", 120, 50);
144+
145+
if (is_pin_25) {
146+
gfx_rca.drawCenterString("Using Pin 25", 120, 110);
147+
} else {
148+
gfx_rca.drawCenterString("Using Pin 26", 120, 110);
149+
}
150+
151+
blink_flag = !blink_flag;
152+
digitalWrite(16, blink_flag);
153+
digitalWrite(17, blink_flag);
154+
}
155+
156+
if (M5.BtnA.isPressed()) {
157+
if (is_pin_25) {
158+
return;
159+
}
160+
is_pin_25 = true;
161+
M5.Display.drawCenterString("Using Pin 25", 160, 120);
162+
163+
lgfx::Panel_CVBS* p = (lgfx::Panel_CVBS*)gfx_rca.panel();
164+
p->deinit();
165+
auto cfg = p->config();
166+
cfg.memory_width = 240;
167+
cfg.memory_height = 180;
168+
cfg.panel_width = 240;
169+
cfg.panel_height = 180;
170+
cfg.offset_x = 0;
171+
cfg.offset_y = 0;
172+
p->config(cfg);
173+
auto cfg_d = p->config_detail();
174+
cfg_d.pin_dac = 25;
175+
cfg_d.use_psram = 0;
176+
cfg_d.output_level = 128;
177+
cfg_d.chroma_level = 128;
178+
p->config_detail(cfg_d);
179+
180+
gfx_rca.init();
181+
gfx_rca.setTextColor(TFT_WHITE, color_list[color_index]);
182+
gfx_rca.drawCenterString("Using Pin 25", 120, 110);
183+
}
184+
185+
if (M5.BtnC.isPressed()) {
186+
if (!is_pin_25) {
187+
return;
188+
}
189+
is_pin_25 = false;
190+
M5.Display.drawCenterString("Using Pin 26", 160, 120);
191+
192+
lgfx::Panel_CVBS* p = (lgfx::Panel_CVBS*)gfx_rca.panel();
193+
p->deinit();
194+
auto cfg = p->config();
195+
cfg.memory_width = 240;
196+
cfg.memory_height = 180;
197+
cfg.panel_width = 240;
198+
cfg.panel_height = 180;
199+
cfg.offset_x = 0;
200+
cfg.offset_y = 0;
201+
p->config(cfg);
202+
auto cfg_d = p->config_detail();
203+
cfg_d.pin_dac = 26;
204+
cfg_d.use_psram = 0;
205+
cfg_d.output_level = 128;
206+
cfg_d.chroma_level = 128;
207+
p->config_detail(cfg_d);
208+
209+
gfx_rca.init();
210+
gfx_rca.setTextColor(TFT_WHITE, color_list[color_index]);
211+
gfx_rca.drawCenterString("Using Pin 26", 120, 110);
212+
}
213+
}

0 commit comments

Comments
 (0)