#pragma once

#ifndef _GPIO_H
#define _GPIO_H

/* x = A to F */

/* GPIO port mode register (GPIOx_MODER) */
#define GPIO_MODE_IN    0x0
#define GPIO_MODE_OUT   0x1
#define GPIO_MODE_AFF   0x2
#define GPIO_MODE_ANL   0x3

/* GPIO port output type register (GPIOx_OTYPER) */
#define GPIO_OTYPE_PP   0x0
#define GPIO_OTYPE_OD   0x1

/* GPIO port output speed register (GPIOx_OSPEEDR) */
#define GPIO_OSPEED_VL  0x0
#define GPIO_OSPEED_LW  0x1
#define GPIO_OSPEED_HI  0x2
#define GPIO_OSPEED_VH  0x3

/* GPIO port pull-up/pull-down register (GPIOx_PUPDR) */
#define GPIO_PUPD_NO    0x0
#define GPIO_PUPD_UP    0x1
#define GPIO_PUPD_DW    0x2
#define GPIO_PUPD_NN    0x3

/* GPIO port input data register (GPIOx_IDR) */

/* GPIO port output data register (GPIOx_ODR) */

/* GPIO port bit set/reset register (GPIOx_BSRR) */

/* GPIO port bit reset register (GPIOx_BRR) (x = A to F) */

/* GPIO port configuration lock register (GPIOx_LCKR) */

/* GPIO alternate function low register (GPIOx_AFRL) for pin 0..7 */
#define GPIO_AFRL_AF0   0x0
#define GPIO_AFRL_AF1   0x1
#define GPIO_AFRL_AF2   0x2
#define GPIO_AFRL_AF3   0x3
#define GPIO_AFRL_AF4   0x4
#define GPIO_AFRL_AF5   0x5
#define GPIO_AFRL_AF6   0x6
#define GPIO_AFRL_AF7   0x7

/* GPIO alternate function high register (GPIOx_AFRH) for pin 0..7 */
#define GPIO_AFRH_AF0   0x0
#define GPIO_AFRH_AF1   0x1
#define GPIO_AFRH_AF2   0x2
#define GPIO_AFRH_AF3   0x3
#define GPIO_AFRH_AF4   0x4
#define GPIO_AFRH_AF5   0x5
#define GPIO_AFRH_AF6   0x6
#define GPIO_AFRH_AF7   0x7

/* PORT = GPIOA..GPIOF, PIN = 0..15 */
#define GPIO_PIN_SET(PORT, PIN)    PORT->BSRR = (1<<PIN)
#define GPIO_PIN_RES(PORT, PIN)    PORT->BRR = (1<<PIN)

#endif
