46 #if defined(STM32F4XX)
47 enum dio_drive_strength {
53 #elif defined(STM32F30X) || defined (STM32F0XX)
54 enum dio_drive_strength {
60 #elif defined(STM32F10X_MD)
61 enum dio_drive_strength {
86 #define DIO_NULL ((uintptr_t) 0)
97 bool open_collector,
enum dio_drive_strength strength);
124 enum dio_drive_strength strength,
bool first_value);
167 #define DIO_BASE ( (uintptr_t) GPIOA )
169 #define DIO_PORT_OFFSET(port) (((uintptr_t) (port)) - DIO_BASE)
171 #define DIO_MAKE_TAG(port, pin) ((uintptr_t) ((DIO_PORT_OFFSET(port) << 16) | ((uint16_t) (pin))))
173 #define GPIOA_DIO(pin_num) DIO_MAKE_TAG(GPIOA, 1<<(pin_num))
174 #define GPIOB_DIO(pin_num) DIO_MAKE_TAG(GPIOB, 1<<(pin_num))
175 #define GPIOC_DIO(pin_num) DIO_MAKE_TAG(GPIOC, 1<<(pin_num))
176 #define GPIOD_DIO(pin_num) DIO_MAKE_TAG(GPIOD, 1<<(pin_num))
177 #define GPIOE_DIO(pin_num) DIO_MAKE_TAG(GPIOE, 1<<(pin_num))
178 #define GPIOF_DIO(pin_num) DIO_MAKE_TAG(GPIOF, 1<<(pin_num))
180 #define GET_DIO_PORT(dio) ( (GPIO_TypeDef *) (((dio) >> 16) + DIO_BASE) )
182 #define GET_DIO_PIN(dio) ((dio) & 0xffff)
184 #define _DIO_PRELUDE_RET(s) \
185 if (t == DIO_NULL) { return (s); } \
186 GPIO_TypeDef * gp = GET_DIO_PORT(t); \
187 uint16_t pin = GET_DIO_PIN(t);
189 #define _DIO_PRELUDE \
190 if (t == DIO_NULL) { return; } \
191 GPIO_TypeDef * gp = GET_DIO_PORT(t); \
192 uint16_t pin = GET_DIO_PIN(t);
212 gp->BSRR = pin << 16;
235 #define DIO_SETREGS_FOURWIDE(reglow, reghigh, idx, val) \
240 (reghigh) = ((reghigh) & ~(15 << (__pos * 4))) | ( (val) << (__pos * 4)); \
242 (reglow) = ((reglow) & ~(15 << (__pos * 4))) | ( (val) << (__pos * 4)); \
246 #define DIO_SETREG_TWOWIDE(reg, idx, val) \
249 (reg) = ((reg) & ~(3 << (__pos * 2))) | ( (val) << (__pos * 2)); \
252 #define DIO_SETREG_ONEWIDE(reg, idx, val) \
255 (reg) = ((reg) & ~(1 << (__pos))) | ( (val) << __pos); \
262 #if defined(STM32F10X_MD)
263 static inline void _dio_remap(
int alt_func)
266 GPIO_PinRemapConfig(alt_func, ENABLE);
272 bool open_collector,
enum dio_drive_strength strength)
276 uint8_t
pos = __builtin_ctz(pin);
278 #if defined(STM32F10X_MD)
279 _dio_remap(alt_func);
284 uint8_t val = 8 | strength;
286 if (open_collector) {
302 #if defined(STM32F10X_MD)
303 _dio_remap(alt_func);
310 #if !defined(STM32F10X_MD)
313 uint8_t
pos = __builtin_ctz(pin);
323 uint8_t
pos = __builtin_ctz(pin);
324 #if defined(STM32F10X_MD)
335 enum dio_drive_strength strength,
bool first_value)
339 uint8_t
pos = __builtin_ctz(pin);
343 #if defined(STM32F10X_MD)
347 uint8_t val = strength;
349 if (open_collector) {
356 if (open_collector) {
380 uint8_t
pos = __builtin_ctz(pin);
382 #if defined(STM32F10X_MD)
411 return !! (gp->IDR & pin);
static void dio_set_altfunc_output(dio_tag_t t, int alt_func, bool open_collector, enum dio_drive_strength strength)
Configures a GPIO as alternate function output.
static void dio_low(dio_tag_t t)
Sets an output GPIO low.
#define DIO_SETREGS_FOURWIDE(reglow, reghigh, idx, val)
static void dio_set_altfunc_input(dio_tag_t t, int alt_func, enum dio_pull pull)
Configures a GPIO as alternate function input.
static void dio_set_input(dio_tag_t t, enum dio_pull pull)
Configures a GPIO as an input.
static void dio_write(dio_tag_t t, bool high)
Sets an output GPIO to a chosen logical level.
static void dio_high(dio_tag_t t)
Sets an output GPIO high.
#define DIO_SETREG_TWOWIDE(reg, idx, val)
static void dio_set_analog(dio_tag_t t)
Configures a GPIO as analog. Disables pullups/pulldowns, etc.
static void dio_set_output(dio_tag_t t, bool open_collector, enum dio_drive_strength strength, bool first_value)
Configures a GPIO as an output.
#define DIO_SETREG_ONEWIDE(reg, idx, val)
static void dio_toggle(dio_tag_t t)
Toggles an output GPIO to the opposite level.
static bool dio_read(dio_tag_t t)
Reads a GPIO logical value.
#define _DIO_PRELUDE_RET(s)