| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- #pragma once
- #include "main.h"
- #include "stdbool.h"
- #include <stm32wbxx_ll_gpio.h>
- #include <stm32wbxx_ll_system.h>
- #include <stm32wbxx_ll_exti.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * Number of gpio on one port
- */
- #define GPIO_NUMBER (16U)
- /**
- * Interrupt callback prototype
- */
- typedef void (*GpioExtiCallback)(void* ctx);
- /**
- * Gpio interrupt type
- */
- typedef struct {
- GpioExtiCallback callback;
- void *context;
- volatile bool ready;
- } GpioInterrupt;
- /**
- * Gpio modes
- */
- typedef enum {
- GpioModeInput,
- GpioModeOutputPushPull,
- GpioModeOutputOpenDrain,
- GpioModeAltFunctionPushPull,
- GpioModeAltFunctionOpenDrain,
- GpioModeAnalog,
- GpioModeInterruptRise,
- GpioModeInterruptFall,
- GpioModeInterruptRiseFall,
- GpioModeEventRise,
- GpioModeEventFall,
- GpioModeEventRiseFall,
- } GpioMode;
- /**
- * Gpio pull modes
- */
- typedef enum {
- GpioPullNo,
- GpioPullUp,
- GpioPullDown,
- } GpioPull;
- /**
- * Gpio speed modes
- */
- typedef enum {
- GpioSpeedLow,
- GpioSpeedMedium,
- GpioSpeedHigh,
- GpioSpeedVeryHigh,
- } GpioSpeed;
- /**
- * Gpio structure
- */
- typedef struct {
- GPIO_TypeDef* port;
- uint16_t pin;
- } GpioPin;
- /**
- * GPIO initialization function
- * @param gpio GpioPin
- * @param mode GpioMode
- * @param pull GpioPull
- * @param speed GpioSpeed
- */
- void hal_gpio_init(
- const GpioPin* gpio,
- const GpioMode mode,
- const GpioPull pull,
- const GpioSpeed speed);
- /**
- * Add and enable interrupt
- * @param gpio GpioPin
- * @param cb GpioExtiCallback
- * @param ctx context for callback
- */
- void hal_gpio_add_int_callback(const GpioPin* gpio, GpioExtiCallback cb, void* ctx);
- /**
- * Enable interrupt
- * @param gpio GpioPin
- */
- void hal_gpio_enable_int_callback(const GpioPin* gpio);
- /**
- * Disable interrupt
- * @param gpio GpioPin
- */
- void hal_gpio_disable_int_callback(const GpioPin* gpio);
- /**
- * Remove interrupt
- * @param gpio GpioPin
- */
- void hal_gpio_remove_int_callback(const GpioPin* gpio);
- /**
- * GPIO write pin
- * @param gpio GpioPin
- * @param state true / false
- */
- static inline void hal_gpio_write(const GpioPin* gpio, const bool state) {
- // writing to BSSR is an atomic operation
- if(state == true) {
- gpio->port->BSRR = gpio->pin;
- } else {
- gpio->port->BSRR = (uint32_t)gpio->pin << GPIO_NUMBER;
- }
- }
- /**
- * GPIO read pin
- * @param gpio GpioPin
- * @return true / false
- */
- static inline bool hal_gpio_read(const GpioPin* gpio) {
- if((gpio->port->IDR & gpio->pin) != 0x00U) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * Get RFID IN level
- * @return false = LOW, true = HIGH
- */
- bool hal_gpio_get_rfid_in_level();
- #ifdef __cplusplus
- }
- #endif
|