VSF Documented
spi_template.inc
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18/*============================ INCLUDES ======================================*/
19/*============================ MACROS ========================================*/
20
21#if VSF_HAL_USE_SPI == ENABLED
22
23#define vsf_real_spi_t VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_t)
24#define vsf_real_spi_capability VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_capability)
25#define vsf_real_spi_ctrl VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_ctrl)
26#define vsf_real_spi_get_configuration VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_get_configuration)
27
28#ifndef VSF_SPI_CFG_REIMPLEMENT_API_CAPABILITY
29# define VSF_SPI_CFG_REIMPLEMENT_API_CAPABILITY DISABLED
30#endif
31
32#ifndef VSF_SPI_CFG_REIMPLEMENT_API_CTRL
33# define VSF_SPI_CFG_REIMPLEMENT_API_CTRL DISABLED
34#endif
35
36#ifndef VSF_SPI_CFG_REIMPLEMENT_API_GET_CONFIGURATION
37# define VSF_SPI_CFG_REIMPLEMENT_API_GET_CONFIGURATION DISABLED
38#endif
39
40#ifdef VSF_SPI_CFG_IMP_REMAP_PREFIX
41# undef VSF_SPI_CFG_REIMPLEMENT_API_CAPABILITY
42# undef VSF_SPI_CFG_REIMPLEMENT_API_GET_CONFIGURATION
43# define VSF_SPI_CFG_REIMPLEMENT_API_CAPABILITY ENABLED
44# define VSF_SPI_CFG_REIMPLEMENT_API_GET_CONFIGURATION ENABLED
45#endif
46
47#if VSF_SPI_CFG_REIMPLEMENT_API_CAPABILITY == DISABLED
48# ifndef VSF_SPI_CFG_CAPABILITY_SUPPORT_AUTO_CS
49# define VSF_SPI_CFG_CAPABILITY_SUPPORT_AUTO_CS 1
50# endif
51# ifndef VSF_SPI_CFG_CAPABILITY_SUPPORT_MANUAL_CS
52# define VSF_SPI_CFG_CAPABILITY_SUPPORT_MANUAL_CS 1
53# endif
54# ifndef VSF_SPI_CFG_CAPABILITY_CS_COUNT
55# define VSF_SPI_CFG_CAPABILITY_CS_COUNT 1
56# endif
57# ifndef VSF_SPI_CFG_CAPABILITY_MAX_CLOCK_HZ
58# define VSF_SPI_CFG_CAPABILITY_MAX_CLOCK_HZ 0xFFFFFFFF
59# endif
60# ifndef VSF_SPI_CFG_CAPABILITY_MIN_CLOCK_HZ
61# define VSF_SPI_CFG_CAPABILITY_MIN_CLOCK_HZ 1
62# endif
63#endif
64
65/*============================ MACROFIED FUNCTIONS ===========================*/
66
67#if VSF_SPI_CFG_REIMPLEMENT_API_CAPABILITY == DISABLED
68vsf_spi_capability_t vsf_real_spi_capability(vsf_real_spi_t *spi_ptr)
69{
70 vsf_spi_capability_t spi_capability = {
71 .support_hardware_cs = VSF_SPI_CFG_CAPABILITY_SUPPORT_AUTO_CS,
72 .support_software_cs = VSF_SPI_CFG_CAPABILITY_SUPPORT_MANUAL_CS,
73 .cs_count = VSF_SPI_CFG_CAPABILITY_CS_COUNT,
74 .max_clock_hz = VSF_SPI_CFG_CAPABILITY_MAX_CLOCK_HZ,
75 .min_clock_hz = VSF_SPI_CFG_CAPABILITY_MIN_CLOCK_HZ,
76 };
77
78 return spi_capability;
79}
80#endif
81
82#if VSF_SPI_CFG_REIMPLEMENT_API_CTRL == DISABLED
83vsf_err_t vsf_real_spi_ctrl(vsf_real_spi_t *spi_ptr, vsf_spi_ctrl_t ctrl, void *param)
84{
86}
87#endif
88
89#if VSF_SPI_CFG_REIMPLEMENT_API_GET_CONFIGURATION == DISABLED
90vsf_err_t vsf_real_spi_get_configuration(vsf_real_spi_t *spi_ptr, vsf_spi_cfg_t *cfg_ptr)
91{
92 VSF_HAL_ASSERT(NULL != spi_ptr);
93 VSF_HAL_ASSERT(NULL != cfg_ptr);
94
95 // Default implementation: not supported, trigger assertion
97
99}
100#endif
101
102/*============================ MACROS ========================================*/
103
104#undef VSF_SPI_CFG_CAPABILITY_SUPPORT_AUTO_CS
105#undef VSF_SPI_CFG_CAPABILITY_SUPPORT_MANUAL_CS
106#undef VSF_SPI_CFG_CAPABILITY_CS_COUNT
107#undef VSF_SPI_CFG_CAPABILITY_MAX_CLOCK_HZ
108#undef VSF_SPI_CFG_CAPABILITY_MIN_CLOCK_HZ
109#undef vsf_real_spi_t
110#undef vsf_real_spi_capability
111#undef vsf_real_spi_ctrl
112#undef vsf_real_spi_get_configuration
113
114/*============================ PROTOTYPES ====================================*/
115/*============================ LOCAL VARIABLES ===============================*/
116/*============================ MACROS ========================================*/
117/*============================ MACROS ========================================*/
118
119#ifdef VSF_SPI_CFG_IMP_REMAP_PREFIX
120
121# define vsf_imp_spi_t VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_t)
122# define vsf_imp_spi_init VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_init)
123# define vsf_imp_spi_enable VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_enable)
124# define vsf_imp_spi_disable VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_disable)
125# define vsf_imp_spi_irq_enable VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_irq_enable)
126# define vsf_imp_spi_irq_disable VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_irq_disable)
127# define vsf_imp_spi_status VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_status)
128# define vsf_imp_spi_capability VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_capability)
129# define vsf_imp_spi_cs_active VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_cs_active)
130# define vsf_imp_spi_cs_inactive VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_cs_inactive)
131# define vsf_imp_spi_fifo_transfer VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_fifo_transfer)
132# define vsf_imp_spi_request_transfer VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_request_transfer)
133# define vsf_imp_spi_cancel_transfer VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_cancel_transfer)
134# define vsf_imp_spi_get_transferred_count VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_get_transferred_count)
135# define vsf_imp_spi_ctrl VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_ctrl)
136# define vsf_imp_spi_get_configuration VSF_MCONNECT(VSF_SPI_CFG_IMP_PREFIX, _spi_get_configuration)
137
138# define vsf_remap_spi_t VSF_MCONNECT(VSF_SPI_CFG_IMP_REMAP_PREFIX, _spi_t)
139# define vsf_remap_spi_init VSF_MCONNECT(VSF_SPI_CFG_IMP_REMAP_PREFIX, _spi_init)
140# define vsf_remap_spi_enable VSF_MCONNECT(VSF_SPI_CFG_IMP_REMAP_PREFIX, _spi_enable)
141# define vsf_remap_spi_disable VSF_MCONNECT(VSF_SPI_CFG_IMP_REMAP_PREFIX, _spi_disable)
142# define vsf_remap_spi_irq_enable VSF_MCONNECT(VSF_SPI_CFG_IMP_REMAP_PREFIX, _spi_irq_enable)
143# define vsf_remap_spi_irq_disable VSF_MCONNECT(VSF_SPI_CFG_IMP_REMAP_PREFIX, _spi_irq_disable)
144# define vsf_remap_spi_status VSF_MCONNECT(VSF_SPI_CFG_IMP_REMAP_PREFIX, _spi_status)
145# define vsf_remap_spi_capability VSF_MCONNECT(VSF_SPI_CFG_IMP_REMAP_PREFIX, _spi_capability)
146# define vsf_remap_spi_cs_active VSF_MCONNECT(VSF_SPI_CFG_IMP_REMAP_PREFIX, _spi_cs_active)
147# define vsf_remap_spi_cs_inactive VSF_MCONNECT(VSF_SPI_CFG_IMP_REMAP_PREFIX, _spi_cs_inactive)
148# define vsf_remap_spi_fifo_transfer VSF_MCONNECT(VSF_SPI_CFG_IMP_REMAP_PREFIX, _spi_fifo_transfer)
149# define vsf_remap_spi_request_transfer VSF_MCONNECT(VSF_SPI_CFG_IMP_REMAP_PREFIX, _spi_request_transfer)
150# define vsf_remap_spi_cancel_transfer VSF_MCONNECT(VSF_SPI_CFG_IMP_REMAP_PREFIX, _spi_cancel_transfer)
151# define vsf_remap_spi_get_transferred_count VSF_MCONNECT(VSF_SPI_CFG_IMP_REMAP_PREFIX, _spi_get_transferred_count)
152# define vsf_remap_spi_ctrl VSF_MCONNECT(VSF_SPI_CFG_IMP_REMAP_PREFIX, _spi_ctrl)
153# define vsf_remap_spi_get_configuration VSF_MCONNECT(VSF_SPI_CFG_IMP_REMAP_PREFIX, _spi_get_configuration)
154
155# define VSF_SPI_CFG_IMP_REMAP_FUNCTIONS \
156 vsf_err_t vsf_imp_spi_init(vsf_imp_spi_t *spi_ptr, vsf_spi_cfg_t *cfg_ptr) \
157 { \
158 VSF_HAL_ASSERT(spi_ptr != NULL); \
159 return vsf_remap_spi_init(spi_ptr, cfg_ptr); \
160 } \
161 void vsf_imp_spi_fini(vsf_imp_spi_t *spi_ptr) \
162 { \
163 VSF_HAL_ASSERT(spi_ptr != NULL); \
164 vsf_remap_spi_fini(spi_ptr); \
165 } \
166 fsm_rt_t vsf_imp_spi_enable(vsf_imp_spi_t *spi_ptr) \
167 { \
168 VSF_HAL_ASSERT(spi_ptr != NULL); \
169 return vsf_remap_spi_enable(spi_ptr); \
170 } \
171 fsm_rt_t vsf_imp_spi_disable(vsf_imp_spi_t *spi_ptr) \
172 { \
173 VSF_HAL_ASSERT(spi_ptr != NULL); \
174 return vsf_remap_spi_disable(spi_ptr); \
175 } \
176 void vsf_imp_spi_irq_enable(vsf_imp_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask) \
177 { \
178 VSF_HAL_ASSERT(spi_ptr != NULL); \
179 vsf_remap_spi_irq_enable(spi_ptr, irq_mask); \
180 } \
181 void vsf_imp_spi_irq_disable(vsf_imp_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask) \
182 { \
183 VSF_HAL_ASSERT(spi_ptr != NULL); \
184 vsf_remap_spi_irq_disable(spi_ptr, irq_mask); \
185 } \
186 vsf_spi_status_t vsf_imp_spi_status(vsf_imp_spi_t *spi_ptr) \
187 { \
188 VSF_HAL_ASSERT(spi_ptr != NULL); \
189 return vsf_remap_spi_status(spi_ptr); \
190 } \
191 vsf_err_t vsf_imp_spi_cs_active(vsf_imp_spi_t *spi_ptr, uint_fast8_t index) \
192 { \
193 VSF_HAL_ASSERT(spi_ptr != NULL); \
194 return vsf_remap_spi_cs_active(spi_ptr, index); \
195 } \
196 vsf_err_t vsf_imp_spi_cs_inactive(vsf_imp_spi_t *spi_ptr, uint_fast8_t index) \
197 { \
198 VSF_HAL_ASSERT(spi_ptr != NULL); \
199 return vsf_remap_spi_cs_inactive(spi_ptr, index); \
200 } \
201 void vsf_imp_spi_fifo_transfer(vsf_imp_spi_t *spi_ptr, \
202 void *out_buffer_ptr, \
203 uint_fast32_t* out_offset_ptr, \
204 void *in_buffer_ptr, \
205 uint_fast32_t* in_offset_ptr, \
206 uint_fast32_t cnt) \
207 { \
208 VSF_HAL_ASSERT(spi_ptr != NULL); \
209 vsf_remap_spi_fifo_transfer(spi_ptr, \
210 out_buffer_ptr, out_offset_ptr, \
211 in_buffer_ptr, in_offset_ptr, \
212 cnt); \
213 } \
214 vsf_err_t vsf_imp_spi_request_transfer(vsf_imp_spi_t *spi_ptr, void *out_buffer_ptr, \
215 void *in_buffer_ptr, uint_fast32_t count) \
216 { \
217 VSF_HAL_ASSERT(spi_ptr != NULL); \
218 return vsf_remap_spi_request_transfer(spi_ptr, out_buffer_ptr, \
219 in_buffer_ptr, count); \
220 } \
221 vsf_err_t vsf_imp_spi_cancel_transfer(vsf_imp_spi_t *spi_ptr) \
222 { \
223 VSF_HAL_ASSERT(spi_ptr != NULL); \
224 return vsf_remap_spi_cancel_transfer(spi_ptr); \
225 } \
226 void vsf_imp_spi_get_transferred_count(vsf_imp_spi_t *spi_ptr, \
227 uint_fast32_t * tx_count, uint_fast32_t *rx_count) \
228 { \
229 VSF_HAL_ASSERT(spi_ptr != NULL); \
230 vsf_remap_spi_get_transferred_count(spi_ptr, tx_count, rx_count); \
231 } \
232 vsf_spi_capability_t vsf_imp_spi_capability(vsf_imp_spi_t *spi_ptr) \
233 { \
234 VSF_HAL_ASSERT(spi_ptr != NULL); \
235 return vsf_remap_spi_capability(spi_ptr); \
236 } \
237 vsf_err_t vsf_imp_spi_ctrl(vsf_imp_spi_t *spi_ptr, vsf_spi_ctrl_t ctrl, void *param) \
238 { \
239 VSF_HAL_ASSERT(spi_ptr != NULL); \
240 return vsf_remap_spi_ctrl(spi_ptr, ctrl, param); \
241 } \
242 vsf_err_t vsf_imp_spi_get_configuration(vsf_imp_spi_t *spi_ptr, vsf_spi_cfg_t *cfg_ptr) \
243 { \
244 VSF_HAL_ASSERT(spi_ptr != NULL); \
245 VSF_HAL_ASSERT(cfg_ptr != NULL); \
246 return vsf_remap_spi_get_configuration(spi_ptr, cfg_ptr); \
247 }
248#endif
249
250/*============================ IMPLEMENTATION ================================*/
251/*============================ GLOBAL VARIABLES ==============================*/
252
253#define VSF_HAL_TEMPLATE_IMP_NAME _spi
254#define VSF_HAL_TEMPLATE_IMP_UPCASE_NAME _SPI
255
256#if !defined(VSF_SPI_CFG_IMP_PREFIX) && !defined(VSF_SPI_CFG_IMP_DEVICE_PREFIX)
257# error "Please define VSF_SPI_CFG_IMP_PREFIX in spi driver"
258#endif
259
260#if !defined(VSF_SPI_CFG_IMP_UPCASE_PREFIX) && !defined(VSF_SPI_CFG_IMP_DEVICE_UPCASE_PREFIX)
261# error "Please define VSF_SPI_CFG_IMP_UPCASE_PREFIX in spi driver"
262#endif
263
264#ifndef VSF_SPI_CFG_IMP_COUNT_MASK_PREFIX
265# define VSF_SPI_CFG_IMP_COUNT_MASK_PREFIX VSF_SPI_CFG_IMP_UPCASE_PREFIX
266#endif
267
268#ifdef VSF_SPI_CFG_IMP_REMAP_FUNCTIONS
269# define VSF_HAL_CFG_IMP_REMAP_FUNCTIONS VSF_SPI_CFG_IMP_REMAP_FUNCTIONS
270#endif
271
273
274#undef VSF_SPI_CFG_IMP_PREFIX
275#undef VSF_SPI_CFG_IMP_COUNT_MASK_PREFIX
276#undef VSF_SPI_CFG_IMP_UPCASE_PREFIX
277#undef VSF_SPI_CFG_IMP_DEVICE_PREFIX
278#undef VSF_SPI_CFG_IMP_DEVICE_UPCASE_PREFIX
279#undef VSF_SPI_CFG_IMP_LV0
280#undef VSF_SPI_CFG_IMP_REMAP_FUNCTIONS
281#undef VSF_SPI_CFG_IMP_HAS_OP
282#undef VSF_SPI_CFG_IMP_EXTERN_OP
283
284#undef vsf_imp_spi_t
285#undef vsf_imp_spi_init
286#undef vsf_imp_spi_enable
287#undef vsf_imp_spi_disable
288#undef vsf_imp_spi_irq_enable
289#undef vsf_imp_spi_irq_disable
290#undef vsf_imp_spi_status
291#undef vsf_imp_spi_capability
292#undef vsf_imp_spi_cs_active
293#undef vsf_imp_spi_cs_inactive
294#undef vsf_imp_spi_fifo_transfer
295#undef vsf_imp_spi_request_transfer
296#undef vsf_imp_spi_cancel_transfer
297#undef vsf_imp_spi_get_transferred_count
298#undef vsf_imp_spi_ctrl
299#undef vsf_imp_spi_get_configuration
300
301#undef vsf_remap_spi_t
302#undef vsf_remap_spi_init
303#undef vsf_remap_spi_enable
304#undef vsf_remap_spi_disable
305#undef vsf_remap_spi_irq_enable
306#undef vsf_remap_spi_irq_disable
307#undef vsf_remap_spi_status
308#undef vsf_remap_spi_capability
309#undef vsf_remap_spi_cs_active
310#undef vsf_remap_spi_cs_inactive
311#undef vsf_remap_spi_fifo_transfer
312#undef vsf_remap_spi_request_transfer
313#undef vsf_remap_spi_cancel_transfer
314#undef vsf_remap_spi_get_transferred_count
315#undef vsf_remap_spi_ctrl
316#undef vsf_remap_spi_get_configuration
317
318#endif /* VSF_HAL_USE_SPI */
319
vsf_err_t
Definition __type.h:42
@ VSF_ERR_NOT_SUPPORT
function not supported
Definition __type.h:46
#define NULL
Definition lvgl.h:26
Predefined VSF SPI capability that can be reimplemented in specific HAL drivers. Even if the hardware...
Definition vsf_template_spi.h:688
uint8_t support_hardware_cs
Supported interrupt masks for SPI operations.
Definition vsf_template_spi.h:694
Configuration structure for SPI.
Definition vsf_template_spi.h:746
#define VSF_HAL_ASSERT(__CON)
all hal modules use this configuration file
Definition vsf_hal_cfg.h:36
vsf_spi_ctrl_t
Predefined VSF SPI control commands that can be reimplemented in specific HAL drivers.
Definition vsf_template_spi.h:778
Generated from commit: vsfteam/vsf@74aa6ce