ald_gpio.h 7.5 KB
Newer Older
W
wangyq2018 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/**
  *********************************************************************************
  *
  * @file    ald_gpio.h
  * @brief   Header file of GPIO module driver
  *
  * @version V1.0
  * @date    07 Nov 2017
  * @author  AE Team
  * @note
  *
  * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
  *
  *********************************************************************************
  */

#ifndef __ALD_GPIO_H__
#define __ALD_GPIO_H__

#ifdef __cplusplus
W
wangyq2018 已提交
21
 extern "C" {
W
wangyq2018 已提交
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
#endif

#include "utils.h"


/** @addtogroup ES32FXXX_ALD
  * @{
  */

/** @addtogroup GPIO
  * @{
  */

/**
  * @defgroup GPIO_Public_Macros GPIO Public Macros
  * @{
  */
#define GPIO_PIN_0	(1U << 0)
#define GPIO_PIN_1	(1U << 1)
#define GPIO_PIN_2	(1U << 2)
#define GPIO_PIN_3	(1U << 3)
#define GPIO_PIN_4	(1U << 4)
#define GPIO_PIN_5	(1U << 5)
#define GPIO_PIN_6	(1U << 6)
#define GPIO_PIN_7	(1U << 7)
#define GPIO_PIN_8	(1U << 8)
#define GPIO_PIN_9	(1U << 9)
#define GPIO_PIN_10	(1U << 10)
#define GPIO_PIN_11	(1U << 11)
#define GPIO_PIN_12	(1U << 12)
#define GPIO_PIN_13	(1U << 13)
#define GPIO_PIN_14	(1U << 14)
#define GPIO_PIN_15	(1U << 15)
W
wangyq2018 已提交
55
#define GPIO_PIN_ALL	(0xFFFFU)
W
wangyq2018 已提交
56 57 58 59 60 61 62 63 64 65 66 67
/**
  * @}
  */

/**
  * @defgroup GPIO_Public_Types GPIO Public Types
  * @{
  */

/**
  * @brief GPIO mode
  */
W
wangyq2018 已提交
68 69 70 71
typedef enum {
	GPIO_MODE_CLOSE  = 0x0U,	/**< Digital close  Analog open */
	GPIO_MODE_INPUT  = 0x1U,	/**< Input */
	GPIO_MODE_OUTPUT = 0x2U,	/**< Output */
W
wangyq2018 已提交
72 73 74 75 76
} gpio_mode_t;

/**
  * @brief GPIO open-drain or push-pull
  */
W
wangyq2018 已提交
77 78 79 80
typedef enum {
	GPIO_PUSH_PULL   = 0x0U,	/**< Push-Pull */
	GPIO_OPEN_DRAIN  = 0x2U,	/**< Open-Drain. Can't output high level */
	GPIO_OPEN_SOURCE = 0x3U,	/**< Open-Source. Can't output low level */
W
wangyq2018 已提交
81 82 83 84 85
} gpio_odos_t;

/**
  * @brief GPIO push-up or push-down
  */
W
wangyq2018 已提交
86 87 88 89 90
typedef enum {
	GPIO_FLOATING     = 0x0U,	/**< Floating */
	GPIO_PUSH_UP      = 0x1U,	/**< Push-Up */
	GPIO_PUSH_DOWN    = 0x2U,	/**< Push-Down */
	GPIO_PUSH_UP_DOWN = 0x3U,	/**< Push-Up and Push-Down */
W
wangyq2018 已提交
91 92 93 94 95
} gpio_push_t;

/**
  * @brief GPIO output drive
  */
W
wangyq2018 已提交
96 97 98
typedef enum {
	GPIO_OUT_DRIVE_NORMAL = 0x0U,	/**< Normal current flow */
	GPIO_OUT_DRIVE_STRONG = 0x1U,	/**< Strong current flow */
W
wangyq2018 已提交
99 100 101 102 103
} gpio_out_drive_t;

/**
  * @brief GPIO filter
  */
W
wangyq2018 已提交
104 105 106
typedef enum {
	GPIO_FILTER_DISABLE = 0x0U,	/**< Disable filter */
	GPIO_FILTER_ENABLE  = 0x1U,	/**< Enable filter */
W
wangyq2018 已提交
107 108 109 110 111
} gpio_filter_t;

/**
  * @brief GPIO type
  */
W
wangyq2018 已提交
112 113 114
typedef enum {
	GPIO_TYPE_CMOS = 0x0U,	/**< CMOS Type */
	GPIO_TYPE_TTL  = 0x1U,	/**< TTL Type */
W
wangyq2018 已提交
115 116 117 118 119
} gpio_type_t;

/**
  * @brief GPIO functions
  */
W
wangyq2018 已提交
120 121 122 123 124 125 126 127 128
typedef enum {
	GPIO_FUNC_0 = 0U,	/**< function #0 */
	GPIO_FUNC_1 = 1U,	/**< function #1 */
	GPIO_FUNC_2 = 2U,	/**< function #2 */
	GPIO_FUNC_3 = 3U,	/**< function #3 */
	GPIO_FUNC_4 = 4U,	/**< function #4 */
	GPIO_FUNC_5 = 5U,	/**< function #5 */
	GPIO_FUNC_6 = 6U,	/**< function #6 */
	GPIO_FUNC_7 = 7U,	/**< function #7 */
W
wangyq2018 已提交
129 130 131 132 133 134
} gpio_func_t;


/**
  * @brief GPIO Init Structure definition
  */
W
wangyq2018 已提交
135 136
typedef struct {
	gpio_mode_t mode;	/**< Specifies the operating mode for the selected pins.
W
wangyq2018 已提交
137
				     This parameter can be any value of @ref gpio_mode_t */
W
wangyq2018 已提交
138
	gpio_odos_t odos;	/**< Specifies the Open-Drain or Push-Pull for the selected pins.
W
wangyq2018 已提交
139
				     This parameter can be a value of @ref gpio_odos_t */
W
wangyq2018 已提交
140
	gpio_push_t pupd;	/**< Specifies the Pull-up or Pull-Down for the selected pins.
W
wangyq2018 已提交
141
				     This parameter can be a value of @ref gpio_push_t */
W
wangyq2018 已提交
142
	gpio_out_drive_t odrv;	/**< Specifies the output driver for the selected pins.
W
wangyq2018 已提交
143
				     This parameter can be a value of @ref gpio_out_drive_t */
W
wangyq2018 已提交
144
	gpio_filter_t flt;	/**< Specifies the input filter for the selected pins.
W
wangyq2018 已提交
145
				     This parameter can be a value of @ref gpio_filter_t */
W
wangyq2018 已提交
146
	gpio_type_t type;	/**< Specifies the type for the selected pins.
W
wangyq2018 已提交
147
				     This parameter can be a value of @ref gpio_type_t */
W
wangyq2018 已提交
148
	gpio_func_t func;	/**< Specifies the function for the selected pins.
W
wangyq2018 已提交
149 150 151 152 153 154
				     This parameter can be a value of @ref gpio_func_t */
} gpio_init_t;

/**
  * @brief EXTI trigger style
  */
W
wangyq2018 已提交
155 156 157 158
typedef enum {
	EXTI_TRIGGER_RISING_EDGE   = 0U,	/**< Rising edge trigger */
	EXTI_TRIGGER_TRAILING_EDGE = 1U,	/**< Trailing edge trigger */
	EXTI_TRIGGER_BOTH_EDGE     = 2U,	/**< Rising and trailing edge trigger */
W
wangyq2018 已提交
159 160 161 162 163
} exti_trigger_style_t;

/**
  * @brief EXTI filter clock select
  */
W
wangyq2018 已提交
164 165 166
typedef enum {
	EXTI_FILTER_CLOCK_10K = 0U,	/**< cks = 10KHz */
	EXTI_FILTER_CLOCK_32K = 1U,	/**< cks = 32KHz */
W
wangyq2018 已提交
167 168 169 170 171
} exti_filter_clock_t;

/**
  * @brief EXTI Init Structure definition
  */
W
wangyq2018 已提交
172 173 174 175
typedef struct {
	type_func_t filter;		/**< Enable filter. */
	exti_filter_clock_t cks;	/**< Filter clock select. */
	uint8_t filter_time;		/**< Filter duration */
W
wangyq2018 已提交
176 177 178 179 180 181 182 183 184
} exti_init_t;
/**
  * @}
  */

/**
  * @defgroup GPIO_Private_Macros GPIO Private Macros
  * @{
  */
W
wangyq2018 已提交
185 186
#define PIN_MASK	0xFFFFU
#define UNLOCK_KEY	0x55AAU
W
wangyq2018 已提交
187 188 189

#define IS_GPIO_PIN(x)	((((x) & (uint16_t)0x00) == 0) && ((x) != (uint16_t)0x0))
#define IS_GPIO_PORT(GPIOx)	((GPIOx == GPIOA) || \
W
wangyq2018 已提交
190 191 192 193 194 195 196
				 (GPIOx == GPIOB) || \
				 (GPIOx == GPIOC) || \
				 (GPIOx == GPIOD) || \
				 (GPIOx == GPIOE) || \
				 (GPIOx == GPIOF) || \
				 (GPIOx == GPIOG) || \
				 (GPIOx == GPIOH))
W
wangyq2018 已提交
197
#define IS_GPIO_MODE(x)		(((x) == GPIO_MODE_CLOSE) || \
W
wangyq2018 已提交
198 199
                                 ((x) == GPIO_MODE_INPUT) || \
                                 ((x) == GPIO_MODE_OUTPUT))
W
wangyq2018 已提交
200
#define IS_GPIO_ODOS(x)		(((x) == GPIO_PUSH_PULL)  || \
W
wangyq2018 已提交
201 202
                                 ((x) == GPIO_OPEN_DRAIN) || \
                                 ((x) == GPIO_OPEN_SOURCE))
W
wangyq2018 已提交
203
#define IS_GPIO_PUPD(x)		(((x) == GPIO_FLOATING)  || \
W
wangyq2018 已提交
204 205 206
                                 ((x) == GPIO_PUSH_UP)   || \
                                 ((x) == GPIO_PUSH_DOWN) || \
                                 ((x) == GPIO_PUSH_UP_DOWN))
W
wangyq2018 已提交
207
#define IS_GPIO_ODRV(x)		(((x) == GPIO_OUT_DRIVE_NORMAL) || \
W
wangyq2018 已提交
208
                                 ((x) == GPIO_OUT_DRIVE_STRONG))
W
wangyq2018 已提交
209
#define IS_GPIO_FLT(x)		(((x) == GPIO_FILTER_DISABLE) || \
W
wangyq2018 已提交
210
                                 ((x) == GPIO_FILTER_ENABLE))
W
wangyq2018 已提交
211
#define IS_GPIO_TYPE(x)		(((x) == GPIO_TYPE_TTL) || \
W
wangyq2018 已提交
212
                                 ((x) == GPIO_TYPE_CMOS))
W
wangyq2018 已提交
213
#define IS_TRIGGER_STYLE(x)	(((x) == EXTI_TRIGGER_RISING_EDGE)   || \
W
wangyq2018 已提交
214 215
                                 ((x) == EXTI_TRIGGER_TRAILING_EDGE) || \
                                 ((x) == EXTI_TRIGGER_BOTH_EDGE))
W
wangyq2018 已提交
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
#define IS_EXTI_FLTCKS_TYPE(x)	(((x) == EXTI_FILTER_CLOCK_10K) || \
                                 ((x) == EXTI_FILTER_CLOCK_32K))
#define IS_GPIO_FUNC(x)		((x) <= 7)
/**
  * @}
  */

/** @addtogroup GPIO_Public_Functions
  * @{
  */

/** @addtogroup GPIO_Public_Functions_Group1
  * @{
  */
void ald_gpio_init(GPIO_TypeDef *GPIOx, uint16_t pin, gpio_init_t *init);
void ald_gpio_init_default(GPIO_TypeDef *GPIOx, uint16_t pin);
void ald_gpio_func_default(GPIO_TypeDef *GPIOx);
void ald_gpio_exti_init(GPIO_TypeDef *GPIOx, uint16_t pin, exti_init_t *init);
/**
  * @}
  */

/** @addtogroup GPIO_Public_Functions_Group2
  * @{
  */
uint8_t ald_gpio_read_pin(GPIO_TypeDef *GPIOx, uint16_t pin);
void ald_gpio_write_pin(GPIO_TypeDef *GPIOx, uint16_t pin, uint8_t val);
void ald_gpio_toggle_pin(GPIO_TypeDef *GPIOx, uint16_t pin);
void ald_gpio_toggle_dir(GPIO_TypeDef *GPIOx, uint16_t pin);
void ald_gpio_lock_pin(GPIO_TypeDef *GPIOx, uint16_t pin);
uint16_t ald_gpio_read_port(GPIO_TypeDef *GPIOx);
void ald_gpio_write_port(GPIO_TypeDef *GPIOx, uint16_t val);
/**
  * @}
  */

/** @addtogroup GPIO_Public_Functions_Group3
  * @{
  */
void ald_gpio_exti_interrupt_config(uint16_t pin, exti_trigger_style_t style, type_func_t status);
flag_status_t ald_gpio_exti_get_flag_status(uint16_t pin);
void ald_gpio_exti_clear_flag_status(uint16_t pin);
/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */
#ifdef __cplusplus
}
#endif

#endif /* __ALD_GPIO_H__ */