sram4 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
31extern "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#elif defined(__MIKROC_AI_FOR_DSPIC__)
45 #ifdef HAL_LL_SPI1_CONTROL_REG_ADDRESS
46 #define BIT_INDEX 9
47 #else
48 #define BIT_INDEX 7
49 #endif
50#endif
51
52#ifdef SAMPLE_REG_CASE_1
53 #ifdef __MIKROC_AI_FOR_PIC32__
54 #define SAMPLE_REG_ADDRESS(index) HAL_LL_SPI ## index ## CON_ADDRESS
55 #elif defined (__MIKROC_AI_FOR_PIC__)
56 #define SAMPLE_REG_ADDRESS(index) HAL_LL_SPI ## index ## CON1_ADDRESS
57 #else
58 #define SAMPLE_REG_ADDRESS(index) HAL_LL_SPI ## index ## _CONTROL_REG_ADDRESS
59 #endif
60#else
61 #define SAMPLE_REG_ADDRESS(index) HAL_LL_SSP ## index ## STAT_ADDRESS
62#endif
63
64#if defined(SPI_MODULE) || defined(SPI_MODULE_1)
65 #define SET_SPI_DATA_SAMPLE_MIDDLE1 clear_reg_bit(SAMPLE_REG_ADDRESS(1), BIT_INDEX);
66 #define SET_SPI_DATA_SAMPLE_EDGE1 set_reg_bit(SAMPLE_REG_ADDRESS(1), BIT_INDEX);
67#else
68 #define SET_SPI_DATA_SAMPLE_MIDDLE1
69 #define SET_SPI_DATA_SAMPLE_EDGE1
70#endif
71
72#ifdef SPI_MODULE_2
73 #define SET_SPI_DATA_SAMPLE_MIDDLE2 clear_reg_bit(SAMPLE_REG_ADDRESS(2), BIT_INDEX);
74 #define SET_SPI_DATA_SAMPLE_EDGE2 set_reg_bit(SAMPLE_REG_ADDRESS(2), BIT_INDEX);
75#else
76 #define SET_SPI_DATA_SAMPLE_MIDDLE2
77 #define SET_SPI_DATA_SAMPLE_EDGE2
78#endif
79
80#ifdef SPI_MODULE_3
81 #define SET_SPI_DATA_SAMPLE_MIDDLE3 clear_reg_bit(SAMPLE_REG_ADDRESS(3), BIT_INDEX);
82 #define SET_SPI_DATA_SAMPLE_EDGE3 set_reg_bit(SAMPLE_REG_ADDRESS(3), BIT_INDEX);
83#else
84 #define SET_SPI_DATA_SAMPLE_MIDDLE3
85 #define SET_SPI_DATA_SAMPLE_EDGE3
86#endif
87
88#ifdef SPI_MODULE_4
89 #define SET_SPI_DATA_SAMPLE_MIDDLE4 clear_reg_bit(SAMPLE_REG_ADDRESS(4), BIT_INDEX);
90 #define SET_SPI_DATA_SAMPLE_EDGE4 set_reg_bit(SAMPLE_REG_ADDRESS(4), BIT_INDEX);
91#else
92 #define SET_SPI_DATA_SAMPLE_MIDDLE4
93 #define SET_SPI_DATA_SAMPLE_EDGE4
94#endif
95
96#ifdef SPI_MODULE_5
97 #define SET_SPI_DATA_SAMPLE_MIDDLE5 clear_reg_bit(SAMPLE_REG_ADDRESS(5), BIT_INDEX);
98 #define SET_SPI_DATA_SAMPLE_EDGE5 set_reg_bit(SAMPLE_REG_ADDRESS(5), BIT_INDEX);
99#else
100 #define SET_SPI_DATA_SAMPLE_MIDDLE5
101 #define SET_SPI_DATA_SAMPLE_EDGE5
102#endif
103
104#ifdef SPI_MODULE_6
105 #define SET_SPI_DATA_SAMPLE_MIDDLE6 clear_reg_bit(SAMPLE_REG_ADDRESS(6), BIT_INDEX);
106 #define SET_SPI_DATA_SAMPLE_EDGE6 set_reg_bit(SAMPLE_REG_ADDRESS(6), BIT_INDEX);
107#else
108 #define SET_SPI_DATA_SAMPLE_MIDDLE6
109 #define SET_SPI_DATA_SAMPLE_EDGE6
110#endif
111
112
113#define SET_SPI_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE1 SET_SPI_DATA_SAMPLE_MIDDLE2 \
114 SET_SPI_DATA_SAMPLE_MIDDLE3 SET_SPI_DATA_SAMPLE_MIDDLE4 \
115 SET_SPI_DATA_SAMPLE_MIDDLE5 SET_SPI_DATA_SAMPLE_MIDDLE6
116#define SET_SPI_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE1 SET_SPI_DATA_SAMPLE_EDGE2 \
117 SET_SPI_DATA_SAMPLE_EDGE3 SET_SPI_DATA_SAMPLE_EDGE4 \
118 SET_SPI_DATA_SAMPLE_EDGE5 SET_SPI_DATA_SAMPLE_EDGE6
119#else
120 #define SET_SPI_DATA_SAMPLE_MIDDLE
121 #define SET_SPI_DATA_SAMPLE_EDGE
122#endif
123
124#ifdef __cplusplus
125}
126#endif
127#endif // _SPI_SPECIFICS_
128
129// ------------------------------------------------------------------------ END