/************************************************************************************************ * Authors : Kerem Yollu & Edwin Koch * Date : 01.11.2021 * Version : 1.0 * * 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 * * LICENCE : Please check the end of this file ************************************************************************************************/ #ifndef _GPIO_H_ #define _GPIO_H_ #ifdef __cplusplus extern "C" { #endif #include #include #ifdef ARM_MCU #include "../stm32f042/Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f042x6.h" typedef enum { // NAME = BASE ADDR | PORT | PIN NO pinA0 = GPIOA_BASE | 0x00 | 0, pinA1 = GPIOA_BASE | 0x00 | 1, pinA2 = GPIOA_BASE | 0x00 | 2, pinA3 = GPIOA_BASE | 0x00 | 3, pinA4 = GPIOA_BASE | 0x00 | 4, pinA5 = GPIOA_BASE | 0x00 | 5, pinA6 = GPIOA_BASE | 0x00 | 6, pinA7 = GPIOA_BASE | 0x00 | 7, pinA8 = GPIOA_BASE | 0x00 | 8, pinA9 = GPIOA_BASE | 0x00 | 9, pinA10 = GPIOA_BASE | 0x00 | 10, pinA11 = GPIOA_BASE | 0x00 | 11, pinA12 = GPIOA_BASE | 0x00 | 12, pinA13 = GPIOA_BASE | 0x00 | 13, pinA14 = GPIOA_BASE | 0x00 | 14, pinA15 = GPIOA_BASE | 0x00 | 15, pinB0 = GPIOB_BASE | 0x10 | 0, pinB1 = GPIOB_BASE | 0x10 | 1, pinB3 = GPIOB_BASE | 0x10 | 3, pinB4 = GPIOB_BASE | 0x10 | 4, pinB5 = GPIOB_BASE | 0x10 | 5, pinB6 = GPIOB_BASE | 0x10 | 6, pinB7 = GPIOB_BASE | 0x10 | 7, pinB8 = GPIOB_BASE | 0x10 | 8, pinF0 = GPIOF_BASE | 0x20 | 0, pinF1 = GPIOF_BASE | 0x20 | 1 }pinNo_t; #endif #ifdef RASPBERRY #endif typedef enum { undefined, input, output, analog, alternate }mode; typedef enum { floating, pushPull, openDrain }stage; typedef enum { none, pullUp, pullDown }pullUpDown; typedef enum { slow, normal, fast, veryFast }speed; typedef enum { disabled, enabled }interrupt; typedef struct { mode md; stage st; pullUpDown pud; speed sp; interrupt intr; }configuration; typedef enum { notValidMode, notValidOut, OutOfRange, NotDeclared, NotReachable, NoPullUpDown, NotAnalog, NotDigital, TooFast, Bocked, AlreadyUsed, NotGpio }errors; // Configuration function that will call all the necessary function for an sucessfull pin initialisation void pinConfig(pinNo_t pinNo, mode mode, stage stage, pullUpDown resistance, speed speed); // Modes to set the direction or function of the pin void pinSetMode(pinNo_t pinNo, mode mode); // Output Stage Push-Pull High-z ect... void pinSetOutputStage(pinNo_t pinNo, stage stage); // Depending of the hardare it is able to select the speed of given pins void pinSetSpeed(pinNo_t pinNo, speed speed); // If internal Pull-up or Pull-donws are wailable void pinSetPullUpDonw(pinNo_t pinNo, pullUpDown resistance); // 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); // Reads the pin's current value uint8_t pinRead(pinNo_t pinNo); // Toggles th pin's value void pinToggle(pinNo_t pinNo); // Sets the pin hihg or low. void pinWrite(pinNo_t pinNo, uint8_t state); // Initiates all the preriferals needed for the given pin void pinInit(pinNo_t pinNo); // Deactivates all the preriferals needed for the given pin void pinDeInit(pinNo_t pinNo); // Resets pin to default void pinReset(pinNo_t pinNo); // Dependeing on the platform an the form of information printing. // Will pirnt tthe rurrent devices pin status and their configrarion. void pinHardwareInfo(pinNo_t pinNo); // Dependeing on the platfonr an the form of information printing. // Handles the given error and stops all further execution. void pinThrowError(); #ifdef __cplusplus } #endif #endif // _GPIO_H_