bargraph4  2.0.0.0
spi_specifics.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2021 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
27 #ifndef _SPI_SPECIFICS_
28 #define _SPI_SPECIFICS_
29 
30 #ifdef __cplusplus
31 extern "C"{
32 #endif
33 
34 #include "mcu_definitions.h"
35 
36 // mikroE toolchain specific
37 #if defined(__MIKROC_AI_FOR_PIC__) || defined (__MIKROC_AI_FOR_DSPIC__) || \
38  defined(__MIKROC_AI_FOR_PIC32__)
39 
40 #ifdef __MIKROC_AI_FOR_PIC__
41  #define BIT_INDEX 7
42 #elif defined(__MIKROC_AI_FOR_PIC32__)
43  #define BIT_INDEX 9
44 #endif
45 
46 #ifdef SAMPLE_REG_CASE_1
47  #ifdef __MIKROC_AI_FOR_PIC32__
48  #define SAMPLE_REG_ADDRESS(index) HAL_LL_SPI ## index ## CON_ADDRESS
49  #else
50  #define SAMPLE_REG_ADDRESS(index) HAL_LL_SPI ## index ## CON1_ADDRESS
51  #endif
52 #else
53  #define SAMPLE_REG_ADDRESS(index) HAL_LL_SSP ## index ## STAT_ADDRESS
54 #endif
55 
56 #if defined(SPI_MODULE) || defined(SPI_MODULE_1)
57  #define SET_SPI_DATA_SAMPLE_MIDDLE1 clear_reg_bit(SAMPLE_REG_ADDRESS(1), BIT_INDEX);
58  #define SET_SPI_DATA_SAMPLE_EDGE1 set_reg_bit(SAMPLE_REG_ADDRESS(1), BIT_INDEX);
59 #else
60  #define SET_SPI_DATA_SAMPLE_MIDDLE1
61  #define SET_SPI_DATA_SAMPLE_EDGE1
62 #endif
63 
64 #ifdef SPI_MODULE_2
65  #define SET_SPI_DATA_SAMPLE_MIDDLE2 clear_reg_bit(SAMPLE_REG_ADDRESS(2), BIT_INDEX);
66  #define SET_SPI_DATA_SAMPLE_EDGE2 set_reg_bit(SAMPLE_REG_ADDRESS(2), BIT_INDEX);
67 #else
68  #define SET_SPI_DATA_SAMPLE_MIDDLE2
69  #define SET_SPI_DATA_SAMPLE_EDGE2
70 #endif
71 
72 #ifdef SPI_MODULE_3
73  #define SET_SPI_DATA_SAMPLE_MIDDLE3 clear_reg_bit(SAMPLE_REG_ADDRESS(3), BIT_INDEX);
74  #define SET_SPI_DATA_SAMPLE_EDGE3 set_reg_bit(SAMPLE_REG_ADDRESS(3), BIT_INDEX);
75 #else
76  #define SET_SPI_DATA_SAMPLE_MIDDLE3
77  #define SET_SPI_DATA_SAMPLE_EDGE3
78 #endif
79 
80 #ifdef SPI_MODULE_4
81  #define SET_SPI_DATA_SAMPLE_MIDDLE4 clear_reg_bit(SAMPLE_REG_ADDRESS(4), BIT_INDEX);
82  #define SET_SPI_DATA_SAMPLE_EDGE4 set_reg_bit(SAMPLE_REG_ADDRESS(4), BIT_INDEX);
83 #else
84  #define SET_SPI_DATA_SAMPLE_MIDDLE4
85  #define SET_SPI_DATA_SAMPLE_EDGE4
86 #endif
87 
88 #ifdef SPI_MODULE_5
89  #define SET_SPI_DATA_SAMPLE_MIDDLE5 clear_reg_bit(SAMPLE_REG_ADDRESS(5), BIT_INDEX);
90  #define SET_SPI_DATA_SAMPLE_EDGE5 set_reg_bit(SAMPLE_REG_ADDRESS(5), BIT_INDEX);
91 #else
92  #define SET_SPI_DATA_SAMPLE_MIDDLE5
93  #define SET_SPI_DATA_SAMPLE_EDGE5
94 #endif
95 
96 #ifdef SPI_MODULE_6
97  #define SET_SPI_DATA_SAMPLE_MIDDLE6 clear_reg_bit(SAMPLE_REG_ADDRESS(6), BIT_INDEX);
98  #define SET_SPI_DATA_SAMPLE_EDGE6 set_reg_bit(SAMPLE_REG_ADDRESS(6), BIT_INDEX);
99 #else
100  #define SET_SPI_DATA_SAMPLE_MIDDLE6
101  #define SET_SPI_DATA_SAMPLE_EDGE6
102 #endif
103 
104 
105 #define SET_SPI_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE1 SET_SPI_DATA_SAMPLE_MIDDLE2 \
106  SET_SPI_DATA_SAMPLE_MIDDLE3 SET_SPI_DATA_SAMPLE_MIDDLE4 \
107  SET_SPI_DATA_SAMPLE_MIDDLE5 SET_SPI_DATA_SAMPLE_MIDDLE6
108 #define SET_SPI_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE1 SET_SPI_DATA_SAMPLE_EDGE2 \
109  SET_SPI_DATA_SAMPLE_EDGE3 SET_SPI_DATA_SAMPLE_EDGE4 \
110  SET_SPI_DATA_SAMPLE_EDGE5 SET_SPI_DATA_SAMPLE_EDGE6
111 #else
112  #define SET_SPI_DATA_SAMPLE_MIDDLE
113  #define SET_SPI_DATA_SAMPLE_EDGE
114 #endif
115 
116 #ifdef __cplusplus
117 }
118 #endif
119 #endif // _SPI_SPECIFICS_
120 
121 // ------------------------------------------------------------------------ END