-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSC16IS7XX.h
1673 lines (1421 loc) · 106 KB
/
SC16IS7XX.h
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
/*!*****************************************************************************
* @file SC16IS7XX.h
* @author Fabien 'Emandhal' MAILLY
* @version 1.0.2
* @date 18/06/2023
* @brief SC16IS740, SC16IS741, SC16IS741A, SC16IS750, SC16IS752, SC16IS760,
* SC16IS762 driver
* @details The SC16IS7XX component is a Single/Double UART with I2C-bus/SPI
* interface, 64 bytes of transmit and receive FIFOs, IrDA SIR built-in support
* Follow datasheet SC16IS740_750_760 Rev.7 ( 9 June 2011)
* SC16IS741_1 Rev.01 (29 April 2010)
* SC16IS741A Rev.1 (18 March 2013)
* SC16IS752_SC16IS762 Rev.9 (22 March 2012)
* Follow AN10571 - Sleep programming for NXP bridge ICs Rev.01 (7 Jan 2007)
* AN10417 - SC16IS760/762 Fast IrDA mode Rev.01 (8 June 2006)
* AN10386 - Baud rate calculation for Philips UARTs Rev.01 (3 August 2005)
******************************************************************************/
/* @page License
*
* Copyright (c) 2020-2023 Fabien MAILLY
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS,
* IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
* EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
/* Revision history:
* 1.0.1 GPIO interface rework
* 1.0.1 I2C interface rework for I2C DMA use and polling
* Add Tx and Rx ring buffers
* 1.0.0 Release version
*****************************************************************************/
#ifndef SC16IS7XX_H_INC
#define SC16IS7XX_H_INC
//=============================================================================
//-----------------------------------------------------------------------------
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
//-----------------------------------------------------------------------------
#if (defined(SC16IS7XX_ONLY_I2C) || !defined(SC16IS7XX_ONLY_SPI)) && !defined(SC16IS7XX_I2C_DEFINED)
# define SC16IS7XX_I2C_DEFINED
#endif
#if (defined(SC16IS7XX_ONLY_SPI) || !defined(SC16IS7XX_ONLY_I2C)) && !defined(SC16IS7XX_SPI_DEFINED)
# define SC16IS7XX_SPI_DEFINED
#endif
//-----------------------------------------------------------------------------
#include "ErrorsDef.h"
#ifdef SC16IS7XX_I2C_DEFINED
# include "I2C_Interface.h"
#endif
#ifdef SC16IS7XX_SPI_DEFINED
# include "SPI_Interface.h"
#endif
#ifdef USE_GENERICS_DEFINED
# include "GPIO_Interface.h"
# include "UART_Interface.h"
#endif
//-----------------------------------------------------------------------------
#ifdef __cplusplus
extern "C" {
# define __SC16IS7XX_PACKED__
# define SC16IS7XX_PACKITEM __pragma(pack(push, 1))
# define SC16IS7XX_UNPACKITEM __pragma(pack(pop))
#else
# define __SC16IS7XX_PACKED__ __attribute__((packed))
# define SC16IS7XX_PACKITEM
# define SC16IS7XX_UNPACKITEM
#endif
//-----------------------------------------------------------------------------
//! This macro is used to check the size of an object. If not, it will raise a "divide by 0" error at compile time
#define SC16IS7XX_CONTROL_ITEM_SIZE(item, size) enum { item##_size_must_be_##size##_bytes = 1 / (int)(!!(sizeof(item) == size)) }
//-----------------------------------------------------------------------------
//********************************************************************************************************************
// SC16IS7XX limits definitions
//********************************************************************************************************************
#define SC16IS7XX_FREQ_MIN ( 1600u ) //! Min Xtal or oscillator frequency
#define SC16IS7XX_XTAL_FREQ_MAX ( 24000000u ) //! Max Xtal frequency
#define SC16IS7XX_OSC_FREQ_MAX ( 80000000u ) //! Max oscillator frequency
#define SC16IS7XX_BAUDRATE_MIN ( 100u ) //! Min Baudrate
#define SC16IS7XX_BAUDRATE_MAX ( 5000000u ) //! Max Baudrate
#define SC16IS7XX_IrDA_SPEED_MAX ( 115200u ) //! Max IrDA baudrate for SC16IS740/741/750/752
#define SC16IS76X_IrDA_SPEED_MAX ( 1152000u ) //! Max IrDA baudrate for SC16IS760/762
#define SC16IS7XX_I2C_CLOCK_MAX ( 400000u ) //! Max I2C clock frequency
#define SC16IS7XX_SPI_CLOCK_MAX ( 4000000u ) //! Max SPI clock frequency for SC16IS740/741/750/752
#define SC16IS76X_SPI_CLOCK_MAX ( 15000000u ) //! Max SPI clock frequency for SC16IS760/762
//-----------------------------------------------------------------------------
//********************************************************************************************************************
// SC16IS7XX device definitions
//********************************************************************************************************************
//! SC16IS7XX I2C address list ('H' => Vdd ; 'L' => Vss/Gnd ; 'C' => SCL ; 'D' => SDA)
#define SC16IS7XX_ADDRESS_A1H_A0H ( 0x90 )
#define SC16IS7XX_ADDRESS_A1H_A0L ( 0x92 )
#define SC16IS7XX_ADDRESS_A1H_A0C ( 0x94 )
#define SC16IS7XX_ADDRESS_A1H_A0D ( 0x96 )
#define SC16IS7XX_ADDRESS_A1L_A0H ( 0x98 )
#define SC16IS7XX_ADDRESS_A1L_A0L ( 0x9A )
#define SC16IS7XX_ADDRESS_A1L_A0C ( 0x9C )
#define SC16IS7XX_ADDRESS_A1L_A0D ( 0x9E )
#define SC16IS7XX_ADDRESS_A1C_A0H ( 0xA0 )
#define SC16IS7XX_ADDRESS_A1C_A0L ( 0xA2 )
#define SC16IS7XX_ADDRESS_A1C_A0C ( 0xA4 )
#define SC16IS7XX_ADDRESS_A1C_A0D ( 0xA6 )
#define SC16IS7XX_ADDRESS_A1D_A0H ( 0xA8 )
#define SC16IS7XX_ADDRESS_A1D_A0L ( 0xAA )
#define SC16IS7XX_ADDRESS_A1D_A0C ( 0xAC )
#define SC16IS7XX_ADDRESS_A1D_A0D ( 0xAE )
//-----------------------------------------------------------------------------
//! SC16IS7XX part number enumerator
typedef enum
{
SC16IS740, //!< SC16IS740 component
SC16IS741, //!< SC16IS741 and SC16IS741A component
SC16IS750, //!< SC16IS750 component
SC16IS752, //!< SC16IS752 component
SC16IS760, //!< SC16IS760 component
SC16IS762, //!< SC16IS762 component
SC16IS7XX_PN_COUNT, // SC16IS7XX device PN count, keep last
} eSC16IS7XX_PN;
//-----------------------------------------------------------------------------
// GPIO pin masks definition
#define SC16IS7XX_GPIO0_MASK ( 1 << 0 ) //! Mask for GPIO0
#define SC16IS7XX_GPIO1_MASK ( 1 << 1 ) //! Mask for GPIO1
#define SC16IS7XX_GPIO2_MASK ( 1 << 2 ) //! Mask for GPIO2
#define SC16IS7XX_GPIO3_MASK ( 1 << 3 ) //! Mask for GPIO3
#define SC16IS7XX_GPIO4_MASK ( 1 << 4 ) //! Mask for GPIO4
#define SC16IS7XX_GPIO5_MASK ( 1 << 5 ) //! Mask for GPIO5
#define SC16IS7XX_GPIO6_MASK ( 1 << 6 ) //! Mask for GPIO6
#define SC16IS7XX_GPIO7_MASK ( 1 << 7 ) //! Mask for GPIO7
//-----------------------------------------------------------------------------
//! Limits which defines devices
typedef struct SC16IS7XX_Limits
{
uint32_t I2C_CLOCK_MAX;
uint32_t SPI_CLOCK_MAX;
bool IrDA_1_4_RATIO;
bool HAVE_GPIO;
bool HAVE_2_UARTS;
} SC16IS7XX_Limits;
//-----------------------------------------------------------------------------
//********************************************************************************************************************
// SC16IS7XX Register list
//********************************************************************************************************************
//! SC16IS7XX registers list
typedef enum
{
// General register set (Accessible only when LCR[7] = 0)
RegSC16IS7XX_RHR = 0x00u, //!< Read mode: Receive Holding Register
RegSC16IS7XX_THR = 0x00u, //!< Write mode: Transmit Holding Register
RegSC16IS7XX_IER = 0x01u, //!< R/W mode: Interrupt Enable Register
RegSC16IS7XX_IIR = 0x02u, //!< Read mode: Interrupt Identification Register
RegSC16IS7XX_FCR = 0x02u, //!< Write mode: FIFO Control Register
RegSC16IS7XX_LCR = 0x03u, //!< R/W mode: Line Control Register
RegSC16IS7XX_MCR = 0x04u, //!< R/W mode: Modem Control Register
RegSC16IS7XX_LSR = 0x05u, //!< Read mode: Line Status Register
RegSC16IS7XX_MSR = 0x06u, //!< Read mode: Modem Status Register
RegSC16IS7XX_SPR = 0x07u, //!< R/W mode: Scratchpad Register
RegSC16IS7XX_TCR = 0x06u, //!< R/W mode: Transmission Control Register (Accessible only when MCR[2]=1 and EFR[4]=1)
RegSC16IS7XX_TLR = 0x07u, //!< R/W mode: Trigger Level Register (Accessible only when MCR[2]=1 and EFR[4]=1)
RegSC16IS7XX_TXLVL = 0x08u, //!< Read mode: Transmit FIFO Level Register
RegSC16IS7XX_RXLVL = 0x09u, //!< Read mode: Receive FIFO Level Register
RegSC16IS7XX_IODir = 0x0Au, //!< R/W mode: I/O pin Direction Register (Only available on the SC16IS75X/SC16IS76X)
RegSC16IS7XX_IOState = 0x0Bu, //!< R/W mode: I/O pin States Register (Only available on the SC16IS75X/SC16IS76X)
RegSC16IS7XX_IOIntEna = 0x0Cu, //!< R/W mode: I/O Interrupt Enable Register (Only available on the SC16IS75X/SC16IS76X)
RegSC16IS7XX_Reserved = 0x0Du, //!< Reserved Register
RegSC16IS7XX_IOControl = 0x0Eu, //!< R/W mode: I/O pins Control Register (Only available on the SC16IS75X/SC16IS76X)
RegSC16IS7XX_EFCR = 0x0Fu, //!< R/W mode: Extra Features Register
// Special register set (Accessible only when LCR[7]=1 and not 0xBF)
RegSC16IS7XX_DLL = 0x00u, //!< R/W mode: Divisor latch LSB
RegSC16IS7XX_DLH = 0x01u, //!< R/W mode: Divisor latch MSB
// Enhanced register set (Accessible when LCR = 0xBF)
RegSC16IS7XX_EFR = 0x02u, //!< R/W mode: Enhanced Feature Register
RegSC16IS7XX_XON1 = 0x04u, //!< R/W mode: Xon1 word
RegSC16IS7XX_XON2 = 0x05u, //!< R/W mode: Xon2 word
RegSC16IS7XX_XOFF1 = 0x06u, //!< R/W mode: Xoff1 word
RegSC16IS7XX_XOFF2 = 0x07u, //!< R/W mode: Xoff2 word
} eSC16IS7XX_Registers;
//! SC16IS7XX registers list
typedef enum
{
SC16IS7XX_LCR_VALUE_SET_SPECIAL_REGISTER = 0x80, //!< Special value of LCR register to access Special Registers (note "The special register set is accessible only when LCR[7] = 1 and not 0xBF" of Table 10 in the datasheet)
SC16IS7XX_LCR_VALUE_SET_ENHANCED_FEATURE_REGISTER = 0xBF, //!< Special value of LCR register to access Special Registers (note "Enhanced Feature Registers are only accessible when LCR = 0xBF" of Table 10 in the datasheet)
SC16IS7XX_LCR_VALUE_SET_GENERAL_REGISTER = ~(0x1u << 7), //!< Special value of LCR[7] register to access General Registers (note "These registers are accessible only when LCR[7] = 0" of Table 10 in the datasheet)
} eSC16IS7XX_AccessTo;
//********************************************************************************************************************
// SC16IS7XX Specific Controller Registers
//********************************************************************************************************************
//! Interrupt Enable Register (Read/Write mode)
SC16IS7XX_PACKITEM
typedef union __SC16IS7XX_PACKED__ SC16IS7XX_IER_Register
{
uint8_t IER;
struct
{
uint8_t RxDataInt : 1; //!< 0 - Receive Holding Register interrupt: '0' => disable the RHR interrupt (normal default condition) ; '1' => enable the RHR interrupt
uint8_t THRemptyInt : 1; //!< 1 - Transmit Holding Register interrupt: '0' => disable the THR interrupt (normal default condition) ; '1' => enable the THR interrupt
uint8_t ReceiveLineInt: 1; //!< 2 - Receive line status interrupt: '0' => disable the receiver line status interrupt (normal default condition) ; '1' => enable the receiver line status interrupt
uint8_t ModemStatInt : 1; //!< 3 - Modem status interrupt: '0' => disable the modem status register interrupt (normal default condition) ; '1' => enable the modem status register interrupt
uint8_t SleepMode : 1; //!< 4 - Sleep mode (This bit in can only be modified if register bit EFR[4] is enabled): '0' => disable Sleep mode (normal default condition) ; '1' => enable Sleep mode
uint8_t Xoff : 1; //!< 5 - Xoff (This bit in can only be modified if register bit EFR[4] is enabled): '0' => disable the Xoff interrupt (normal default condition) ; '1' => enable the Xoff interrupt
uint8_t RTSIntEnable : 1; //!< 6 - RTS interrupt enable (This bit in can only be modified if register bit EFR[4] is enabled): '0' => disable the RTS interrupt (normal default condition) ; '1' => enable the RTS interrupt
uint8_t CTSIntEnable : 1; //!< 7 - CTS interrupt enable (This bit in can only be modified if register bit EFR[4] is enabled): '0' => disable the CTS interrupt (normal default condition) ; '1' => enable the CTS interrupt
} Bits;
} SC16IS7XX_IER_Register;
SC16IS7XX_UNPACKITEM
SC16IS7XX_CONTROL_ITEM_SIZE(SC16IS7XX_IER_Register, 1);
#define SC16IS7XX_IER_RHR_INTERRUPT_ENABLE (0x1u << 0) //!< Enable the Receive Holding Register interrupt
#define SC16IS7XX_IER_RHR_INTERRUPT_DISABLE (0x0u << 0) //!< Disable the Receive Holding Register interrupt
#define SC16IS7XX_IER_THR_INTERRUPT_ENABLE (0x1u << 1) //!< Enable the Transmit Holding Register interrupt
#define SC16IS7XX_IER_THR_INTERRUPT_DISABLE (0x0u << 1) //!< Disable the Transmit Holding Register interrupt
#define SC16IS7XX_IER_RLS_INTERRUPT_ENABLE (0x1u << 2) //!< Enable the Receive Line Status interrupt
#define SC16IS7XX_IER_RLS_INTERRUPT_DISABLE (0x0u << 2) //!< Disable the Receive Line Status interrupt
#define SC16IS7XX_IER_MODEM_STATUS_INTERRUPT_ENABLE (0x1u << 3) //!< Enable the Modem Status interrupt
#define SC16IS7XX_IER_MODEM_STATUS_INTERRUPT_DISABLE (0x0u << 3) //!< Disable the Modem Status interrupt.
#define SC16IS7XX_IER_SLEEP_MODE_ENABLE (0x1u << 4) //!< Enable the Sleep mode
#define SC16IS7XX_IER_SLEEP_MODE_DISABLE (0x0u << 4) //!< Disable the Sleep mode
#define SC16IS7XX_IER_XOFF_INTERRUPT_ENABLE (0x1u << 5) //!< Enable the Xoff interrupt
#define SC16IS7XX_IER_XOFF_INTERRUPT_DISABLE (0x0u << 5) //!< Disable the Xoff interrupt
#define SC16IS7XX_IER_RTS_INTERRUPT_ENABLE (0x1u << 6) //!< Enable the RTS interrupt
#define SC16IS7XX_IER_RTS_INTERRUPT_DISABLE (0x0u << 6) //!< Disable the RTS interrupt
#define SC16IS7XX_IER_CTS_INTERRUPT_ENABLE (0x1u << 7) //!< Enable the CTS interrupt
#define SC16IS7XX_IER_CTS_INTERRUPT_DISABLE (0x0u << 7) //!< Disable the CTS interrupt
#define SC16IS7XX_IER_SLEEP_MODE_Mask (0x1u << 4) //!< Bitmask for Sleep mode
//! Interrupt Events, can be OR'ed.
typedef enum
{
SC16IS7XX_NO_INTERRUPT = 0x00, //!< No interrupt events
SC16IS7XX_RX_FIFO_INTERRUPT = 0x01, //!< Receive Holding Register interrupt event. Set by SC16IS7XX_UARTconfig.RxTrigLvl
SC16IS7XX_TX_FIFO_INTERRUPT = 0x02, //!< Transmit Holding Register interrupt event. Set by SC16IS7XX_UARTconfig.TxTrigLvl
SC16IS7XX_RX_LINE_INTERRUPT = 0x04, //!< Receive Line Status interrupt event. Set when there is an error anywhere in the RX FIFO, and is cleared only when there are no more errors remaining in the FIFO
SC16IS7XX_MODEM_LINE_INTERRUPT = 0x08, //!< Modem Status interrupt event. Change of state of modem input pins
SC16IS7XX_XOFF_INTERRUPT = 0x20, //!< Xoff interrupt event. Set when an Xoff flow character is detected
SC16IS7XX_RTS_INTERRUPT = 0x40, //!< RTS interrupt event. RTS pin change state from active (LOW) to inactive (HIGH)
SC16IS7XX_CTS_INTERRUPT = 0x80, //!< CTS interrupt event. CTS pin change state from active (LOW) to inactive (HIGH)
SC16IS7XX_ENABLE_ALL_INTERRUPTS = 0xEF, //!< Enable all interrupts
SC16IS7XX_INTERRUPTS_FLAGS_MASK = 0xEF, //!< Interrupts flags mask
} eSC16IS7XX_Interrupts;
typedef eSC16IS7XX_Interrupts setSC16IS7XX_Interrupts; //! Set of Interrupt Events (can be OR'ed)
//-----------------------------------------------------------------------------
//! FIFO Control Register (Write mode)
SC16IS7XX_PACKITEM
typedef union __SC16IS7XX_PACKED__ SC16IS7XX_FCR_Register
{
uint8_t FCR;
struct
{
uint8_t FIFOenable : 1; //!< 0 - FIFO enable: '0' => disable the transmit and receive FIFO (normal default condition) ; '1' => enable the transmit and receive FIFO
uint8_t RxFIFOreset: 1; //!< 1 - RX FIFO reset (The user must wait at least 2x Tclk of XTAL1 before reading or writing data to RHR and THR, respectively): '0' => no FIFO receive reset (normal default condition) ; '1' => clears the contents of the receive FIFO and resets the FIFO level logic (the Receive Shift Register is not cleared or altered). This bit will return to a logic 0 after clearing the FIFO
uint8_t TxFIFOreset: 1; //!< 2 - TX FIFO reset (The user must wait at least 2x Tclk of XTAL1 before reading or writing data to RHR and THR, respectively): '0' => no FIFO transmit reset (normal default condition) ; '1' => clears the contents of the transmit FIFO and resets the FIFO level logic (the Transmit Shift Register is not cleared or altered). This bit will return to a logic 0 after clearing the FIFO
uint8_t : 1; //!< 3
uint8_t TxTrigLevel: 2; //!< 4-5 - TX trigger level. Sets the trigger level for the TX FIFO (This bit in can only be modified if register bit EFR[4] is enabled)
uint8_t RxTrigLevel: 2; //!< 6-7 - RX trigger level. Sets the trigger level for the RX FIFO
} Bits;
} SC16IS7XX_FCR_Register;
SC16IS7XX_UNPACKITEM
SC16IS7XX_CONTROL_ITEM_SIZE(SC16IS7XX_FCR_Register, 1);
#define SC16IS7XX_FCR_RX_TX_FIFO_ENABLE (0x1u << 0) //!< Enable the transmit and receive FIFO
#define SC16IS7XX_FCR_RX_TX_FIFO_DISABLE (0x0u << 0) //!< Disable the transmit and receive FIFO
#define SC16IS7XX_FCR_RESET_RX_FIFO (0x1u << 1) //!< Clears the contents of the receive FIFO and resets the FIFO level logic (the Receive Shift Register is not cleared or altered). This bit will return to a logic 0 after clearing the FIFO
#define SC16IS7XX_FCR_RESET_TX_FIFO (0x1u << 2) //!< Clears the contents of the transmit FIFO and resets the FIFO level logic (the Transmit Shift Register is not cleared or altered). This bit will return to a logic 0 after clearing the FIFO
//! Tx interrupt trigger level for the FCR register
typedef enum
{
SC16IS7XX_TX_TRIGGER_LEVEL_08 = 0b00, //!< Tx interrupt trigger level is 8 characters (default)
SC16IS7XX_TX_TRIGGER_LEVEL_16 = 0b01, //!< Tx interrupt trigger level is 16 characters
SC16IS7XX_TX_TRIGGER_LEVEL_32 = 0b10, //!< Tx interrupt trigger level is 32 characters
SC16IS7XX_TX_TRIGGER_LEVEL_56 = 0b11, //!< Tx interrupt trigger level is 56 characters
} eSC16IS7XX_TxTrigLevel;
#define SC16IS7XX_FCR_TX_TRIGGER_LEVEL_Pos 4
#define SC16IS7XX_FCR_TX_TRIGGER_LEVEL_Mask (0x3u << SC16IS7XX_FCR_TX_TRIGGER_LEVEL_Pos)
#define SC16IS7XX_FCR_TX_TRIGGER_LEVEL_SET(value) (((uint8_t)(value) << SC16IS7XX_FCR_TX_TRIGGER_LEVEL_Pos) & SC16IS7XX_FCR_TX_TRIGGER_LEVEL_Mask) //!< Set Tx Interrupt Trigger Level
#define SC16IS7XX_FCR_TX_TRIGGER_LEVEL_GET(value) (((uint8_t)(value) & SC16IS7XX_FCR_TX_TRIGGER_LEVEL_Mask) >> SC16IS7XX_FCR_TX_TRIGGER_LEVEL_Pos) //!< Get Tx Interrupt Trigger Level
//! Rx interrupt trigger level for the FCR register
typedef enum
{
SC16IS7XX_RX_TRIGGER_LEVEL_08 = 0b00, //!< Rx interrupt trigger level is 8 characters (default)
SC16IS7XX_RX_TRIGGER_LEVEL_16 = 0b01, //!< Rx interrupt trigger level is 16 characters
SC16IS7XX_RX_TRIGGER_LEVEL_56 = 0b10, //!< Rx interrupt trigger level is 56 characters
SC16IS7XX_RX_TRIGGER_LEVEL_60 = 0b11, //!< Rx interrupt trigger level is 60 characters
} eSC16IS7XX_RxTrigLevel;
#define SC16IS7XX_FCR_RX_TRIGGER_LEVEL_Pos 6
#define SC16IS7XX_FCR_RX_TRIGGER_LEVEL_Mask (0x3u << SC16IS7XX_FCR_RX_TRIGGER_LEVEL_Pos)
#define SC16IS7XX_FCR_RX_TRIGGER_LEVEL_SET(value) (((uint8_t)(value) << SC16IS7XX_FCR_RX_TRIGGER_LEVEL_Pos) & SC16IS7XX_FCR_RX_TRIGGER_LEVEL_Mask) //!< Set Rx Interrupt Trigger Level
#define SC16IS7XX_FCR_RX_TRIGGER_LEVEL_GET(value) (((uint8_t)(value) & SC16IS7XX_FCR_RX_TRIGGER_LEVEL_Mask) >> SC16IS7XX_FCR_RX_TRIGGER_LEVEL_Pos) //!< Get Rx Interrupt Trigger Level
//-----------------------------------------------------------------------------
//! Interrupt Identification Register (Read mode)
SC16IS7XX_PACKITEM
typedef union __SC16IS7XX_PACKED__ SC16IS7XX_IIR_Register
{
uint8_t IIR;
struct
{
uint8_t IntStatus : 1; //!< 0 - Interrupt status: '0' => an interrupt is pending ; '1' => no interrupt is pending
uint8_t IntIdentify: 5; //!< 1-5 - 5-bit encoded interrupt source
uint8_t FIFOenable1: 1; //!< 6 - FIFO enable ; mirror the contents of FCR[0]
uint8_t FIFOenable2: 1; //!< 7 - FIFO enable ; mirror the contents of FCR[0]
} Bits;
} SC16IS7XX_IIR_Register;
SC16IS7XX_UNPACKITEM
SC16IS7XX_CONTROL_ITEM_SIZE(SC16IS7XX_IIR_Register, 1);
#define SC16IS7XX_IIR_NO_INTERRUPT_PENDING (0x1u << 0) //!< No interrupt is pending
#define SC16IS7XX_IIR_INTERRUPT_PENDING (0x0u << 0) //!< An interrupt is pending
#define SC16IS7XX_IIR_INTERRUPT_PENDING_Mask (0x1u << 0) //!< Interrupt is pending mask
//! 5-bit encoded interrupt source for the IIR register
typedef enum
{
SC16IS7XX_RECEIVER_LINE_STATUS = 0b000110, //!< Receiver Line Status error
SC16IS7XX_RECEIVER_TIMEOUT = 0b001100, //!< Receiver time-out interrupt
SC16IS7XX_RHR_INTERRUPT = 0b000100, //!< RHR interrupt
SC16IS7XX_THR_INTERRUPT = 0b000010, //!< THR interrupt
SC16IS7XX_MODEM_INTERRUPT = 0b000000, //!< Modem interrupt
SC16IS7XX_INPUT_PIN_CHANGE_STATE = 0b110000, //!< Input pin change of state
SC16IS7XX_RECEIVED_XOFF_SIGNAL = 0b010000, //!< Received Xoff signal/special character
SC16IS7XX_CTS_RTS_CHANGE_LOW_TO_HIGH = 0b100000, //!< CTS, RTS change of state from active (LOW) to inactive (HIGH)
} eSC16IS7XX_InterruptSource;
#define SC16IS7XX_IIR_INTERRUT_SOURCE_Pos 0
#define SC16IS7XX_IIR_INTERRUT_SOURCE_Mask (0x3Fu << SC16IS7XX_IIR_INTERRUT_SOURCE_Pos)
#define SC16IS7XX_IIR_INTERRUT_SOURCE_SET(value) (((uint8_t)(value) << SC16IS7XX_IIR_INTERRUT_SOURCE_Pos) & SC16IS7XX_IIR_INTERRUT_SOURCE_Mask) //!< Set interrupt source
#define SC16IS7XX_IIR_INTERRUT_SOURCE_GET(value) (((uint8_t)(value) & SC16IS7XX_IIR_INTERRUT_SOURCE_Mask) >> SC16IS7XX_IIR_INTERRUT_SOURCE_Pos) //!< Get interrupt source
#define SC16IS7XX_IIR_FIFOs_ARE_ENABLE (0x3u << 6) //!< FIFOs (Transmit and receive) are enable ; mirror the contents of FCR[0]
#define SC16IS7XX_IIR_FIFOs_ARE_DISABLE (0x0u << 6) //!< FIFOs (Transmit and receive) are disable ; mirror the contents of FCR[0]
//-----------------------------------------------------------------------------
//! Line Control Register (Read/Write mode)
SC16IS7XX_PACKITEM
typedef union __SC16IS7XX_PACKED__ SC16IS7XX_LCR_Register
{
uint8_t LCR;
struct
{
uint8_t WordLength : 2; //!< 0-1 - Word length bit. These two bits specify the word length to be transmitted or received
uint8_t StopBit : 1; //!< 2 - Number of stop bits. Specifies the number of stop bits: '0' => 1 stop bit ; '1' => if Word Length is 5 bits then it's 1½ stop bit else it's stop bits
uint8_t Parity : 3; //!< 3-5 - Parity enable: '0' => no parity (normal default condition) ; '1' => a parity bit is generated during transmission and the receiver checks for received parity
uint8_t SetBreak : 1; //!< 6 - Break control bit. When enabled, the break control bit causes a break condition to be transmitted (the TX output is forced to a logic 0 state). This condition exists until disabled by setting LCR[6] to a logic 0. '0' => no TX break condition (normal default condition) ; '1' => forces the transmitter output (TX) to a logic 0 to alert the communication terminal to a line break condition
uint8_t DivLatchEna: 1; //!< 7 - Divisor Latch Enable: '0' => divisor latch disabled (normal default condition) ; '1' => divisor latch enabled
} Bits;
} SC16IS7XX_LCR_Register;
SC16IS7XX_UNPACKITEM
SC16IS7XX_CONTROL_ITEM_SIZE(SC16IS7XX_LCR_Register, 1);
//! Data length of the UART configuration for the LCR register
typedef enum
{
SC16IS7XX_DATA_LENGTH_5bits = 0b00, //!< Data length is 5 bits
SC16IS7XX_DATA_LENGTH_6bits = 0b01, //!< Data length is 6 bits
SC16IS7XX_DATA_LENGTH_7bits = 0b10, //!< Data length is 7 bits
SC16IS7XX_DATA_LENGTH_8bits = 0b11, //!< Data length is 8 bits
} eSC16IS7XX_DataLength;
#define SC16IS7XX_LCR_DATA_LENGTH_Pos 0
#define SC16IS7XX_LCR_DATA_LENGTH_Mask (0x3u << SC16IS7XX_LCR_DATA_LENGTH_Pos)
#define SC16IS7XX_LCR_DATA_LENGTH_SET(value) (((uint8_t)(value) << SC16IS7XX_LCR_DATA_LENGTH_Pos) & SC16IS7XX_LCR_DATA_LENGTH_Mask) //!< Set data length
#define SC16IS7XX_LCR_DATA_LENGTH_GET(value) (((uint8_t)(value) & SC16IS7XX_LCR_DATA_LENGTH_Mask) >> SC16IS7XX_LCR_DATA_LENGTH_Pos) //!< Get data length
//! SC16IS740/750/760 UART Stop Bit Length
typedef enum
{
SC16IS7XX_STOP_BIT_1bit, //!< UART stop bit length 1 bit (word length = 5, 6, 7, 8)
SC16IS7XX_STOP_BIT_1bit5, //!< UART stop bit length 1.5 bit (word length = 5)
SC16IS7XX_STOP_BIT_2bits, //!< UART stop bit length 2 bits (word length = 6, 7, 8)
} eSC16IS7XX_StopBit;
#define SC16IS7XX_LCR_EXTENDED_STOP_BIT (0x1u << 2) //!< Set stop bit to 1.5 bit or 2 bits
#define SC16IS7XX_LCR_ONLY_1_STOP_BIT (0x0u << 2) //!< Set stop bit to 1 bit
//! Parity of the UART configuration for the LCR register
typedef enum
{
SC16IS7XX_NO_PARITY = 0b000, //!< No parity
SC16IS7XX_ODD_PARITY = 0b001, //!< Odd parity
SC16IS7XX_EVEN_PARITY = 0b011, //!< Even parity
SC16IS7XX_FORCED_1_PARITY = 0b101, //!< Forced '1' parity
SC16IS7XX_FORCED_0_PARITY = 0b111, //!< Forced '0' parity
} eSC16IS7XX_Parity;
#define SC16IS7XX_LCR_PARITY_Pos 3
#define SC16IS7XX_LCR_PARITY_Mask (0x7u << SC16IS7XX_LCR_PARITY_Pos)
#define SC16IS7XX_LCR_PARITY_SET(value) (((uint8_t)(value) << SC16IS7XX_LCR_PARITY_Pos) & SC16IS7XX_LCR_PARITY_Mask) //!< Set parity
#define SC16IS7XX_LCR_PARITY_GET(value) (((uint8_t)(value) & SC16IS7XX_LCR_PARITY_Mask) >> SC16IS7XX_LCR_PARITY_Pos) //!< Get parity
#define SC16IS7XX_LCR_FORCE_TRANSMITTER_OUTPUT_TO_0 (0x1u << 6) //!< Forces the transmitter output (TX) to a logic 0 to alert the communication terminal to a line break condition
#define SC16IS7XX_LCR_NO_BREAK_CONDITION (0x0u << 6) //!< No TX break condition
#define SC16IS7XX_LCR_DIVISOR_LATCH_ENABLE (0x1u << 7) //!< Enable divisor latch
#define SC16IS7XX_LCR_DIVISOR_LATCH_DISABLE (0x0u << 7) //!< Disable divisor latch
#define SC16IS7XX_LCR_LINE_CONTROL_Mask ( SC16IS7XX_LCR_PARITY_Mask | SC16IS7XX_LCR_EXTENDED_STOP_BIT | SC16IS7XX_LCR_DATA_LENGTH_Mask )
//-----------------------------------------------------------------------------
//! Modem Control Register (Read/Write mode)
SC16IS7XX_PACKITEM
typedef union __SC16IS7XX_PACKED__ SC16IS7XX_MCR_Register
{
uint8_t MCR;
struct
{
uint8_t DTR : 1; //!< 0 - DTR/(IO5) (Only available on the SC16IS75X/76X) ; If GPIO5 is selected as DTR modem pin through IOControl register bit 1, the state of DTR pin can be controlled as follow. Writing to IOState bit 5 will not have any effect on this pin ; '0' => force DTR output to inactive (HIGH) ; '1' => force DTR output to active (LOW)
uint8_t RTS : 1; //!< 1 - RTS: '0' => force RTS output to inactive (HIGH) ; '1' => force RTS output to active (LOW). In Loopback mode, controls MSR[4]. If Auto RTS is enabled, the RTS output is controlled by hardware flow control
uint8_t TCR_TLREnable : 1; //!< 2 - TCR and TLR enable (This bit in can only be modified if register bit EFR[4] is enabled): '0' => disable the TCR and TLR register ; '1' => enable the TCR and TLR register
uint8_t : 1; //!< 3
uint8_t EnableLoopback: 1; //!< 4 - Loopback enable: '0' => normal operating mode ; '1' => enable local Loopback mode (internal). In this mode the MCR[1:0] signals are looped back into MSR[4:5] and the TX output is looped back to the RX input internally
uint8_t XonAny : 1; //!< 5 - Xon Any (This bit in can only be modified if register bit EFR[4] is enabled): '0' => disable Xon Any function ; '1' => enable Xon Any function
uint8_t IrDAModeEnable: 1; //!< 6 - IrDA mode enable (This bit in can only be modified if register bit EFR[4] is enabled): '0' => normal UART mode ; '1' => IrDA mode
uint8_t ClockDivisor : 1; //!< 7 - Clock divisor (This bit in can only be modified if register bit EFR[4] is enabled): '0' => divide-by-1 clock input ; '1' => divide-by-4 clock input
} Bits;
} SC16IS7XX_MCR_Register;
SC16IS7XX_UNPACKITEM
SC16IS7XX_CONTROL_ITEM_SIZE(SC16IS7XX_MCR_Register, 1);
#define SC16IS7XX_MCR_FORCE_DTR_OUTPUT_ACTIVE (0x1u << 0) //!< Force DTR output to active (LOW)
#define SC16IS7XX_MCR_FORCE_DTR_OUTPUT_INACTIVE (0x0u << 0) //!< Force DTR output to inactive (HIGH)
#define SC16IS7XX_MCR_FORCE_RTS_OUTPUT_ACTIVE (0x1u << 1) //!< Force RTS output to active (LOW). In Loopback mode, controls MSR[4]. If Auto-RTS is enabled, the RTS output is controlled by hardware flow control
#define SC16IS7XX_MCR_FORCE_RTS_OUTPUT_INACTIVE (0x0u << 1) //!< Force RTS output to inactive (HIGH)
#define SC16IS7XX_MCR_TCR_AND_TLR_REGISTER_ENABLE (0x1u << 2) //!< Enable the TCR and TLR register
#define SC16IS7XX_MCR_TCR_AND_TLR_REGISTER_DISABLE (0x0u << 2) //!< Disable the TCR and TLR register
#define SC16IS7XX_MCR_LOOPBACK_ENABLE (0x1u << 4) //!< Enable local Loopback mode (internal). In this mode the MCR[1:0] signals are looped back into MSR[4:5] and the TX output is looped back to the RX input internally
#define SC16IS7XX_MCR_LOOPBACK_DISABLE (0x0u << 4) //!< Disable local loopback mode, i.e normal operating mode
#define SC16IS7XX_MCR_XON_ANY_FUNCTION_ENABLE (0x1u << 5) //!< Enable Xon Any function
#define SC16IS7XX_MCR_XON_ANY_FUNCTION_DISABLE (0x0u << 5) //!< Disable Xon Any function
#define SC16IS7XX_MCR_IrDA_MODE (0x1u << 6) //!< IrDA mode enable
#define SC16IS7XX_MCR_NORMAL_UART_MODE (0x0u << 6) //!< Normal UART mode
#define SC16IS7XX_MCR_CLOCK_INPUT_DIVIDE_BY_4 (0x1u << 7) //!< Divide-by-4 clock input
#define SC16IS7XX_MCR_CLOCK_INPUT_DIVIDE_BY_1 (0x0u << 7) //!< Divide-by-1 clock input
#define SC16IS7XX_MCR_TCR_AND_TLR_REGISTER_Mask (0x1u << 2) //!< Bitmask the TCR and TLR register
#define SC16IS7XX_MCR_XON_ANY_FUNCTION_Mask (0x1u << 5) //!< Bitmask the Xon Any function
#define SC16IS7XX_MCR_CLOCK_INPUT_DIVIDE_Mask (0x1u << 7) //!< Bitmask the clock input divide
#define SC16IS7XX_MCR_NORMAL_OPERATING_MODE ( ~(0x1u << 4) ) //!< Bitmask the normal operating mode
#define SC16IS7XX_MCR_IrDA_MODE_Mask (0x1u << 6) //!< Bitmask the IrDA operating mode
//-----------------------------------------------------------------------------
//! Line Status Register (Read mode only)
SC16IS7XX_PACKITEM
typedef union __SC16IS7XX_PACKED__ SC16IS7XX_LSR_Register
{
uint8_t LSR;
struct
{
uint8_t DataIn : 1; //!< 0 - Data in receiver: '0' => no data in receive FIFO (normal default condition) ; '1' => at least one character in the RX FIFO
uint8_t OverrunError : 1; //!< 1 - Overrun error: '0' => no overrun error (normal default condition) ; '1' => overrun error has occurred
uint8_t ParityError : 1; //!< 2 - Parity error: '0' => no parity error (normal default condition) ; '1' => parity error in data being read from RX FIFO
uint8_t FramingError : 1; //!< 3 - Framing error: '0' => no framing error in data being read from RX FIFO (normal default condition) ; '1' => framing error occurred in data being read from RX FIFO, that is, received data did not have a valid stop bit
uint8_t BreakInt : 1; //!< 4 - Break interrupt: '0' => no break condition (normal default condition) ; '1' => a break condition occurred and associated character is 0x00, that is, RX was LOW for one character time frame
uint8_t THRempty : 1; //!< 5 - THR empty: '0' => transmit hold register is not empty ; '1' => transmit hold register is empty. The host can now load up to 64 characters of data into the THR if the TX FIFO is enabled
uint8_t THRandTSRempty: 1; //!< 6 - THR and TSR empty: '0' => transmitter hold and shift registers are not empty ; '1' => transmitter hold and shift registers are empty
uint8_t FifoDataError : 1; //!< 7 - FIFO data error: '0' => no error (normal default condition) ; '1' => at least one parity error, framing error, or break indication is in the receiver FIFO. This bit is cleared when no more errors are present in the FIFO
} Bits;
} SC16IS7XX_LSR_Register;
SC16IS7XX_UNPACKITEM
SC16IS7XX_CONTROL_ITEM_SIZE(SC16IS7XX_LSR_Register, 1);
#define SC16IS7XX_LSR_DATA_IN_RX_FIFO (0x1u << 0) //!< At least one character in the RX FIFO
#define SC16IS7XX_LSR_NO_DATA_IN_RX_FIFO (0x0u << 0) //!< No data in receive FIFO
#define SC16IS7XX_LSR_OVERRUN_ERROR (0x1u << 1) //!< Overrun error has occurred
#define SC16IS7XX_LSR_NO_OVERRUN_ERROR (0x0u << 1) //!< No overrun error
#define SC16IS7XX_LSR_PARITY_ERROR (0x1u << 2) //!< Parity error in data being read from RX FIFO
#define SC16IS7XX_LSR_NO_PARITY_ERROR (0x0u << 2) //!< No parity error
#define SC16IS7XX_LSR_FRAMING_ERROR (0x1u << 3) //!< Framing error occurred in data being read from RX FIFO (received data did not have a valid stop bit)
#define SC16IS7XX_LSR_NO_FRAMING_ERROR (0x0u << 3) //!< No framing error in data being read from RX FIFO
#define SC16IS7XX_LSR_BREAK_CONDITION_OCCUR (0x1u << 4) //!< A break condition occurred and associated character is 0x00 (RX was LOW for one character time frame)
#define SC16IS7XX_LSR_NO_BREAK_CONDITION (0x0u << 4) //!< No break condition
#define SC16IS7XX_LSR_THR_EMPTY (0x1u << 5) //!< Transmit Hold Register is empty. The host can now load up to 64 characters of data into the THR if the TX FIFO is enabled
#define SC16IS7XX_LSR_THR_NOT_EMPTY (0x0u << 5) //!< Transmit Hold Register is not empty
#define SC16IS7XX_LSR_THR_AND_TSR_EMPTY (0x1u << 6) //!< Transmitter hold and shift registers are empty
#define SC16IS7XX_LSR_THR_AND_TSR_NOT_EMPTY (0x0u << 6) //!< Transmitter hold and shift registers are not empty
#define SC16IS7XX_LSR_FIFO_DATA_ERROR (0x1u << 7) //!< At least one parity error, framing error, or break indication is in the receiver FIFO. This bit is cleared when no more errors are present in the FIFO
#define SC16IS7XX_LSR_NO_ERROR (0x0u << 7) //!< No FIFO data error
#define SC16IS7XX_LSR_DATA_RECEIVE_ERROR_Mask ( SC16IS7XX_LSR_FIFO_DATA_ERROR | SC16IS7XX_LSR_BREAK_CONDITION_OCCUR | SC16IS7XX_LSR_FRAMING_ERROR | SC16IS7XX_LSR_PARITY_ERROR | SC16IS7XX_LSR_OVERRUN_ERROR ) //!< At least one parity error, framing error, overrun, or break indication is in the receiver FIFO
#define SC16IS7XX_IS_THR_AND_TSR_EMPTY(value) ( ((value) && SC16IS7XX_LSR_THR_AND_TSR_EMPTY) > 0 ) //! Are the THR and TSR empty?
//! Data receive error enum
typedef enum
{
SC16IS7XX_NO_RX_ERROR = 0x00, //!< No error on the last character received
SC16IS7XX_OVERRUN_ERROR = SC16IS7XX_LSR_OVERRUN_ERROR, //!< Overrun error has occurred
SC16IS7XX_PARITY_ERROR = SC16IS7XX_LSR_PARITY_ERROR, //!< Parity error in data being read from RX FIFO
SC16IS7XX_FRAMING_ERROR = SC16IS7XX_LSR_FRAMING_ERROR, //!< Framing error occurred in data being read from RX FIFO (received data did not have a valid stop bit)
SC16IS7XX_BREAK_ERROR = SC16IS7XX_LSR_BREAK_CONDITION_OCCUR, //!< A break condition occurred and associated character is 0x00 (RX was LOW for one character time frame)
SC16IS7XX_RX_ERROR_Mask = ( SC16IS7XX_LSR_BREAK_CONDITION_OCCUR | SC16IS7XX_LSR_FRAMING_ERROR | SC16IS7XX_LSR_PARITY_ERROR | SC16IS7XX_LSR_OVERRUN_ERROR )
} eSC16IS7XX_ReceiveError;
typedef eSC16IS7XX_ReceiveError setSC16IS7XX_ReceiveError; //! Set of receive errors (can be OR'ed)
//! UART status enum
typedef enum
{
SC16IS7XX_NO_CURRENT_STATUS = 0x00, //!< No current status
SC16IS7XX_DATA_IN_RX_FIFO = SC16IS7XX_LSR_DATA_IN_RX_FIFO, //!< At least one character in the RX FIFO
SC16IS7XX_THR_EMPTY = SC16IS7XX_LSR_THR_EMPTY, //!< Transmit Hold Register is empty. The host can now load up to 64 characters of data into the THR if the TX FIFO is enabled
SC16IS7XX_THR_AND_TSR_EMPTY = SC16IS7XX_LSR_THR_AND_TSR_EMPTY, //!< Transmitter hold and shift registers are empty
SC16IS7XX_FIFO_DATA_ERROR = SC16IS7XX_LSR_FIFO_DATA_ERROR, //!< At least one parity error, framing error, or break indication is in the receiver FIFO. This bit is cleared when no more errors are present in the FIFO
SC16IS7XX_STATUS_Mask = ( SC16IS7XX_FIFO_DATA_ERROR | SC16IS7XX_THR_AND_TSR_EMPTY | SC16IS7XX_THR_EMPTY | SC16IS7XX_DATA_IN_RX_FIFO )
} eSC16IS7XX_Status;
typedef eSC16IS7XX_Status setSC16IS7XX_Status; //! Set of UART status (can be OR'ed)
//-----------------------------------------------------------------------------
//! Modem Status Register (Read mode only)
SC16IS7XX_PACKITEM
typedef union __SC16IS7XX_PACKED__ SC16IS7XX_MSR_Register
{
uint8_t MSR;
struct
{
uint8_t CTSchange : 1; //!< 0 - CTS change ; Indicates that CTS input has changed state. Cleared on a read
uint8_t DSR_IO4change: 1; //!< 1 - DSR/(IO4) change (Only available on the SC16IS75X/76X) ; Indicates that DSR input has changed state. Cleared on a read
uint8_t RI_IO7change : 1; //!< 2 - RI/(IO7) change (Only available on the SC16IS75X/76X) ; Indicates that RI input has changed state from LOW to HIGH. Cleared on a read
uint8_t CD_IO6change : 1; //!< 3 - CD/(IO6) change (Only available on the SC16IS75X/76X) ; Indicates that CD input has changed state. Cleared on a read
uint8_t CTS : 1; //!< 4 - CTS (active HIGH, logical 1). This bit is the complement of the CTS input
uint8_t DSR_IO4 : 1; //!< 5 - DSR/(IO4) (Only available on the SC16IS75X/76X) ; If GPIO4 is selected as DSR modem pin through IOControl register bit 1, the state of DSR pin can be read from this bit. This bit is the complement of the DSR input. Reading IOState bit 4 does not reflect the true state of DSR pin
uint8_t RI_IO7 : 1; //!< 6 - RI/(IO7) (Only available on the SC16IS75X/76X) ; If GPIO7 is selected as RI modem pin through IOControl register bit 1, the state of RI pin can be read from this bit. This bit is the complement of the RI input. Reading IOState bit 6 does not reflect the true state of RI pin
uint8_t CD_IO6 : 1; //!< 7 - CD/(IO6) (Only available on the SC16IS75X/76X) ; If GPIO6 is selected as CD modem pin through IOControl register bit 1, the state of CD pin can be read from this bit. This bit is the complement of the CD input. Reading IOState bit 6 does not reflect the true state of CD pin
} Bits;
} SC16IS7XX_MSR_Register;
SC16IS7XX_UNPACKITEM
SC16IS7XX_CONTROL_ITEM_SIZE(SC16IS7XX_MSR_Register, 1);
#define SC16IS7XX_MSR_CTS_INPUT_CHANGE (0x1u << 0) //!< dCTS. Indicates that CTS input has changed state. Cleared on a read
#define SC16IS7XX_MSR_DSR_INPUT_CHANGE (0x1u << 1) //!< dDSR. Indicates that DSR input has changed state. Cleared on a read
#define SC16IS7XX_MSR_RI_INPUT_CHANGE (0x1u << 2) //!< dRI. Indicates that RI input has changed state from LOW to HIGH. Cleared on a read
#define SC16IS7XX_MSR_CD_INPUT_CHANGE (0x1u << 3) //!< dCD. Indicates that CD input has changed state. Cleared on a read
#define SC16IS7XX_MSR_CTS_PIN_IS_LOW (0x1u << 4) //!< CTS (active HIGH, logical 1). This bit is the complement of the CTS input
#define SC16IS7XX_MSR_CTS_PIN_IS_HIGH (0x0u << 4) //!< CTS (active HIGH, logical 1). This bit is the complement of the CTS input
#define SC16IS7XX_MSR_DSR_PIN_IS_LOW (0x1u << 5) //!< DSR (active HIGH, logical 1). If GPIO4 or GPIO0 is selected as DSR modem pin through IOControl register bit 1 or bit 2, the state of DSR pin can be read from this bit. This bit is the complement of the DSR input. Reading IOState bit 4 or bit 0 does not reflect the true state of DSR pin
#define SC16IS7XX_MSR_DSR_PIN_IS_HIGH (0x0u << 5) //!< DSR (active HIGH, logical 1). If GPIO4 or GPIO0 is selected as DSR modem pin through IOControl register bit 1 or bit 2, the state of DSR pin can be read from this bit. This bit is the complement of the DSR input. Reading IOState bit 4 or bit 0 does not reflect the true state of DSR pin
#define SC16IS7XX_MSR_RI_PIN_IS_LOW (0x1u << 6) //!< RI (active HIGH, logical 1). If GPIO7 or GPIO3 is selected as RI modem pin through IOControl register bit 1 or bit 2, the state of RI pin can be read from this bit. This bit is the complement of the RI input. Reading IOState bit 7 or bit 3 does not reflect the true state of RI pin
#define SC16IS7XX_MSR_RI_PIN_IS_HIGH (0x0u << 6) //!< RI (active HIGH, logical 1). If GPIO7 or GPIO3 is selected as RI modem pin through IOControl register bit 1 or bit 2, the state of RI pin can be read from this bit. This bit is the complement of the RI input. Reading IOState bit 7 or bit 3 does not reflect the true state of RI pin
#define SC16IS7XX_MSR_CD_PIN_IS_LOW (0x1u << 7) //!< CD (active HIGH, logical 1). If GPIO6 or GPIO2 is selected as CD modem pin through IOControl register bit 1 or bit 2, the state of CD pin can be read from this bit. This bit is the complement of the CD input. Reading IOState bit 6 or bit 2 does not reflect the true state of CD pin
#define SC16IS7XX_MSR_CD_PIN_IS_HIGH (0x0u << 7) //!< CD (active HIGH, logical 1). If GPIO6 or GPIO2 is selected as CD modem pin through IOControl register bit 1 or bit 2, the state of CD pin can be read from this bit. This bit is the complement of the CD input. Reading IOState bit 6 or bit 2 does not reflect the true state of CD pin
//-----------------------------------------------------------------------------
/*! Transmission Control Register
* @warning TCR[3:0] > TCR[7:4]. Also, the TCR must be programmed with this condition before auto RTS or software flow control is enabled to avoid spurious operation of the device.
*/
SC16IS7XX_PACKITEM
typedef union __SC16IS7XX_PACKED__ SC16IS7XX_TCR_Register
{
uint8_t TCR;
struct
{
uint8_t RxTrigHaltTx: 4; //!< 0-3 - RX FIFO trigger level to ask peer to halt transmission. Trigger levels is available from 0 to 60 characters with a granularity of four
uint8_t RxTrigResume: 4; //!< 4-7 - RX FIFO trigger level to ask peer to resume transmission. Trigger levels is available from 0 to 60 characters with a granularity of four
} Bits;
} SC16IS7XX_TCR_Register;
SC16IS7XX_UNPACKITEM
SC16IS7XX_CONTROL_ITEM_SIZE(SC16IS7XX_TCR_Register, 1);
//! Trigger level to ask peer to resume/hold transmission
typedef enum
{
SC16IS7XX_RESUME_WHEN_RX_FIFO_AT_0_CHAR , //!< Ask peer to resume/hold transmission when there is 0 char in the RX FIFO
SC16IS7XX_RESUME_WHEN_RX_FIFO_AT_4_CHAR , //!< Ask peer to resume/hold transmission when there are 4 chars in the RX FIFO
SC16IS7XX_RESUME_WHEN_RX_FIFO_AT_8_CHAR , //!< Ask peer to resume/hold transmission when there are 8 chars in the RX FIFO
SC16IS7XX_RESUME_WHEN_RX_FIFO_AT_12_CHAR, //!< Ask peer to resume/hold transmission when there are 12 chars in the RX FIFO
SC16IS7XX_RESUME_WHEN_RX_FIFO_AT_16_CHAR, //!< Ask peer to resume/hold transmission when there are 16 chars in the RX FIFO
SC16IS7XX_RESUME_WHEN_RX_FIFO_AT_20_CHAR, //!< Ask peer to resume/hold transmission when there are 20 chars in the RX FIFO
SC16IS7XX_RESUME_WHEN_RX_FIFO_AT_24_CHAR, //!< Ask peer to resume/hold transmission when there are 24 chars in the RX FIFO
SC16IS7XX_RESUME_WHEN_RX_FIFO_AT_28_CHAR, //!< Ask peer to resume/hold transmission when there are 28 chars in the RX FIFO
SC16IS7XX_RESUME_WHEN_RX_FIFO_AT_32_CHAR, //!< Ask peer to resume/hold transmission when there are 32 chars in the RX FIFO
SC16IS7XX_RESUME_WHEN_RX_FIFO_AT_36_CHAR, //!< Ask peer to resume/hold transmission when there are 36 chars in the RX FIFO
SC16IS7XX_RESUME_WHEN_RX_FIFO_AT_40_CHAR, //!< Ask peer to resume/hold transmission when there are 40 chars in the RX FIFO
SC16IS7XX_RESUME_WHEN_RX_FIFO_AT_44_CHAR, //!< Ask peer to resume/hold transmission when there are 44 chars in the RX FIFO
SC16IS7XX_RESUME_WHEN_RX_FIFO_AT_48_CHAR, //!< Ask peer to resume/hold transmission when there are 48 chars in the RX FIFO
SC16IS7XX_RESUME_WHEN_RX_FIFO_AT_52_CHAR, //!< Ask peer to resume/hold transmission when there are 52 chars in the RX FIFO
SC16IS7XX_RESUME_WHEN_RX_FIFO_AT_56_CHAR, //!< Ask peer to resume/hold transmission when there are 56 chars in the RX FIFO
SC16IS7XX_RESUME_WHEN_RX_FIFO_AT_60_CHAR, //!< Ask peer to resume/hold transmission when there are 60 chars in the RX FIFO
} eSC16IS7XX_TriggerCtrlLevel;
#define SC16IS7XX_TCR_HALT_TRIGGER_LEVEL_Pos 0
#define SC16IS7XX_TCR_HALT_TRIGGER_LEVEL_Mask (0xFu << SC16IS7XX_TCR_HALT_TRIGGER_LEVEL_Pos)
#define SC16IS7XX_TCR_HALT_TRIGGER_LEVEL_SET(value) (((uint8_t)(value) << SC16IS7XX_TCR_HALT_TRIGGER_LEVEL_Pos) & SC16IS7XX_TCR_HALT_TRIGGER_LEVEL_Mask) //!< Set RX FIFO trigger level to halt transmission
#define SC16IS7XX_TCR_HALT_TRIGGER_LEVEL_GET(value) (((uint8_t)(value) & SC16IS7XX_TCR_HALT_TRIGGER_LEVEL_Mask) >> SC16IS7XX_TCR_HALT_TRIGGER_LEVEL_Pos) //!< Get RX FIFO trigger level to halt transmission
#define SC16IS7XX_TCR_RESUME_TRIGGER_LEVEL_Pos 4
#define SC16IS7XX_TCR_RESUME_TRIGGER_LEVEL_Mask (0xFu << SC16IS7XX_TCR_RESUME_TRIGGER_LEVEL_Pos)
#define SC16IS7XX_TCR_RESUME_TRIGGER_LEVEL_SET(value) (((uint8_t)(value) << SC16IS7XX_TCR_RESUME_TRIGGER_LEVEL_Pos) & SC16IS7XX_TCR_RESUME_TRIGGER_LEVEL_Mask) //!< Set RX FIFO trigger level to resume
#define SC16IS7XX_TCR_RESUME_TRIGGER_LEVEL_GET(value) (((uint8_t)(value) & SC16IS7XX_TCR_RESUME_TRIGGER_LEVEL_Mask) >> SC16IS7XX_TCR_RESUME_TRIGGER_LEVEL_Pos) //!< Get RX FIFO trigger level to resume
#define SC16IS7XX_TCR_HALT_TRIGGER_LEVEL_CHAR_COUNT_DIV4_SET(value) ( (uint8_t)(value) >> 2 ) //! Calc RX FIFO trigger level to ask peer to halt transmission. Trigger levels is available from 0 to 60 characters with a granularity of four
#define SC16IS7XX_TCR_RESUME_TRIGGER_LEVEL_CHAR_COUNT_DIV4_SET(value) ( (uint8_t)(value) >> 2 ) //! Calc RX FIFO trigger level to ask peer to resume transmission. Trigger levels is available from 0 to 60 characters with a granularity of four
//-----------------------------------------------------------------------------
//! Trigger Level Register
SC16IS7XX_PACKITEM
typedef union __SC16IS7XX_PACKED__ SC16IS7XX_TLR_Register
{
uint8_t TLR;
struct
{
uint8_t TxFIFOlevelTrig: 4; //!< 0-3 - TX FIFO trigger levels (4 to 60), number of spaces available
uint8_t RxFIFOlevelTrig: 4; //!< 4-7 - RX FIFO trigger levels (4 to 60), number of characters available
} Bits;
} SC16IS7XX_TLR_Register;
SC16IS7XX_UNPACKITEM
SC16IS7XX_CONTROL_ITEM_SIZE(SC16IS7XX_TLR_Register, 1);
//! Tx FIFO Trigger level of characters available for interrupt
typedef enum
{
SC16IS7XX_TX_FIFO_TRIGGER_AT_4_CHAR_SPACE = 1, //!< TX FIFO trigger at a level of 4 characters spaces available
SC16IS7XX_TX_FIFO_TRIGGER_AT_8_CHAR_SPACE = 2, //!< TX FIFO trigger at a level of 8 characters spaces available
SC16IS7XX_TX_FIFO_TRIGGER_AT_12_CHAR_SPACE = 3, //!< TX FIFO trigger at a level of 12 characters spaces available
SC16IS7XX_TX_FIFO_TRIGGER_AT_16_CHAR_SPACE = 4, //!< TX FIFO trigger at a level of 16 characters spaces available
SC16IS7XX_TX_FIFO_TRIGGER_AT_20_CHAR_SPACE = 5, //!< TX FIFO trigger at a level of 20 characters spaces available
SC16IS7XX_TX_FIFO_TRIGGER_AT_24_CHAR_SPACE = 6, //!< TX FIFO trigger at a level of 24 characters spaces available
SC16IS7XX_TX_FIFO_TRIGGER_AT_28_CHAR_SPACE = 7, //!< TX FIFO trigger at a level of 28 characters spaces available
SC16IS7XX_TX_FIFO_TRIGGER_AT_32_CHAR_SPACE = 8, //!< TX FIFO trigger at a level of 32 characters spaces available
SC16IS7XX_TX_FIFO_TRIGGER_AT_36_CHAR_SPACE = 9, //!< TX FIFO trigger at a level of 36 characters spaces available
SC16IS7XX_TX_FIFO_TRIGGER_AT_40_CHAR_SPACE = 10, //!< TX FIFO trigger at a level of 40 characters spaces available
SC16IS7XX_TX_FIFO_TRIGGER_AT_44_CHAR_SPACE = 11, //!< TX FIFO trigger at a level of 44 characters spaces available
SC16IS7XX_TX_FIFO_TRIGGER_AT_48_CHAR_SPACE = 12, //!< TX FIFO trigger at a level of 48 characters spaces available
SC16IS7XX_TX_FIFO_TRIGGER_AT_52_CHAR_SPACE = 13, //!< TX FIFO trigger at a level of 52 characters spaces available
SC16IS7XX_TX_FIFO_TRIGGER_AT_56_CHAR_SPACE = 14, //!< TX FIFO trigger at a level of 56 characters spaces available
SC16IS7XX_TX_FIFO_TRIGGER_AT_60_CHAR_SPACE = 15, //!< TX FIFO trigger at a level of 60 characters spaces available
} eSC16IS7XX_IntTxTriggerLevel;
//! Rx FIFO Trigger level of characters available for interrupt
typedef enum
{
SC16IS7XX_RX_FIFO_TRIGGER_AT_4_CHAR_AVAILABLE = 1, //!< RX FIFO trigger at a level of 4 characters available
SC16IS7XX_RX_FIFO_TRIGGER_AT_8_CHAR_AVAILABLE = 2, //!< RX FIFO trigger at a level of 8 characters available
SC16IS7XX_RX_FIFO_TRIGGER_AT_12_CHAR_AVAILABLE = 3, //!< RX FIFO trigger at a level of 12 characters available
SC16IS7XX_RX_FIFO_TRIGGER_AT_16_CHAR_AVAILABLE = 4, //!< RX FIFO trigger at a level of 16 characters available
SC16IS7XX_RX_FIFO_TRIGGER_AT_20_CHAR_AVAILABLE = 5, //!< RX FIFO trigger at a level of 20 characters available
SC16IS7XX_RX_FIFO_TRIGGER_AT_24_CHAR_AVAILABLE = 6, //!< RX FIFO trigger at a level of 24 characters available
SC16IS7XX_RX_FIFO_TRIGGER_AT_28_CHAR_AVAILABLE = 7, //!< RX FIFO trigger at a level of 28 characters available
SC16IS7XX_RX_FIFO_TRIGGER_AT_32_CHAR_AVAILABLE = 8, //!< RX FIFO trigger at a level of 32 characters available
SC16IS7XX_RX_FIFO_TRIGGER_AT_36_CHAR_AVAILABLE = 9, //!< RX FIFO trigger at a level of 36 characters available
SC16IS7XX_RX_FIFO_TRIGGER_AT_40_CHAR_AVAILABLE = 10, //!< RX FIFO trigger at a level of 40 characters available
SC16IS7XX_RX_FIFO_TRIGGER_AT_44_CHAR_AVAILABLE = 11, //!< RX FIFO trigger at a level of 44 characters available
SC16IS7XX_RX_FIFO_TRIGGER_AT_48_CHAR_AVAILABLE = 12, //!< RX FIFO trigger at a level of 48 characters available
SC16IS7XX_RX_FIFO_TRIGGER_AT_52_CHAR_AVAILABLE = 13, //!< RX FIFO trigger at a level of 52 characters available
SC16IS7XX_RX_FIFO_TRIGGER_AT_56_CHAR_AVAILABLE = 14, //!< RX FIFO trigger at a level of 56 characters available
SC16IS7XX_RX_FIFO_TRIGGER_AT_60_CHAR_AVAILABLE = 15, //!< RX FIFO trigger at a level of 60 characters available
} eSC16IS7XX_IntRxTriggerLevel;
#define SC16IS7XX_TLR_TX_FIFO_TRIGGER_LEVEL_Pos 0
#define SC16IS7XX_TLR_TX_FIFO_TRIGGER_LEVEL_Mask (0xFu << SC16IS7XX_TLR_TX_FIFO_TRIGGER_LEVEL_Pos)
#define SC16IS7XX_TLR_TX_FIFO_TRIGGER_LEVEL_SET(value) (((uint8_t)(value) << SC16IS7XX_TLR_TX_FIFO_TRIGGER_LEVEL_Pos) & SC16IS7XX_TLR_TX_FIFO_TRIGGER_LEVEL_Mask) //!< Set TX FIFO trigger levels (4 to 60), number of spaces available
#define SC16IS7XX_TLR_TX_FIFO_TRIGGER_LEVEL_GET(value) (eSC16IS7XX_IntTxTriggerLevel)(((uint8_t)(value) & SC16IS7XX_TLR_TX_FIFO_TRIGGER_LEVEL_Mask) >> SC16IS7XX_TLR_TX_FIFO_TRIGGER_LEVEL_Pos) //!< Get TX FIFO trigger levels (4 to 60), number of spaces available
#define SC16IS7XX_TLR_RX_FIFO_TRIGGER_LEVEL_Pos 4
#define SC16IS7XX_TLR_RX_FIFO_TRIGGER_LEVEL_Mask (0xFu << SC16IS7XX_TLR_RX_FIFO_TRIGGER_LEVEL_Pos)
#define SC16IS7XX_TLR_RX_FIFO_TRIGGER_LEVEL_SET(value) (((uint8_t)(value) << SC16IS7XX_TLR_RX_FIFO_TRIGGER_LEVEL_Pos) & SC16IS7XX_TLR_RX_FIFO_TRIGGER_LEVEL_Mask) //!< Set RX FIFO trigger levels (4 to 60), number of characters available
#define SC16IS7XX_TLR_RX_FIFO_TRIGGER_LEVEL_GET(value) (eSC16IS7XX_IntRxTriggerLevel)(((uint8_t)(value) & SC16IS7XX_TLR_RX_FIFO_TRIGGER_LEVEL_Mask) >> SC16IS7XX_TLR_RX_FIFO_TRIGGER_LEVEL_Pos) //!< Get RX FIFO trigger levels (4 to 60), number of characters available
//-----------------------------------------------------------------------------
//! I/O pins Control Register (Only available on the SC16IS75X/SC16IS76X)
SC16IS7XX_PACKITEM
typedef union __SC16IS7XX_PACKED__ SC16IS7XX_IOControl_Register
{
uint8_t IOControl;
struct
{
uint8_t Latch : 1; //!< 0 - Latch: '0' => input values are not latched ; '1' => input values are latched
uint8_t IOorModemUARTA: 1; //!< 1 - I/O[7:4] or RI, CD, DTR, DSR of UARTA: '0' => GPIO[7:4] behave as I/O pins ; '1' => GPIO[7:4] behave as RI, CD, DTR, DSR (Only available on the SC16IS75X/76X)
uint8_t IOorModemUARTB: 1; //!< 2 - I/O[3:0] or RI, CD, DTR, DSR of UARTB: '0' => GPIO[3:0] behave as I/O pins ; '1' => GPIO[3:0] behave as RI, CD, DTR, DSR (Only available on the SC16IS752/762)
uint8_t UARTSoftReset : 1; //!< 3 - UART software reset (Device returns NACK on I2C-bus when this bit is written) ; A write to bit will reset the device. Once the device is reset this bit is automatically set to ‘0’
uint8_t : 4; //!< 4-7
} Bits;
} SC16IS7XX_IOControl_Register;
SC16IS7XX_UNPACKITEM
SC16IS7XX_CONTROL_ITEM_SIZE(SC16IS7XX_IOControl_Register, 1);
#define SC16IS7XX_IOCTRL_LATCH_INPUT_VALUES_ENABLE (0x1u << 0) //!< Input values are latched. A change in the input generates an interrupt and the input logic value is loaded in the bit of the corresponding input state register (IOState). A read of the IOState register clears the interrupt. If the input pin goes back to its initial logic state before the interrupt register is read, then the interrupt is not cleared and the corresponding bit of the IOState register keeps the logic value that initiates the interrupt
#define SC16IS7XX_IOCTRL_LATCH_INPUT_VALUES_DISABLE (0x0u << 0) //!< Input value are not latched. A change in any input generates an interrupt. A read of the input register clears the interrupt. If the input goes back to its initial logic state before the input register is read, then the interrupt is cleared
#define SC16IS7XX_IOCTRL_GPIO7_4_AS_MODEM (0x1u << 1) //!< GPIO[7:4] behave as RIA, CDA, DTRA, DSRA
#define SC16IS7XX_IOCTRL_GPIO7_4_AS_IO (0x0u << 1) //!< GPIO[7:4] behave as I/O pins
#define SC16IS7XX_IOCTRL_GPIO3_0_AS_MODEM (0x1u << 2) //!< GPIO[3:0] behave as RIB, CDB, DTRB, DSRB
#define SC16IS7XX_IOCTRL_GPIO3_0_AS_IO (0x0u << 2) //!< GPIO[3:0] behave as I/O pins
#define SC16IS7XX_IOCTRL_SOFTWARE_RESET (0x1u << 3) //!< Software Reset. A write to this bit will reset the device. Once the device is reset this bit is automatically set to logic 0
#define SC16IS7XX_IOCTRL_UARTA_MODEM_MODE_Mask ( SC16IS7XX_IOCTRL_GPIO7_4_AS_MODEM ) //!< Bitmask for the UARTA modem mode
#define SC16IS7XX_IOCTRL_UARTB_MODEM_MODE_Mask ( SC16IS7XX_IOCTRL_GPIO3_0_AS_MODEM ) //!< Bitmask for the UARTB modem mode
//-----------------------------------------------------------------------------
//! Extra Features Register (Read/Write mode)
SC16IS7XX_PACKITEM
typedef union __SC16IS7XX_PACKED__ SC16IS7XX_EFCR_Register
{
uint8_t EFCR;
struct
{
uint8_t Mode9bitEnable : 1; //!< 0 - Enable 9-bit or Multidrop mode (RS-485): '0' => normal RS-232 mode ; '1' => enables RS-485 mode
uint8_t ReceiverDisable : 1; //!< 1 - Receiver disable: '0' => receiver is enabled ; '1' => receiver is disabled
uint8_t TransmitterDisable: 1; //!< 2 - Transmitter disable: '0' => transmitter is enabled ; '1' => transmitter is disabled
uint8_t : 1; //!< 3
uint8_t AutoRS485RTSdir : 1; //!< 4 - Auto RS-485 RTS direction control: '0' => transmitter does not control RTS pin ; '1' => transmitter controls RTS pin
uint8_t AutoRS485RTSinv : 1; //!< 5 - Auto RS-485 RTS output inversion: '0' => RTS = 0 during transmission and RTS = 1 during reception ; '1' => RTS = 1 during transmission and RTS = 0 during reception
uint8_t : 1; //!< 6
uint8_t IrDAmode : 1; //!< 7 - IrDA mode (slow/fast) (IrDA mode slow/fast for SC16IS76X, slow only for SC16IS75X): '0' => IrDA SIR, 3/16 pulse ratio, data rate up to 115.2 kbit/s ; '1' => IrDA SIR, 1/4 pulse ratio, data rate up to 1.152 Mbit/s
} Bits;
} SC16IS7XX_EFCR_Register;
SC16IS7XX_UNPACKITEM
SC16IS7XX_CONTROL_ITEM_SIZE(SC16IS7XX_EFCR_Register, 1);
#define SC16IS7XX_EFCR_9BIT_MODE_ENABLE (0x1u << 0) //!< Enable 9-bit or Multidrop mode (RS-485)
#define SC16IS7XX_EFCR_9BIT_MODE_DISABLE (0x0u << 0) //!< Disable 9-bit or Multidrop mode (RS-485)
#define SC16IS7XX_EFCR_RX_DISABLE (0x1u << 1) //!< Receiver is disabled
#define SC16IS7XX_EFCR_RX_ENABLE (0x0u << 1) //!< Receiver is enabled
#define SC16IS7XX_EFCR_TX_DISABLE (0x1u << 2) //!< Transmitter is disabled
#define SC16IS7XX_EFCR_TX_ENABLE (0x0u << 2) //!< Transmitter is enabled
#define SC16IS7XX_EFCR_TX_CONTROL_RTS (0x1u << 4) //!< Transmitter controls RTS pin
#define SC16IS7XX_EFCR_TX_NOT_CONTROL_RTS (0x0u << 4) //!< Transmitter does not control RTS pin
#define SC16IS7XX_EFCR_INVERT_RTS_PIN (0x1u << 5) //!< RTS = 1 during transmission and RTS = 0 during reception
#define SC16IS7XX_EFCR_NORMAL_RTS_PIN (0x0u << 5) //!< RTS = 0 during transmission and RTS = 1 during reception
#define SC16IS7XX_EFCR_IrDA_1_4_PULSE_RATIO (0x1u << 7) //!< IrDA SIR, 1⁄4 pulse ratio, data rate up to 1.152 Mbit/s
#define SC16IS7XX_EFCR_IrDA_3_16_PULSE_RATIO (0x0u << 7) //!< IrDA SIR, 3⁄16 pulse ratio, data rate up to 115.2 kbit/s
#define SC16IS7XX_EFCR_TX_RX_DISABLE_Mask ( (0x1u << 2) | (0x1u << 1) ) //!< Bitmask for the transmitter/receiver disable
#define SC16IS7XX_EFCR_LINE_CONTROL_MODE_Mask ( SC16IS7XX_EFCR_9BIT_MODE_ENABLE | SC16IS7XX_EFCR_TX_CONTROL_RTS | SC16IS7XX_EFCR_INVERT_RTS_PIN | SC16IS7XX_EFCR_IrDA_1_4_PULSE_RATIO ) //!< Bitmask for the line control mode
//-----------------------------------------------------------------------------
//! Enhanced Feature Register (Read/Write mode)
SC16IS7XX_PACKITEM
typedef union __SC16IS7XX_PACKED__ SC16IS7XX_EFR_Register
{
uint8_t EFR;
struct
{
uint8_t SoftFlowCtrl : 4; //!< 0-3 - Software flow transmitter and receiver control bits
uint8_t EnaEnhancedFunc: 1; //!< 4 - Enable enhanced functions: '0' => disables enhanced functions and writing to IER[7:4], FCR[5:4], MCR[7:5] ; '1' => enables the enhanced function IER[7:4], FCR[5:4], and MCR[7:5] so that they can be modified
uint8_t SpecialCharDet : 1; //!< 5 - Special character detect: '0' => Special character detect disabled (normal default condition) ; '1' => Special character detect enabled. Received data is compared with Xoff2 data. If a match occurs, the received data is transferred to FIFO and IIR[4] is set to a logical 1 to indicate a special character has been detected
uint8_t AutoRTS : 1; //!< 6 - Auto RTS: '0' => RTS flow control is disabled (normal default condition) ; '1' => RTS flow control is enabled. The RTS pin goes HIGH when the receiver FIFO halt trigger level TCR[3:0] is reached, and goes LOW when the receiver FIFO resume transmission trigger level TCR[7:4] is reached
uint8_t AutoCTS : 1; //!< 7 - Auto CTS: '0' => CTS flow control is disabled (normal default condition) ; '1' => CTS flow control is enabled. Transmission will stop when a HIGH signal is detected on the CTS pin
} Bits;
} SC16IS7XX_EFR_Register;
SC16IS7XX_UNPACKITEM
SC16IS7XX_CONTROL_ITEM_SIZE(SC16IS7XX_EFR_Register, 1);
//! Software flow transmitter and receiver control configuration for the EFR register
typedef enum
{
SC16IS7XX_NoTxCtrlFlow_NoRxCtrlFlow = 0b0000, //!< No transmit flow control, No receive flow control
SC16IS7XX_NoTxCtrlFlow_RxXon1Xoff1 = 0b0001, //!< No transmit flow control, Receiver compares Xon1 + Xoff1
SC16IS7XX_NoTxCtrlFlow_RxXon2Xoff2 = 0b0010, //!< No transmit flow control, Receiver compares Xon2 + Xoff2
SC16IS7XX_NoTxCtrlFlow_RxXon1and2Xoff1and2 = 0b0011, //!< No transmit flow control, Receiver compares Xon1 and Xon2 + Xoff1 and Xoff2
SC16IS7XX_TxXon1Xoff1_NoRxCtrlFlow = 0b0100, //!< Transmit Xon1 + Xoff1, No receive flow control
SC16IS7XX_TxXon1Xoff1_RxXon1Xoff1 = 0b0101, //!< Transmit Xon1 + Xoff1, Receiver compares Xon1 + Xoff1
SC16IS7XX_TxXon1Xoff1_RxXon2Xoff2 = 0b0110, //!< Transmit Xon1 + Xoff1, Receiver compares Xon2 + Xoff2
SC16IS7XX_TxXon1Xoff1_RxXon1or2Xoff1or2 = 0b0111, //!< Transmit Xon1 + Xoff1, Receiver compares Xon1 or Xon2 + Xoff1 or Xoff2
SC16IS7XX_TxXon2Xoff2_NoRxCtrlFlow = 0b1000, //!< Transmit Xon2 + Xoff2, No receive flow control
SC16IS7XX_TxXon2Xoff2_RxXon1Xoff1 = 0b1001, //!< Transmit Xon2 + Xoff2, Receiver compares Xon1 + Xoff1
SC16IS7XX_TxXon2Xoff2_RxXon2Xoff2 = 0b1010, //!< Transmit Xon2 + Xoff2, Receiver compares Xon2 + Xoff2
SC16IS7XX_TxXon2Xoff2_RxXon1or2Xoff1or2 = 0b1011, //!< Transmit Xon2 + Xoff2, Receiver compares Xon1 or Xon2 + Xoff1 or Xoff2
SC16IS7XX_TxXon1and2Xoff1and2_NoRxCtrlFlow = 0b1100, //!< Transmit Xon1 and Xon2 + Xoff1 and Xoff2, No receive flow control
SC16IS7XX_TxXon1and2Xoff1and2_RxXon1Xoff1 = 0b1101, //!< Transmit Xon1 and Xon2 + Xoff1 and Xoff2, Receiver compares Xon1 + Xoff1
SC16IS7XX_TxXon1and2Xoff1and2_RxXon2Xoff2 = 0b1110, //!< Transmit Xon1 and Xon2 + Xoff1 and Xoff2, Receiver compares Xon2 + Xoff2
SC16IS7XX_TxXon1and2Xoff1and2_RxXon1and2Xoff1and2 = 0b1111, //!< Transmit Xon1 and Xon2 + Xoff1 and Xoff2, Receiver compares Xon1 and Xon2 + Xoff1 and Xoff2
} eSC16IS7XX_SoftFlowCtrl;
#define SC16IS7XX_EFR_SOFT_FLOW_CONTROL_Pos 0
#define SC16IS7XX_EFR_SOFT_FLOW_CONTROL_Mask (0xFu << SC16IS7XX_EFR_SOFT_FLOW_CONTROL_Pos)
#define SC16IS7XX_EFR_SOFT_FLOW_CONTROL_SET(value) (((uint8_t)(value) << SC16IS7XX_EFR_SOFT_FLOW_CONTROL_Pos) & SC16IS7XX_EFR_SOFT_FLOW_CONTROL_Mask) //!< Set Software flow transmitter and receiver control configuration
#define SC16IS7XX_EFR_SOFT_FLOW_CONTROL_GET(value) (((uint8_t)(value) & SC16IS7XX_EFR_SOFT_FLOW_CONTROL_Mask) >> SC16IS7XX_EFR_SOFT_FLOW_CONTROL_Pos) //!< Get Software flow transmitter and receiver control configuration
#define SC16IS7XX_EFR_ENHANCED_FUNCTION_ENABLE (0x1u << 4) //!< Enables the enhanced function IER[7:4], FCR[5:4], and MCR[7:5] so that they can be modified
#define SC16IS7XX_EFR_ENHANCED_FUNCTION_DISABLE (0x0u << 4) //!< Disables enhanced functions and writing to IER[7:4], FCR[5:4], MCR[7:5]
#define SC16IS7XX_EFR_SPECIAL_CHAR_DETECT_ENABLE (0x1u << 5) //!< Special character detect enabled. Received data is compared with Xoff2 data. If a match occurs, the received data is transferred to FIFO and IIR[4] is set to a logical 1 to indicate a special character has been detected
#define SC16IS7XX_EFR_SPECIAL_CHAR_DETECT_DISABLE (0x0u << 5) //!< Special character detect disabled
#define SC16IS7XX_EFR_RTS_FLOW_CONTROL_ENABLE (0x1u << 6) //!< RTS flow control is enabled. The RTS pin goes HIGH when the receiver FIFO halt trigger level TCR[3:0] is reached, and goes LOW when the receiver FIFO resume transmission trigger level TCR[7:4] is reached
#define SC16IS7XX_EFR_RTS_FLOW_CONTROL_DISABLE (0x0u << 6) //!< RTS flow control is disabled
#define SC16IS7XX_EFR_CTS_FLOW_CONTROL_ENABLE (0x1u << 7) //!< CTS flow control is enabled. Transmission will stop when a HIGH signal is detected on the CTS pin
#define SC16IS7XX_EFR_CTS_FLOW_CONTROL_DISABLE (0x0u << 7) //!< CTS flow control is disabled
#define SC16IS7XX_IS_SOFT_CONTROL_FLOW_USES_XOFF2(value) ( (((uint8_t)(value) & 0x02) > 0) || (((uint8_t)(value) & 0x08) > 0) ) //!< Is the software control flow uses Xoff2 char?
#define SC16IS7XX_EFR_ENHANCED_FUNCTION_Mask (0x1u << 4) //!< Bitmask for the enhanced function
#define SC16IS7XX_EFR_SPECIAL_CHAR_DETECT_Mask (0x1u << 5) //!< Bitmask for the special character detect
//********************************************************************************************************************
//! SPI byte command (Read/Write mode)
SC16IS7XX_PACKITEM
typedef union __SC16IS7XX_PACKED__ SC16IS7XX_SPIcommand
{
uint8_t SPIdata;
struct
{
uint8_t : 1; //!< 0
uint8_t CH1CH0 : 2; //!< 1-2 - Channel select: '00' => channel A ; '01' => channel B ; '1x' => reserved
uint8_t Address : 4; //!< 3-6 - UART’s internal register select
uint8_t ReadWrite: 1; //!< 7 - Read/Write: '0' => write to Device ; '1' => read from Device
} Bits;
} SC16IS7XX_SPIcommand;
SC16IS7XX_UNPACKITEM
SC16IS7XX_CONTROL_ITEM_SIZE(SC16IS7XX_SPIcommand, 1);
#define SC16IS7XX_SPI_READ (0x1u << 7) //!< Set the SPI read
#define SC16IS7XX_SPI_WRITE (0x0u << 7) //!< Set the SPI write
//! I2C byte command
SC16IS7XX_PACKITEM
typedef union __SC16IS7XX_PACKED__ SC16IS7XX_I2Ccommand
{
uint8_t I2Cdata;
struct
{
uint8_t : 1; //!< 0
uint8_t CH1CH0 : 2; //!< 1-2 - Channel select: '00' => channel A ; '01' => channel B ; '1x' => reserved
uint8_t Address: 4; //!< 3-6 - UART’s internal register select
uint8_t : 1; //!< 7
} Bits;
} SC16IS7XX_I2Ccommand;
SC16IS7XX_UNPACKITEM
SC16IS7XX_CONTROL_ITEM_SIZE(SC16IS7XX_I2Ccommand, 1);
#define SC16IS7XX_CHANNEL_Pos 1
#define SC16IS7XX_CHANNEL_Mask (0x3u << SC16IS7XX_CHANNEL_Pos)
#define SC16IS7XX_CHANNEL_SET(value) (((uint8_t)(value) << SC16IS7XX_CHANNEL_Pos) & SC16IS7XX_CHANNEL_Mask) //!< Set Channels bits
#define SC16IS7XX_CHANNEL_GET(value) ((eSC16IS7XX_Channels)(((value) & SC16IS7XX_CHANNEL_Mask) >> SC16IS7XX_CHANNEL_Pos)) //!< Get Channels bits
#define SC16IS7XX_ADDRESS_Pos 3
#define SC16IS7XX_ADDRESS_Mask (0xFu << SC16IS7XX_ADDRESS_Pos)
#define SC16IS7XX_ADDRESS_SET(value) (((uint8_t)(value) << SC16IS7XX_ADDRESS_Pos) & SC16IS7XX_ADDRESS_Mask) //!< Set Address bits
#define SC16IS7XX_ADDRESS_GET(value) (((value) & SC16IS7XX_ADDRESS_Mask) >> SC16IS7XX_ADDRESS_Pos) //!< Get Address bits
//-----------------------------------------------------------------------------
//! Interface select
typedef enum
{
SC16IS7XX_INTERFACE_SPI, //!< Select Interface SPI
SC16IS7XX_INTERFACE_I2C, //!< Select Interface I2C
} eSC16IS7XX_Interface;
//! Channel select
typedef enum
{
SC16IS7XX_NO_CHANNEL = 0, //!< Select no specific channel
SC16IS7XX_CHANNEL_A = 0, //!< Select channel A
SC16IS7XX_CHANNEL_B = 1, //!< Select channel B
SC16IS7XX_CHANNEL_COUNT , // Keep last
} eSC16IS7XX_Channel;
//-----------------------------------------------------------------------------
//********************************************************************************************************************
// SC16IS7XX Driver API
//********************************************************************************************************************
typedef struct SC16IS7XX SC16IS7XX; //! SC16IS7XX component object structure
//-----------------------------------------------------------------------------
//! SC16IS7XX device object structure
struct SC16IS7XX
{
//--- Device configuration ---
void *UserDriverData; //!< Optional, can be used to store driver data or NULL
uint32_t XtalFreq; //!< Component Xtal frequency (maximum 80MHz). Set it to 0 if oscillator is used
uint32_t OscFreq; //!< Component oscillator frequency (maximum 24MHz). Set it to 0 if crystal is used
eSC16IS7XX_PN DevicePN; //!< Part number of the device
//--- Interface driver call functions ---
eSC16IS7XX_Interface Interface; //!< Interface to use with this device
union
{
#ifdef SC16IS7XX_I2C_DEFINED
struct
{
uint8_t I2Caddress; //!< Address I2C of the device (0x90 to 0xAE). Use defines SC16IS7XX_ADDRESS_A1x_A0x
# ifdef USE_DYNAMIC_INTERFACE
I2C_Interface* I2C; //!< This is the I2C_Interface descriptor pointer that will be used to communicate with the device
# else
I2C_Interface I2C; //!< This is the I2C_Interface descriptor that will be used to communicate with the device
# endif
};
#endif
#ifdef SC16IS7XX_SPI_DEFINED
struct
{
uint8_t SPIchipSelect; //!< This is the Chip Select index that will be set at the call of a transfer
# ifdef USE_DYNAMIC_INTERFACE
SPI_Interface* SPI; //!< This is the SPI_Interface descriptor pointer that will be used to communicate with the device
# else
SPI_Interface SPI; //!< This is the SPI_Interface descriptor that will be used to communicate with the device
# endif
};
#endif
};
uint32_t InterfaceClockSpeed; //!< SPI/I2C clock speed in Hertz
//--- GPIO configuration ---
uint8_t GPIOsOutDir; //!< GPIOs pins direction (0 = set to output ; 1 = set to input). Used to speed up direction change
uint8_t GPIOsOutLevel; //!< GPIOs pins output level (0 = set to '0' ; 1 = set to '1'). Used to speed up output change
};
//! This unique ID is a helper for pointer recognition when using USE_GENERICS_DEFINED for generic call of GPIO or PORT use (using GPIO_Interface.h)
#define SC16IS7XX_UNIQUE_ID ( (((uint32_t)'S' << 0) ^ ((uint32_t)'C' << 3) ^ ((uint32_t)'1' << 6) ^ ((uint32_t)'6' << 9) ^ ((uint32_t)'I' << 12) ^ ((uint32_t)'S' << 15) ^ ((uint32_t)'7' << 18) ^ ((uint32_t)'X' << 21) ^ ((uint32_t)'X' << 23)) + __LINE__ + (sizeof(struct SC16IS7XX) << 19) )
//-----------------------------------------------------------------------------
//! SC16IS7XX device configuration structure
typedef struct SC16IS7XX_Config
{
//--- GPIOs configuration ---
uint8_t StartupPinsDirection; //!< Startup GPIOs direction (0 = output ; 1 = input)
uint8_t StartupPinsLevel; //!< Startup GPIOs output level (0 = set to '0' ; 1 = set to '1')
uint8_t PinsInterruptEnable; //!< GPIOs individual Interrupt (0 = disable ; 1 = enable)
} SC16IS7XX_Config;
//-----------------------------------------------------------------------------
/*! @brief SC16IS7XX initialization
*
* This function initializes the SC16IS7XX driver, call the initialization of the interface driver, and soft reset the device. It also checks the hardware communication with the device
* @param[in] *pComp Is the pointed structure of the device to be initialized
* @param[in] *pConf Is the pointed structure of the device configuration. This is mainly the GPIOs startup configuration. This parameter can be NULL if the configuration of GPIO is not helpful
* @return Returns an #eERRORRESULT value enum
*/
eERRORRESULT Init_SC16IS7XX(SC16IS7XX *pComp, const SC16IS7XX_Config *pConf);
/*! @brief Perform a Software Reset the SC16IS7XX
*
* @param[in] *pComp Is the pointed structure of the device to reset
* @return Returns an #eERRORRESULT value enum
*/
eERRORRESULT SC16IS7XX_SoftResetDevice(SC16IS7XX *pComp);
/*! @brief Hardware communication tests of the SC16IS7XX
*
* @param[in] *pComp Is the pointed structure of the device to test
* @return Returns an #eERRORRESULT value enum
*/