You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
KED/bsl/csl/interfaces/pin.h

190 lines
4.7 KiB

/**
**************************************************************************************************
* @file pin.h
* @author Kerem Yollu & Edwin Koch
* @date 01.11.2021
* @version 1.0
**************************************************************************************************
* @brief pin functionalities description and implementation template
*
* **Detailed Description :**
*
* This header file for pin control is based on the most common configuation options
* curenty awailable for modern hardware.
* Depending of the used Chip, some function may vary or be unawailable.
* Please take a minute to go and explore the according Chips pin.c file to see woh each function
* is implmented.
*
* @todo
* - 01.11.2021 : Should we add a seprate header in the cls layer containing the pinNo_t ?
* - 01.11.2021 : Depending on request implment a pinLock() function
**************************************************************************************************
*/
#ifndef _GPIO_H_
#define _GPIO_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
// include the target device definitions -> CMAKE chooses the correct file
#include "hardwareDescription.h"
#ifdef RASPBERRY
#endif
/*! Enum of possible Pin Modes */
typedef enum
{
def_mode, /*!< Is the **default** mode */
input, /*!< Set pin as **Input** */
output, /*!< Set pin as **Output** */
analog, /*!< Set pin as **Analog** */
alternate /*!< Set pin as **Alternate** */
}pinMode_t;
/*! Enum of possible Outpout Stages */
typedef enum
{
def_stage, /*!< Set ouput stage to **Default** */
floating, /*!< Set ouput stage to **Floating** */
pushPull, /*!< Set ouput stage to **Push Pull** */
openDrain /*!< Set ouput stage to **Open Drain** */
}pinStage_t;
/*! Enum for the internal Pull-Up/Down resistors */
typedef enum
{
def_res, /*!< **Default** internal resistance */
none, /*!< **Disbales** internal resistance */
pullUp, /*!< Set internal resistance as **Pull-Up** */
pullDown /*!< Set internal resistance as **Pull-Down** */
}pinPullUpDown_t;
/*! Enum to set the pin's speed*/
typedef enum
{
def_speed, /*!< set pin's spped to **Default** */
slow, /*!< set pin's speed to **Slow** */
normal, /*!< set pin's speed to **Normal** */
fast, /*!< set pin's speed to **Fast** */
veryFast /*!< set pin's speed to **Very Fast** */
}pinSpeed_t;
typedef enum
{
disabled,
enabled
}pinInterrupt_t;
typedef struct
{
pinMode_t md;
pinStage_t st;
pinPullUpDown_t pud;
pinSpeed_t sp;
pinInterrupt_t intr;
}pinConfiguration_t;
typedef enum
{
notValidMode,
UnvalidAlternate,
OutOfRangeAlternate,
NotValidSpeed,
notValidOut,
OutOfRange,
NotDeclared,
NotReachable,
NoPullUpDown,
NotAnalog,
NotDigital,
Bocked,
AlreadyUsed,
NotGpio
}pinErrors_t;
/**
* @brief Configuration function that will call all the necessary function for an sucessfull pin initialisation
* @param pinNo_t mode_t
* @retval none
*/
void pinConfig(pinNo_t pinNo, pinMode_t mode, pinStage_t stage, pinPullUpDown_t resistance, pinSpeed_t speed);
/**
* @brief Modes to set the direction or function of the pin
*/
void pinSetMode(pinNo_t pinNo, pinMode_t mode);
/**
* @brief Output Stage Push-Pull High-z ect...
*/
void pinSetOutputStage(pinNo_t pinNo, pinStage_t stage);
/**
* @brief Depending of the hardare it is able to select the speed of given pins
*/
void pinSetSpeed(pinNo_t pinNo, pinSpeed_t speed);
/**
* @brief If internal Pull-up or Pull-donws are wailable
*/
void pinSetPullUpDonw(pinNo_t pinNo, pinPullUpDown_t resistance);
/**
* @brief If pin is set as alternate this function will modify the pins functionality
* If pin isn't set as alternate this function will set the pin to alternate mode.
*/
void pinSetAlternate(pinNo_t pinNo, uint16_t alternate);
/**
* @brief Reads the pin's current value
*/
uint8_t pinRead(pinNo_t pinNo);
/**
* @brief Toggles th pin's value
*/
void pinToggle(pinNo_t pinNo);
/**
* @brief Sets the pin hihg or low.
*/
void pinWrite(pinNo_t pinNo, uint8_t state);
/**
* @brief Initiates all the preriferals needed for the given pin
*/
void pinInit(pinNo_t pinNo);
/**
* @brief Deactivates all the preriferals needed for the given pin
*/
void pinDeInit(pinNo_t pinNo);
/**
* @brief Resets pin to default
*/
void pinReset(pinNo_t pinNo);
/**
* @brief Will pirnt tthe rurrent devices pin status and their configrarion.
* Dependeing on the platform an the form of information printing.
*/
void pinHardwareInfo(pinNo_t pinNo);
/**
* @brief Handles the given error and stops all further execution.
* Dependeing on the platfonr an the form of information printing.
*/
void pinThrowError(pinErrors_t error);
#ifdef __cplusplus
}
#endif
#endif // _GPIO_H_