MCAL.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: Beerware
2 /**
3  * @file MCAL.h
4  * @brief Microcontroller Abstraction Layer
5  * @details MCAL for STM32F1xx microcontroller
6  */
7 #pragma once
8 
9 #include <stdbool.h>
10 #include <stdint.h>
11 #include "stm32f1xx_hal.h"
12 
13 /**
14  * @enum GPIOPort
15  * @brief GPIO ports
16  */
17 typedef enum
18 {
19  GPIO_PORT_A = 0, ///< GPIO port A
20  GPIO_PORT_B, ///< GPIO port B
21  GPIO_PORT_C, ///< GPIO port C
22  GPIO_PORT_D ///< GPIO port D
23 
24 } GPIOPort;
25 
26 /**
27  * @enum I2CMemAddSize
28  * @brief I²C memory address size
29  */
30 typedef enum
31 {
32  I2C_MEMSIZE_8BIT = 0, ///< I²C memory address size (8-Bit)
33  I2C_MEMSIZE_16BIT ///< I²C memory address size (16-Bit)
34 
36 
37 bool GPIO_IsSet(GPIOPort ePort, uint16_t u16PinMask);
38 void GPIO_PullDown(GPIOPort ePort, uint16_t u16PinMask);
39 void GPIO_RaiseHigh(GPIOPort ePort, uint16_t u16PinMask);
40 void GPIO_Toggle(GPIOPort ePort, uint16_t u16PinMask);
41 int I2C_Receive(uint16_t u16DevAddress, uint16_t u16MemAddress, I2CMemAddSize eMemAddSize, uint8_t* pu8RxBuffer, uint16_t u16Size);
42 int I2C_Transmit(uint16_t u16DevAddress, uint16_t u16MemAddress, I2CMemAddSize eMemAddSize, uint8_t* pu8TxBuffer, uint16_t u16Size);
43 void I2C_WaitUntilReady(uint16_t u16DevAddress);
44 void MCAL_Sleep(uint16_t u16DelayInUs);
45 int RTC_GetTime(uint8_t* pu8Hours, uint8_t* pu8Minutes, uint8_t* pu8Seconds);
46 int RTC_SetTime(uint8_t u8Hours, uint8_t u8Minutes, uint8_t u8Seconds);
47 int SPI_Transmit(uint8_t* pu8TxData, uint16_t u16Size);
48 int SPI_Receive(uint8_t* pu8RxData, uint16_t u16Size);
49 int SPI_TransmitReceive(uint8_t* pu8TxData, uint8_t* pu8RxData, uint16_t u16Size);
@ GPIO_PORT_C
GPIO port C.
Definition: MCAL.h:21
int SPI_Transmit(uint8_t *pu8TxData, uint16_t u16Size)
Transmit an amount via SPI.
Definition: MCAL.c:279
void MCAL_Sleep(uint16_t u16DelayInUs)
Microsecond delay (blocking)
Definition: MCAL.c:207
int I2C_Transmit(uint16_t u16DevAddress, uint16_t u16MemAddress, I2CMemAddSize eMemAddSize, uint8_t *pu8TxBuffer, uint16_t u16Size)
Transmit an amount via I²C.
Definition: MCAL.c:149
int SPI_TransmitReceive(uint8_t *pu8TxData, uint8_t *pu8RxData, uint16_t u16Size)
Transmit and Receive an amount of data via SPI.
Definition: MCAL.c:321
void GPIO_Toggle(GPIOPort ePort, uint16_t u16PinMask)
Toggle output pin(s) between high and low.
Definition: MCAL.c:83
void GPIO_PullDown(GPIOPort ePort, uint16_t u16PinMask)
Pull output pin(s) low.
Definition: MCAL.c:57
void GPIO_RaiseHigh(GPIOPort ePort, uint16_t u16PinMask)
Raise output pin(s) high.
Definition: MCAL.c:70
int RTC_GetTime(uint8_t *pu8Hours, uint8_t *pu8Minutes, uint8_t *pu8Seconds)
Get current time from RTC.
Definition: MCAL.c:225
void I2C_WaitUntilReady(uint16_t u16DevAddress)
Wait for the end of the transfer.
Definition: MCAL.c:186
I2CMemAddSize
I²C memory address size.
Definition: MCAL.h:30
@ GPIO_PORT_B
GPIO port B.
Definition: MCAL.h:20
int I2C_Receive(uint16_t u16DevAddress, uint16_t u16MemAddress, I2CMemAddSize eMemAddSize, uint8_t *pu8RxBuffer, uint16_t u16Size)
Receive an amount via I²C.
Definition: MCAL.c:105
int RTC_SetTime(uint8_t u8Hours, uint8_t u8Minutes, uint8_t u8Seconds)
Set current RTC time.
Definition: MCAL.c:253
int SPI_Receive(uint8_t *pu8RxData, uint16_t u16Size)
Receive an amount of data via SPI.
Definition: MCAL.c:299
@ I2C_MEMSIZE_16BIT
I²C memory address size (16-Bit)
Definition: MCAL.h:33
GPIOPort
GPIO ports.
Definition: MCAL.h:17
bool GPIO_IsSet(GPIOPort ePort, uint16_t u16PinMask)
Read current input pin state.
Definition: MCAL.c:36
@ GPIO_PORT_D
GPIO port D.
Definition: MCAL.h:22
@ I2C_MEMSIZE_8BIT
I²C memory address size (8-Bit)
Definition: MCAL.h:32
@ GPIO_PORT_A
GPIO port A.
Definition: MCAL.h:19