MAX32675 Peripheral Driver API
Peripheral Driver API for the MAX32675
spi.h
1 
6 /* ****************************************************************************
7  * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the "Software"),
11  * to deal in the Software without restriction, including without limitation
12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  * and/or sell copies of the Software, and to permit persons to whom the
14  * Software is furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included
17  * in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
23  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  *
27  * Except as contained in this notice, the name of Maxim Integrated
28  * Products, Inc. shall not be used except as stated in the Maxim Integrated
29  * Products, Inc. Branding Policy.
30  *
31  * The mere transfer of this software does not imply any licenses
32  * of trade secrets, proprietary technology, copyrights, patents,
33  * trademarks, maskwork rights, or any other form of intellectual
34  * property whatsoever. Maxim Integrated Products, Inc. retains all
35  * ownership rights.
36  *
37  *************************************************************************** */
38 #ifndef _SPI_H_
39 #define _SPI_H_
40 
41 /***** includes *******/
42 #include "spi_regs.h"
43 #include "mxc_sys.h"
44 #include "mxc_assert.h"
45 #include "gpio.h"
46 #include "mxc_pins.h"
47 #include "mxc_lock.h"
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
59 /***** Definitions *****/
60 
81 typedef enum {
87 
88 typedef struct _mxc_spi_req_t mxc_spi_req_t;
89 
96 typedef void (*spi_complete_cb_t) (void * req, int result);
97 
106  int ssIdx;
108  uint8_t *txData;
109  uint8_t *rxData;
113  uint32_t txLen;
117  uint32_t rxLen;
118  uint32_t txCnt;
119  uint32_t rxCnt;
120 
122 };
123 
124 /* ************************************************************************* */
125 /* Control/Configuration functions */
126 /* ************************************************************************* */
127 
157 int MXC_SPI_Init (mxc_spi_regs_t* spi, int masterMode, int quadModeUsed, int numSlaves,
158  unsigned ssPolarity, unsigned int hz);
159 
168 
182 
194 int MXC_SPI_SetFrequency (mxc_spi_regs_t* spi, unsigned int hz);
195 
205 unsigned int MXC_SPI_GetFrequency (mxc_spi_regs_t* spi);
206 
215 int MXC_SPI_SetDataSize (mxc_spi_regs_t* spi, int dataSize);
216 
225 
226 
227 /* ************************************************************************* */
228 /* Low-level functions */
229 /* ************************************************************************* */
230 
241 int MXC_SPI_SetSlave (mxc_spi_regs_t* spi, int ssIdx);
242 
253 
262 int MXC_SPI_SetWidth (mxc_spi_regs_t* spi, mxc_spi_width_t spiWidth);
263 
272 
286 
297 
308 
318 unsigned int MXC_SPI_ReadRXFIFO (mxc_spi_regs_t* spi, unsigned char* bytes,
319  unsigned int len);
320 
328 unsigned int MXC_SPI_GetRXFIFOAvailable (mxc_spi_regs_t* spi);
329 
339 unsigned int MXC_SPI_WriteTXFIFO (mxc_spi_regs_t* spi, unsigned char* bytes,
340  unsigned int len);
341 
349 unsigned int MXC_SPI_GetTXFIFOAvailable (mxc_spi_regs_t* spi);
350 
357 
364 
382 int MXC_SPI_SetRXThreshold (mxc_spi_regs_t* spi, unsigned int numBytes);
383 
391 unsigned int MXC_SPI_GetRXThreshold (mxc_spi_regs_t* spi);
392 
410 int MXC_SPI_SetTXThreshold (mxc_spi_regs_t* spi, unsigned int numBytes);
411 
419 unsigned int MXC_SPI_GetTXThreshold (mxc_spi_regs_t* spi);
420 
431 unsigned int MXC_SPI_GetFlags (mxc_spi_regs_t* spi);
432 
442 
452 void MXC_SPI_EnableInt (mxc_spi_regs_t* spi, unsigned int mask);
453 
463 void MXC_SPI_DisableInt (mxc_spi_regs_t* spi, unsigned int mask);
464 
465 /* ************************************************************************* */
466 /* Transaction level functions */
467 /* ************************************************************************* */
468 
492 int MXC_SPI_MasterTransaction (mxc_spi_req_t* req);
493 
504 int MXC_SPI_MasterTransactionAsync (mxc_spi_req_t* req);
505 
521 int MXC_SPI_MasterTransactionDMA (mxc_spi_req_t* req);
522 
538 int MXC_SPI_SlaveTransaction (mxc_spi_req_t* req);
539 
550 int MXC_SPI_SlaveTransactionAsync (mxc_spi_req_t* req);
551 
567 int MXC_SPI_SlaveTransactionDMA (mxc_spi_req_t* req);
568 
580 int MXC_SPI_SetDefaultTXData (mxc_spi_regs_t* spi, unsigned int defaultTXData);
581 
592 
603 
606 #ifdef __cplusplus
607 }
608 #endif
609 
610 #endif /* _PT_H_ */
MXC_SPI_GetDataSize
int MXC_SPI_GetDataSize(mxc_spi_regs_t *spi)
Gets the number of bits per character.
MXC_SPI_Shutdown
int MXC_SPI_Shutdown(mxc_spi_regs_t *spi)
Disable and shutdown SPI peripheral.
SPI_WIDTH_STANDARD
@ SPI_WIDTH_STANDARD
MISO/MOSI, full duplex.
Definition: spi.h:83
MXC_SPI_SetSlave
int MXC_SPI_SetSlave(mxc_spi_regs_t *spi, int ssIdx)
Sets the slave select (SS) line used for transmissions.
spi_complete_cb_t
void(* spi_complete_cb_t)(void *req, int result)
The callback routine used to indicate the transaction has terminated.
Definition: spi.h:96
_mxc_spi_req_t::txLen
uint32_t txLen
Number of bytes to be sent from txData.
Definition: spi.h:116
mxc_spi_regs_t
Definition: spi_regs.h:88
MXC_SPI_SlaveTransactionDMA
int MXC_SPI_SlaveTransactionDMA(mxc_spi_req_t *req)
Setup a DMA driven SPI transaction.
MXC_SPI_GetRXThreshold
unsigned int MXC_SPI_GetRXThreshold(mxc_spi_regs_t *spi)
Get the current receive threshold level.
_mxc_spi_req_t::txData
uint8_t * txData
Definition: spi.h:108
MXC_SPI_AbortTransmission
int MXC_SPI_AbortTransmission(mxc_spi_regs_t *spi)
Aborts an ongoing SPI Transmission.
SPI_WIDTH_QUAD
@ SPI_WIDTH_QUAD
4 Data lines, half duplex
Definition: spi.h:85
MXC_SPI_SlaveTransactionAsync
int MXC_SPI_SlaveTransactionAsync(mxc_spi_req_t *req)
Setup an interrupt-driven SPI transaction.
_mxc_spi_req_t::completeCB
spi_complete_cb_t completeCB
Pointer to function called when transaction is complete.
Definition: spi.h:121
MXC_SPI_SetDataSize
int MXC_SPI_SetDataSize(mxc_spi_regs_t *spi, int dataSize)
Sets the number of bits per character.
MXC_SPI_GetTXFIFOAvailable
unsigned int MXC_SPI_GetTXFIFOAvailable(mxc_spi_regs_t *spi)
Get the amount of free space available in the transmit FIFO.
MXC_SPI_SetDefaultTXData
int MXC_SPI_SetDefaultTXData(mxc_spi_regs_t *spi, unsigned int defaultTXData)
Sets the TX data to transmit as a 'dummy' byte.
_mxc_spi_req_t::rxLen
uint32_t rxLen
Number of bytes to be stored in rxData.
Definition: spi.h:117
MXC_SPI_GetRXFIFOAvailable
unsigned int MXC_SPI_GetRXFIFOAvailable(mxc_spi_regs_t *spi)
Get the number of bytes currently available in the receive FIFO.
MXC_SPI_ReadyForSleep
int MXC_SPI_ReadyForSleep(mxc_spi_regs_t *spi)
Checks if the given SPI bus can be placed in sleep mode.
_mxc_spi_req_t::ssIdx
int ssIdx
Slave select line to use (Master only, ignored in slave mode)
Definition: spi.h:106
MXC_SPI_GetSlave
int MXC_SPI_GetSlave(mxc_spi_regs_t *spi)
Gets the slave select (SS) line used for transmissions.
MXC_SPI_AsyncHandler
void MXC_SPI_AsyncHandler(mxc_spi_regs_t *spi)
The processing function for asynchronous transactions.
MXC_SPI_ClearTXFIFO
void MXC_SPI_ClearTXFIFO(mxc_spi_regs_t *spi)
Removes and discards all bytes currently in the transmit FIFO.
MXC_SPI_WriteTXFIFO
unsigned int MXC_SPI_WriteTXFIFO(mxc_spi_regs_t *spi, unsigned char *bytes, unsigned int len)
Loads bytes into the transmit FIFO.
_mxc_spi_req_t::ssDeassert
int ssDeassert
1 - Deassert SS at end of transaction, 0 - leave SS asserted
Definition: spi.h:107
MXC_SPI_SetRXThreshold
int MXC_SPI_SetRXThreshold(mxc_spi_regs_t *spi, unsigned int numBytes)
Set the receive threshold level.
MXC_SPI_GetTXThreshold
unsigned int MXC_SPI_GetTXThreshold(mxc_spi_regs_t *spi)
Get the current transmit threshold level.
MXC_SPI_MasterTransactionDMA
int MXC_SPI_MasterTransactionDMA(mxc_spi_req_t *req)
Setup a DMA driven SPI transaction.
MXC_SPI_EnableInt
void MXC_SPI_EnableInt(mxc_spi_regs_t *spi, unsigned int mask)
Enables specific interrupts.
MXC_SPI_SetTXThreshold
int MXC_SPI_SetTXThreshold(mxc_spi_regs_t *spi, unsigned int numBytes)
Set the transmit threshold level.
MXC_SPI_GetFlags
unsigned int MXC_SPI_GetFlags(mxc_spi_regs_t *spi)
Gets the interrupt flags that are currently set.
MXC_SPI_ReadRXFIFO
unsigned int MXC_SPI_ReadRXFIFO(mxc_spi_regs_t *spi, unsigned char *bytes, unsigned int len)
Unloads bytes from the receive FIFO.
MXC_SPI_GetFrequency
unsigned int MXC_SPI_GetFrequency(mxc_spi_regs_t *spi)
Get the frequency of the SPI interface.
MXC_SPI_MasterTransaction
int MXC_SPI_MasterTransaction(mxc_spi_req_t *req)
Performs a blocking SPI transaction.
_mxc_spi_req_t
The information required to perform a complete SPI transaction.
Definition: spi.h:104
mxc_spi_width_t
mxc_spi_width_t
The list of SPI Widths supported.
Definition: spi.h:81
MXC_SPI_SlaveTransaction
int MXC_SPI_SlaveTransaction(mxc_spi_req_t *req)
Performs a blocking SPI transaction.
SPI_WIDTH_DUAL
@ SPI_WIDTH_DUAL
2 Data lines, half duplex
Definition: spi.h:84
SPI_WIDTH_3WIRE
@ SPI_WIDTH_3WIRE
1 Data line, half duplex
Definition: spi.h:82
MXC_SPI_GetWidth
mxc_spi_width_t MXC_SPI_GetWidth(mxc_spi_regs_t *spi)
Gets the SPI width used for transmissions.
MXC_SPI_GetActive
int MXC_SPI_GetActive(mxc_spi_regs_t *spi)
Checks the SPI Peripheral for an ongoing transmission.
MXC_SPI_Init
int MXC_SPI_Init(mxc_spi_regs_t *spi, int masterMode, int quadModeUsed, int numSlaves, unsigned ssPolarity, unsigned int hz)
Initialize and enable SPI peripheral.
_mxc_spi_req_t::rxData
uint8_t * rxData
Definition: spi.h:112
MXC_SPI_ClearRXFIFO
void MXC_SPI_ClearRXFIFO(mxc_spi_regs_t *spi)
Removes and discards all bytes currently in the receive FIFO.
MXC_SPI_SetWidth
int MXC_SPI_SetWidth(mxc_spi_regs_t *spi, mxc_spi_width_t spiWidth)
Sets the SPI width used for transmissions.
MXC_SPI_StartTransmission
int MXC_SPI_StartTransmission(mxc_spi_regs_t *spi)
Starts a SPI Transmission.
_mxc_spi_req_t::rxCnt
uint32_t rxCnt
Number of bytes stored in rxData.
Definition: spi.h:119
MXC_SPI_DisableInt
void MXC_SPI_DisableInt(mxc_spi_regs_t *spi, unsigned int mask)
Disables specific interrupts.
MXC_SPI_MasterTransactionAsync
int MXC_SPI_MasterTransactionAsync(mxc_spi_req_t *req)
Setup an interrupt-driven SPI transaction.
_mxc_spi_req_t::txCnt
uint32_t txCnt
Number of bytes actually transmitted from txData.
Definition: spi.h:118
MXC_SPI_SetFrequency
int MXC_SPI_SetFrequency(mxc_spi_regs_t *spi, unsigned int hz)
Set the frequency of the SPI interface.
_mxc_spi_req_t::spi
mxc_spi_regs_t * spi
Point to SPI registers.
Definition: spi.h:105
MXC_SPI_AbortAsync
void MXC_SPI_AbortAsync(mxc_spi_regs_t *spi)
Abort any asynchronous requests in progress.
MXC_SPI_ClearFlags
void MXC_SPI_ClearFlags(mxc_spi_regs_t *spi)
Clears the interrupt flags that are currently set.