MAX32675 Peripheral Driver API
Peripheral Driver API for the MAX32675
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Modules
spi.h
1
6/******************************************************************************
7 *
8 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9 * Analog Devices, Inc.),
10 * Copyright (C) 2023-2024 Analog Devices, Inc.
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 ******************************************************************************/
25#ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32675_SPI_H_
26#define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32675_SPI_H_
27
28/***** includes *******/
29#include "spi_regs.h"
30#include "mxc_sys.h"
31#include "mxc_assert.h"
32#include "gpio.h"
33#include "mxc_pins.h"
34#include "mxc_lock.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
46/***** Definitions *****/
47
68typedef enum {
74
86typedef enum {
92
93typedef struct _mxc_spi_req_t mxc_spi_req_t;
94
101typedef void (*spi_complete_cb_t)(void *req, int result);
102
111 int ssIdx;
113 uint8_t *txData;
117 uint8_t *rxData;
121 uint32_t txLen;
122 uint32_t rxLen;
123 uint32_t txCnt;
124 uint32_t rxCnt;
125
127};
128
129/* ************************************************************************* */
130/* Control/Configuration functions */
131/* ************************************************************************* */
132
167int MXC_SPI_Init(mxc_spi_regs_t *spi, int masterMode, int quadModeUsed, int numSlaves,
168 unsigned ssPolarity, unsigned int hz);
169
178
192
201
213int MXC_SPI_SetFrequency(mxc_spi_regs_t *spi, unsigned int hz);
214
225
234int MXC_SPI_SetDataSize(mxc_spi_regs_t *spi, int dataSize);
235
244
245/* ************************************************************************* */
246/* Low-level functions */
247/* ************************************************************************* */
248
259int MXC_SPI_SetSlave(mxc_spi_regs_t *spi, int ssIdx);
260
271
281
290
300
309
323
334
345
355unsigned int MXC_SPI_ReadRXFIFO(mxc_spi_regs_t *spi, unsigned char *bytes, unsigned int len);
356
365
375unsigned int MXC_SPI_WriteTXFIFO(mxc_spi_regs_t *spi, unsigned char *bytes, unsigned int len);
376
385
392
399
417int MXC_SPI_SetRXThreshold(mxc_spi_regs_t *spi, unsigned int numBytes);
418
427
445int MXC_SPI_SetTXThreshold(mxc_spi_regs_t *spi, unsigned int numBytes);
446
455
467
477
487void MXC_SPI_EnableInt(mxc_spi_regs_t *spi, unsigned int mask);
488
498void MXC_SPI_DisableInt(mxc_spi_regs_t *spi, unsigned int mask);
499
500/* ************************************************************************* */
501/* Transaction level functions */
502/* ************************************************************************* */
503
527int MXC_SPI_MasterTransaction(mxc_spi_req_t *req);
528
539int MXC_SPI_MasterTransactionAsync(mxc_spi_req_t *req);
540
556int MXC_SPI_MasterTransactionDMA(mxc_spi_req_t *req);
557
573int MXC_SPI_SlaveTransaction(mxc_spi_req_t *req);
574
585int MXC_SPI_SlaveTransactionAsync(mxc_spi_req_t *req);
586
602int MXC_SPI_SlaveTransactionDMA(mxc_spi_req_t *req);
603
615int MXC_SPI_SetDefaultTXData(mxc_spi_regs_t *spi, unsigned int defaultTXData);
616
627
638
650
653#ifdef __cplusplus
654}
655#endif
656
657#endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32675_SPI_H_
Definition: spi_regs.h:76
uint8_t * txData
Definition: spi.h:113
uint32_t rxLen
Number of bytes to be stored in rxData.
Definition: spi.h:122
uint32_t rxCnt
Number of bytes stored in rxData.
Definition: spi.h:124
int ssIdx
Slave select line to use (Master only, ignored in slave mode)
Definition: spi.h:111
mxc_spi_regs_t * spi
Point to SPI registers.
Definition: spi.h:110
spi_complete_cb_t completeCB
Pointer to function called when transaction is complete.
Definition: spi.h:126
uint32_t txCnt
Number of bytes actually transmitted from txData.
Definition: spi.h:123
uint8_t * rxData
Definition: spi.h:117
uint32_t txLen
Number of bytes to be sent from txData.
Definition: spi.h:121
int ssDeassert
1 - Deassert SS at end of transaction, 0 - leave SS asserted
Definition: spi.h:112
int MXC_SPI_SetFrequency(mxc_spi_regs_t *spi, unsigned int hz)
Set the frequency of the SPI interface.
unsigned int MXC_SPI_GetFlags(mxc_spi_regs_t *spi)
Gets the interrupt flags that are currently set.
int MXC_SPI_GetSlave(mxc_spi_regs_t *spi)
Gets the slave select (SS) line used for transmissions.
unsigned int MXC_SPI_GetTXFIFOAvailable(mxc_spi_regs_t *spi)
Get the amount of free space available in the transmit FIFO.
void MXC_SPI_ClearFlags(mxc_spi_regs_t *spi)
Clears the interrupt flags that are currently set.
void MXC_SPI_EnableInt(mxc_spi_regs_t *spi, unsigned int mask)
Enables specific interrupts.
unsigned int MXC_SPI_ReadRXFIFO(mxc_spi_regs_t *spi, unsigned char *bytes, unsigned int len)
Unloads bytes from the receive FIFO.
void MXC_SPI_DisableInt(mxc_spi_regs_t *spi, unsigned int mask)
Disables specific interrupts.
int MXC_SPI_SetRXThreshold(mxc_spi_regs_t *spi, unsigned int numBytes)
Set the receive threshold level.
int MXC_SPI_SetWidth(mxc_spi_regs_t *spi, mxc_spi_width_t spiWidth)
Sets the SPI width used for transmissions.
int MXC_SPI_SetSlave(mxc_spi_regs_t *spi, int ssIdx)
Sets the slave select (SS) line used for transmissions.
int MXC_SPI_GetDataSize(mxc_spi_regs_t *spi)
Gets the number of bits per character.
unsigned int MXC_SPI_GetTXThreshold(mxc_spi_regs_t *spi)
Get the current transmit threshold level.
int MXC_SPI_GetPeripheralClock(mxc_spi_regs_t *spi)
Returns the frequency of the clock used as the bit rate generator for a given SPI instance.
int MXC_SPI_SetDataSize(mxc_spi_regs_t *spi, int dataSize)
Sets the number of bits per character.
int MXC_SPI_ReadyForSleep(mxc_spi_regs_t *spi)
Checks if the given SPI bus can be placed in sleep mode.
mxc_spi_mode_t MXC_SPI_GetMode(mxc_spi_regs_t *spi)
Gets the spi mode.
unsigned int MXC_SPI_GetRXFIFOAvailable(mxc_spi_regs_t *spi)
Get the number of bytes currently available in the receive FIFO.
mxc_spi_mode_t
The list of SPI modes.
Definition: spi.h:86
int MXC_SPI_SlaveTransactionAsync(mxc_spi_req_t *req)
Setup an interrupt-driven SPI transaction.
unsigned int MXC_SPI_GetFrequency(mxc_spi_regs_t *spi)
Get the frequency of the SPI interface.
void MXC_SPI_ClearTXFIFO(mxc_spi_regs_t *spi)
Removes and discards all bytes currently in the transmit FIFO.
int MXC_SPI_MasterTransactionAsync(mxc_spi_req_t *req)
Setup an interrupt-driven SPI transaction.
mxc_spi_width_t
The list of SPI Widths supported.
Definition: spi.h:68
int MXC_SPI_SetTXThreshold(mxc_spi_regs_t *spi, unsigned int numBytes)
Set the transmit threshold level.
int MXC_SPI_Shutdown(mxc_spi_regs_t *spi)
Disable and shutdown SPI peripheral.
int MXC_SPI_SlaveTransactionDMA(mxc_spi_req_t *req)
Setup a DMA driven SPI transaction.
mxc_spi_width_t MXC_SPI_GetWidth(mxc_spi_regs_t *spi)
Gets the SPI width used for transmissions.
int MXC_SPI_SlaveTransaction(mxc_spi_req_t *req)
Performs a blocking SPI transaction.
int MXC_SPI_SetMode(mxc_spi_regs_t *spi, mxc_spi_mode_t spiMode)
Sets the spi mode using clock polarity and clock phase.
void MXC_SPI_AsyncHandler(mxc_spi_regs_t *spi)
The processing function for asynchronous transactions.
int MXC_SPI_GetActive(mxc_spi_regs_t *spi)
Checks the SPI Peripheral for an ongoing transmission.
void MXC_SPI_ClearRXFIFO(mxc_spi_regs_t *spi)
Removes and discards all bytes currently in the receive FIFO.
int MXC_SPI_AbortTransmission(mxc_spi_regs_t *spi)
Aborts an ongoing SPI Transmission.
unsigned int MXC_SPI_WriteTXFIFO(mxc_spi_regs_t *spi, unsigned char *bytes, unsigned int len)
Loads bytes into the transmit FIFO.
int MXC_SPI_SetDefaultTXData(mxc_spi_regs_t *spi, unsigned int defaultTXData)
Sets the TX data to transmit as a 'dummy' byte.
void MXC_SPI_AbortAsync(mxc_spi_regs_t *spi)
Abort any asynchronous requests in progress.
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.
unsigned int MXC_SPI_GetRXThreshold(mxc_spi_regs_t *spi)
Get the current receive threshold level.
int MXC_SPI_StartTransmission(mxc_spi_regs_t *spi)
Starts a SPI Transmission.
int MXC_SPI_MasterTransactionDMA(mxc_spi_req_t *req)
Setup a DMA driven SPI transaction.
int MXC_SPI_MasterTransaction(mxc_spi_req_t *req)
Performs a blocking SPI transaction.
void(* spi_complete_cb_t)(void *req, int result)
The callback routine used to indicate the transaction has terminated.
Definition: spi.h:101
void MXC_SPI_HWSSControl(mxc_spi_regs_t *spi, int state)
Enable/Disable HW CS control feature.
@ SPI_MODE_0
clock phase = 0, clock polarity = 0
Definition: spi.h:87
@ SPI_MODE_2
clock phase = 1, clock polarity = 0
Definition: spi.h:89
@ SPI_MODE_1
clock phase = 0, clock polarity = 1
Definition: spi.h:88
@ SPI_MODE_3
clock phase = 1, clock polarity = 1
Definition: spi.h:90
@ SPI_WIDTH_QUAD
4 Data lines, half duplex
Definition: spi.h:72
@ SPI_WIDTH_STANDARD
MISO/MOSI, full duplex.
Definition: spi.h:70
@ SPI_WIDTH_3WIRE
1 Data line, half duplex
Definition: spi.h:69
@ SPI_WIDTH_DUAL
2 Data lines, half duplex
Definition: spi.h:71
The information required to perform a complete SPI transaction.
Definition: spi.h:109
Registers, Bit Masks and Bit Positions for the SPI Peripheral Module.