-
Notifications
You must be signed in to change notification settings - Fork 4
/
IOSTM.cpp
828 lines (640 loc) · 21.3 KB
/
IOSTM.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
// SPDX-License-Identifier: GPL-2.0-only
/*
* Digital Voice Modem - Hotspot Firmware
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2020 Jonathan Naylor, G4KLX
* Copyright (C) 2016 Jim McLaughlin, KI6ZUM
* Copyright (C) 2016,2017,2018,2019,2020 Andy Uribe, CA6JAU
* Copyright (C) 2017 Danilo, DB4PLE
* Copyright (C) 2021,2024 Bryan Biedenkapp, N2PLL
*
*/
#include "Globals.h"
#include "IO.h"
// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
#if defined(STM32F10X_MD)
/**
* The STM32 factory-programmed UUID memory.
* Three values of 32 bits each starting at this address
* Use like this: STM32_UUID[0], STM32_UUID[1], STM32_UUID[2]
*/
#define STM32_UUID ((uint32_t *)0x1FFFF7E8)
#if defined(PI_HAT_7021_REV_02)
#define PIN_SCLK GPIO_Pin_4
#define PORT_SCLK GPIOB
#define PIN_SREAD GPIO_Pin_5
#define PORT_SREAD GPIOB
#define PIN_SDATA GPIO_Pin_6
#define PORT_SDATA GPIOB
#define PIN_SLE GPIO_Pin_7
#define PORT_SLE GPIOB
#define PIN_CE GPIO_Pin_14
#define PORT_CE GPIOC
#define PIN_RXD GPIO_Pin_3
#define PORT_RXD GPIOB
// TXD used in SPI Data mode of ADF7021
// TXD is TxRxCLK of ADF7021, standard TX/RX data interface
#define PIN_TXD GPIO_Pin_15
#define PORT_TXD GPIOA
#define PIN_TXD_INT GPIO_PinSource15
#define PORT_TXD_INT GPIO_PortSourceGPIOA
// CLKOUT used in SPI Data mode of ADF7021
#define PIN_CLKOUT GPIO_Pin_14
#define PORT_CLKOUT GPIOA
#define PIN_CLKOUT_INT GPIO_PinSource14
#define PORT_CLKOUT_INT GPIO_PortSourceGPIOA
#define PIN_LED GPIO_Pin_13
#define PORT_LED GPIOC
#define PIN_DEB GPIO_Pin_11
#define PORT_DEB GPIOA
#define PIN_NXDN_LED GPIO_Pin_8
#define PORT_NXDN_LED GPIOA
#define PIN_DMR_LED GPIO_Pin_15
#define PORT_DMR_LED GPIOB
#define PIN_P25_LED GPIO_Pin_12
#define PORT_P25_LED GPIOA
#define PIN_PTT_LED GPIO_Pin_12
#define PORT_PTT_LED GPIOB
#define PIN_COS_LED GPIO_Pin_13
#define PORT_COS_LED GPIOB
#elif defined(ZUMSPOT_ADF7021) || defined(SKYBRIDGE_HS)
#define PIN_SCLK GPIO_Pin_5
#define PORT_SCLK GPIOB
#define PIN_SREAD GPIO_Pin_6
#define PORT_SREAD GPIOB
#define PIN_SDATA GPIO_Pin_7
#define PORT_SDATA GPIOB
#define PIN_SLE GPIO_Pin_8
#define PORT_SLE GPIOB
#define PIN_SLE2 GPIO_Pin_6
#define PORT_SLE2 GPIOA
#define PIN_CE GPIO_Pin_14
#define PORT_CE GPIOC
#define PIN_RXD GPIO_Pin_4
#define PORT_RXD GPIOB
#define PIN_SGL_DBL GPIO_Pin_12
#define PORT_SGL_DBL GPIOA
#define PIN_DL_DPX GPIO_Pin_15
#define PORT_DL_DPX GPIOC
#define PIN_SET_BAND GPIO_Pin_15
#define PORT_SET_BAND GPIOA
// TXD used in SPI Data mode of ADF7021
// TXD is TxRxCLK of ADF7021, standard TX/RX data interface
#define PIN_TXD GPIO_Pin_3
#define PORT_TXD GPIOB
#define PIN_TXD_INT GPIO_PinSource3
#define PORT_TXD_INT GPIO_PortSourceGPIOB
#if defined(DUPLEX)
#define PIN_RXD2 GPIO_Pin_11
#define PORT_RXD2 GPIOA
// TXD2 is TxRxCLK of the second ADF7021, standard TX/RX data interface
#define PIN_TXD2 GPIO_Pin_8
#define PORT_TXD2 GPIOA
#define PIN_TXD2_INT GPIO_PinSource8
#define PORT_TXD2_INT GPIO_PortSourceGPIOA
#endif
// CLKOUT used in SPI Data mode of ADF7021
#define PIN_CLKOUT GPIO_Pin_15
#define PORT_CLKOUT GPIOA
#define PIN_CLKOUT_INT GPIO_PinSource15
#define PORT_CLKOUT_INT GPIO_PortSourceGPIOA
#define PIN_LED GPIO_Pin_13
#define PORT_LED GPIOC
#define PIN_DEB GPIO_Pin_9
#define PORT_DEB GPIOB
#define PIN_NXDN_LED GPIO_Pin_7
#define PORT_NXDN_LED GPIOA
#define PIN_DMR_LED GPIO_Pin_13
#define PORT_DMR_LED GPIOB
#define PIN_P25_LED GPIO_Pin_0
#define PORT_P25_LED GPIOB
#define PIN_PTT_LED GPIO_Pin_14
#define PORT_PTT_LED GPIOB
#define PIN_COS_LED GPIO_Pin_15
#define PORT_COS_LED GPIOB
#elif defined(MMDVM_HS_HAT_REV12) || defined(MMDVM_HS_DUAL_HAT_REV10) || defined(NANO_HOTSPOT) || defined(NANO_DV_REV11)
#define PIN_SCLK GPIO_Pin_5
#define PORT_SCLK GPIOB
#define PIN_SREAD GPIO_Pin_7
#define PORT_SREAD GPIOB
#define PIN_SDATA GPIO_Pin_6
#define PORT_SDATA GPIOB
#define PIN_SLE GPIO_Pin_8
#define PORT_SLE GPIOB
#define PIN_SLE2 GPIO_Pin_6
#define PORT_SLE2 GPIOA
#define PIN_CE GPIO_Pin_14
#define PORT_CE GPIOC
#define PIN_RXD GPIO_Pin_4
#define PORT_RXD GPIOB
#define PIN_RXD2 GPIO_Pin_4
#define PORT_RXD2 GPIOA
// TXD used in SPI Data mode of ADF7021
// TXD is TxRxCLK of ADF7021, standard TX/RX data interface
#define PIN_TXD GPIO_Pin_3
#define PORT_TXD GPIOB
#define PIN_TXD_INT GPIO_PinSource3
#define PORT_TXD_INT GPIO_PortSourceGPIOB
// TXD2 is TxRxCLK of the second ADF7021, standard TX/RX data interface
#define PIN_TXD2 GPIO_Pin_5
#define PORT_TXD2 GPIOA
#define PIN_TXD2_INT GPIO_PinSource5
#define PORT_TXD2_INT GPIO_PortSourceGPIOA
// CLKOUT used in SPI Data mode of ADF7021
#define PIN_CLKOUT GPIO_Pin_15
#define PORT_CLKOUT GPIOA
#define PIN_CLKOUT_INT GPIO_PinSource15
#define PORT_CLKOUT_INT GPIO_PortSourceGPIOA
#define PIN_LED GPIO_Pin_13
#define PORT_LED GPIOC
#define PIN_DEB GPIO_Pin_9
#define PORT_DEB GPIOB
#define PIN_NXDN_LED GPIO_Pin_8
#define PORT_NXDN_LED GPIOA
#define PIN_DMR_LED GPIO_Pin_13
#define PORT_DMR_LED GPIOB
#define PIN_P25_LED GPIO_Pin_0
#define PORT_P25_LED GPIOB
#define PIN_PTT_LED GPIO_Pin_14
#define PORT_PTT_LED GPIOB
#define PIN_COS_LED GPIO_Pin_15
#define PORT_COS_LED GPIOB
#else
#error "Either PI_HAT_7021_REV_02, ZUMSPOT_ADF7021, MMDVM_HS_HAT_REV12, MMDVM_HS_DUAL_HAT_REV10, NANO_HOTSPOT, NANO_DV_REV11, or SKYBRIDGE_HS need to be defined"
#endif
// ---------------------------------------------------------------------------
// Global Functions
// ---------------------------------------------------------------------------
extern "C" {
#if defined(PI_HAT_7021_REV_02)
#if defined(BIDIR_DATA_PIN)
void EXTI15_10_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line15) != RESET) {
io.interrupt1();
EXTI_ClearITPendingBit(EXTI_Line15);
}
}
#else
void EXTI15_10_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line14) != RESET) {
io.interrupt1();
EXTI_ClearITPendingBit(EXTI_Line14);
}
}
#endif // BIDIR_DATA_PIN
#elif defined(ZUMSPOT_ADF7021) || defined(LIBRE_KIT_ADF7021) || defined(MMDVM_HS_HAT_REV12) || defined(MMDVM_HS_DUAL_HAT_REV10) || defined(NANO_HOTSPOT) || defined(NANO_DV_REV11) || defined(D2RG_MMDVM_HS) || defined(SKYBRIDGE_HS)
#if defined(BIDIR_DATA_PIN)
void EXTI3_IRQHandler(void) {
if (EXTI_GetITStatus(EXTI_Line3) != RESET) {
io.interrupt1();
EXTI_ClearITPendingBit(EXTI_Line3);
}
}
#else
void EXTI15_10_IRQHandler(void) {
if (EXTI_GetITStatus(EXTI_Line15) != RESET) {
io.interrupt1();
EXTI_ClearITPendingBit(EXTI_Line15);
}
}
#endif // BIDIR_DATA_PIN
#if defined(DUPLEX)
void EXTI9_5_IRQHandler(void) {
#if defined(ZUMSPOT_ADF7021) || defined(SKYBRIDGE_HS)
if (EXTI_GetITStatus(EXTI_Line8) != RESET) {
io.interrupt2();
EXTI_ClearITPendingBit(EXTI_Line8);
}
#else
if (EXTI_GetITStatus(EXTI_Line5) != RESET) {
io.interrupt2();
EXTI_ClearITPendingBit(EXTI_Line5);
}
#endif // ZUMSPOT_ADF7021 || SKYBRIDGE_HS
}
#endif
#endif
}
/* Function delay_us() from stm32duino project */
static inline void delay_us(uint32_t us)
{
us *= 12;
/* fudge for function call overhead */
us--;
asm volatile(
" mov r0, %[us] \n\t"
"1: subs r0, #1 \n\t"
" bhi 1b \n\t"
:
: [us] "r" (us)
: "r0");
}
/* */
static inline void delay_ns()
{
asm volatile(
"nop \n\t"
"nop \n\t"
"nop \n\t"
);
}
// ---------------------------------------------------------------------------
// Public Class Members
// ---------------------------------------------------------------------------
/* Gets the CPU type the firmware is running on. */
uint8_t IO::getCPU() const
{
return CPU_TYPE_STM32;
}
/* Gets the unique identifier for the air interface. */
void IO::getUDID(uint8_t* buffer)
{
::memcpy(buffer, (void*)STM32_UUID, 12U);
}
/* */
void IO::resetMCU()
{
DEBUG1("reset - bye-bye");
delayUS(250 * 1000);
setLEDInt(false);
setCOSInt(false);
setDMRInt(false);
setP25Int(false);
setNXDNInt(false);
delayUS(250 * 1000);
NVIC_SystemReset();
}
/* */
void IO::delayBit()
{
delay_ns();
}
#if defined(ZUMSPOT_ADF7021) || defined(SKYBRIDGE_HS)
/* */
bool IO::isDualBand()
{
return GPIO_ReadInputDataBit(PORT_DL_DPX, PIN_DL_DPX) == Bit_SET;
}
#endif
/* */
void IO::SCLK(bool on)
{
GPIO_WriteBit(PORT_SCLK, PIN_SCLK, on ? Bit_SET : Bit_RESET);
}
/* */
void IO::SDATA(bool on)
{
GPIO_WriteBit(PORT_SDATA, PIN_SDATA, on ? Bit_SET : Bit_RESET);
}
/* */
bool IO::SREAD()
{
return GPIO_ReadInputDataBit(PORT_SREAD, PIN_SREAD) == Bit_SET;
}
/* */
void IO::SLE1(bool on)
{
GPIO_WriteBit(PORT_SLE, PIN_SLE, on ? Bit_SET : Bit_RESET);
}
#if defined(DUPLEX)
/* */
void IO::SLE2(bool on)
{
GPIO_WriteBit(PORT_SLE2, PIN_SLE2, on ? Bit_SET : Bit_RESET);
}
/* */
bool IO::RXD2()
{
return GPIO_ReadInputDataBit(PORT_RXD2, PIN_RXD2) == Bit_SET;
}
#endif
/* */
void IO::CE(bool on)
{
GPIO_WriteBit(PORT_CE, PIN_CE, on ? Bit_SET : Bit_RESET);
}
/* */
bool IO::RXD1()
{
return GPIO_ReadInputDataBit(PORT_RXD, PIN_RXD) == Bit_SET;
}
/* */
bool IO::CLK()
{
#if defined(BIDIR_DATA_PIN)
return GPIO_ReadInputDataBit(PORT_TXD, PIN_TXD) == Bit_SET;
#else
return GPIO_ReadInputDataBit(PORT_CLKOUT, PIN_CLKOUT) == Bit_SET;
#endif
}
// ---------------------------------------------------------------------------
// Private Class Members
// ---------------------------------------------------------------------------
#if defined(ZUMSPOT_ADF7021) || defined(SKYBRIDGE_HS)
/* */
void IO::setBandVHF(bool enable)
{
GPIO_WriteBit(PORT_SET_BAND, PIN_SET_BAND, enable ? Bit_SET : Bit_RESET);
}
/* */
bool IO::hasSingleADF7021()
{
return GPIO_ReadInputDataBit(PORT_SGL_DBL, PIN_SGL_DBL) == Bit_SET;
}
#endif
/* */
void IO::delayIfCal()
{
delayUS(10000);
}
/* */
void IO::delayReset()
{
delayUS(300);
}
/* */
void IO::delayUS(uint32_t us)
{
::delay_us(us);
}
/* Initializes hardware interrupts. */
void IO::initInt()
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_StructInit(&GPIO_InitStruct);
EXTI_InitTypeDef EXTI_InitStructure;
#if defined(DUPLEX)
EXTI_InitTypeDef EXTI_InitStructure2;
#endif
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
#if defined(PI_HAT_7021_REV_02)
GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
#elif defined(ZUMSPOT_ADF7021) || defined(LIBRE_KIT_ADF7021) || defined(MMDVM_HS_HAT_REV12) || defined(MMDVM_HS_DUAL_HAT_REV10) || defined(NANO_HOTSPOT) || defined(NANO_DV_REV11) || defined(D2RG_MMDVM_HS) || defined(SKYBRIDGE_HS)
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
#endif
#if defined(ZUMSPOT_ADF7021) || defined(SKYBRIDGE_HS)
// Pin defines if the board has a single ADF7021 or double
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_SGL_DBL;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(PORT_SGL_DBL, &GPIO_InitStruct);
// Pin defines if the board is dual band or duplex
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_DL_DPX;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(PORT_DL_DPX, &GPIO_InitStruct);
// Pin will set UHF or VHF
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_SET_BAND;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_SET_BAND, &GPIO_InitStruct);
// TODO: Remove this line
// GPIO_WriteBit(PORT_SET_BAND, PIN_SET_BAND, Bit_RESET);
#endif
volatile unsigned int delay;
for (delay = 0; delay < 512; delay++);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStruct);
RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
// Pin SCLK
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_SCLK;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_SCLK, &GPIO_InitStruct);
// Pin SDATA
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_SDATA;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_SDATA, &GPIO_InitStruct);
// Pin SREAD
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_SREAD;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(PORT_SREAD, &GPIO_InitStruct);
// Pin SLE
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_SLE;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_SLE, &GPIO_InitStruct);
#if defined(DUPLEX)
// Pin SLE2
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_SLE2;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_SLE2, &GPIO_InitStruct);
// Pin RXD2
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_RXD2;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(PORT_RXD2, &GPIO_InitStruct);
#endif
// Pin CE
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_CE;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_CE, &GPIO_InitStruct);
// Pin RXD
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_RXD;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(PORT_RXD, &GPIO_InitStruct);
// Pin TXD
// TXD is TxRxCLK of ADF7021, standard TX/RX data interface
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_TXD;
#if defined(BIDIR_DATA_PIN)
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
#else
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
#endif
GPIO_Init(PORT_TXD, &GPIO_InitStruct);
#if defined(DUPLEX)
GPIO_InitStruct.GPIO_Pin = PIN_TXD2;
GPIO_Init(PORT_TXD2, &GPIO_InitStruct);
#endif
// Pin TXRX_CLK
#if !defined(BIDIR_DATA_PIN)
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_CLKOUT;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(PORT_CLKOUT, &GPIO_InitStruct);
#endif
// Pin LED
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_LED;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_LED, &GPIO_InitStruct);
// Pin Debug
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_DEB;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_DEB, &GPIO_InitStruct);
// NXDN LED
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_NXDN_LED;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_NXDN_LED, &GPIO_InitStruct);
// DMR LED
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_DMR_LED;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_DMR_LED, &GPIO_InitStruct);
// P25 LED
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_P25_LED;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_P25_LED, &GPIO_InitStruct);
// PTT LED
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_PTT_LED;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_PTT_LED, &GPIO_InitStruct);
// COS LED
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_COS_LED;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PORT_COS_LED, &GPIO_InitStruct);
#if defined(PI_HAT_7021_REV_02)
#if defined(BIDIR_DATA_PIN)
// Connect EXTI15 Line
GPIO_EXTILineConfig(PORT_TXD_INT, PIN_TXD_INT);
// Configure EXTI15 line
EXTI_InitStructure.EXTI_Line = EXTI_Line15;
#else
// Connect EXTI14 Line
GPIO_EXTILineConfig(PORT_CLKOUT_INT, PIN_CLKOUT_INT);
// Configure EXTI14 line
EXTI_InitStructure.EXTI_Line = EXTI_Line14;
#endif
#elif defined(ZUMSPOT_ADF7021) || defined(LIBRE_KIT_ADF7021) || defined(MMDVM_HS_HAT_REV12) || defined(MMDVM_HS_DUAL_HAT_REV10) || defined(NANO_HOTSPOT) || defined(NANO_DV_REV11) || defined(D2RG_MMDVM_HS) || defined(SKYBRIDGE_HS)
#if defined(BIDIR_DATA_PIN)
// Connect EXTI3 Line
GPIO_EXTILineConfig(PORT_TXD_INT, PIN_TXD_INT);
// Configure EXTI3 line
EXTI_InitStructure.EXTI_Line = EXTI_Line3;
#else
// Connect EXTI15 Line
GPIO_EXTILineConfig(PORT_CLKOUT_INT, PIN_CLKOUT_INT);
// Configure EXTI15 line
EXTI_InitStructure.EXTI_Line = EXTI_Line15;
#endif
#if defined(DUPLEX)
// Connect EXTI5 Line
GPIO_EXTILineConfig(PORT_TXD2_INT, PIN_TXD2_INT);
// Configure EXT5 line
#if defined(ZUMSPOT_ADF7021) || defined(SKYBRIDGE_HS)
EXTI_InitStructure2.EXTI_Line = EXTI_Line8;
#else
EXTI_InitStructure2.EXTI_Line = EXTI_Line5;
#endif
#endif
#endif
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
#if defined(DUPLEX)
EXTI_InitStructure2.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure2.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure2.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure2);
#endif
}
/* Starts hardware interrupts. */
void IO::startInt()
{
NVIC_InitTypeDef NVIC_InitStructure;
#if defined(DUPLEX)
NVIC_InitTypeDef NVIC_InitStructure2;
#endif
#if defined(PI_HAT_7021_REV_02)
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
#elif defined(ZUMSPOT_ADF7021) || defined(LIBRE_KIT_ADF7021) || defined(MMDVM_HS_HAT_REV12) || defined(MMDVM_HS_DUAL_HAT_REV10) || defined(NANO_HOTSPOT) || defined(NANO_DV_REV11) || defined(D2RG_MMDVM_HS) || defined(SKYBRIDGE_HS)
#if defined(BIDIR_DATA_PIN)
// Enable and set EXTI3 Interrupt
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;
#else
// Enable and set EXTI15 Interrupt
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
#endif
#if defined(DUPLEX)
NVIC_InitStructure2.NVIC_IRQChannel = EXTI9_5_IRQn;
#endif
#endif
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 15;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
#if defined(DUPLEX)
NVIC_InitStructure2.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure2.NVIC_IRQChannelSubPriority = 15;
NVIC_InitStructure2.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure2);
#endif
}
#if defined(BIDIR_DATA_PIN)
/* */
void IO::setDataDirOut(bool dir)
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = PIN_RXD;
if (dir)
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
else
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(PORT_RXD, &GPIO_InitStruct);
}
#endif
#if defined(BIDIR_DATA_PIN)
/* */
void IO::setRXDInt(bool on)
{
GPIO_WriteBit(PORT_RXD, PIN_RXD, on ? Bit_SET : Bit_RESET);
}
#endif
/* */
void IO::setTXDInt(bool on)
{
GPIO_WriteBit(PORT_TXD, PIN_TXD, on ? Bit_SET : Bit_RESET);
}
/* */
void IO::setLEDInt(bool on)
{
GPIO_WriteBit(PORT_LED, PIN_LED, on ? Bit_SET : Bit_RESET);
}
/* */
void IO::setPTTInt(bool on)
{
GPIO_WriteBit(PORT_PTT_LED, PIN_PTT_LED, on ? Bit_SET : Bit_RESET);
}
/* */
void IO::setCOSInt(bool on)
{
GPIO_WriteBit(PORT_COS_LED, PIN_COS_LED, on ? Bit_SET : Bit_RESET);
}
/* */
void IO::setDMRInt(bool on)
{
GPIO_WriteBit(PORT_DMR_LED, PIN_DMR_LED, on ? Bit_SET : Bit_RESET);
}
/* */
void IO::setP25Int(bool on)
{
GPIO_WriteBit(PORT_P25_LED, PIN_P25_LED, on ? Bit_SET : Bit_RESET);
}
/* */
void IO::setNXDNInt(bool on)
{
GPIO_WriteBit(PORT_NXDN_LED, PIN_NXDN_LED, on ? Bit_SET : Bit_RESET);
}
#endif // STM32F10X_MD