sam_spi/spi_master.h
Go to the documentation of this file.
1 
33 /*
34  * Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
35  */
36 
37 #ifndef _SPI_MASTER_H_
38 #define _SPI_MASTER_H_
39 
40 #include "compiler.h"
41 #include "sysclk.h"
42 #include "status_codes.h"
43 #include "spi.h"
44 
46 #include "conf_spi_master.h"
48 
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 
58 #ifndef CONFIG_SPI_MASTER_DELAY_BCS
59 #define CONFIG_SPI_MASTER_DELAY_BCS 0
60 #endif
61 
63 #ifndef CONFIG_SPI_MASTER_BITS_PER_TRANSFER
64 #define CONFIG_SPI_MASTER_BITS_PER_TRANSFER SPI_CSR_BITS_8_BIT
65 #endif
66 
68 #ifndef CONFIG_SPI_MASTER_DELAY_BCT
69 #define CONFIG_SPI_MASTER_DELAY_BCT 0
70 #endif
71 
73 #ifndef CONFIG_SPI_MASTER_DELAY_BS
74 #define CONFIG_SPI_MASTER_DELAY_BS 0
75 #endif
76 
78 #ifndef CONFIG_SPI_MASTER_DUMMY
79 #define CONFIG_SPI_MASTER_DUMMY 0xFF
80 #endif
81 
86 #define SPI_CPHA (1 << 0)
87 
91 #define SPI_CPOL (1 << 1)
92 
96 #define SPI_MODE_0 0
97 
100 #define SPI_MODE_1 (SPI_CPHA)
101 
104 #define SPI_MODE_2 (SPI_CPOL)
105 
108 #define SPI_MODE_3 (SPI_CPOL | SPI_CPHA)
109 
110 #ifndef SPI_TYPE_DEFS
111 #define SPI_TYPE_DEFS
112 typedef uint8_t spi_flags_t;
114 
116 typedef uint32_t board_spi_select_id_t;
117 #endif
118 
120 struct spi_device {
122  board_spi_select_id_t id;
123 };
124 
130 extern void spi_master_init(Spi *p_spi);
131 
146 extern void spi_master_setup_device(Spi *p_spi, struct spi_device *device,
147  spi_flags_t flags, uint32_t baud_rate, board_spi_select_id_t sel_id);
148 
158 extern void spi_select_device(Spi *p_spi, struct spi_device *device);
159 
170 extern void spi_deselect_device(Spi *p_spi, struct spi_device *device);
171 
172 
179 static inline void spi_write_single(Spi *p_spi, uint8_t data)
180 {
181  spi_put(p_spi, (uint16_t)data);
182 }
183 
195 extern status_code_t spi_write_packet(Spi *p_spi,
196  const uint8_t *data, size_t len);
197 
204 static inline void spi_read_single(Spi *p_spi, uint8_t *data)
205 {
206  *data = (uint8_t)spi_get(p_spi);
207 }
208 
220 extern status_code_t spi_read_packet(Spi *p_spi, uint8_t *data, size_t len);
221 
232 extern status_code_t spi_transceive_packet(Spi *p_spi, uint8_t *tx_data, uint8_t *rx_data, size_t len);
233 
235 
236 #ifdef __cplusplus
237 }
238 #endif
239 
240 
242 #endif // _SPI_MASTER_H_
static void spi_read_single(Spi *p_spi, uint8_t *data)
Receive one byte from an SPI device.
status_code_t spi_transceive_packet(Spi *p_spi, uint8_t *tx_data, uint8_t *rx_data, size_t len)
Send and receive a sequence of bytes from an SPI device.
Definition: spi_master.c:256
void spi_select_device(Spi *p_spi, struct spi_device *device)
Select the given device on the SPI bus.
Definition: spi_master.c:132
Status code definitions.
Spi Master configuration.
board_spi_select_id_t id
Board specific select id.
void spi_deselect_device(Spi *p_spi, struct spi_device *device)
Deselect the given device on the SPI bus.
Definition: spi_master.c:155
Spi hardware registers.
status_code_t spi_read_packet(Spi *p_spi, uint8_t *data, size_t len)
Receive a sequence of bytes from an SPI device.
Definition: spi_master.c:215
Commonly used includes, types and macros.
USBInterfaceDescriptor data
void spi_master_init(Spi *p_spi)
Initialize the SPI in master mode.
Definition: spi_master.c:68
static void spi_write_single(Spi *p_spi, uint8_t data)
Write one byte to an SPI device.
static void spi_put(Spi *p_spi, uint16_t data)
Put one data to a SPI peripheral.
enum status_code status_code_t
Definition: status_codes.h:97
status_code_t spi_write_packet(Spi *p_spi, const uint8_t *data, size_t len)
Send a sequence of bytes to an SPI device.
Definition: spi_master.c:181
uint8_t spi_flags_t
SPI Flags Definition.
Polled SPI device definition.
static uint16_t spi_get(Spi *p_spi)
Get one data to a SPI peripheral.
void spi_master_setup_device(Spi *p_spi, struct spi_device *device, spi_flags_t flags, uint32_t baud_rate, board_spi_select_id_t sel_id)
Set up an SPI device.
Definition: spi_master.c:100
uint32_t board_spi_select_id_t
Board SPI Select Id Definition.


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:58