Serial Peripheral Interface Reusable Driver v1.1
This project implements SPI reusable driver that can be adapted to various microcontrollers.
Loading...
Searching...
No Matches
spi_cfg.h File Reference

This module contains interface definitions for the SPI configuration. This is the header file for the definition of the interface for retrieving the Serial Peripheral interface configuration table. More...

#include <stdio.h>
Include dependency graph for spi_cfg.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SpiConfig_t
 

Macros

#define SPI_PORTS_NUMBER   4U
 

Enumerations

enum  SpiChannel_t {
  SPI_CHANNEL1 , SPI_CHANNEL2 , SPI_CHANNEL3 , SPI_CHANNEL4 ,
  SPI_MAX_CHANNEL
}
 
enum  SpiMode_t {
  SPI_MODE0 , SPI_MODE1 , SPI_MODE2 , SPI_MODE3 ,
  SPI_MAX_MODE
}
 
enum  SpiHierarchy_t { SPI_SLAVE , SPI_MASTER , SPI_MAX_HIERARCHY }
 
enum  SpiBaudRate_t {
  SPI_FPCLK2 , SPI_FPCLK4 , SPI_FPCLK8 , SPI_FPCLK16 ,
  SPI_FPCLK32 , SPI_FPCLK64 , SPI_FPCLK128 , SPI_FPCLK256 ,
  SPI_MAX_FPCLK
}
 
enum  SpiSlaveSelect_t { SPI_SOFTWARE_NSS , SPI_HARDWARE_NSS_ENABLED , SPI_HARDWARE_NSS_DISABLED , SPI_MAX_NSS }
 
enum  SpiFrameFormat_t { SPI_MSB , SPI_LSB , SPI_MAX_FF }
 
enum  SpiTypeTransfer_t { SPI_FULL_DUPLEX , SPI_RECEIVE_MODE , SPI_MAX_DF }
 
enum  SpiDataSize_t { SPI_8BITS , SPI_16BITS , SPI_MAX_BITS }
 

Functions

const SpiConfig_t *const SPI_ConfigGet (void)
 
size_t SPI_configSizeGet (void)
 

Detailed Description

This module contains interface definitions for the SPI configuration. This is the header file for the definition of the interface for retrieving the Serial Peripheral interface configuration table.

Author
Jose Luis Figueroa
Version
1.1
Date
2025-03-11

Macro Definition Documentation

◆ SPI_PORTS_NUMBER

#define SPI_PORTS_NUMBER   4U

Defines the number of ports on the processor.

Enumeration Type Documentation

◆ SpiBaudRate_t

Define the baud rate control.

Enumerator
SPI_FPCLK2 

Baud rate divided by 2

SPI_FPCLK4 

Baud rate divided by 4

SPI_FPCLK8 

Baud rate divided by 8

SPI_FPCLK16 

Baud rate divided by 16

SPI_FPCLK32 

Baud rate divided by 32

SPI_FPCLK64 

Baud rate divided by 64

SPI_FPCLK128 

Baud rate divided by 128

SPI_FPCLK256 

Baud rate divided by 256

SPI_MAX_FPCLK 

Maximum baud rate

◆ SpiChannel_t

Define the SPI channels on the MCU device. It is used to specify SPI channel to configure the register map.

Enumerator
SPI_CHANNEL1 

SPI Channel 1

SPI_CHANNEL2 

SPI Channel 2

SPI_CHANNEL3 

SPI Channel 3

SPI_CHANNEL4 

SPI Channel 4

SPI_MAX_CHANNEL 

Maximum SPI Channel

◆ SpiDataSize_t

Define the data frame format. Set bits number of data.

Enumerator
SPI_8BITS 

8 bits data is selected for communication

SPI_16BITS 

16 bits data is selected for communication

SPI_MAX_BITS 

Maximum number of bits

◆ SpiFrameFormat_t

Define the frame format. Choose the direction of the data frame to be sent.

Enumerator
SPI_MSB 

Most significant bit transmitted first

SPI_LSB 

Less significant bit transmitted first

SPI_MAX_FF 

Maximum frame format

◆ SpiHierarchy_t

Define the hierarchy of the device. Set the device as slave or master.

Enumerator
SPI_SLAVE 

Slave configuration

SPI_MASTER 

Master configuration

SPI_MAX_HIERARCHY 

Maximum hierarchy

◆ SpiMode_t

enum SpiMode_t

Define the bus mode according to clock polarity and clock phase.

Enumerator
SPI_MODE0 

Mode 0 (CPOL=0 and CPHA=0)

SPI_MODE1 

Mode 1 (CPOL=0 and CPHA=1)

SPI_MODE2 

Mode 2 (CPOL=1 and CPHA=0)

SPI_MODE3 

Mode 3 (CPOL=1 and CPHA=1)

SPI_MAX_MODE 

Maximum mode

◆ SpiSlaveSelect_t

Define the slave select pin management (NSS input). The slave
selector could be configured by software or hardware. SW_NSS: Slave select is driven internally. NSS pin remains free. HW_NSS_ENABLED: Device operates in master mode (NSS pin is used). HW_NSS_DISABLED: Device operates in slave mode (NSS pin is used).

Enumerator
SPI_SOFTWARE_NSS 

Software NSS pin management

SPI_HARDWARE_NSS_ENABLED 

Hardware NSS pin management (Master)

SPI_HARDWARE_NSS_DISABLED 

Hardware NSS pin management (slave)

SPI_MAX_NSS 

Maximum NSS input

◆ SpiTypeTransfer_t

Define the type of data transfer.

Enumerator
SPI_FULL_DUPLEX 

Set full duplex communication

SPI_RECEIVE_MODE 

Set Receive only communication

SPI_MAX_DF 

Set the maximum data transfer

Function Documentation

◆ SPI_ConfigGet()

const SpiConfig_t *const SPI_ConfigGet ( void )

Description: This function is used to initialize the SPI based on the configuration table defined in spi_cfg module.

PRE-CONDITION: configuration table needs to be populated (sizeof > 0).
POST-CONDITION: A constant pointer to the first member of the configuration table will be returned.

Returns
A pointer to the configuration table.

Example:

size_t configSize = DIO_configSizeGet();
SPI_Init(SpiConfig, configSize);
size_t DIO_configSizeGet(void)
Definition dio_cfg.c:134
const SpiConfig_t SpiConfig[]
Definition spi_cfg.c:41
const SpiConfig_t *const SPI_ConfigGet(void)
Definition spi_cfg.c:89
Definition spi_cfg.h:135
See also
SPI_configGet
SPI_configSizeGet
SPI_Init
SPI_Transfer
SPI_RegisterWrite
SPI_RegisterRead
SPI_CallbackRegister

◆ SPI_configSizeGet()

size_t SPI_configSizeGet ( void )

Description: This function is used to get the size of the configuration table.

PRE-CONDITION: configuration table needs to be populated (sizeof > 0)

POST-CONDITION: The size of the configuration table will be returned.

Returns
The size of the configuration table.

Example:

size_t configSize = DIO_configSizeGet();
SPI_Init(SpiConfig, configSize);
See also
SPI_configGet
SPI_configSizeGet
SPI_Init
SPI_Transfer
SPI_RegisterWrite
SPI_RegisterRead
SPI_CallbackRegister