summaryrefslogtreecommitdiff
path: root/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/include/ab32vg1_hal_gpio.h
blob: 0202566e70c0aeb044e6fe5d603760aea9c9660c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright (c) 2020-2020, BLUETRUM Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#ifndef AB32VG1_HAL_GPIO_H__
#define AB32VG1_HAL_GPIO_H__

#include "ab32vg1_hal_def.h"

struct gpio_init
{
    uint8_t  pin;
    uint8_t  dir;
    uint8_t  de;
    uint8_t  pull;
    uint32_t alternate;
    uint32_t af_con;        /*!< Alternate function control
                                [4:0]: Mapping name
                                [6:5]: Mapping control register
                                [7]:   Mapping enable bit */
};
typedef struct gpio_init *gpio_init_t;

enum
{
    GPIOxSET = 0x00,
    GPIOxCLR,
    GPIOx,
    GPIOxDIR,
    GPIOxDE,
    GPIOxFEN,
    GPIOxDRV,
    GPIOxPU,
    GPIOxPD,
    GPIOxPU200K,
    GPIOxPD200K,
    GPIOxPU300K,
    GPIOxPD300K,
};

/* Private constants */

#define FUNCMCONx(x)            *(volatile uint32_t*)(SFR0_BASE + (0x07 + (x))*4)

/* Exported constants */
#define GPIO_DIR_INPUT      (0x01u)
#define GPIO_DIR_OUTPUT     (0x02u)

#define GPIO_DIGITAL        (0x01u)
#define GPIO_ANALOG         (0x02u)

#define GPIO_AFDIS              (0u << 7)
#define GPIO_AFEN               (1u << 7)
#define GPIO_AFCON0             (0u << 5)     /*!< When using UARTT0 UART1 HSUART SPI0 and SD0 */
#define GPIO_AFCON1             (1u << 5)     /*!< When using LPWM0 LPWM1 LPWM2 LPWM3 SPI1 UART2 and CLKOUT */
#define GPIO_AFCON2             (2u << 5)     /*!< When using IR TIMER3 TIMER4 TIMER5 and IIS */
#define GPIO_AFCON_MASK         (0x3u << 5)
#define GPIO_GET_AFCON(af_con)  (uint8_t)(((af_con) & (GPIO_AFCON_MASK)) >> 5)

#define GPIO_NOPULL         (0x00u)
#define GPIO_PULLUP         (0x01u)
#define GPIO_PULLDOWN       (0x02u)

#define GPIO_PIN_LOW        (0x00u)
#define GPIO_PIN_HIGH       (0x01u)

#define GPIOA_BASE          ((hal_sfr_t)(&GPIOASET))
#define GPIOB_BASE          ((hal_sfr_t)(&GPIOBSET))
#define GPIOE_BASE          ((hal_sfr_t)(&GPIOESET))
#define GPIOF_BASE          ((hal_sfr_t)(&GPIOFSET))

#define GPIO_PIN_0          (BIT(0))
#define GPIO_PIN_1          (BIT(1))
#define GPIO_PIN_2          (BIT(2))
#define GPIO_PIN_3          (BIT(3))
#define GPIO_PIN_4          (BIT(4))
#define GPIO_PIN_5          (BIT(5))
#define GPIO_PIN_6          (BIT(6))
#define GPIO_PIN_7          (BIT(7))

/* Include GPIO HAL Extended module */
#include "ab32vg1_hal_gpio_ex.h"

/* Initialization and de-initialization functions */
void hal_gpio_init(hal_sfr_t gpiox, gpio_init_t gpio_init);

/* IO operation function */
uint8_t hal_gpio_read(hal_sfr_t gpiox, uint8_t pin);
void hal_gpio_write(hal_sfr_t gpiox, uint8_t pin, uint8_t state);
void hal_gpio_toggle(hal_sfr_t gpiox, uint8_t pin);

#endif