no-OS
no_os_spi.h
Go to the documentation of this file.
1 /***************************************************************************/
40 #ifndef _NO_OS_SPI_H_
41 #define _NO_OS_SPI_H_
42 
43 /******************************************************************************/
44 /***************************** Include Files **********************************/
45 /******************************************************************************/
46 
47 #include <stdint.h>
48 
49 /******************************************************************************/
50 /********************** Macros and Constants Definitions **********************/
51 /******************************************************************************/
52 
53 #define NO_OS_SPI_CPHA 0x01
54 #define NO_OS_SPI_CPOL 0x02
55 
56 /******************************************************************************/
57 /*************************** Types Declarations *******************************/
58 /******************************************************************************/
59 
64 typedef enum no_os_spi_mode {
66  NO_OS_SPI_MODE_0 = (0 | 0),
74 
79 typedef enum no_os_spi_bit_order {
85 
90 struct no_os_spi_msg {
92  uint8_t *tx_buff;
94  uint8_t *rx_buff;
96  uint32_t bytes_number;
98  uint8_t cs_change;
99 };
100 
106 struct no_os_spi_platform_ops ;
107 
112 typedef struct no_os_spi_init_param {
114  uint32_t device_id;
116  uint32_t max_speed_hz;
118  uint8_t chip_select;
125  void *extra;
127 
132 typedef struct no_os_spi_desc {
134  uint32_t device_id;
136  uint32_t max_speed_hz;
138  uint8_t chip_select;
145  void *extra;
147 
155  int32_t (*init)(struct no_os_spi_desc **, const struct no_os_spi_init_param *);
157  int32_t (*write_and_read)(struct no_os_spi_desc *, uint8_t *, uint16_t);
159  int32_t (*transfer)(struct no_os_spi_desc *, struct no_os_spi_msg *, uint32_t);
161  int32_t (*remove)(struct no_os_spi_desc *);
162 };
163 
164 /******************************************************************************/
165 /************************ Functions Declarations ******************************/
166 /******************************************************************************/
167 
168 /* Initialize the SPI communication peripheral. */
169 int32_t no_os_spi_init(struct no_os_spi_desc **desc,
170  const struct no_os_spi_init_param *param);
171 
172 /* Free the resources allocated by no_os_spi_init(). */
173 int32_t no_os_spi_remove(struct no_os_spi_desc *desc);
174 
175 /* Write and read data to/from SPI. */
176 int32_t no_os_spi_write_and_read(struct no_os_spi_desc *desc,
177  uint8_t *data,
178  uint16_t bytes_number);
179 
180 /* Iterate over the spi_msg array and send all messages at once */
181 int32_t no_os_spi_transfer(struct no_os_spi_desc *desc,
182  struct no_os_spi_msg *msgs,
183  uint32_t len);
184 
185 
186 #endif // _NO_OS_SPI_H_
NO_OS_SPI_MODE_1
@ NO_OS_SPI_MODE_1
Definition: no_os_spi.h:68
no_os_spi_mode
no_os_spi_mode
SPI configuration for clock phase and polarity.
Definition: no_os_spi.h:64
no_os_spi_desc::device_id
uint32_t device_id
Definition: no_os_spi.h:134
NO_OS_SPI_CPOL
#define NO_OS_SPI_CPOL
Definition: no_os_spi.h:54
no_os_spi_init_param::bit_order
enum no_os_spi_bit_order bit_order
Definition: no_os_spi.h:122
no_os_spi_write_and_read
int32_t no_os_spi_write_and_read(struct no_os_spi_desc *desc, uint8_t *data, uint16_t bytes_number)
Write and read data to/from SPI.
Definition: no_os_spi.c:82
no_os_spi_msg
Definition: no_os_spi.h:90
no_os_spi_platform_ops
Structure holding SPI function pointers that point to the platform specific function.
Definition: no_os_spi.h:153
no_os_spi_init_param::mode
enum no_os_spi_mode mode
Definition: no_os_spi.h:120
NO_OS_SPI_MODE_2
@ NO_OS_SPI_MODE_2
Definition: no_os_spi.h:70
no_os_spi_bit_order
no_os_spi_bit_order
SPI configuration for bit order (MSB/LSB).
Definition: no_os_spi.h:79
no_os_spi_desc
struct no_os_spi_desc no_os_spi_desc
no_os_spi_init_param::platform_ops
const struct no_os_spi_platform_ops * platform_ops
Definition: no_os_spi.h:123
NO_OS_SPI_MODE_3
@ NO_OS_SPI_MODE_3
Definition: no_os_spi.h:72
no_os_spi_msg::tx_buff
uint8_t * tx_buff
Definition: no_os_spi.h:92
no_os_spi_init_param::device_id
uint32_t device_id
Definition: no_os_spi.h:114
no_os_spi_init_param::chip_select
uint8_t chip_select
Definition: no_os_spi.h:118
no_os_spi_desc::chip_select
uint8_t chip_select
Definition: no_os_spi.h:138
no_os_spi_msg::rx_buff
uint8_t * rx_buff
Definition: no_os_spi.h:94
no_os_spi_msg::cs_change
uint8_t cs_change
Definition: no_os_spi.h:98
no_os_spi_desc::bit_order
enum no_os_spi_bit_order bit_order
Definition: no_os_spi.h:142
no_os_spi_platform_ops::transfer
int32_t(* transfer)(struct no_os_spi_desc *, struct no_os_spi_msg *, uint32_t)
Definition: no_os_spi.h:159
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:132
no_os_spi_transfer
int32_t no_os_spi_transfer(struct no_os_spi_desc *desc, struct no_os_spi_msg *msgs, uint32_t len)
Iterate over head list and send all spi messages.
Definition: no_os_spi.c:96
no_os_spi_msg::bytes_number
uint32_t bytes_number
Definition: no_os_spi.h:96
no_os_spi_desc::extra
void * extra
Definition: no_os_spi.h:145
no_os_spi_init_param::max_speed_hz
uint32_t max_speed_hz
Definition: no_os_spi.h:116
no_os_spi_platform_ops::remove
int32_t(* remove)(struct no_os_spi_desc *)
Definition: no_os_spi.h:161
NO_OS_SPI_BIT_ORDER_LSB_FIRST
@ NO_OS_SPI_BIT_ORDER_LSB_FIRST
Definition: no_os_spi.h:83
NO_OS_SPI_BIT_ORDER_MSB_FIRST
@ NO_OS_SPI_BIT_ORDER_MSB_FIRST
Definition: no_os_spi.h:81
no_os_spi_platform_ops::write_and_read
int32_t(* write_and_read)(struct no_os_spi_desc *, uint8_t *, uint16_t)
Definition: no_os_spi.h:157
no_os_spi_remove
int32_t no_os_spi_remove(struct no_os_spi_desc *desc)
Free the resources allocated by no_os_spi_init().
Definition: no_os_spi.c:70
no_os_spi_desc::platform_ops
const struct no_os_spi_platform_ops * platform_ops
Definition: no_os_spi.h:143
no_os_spi_desc::max_speed_hz
uint32_t max_speed_hz
Definition: no_os_spi.h:136
no_os_spi_init
int32_t no_os_spi_init(struct no_os_spi_desc **desc, const struct no_os_spi_init_param *param)
Initialize the SPI communication peripheral.
Definition: no_os_spi.c:51
NO_OS_SPI_CPHA
#define NO_OS_SPI_CPHA
Definition: no_os_spi.h:53
no_os_spi_platform_ops::init
int32_t(* init)(struct no_os_spi_desc **, const struct no_os_spi_init_param *)
Definition: no_os_spi.h:155
no_os_spi_init_param::extra
void * extra
Definition: no_os_spi.h:125
NO_OS_SPI_MODE_0
@ NO_OS_SPI_MODE_0
Definition: no_os_spi.h:66
no_os_spi_desc::mode
enum no_os_spi_mode mode
Definition: no_os_spi.h:140
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:112
no_os_spi_init_param
struct no_os_spi_init_param no_os_spi_init_param