MCAL.c File Reference

Microcontroller Abstraction Layer. More...

#include <stdbool.h>
#include <stdint.h>
#include "MCAL.h"
#include "stm32f1xx_hal.h"
#include "stm32f1xx_hal_i2c.h"
#include "stm32f1xx_hal_spi.h"
#include "stm32f1xx_hal_rtc.h"
#include "stm32f1xx_hal_tim.h"
Include dependency graph for MCAL.c:

Go to the source code of this file.

Functions

static GPIO_TypeDef * _MCAL_ConvertGPIOPort (GPIOPort ePort)
 Convert GPIOPort to STM32_HAL's GPIO_TypeDef. More...
 
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...
 

Variables

I2C_HandleTypeDef hi2c2
 I²C 2 handle.
 
SPI_HandleTypeDef hspi1
 SPI 1 handle.
 
RTC_HandleTypeDef hrtc
 RTC handle.
 
TIM_HandleTypeDef htim1
 Timer 1 handle.
 

Detailed Description

Microcontroller Abstraction Layer.

MCAL for STM32F1xx microcontroller

Author
Michael Fitzmayer

Definition in file MCAL.c.

Function Documentation

◆ _MCAL_ConvertGPIOPort()

static GPIO_TypeDef * _MCAL_ConvertGPIOPort ( GPIOPort  ePort)
static

Convert GPIOPort to STM32_HAL's GPIO_TypeDef.

Parameters
ePortGPIO port
Returns
Pointer to respective GPIO_TypeDef

Definition at line 337 of file MCAL.c.

Here is the caller graph for this function:

◆ 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.