18#ifndef __VSF_TEMPLATE_SPI_H__
19#define __VSF_TEMPLATE_SPI_H__
33#ifndef VSF_SPI_CFG_MULTI_CLASS
34# define VSF_SPI_CFG_MULTI_CLASS ENABLED
37#if defined(VSF_HW_SPI_COUNT) && !defined(VSF_HW_SPI_MASK)
38# define VSF_HW_SPI_MASK VSF_HAL_COUNT_TO_MASK(VSF_HW_SPI_COUNT)
41#if defined(VSF_HW_SPI_MASK) && !defined(VSF_HW_SPI_COUNT)
42# define VSF_HW_SPI_COUNT VSF_HAL_MASK_TO_COUNT(VSF_HW_SPI_MASK)
46#ifndef VSF_SPI_CFG_PREFIX
47# if (VSF_SPI_CFG_MULTI_CLASS == DISABLED) && defined(VSF_HW_SPI_COUNT) && (VSF_HW_SPI_COUNT != 0)
48# define VSF_SPI_CFG_PREFIX vsf_hw
50# define VSF_SPI_CFG_PREFIX vsf
54#ifndef VSF_SPI_CFG_FUNCTION_RENAME
55# define VSF_SPI_CFG_FUNCTION_RENAME ENABLED
60#ifndef VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE
61# define VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE DISABLED
66#ifndef VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK
67# define VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK DISABLED
72#ifndef VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS
73# define VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS DISABLED
79#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
80# define VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG DISABLED
86#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
87# define VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY DISABLED
93#ifndef VSF_SPI_CFG_REIMPLEMENT_MODE_TO_DATA_BITS
94# define VSF_SPI_CFG_REIMPLEMENT_MODE_TO_DATA_BITS DISABLED
100#ifndef VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_MODE
101# define VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_MODE DISABLED
107#ifndef VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_BYTES
108# define VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_BYTES DISABLED
111#ifndef VSF_SPI_CFG_INHERT_HAL_CAPABILITY
112# define VSF_SPI_CFG_INHERT_HAL_CAPABILITY ENABLED
117#define VSF_SPI_APIS(__prefix_name) \
118 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, spi, init, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr, vsf_spi_cfg_t *cfg_ptr) \
119 __VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, fini, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr) \
120 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, spi, enable, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr) \
121 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, spi, disable, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr) \
122 __VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, irq_enable, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr, vsf_spi_irq_mask_t irq_mask) \
123 __VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, irq_disable, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr, vsf_spi_irq_mask_t irq_mask) \
124 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_spi_status_t, spi, status, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr) \
125 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_spi_capability_t, spi, capability, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr) \
126 __VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, cs_active, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr, uint_fast8_t index) \
127 __VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, cs_inactive, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr, uint_fast8_t index) \
128 __VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, fifo_transfer, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr, \
129 void *out_buffer_ptr, uint_fast32_t *out_offset_ptr, \
130 void *in_buffer_ptr, uint_fast32_t *in_offset_ptr, uint_fast32_t cnt) \
131 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, spi, request_transfer, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr, void *out_buffer_ptr, \
132 void *in_buffer_ptr, uint_fast32_t count) \
133 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, spi, cancel_transfer, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr) \
134 __VSF_HAL_TEMPLATE_API(__prefix_name, void, spi, get_transferred_count, VSF_MCONNECT(__prefix_name, _spi_t) *spi_ptr, uint_fast32_t * tx_count, uint_fast32_t *rx_count)
139#if VSF_SPI_CFG_REIMPLEMENT_TYPE_MODE == DISABLED
399#ifndef VSF_SPI_CS_MODE_MASK
402#ifdef VSF_SPI_CS_HARDWARE_INPUT_MODE
403 | VSF_SPI_CS_HARDWARE_INPUT_MODE
408#ifndef VSF_SPI_DATASIZE_MASK
420#ifdef VSF_SPI_DATALINE_MASK
421 | VSF_SPI_DATALINE_MASK
423#ifdef VSF_SPI_MOTORALA_TI_MASK
424 | VSF_SPI_MOTORALA_TI_MASK
426#ifdef VSF_SPI_CRC_MASK
429#ifdef VSF_SPI_CLOCK_PRESCLER_MASK
430 | VSF_SPI_CLOCK_PRESCLER_MASK
434#if VSF_SPI_CFG_REIMPLEMENT_TYPE_IRQ_MASK == DISABLED
483#if VSF_SPI_CFG_REIMPLEMENT_TYPE_STATUS == DISABLED
494#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
496#if VSF_SPI_CFG_INHERT_HAL_CAPABILITY == ENABLED
510#if VSF_SPI_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
534#undef __VSF_HAL_TEMPLATE_API
535#define __VSF_HAL_TEMPLATE_API VSF_HAL_TEMPLATE_API_FP
540#if VSF_SPI_CFG_MULTI_CLASS == ENABLED
776#if VSF_SPI_CFG_REIMPLEMENT_MODE_TO_DATA_BITS == ENABLD
777# if defined(VSF_SPI_DATASIZE_BIT_OFFSET) && defined(VSF_SPI_DATASIZE_VALUE_OFFSET)
781 return bits + VSF_SPI_DATASIZE_VALUE_OFFSET;
788#ifdef VSF_SPI_DATASIZE_4
792#ifdef VSF_SPI_DATASIZE_5
796#ifdef VSF_SPI_DATASIZE_6
800#ifdef VSF_SPI_DATASIZE_7
806#ifdef VSF_SPI_DATASIZE_9
810#ifdef VSF_SPI_DATASIZE_10
814#ifdef VSF_SPI_DATASIZE_11
818#ifdef VSF_SPI_DATASIZE_12
822#ifdef VSF_SPI_DATASIZE_13
826#ifdef VSF_SPI_DATASIZE_14
830#ifdef VSF_SPI_DATASIZE_15
836#ifdef VSF_SPI_DATASIZE_17
840#ifdef VSF_SPI_DATASIZE_18
844#ifdef VSF_SPI_DATASIZE_19
848#ifdef VSF_SPI_DATASIZE_20
852#ifdef VSF_SPI_DATASIZE_21
856#ifdef VSF_SPI_DATASIZE_22
860#ifdef VSF_SPI_DATASIZE_23
864#ifdef VSF_SPI_DATASIZE_24
868#ifdef VSF_SPI_DATASIZE_25
872#ifdef VSF_SPI_DATASIZE_26
876#ifdef VSF_SPI_DATASIZE_27
880#ifdef VSF_SPI_DATASIZE_28
884#ifdef VSF_SPI_DATASIZE_29
888#ifdef VSF_SPI_DATASIZE_30
892#ifdef VSF_SPI_DATASIZE_31
905#if VSF_SPI_CFG_REIMPLEMENT_DATA_BITS_TO_MODE == ENABLD
906# if defined(VSF_SPI_DATASIZE_BIT_OFFSET) && defined(VSF_SPI_DATASIZE_VALUE_OFFSET)
915#ifdef VSF_SPI_DATASIZE_4
919#ifdef VSF_SPI_DATASIZE_5
923#ifdef VSF_SPI_DATASIZE_6
927#ifdef VSF_SPI_DATASIZE_7
933#ifdef VSF_SPI_DATASIZE_9
937#ifdef VSF_SPI_DATASIZE_10
941#ifdef VSF_SPI_DATASIZE_11
945#ifdef VSF_SPI_DATASIZE_12
949#ifdef VSF_SPI_DATASIZE_13
953#ifdef VSF_SPI_DATASIZE_14
957#ifdef VSF_SPI_DATASIZE_15
963#ifdef VSF_SPI_DATASIZE_17
967#ifdef VSF_SPI_DATASIZE_18
971#ifdef VSF_SPI_DATASIZE_19
975#ifdef VSF_SPI_DATASIZE_20
979#ifdef VSF_SPI_DATASIZE_21
983#ifdef VSF_SPI_DATASIZE_22
987#ifdef VSF_SPI_DATASIZE_23
991#ifdef VSF_SPI_DATASIZE_24
995#ifdef VSF_SPI_DATASIZE_25
999#ifdef VSF_SPI_DATASIZE_26
1003#ifdef VSF_SPI_DATASIZE_27
1007#ifdef VSF_SPI_DATASIZE_28
1011#ifdef VSF_SPI_DATASIZE_29
1015#ifdef VSF_SPI_DATASIZE_30
1019#ifdef VSF_SPI_DATASIZE_31
1032#if VSF_SPI_CFG_REIMPLEMENT_MODE_TO_BYTES == ENABLD
1048#if VSF_SPI_CFG_FUNCTION_RENAME == ENABLED
1049# define __vsf_spi_t VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_t)
1050# define vsf_spi_init(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_init) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1051# define vsf_spi_enable(__SPI) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_enable) ((__vsf_spi_t *)(__SPI))
1052# define vsf_spi_disable(__SPI) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_disable) ((__vsf_spi_t *)(__SPI))
1053# define vsf_spi_irq_enable(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_irq_enable) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1054# define vsf_spi_irq_disable(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_irq_disable) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1055# define vsf_spi_status(__SPI) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_status) ((__vsf_spi_t *)(__SPI))
1056# define vsf_spi_capability(__SPI) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_capability) ((__vsf_spi_t *)(__SPI))
1057# define vsf_spi_cs_active(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_cs_active) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1058# define vsf_spi_cs_inactive(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_cs_inactive) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1059# define vsf_spi_fifo_transfer(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_fifo_transfer) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1060# define vsf_spi_request_transfer(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_request_transfer) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
1061# define vsf_spi_cancel_transfer(__SPI) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_cancel_transfer) ((__vsf_spi_t *)(__SPI))
1062# define vsf_spi_get_transferred_count(__SPI, ...) VSF_MCONNECT(VSF_SPI_CFG_PREFIX, _spi_get_transferred_count) ((__vsf_spi_t *)(__SPI), ##__VA_ARGS__)
vsf_err_t
Definition __type.h:42
vsf_spi_mode_t
Definition spi.h:33
@ VSF_SPI_DATASIZE_31
Definition spi.h:67
@ VSF_SPI_DATASIZE_28
Definition spi.h:64
@ VSF_SPI_DATASIZE_6
Definition spi.h:98
@ VSF_SPI_DATASIZE_17
Definition spi.h:53
@ VSF_SPI_DATASIZE_9
Definition spi.h:45
@ VSF_SPI_DATASIZE_18
Definition spi.h:54
@ VSF_SPI_DATASIZE_11
Definition spi.h:47
@ VSF_SPI_DATASIZE_20
Definition spi.h:56
@ VSF_SPI_DATASIZE_21
Definition spi.h:57
@ VSF_SPI_DATASIZE_27
Definition spi.h:63
@ VSF_SPI_DATASIZE_14
Definition spi.h:50
@ VSF_SPI_DATASIZE_BIT_OFFSET
Definition spi.h:42
@ VSF_SPI_DATASIZE_26
Definition spi.h:62
@ VSF_SPI_DATASIZE_13
Definition spi.h:49
@ VSF_SPI_DATASIZE_7
Definition spi.h:99
@ VSF_SPI_DATASIZE_5
Definition spi.h:97
@ VSF_SPI_DATASIZE_12
Definition spi.h:48
@ VSF_SPI_DATASIZE_22
Definition spi.h:58
@ VSF_SPI_DATASIZE_24
Definition spi.h:60
@ VSF_SPI_DATASIZE_4
datasize is 8 bits
Definition spi.h:96
@ VSF_SPI_DATASIZE_29
Definition spi.h:65
@ VSF_SPI_DATASIZE_25
Definition spi.h:61
@ VSF_SPI_DATASIZE_30
Definition spi.h:66
@ VSF_SPI_DATASIZE_19
Definition spi.h:55
@ VSF_SPI_DATASIZE_23
Definition spi.h:59
@ VSF_SPI_DATASIZE_10
Definition spi.h:46
@ VSF_SPI_DATASIZE_15
Definition spi.h:51
vsf_arch_prio_t
Definition cortex_a_generic.h:88
unsigned int uint32_t
Definition lvgl.h:43
unsigned char uint8_t
Definition lvgl.h:40
const i_spi_t vsf_spi_irq_mask_t irq_mask
Definition spi_interface.h:38
unsigned char uint_fast8_t
Definition stdint.h:23
unsigned int uint_fast32_t
Definition stdint.h:27
Definition vsf_template_hal_driver.h:203
Definition vsf_template_hal_driver.h:196
Definition vsf_template_spi.h:495
uint8_t support_software_cs
Definition vsf_template_spi.h:502
uint32_t max_clock_hz
Definition vsf_template_spi.h:505
uint8_t cs_count
Definition vsf_template_spi.h:503
uint8_t support_hardware_cs
Definition vsf_template_spi.h:501
uint32_t min_clock_hz
Definition vsf_template_spi.h:506
inherit(vsf_peripheral_capability_t) vsf_spi_irq_mask_t irq_mask
spi configuration for api
Definition vsf_template_spi.h:525
uint32_t clock_hz
Definition vsf_template_spi.h:527
vsf_spi_isr_t isr
Definition vsf_template_spi.h:528
vsf_spi_mode_t mode
spi working mode
Definition vsf_template_spi.h:526
uint8_t auto_cs_index
spi auto chip select of pin when multiple cs are supported
Definition vsf_template_spi.h:529
spi isr for api
Definition vsf_template_spi.h:518
vsf_spi_isr_handler_t * handler_fn
Definition vsf_template_spi.h:519
void * target_ptr
Definition vsf_template_spi.h:520
vsf_arch_prio_t prio
Definition vsf_template_spi.h:521
Definition vsf_template_spi.h:533
Definition vsf_template_spi.h:484
Definition vsf_template_spi.h:541
const vsf_spi_op_t * op
Definition vsf_template_spi.h:542
fsm_rt_t
Definition vsf_fsm.h:315
#define vsf_spi_cs_inactive(__SPI,...)
Definition vsf_template_spi.h:1058
@ VSF_SPI_IRQ_MASK_RX_CPL
For SPI transfers, send completion is definitely earlier than receive completion.
Definition vsf_template_spi.h:473
@ VSF_SPI_IRQ_MASK_TX_FIFO_THRESHOLD
Definition vsf_template_spi.h:469
@ VSF_SPI_IRQ_ALL_BITS_MASK
Definition vsf_template_spi.h:475
@ VSF_SPI_IRQ_MASK_RX_FIFO_THRESHOLD
Definition vsf_template_spi.h:470
#define vsf_spi_get_transferred_count(__SPI,...)
Definition vsf_template_spi.h:1062
#define vsf_spi_cs_active(__SPI,...)
Definition vsf_template_spi.h:1057
void vsf_spi_isr_handler_t(void *target_ptr, vsf_spi_t *spi_ptr, vsf_spi_irq_mask_t irq_mask)
Definition vsf_template_spi.h:513
struct vsf_spi_capability_t vsf_spi_capability_t
#define VSF_SPI_APIS(__prefix_name)
Definition vsf_template_spi.h:117
#define vsf_spi_status(__SPI)
Definition vsf_template_spi.h:1055
#define vsf_spi_init(__SPI,...)
Definition vsf_template_spi.h:1050
#define vsf_spi_irq_disable(__SPI,...)
Definition vsf_template_spi.h:1054
#define vsf_spi_capability(__SPI)
Definition vsf_template_spi.h:1056
#define vsf_spi_irq_enable(__SPI,...)
Definition vsf_template_spi.h:1053
vsf_spi_irq_mask_t
Predefined VSF SPI interrupt that can be reimplemented in specific hal drivers.
Definition vsf_template_spi.h:454
@ VSF_SPI_IRQ_MASK_OVERFLOW_ERR
Definition vsf_template_spi.h:463
@ VSF_SPI_IRQ_MASK_CPL
Definition vsf_template_spi.h:461
@ VSF_SPI_IRQ_MASK_RX
Definition vsf_template_spi.h:457
@ VSF_SPI_IRQ_MASK_TX
Definition vsf_template_spi.h:456
@ VSF_SPI_IRQ_MASK_ERROR
Definition vsf_template_spi.h:464
@ VSF_SPI_IRQ_MASK_TX_CPL
Definition vsf_template_spi.h:460
#define vsf_spi_cancel_transfer(__SPI)
Definition vsf_template_spi.h:1061
#define vsf_spi_request_transfer(__SPI,...)
Definition vsf_template_spi.h:1060
struct vsf_spi_status_t vsf_spi_status_t
vsf_spi_mode_t
Predefined VSF SPI modes that can be reimplemented in specific hal drivers.
Definition vsf_template_spi.h:187
@ VSF_SPI_CPHA_LOW
SCK clock phase is low.
Definition vsf_template_spi.h:197
@ VSF_SPI_SLAVE
select slave mode
Definition vsf_template_spi.h:189
@ VSF_SPI_DATASIZE_16
Definition vsf_template_spi.h:217
@ VSF_SPI_LSB_FIRST
transfer LSB first
Definition vsf_template_spi.h:192
@ VSF_SPI_CPOL_HIGH
SCK clock polarity is high.
Definition vsf_template_spi.h:196
@ VSF_SPI_MODE_1
Definition vsf_template_spi.h:201
@ VSF_SPI_DATASIZE_8
Definition vsf_template_spi.h:216
@ VSF_SPI_MASTER
select master mode
Definition vsf_template_spi.h:188
@ VSF_SPI_CPHA_HIGH
SCK clock phase is high.
Definition vsf_template_spi.h:198
@ VSF_SPI_MSB_FIRST
default enable MSB
Definition vsf_template_spi.h:191
@ VSF_SPI_DATASIZE_32
Definition vsf_template_spi.h:218
@ VSF_SPI_CS_SOFTWARE_MODE
SCK Chip Select by software(vsf_spi_cs_active/vsf_spi_cs_inactive)
Definition vsf_template_spi.h:206
@ VSF_SPI_MODE_0
Definition vsf_template_spi.h:200
@ VSF_SPI_CS_HARDWARE_MODE
Definition vsf_template_spi.h:209
@ VSF_SPI_MODE_3
Definition vsf_template_spi.h:203
@ VSF_SPI_CPOL_LOW
SCK clock polarity is low.
Definition vsf_template_spi.h:195
@ VSF_SPI_MODE_2
Definition vsf_template_spi.h:202
#define vsf_spi_enable(__SPI)
Definition vsf_template_spi.h:1051
#define vsf_spi_disable(__SPI)
Definition vsf_template_spi.h:1052
#define vsf_spi_fifo_transfer(__SPI,...)
Definition vsf_template_spi.h:1059
void vsf_spi_fini(vsf_spi_t *spi_ptr)
finalize a spi instance.
Definition spi_common.c:47
@ VSF_SPI_MODE_MASK
Definition vsf_template_spi.h:394
@ VSF_SPI_BIT_ORDER_MASK
Definition vsf_template_spi.h:391
@ VSF_SPI_DIR_MODE_MASK
Definition vsf_template_spi.h:388
@ VSF_SPI_CS_MODE_MASK
Definition vsf_template_spi.h:400
@ VSF_SPI_MODE_ALL_BITS_MASK
Definition vsf_template_spi.h:414
@ VSF_SPI_DATASIZE_MASK
Definition vsf_template_spi.h:409