/* GPIO.h */ /*! @file GPIO.h @brief Base abstraction layer for the Broadcom BCM2835 for the Raspberry pi gpio pins. If this code is ported to an newer raspberry pi this should be the only file that you should modify. */ /* History: 07/20/2022: Julian Zelazny Moved GPIO registers to GPIO.c due to disuse in the .h file. Fixed function gpioWritePin corrupting GPIO due to reading write only registers. 07/19/2022: Julian Zelazny Started file, a redo of the original GPIO.c & GPIO.h */ #ifndef _GPIO_H #define _GPIO_H #ifdef __cplusplus extern "C" { #endif #include #include /*============================================================================*/ /*! @enum gpioPin_t all 28 gpio pins available for user use */ typedef enum { GPIO00, GPIO01, GPIO02, GPIO03, GPIO04, GPIO05, GPIO06, GPIO07, GPIO08, GPIO09, GPIO10, GPIO11, GPIO12, GPIO13, GPIO14, GPIO15, GPIO16, GPIO17, GPIO18, GPIO19, GPIO20, GPIO21, GPIO22, GPIO23, GPIO24, GPIO25, GPIO26, GPIO27 }gpioPin_t; /*! @enum gpioPinFunction_t tells the PI what type of function the GPIO pin has. Please refer to BCM2835-ARM-Peripherals.pdf for what the alt functions are. */ typedef enum { PIN_INPUT, PIN_OUTPUT, PIN_ALT5, PIN_ALT4, PIN_ALT0, PIN_ALT1, PIN_ALT2, PIN_ALT3 }gpioPinFunction_t; /*============================================================================*/ /*! @brief gets the raw logic level @return the 28-raw logic level, pins set to output will return their current output value or 0 if the function gpioInit was not called. */ uint32_t gpioGetRawLogicLevels(void); /*! @brief sets the raw logic level @param, bitmask the 28-bit bitmask for the logic levels we want to set. Pins set as input will ignore this */ void gpioSetRawLogicLevels(uint32_t bitmask); /*! @brief sets the pin to a specific mode @param pinNumber which pin we want to change. @param mode the mode we want to change the pin to. */ void gpioSetPinType(gpioPin_t pinNumber, gpioPinFunction_t mode); /*! @brief get the pin function @param pinNumber which pin we want to change. @return the function type */ gpioPinFunction_t gpioGetPinType(gpioPin_t pinNumber); /*! @brief read the raw pin value @param pinNumber the pin we want to read @return true if logic high, false if logic low or you failed to call gpioInit */ bool gpioReadPin(gpioPin_t pinNumber); /*! @brief sets the pin to a logic level high or low @param pinNumber the pin we want to write to @param logicHigh true for high, false for low */ void gpioWritePin(gpioPin_t pinNumber, bool logicHigh); /*! @brief THIS MUST BE CALLED BEFORE ANY OTHER FUNCTION @return true if the register were able to be mmap'ed into program memory */ bool gpioInit(void); /*============================================================================*/ #ifdef __cplusplus } #endif #endif //_GPIOCORE_H