MAX32655 Peripheral Driver API
Peripheral Driver API for the MAX32655
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  * $Date$
38  * $Revision$
39  *
40  *************************************************************************** */
41 #ifndef _SPI_H_
42 #define _SPI_H_
43 
44 /***** includes *******/
45 #include <stdbool.h>
46 #include "spi_regs.h"
47 #include "mxc_sys.h"
48 #include "mxc_assert.h"
49 #include "gpio.h"
50 #include "mxc_pins.h"
51 #include "mxc_lock.h"
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
63 /***** Definitions *****/
64 
85 typedef enum {
91 
92 typedef struct _mxc_spi_pins_t mxc_spi_pins_t;
93 
94 struct _mxc_spi_pins_t {
100  bool clock;
101  bool ss0;
102  bool ss1;
103  bool ss2;
104  bool miso;
105  bool mosi;
106  bool sdio2;
107  bool sdio3;
108  /*** @} */ // end of required group
109 };
110 
111 typedef struct _mxc_spi_req_t mxc_spi_req_t;
118 typedef void (*spi_complete_t) (void * req, int result);
119 
131  int ssIdx;
133  uint8_t *txData;
134  uint8_t *rxData;
138  uint32_t txLen;
142  uint32_t rxLen;
143  uint32_t txCnt;
144  uint32_t rxCnt;
145  /*** @} */ // end of required group
146 
151  /*** @} */ // end of async group
152 };
153 
154 /* ************************************************************************* */
155 /* Control/Configuration functions */
156 /* ************************************************************************* */
157 
187 int MXC_SPI_Init (mxc_spi_regs_t* spi, int masterMode, int quadModeUsed, int numSlaves,
188  unsigned ssPolarity, unsigned int hz, mxc_spi_pins_t pins);
189 
198 
212 
224 int MXC_SPI_SetFrequency (mxc_spi_regs_t* spi, unsigned int hz);
225 
235 unsigned int MXC_SPI_GetFrequency (mxc_spi_regs_t* spi);
236 
245 int MXC_SPI_SetDataSize (mxc_spi_regs_t* spi, int dataSize);
246 
255 
256 
257 /* ************************************************************************* */
258 /* Low-level functions */
259 /* ************************************************************************* */
260 
271 int MXC_SPI_SetSlave (mxc_spi_regs_t* spi, int ssIdx);
272 
283 
292 int MXC_SPI_SetWidth (mxc_spi_regs_t* spi, mxc_spi_width_t spiWidth);
293 
301 mxc_spi_width_t MXC_SPI_GetWidth (mxc_spi_regs_t* spi);
315 
326 
337 
347 unsigned int MXC_SPI_ReadRXFIFO (mxc_spi_regs_t* spi, unsigned char* bytes,
348  unsigned int len);
349 
357 unsigned int MXC_SPI_GetRXFIFOAvailable (mxc_spi_regs_t* spi);
358 
368 unsigned int MXC_SPI_WriteTXFIFO (mxc_spi_regs_t* spi, unsigned char* bytes,
369  unsigned int len);
370 
378 unsigned int MXC_SPI_GetTXFIFOAvailable (mxc_spi_regs_t* spi);
379 
386 
393 
411 int MXC_SPI_SetRXThreshold (mxc_spi_regs_t* spi, unsigned int numBytes);
412 
420 unsigned int MXC_SPI_GetRXThreshold (mxc_spi_regs_t* spi);
421 
439 int MXC_SPI_SetTXThreshold (mxc_spi_regs_t* spi, unsigned int numBytes);
440 
448 unsigned int MXC_SPI_GetTXThreshold (mxc_spi_regs_t* spi);
449 
460 unsigned int MXC_SPI_GetFlags (mxc_spi_regs_t* spi);
461 
472 
484 void MXC_SPI_EnableInt (mxc_spi_regs_t* spi, unsigned int intEn);
485 
497 void MXC_SPI_DisableInt (mxc_spi_regs_t* spi, unsigned int intDis);
498 
499 /* ************************************************************************* */
500 /* Transaction level functions */
501 /* ************************************************************************* */
502 
526 int MXC_SPI_MasterTransaction (mxc_spi_req_t* req);
527 
538 int MXC_SPI_MasterTransactionAsync (mxc_spi_req_t* req);
539 
540 
556 int MXC_SPI_MasterTransactionDMA (mxc_spi_req_t* req);
557 
558 
574 int MXC_SPI_SlaveTransaction (mxc_spi_req_t* req);
575 
576 
587 int MXC_SPI_SlaveTransactionAsync (mxc_spi_req_t* req);
588 
589 
605 int MXC_SPI_SlaveTransactionDMA (mxc_spi_req_t* req);
606 
607 
619 int MXC_SPI_SetDefaultTXData (mxc_spi_regs_t* spi, unsigned int defaultTXData);
620 
631 
644 #ifdef __cplusplus
645 }
646 #endif
647 
648 #endif /* _SPI_H_ */
int MXC_SPI_SlaveTransactionAsync(mxc_spi_req_t *req)
Setup an interrupt-driven SPI transaction.
int MXC_SPI_SlaveTransactionDMA(mxc_spi_req_t *req)
Setup a DMA driven SPI transaction.
void MXC_SPI_EnableInt(mxc_spi_regs_t *spi, unsigned int intEn)
Enables specific interrupts.
Definition: spi_regs.h:88
4 Data lines, half duplex
Definition: spi.h:89
void MXC_SPI_DisableInt(mxc_spi_regs_t *spi, unsigned int intDis)
Disables specific interrupts.
int MXC_SPI_GetSlave(mxc_spi_regs_t *spi)
Gets the slave select (SS) line used for transmissions.
uint8_t * txData
Definition: spi.h:133
int MXC_SPI_ReadyForSleep(mxc_spi_regs_t *spi)
Checks if the given SPI bus can be placed in sleep mode.
bool ss2
Slave select pin 2.
Definition: spi.h:103
void MXC_SPI_AbortAsync(mxc_spi_regs_t *spi)
Abort any asynchronous requests in progress.
spi_complete_t completeCB
Pointer to function called when transaction is complete.
Definition: spi.h:150
int MXC_SPI_GetDataSize(mxc_spi_regs_t *spi)
Gets the number of bits per character.
bool clock
Clock pin.
Definition: spi.h:100
uint32_t txCnt
Number of bytes actually transmitted from txData.
Definition: spi.h:143
int MXC_SPI_Init(mxc_spi_regs_t *spi, int masterMode, int quadModeUsed, int numSlaves, unsigned ssPolarity, unsigned int hz, mxc_spi_pins_t pins)
Initialize and enable SPI peripheral.
bool sdio3
SDIO3 pin.
Definition: spi.h:107
void(* spi_complete_t)(void *req, int result)
The callback routine used to indicate the transaction has terminated.
Definition: spi.h:118
int MXC_SPI_SetSlave(mxc_spi_regs_t *spi, int ssIdx)
Sets the slave select (SS) line used for transmissions.
void MXC_SPI_ClearFlags(mxc_spi_regs_t *spi)
Clears the interrupt flags that are currently set.
int MXC_SPI_SetDefaultTXData(mxc_spi_regs_t *spi, unsigned int defaultTXData)
Sets the TX data to transmit as a &#39;dummy&#39; byte.
1 Data line, half duplex
Definition: spi.h:86
int MXC_SPI_SetDataSize(mxc_spi_regs_t *spi, int dataSize)
Sets the number of bits per character.
void MXC_SPI_AsyncHandler(mxc_spi_regs_t *spi)
The processing function for asynchronous transactions.
bool sdio2
SDIO2 pin.
Definition: spi.h:106
mxc_spi_regs_t * spi
Point to SPI registers.
Definition: spi.h:130
int MXC_SPI_SetWidth(mxc_spi_regs_t *spi, mxc_spi_width_t spiWidth)
Sets the SPI width used for transmissions.
2 Data lines, half duplex
Definition: spi.h:88
int MXC_SPI_MasterTransactionDMA(mxc_spi_req_t *req)
Setup a DMA driven SPI transaction.
int MXC_SPI_Shutdown(mxc_spi_regs_t *spi)
Disable and shutdown SPI peripheral.
bool mosi
mosi pin
Definition: spi.h:105
int MXC_SPI_SetFrequency(mxc_spi_regs_t *spi, unsigned int hz)
Set the frequency of the SPI interface.
unsigned int MXC_SPI_GetRXFIFOAvailable(mxc_spi_regs_t *spi)
Get the number of bytes currently available in the receive FIFO.
mxc_spi_width_t MXC_SPI_GetWidth(mxc_spi_regs_t *spi)
Gets the SPI width used for transmissions.
void MXC_SPI_ClearRXFIFO(mxc_spi_regs_t *spi)
Removes and discards all bytes currently in the receive FIFO.
int MXC_SPI_SetRXThreshold(mxc_spi_regs_t *spi, unsigned int numBytes)
Set the receive threshold level.
unsigned int MXC_SPI_GetRXThreshold(mxc_spi_regs_t *spi)
Get the current receive threshold level.
bool ss1
Slave select pin 1.
Definition: spi.h:102
int MXC_SPI_StartTransmission(mxc_spi_regs_t *spi)
Starts a SPI Transmission.
int MXC_SPI_MasterTransactionAsync(mxc_spi_req_t *req)
Setup an interrupt-driven SPI transaction.
int ssDeassert
1 - Deassert SS at end of transaction, 0 - leave SS asserted
Definition: spi.h:132
unsigned int MXC_SPI_ReadRXFIFO(mxc_spi_regs_t *spi, unsigned char *bytes, unsigned int len)
Unloads bytes from the receive FIFO.
unsigned int MXC_SPI_GetTXThreshold(mxc_spi_regs_t *spi)
Get the current transmit threshold level.
unsigned int MXC_SPI_GetTXFIFOAvailable(mxc_spi_regs_t *spi)
Get the amount of free space available in the transmit FIFO.
unsigned int MXC_SPI_GetFlags(mxc_spi_regs_t *spi)
Gets the interrupt flags that are currently set.
MISO/MOSI, full duplex.
Definition: spi.h:87
int MXC_SPI_SlaveTransaction(mxc_spi_req_t *req)
Performs a blocking SPI transaction.
unsigned int MXC_SPI_WriteTXFIFO(mxc_spi_regs_t *spi, unsigned char *bytes, unsigned int len)
Loads bytes into the transmit FIFO.
void MXC_SPI_ClearTXFIFO(mxc_spi_regs_t *spi)
Removes and discards all bytes currently in the transmit FIFO.
uint32_t rxCnt
Number of bytes stored in rxData.
Definition: spi.h:144
unsigned int MXC_SPI_GetFrequency(mxc_spi_regs_t *spi)
Get the frequency of the SPI interface.
uint32_t rxLen
Number of bytes to be stored in rxData.
Definition: spi.h:142
int MXC_SPI_MasterTransaction(mxc_spi_req_t *req)
Performs a blocking SPI transaction.
int MXC_SPI_GetActive(mxc_spi_regs_t *spi)
Checks the SPI Peripheral for an ongoing transmission.
The information required to perform a complete SPI transaction.
Definition: spi.h:125
int ssIdx
Slave select line to use (Master only, ignored in slave mode)
Definition: spi.h:131
int MXC_SPI_AbortTransmission(mxc_spi_regs_t *spi)
Aborts an ongoing SPI Transmission.
int MXC_SPI_SetTXThreshold(mxc_spi_regs_t *spi, unsigned int numBytes)
Set the transmit threshold level.
bool miso
miso pin
Definition: spi.h:104
bool ss0
Slave select pin 0.
Definition: spi.h:101
mxc_spi_width_t
The list of SPI Widths supported.
Definition: spi.h:85