-
Notifications
You must be signed in to change notification settings - Fork 61
/
M5Unified.cpp
1650 lines (1479 loc) · 56.7 KB
/
M5Unified.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) M5Stack. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#include "M5Unified.hpp"
#if !defined (M5UNIFIED_PC_BUILD)
#include <soc/efuse_reg.h>
#include <soc/gpio_periph.h>
#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32)
#if __has_include (<driver/touch_sens.h>)
#include <driver/touch_sens.h>
#elif __has_include (<driver/touch_sensor.h>)
#include <driver/touch_sensor.h>
#endif
#endif
#if __has_include (<driver/i2s_type.h>)
#include <driver/i2s_type.h>
#endif
#if __has_include (<esp_idf_version.h>)
#include <esp_idf_version.h>
#if ESP_IDF_VERSION_MAJOR >= 4
/// [[fallthrough]];
#define NON_BREAK ;[[fallthrough]];
#endif
#endif
#endif
/// [[fallthrough]];
#ifndef NON_BREAK
#define NON_BREAK ;
#endif
/// global instance.
m5::M5Unified M5;
void __attribute((weak)) adc_power_acquire(void)
{
#if !defined (M5UNIFIED_PC_BUILD)
#if defined (ESP_IDF_VERSION_VAL)
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(3, 3, 4)
adc_power_on();
#endif
#else
adc_power_on();
#endif
#endif
}
namespace m5
{
int8_t M5Unified::_get_pin_table[pin_name_max];
#if defined (M5UNIFIED_PC_BUILD)
void M5Unified::_setup_pinmap(board_t)
{
std::fill(_get_pin_table, _get_pin_table + pin_name_max, 255);
}
#else
// ピン番号テーブル。 unknownをテーブルの最後に配置する。該当が無い場合はunknownの値が使用される。
static constexpr const uint8_t _pin_table_i2c_ex_in[][5] = {
// In CL,DA, EX CL,DA
#if defined (CONFIG_IDF_TARGET_ESP32S3)
{ board_t::board_M5StackCoreS3, GPIO_NUM_11,GPIO_NUM_12 , GPIO_NUM_1 ,GPIO_NUM_2 },
{ board_t::board_M5StackCoreS3SE,GPIO_NUM_11,GPIO_NUM_12, GPIO_NUM_1 ,GPIO_NUM_2 },
{ board_t::board_M5StampS3 , 255 ,255 , GPIO_NUM_15,GPIO_NUM_13 },
{ board_t::board_M5Capsule , GPIO_NUM_10,GPIO_NUM_8 , GPIO_NUM_15,GPIO_NUM_13 },
{ board_t::board_M5Dial , GPIO_NUM_12,GPIO_NUM_11 , GPIO_NUM_15,GPIO_NUM_13 },
{ board_t::board_M5DinMeter , GPIO_NUM_12,GPIO_NUM_11 , GPIO_NUM_15,GPIO_NUM_13 },
{ board_t::board_M5AirQ , GPIO_NUM_12,GPIO_NUM_11 , GPIO_NUM_15,GPIO_NUM_13 },
{ board_t::board_M5Cardputer , 255 ,255 , GPIO_NUM_1 ,GPIO_NUM_2 },
{ board_t::board_M5VAMeter , GPIO_NUM_6 ,GPIO_NUM_5 , GPIO_NUM_9 ,GPIO_NUM_8 },
{ board_t::board_M5AtomS3R , GPIO_NUM_0 ,GPIO_NUM_45 , GPIO_NUM_1 ,GPIO_NUM_2 },
{ board_t::board_M5AtomS3RExt , GPIO_NUM_0 ,GPIO_NUM_45 , GPIO_NUM_1 ,GPIO_NUM_2 },
{ board_t::board_M5AtomS3RCam , GPIO_NUM_0 ,GPIO_NUM_45 , GPIO_NUM_1 ,GPIO_NUM_2 },
{ board_t::board_unknown , GPIO_NUM_39,GPIO_NUM_38 , GPIO_NUM_1 ,GPIO_NUM_2 }, // AtomS3,AtomS3Lite,AtomS3U
#elif defined (CONFIG_IDF_TARGET_ESP32C3)
{ board_t::board_unknown , 255 ,255 , GPIO_NUM_0 ,GPIO_NUM_1 },
#elif defined (CONFIG_IDF_TARGET_ESP32C6)
{ board_t::board_unknown , 255 ,255 , GPIO_NUM_1 ,GPIO_NUM_2 }, // NanoC6
#else
{ board_t::board_M5Stack , GPIO_NUM_22,GPIO_NUM_21 , GPIO_NUM_22,GPIO_NUM_21 },
{ board_t::board_M5Paper , GPIO_NUM_22,GPIO_NUM_21 , GPIO_NUM_32,GPIO_NUM_25 },
{ board_t::board_M5TimerCam , GPIO_NUM_14,GPIO_NUM_12 , GPIO_NUM_13,GPIO_NUM_4 },
{ board_t::board_M5AtomLite , GPIO_NUM_21,GPIO_NUM_25 , GPIO_NUM_32,GPIO_NUM_26 },
{ board_t::board_M5AtomMatrix , GPIO_NUM_21,GPIO_NUM_25 , GPIO_NUM_32,GPIO_NUM_26 },
{ board_t::board_M5AtomEcho , GPIO_NUM_21,GPIO_NUM_25 , GPIO_NUM_32,GPIO_NUM_26 },
{ board_t::board_M5AtomU , GPIO_NUM_21,GPIO_NUM_25 , GPIO_NUM_32,GPIO_NUM_26 },
{ board_t::board_M5AtomPsram , GPIO_NUM_21,GPIO_NUM_25 , GPIO_NUM_32,GPIO_NUM_26 },
{ board_t::board_unknown , GPIO_NUM_22,GPIO_NUM_21 , GPIO_NUM_33,GPIO_NUM_32 }, // Core2,Tough,StickC,CoreInk,Station,StampPico
#endif
};
static constexpr const uint8_t _pin_table_port_bc[][5] = {
//pB p1,p2, pC p1,p2
#if defined (CONFIG_IDF_TARGET_ESP32S3)
{ board_t::board_M5StackCoreS3, GPIO_NUM_8 ,GPIO_NUM_9 , GPIO_NUM_18,GPIO_NUM_17 },
{ board_t::board_M5StackCoreS3SE,GPIO_NUM_8,GPIO_NUM_9 , GPIO_NUM_18,GPIO_NUM_17 },
{ board_t::board_M5Dial , GPIO_NUM_1 ,GPIO_NUM_2 , 255 ,255 },
{ board_t::board_M5DinMeter , GPIO_NUM_1 ,GPIO_NUM_2 , 255 ,255 },
#elif defined (CONFIG_IDF_TARGET_ESP32C3)
#elif defined (CONFIG_IDF_TARGET_ESP32C6)
#else
{ board_t::board_M5Stack , GPIO_NUM_36,GPIO_NUM_26 , GPIO_NUM_16,GPIO_NUM_17 },
{ board_t::board_M5StackCore2 , GPIO_NUM_36,GPIO_NUM_26 , GPIO_NUM_13,GPIO_NUM_14 },
{ board_t::board_M5Paper , GPIO_NUM_33,GPIO_NUM_26 , GPIO_NUM_19,GPIO_NUM_18 },
{ board_t::board_M5Station , GPIO_NUM_35,GPIO_NUM_25 , GPIO_NUM_13,GPIO_NUM_14 },
#endif
{ board_t::board_unknown , 255 ,255 , 255 ,255 },
};
static constexpr const uint8_t _pin_table_port_de[][5] = {
//pD p1,p2, pE p1,p2
#if defined (CONFIG_IDF_TARGET_ESP32S3)
{ board_t::board_M5StackCoreS3, 14,10, 18,17 },
{ board_t::board_M5StackCoreS3SE,14,10,18,17 },
#elif defined (CONFIG_IDF_TARGET_ESP32C3)
#elif defined (CONFIG_IDF_TARGET_ESP32C6)
#else
{ board_t::board_M5Stack , GPIO_NUM_34,GPIO_NUM_35 , GPIO_NUM_5 ,GPIO_NUM_13 },
{ board_t::board_M5StackCore2 , GPIO_NUM_34,GPIO_NUM_35 , GPIO_NUM_27,GPIO_NUM_19 },
{ board_t::board_M5Station , GPIO_NUM_36,GPIO_NUM_26 , GPIO_NUM_16,GPIO_NUM_17 }, // B2 / C2
#endif
{ board_t::board_unknown , 255 ,255 , 255 ,255 },
};
static constexpr const uint8_t _pin_table_spi_sd[][5] = {
// clk,mosi,miso,cs
#if defined (CONFIG_IDF_TARGET_ESP32S3)
{ board_t::board_M5StackCoreS3, GPIO_NUM_36, GPIO_NUM_37, GPIO_NUM_35, GPIO_NUM_4 },
{ board_t::board_M5StackCoreS3SE,GPIO_NUM_36,GPIO_NUM_37, GPIO_NUM_35, GPIO_NUM_4 },
{ board_t::board_M5Capsule , GPIO_NUM_14, GPIO_NUM_12, GPIO_NUM_39, GPIO_NUM_11 },
{ board_t::board_M5Cardputer , GPIO_NUM_40, GPIO_NUM_14, GPIO_NUM_39, GPIO_NUM_12 },
#elif defined (CONFIG_IDF_TARGET_ESP32C3)
#elif defined (CONFIG_IDF_TARGET_ESP32C6)
#else
{ board_t::board_M5Stack , GPIO_NUM_18, GPIO_NUM_23, GPIO_NUM_19, GPIO_NUM_4 },
{ board_t::board_M5StackCore2 , GPIO_NUM_18, GPIO_NUM_23, GPIO_NUM_38, GPIO_NUM_4 },
{ board_t::board_M5Paper , GPIO_NUM_14, GPIO_NUM_12, GPIO_NUM_13, GPIO_NUM_4 },
#endif
{ board_t::board_unknown , 255 , 255 , 255 , 255 },
};
static constexpr const uint8_t _pin_table_other0[][2] = {
//RGBLED
#if defined (CONFIG_IDF_TARGET_ESP32S3)
{ board_t::board_M5AtomS3U , GPIO_NUM_35 },
{ board_t::board_M5AtomS3Lite , GPIO_NUM_35 },
{ board_t::board_M5StampS3 , GPIO_NUM_21 },
{ board_t::board_M5Capsule , GPIO_NUM_21 },
{ board_t::board_M5Cardputer , GPIO_NUM_21 },
#elif defined (CONFIG_IDF_TARGET_ESP32C3)
{ board_t::board_M5StampC3 , GPIO_NUM_2 },
{ board_t::board_M5StampC3U , GPIO_NUM_2 },
#elif defined (CONFIG_IDF_TARGET_ESP32C6)
{ board_t::board_M5NanoC6 , GPIO_NUM_20 },
#else
{ board_t::board_M5Stack , GPIO_NUM_15 },
{ board_t::board_M5StackCore2 , GPIO_NUM_25 },
{ board_t::board_M5Station , GPIO_NUM_4 },
{ board_t::board_M5AtomLite , GPIO_NUM_27 },
{ board_t::board_M5AtomMatrix , GPIO_NUM_27 },
{ board_t::board_M5AtomEcho , GPIO_NUM_27 },
{ board_t::board_M5AtomU , GPIO_NUM_27 },
{ board_t::board_M5AtomPsram , GPIO_NUM_27 },
{ board_t::board_M5StampPico , GPIO_NUM_27 },
#endif
{ board_t::board_unknown , 255 },
};
static constexpr const uint8_t _pin_table_other1[][2] = {
//POWER_HOLD
#if defined (CONFIG_IDF_TARGET_ESP32S3)
{ board_t::board_M5Dial , GPIO_NUM_46 },
{ board_t::board_M5Capsule , GPIO_NUM_46 },
{ board_t::board_M5AirQ , GPIO_NUM_46 },
{ board_t::board_M5DinMeter , GPIO_NUM_46 },
#elif defined (CONFIG_IDF_TARGET_ESP32C3)
#elif defined (CONFIG_IDF_TARGET_ESP32C6)
#else
{ board_t::board_M5StickCPlus2 , GPIO_NUM_4 },
{ board_t::board_M5Paper , GPIO_NUM_2 },
{ board_t::board_M5StackCoreInk, GPIO_NUM_12 },
{ board_t::board_M5TimerCam , GPIO_NUM_33 },
#endif
{ board_t::board_unknown , 255 },
};
void M5Unified::_setup_pinmap(board_t id)
{
constexpr const std::pair<const void*, size_t> tbl[] = {
{ _pin_table_i2c_ex_in, sizeof(_pin_table_i2c_ex_in[0]) },
{ _pin_table_port_bc, sizeof(_pin_table_port_bc[0]) },
{ _pin_table_port_de, sizeof(_pin_table_port_de[0]) },
{ _pin_table_spi_sd, sizeof(_pin_table_spi_sd[0]) },
{ _pin_table_other0, sizeof(_pin_table_other0[0]) },
{ _pin_table_other1, sizeof(_pin_table_other1[0]) },
};
int8_t* dst = _get_pin_table;
for (auto &p : tbl) {
const uint8_t* t = (uint8_t*)p.first;
size_t len = p.second;
while (t[0] != id && t[0] != board_t::board_unknown) { t += len; }
memcpy(dst, &t[1], len - 1);
dst += len - 1;
}
}
#endif
#if defined (CONFIG_IDF_TARGET_ESP32S3)
static constexpr uint8_t aw88298_i2c_addr = 0x36;
static constexpr uint8_t es7210_i2c_addr = 0x40;
static constexpr uint8_t aw9523_i2c_addr = 0x58;
static void aw88298_write_reg(uint8_t reg, uint16_t value)
{
value = __builtin_bswap16(value);
M5.In_I2C.writeRegister(aw88298_i2c_addr, reg, (const uint8_t*)&value, 2, 400000);
}
static void es7210_write_reg(uint8_t reg, uint8_t value)
{
M5.In_I2C.writeRegister(es7210_i2c_addr, reg, &value, 1, 400000);
}
#endif
bool M5Unified::_speaker_enabled_cb(void* args, bool enabled)
{
#if defined (M5UNIFIED_PC_BUILD)
(void)args;
(void)enabled;
#else
auto self = (M5Unified*)args;
switch (self->getBoard())
{
#if defined (CONFIG_IDF_TARGET_ESP32S3)
case board_t::board_M5StackCoreS3:
case board_t::board_M5StackCoreS3SE:
{
auto cfg = self->Speaker.config();
if (cfg.pin_bck == GPIO_NUM_34 && enabled)
{
self->In_I2C.bitOn(aw9523_i2c_addr, 0x02, 0b00000100, 400000);
/// サンプリングレートに応じてAW88298のレジスタの設定値を変える;
static constexpr uint8_t rate_tbl[] = {4,5,6,8,10,11,15,20,22,44};
size_t reg0x06_value = 0;
size_t rate = (cfg.sample_rate + 1102) / 2205;
while (rate > rate_tbl[reg0x06_value] && ++reg0x06_value < sizeof(rate_tbl)) {}
reg0x06_value |= 0x14C0; // I2SBCK=0 (BCK mode 16*2)
aw88298_write_reg( 0x61, 0x0673 ); // boost mode disabled
aw88298_write_reg( 0x04, 0x4040 ); // I2SEN=1 AMPPD=0 PWDN=0
aw88298_write_reg( 0x05, 0x0008 ); // RMSE=0 HAGCE=0 HDCCE=0 HMUTE=0
aw88298_write_reg( 0x06, reg0x06_value );
aw88298_write_reg( 0x0C, 0x0064 ); // volume setting (full volume)
}
else /// disableにする場合および内蔵スピーカ以外を操作対象とした場合、内蔵スピーカを停止する。
{
aw88298_write_reg( 0x04, 0x4000 ); // I2SEN=0 AMPPD=0 PWDN=0
self->In_I2C.bitOff(aw9523_i2c_addr, 0x02, 0b00000100, 400000);
}
}
break;
#elif !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32)
case board_t::board_M5StackCore2:
case board_t::board_M5Tough:
{
auto spk_cfg = self->Speaker.config();
if (spk_cfg.pin_bck == GPIO_NUM_12
&& spk_cfg.pin_ws == GPIO_NUM_0
&& spk_cfg.pin_data_out == GPIO_NUM_2
) {
switch (self->Power.getType()) {
case m5::Power_Class::pmic_axp192:
self->Power.Axp192.setGPIO2(enabled);
break;
case m5::Power_Class::pmic_axp2101:
self->Power.Axp2101.setALDO3(enabled * 3300);
break;
default:
break;
}
}
}
break;
case board_t::board_M5StickC:
case board_t::board_M5StickCPlus:
case board_t::board_M5StickCPlus2:
case board_t::board_M5StackCoreInk:
/// for SPK HAT
if (self->use_hat_spk)
{
gpio_num_t pin_en = self->_board == board_t::board_M5StackCoreInk ? GPIO_NUM_25 : GPIO_NUM_0;
if (enabled)
{
m5gfx::pinMode(pin_en, m5gfx::pin_mode_t::output);
m5gfx::gpio_hi(pin_en);
}
else
{ m5gfx::gpio_lo(pin_en); }
}
break;
#endif
default:
break;
}
#endif
return true;
}
bool M5Unified::_microphone_enabled_cb(void* args, bool enabled)
{
#if defined (M5UNIFIED_PC_BUILD)
(void)args;
(void)enabled;
#else
auto self = (M5Unified*)args;
switch (self->getBoard())
{
#if defined (CONFIG_IDF_TARGET_ESP32S3)
case board_t::board_M5StackCoreS3:
case board_t::board_M5StackCoreS3SE:
{
auto cfg = self->Mic.config();
if (cfg.pin_bck == GPIO_NUM_34)
{
es7210_write_reg(0x00, 0xFF); // RESET_CTL
struct __attribute__((packed)) reg_data_t
{
uint8_t reg;
uint8_t value;
};
if (enabled)
{
static constexpr reg_data_t data[] =
{
{ 0x00, 0x41 }, // RESET_CTL
{ 0x01, 0x1f }, // CLK_ON_OFF
{ 0x06, 0x00 }, // DIGITAL_PDN
{ 0x07, 0x20 }, // ADC_OSR
{ 0x08, 0x10 }, // MODE_CFG
{ 0x09, 0x30 }, // TCT0_CHPINI
{ 0x0A, 0x30 }, // TCT1_CHPINI
{ 0x20, 0x0a }, // ADC34_HPF2
{ 0x21, 0x2a }, // ADC34_HPF1
{ 0x22, 0x0a }, // ADC12_HPF2
{ 0x23, 0x2a }, // ADC12_HPF1
{ 0x02, 0xC1 },
{ 0x04, 0x01 },
{ 0x05, 0x00 },
{ 0x11, 0x60 },
{ 0x40, 0x42 }, // ANALOG_SYS
{ 0x41, 0x70 }, // MICBIAS12
{ 0x42, 0x70 }, // MICBIAS34
{ 0x43, 0x1B }, // MIC1_GAIN
{ 0x44, 0x1B }, // MIC2_GAIN
{ 0x45, 0x00 }, // MIC3_GAIN
{ 0x46, 0x00 }, // MIC4_GAIN
{ 0x47, 0x00 }, // MIC1_LP
{ 0x48, 0x00 }, // MIC2_LP
{ 0x49, 0x00 }, // MIC3_LP
{ 0x4A, 0x00 }, // MIC4_LP
{ 0x4B, 0x00 }, // MIC12_PDN
{ 0x4C, 0xFF }, // MIC34_PDN
{ 0x01, 0x14 }, // CLK_ON_OFF
};
for (auto& d: data)
{
es7210_write_reg(d.reg, d.value);
}
}
/*
uint8_t buf[0x50];
for (int i = 0; i < 0x50; ++i)
{
self->In_I2C.readRegister(es7210_i2c_addr, i, &buf[i], 1, 400000);
if ((i & 15) == 15)
{
auto d = &buf[i-15];
ESP_LOGE("DEBUG","%02x :%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x"
,i>>4 , d[ 0], d[ 1], d[ 2], d[ 3], d[ 4], d[ 5], d[ 6], d[ 7], d[ 8], d[ 9], d[10], d[11], d[12], d[13], d[14], d[15]);
}
}
//*/
}
}
break;
#elif !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32)
case board_t::board_M5StickC:
case board_t::board_M5StickCPlus:
self->Power.Axp192.setLDO0(enabled ? 2800 : 0);
break;
#endif
default:
break;
}
#endif
return true;
}
#if defined (M5UNIFIED_PC_BUILD)
#elif !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32)
static constexpr gpio_num_t TFCARD_CS_PIN = GPIO_NUM_4;
static constexpr gpio_num_t CoreInk_BUTTON_EXT_PIN = GPIO_NUM_5;
static constexpr gpio_num_t CoreInk_BUTTON_PWR_PIN = GPIO_NUM_27;
#endif
board_t M5Unified::_check_boardtype(board_t board)
{
#if defined (M5UNIFIED_PC_BUILD)
#elif !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32)
if (board == board_t::board_unknown)
{
switch (m5gfx::get_pkg_ver())
{
case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ6:
board = board_t::board_M5TimerCam;
break;
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4:
{
m5gfx::gpio::pin_backup_t pin_backup[] = { GPIO_NUM_2, GPIO_NUM_13, GPIO_NUM_19, GPIO_NUM_22, GPIO_NUM_27, GPIO_NUM_33, GPIO_NUM_34 };
m5gfx::pinMode(GPIO_NUM_34, m5gfx::pin_mode_t::input);
m5gfx::pinMode(GPIO_NUM_2, m5gfx::pin_mode_t::input_pullup);
board = board_t::board_M5StampPico;
if (m5gfx::gpio_in(GPIO_NUM_2)) // Branches other than StampPico ( StampPico G2 is always LOW )
{
board = board_t::board_M5AtomU;
if (m5gfx::gpio_in(GPIO_NUM_34)) { // Branches other than AtomU ( AtomU G34 is always LOW )
board = board_t::board_M5AtomMatrix;
#if SOC_TOUCH_SENSOR_SUPPORTED
/* G27(RGBLED)に対してタッチセンサを用い、容量の差に基づいて Matrix の識別を行う。
G27に対してタッチセンサを使用すると、得られる値は Lite/ECHOの方が大きく、Matrixの方が小さい。
なおタッチセンサの値には個体差があるため、判定の基準として絶対値ではなく G13(NC)のタッチセンサ値を比較に用いる。
*/
uint16_t g13, g27;
touch_pad_init();
touch_pad_config(TOUCH_PAD_NUM4, TOUCH_PAD_THRESHOLD_MAX); // TOUCH_PAD_NUM4 == GPIO13
touch_pad_config(TOUCH_PAD_NUM7, TOUCH_PAD_THRESHOLD_MAX); // TOUCH_PAD_NUM7 == GPIO27
touch_pad_read(TOUCH_PAD_NUM4, &g13);
touch_pad_read(TOUCH_PAD_NUM7, &g27);
touch_pad_deinit();
int diff = (g27 * 3 - g13);
// M5_LOGV("G13 = %d / G27 = %d / diff = %d", g13, g27, diff);
// Branches other than AtomMatrix
if (diff >= 0)
#else
/*
タッチセンサAPIが使えない場合の処理 (ESP-IDFのバージョンに依る)
GPIOの立上り速度の差を用いて LiteとMatrix の識別を行う。
(Matrixの方がinput_pullupでHIGHになるまでの時間が長いため、この性質を利用して判定する)
*/
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
uint32_t g27 = 0;
// 8回読み取って立上り速度の差を見る
for (int i = 0; i < 8; ++i)
{
lgfx::pinMode(GPIO_NUM_27, lgfx::pin_mode_t::input_pulldown);
delay(1);
taskENTER_CRITICAL(&mux);
lgfx::pinMode(GPIO_NUM_27, lgfx::pin_mode_t::input_pullup);
g27 += lgfx::gpio_in(GPIO_NUM_27);
taskEXIT_CRITICAL(&mux);
}
// Branches other than AtomMatrix ( AtomMatrix G27 is delayed from becoming HIGH )
if (g27 > 4)
#endif
{
auto result = m5gfx::gpio::command(
(const uint8_t[]) {
m5gfx::gpio::command_mode_input_pulldown, GPIO_NUM_22,
m5gfx::gpio::command_mode_input_pulldown, GPIO_NUM_19,
m5gfx::gpio::command_mode_input_pulldown, GPIO_NUM_33,
m5gfx::gpio::command_mode_input_pullup , GPIO_NUM_33,
m5gfx::gpio::command_mode_input_pullup , GPIO_NUM_19,
m5gfx::gpio::command_mode_input_pullup , GPIO_NUM_22,
m5gfx::gpio::command_read , GPIO_NUM_33,
m5gfx::gpio::command_read , GPIO_NUM_19,
m5gfx::gpio::command_read , GPIO_NUM_22,
m5gfx::gpio::command_mode_input , GPIO_NUM_33,
m5gfx::gpio::command_mode_input , GPIO_NUM_19,
m5gfx::gpio::command_mode_input , GPIO_NUM_22,
m5gfx::gpio::command_delay , 1,
m5gfx::gpio::command_read , GPIO_NUM_33,
m5gfx::gpio::command_read , GPIO_NUM_19,
m5gfx::gpio::command_read , GPIO_NUM_22,
}
);
// G19 G22 G33 = ECHOのI2Sスピーカ用ピン。プルアップを無効化するとすぐにLOWになるため、この性質を利用して判定する。
// なお当該ピンに何かを外付けしている場合は判定に失敗する可能性がある。
board = board_t::board_M5AtomLite;
if ((result) == 0b111000)
{ // Branches for AtomECHO
board = board_t::board_M5AtomEcho;
}
}
}
}
for (auto &backup : pin_backup) {
backup.restore();
}
}
break;
case 6: // EFUSE_RD_CHIP_VER_PKG_ESP32PICOV3_02: // ATOM PSRAM
board = board_t::board_M5AtomPsram;
break;
default:
#if defined ( ARDUINO_M5STACK_CORE_ESP32 ) || defined ( ARDUINO_M5STACK_FIRE ) || defined ( ARDUINO_M5Stack_Core_ESP32 )
board = board_t::board_M5Stack;
#elif defined ( ARDUINO_M5STACK_CORE2 ) || defined ( ARDUINO_M5STACK_Core2 )
board = board_t::board_M5StackCore2;
#elif defined ( ARDUINO_M5STICK_C ) || defined ( ARDUINO_M5Stick_C )
board = board_t::board_M5StickC;
#elif defined ( ARDUINO_M5STICK_C_PLUS ) || defined ( ARDUINO_M5Stick_C_Plus )
board = board_t::board_M5StickCPlus;
#elif defined ( ARDUINO_M5STACK_COREINK ) || defined ( ARDUINO_M5Stack_CoreInk )
board = board_t::board_M5StackCoreInk;
#elif defined ( ARDUINO_M5STACK_PAPER ) || defined ( ARDUINO_M5STACK_Paper )
board = board_t::board_M5Paper;
#elif defined ( ARDUINO_M5STACK_TOUGH )
board = board_t::board_M5Tough;
#elif defined ( ARDUINO_M5STACK_ATOM ) || defined ( ARDUINO_M5Stack_ATOM )
board = board_t::board_M5AtomLite;
#elif defined ( ARDUINO_M5STACK_TIMER_CAM ) || defined ( ARDUINO_M5Stack_Timer_CAM )
board = board_t::board_M5TimerCam;
#endif
break;
}
}
#elif defined (CONFIG_IDF_TARGET_ESP32S3)
switch (m5gfx::get_pkg_ver())
{
default:
case 0: // EFUSE_PKG_VERSION_ESP32S3: // QFN56
if (board == board_t::board_unknown)
{ /// StampS3 or AtomS3Lite,S3U ?
/// After setting GPIO38 to INPUT PULL-UP, change to INPUT and read it.
/// In the case of STAMPS3: Returns 0. Charge is sucked by SGM2578.
/// In the case of ATOMS3Lite/S3U : Returns 1. Charge remains. ( Since it is not connected to anywhere. )
///
/// AtomS3Lite or AtomS3U ?
/// After setting GPIO4 to INPUT PULL-UP, read it.
/// In the case of ATOMS3Lite : Returns 0. Charge is sucked by InfraRed.
/// In the case of ATOMS3U : Returns 1. Charge remains. ( Since it is not connected to anywhere. )
m5gfx::gpio::pin_backup_t pin_backup[] = { GPIO_NUM_4, GPIO_NUM_8, GPIO_NUM_10, GPIO_NUM_12, GPIO_NUM_38 };
auto result = m5gfx::gpio::command(
(const uint8_t[]) {
m5gfx::gpio::command_mode_input_pulldown, GPIO_NUM_4,
m5gfx::gpio::command_mode_input_pulldown, GPIO_NUM_12,
m5gfx::gpio::command_mode_input_pulldown, GPIO_NUM_38,
m5gfx::gpio::command_mode_input_pulldown, GPIO_NUM_8,
m5gfx::gpio::command_mode_input_pulldown, GPIO_NUM_10,
m5gfx::gpio::command_mode_input_pullup , GPIO_NUM_4,
m5gfx::gpio::command_mode_input_pullup , GPIO_NUM_12,
m5gfx::gpio::command_mode_input_pullup , GPIO_NUM_38,
m5gfx::gpio::command_read , GPIO_NUM_8,
m5gfx::gpio::command_read , GPIO_NUM_10,
m5gfx::gpio::command_read , GPIO_NUM_4,
m5gfx::gpio::command_read , GPIO_NUM_12,
m5gfx::gpio::command_read , GPIO_NUM_38,
m5gfx::gpio::command_mode_input , GPIO_NUM_38,
m5gfx::gpio::command_delay , 1,
m5gfx::gpio::command_read , GPIO_NUM_38,
m5gfx::gpio::command_end
}
);
/// result には、command_read で得たGPIOの状態が1bitずつ4回分入っている。
board = ((const board_t[])
{ // ↓StampS3 pattern↓
board_t::board_unknown, board_t::board_unknown, board_t::board_M5StampS3, board_t::board_unknown, // ← unknown
board_t::board_M5AtomS3Lite,board_t::board_M5AtomS3Lite,board_t::board_unknown , board_t::board_M5AtomS3Lite, // ← AtomS3Lite pattern
board_t::board_M5AtomS3U, board_t::board_M5AtomS3U, board_t::board_M5StampS3, board_t::board_M5AtomS3U, // ← AtomS3U pattern
board_t::board_unknown, board_t::board_unknown, board_t::board_M5StampS3, board_t::board_unknown, // ← unknown
})[result&15];
if ((result & 3) == 2) { // StampS3 pattern
if ((result >> 3) == 0b110) {
board = board_t::board_M5Capsule;
// 自動検出の際。PortAに余分な波形が出ているので、一度 I2C STOPコンディションを出しておく。
// ※ これをしないと正しく動作しないデバイスが存在した。UnitHEART MAX30100
m5gfx::gpio::command(
(const uint8_t[]) {
m5gfx::gpio::command_mode_output, GPIO_NUM_15,
m5gfx::gpio::command_write_low , GPIO_NUM_15,
m5gfx::gpio::command_mode_output, GPIO_NUM_13,
m5gfx::gpio::command_write_low , GPIO_NUM_13,
m5gfx::gpio::command_write_high , GPIO_NUM_15,
m5gfx::gpio::command_write_high , GPIO_NUM_13,
m5gfx::gpio::command_end
}
);
}
}
for (auto &backup : pin_backup) {
backup.restore();
}
}
break;
case 1: // EFUSE_PKG_VERSION_ESP32S3PICO: // LGA56
if (board == board_t::board_unknown)
{ /// AtomS3RCam or AtomS3RExt ?
// Cam = GC0308 = I2C 7bit addr = 0x21
// CamM12 = OV3660 = I2C 7bit addr = 0x3C
board = board_t::board_M5AtomS3RExt;
m5gfx::gpio_lo(GPIO_NUM_18);
m5gfx::pinMode(GPIO_NUM_18, m5gfx::pin_mode_t::output);
m5gfx::gpio::pin_backup_t pin_backup[] = { GPIO_NUM_9, GPIO_NUM_12, GPIO_NUM_21 };
{ // G9=SCL, G12=SDA, G21=XCLK
m5gfx::gpio::command(
(const uint8_t[]) {
m5gfx::gpio::command_write_low, GPIO_NUM_9,
m5gfx::gpio::command_mode_output, GPIO_NUM_9, // SCL
m5gfx::gpio::command_write_low, GPIO_NUM_12,
m5gfx::gpio::command_mode_output, GPIO_NUM_12, // SDA
m5gfx::gpio::command_mode_output, GPIO_NUM_21, // XCL
m5gfx::gpio::command_write_high, GPIO_NUM_9,
m5gfx::gpio::command_write_high, GPIO_NUM_21,
m5gfx::gpio::command_write_high, GPIO_NUM_12,
});
auto lo_reg = m5gfx::get_gpio_lo_reg(GPIO_NUM_21);
auto hi_reg = m5gfx::get_gpio_hi_reg(GPIO_NUM_21);
// prepare camera module (need XCLK signal)
for (int xclk = 32768 * 54; xclk != 0; --xclk)
{
*lo_reg = 1 << GPIO_NUM_21;
*hi_reg = 1 << GPIO_NUM_21;
}
uint32_t result = 0;
for (uint8_t i2caddr: (const uint8_t[]){ 0x3C << 1, 0x21 << 1 }) {
for (int xclk = 32768 * 2; xclk != 0; --xclk) {
*lo_reg = 1 << GPIO_NUM_21;
*hi_reg = 1 << GPIO_NUM_21;
}
bool nack = true;
// The camera module is identified using I2C communication via GPIO self-operation.
*lo_reg = 1 << GPIO_NUM_12; // SDA LOW = START
for (int cycle = 0; cycle < 20; ++cycle) {
for (int j = 0; j < 2; ++j) {
for (int xclk = 8; xclk != 0; --xclk) {
*lo_reg = 1 << GPIO_NUM_21;
*hi_reg = 1 << GPIO_NUM_21;
}
*((cycle & 1) ? hi_reg : lo_reg) = 1 << GPIO_NUM_9; // SCL
}
if (cycle & 1) {
if (cycle == 17) {
nack = m5gfx::gpio_in(GPIO_NUM_12);
}
} else {
*((i2caddr & 0x80) ? hi_reg : lo_reg) = 1 << GPIO_NUM_12; // SDA
i2caddr <<= 1;
if (cycle >= 16) {
m5gfx::pinMode(GPIO_NUM_12, (cycle == 16) ? m5gfx::pin_mode_t::input : m5gfx::pin_mode_t::output);
}
}
}
*hi_reg = 1 << GPIO_NUM_12; // SDA HIGH = STOP
result = result << 1 | nack;
}
// printf("CAM TEST RESULT: %08x \r\n", (int)result);
if (result == 1 || result == 2) {
// result == 1 : OV3660
// result == 2 : GC0308
board = board_t::board_M5AtomS3RCam;
}
}
for (auto &backup : pin_backup) {
backup.restore();
}
}
}
#elif defined (CONFIG_IDF_TARGET_ESP32C3)
if (board == board_t::board_unknown)
{ // StampC3 or StampC3U ?
uint32_t tmp = *((volatile uint32_t *)(IO_MUX_GPIO20_REG));
m5gfx::pinMode(GPIO_NUM_20, m5gfx::pin_mode_t::input_pulldown);
// StampC3 has a strong external pull-up on GPIO20, which is HIGH even when input_pulldown is set.
// Therefore, if it is LOW, it is not StampC3 and can be assumed to be StampC3U.
// However, even if it goes HIGH, something may be connected to GPIO20 by StampC3U, so it is treated as unknown.
// The StampC3U determination uses the fallback_board setting.
if (m5gfx::gpio_in(GPIO_NUM_20) == false)
{
board = board_t::board_M5StampC3U;
}
*((volatile uint32_t *)(IO_MUX_GPIO20_REG)) = tmp;
}
#elif defined (CONFIG_IDF_TARGET_ESP32C6)
if (board == board_t::board_unknown)
{ // NanoC6 {
board = board_t::board_M5NanoC6;
}
#endif
return board;
}
void M5Unified::_setup_i2c(board_t board)
{
#if defined (M5UNIFIED_PC_BUILD)
(void)board;
#else
gpio_num_t in_scl = (gpio_num_t)getPin(pin_name_t::in_i2c_scl);
gpio_num_t in_sda = (gpio_num_t)getPin(pin_name_t::in_i2c_sda);
gpio_num_t ex_scl = (gpio_num_t)getPin(pin_name_t::ex_i2c_scl);
gpio_num_t ex_sda = (gpio_num_t)getPin(pin_name_t::ex_i2c_sda);
i2c_port_t ex_port = I2C_NUM_0;
#if SOC_I2C_NUM == 1
i2c_port_t in_port = I2C_NUM_0;
#else
i2c_port_t in_port = I2C_NUM_1;
if (in_scl == ex_scl && in_sda == ex_sda) {
in_port = ex_port;
}
#endif
if ((int)in_scl >= 0)
{
In_I2C.begin(in_port, in_sda, in_scl);
}
else
{
In_I2C.setPort(I2C_NUM_MAX, in_sda, in_scl);
}
if ((int)ex_scl >= 0)
{
Ex_I2C.setPort(ex_port, ex_sda, ex_scl);
}
#endif
}
void M5Unified::_begin(const config_t& cfg)
{
/// setup power management ic
Power.begin();
Power.setExtOutput(cfg.output_power);
if (cfg.led_brightness)
{
M5.Power.setLed(cfg.led_brightness);
}
auto pmic_type = Power.getType();
if (pmic_type == Power_Class::pmic_t::pmic_axp2101
|| pmic_type == Power_Class::pmic_t::pmic_axp192)
{
use_pmic_button = cfg.pmic_button;
/// Slightly lengthen the acceptance time of the AXP192 power button multiclick.
BtnPWR.setHoldThresh(BtnPWR.getHoldThresh() * 1.2);
}
if (cfg.clear_display)
{
Display.clear();
}
#if defined (M5UNIFIED_PC_BUILD)
#elif !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32)
switch (_board)
{
case board_t::board_M5Stack:
// Countermeasure to the problem that GPIO15 affects WiFi sensitivity when M5GO bottom is connected.
m5gfx::pinMode(GPIO_NUM_15, m5gfx::pin_mode_t::output);
m5gfx::gpio_lo(GPIO_NUM_15);
// M5Stack Core v2.6 has a problem that SPI communication speed cannot be increased.
// This problem can be solved by increasing the GPIO drive current.
// ※ This allows SunDisk SD cards to communicate at 20 MHz. (without M5GO bottom.)
// This allows communication with ModuleDisplay at 80 MHz.
for (auto gpio: (const gpio_num_t[]){ GPIO_NUM_18, GPIO_NUM_19, GPIO_NUM_23 })
{
uint32_t tmp = *(volatile uint32_t*)(GPIO_PIN_MUX_REG[gpio]);
*(volatile uint32_t*)(GPIO_PIN_MUX_REG[gpio]) = tmp | FUN_DRV_M; // gpio drive current set to 40mA.
gpio_pulldown_dis(gpio); // disable pulldown.
gpio_pullup_en(gpio); // enable pullup.
}
break;
case board_t::board_M5StickC:
case board_t::board_M5StickCPlus:
case board_t::board_M5AtomLite:
case board_t::board_M5AtomMatrix:
case board_t::board_M5AtomEcho:
case board_t::board_M5AtomU:
// Countermeasure to the problem that CH552 applies 4v to GPIO0, thus reducing WiFi sensitivity.
// Setting output_high adds a bias of 3.3v and suppresses overvoltage.
m5gfx::pinMode(GPIO_NUM_0, m5gfx::pin_mode_t::output);
m5gfx::gpio_hi(GPIO_NUM_0);
break;
default:
break;
}
#endif
switch (_board) /// setup Hardware Buttons
{
#if defined (M5UNIFIED_PC_BUILD)
#elif !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32)
case board_t::board_M5StackCoreInk:
m5gfx::pinMode(CoreInk_BUTTON_EXT_PIN, m5gfx::pin_mode_t::input); // TopButton
m5gfx::pinMode(CoreInk_BUTTON_PWR_PIN, m5gfx::pin_mode_t::input); // PowerButton
NON_BREAK; /// don't break;
case board_t::board_M5Paper:
case board_t::board_M5Station:
case board_t::board_M5Stack:
m5gfx::pinMode(GPIO_NUM_38, m5gfx::pin_mode_t::input);
NON_BREAK; /// don't break;
case board_t::board_M5StickC:
case board_t::board_M5StickCPlus:
m5gfx::pinMode(GPIO_NUM_37, m5gfx::pin_mode_t::input);
NON_BREAK; /// don't break;
case board_t::board_M5AtomLite:
case board_t::board_M5AtomMatrix:
case board_t::board_M5AtomEcho:
case board_t::board_M5AtomPsram:
case board_t::board_M5AtomU:
case board_t::board_M5StampPico:
m5gfx::pinMode(GPIO_NUM_39, m5gfx::pin_mode_t::input);
NON_BREAK; /// don't break;
case board_t::board_M5StackCore2:
case board_t::board_M5Tough:
/// for GPIO 36,39 Chattering prevention.
adc_power_acquire();
break;
case board_t::board_M5StickCPlus2:
m5gfx::pinMode(GPIO_NUM_35, m5gfx::pin_mode_t::input);
m5gfx::pinMode(GPIO_NUM_37, m5gfx::pin_mode_t::input);
m5gfx::pinMode(GPIO_NUM_39, m5gfx::pin_mode_t::input);
break;
#elif defined (CONFIG_IDF_TARGET_ESP32C3)
case board_t::board_M5StampC3:
m5gfx::pinMode(GPIO_NUM_3, m5gfx::pin_mode_t::input_pullup);
break;
case board_t::board_M5StampC3U:
m5gfx::pinMode(GPIO_NUM_9, m5gfx::pin_mode_t::input_pullup);
break;
#elif defined (CONFIG_IDF_TARGET_ESP32C6)
case board_t::board_M5NanoC6:
m5gfx::pinMode(GPIO_NUM_9, m5gfx::pin_mode_t::input_pullup);
break;
#elif defined (CONFIG_IDF_TARGET_ESP32S3)
case board_t::board_M5AtomS3:
case board_t::board_M5AtomS3Lite:
case board_t::board_M5AtomS3U:
case board_t::board_M5AtomS3R:
m5gfx::pinMode(GPIO_NUM_41, m5gfx::pin_mode_t::input);
break;
case board_t::board_M5AirQ:
m5gfx::pinMode(GPIO_NUM_0, m5gfx::pin_mode_t::input);
m5gfx::pinMode(GPIO_NUM_8, m5gfx::pin_mode_t::input);
break;
case board_t::board_M5VAMeter:
m5gfx::pinMode(GPIO_NUM_0, m5gfx::pin_mode_t::input);
m5gfx::pinMode(GPIO_NUM_2, m5gfx::pin_mode_t::input);
break;
case board_t::board_M5StampS3:
case board_t::board_M5Cardputer:
m5gfx::pinMode(GPIO_NUM_0, m5gfx::pin_mode_t::input);
break;
case board_t::board_M5Capsule:
case board_t::board_M5Dial:
case board_t::board_M5DinMeter:
m5gfx::pinMode(GPIO_NUM_42, m5gfx::pin_mode_t::input);
break;
#endif
default:
break;
}
#if defined ( ARDUINO )
if (cfg.serial_baudrate)
{ // Wait with delay to prevent startup log output from disappearing.
delay(16);
Serial.begin(cfg.serial_baudrate);
}
#endif
}
void M5Unified::_begin_spk(config_t& cfg)
{
if (cfg.internal_mic)
{
auto mic_cfg = Mic.config();
mic_cfg.over_sampling = 1;
mic_cfg.i2s_port = I2S_NUM_0;
switch (_board)
{
#if defined (M5UNIFIED_PC_BUILD)
#elif defined (CONFIG_IDF_TARGET_ESP32S3)
case board_t::board_M5StackCoreS3:
case board_t::board_M5StackCoreS3SE:
if (cfg.internal_mic)
{
mic_cfg.magnification = 2;
mic_cfg.over_sampling = 1;
mic_cfg.pin_mck = GPIO_NUM_0;
mic_cfg.pin_bck = GPIO_NUM_34;
mic_cfg.pin_ws = GPIO_NUM_33;
mic_cfg.pin_data_in = GPIO_NUM_14;
mic_cfg.i2s_port = I2S_NUM_1;
mic_cfg.stereo = true;
}
break;
case board_t::board_M5AtomS3U:
if (cfg.internal_mic)
{
mic_cfg.pin_data_in = GPIO_NUM_38;
mic_cfg.pin_ws = GPIO_NUM_39;
}
break;
case board_t::board_M5Cardputer:
if (cfg.internal_mic)
{
mic_cfg.pin_data_in = GPIO_NUM_46;
mic_cfg.pin_ws = GPIO_NUM_43;
}
break;
case board_t::board_M5Capsule:
if (cfg.internal_mic)
{
mic_cfg.pin_data_in = GPIO_NUM_41;
mic_cfg.pin_ws = GPIO_NUM_40;
}
break;
#elif !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32)
case board_t::board_M5Stack:
if (cfg.internal_mic)
{