Digital Input/Output Reusable Driver v1.1
This project implements a GPIO reusable driver that can be adapted to various microcontrollers.
Loading...
Searching...
No Matches
dio.h File Reference

The interface definition for the DIO. This is the header file for the definition of the interface for a digital input/output peripheral on a standard microcontroller. More...

#include <stdint.h>
#include <stdio.h>
#include <assert.h>
#include "dio_cfg.h"
#include "stm32f4xx.h"
Include dependency graph for dio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  DioPinConfig_t
 

Functions

void DIO_init (const DioConfig_t *const Config, size_t configSize)
 
DioPinState_t DIO_pinRead (const DioPinConfig_t *const PinConfig)
 
void DIO_pinWrite (const DioPinConfig_t *const PinConfig, DioPinState_t State)
 
void DIO_pinToggle (const DioPinConfig_t *const PinConfig)
 
void DIO_registerWrite (uint32_t address, uint32_t value)
 
uint32_t DIO_registerRead (uint32_t address)
 

Detailed Description

The interface definition for the DIO. This is the header file for the definition of the interface for a digital input/output peripheral on a standard microcontroller.

Author
Jose Luis Figueroa
Version
1.1
Date
2023-03-04

Function Documentation

◆ DIO_init()

void DIO_init ( const DioConfig_t *const Config,
size_t configSize )

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

PRE-CONDITION: The MCU clocks must be configured and enabled.
PRE-CONDITION: Configuration table needs to be populated (sizeof > 0)
PRE-CONDITION: NUMBER_OF_PORTS > 0
PRE-CONDITION: The setting is within the maximum values (DIO_MAX).

POST-CONDITION: The DIO peripheral is set up with the configuration settings.

Parameters
[in]Configis a pointer to the configuration table that contains the initialization for the peripheral.
[in]configSizeis the size of the configuration table.
Returns
void

Example:

const Dio_ConfigType_t * const DioConfig = DIO_configGet();
size_t configSize = DIO_configSizeGet();
DIO_Init(DioConfig, configSize);
size_t DIO_configSizeGet(void)
Definition dio_cfg.c:139
const DioConfig_t DioConfig[]
Definition dio_cfg.c:41
const DioConfig_t *const DIO_configGet(void)
Definition dio_cfg.c:98
See also
DIO_configGet
DIO_configSizeGet
DIO_init
DIO_pinRead
DIO_pinWrite
DIO_pinToggle
DIO_registerWrite
DIO_registerRead

◆ DIO_pinRead()

DioPinState_t DIO_pinRead ( const DioPinConfig_t *const PinConfig)

Description: This function is used to reads the state of a specified pin. This function reads the state of a digital input/output pin specified by the DioPinConfig_t structure, which contains the port and pin information.

PRE-CONDITION: The pin is configured as INPUT
PRE-CONDITION: The pin is configured as GPIO
PRE-CONDITION: DioPinConfig_t needs to be populated (sizeof > 0)
PRE-CONDITION: The Port is within the maximum DioPort_t.
PRE-CONDITION: The Pin is within the maximum DioPin_t. definition.

POST-CONDITION: The channel state is returned.

Parameters
[in]PinConfigA pointer to a structure containing the port and pin to be read.
Returns
DioPinState_t The state of the pin (high or low).

Example:

const DioPinConfig_t UserButton1=
{
.Port = DIO_PC,
.Pin = DIO_PC13
};
bool pin = DIO_pinRead(&UserButton1);
DioPinState_t DIO_pinRead(const DioPinConfig_t *const PinConfig)
Definition dio.c:416
@ DIO_PC
Definition dio_cfg.h:50
@ DIO_PC13
Definition dio_cfg.h:107
Definition dio.h:42
See also
DIO_ConfigGet
DIO_configSizeGet
DIO_init
DIO_pinRead
DIO_pinWrite
DIO_pinToggle
DIO_registerWrite
DIO_registerRead

◆ DIO_pinToggle()

void DIO_pinToggle ( const DioPinConfig_t *const PinConfig)

Description: This function is used to toggle the current state of a pin. This function reads the state of a digital input/output pin specified by the DioPinConfig_t structure, which contains the port and pin information.

PRE-CONDITION: The channel is configured as output
PRE-CONDITION: The channel is configured as GPIO
PRE-CONDITION: DioPinConfig_t needs to be populated (sizeof > 0)
PRE-CONDITION: The Port is within the maximum DioPort_t.
PRE-CONDITION: The Pin is within the maximum DioPin_t.

POST-CONDITION: The channel state is toggled.

Parameters
[in]pinConfigA pointer to a structure containing the port and pin to be toggled.
Returns
void

Example:

const DioPinConfig_t UserLED1=
{
.Port = DIO_PA,
.Pin = DIO_PA5
};
DIO_pinToggle(&UserLED1);
void DIO_pinToggle(const DioPinConfig_t *const PinConfig)
Definition dio.c:550
@ DIO_PA
Definition dio_cfg.h:48
@ DIO_PA5
Definition dio_cfg.h:68
See also
DIO_ConfigGet
DIO_configSizeGet
DIO_init
DIO_pinRead
DIO_pinWrite
DIO_pinToggle
DIO_registerWrite
DIO_registerRead

◆ DIO_pinWrite()

void DIO_pinWrite ( const DioPinConfig_t *const PinConfig,
DioPinState_t State )

Description: This function is used to write the state of a pin as either logic high or low. it reads the state of a digital input/output pin specified by the DioPinConfig_t structure and the DioPinState_t to define the desired state, which contains the port and pin information.

PRE-CONDITION: The pin is configured as OUTPUT
PRE-CONDITION: The pin is configured as GPIO
PRE-CONDITION: DioPinConfig_t needs to be populated (sizeof > 0)
PRE-CONDITION: The Port is within the maximum DioPort_t.
PRE-CONDITION: The Pin is within the maximum DioPin_t.
PRE-CONDITION: The State is within the maximum DioPinState_t.

POST-CONDITION: The channel state is Stated.

Parameters
[in]pinConfigA pointer to a structure containing the port and pin to be written.
[in]Stateis HIGH or LOW as defined in the DioPinState_t enum.
Returns
void

Example:

const DioPinConfig_t UserLED1=
{
.Port = DIO_PA,
.Pin = DIO_PA5
};
const DioPinConfig_t UserLED2=
{
.Port = DIO_PA,
.Pin = DIO_PA6
};
DIO_pinWrite(&UserLED1, LOW); //Set the pin low
DIO_pinWrite(&UserLED2, HIGH); //Set the pin high
void DIO_pinWrite(const DioPinConfig_t *const PinConfig, DioPinState_t State)
Definition dio.c:485
@ DIO_PA6
Definition dio_cfg.h:69
See also
DIO_ConfigGet
DIO_configSizeGet
DIO_init
DIO_pinRead
DIO_pinWrite
DIO_pinToggle
DIO_registerWrite
DIO_registerRead

◆ DIO_registerRead()

uint32_t DIO_registerRead ( uint32_t address)

Description: This function is used to directly address a Dio register. The function should be used to access specialized functionality in the Dio peripheral that is not exposed by any other function of the interface.

PRE-CONDITION: Address is within the boundaries of the Dio register address space.

POST-CONDITION: The value stored in the register is returned to the caller.

Parameters
[in]addressis the address of the Dio register to read.
Returns
The current value of the Dio register.

Example:

type dioValue = DIO_registerRead(0x1000);
uint32_t DIO_registerRead(uint32_t address)
Definition dio.c:638
See also
DIO_ConfigGet
DIO_configSizeGet
DIO_init
DIO_pinRead
DIO_pinWrite
DIO_pinToggle
DIO_registerWrite
DIO_registerRead

◆ DIO_registerWrite()

void DIO_registerWrite ( uint32_t address,
uint32_t value )

Description: This function is used to directly address and modify a GPIO register. The function should be used to access specialized functionality in the DIO peripheral that is not exposed by any other function of the interface.

PRE-CONDITION: Address is within the boundaries of the DIO register address space.

POST-CONDITION: The register located at address with be updated with value.

Parameters
[in]addressis a register address within the DIO peripheral map.
[in]valueis the value to set the DIO register.
Returns
void

Example

DIO_registerWrite(0x1000, 0x15);
void DIO_registerWrite(uint32_t address, uint32_t value)
Definition dio.c:598
See also
DIO_ConfigGet
DIO_configSizeGet
DIO_init
DIO_pinRead
DIO_pinWrite
DIO_pinToggle
DIO_registerWrite
DIO_registerRead