2017-04-09 21:55:07 -07:00
|
|
|
#ifndef STM32_GPIO_H
|
|
|
|
#define STM32_GPIO_H
|
|
|
|
|
|
|
|
#include "stm32_def.h"
|
|
|
|
|
|
|
|
#include "variant.h"
|
|
|
|
|
2017-04-10 09:24:58 -07:00
|
|
|
#define INPUT 0x0
|
|
|
|
#define OUTPUT 0x1
|
|
|
|
#define INPUT_PULLUP 0x2
|
|
|
|
#define INPUT_PULLDOWN 0x3
|
|
|
|
|
2017-04-09 21:55:07 -07:00
|
|
|
#ifndef GPIO_SPEED_FREQ_VERY_HIGH
|
|
|
|
#define GPIO_SPEED_FREQ_VERY_HIGH GPIO_SPEED_FREQ_HIGH
|
|
|
|
#endif
|
|
|
|
|
2017-04-12 12:08:34 -07:00
|
|
|
#define RwReg uint32_t
|
|
|
|
|
|
|
|
|
2017-04-09 21:55:07 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"{
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GPIO_TypeDef *port;
|
|
|
|
uint32_t pin_mask;
|
|
|
|
} stm32_port_pin_type;
|
|
|
|
|
2017-04-11 21:15:09 -07:00
|
|
|
typedef uint32_t (*stm32_clock_freq_func)();
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
void *instance;
|
|
|
|
stm32_clock_freq_func clock_freq_func;
|
|
|
|
} stm32_clock_freq_list_type;
|
|
|
|
|
2017-04-09 21:55:07 -07:00
|
|
|
extern const stm32_port_pin_type port_pin_list[NUM_PINS];
|
|
|
|
|
2017-04-11 21:15:09 -07:00
|
|
|
/**
|
|
|
|
* Start clock for the fedined port
|
|
|
|
*/
|
|
|
|
void stm32_gpio_clock_enable(GPIO_TypeDef *port);
|
2017-04-09 21:55:07 -07:00
|
|
|
|
|
|
|
inline void digitalWrite(uint8_t pin, uint8_t value) {
|
2017-04-11 11:32:37 -07:00
|
|
|
if (pin >= sizeof(port_pin_list) / sizeof(port_pin_list[0])) {
|
2017-04-09 21:55:07 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
stm32_port_pin_type port_pin = port_pin_list[pin];
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(port_pin.port, port_pin.pin_mask, value ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-09 22:10:33 -07:00
|
|
|
|
|
|
|
inline int digitalRead(uint8_t pin) {
|
2017-04-11 11:32:37 -07:00
|
|
|
if (pin >= sizeof(port_pin_list) / sizeof(port_pin_list[0])) {
|
2017-04-09 22:10:33 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
stm32_port_pin_type port_pin = port_pin_list[pin];
|
|
|
|
|
|
|
|
return HAL_GPIO_ReadPin(port_pin.port, port_pin.pin_mask);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-09 21:55:07 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|