-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathctsu.hpp
1275 lines (1174 loc) · 35.9 KB
/
ctsu.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
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
#pragma once
//=========================================================================//
/*! @file
@brief Capacitive Touch Sensing Unit / 静電容量式タッチセンサ @n
・RX113 @n
・RX130 @n
・RX231 @n
・RX671
@author 平松邦仁 ([email protected])
@copyright Copyright (C) 2024 Kunihito Hiramatsu @n
Released under the MIT license @n
https://github.com/hirakuni45/RX/blob/master/LICENSE
*/
//=========================================================================//
#include "common/device.hpp"
namespace device {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief CTSU base class
@param[in] base ベース・アドレス
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
template <uint32_t base>
struct ctsu_base_t {
//-----------------------------------------------------------------//
/*!
@brief CTSU 制御レジスタ 0 (CTSUCR0)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
template <uint32_t ofs>
struct ctsucr0_t : public rw8_t<ofs> {
typedef rw8_t<ofs> io_;
using io_::operator =;
using io_::operator ();
using io_::operator |=;
using io_::operator &=;
bit_rw_t <io_, bitpos::B0> CTSUSTRT;
bit_rw_t <io_, bitpos::B1> CTSUCAP;
bit_rw_t <io_, bitpos::B2> CTSUSNZ;
bit_rw_t <io_, bitpos::B3> CTSUIOC;
bit_rw_t <io_, bitpos::B4> CTSUINIT;
};
static inline ctsucr0_t<base + 0x00> CTSUCR0;
//-----------------------------------------------------------------//
/*!
@brief CTSU 制御レジスタ 1 (CTSUCR1)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
template <uint32_t ofs>
struct ctsucr1_t : public rw8_t<ofs> {
typedef rw8_t<ofs> io_;
using io_::operator =;
using io_::operator ();
using io_::operator |=;
using io_::operator &=;
bit_rw_t <io_, bitpos::B0> CTSUPON;
bit_rw_t <io_, bitpos::B1> CTSUCSW;
bit_rw_t <io_, bitpos::B2> CTSUATUNE0;
bit_rw_t <io_, bitpos::B3> CTSUATUNE1;
bits_rw_t<io_, bitpos::B4, 2> CTSUCLK;
bits_rw_t<io_, bitpos::B6, 2> CTSUMD;
};
static inline ctsucr1_t<base + 0x01> CTSUCR1;
//-----------------------------------------------------------------//
/*!
@brief CTSU 同期ノイズ低減設定レジスタ (CTSUSDPRS)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
template <uint32_t ofs>
struct ctsusdprs_t : public rw8_t<ofs> {
typedef rw8_t<ofs> io_;
using io_::operator =;
using io_::operator ();
using io_::operator |=;
using io_::operator &=;
bits_rw_t<io_, bitpos::B0, 4> CTSUPRRATIO;
bits_rw_t<io_, bitpos::B4, 2> CTSUPRMODE;
bit_rw_t <io_, bitpos::B6> CTSUSOFF;
};
static inline ctsusdprs_t<base + 0x02> CTSUSDPRS;
//-----------------------------------------------------------------//
/*!
@brief CTSU センサ安定待ち時間レジスタ (CTSUSST)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
template <uint32_t ofs>
struct ctsusst_t : public rw8_t<ofs> {
typedef rw8_t<ofs> io_;
using io_::operator =;
using io_::operator ();
using io_::operator |=;
using io_::operator &=;
bits_rw_t<io_, bitpos::B0, 8> CTSUSST;
};
static inline ctsusst_t<base + 0x03> CTSUSST;
//-----------------------------------------------------------------//
/*!
@brief CTSU 計測チャネルレジスタ 0 (CTSUMCH0)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
template <uint32_t ofs>
struct ctsumch0_t : public rw8_t<ofs> {
typedef rw8_t<ofs> io_;
using io_::operator =;
using io_::operator ();
using io_::operator |=;
using io_::operator &=;
bits_rw_t<io_, bitpos::B0, 6> CTSUMCH0;
};
static inline ctsumch0_t<base + 0x04> CTSUMCH0;
//-----------------------------------------------------------------//
/*!
@brief CTSU 計測チャネルレジスタ 1 (CTSUMCH1)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
template <uint32_t ofs>
struct ctsumch1_t : public rw8_t<ofs> {
typedef rw8_t<ofs> io_;
using io_::operator =;
using io_::operator ();
using io_::operator |=;
using io_::operator &=;
bits_rw_t<io_, bitpos::B0, 6> CTSUMCH1;
};
static inline ctsumch1_t<base + 0x05> CTSUMCH1;
//-----------------------------------------------------------------//
/*!
@brief CTSU 高域ノイズ低減制御レジスタ (CTSUDCLKC)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
template <uint32_t ofs>
struct ctsudclkc_t : public rw8_t<ofs> {
typedef rw8_t<ofs> io_;
using io_::operator =;
using io_::operator ();
using io_::operator |=;
using io_::operator &=;
bits_rw_t<io_, bitpos::B0, 2> CTSUSSMOD;
bits_rw_t<io_, bitpos::B4, 2> CTSUSSCNT;
};
static inline ctsudclkc_t<base + 0x10> CTSUDCLKC;
//-----------------------------------------------------------------//
/*!
@brief CTSU ステータスレジスタ (CTSUST)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
template <uint32_t ofs>
struct ctsust_t : public rw8_t<ofs> {
typedef rw8_t<ofs> io_;
using io_::operator =;
using io_::operator ();
using io_::operator |=;
using io_::operator &=;
bits_ro_t<io_, bitpos::B0, 3> CTSUSTC;
bit_ro_t <io_, bitpos::B4> CTSUDTSR;
bit_rw_t <io_, bitpos::B5> CTSUSOVF;
bit_rw_t <io_, bitpos::B6> CTSUROVF;
bit_ro_t <io_, bitpos::B7> CTSUPS;
};
static inline ctsust_t<base + 0x11> CTSUST;
//-----------------------------------------------------------------//
/*!
@brief CTSU 高域ノイズ低減スペクトラム拡散制御レジスタ (CTSUSSC)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
template <uint32_t ofs>
struct ctsussc_t : public rw16_t<ofs> {
typedef rw16_t<ofs> io_;
using io_::operator =;
using io_::operator ();
using io_::operator |=;
using io_::operator &=;
bits_rw_t<io_, bitpos::B8, 4> CTSUSSDIV;
};
static inline ctsussc_t<base + 0x12> CTSUSSC;
//-----------------------------------------------------------------//
/*!
@brief CTSU センサオフセットレジスタ 0 (CTSUSO0)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
template <uint32_t ofs>
struct ctsuso0_t : public rw16_t<ofs> {
typedef rw16_t<ofs> io_;
using io_::operator =;
using io_::operator ();
using io_::operator |=;
using io_::operator &=;
bits_rw_t<io_, bitpos::B0, 10> CTSUSO;
bits_rw_t<io_, bitpos::B10, 6> CTSUSNUM;
};
static inline ctsuso0_t<base + 0x14> CTSUSO0;
//-----------------------------------------------------------------//
/*!
@brief CTSU センサオフセットレジスタ 1 (CTSUSO1)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
template <uint32_t ofs>
struct ctsuso1_t : public rw16_t<ofs> {
typedef rw16_t<ofs> io_;
using io_::operator =;
using io_::operator ();
using io_::operator |=;
using io_::operator &=;
bits_rw_t<io_, bitpos::B0, 8> CTSURICOA;
bits_rw_t<io_, bitpos::B8, 5> CTSUSDPA;
bits_rw_t<io_, bitpos::B13, 2> CTSUICOG;
};
static inline ctsuso1_t<base + 0x16> CTSUSO1;
//-----------------------------------------------------------------//
/*!
@brief CTSU センサカウンタ (CTSUSC)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
template <uint32_t ofs>
struct ctsusc_t : public rw16_t<ofs> {
typedef rw16_t<ofs> io_;
using io_::operator =;
using io_::operator ();
using io_::operator |=;
using io_::operator &=;
bits_rw_t<io_, bitpos::B0, 16> CTSUSC;
};
static inline ctsusc_t<base + 0x18> CTSUSC;
//-----------------------------------------------------------------//
/*!
@brief CTSU リファレンスカウンタ (CTSURC)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
template <uint32_t ofs>
struct ctsurc_t : public rw16_t<ofs> {
typedef rw16_t<ofs> io_;
using io_::operator =;
using io_::operator ();
using io_::operator |=;
using io_::operator &=;
bits_rw_t<io_, bitpos::B0, 16> CTSURC;
};
static inline ctsurc_t<base + 0x1A> CTSURC;
//-----------------------------------------------------------------//
/*!
@brief CTSU エラーステータスレジスタ (CTSUERRS)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
template <uint32_t ofs>
struct ctsuerrs_t : public rw16_t<ofs> {
typedef rw16_t<ofs> io_;
using io_::operator =;
using io_::operator ();
using io_::operator |=;
using io_::operator &=;
bits_rw_t<io_, bitpos::B0, 2> CTSUSPMD;
bit_rw_t <io_, bitpos::B2> CTSUTSOD;
bit_rw_t <io_, bitpos::B3> CTSUDRV;
bit_rw_t <io_, bitpos::B7> CTSUTSOC;
bit_rw_t <io_, bitpos::B15> CTSUICOMP;
};
static inline ctsuerrs_t<base + 0x1C> CTSUERRS;
};
struct ctsu_utils {
//-----------------------------------------------------------------//
/*!
@brief CTSU チャネル有効制御レジスタ n (CTSUCHACn) (n = 0 ~ 4)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
template <uint32_t ofs>
struct ctsuchacn_t : public rw8_t<ofs> {
typedef rw8_t<ofs> io_;
using io_::operator =;
using io_::operator ();
using io_::operator |=;
using io_::operator &=;
bit_rw_t <io_, bitpos::B0> CTSUCHAC0;
bit_rw_t <io_, bitpos::B1> CTSUCHAC1;
bit_rw_t <io_, bitpos::B2> CTSUCHAC2;
bit_rw_t <io_, bitpos::B3> CTSUCHAC3;
bit_rw_t <io_, bitpos::B4> CTSUCHAC4;
bit_rw_t <io_, bitpos::B5> CTSUCHAC5;
bit_rw_t <io_, bitpos::B6> CTSUCHAC6;
bit_rw_t <io_, bitpos::B7> CTSUCHAC7;
};
//-----------------------------------------------------------------//
/*!
@brief CTSU チャネル送受信制御レジスタ n (CTSUCHTRCn) (n = 0 ~ 4)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
template <uint32_t ofs>
struct ctsuchtrcn_t : public rw8_t<ofs> {
typedef rw8_t<ofs> io_;
using io_::operator =;
using io_::operator ();
using io_::operator |=;
using io_::operator &=;
bit_rw_t <io_, bitpos::B0> CTSUCHTRC0;
bit_rw_t <io_, bitpos::B1> CTSUCHTRC1;
bit_rw_t <io_, bitpos::B2> CTSUCHTRC2;
bit_rw_t <io_, bitpos::B3> CTSUCHTRC3;
bit_rw_t <io_, bitpos::B4> CTSUCHTRC4;
bit_rw_t <io_, bitpos::B5> CTSUCHTRC5;
bit_rw_t <io_, bitpos::B6> CTSUCHTRC6;
bit_rw_t <io_, bitpos::B7> CTSUCHTRC7;
};
//-----------------------------------------------------------------//
/*!
@brief CTSU チャネル制御クラス
@param[in] base ベース・アドレス
@param[in] PORT ポート型
*/
//-----------------------------------------------------------------//
template <uint32_t base, typename PORT>
struct ctsuchctrl_t {
bool get(PORT port) noexcept
{
if(port != PORT::TSCAP) {
auto n = static_cast<uint8_t>(port);
auto adr = base + (n >> 3);
auto tmp = rd8_(adr);
return tmp & (1 << (n & 7));
} else {
return 0;
}
}
void set(PORT port, bool val = true) noexcept
{
if(port != PORT::TSCAP) {
auto n = static_cast<uint8_t>(port);
auto adr = base + (n >> 3);
auto tmp = rd8_(adr);
if(val) {
tmp |= 1 << (n & 7);
} else {
tmp &= ~(1 << (n & 7));
}
wr8_(adr, tmp);
}
}
bool operator () (PORT port) {
return get(port);
}
};
};
#if defined(SIG_RX113)
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief RX113 静電容量式タッチセンサ CTSU クラス
@param[in] base ベース・アドレス
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
template <uint32_t base>
struct ctsu_t : public ctsu_base_t<base> {
static constexpr auto PERIPHERAL = peripheral::CTSU; ///< ペリフェラル型
static constexpr auto WRI = ICU::VECTOR::CTSUWR; ///< チャネル毎の設定レジスタ書き込み要求割り込み
static constexpr auto RDI = ICU::VECTOR::CTSURD; ///< 測定データ転送要求割り込み
static constexpr auto FNI = ICU::VECTOR::CTSUFN; ///< 測定終了割り込み
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief CTSU ポート型
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
enum class PORT : uint8_t {
TSCAP = 12, ///< P26
TS0 = 0, ///< P07
TS1, ///< P04
TS2, ///< P02
TS3, ///< PJ3
TS4, ///< P25
TS5, ///< P24
TS6, ///< P23
TS7, ///< P22
TS8, ///< P21
TS9, ///< P20
TS10, ///< P27
TS11, ///< P26
};
//-----------------------------------------------------------------//
/*!
@brief CTSU ポートを有効にする
@param[in] port CTSU ポート
@param[in] ena 無効にする場合「false」
*/
//-----------------------------------------------------------------//
static void enable(PORT port, bool ena = true) noexcept
{
MPC::PWPR.B0WI = 0; // PWPR 書き込み許可
MPC::PWPR.PFSWE = 1; // PxxPFS 書き込み許可
uint8_t sel = ena ? 0b1'1001 : 0;
switch(port) {
case PORT::TSCAP:
PORT2::PMR.B6 = 0;
MPC::P26PFS.PSEL = sel;
PORT2::PMR.B6 = ena;
break;
case PORT::TS0:
PORT0::PMR.B7 = 0;
MPC::P07PFS.PSEL = sel;
PORT0::PMR.B7 = ena;
break;
case PORT::TS1:
PORT0::PMR.B4 = 0;
MPC::P04PFS.PSEL = sel;
PORT0::PMR.B4 = ena;
break;
case PORT::TS2:
PORT0::PMR.B2 = 0;
MPC::P02PFS.PSEL = sel;
PORT0::PMR.B2 = ena;
break;
case PORT::TS3:
PORTJ::PMR.B3 = 0;
MPC::PJ3PFS.PSEL = sel;
PORTJ::PMR.B3 = ena;
break;
case PORT::TS4:
PORT2::PMR.B5 = 0;
MPC::P25PFS.PSEL = sel;
PORT2::PMR.B5 = ena;
break;
case PORT::TS5:
PORT2::PMR.B4 = 0;
MPC::P24PFS.PSEL = sel;
PORT2::PMR.B4 = ena;
break;
case PORT::TS6:
PORT2::PMR.B3 = 0;
MPC::P23PFS.PSEL = sel;
PORT2::PMR.B3 = ena;
break;
case PORT::TS7:
PORT2::PMR.B2 = 0;
MPC::P22PFS.PSEL = sel;
PORT2::PMR.B2 = ena;
break;
case PORT::TS8:
PORT2::PMR.B1 = 0;
MPC::P21PFS.PSEL = sel;
PORT2::PMR.B1 = ena;
break;
case PORT::TS9:
PORT2::PMR.B0 = 0;
MPC::P20PFS.PSEL = sel;
PORT2::PMR.B0 = ena;
break;
case PORT::TS10:
PORT2::PMR.B7 = 0;
MPC::P27PFS.PSEL = sel;
PORT2::PMR.B7 = ena;
break;
case PORT::TS11:
PORT2::PMR.B6 = 0;
MPC::P26PFS.PSEL = sel;
PORT2::PMR.B6 = ena;
break;
default:
break;
}
MPC::PWPR = device::MPC::PWPR.B0WI.b();
}
//-----------------------------------------------------------------//
/*!
@brief CTSU チャネル有効制御レジスタ n (CTSUCHACn) (n = 0 ~ 3)
*/
//-----------------------------------------------------------------//
typedef ctsu_utils::ctsuchacn_t<base + 0x06> CTSUCHAC0_;
static inline CTSUCHAC0_ CTSUCHAC0;
static inline ctsu_utils::ctsuchacn_t<base + 0x07> CTSUCHAC1;
static inline ctsu_utils::ctsuchctrl_t<base + 0x06, PORT> CTSUCHAC;
//-----------------------------------------------------------------//
/*!
@brief CTSU チャネル送受信制御レジスタ n (CTSUCHTRCn) (n = 0 ~ 3)
*/
//-----------------------------------------------------------------//
typedef ctsu_utils::ctsuchtrcn_t<base + 0x0B> CTSUCHTRC0_;
static inline CTSUCHTRC0_ CTSUCHTRC0;
typedef ctsu_utils::ctsuchtrcn_t<base + 0x0C> CTSUCHTRC1;
static inline ctsu_utils::ctsuchctrl_t<base + 0x08, PORT> CTSUCHTRC;
//-----------------------------------------------------------------//
/*!
@brief CTSU 基準電流調整レジスタ (CTSUTRMR)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
static inline rw8_t<0x007F'FFBE> CTSUTRMR;
};
#elif defined(SIG_RX130)
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief RX130 静電容量式タッチセンサ CTSUa クラス
@param[in] base ベース・アドレス
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
template <uint32_t base>
struct ctsu_t : public ctsu_base_t<base> {
static constexpr auto PERIPHERAL = peripheral::CTSU; ///< ペリフェラル型
static constexpr auto WRI = ICU::VECTOR::CTSUWR; ///< チャネル毎の設定レジスタ書き込み要求割り込み
static constexpr auto RDI = ICU::VECTOR::CTSURD; ///< 測定データ転送要求割り込み
static constexpr auto FNI = ICU::VECTOR::CTSUFN; ///< 測定終了割り込み
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief CTSU ポート型
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
enum class PORT : uint8_t {
TSCAP = 36, ///< PC4
TS0 = 0, ///< P32
TS1, ///< P31
TS2, ///< P30
TS3, ///< P27
TS4, ///< P26
TS5, ///< P15
TS6, ///< P14
TS7, ///< PH3
TS8, ///< PH2
TS9, ///< PH1
TS10, ///< PH0
TS11, ///< P55
TS12, ///< P54
TS13, ///< PC7
TS14, ///< PC6
TS15, ///< PC5
TS16, ///< PC3
TS17, ///< PC2
TS18, ///< PB7
TS19, ///< PB6
TS20, ///< PB5
TS21, ///< PB4
TS22, ///< PB3
TS23, ///< PB2
TS24, ///< PB1
TS25, ///< PB0
TS26, ///< PA6
TS27, ///< PA5
TS28, ///< PA4
TS29, ///< PA3
TS30, ///< PA2
TS31, ///< PA1
TS32, ///< PA0
TS33, ///< PE4
TS34, ///< PE3
TS35, ///< PE2
};
//-----------------------------------------------------------------//
/*!
@brief CTSU ポートを有効にする
@param[in] port CTSU ポート
@param[in] ena 無効にする場合「false」
*/
//-----------------------------------------------------------------//
static void enable(PORT port, bool ena = true) noexcept
{
MPC::PWPR.B0WI = 0; // PWPR 書き込み許可
MPC::PWPR.PFSWE = 1; // PxxPFS 書き込み許可
uint8_t sel = ena ? 0b1'1001 : 0;
switch(port) {
case PORT::TSCAP:
PORTC::PMR.B4 = 0;
MPC::PC4PFS.PSEL = sel;
PORTC::PMR.B4 = ena;
break;
case PORT::TS0:
PORT3::PMR.B2 = 0;
MPC::P32PFS.PSEL = sel;
PORT3::PMR.B2 = ena;
break;
case PORT::TS1:
PORT3::PMR.B1 = 0;
MPC::P31PFS.PSEL = sel;
PORT3::PMR.B1 = ena;
break;
case PORT::TS2:
PORT3::PMR.B0 = 0;
MPC::P30PFS.PSEL = sel;
PORT3::PMR.B0 = ena;
break;
case PORT::TS3:
PORT2::PMR.B7 = 0;
MPC::P27PFS.PSEL = sel;
PORT2::PMR.B7 = ena;
break;
case PORT::TS4:
PORT2::PMR.B6 = 0;
MPC::P26PFS.PSEL = sel;
PORT2::PMR.B6 = ena;
break;
case PORT::TS5:
PORT1::PMR.B5 = 0;
MPC::P15PFS.PSEL = sel;
PORT1::PMR.B5 = ena;
break;
case PORT::TS6:
PORT1::PMR.B4 = 0;
MPC::P14PFS.PSEL = sel;
PORT1::PMR.B4 = ena;
break;
case PORT::TS7:
PORTH::PMR.B3 = 0;
MPC::PH3PFS.PSEL = sel;
PORTH::PMR.B3 = ena;
break;
case PORT::TS8:
PORTH::PMR.B2 = 0;
MPC::PH2PFS.PSEL = sel;
PORTH::PMR.B2 = ena;
break;
case PORT::TS9:
PORTH::PMR.B1 = 0;
MPC::PH1PFS.PSEL = sel;
PORTH::PMR.B1 = ena;
break;
case PORT::TS10:
PORTH::PMR.B0 = 0;
MPC::PH0PFS.PSEL = sel;
PORTH::PMR.B0 = ena;
break;
case PORT::TS11:
PORT5::PMR.B5 = 0;
MPC::P55PFS.PSEL = sel;
PORT5::PMR.B5 = ena;
break;
case PORT::TS12:
PORT5::PMR.B4 = 0;
MPC::P54PFS.PSEL = sel;
PORT5::PMR.B4 = ena;
break;
case PORT::TS13:
PORTC::PMR.B7 = 0;
MPC::PC7PFS.PSEL = sel;
PORTC::PMR.B7 = ena;
break;
case PORT::TS14:
PORTC::PMR.B6 = 0;
MPC::PC6PFS.PSEL = sel;
PORTC::PMR.B6 = ena;
break;
case PORT::TS15:
PORTC::PMR.B5 = 0;
MPC::PC5PFS.PSEL = sel;
PORTC::PMR.B5 = ena;
break;
case PORT::TS16:
PORTC::PMR.B3 = 0;
MPC::PC3PFS.PSEL = sel;
PORTC::PMR.B3 = ena;
break;
case PORT::TS17:
PORTC::PMR.B2 = 0;
MPC::PC2PFS.PSEL = sel;
PORTC::PMR.B2 = ena;
break;
case PORT::TS18:
PORTB::PMR.B7 = 0;
MPC::PB7PFS.PSEL = sel;
PORTB::PMR.B7 = ena;
break;
case PORT::TS19:
PORTB::PMR.B6 = 0;
MPC::PB6PFS.PSEL = sel;
PORTB::PMR.B6 = ena;
break;
case PORT::TS20:
PORTB::PMR.B5 = 0;
MPC::PB5PFS.PSEL = sel;
PORTB::PMR.B5 = ena;
break;
case PORT::TS21:
PORTB::PMR.B4 = 0;
MPC::PB4PFS.PSEL = sel;
PORTB::PMR.B4 = ena;
break;
case PORT::TS22:
PORTB::PMR.B3 = 0;
MPC::PB3PFS.PSEL = sel;
PORTB::PMR.B3 = ena;
break;
case PORT::TS23:
PORTB::PMR.B2 = 0;
MPC::PB2PFS.PSEL = sel;
PORTB::PMR.B2 = ena;
break;
case PORT::TS24:
PORTB::PMR.B1 = 0;
MPC::PB1PFS.PSEL = sel;
PORTB::PMR.B1 = ena;
break;
case PORT::TS25:
PORTB::PMR.B0 = 0;
MPC::PB0PFS.PSEL = sel;
PORTB::PMR.B0 = ena;
break;
case PORT::TS26:
PORTA::PMR.B6 = 0;
MPC::PA6PFS.PSEL = sel;
PORTA::PMR.B6 = ena;
break;
case PORT::TS27:
PORTA::PMR.B5 = 0;
MPC::PA5PFS.PSEL = sel;
PORTA::PMR.B5 = ena;
break;
case PORT::TS28:
PORTA::PMR.B4 = 0;
MPC::PA4PFS.PSEL = sel;
PORTA::PMR.B4 = ena;
break;
case PORT::TS29:
PORTA::PMR.B3 = 0;
MPC::PA3PFS.PSEL = sel;
PORTA::PMR.B3 = ena;
break;
case PORT::TS30:
PORTA::PMR.B2 = 0;
MPC::PA2PFS.PSEL = sel;
PORTA::PMR.B2 = ena;
break;
case PORT::TS31:
PORTA::PMR.B1 = 0;
MPC::PA1PFS.PSEL = sel;
PORTA::PMR.B1 = ena;
break;
case PORT::TS32:
PORTA::PMR.B0 = 0;
MPC::PA0PFS.PSEL = sel;
PORTA::PMR.B0 = ena;
break;
case PORT::TS33:
PORTE::PMR.B4 = 0;
MPC::PE4PFS.PSEL = sel;
PORTE::PMR.B4 = ena;
break;
case PORT::TS34:
PORTE::PMR.B3 = 0;
MPC::PE3PFS.PSEL = sel;
PORTE::PMR.B3 = ena;
break;
case PORT::TS35:
PORTE::PMR.B2 = 0;
MPC::PE2PFS.PSEL = sel;
PORTE::PMR.B2 = ena;
break;
default:
break;
}
MPC::PWPR = device::MPC::PWPR.B0WI.b();
}
//-----------------------------------------------------------------//
/*!
@brief CTSU チャネル有効制御レジスタ n (CTSUCHACn) (n = 0 ~ 3)
*/
//-----------------------------------------------------------------//
typedef ctsu_utils::ctsuchacn_t<base + 0x06> CTSUCHAC0_;
static inline CTSUCHAC0_ CTSUCHAC0;
static inline ctsu_utils::ctsuchacn_t<base + 0x07> CTSUCHAC1;
static inline ctsu_utils::ctsuchacn_t<base + 0x08> CTSUCHAC2;
static inline ctsu_utils::ctsuchacn_t<base + 0x09> CTSUCHAC3;
static inline ctsu_utils::ctsuchacn_t<base + 0x0A> CTSUCHAC4;
static inline ctsu_utils::ctsuchctrl_t<base + 0x06, PORT> CTSUCHAC;
//-----------------------------------------------------------------//
/*!
@brief CTSU チャネル送受信制御レジスタ n (CTSUCHTRCn) (n = 0 ~ 3)
*/
//-----------------------------------------------------------------//
typedef ctsu_utils::ctsuchtrcn_t<base + 0x0B> CTSUCHTRC0_;
static inline CTSUCHTRC0_ CTSUCHTRC0;
typedef ctsu_utils::ctsuchtrcn_t<base + 0x0C> CTSUCHTRC1;
typedef ctsu_utils::ctsuchtrcn_t<base + 0x0D> CTSUCHTRC2;
typedef ctsu_utils::ctsuchtrcn_t<base + 0x0E> CTSUCHTRC3;
typedef ctsu_utils::ctsuchtrcn_t<base + 0x0F> CTSUCHTRC4;
static inline ctsu_utils::ctsuchctrl_t<base + 0x08, PORT> CTSUCHTRC;
//-----------------------------------------------------------------//
/*!
@brief CTSU 基準電流調整レジスタ (CTSUTRMR)
@param[in] ofs オフセット
*/
//-----------------------------------------------------------------//
static inline rw8_t<0x007F'FFBE> CTSUTRMR;
};
#elif defined(SIG_RX231)
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief RX231 静電容量式タッチセンサ CTSU クラス
@param[in] base ベース・アドレス
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
template <uint32_t base>
struct ctsu_t : public ctsu_base_t<base> {
static constexpr auto PERIPHERAL = peripheral::CTSU; ///< ペリフェラル型
static constexpr auto WRI = ICU::VECTOR::CTSUWR; ///< チャネル毎の設定レジスタ書き込み要求割り込み
static constexpr auto RDI = ICU::VECTOR::CTSURD; ///< 測定データ転送要求割り込み
static constexpr auto FNI = ICU::VECTOR::CTSUFN; ///< 測定終了割り込み
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief CTSU ポート型
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
enum class PORT : uint8_t {
TSCAP = 36, ///< PC4
TS0 = 0, ///< P34
TS1, ///< P33
TS2, ///< P27
TS3, ///< P26
TS4, ///< P25
TS5, ///< P24
TS6, ///< P23
TS7, ///< P22
TS8, ///< P21
TS9, ///< P20
TS12 = 12, ///< P15
TS13, ///< P14
TS15 = 15, ///< P55
TS16, ///< P54
TS17, ///< P53
TS18, ///< P52
TS19, ///< P51
TS20, ///< P50
TS22 = 22, ///< PC6
TS23, ///< PC5
TS27 = 27, ///< PC3
TS30 = 30, ///< PC2
TS33 = 33, ///< PC1
TS35 = 35, ///< PC0
};
//-----------------------------------------------------------------//
/*!
@brief CTSU ポートを有効にする
@param[in] port CTSU ポート
@param[in] ena 無効にする場合「false」
*/
//-----------------------------------------------------------------//
static void enable(PORT port, bool ena = true) noexcept
{
MPC::PWPR.B0WI = 0; // PWPR 書き込み許可
MPC::PWPR.PFSWE = 1; // PxxPFS 書き込み許可
uint8_t sel = ena ? 0b1'1001 : 0;
switch(port) {
case PORT::TSCAP:
PORTC::PMR.B4 = 0;
MPC::PC4PFS.PSEL = sel;
PORTC::PMR.B4 = ena;
break;
case PORT::TS0:
PORT3::PMR.B4 = 0;
MPC::P34PFS.PSEL = sel;
PORT3::PMR.B4 = ena;
break;
case PORT::TS1:
PORT3::PMR.B3 = 0;
MPC::P33PFS.PSEL = sel;
PORT3::PMR.B3 = ena;
break;
case PORT::TS2:
PORT2::PMR.B7 = 0;
MPC::P27PFS.PSEL = sel;
PORT2::PMR.B7 = ena;
break;
case PORT::TS3:
PORT2::PMR.B6 = 0;
MPC::P26PFS.PSEL = sel;
PORT2::PMR.B6 = ena;
break;
case PORT::TS4:
PORT2::PMR.B5 = 0;
MPC::P25PFS.PSEL = sel;
PORT2::PMR.B5 = ena;
break;
case PORT::TS5:
PORT2::PMR.B4 = 0;
MPC::P24PFS.PSEL = sel;
PORT2::PMR.B4 = ena;
break;
case PORT::TS6:
PORT2::PMR.B3 = 0;
MPC::P23PFS.PSEL = sel;
PORT2::PMR.B3 = ena;
break;
case PORT::TS7:
PORT2::PMR.B2 = 0;
MPC::P22PFS.PSEL = sel;
PORT2::PMR.B2 = ena;
break;
case PORT::TS8:
PORT2::PMR.B1 = 0;
MPC::P21PFS.PSEL = sel;
PORT2::PMR.B1 = ena;
break;
case PORT::TS9:
PORT2::PMR.B0 = 0;
MPC::P20PFS.PSEL = sel;
PORT2::PMR.B0 = ena;
break;
case PORT::TS12:
PORT1::PMR.B5 = 0;
MPC::P15PFS.PSEL = sel;
PORT1::PMR.B5 = ena;
break;
case PORT::TS13:
PORT1::PMR.B4 = 0;
MPC::P14PFS.PSEL = sel;
PORT1::PMR.B4 = ena;
break;
case PORT::TS15: