2021-02-18 12:49:32 +00:00
|
|
|
#pragma once
|
|
|
|
#include "main.h"
|
|
|
|
#include "stdbool.h"
|
2021-04-29 08:51:48 +00:00
|
|
|
#include <stm32wbxx_ll_gpio.h>
|
|
|
|
#include <stm32wbxx_ll_system.h>
|
|
|
|
#include <stm32wbxx_ll_exti.h>
|
2021-02-18 12:49:32 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-04-29 08:51:48 +00:00
|
|
|
/**
|
|
|
|
* Number of gpio on one port
|
|
|
|
*/
|
2021-02-18 12:49:32 +00:00
|
|
|
#define GPIO_NUMBER (16U)
|
|
|
|
|
2021-04-29 08:51:48 +00:00
|
|
|
/**
|
|
|
|
* Interrupt callback prototype
|
|
|
|
*/
|
|
|
|
typedef void (*GpioExtiCallback)(void* ctx);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gpio interrupt type
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
GpioExtiCallback callback;
|
|
|
|
void *context;
|
|
|
|
volatile bool ready;
|
|
|
|
} GpioInterrupt;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gpio modes
|
|
|
|
*/
|
2021-02-18 12:49:32 +00:00
|
|
|
typedef enum {
|
2021-04-29 08:51:48 +00:00
|
|
|
GpioModeInput,
|
|
|
|
GpioModeOutputPushPull,
|
|
|
|
GpioModeOutputOpenDrain,
|
|
|
|
GpioModeAltFunctionPushPull,
|
|
|
|
GpioModeAltFunctionOpenDrain,
|
|
|
|
GpioModeAnalog,
|
|
|
|
GpioModeInterruptRise,
|
|
|
|
GpioModeInterruptFall,
|
|
|
|
GpioModeInterruptRiseFall,
|
|
|
|
GpioModeEventRise,
|
|
|
|
GpioModeEventFall,
|
|
|
|
GpioModeEventRiseFall,
|
2021-02-18 12:49:32 +00:00
|
|
|
} GpioMode;
|
|
|
|
|
2021-04-29 08:51:48 +00:00
|
|
|
/**
|
|
|
|
* Gpio pull modes
|
|
|
|
*/
|
2021-03-31 17:52:26 +00:00
|
|
|
typedef enum {
|
2021-04-29 08:51:48 +00:00
|
|
|
GpioPullNo,
|
|
|
|
GpioPullUp,
|
|
|
|
GpioPullDown,
|
2021-03-31 17:52:26 +00:00
|
|
|
} GpioPull;
|
|
|
|
|
2021-04-29 08:51:48 +00:00
|
|
|
/**
|
|
|
|
* Gpio speed modes
|
|
|
|
*/
|
2021-02-18 12:49:32 +00:00
|
|
|
typedef enum {
|
2021-04-29 08:51:48 +00:00
|
|
|
GpioSpeedLow,
|
|
|
|
GpioSpeedMedium,
|
|
|
|
GpioSpeedHigh,
|
|
|
|
GpioSpeedVeryHigh,
|
2021-02-18 12:49:32 +00:00
|
|
|
} GpioSpeed;
|
|
|
|
|
2021-04-29 08:51:48 +00:00
|
|
|
/**
|
|
|
|
* Gpio structure
|
|
|
|
*/
|
2021-02-18 12:49:32 +00:00
|
|
|
typedef struct {
|
|
|
|
GPIO_TypeDef* port;
|
|
|
|
uint16_t pin;
|
|
|
|
} GpioPin;
|
|
|
|
|
2021-04-29 08:51:48 +00:00
|
|
|
/**
|
|
|
|
* GPIO initialization function
|
|
|
|
* @param gpio GpioPin
|
|
|
|
* @param mode GpioMode
|
|
|
|
* @param pull GpioPull
|
|
|
|
* @param speed GpioSpeed
|
|
|
|
*/
|
2021-02-18 12:49:32 +00:00
|
|
|
void hal_gpio_init(
|
|
|
|
const GpioPin* gpio,
|
|
|
|
const GpioMode mode,
|
|
|
|
const GpioPull pull,
|
|
|
|
const GpioSpeed speed);
|
|
|
|
|
2021-04-29 08:51:48 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2021-02-18 12:49:32 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-29 08:51:48 +00:00
|
|
|
/**
|
|
|
|
* GPIO read pin
|
|
|
|
* @param gpio GpioPin
|
|
|
|
* @return true / false
|
|
|
|
*/
|
2021-02-18 12:49:32 +00:00
|
|
|
static inline bool hal_gpio_read(const GpioPin* gpio) {
|
|
|
|
if((gpio->port->IDR & gpio->pin) != 0x00U) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-29 08:51:48 +00:00
|
|
|
/**
|
|
|
|
* Get RFID IN level
|
|
|
|
* @return false = LOW, true = HIGH
|
|
|
|
*/
|
|
|
|
bool hal_gpio_get_rfid_in_level();
|
|
|
|
|
2021-02-18 12:49:32 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|