MAX32665 SDK Documentation  0.2
Software Development Kit Overview and API Documentation
spi.h
1 
7 /* ****************************************************************************
8  * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and associated documentation files (the "Software"),
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included
18  * in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
24  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  * OTHER DEALINGS IN THE SOFTWARE.
27  *
28  * Except as contained in this notice, the name of Maxim Integrated
29  * Products, Inc. shall not be used except as stated in the Maxim Integrated
30  * Products, Inc. Branding Policy.
31  *
32  * The mere transfer of this software does not imply any licenses
33  * of trade secrets, proprietary technology, copyrights, patents,
34  * trademarks, maskwork rights, or any other form of intellectual
35  * property whatsoever. Maxim Integrated Products, Inc. retains all
36  * ownership rights.
37  *
38  * $Date: 2018-11-05 13:40:08 -0600 (Mon, 05 Nov 2018) $
39  * $Revision: 38949 $
40  *
41  *************************************************************************** */
42 #ifndef _SPI_H_
43 #define _SPI_H_
44 
45 /* **** Includes **** */
46 #include "spi17y_regs.h"
47 #include "mxc_sys.h"
48 #include "spi17y.h"
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
60 /* **** Definitions **** */
61 
65 typedef enum {
66  SPI0, // SPI17Y instance 0,
67  SPI1, // SPI17Y instance 1
68  SPI2, // SPI17Y instance 2
69 }spi_type;
70 
71 #define MXC_SPI0 MXC_SPI17Y0 // SPI17Y instance 0,
72 #define MXC_SPI1 MXC_SPI17Y1 // SPI17Y instance 1
73 #define MXC_SPI2 MXC_SPI17Y2 // SPI17Y instance 2
74 
78 #define SPI0_IRQn SPI17Y0_IRQn
79 #define SPI1_IRQn SPI17Y1_IRQn
80 #define SPI2_IRQn SPI17Y2_IRQn
81 
82 
86 #define SPI_WIDTH_1 SPI17Y_WIDTH_1
87 #define SPI_WIDTH_2 SPI17Y_WIDTH_2
88 #define SPI_WIDTH_4 SPI17Y_WIDTH_4
93 #define SPI_POL_LOW SPI17Y_POL_LOW
94 #define SPI_POL_HIGH SPI17Y_POL_HIGH
96 typedef sys_cfg_spi17y_t sys_cfg_spi_t;
97 
98 
102 typedef union {
103  mxc_spi17y_regs_t spi17y_regs;
104 }spi_regs_t;
105 
106 
110 typedef struct spi_req spi_req_t;
111 
125 typedef void (*spi_callback_fn)(void * req, int error_code);
126 
133 struct spi_req {
134  uint8_t ssel;
135  uint8_t deass;
137  const void *tx_data;
138  void *rx_data;
140  unsigned len;
141  unsigned bits;
142  unsigned rx_num;
143  unsigned tx_num;
144  spi_callback_fn callback;
145 };
146 
147 
148 /* **** Function Prototypes **** */
149 
160 int SPI_Init(spi_type spi_name, unsigned int mode, unsigned int freq, sys_cfg_spi_t spi17y_cfg);
161 
171 int SPI_MasterTransAsync(spi_type spi_name, spi_req_t *req);
172 
181 int SPI_MasterTrans(spi_type spi_name, spi_req_t *req);
182 
191 int SPI_SlaveTransAsync(spi_type spi_name, spi_req_t *req);
192 
201 int SPI_SlaveTrans(spi_type spi_name, spi_req_t *req);
202 
210 int SPI_Shutdown(spi_type spi_name);
211 
212 
221 int SPI_AbortAsync(spi_type spi_name, spi_req_t *req);
222 
230 int SPI_Handler(spi_type spi_name);
231 
239 int SPI_Enable(spi_type spi_name);
240 
248 int SPI_Disable(spi_type spi_name);
249 
257 int SPI_Clear_fifo(spi_type spi_name);
258 
259 //-------------------------------------------------------------------------------------------
262 #ifdef __cplusplus
263 }
264 #endif
265 
266 #endif /* _SPI_H_ */
267 
268 
269 
spi17y_width_t width
Number of data lines to use, see spi17y_width_t.
Definition: spi.h:139
int SPI_Enable(spi_type spi_name)
Enable SPI.
unsigned bits
Number of bits in transfer unit (e.g.
Definition: spi.h:141
int SPI_AbortAsync(spi_type spi_name, spi_req_t *req)
Aborts an Asynchronous request.
int SPI_Disable(spi_type spi_name)
Disable SPI.
spi17y_sspol_t ssel_pol
Slave select line polarity.
Definition: spi.h:136
int SPI_SlaveTransAsync(spi_type spi_name, spi_req_t *req)
Asynchronously read/write SPI Slave data.
spi17y_width_t
Enumeration type for setting the number data lines to use for communication.
Definition: spi17y.h:66
int SPI_Clear_fifo(spi_type spi_name)
Clear the TX and RX FIFO.
const void * tx_data
Pointer to a buffer to transmit data from.
Definition: spi.h:137
int SPI_SlaveTrans(spi_type spi_name, spi_req_t *req)
Execute a slave transaction.
SPI17Y Configuration Object.
Definition: mxc_sys.h:177
int SPI_Init(spi_type spi_name, unsigned int mode, unsigned int freq, sys_cfg_spi_t spi17y_cfg)
Initialize the spi.
void * rx_data
Pointer to a buffer to store data received.
Definition: spi.h:138
spi_callback_fn callback
Callback function if desired, NULL otherwise.
Definition: spi.h:144
int SPI_MasterTransAsync(spi_type spi_name, spi_req_t *req)
Asynchronously read/write SPI Master data.
uint8_t deass
Non-zero to de-assert slave select after transaction.
Definition: spi.h:135
unsigned len
Number of transfer units to send from the tx_data buffer.
Definition: spi.h:140
spi17y_sspol_t
Enumeration type for setting the polarity of ss lines.
Definition: spi17y.h:75
Structure type to access the SPI17Y Registers.
Definition: spi17y_regs.h:88
Union consolidating SPI registers.
Definition: spi.h:102
unsigned tx_num
Number of bytes actually sent from the tx_data buffer.
Definition: spi.h:143
uint8_t ssel
Slave select line to use.
Definition: spi.h:134
Structure type representing a SPI Master Transaction request.
Definition: spi.h:133
int SPI_Shutdown(spi_type spi_name)
Shutdown SPI module.
int SPI_Handler(spi_type spi_name)
Execute SPI transaction based on interrupt handler.
unsigned rx_num
Number of bytes actually read into the rx_data buffer.
Definition: spi.h:142
int SPI_MasterTrans(spi_type spi_name, spi_req_t *req)
Execute a master transaction.
spi_type
Assigning SPI0 instances.
Definition: spi.h:65