MCAL.h File Reference

Microcontroller Abstraction Layer. More...

#include <stdbool.h>
#include <stdint.h>
#include "stm32f1xx_hal.h"
Include dependency graph for MCAL.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  GPIOPort { GPIO_PORT_A = 0, GPIO_PORT_B, GPIO_PORT_C, GPIO_PORT_D }
 GPIO ports. More...
 
enum  I2CMemAddSize { I2C_MEMSIZE_8BIT = 0, I2C_MEMSIZE_16BIT }
 I²C memory address size. More...
 

Functions

bool GPIO_IsSet (GPIOPort ePort, uint16_t u16PinMask)
 Read current input pin state. More...
 
void GPIO_PullDown (GPIOPort ePort, uint16_t u16PinMask)
 Pull output pin(s) low. More...
 
void GPIO_RaiseHigh (GPIOPort ePort, uint16_t u16PinMask)
 Raise output pin(s) high. More...
 
void GPIO_Toggle (GPIOPort ePort, uint16_t u16PinMask)
 Toggle output pin(s) between high and low. More...
 
int I2C_Receive (uint16_t u16DevAddress, uint16_t u16MemAddress, I2CMemAddSize eMemAddSize, uint8_t *pu8RxBuffer, uint16_t u16Size)
 Receive an amount via I²C. More...
 
int I2C_Transmit (uint16_t u16DevAddress, uint16_t u16MemAddress, I2CMemAddSize eMemAddSize, uint8_t *pu8TxBuffer, uint16_t u16Size)
 Transmit an amount via I²C. More...
 
void I2C_WaitUntilReady (uint16_t u16DevAddress)
 Wait for the end of the transfer. More...
 
void MCAL_Sleep (uint16_t u16DelayInUs)
 Microsecond delay (blocking) More...
 
int RTC_GetTime (uint8_t *pu8Hours, uint8_t *pu8Minutes, uint8_t *pu8Seconds)
 Get current time from RTC. More...
 
int RTC_SetTime (uint8_t u8Hours, uint8_t u8Minutes, uint8_t u8Seconds)
 Set current RTC time. More...
 
int SPI_Transmit (uint8_t *pu8TxData, uint16_t u16Size)
 Transmit an amount via SPI. More...
 
int SPI_Receive (uint8_t *pu8RxData, uint16_t u16Size)
 Receive an amount of data via SPI. More...
 
int SPI_TransmitReceive (uint8_t *pu8TxData, uint8_t *pu8RxData, uint16_t u16Size)
 Transmit and Receive an amount of data via SPI. More...
 

Detailed Description

Microcontroller Abstraction Layer.

MCAL for STM32F1xx microcontroller

Definition in file MCAL.h.

Enumeration Type Documentation

◆ GPIOPort

enum GPIOPort

GPIO ports.

Enumerator
GPIO_PORT_A 

GPIO port A.

GPIO_PORT_B 

GPIO port B.

GPIO_PORT_C 

GPIO port C.

GPIO_PORT_D 

GPIO port D.

Definition at line 17 of file MCAL.h.

◆ I2CMemAddSize

I²C memory address size.

Enumerator
I2C_MEMSIZE_8BIT 

I²C memory address size (8-Bit)

I2C_MEMSIZE_16BIT 

I²C memory address size (16-Bit)

Definition at line 30 of file MCAL.h.

Function Documentation

◆ GPIO_IsSet()

bool GPIO_IsSet ( GPIOPort  ePort,
uint16_t  u16PinMask 
)

Read current input pin state.

Parameters
ePortGPIO port
u16PinMaskPin mask
Returns
Boolean state
Return values
truePin is high
falsePin is low

Definition at line 36 of file MCAL.c.

Here is the call graph for this function:

◆ GPIO_PullDown()

void GPIO_PullDown ( GPIOPort  ePort,
uint16_t  u16PinMask 
)

Pull output pin(s) low.

Parameters
ePortGPIO port
u16PinMaskPin mask

Definition at line 57 of file MCAL.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GPIO_RaiseHigh()

void GPIO_RaiseHigh ( GPIOPort  ePort,
uint16_t  u16PinMask 
)

Raise output pin(s) high.

Parameters
ePortGPIO port
u16PinMaskPin mask

Definition at line 70 of file MCAL.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GPIO_Toggle()

void GPIO_Toggle ( GPIOPort  ePort,
uint16_t  u16PinMask 
)

Toggle output pin(s) between high and low.

Parameters
ePortGPIO port
u16PinMaskPin mask

Definition at line 83 of file MCAL.c.

Here is the call graph for this function:

◆ I2C_Receive()

int I2C_Receive ( uint16_t  u16DevAddress,
uint16_t  u16MemAddress,
I2CMemAddSize  eMemAddSize,
uint8_t *  pu8RxBuffer,
uint16_t  u16Size 
)

Receive an amount via I²C.

Parameters
u16DevAddressTarget device address
u16MemAddressInternal memory address
eMemAddSizeMemory address size
pu8RxBufferPointer to data buffer
u16SizeAmount of data to be sent
Returns
Error code
Return values
0OK
-1Error

Definition at line 105 of file MCAL.c.

Here is the caller graph for this function:

◆ I2C_Transmit()

int I2C_Transmit ( uint16_t  u16DevAddress,
uint16_t  u16MemAddress,
I2CMemAddSize  eMemAddSize,
uint8_t *  pu8TxBuffer,
uint16_t  u16Size 
)

Transmit an amount via I²C.

Parameters
u16DevAddressTarget device address
u16MemAddressInternal memory address
eMemAddSizeMemory address size
pu8TxBufferPointer to data buffer
u16SizeAmount of data to be sent
Returns
Error code
Return values
0OK
-1Error

Definition at line 149 of file MCAL.c.

Here is the caller graph for this function:

◆ I2C_WaitUntilReady()

void I2C_WaitUntilReady ( uint16_t  u16DevAddress)

Wait for the end of the transfer.

Before starting a new communication transfer, the CPU need to check the current state of the peripheral; if it's busy the CPU need to wait for the end of current transfer before starting a new one.

Parameters
u16DevAddressTarget device address

Definition at line 186 of file MCAL.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MCAL_Sleep()

void MCAL_Sleep ( uint16_t  u16DelayInUs)

Microsecond delay (blocking)

Parameters
u16DelayInUsDelay in microseconds

Definition at line 207 of file MCAL.c.

Here is the caller graph for this function:

◆ RTC_GetTime()

int RTC_GetTime ( uint8_t *  pu8Hours,
uint8_t *  pu8Minutes,
uint8_t *  pu8Seconds 
)

Get current time from RTC.

Parameters
pu8HoursPointer to hours
pu8MinutesPointer to minutes
pu8SecondsPointer to seconds
Returns
Error code
Return values
0OK
-1Error

Definition at line 225 of file MCAL.c.

Here is the caller graph for this function:

◆ RTC_SetTime()

int RTC_SetTime ( uint8_t  u8Hours,
uint8_t  u8Minutes,
uint8_t  u8Seconds 
)

Set current RTC time.

Parameters
u8HoursHours
u8MinutesMinutes
u8SecondsSeconds
Returns
Error code
Return values
0OK
-1Error

Definition at line 253 of file MCAL.c.

◆ SPI_Receive()

int SPI_Receive ( uint8_t *  pu8RxData,
uint16_t  u16Size 
)

Receive an amount of data via SPI.

Parameters
pu8RxDataPointer to data buffer
u16SizeAmount of data to be sent
Returns
Error code
Return values
0OK
-1Error

Definition at line 299 of file MCAL.c.

◆ SPI_Transmit()

int SPI_Transmit ( uint8_t *  pu8TxData,
uint16_t  u16Size 
)

Transmit an amount via SPI.

Parameters
pu8TxDataPointer to data buffer
u16SizeAmount of data to be sent
Returns
Error code
Return values
0OK
-1Error

Definition at line 279 of file MCAL.c.

Here is the caller graph for this function:

◆ SPI_TransmitReceive()

int SPI_TransmitReceive ( uint8_t *  pu8TxData,
uint8_t *  pu8RxData,
uint16_t  u16Size 
)

Transmit and Receive an amount of data via SPI.

Parameters
pu8TxDataPointer to transmission data buffer
pu8RxDataPointer to reception data buffer
u16SizeAmount of data to be sent and received
Returns
Error code
Return values
0OK
-1Error

Definition at line 321 of file MCAL.c.