Wakeup Light with touch user interface, anti-aliased Font, SD card access and RTC usage on STM32F746NG-DISCO board
Dependencies: BSP_DISCO_F746NG_patch_fixed LCD_DISCO_F746NG TS_DISCO_F746NG FATFileSystem TinyJpgDec_interwork mbed-src
tm_stm32_gpio.h
00001 /** 00002 * @author Tilen Majerle 00003 * @email tilen@majerle.eu 00004 * @website http://stm32f4-discovery.com 00005 * @link http://stm32f4-discovery.com/2015/07/hal-library-1-5-gpio-library-for-stm32fxxx/ 00006 * @version v1.0 00007 * @ide Keil uVision 00008 * @license GNU GPL v3 00009 * @brief GPIO Library for STM32F4xx and STM32F7xx devices 00010 * 00011 \verbatim 00012 ---------------------------------------------------------------------- 00013 Copyright (C) Tilen Majerle, 2015 00014 00015 This program is free software: you can redistribute it and/or modify 00016 it under the terms of the GNU General Public License as published by 00017 the Free Software Foundation, either version 3 of the License, or 00018 any later version. 00019 00020 This program is distributed in the hope that it will be useful, 00021 but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 GNU General Public License for more details. 00024 00025 You should have received a copy of the GNU General Public License 00026 along with this program. If not, see <http://www.gnu.org/licenses/>. 00027 ---------------------------------------------------------------------- 00028 \endverbatim 00029 */ 00030 #ifndef TM_GPIO_H 00031 #define TM_GPIO_H 100 00032 00033 /* C++ detection */ 00034 #ifdef __cplusplus 00035 extern "C" { 00036 #endif 00037 00038 /** 00039 * @addtogroup TM_STM32Fxxx_HAL_Libraries 00040 * @{ 00041 */ 00042 00043 /** 00044 * @defgroup TM_GPIO 00045 * @brief TM GPIO Library for STM32Fxxx 00046 * @{ 00047 * 00048 * GPIO library can be used for GPIO pins. 00049 * 00050 * It features fast initialization methods as well pin input/output methods. 00051 * 00052 * It can be used as replacement for STD/HAL drivers GPIO library. 00053 * 00054 * \par Changelog 00055 * 00056 \verbatim 00057 Version 1.0 00058 - Initial release 00059 \endverbatim 00060 * 00061 * \par Dependencies 00062 * 00063 \verbatim 00064 - STM32Fxxx HAL 00065 - defines.h 00066 \endverbatim 00067 */ 00068 #include "stm32fxxx_hal.h" 00069 #include "defines.h" 00070 00071 /** 00072 * @defgroup TM_GPIO_Macros 00073 * @brief GPIO Library macros 00074 * @{ 00075 */ 00076 00077 /** 00078 * @brief GPIO Pins declarations 00079 * @note For HAL drivers compatibility 00080 */ 00081 00082 #ifndef GPIO_PIN_0 00083 #define GPIO_PIN_0 ((uint16_t)0x0001) 00084 #define GPIO_PIN_1 ((uint16_t)0x0002) 00085 #define GPIO_PIN_2 ((uint16_t)0x0004) 00086 #define GPIO_PIN_3 ((uint16_t)0x0008) 00087 #define GPIO_PIN_4 ((uint16_t)0x0010) 00088 #define GPIO_PIN_5 ((uint16_t)0x0020) 00089 #define GPIO_PIN_6 ((uint16_t)0x0040) 00090 #define GPIO_PIN_7 ((uint16_t)0x0080) 00091 #define GPIO_PIN_8 ((uint16_t)0x0100) 00092 #define GPIO_PIN_9 ((uint16_t)0x0200) 00093 #define GPIO_PIN_10 ((uint16_t)0x0400) 00094 #define GPIO_PIN_11 ((uint16_t)0x0800) 00095 #define GPIO_PIN_12 ((uint16_t)0x1000) 00096 #define GPIO_PIN_13 ((uint16_t)0x2000) 00097 #define GPIO_PIN_14 ((uint16_t)0x4000) 00098 #define GPIO_PIN_15 ((uint16_t)0x8000) 00099 #define GPIO_PIN_ALL ((uint16_t)0xFFFF) 00100 #endif 00101 00102 /** 00103 * @brief GPIO Pins declarations 00104 * @note For STD Periph drivers compatibility 00105 */ 00106 00107 #ifndef GPIO_Pin_0 00108 #define GPIO_Pin_0 ((uint16_t)0x0001) 00109 #define GPIO_Pin_1 ((uint16_t)0x0002) 00110 #define GPIO_Pin_2 ((uint16_t)0x0004) 00111 #define GPIO_Pin_3 ((uint16_t)0x0008) 00112 #define GPIO_Pin_4 ((uint16_t)0x0010) 00113 #define GPIO_Pin_5 ((uint16_t)0x0020) 00114 #define GPIO_Pin_6 ((uint16_t)0x0040) 00115 #define GPIO_Pin_7 ((uint16_t)0x0080) 00116 #define GPIO_Pin_8 ((uint16_t)0x0100) 00117 #define GPIO_Pin_9 ((uint16_t)0x0200) 00118 #define GPIO_Pin_10 ((uint16_t)0x0400) 00119 #define GPIO_Pin_11 ((uint16_t)0x0800) 00120 #define GPIO_Pin_12 ((uint16_t)0x1000) 00121 #define GPIO_Pin_13 ((uint16_t)0x2000) 00122 #define GPIO_Pin_14 ((uint16_t)0x4000) 00123 #define GPIO_Pin_15 ((uint16_t)0x8000) 00124 #define GPIO_Pin_All ((uint16_t)0xFFFF) 00125 #endif 00126 00127 /** 00128 * @} 00129 */ 00130 00131 /** 00132 * @defgroup TM_GPIO_Typedefs 00133 * @brief GPIO Typedefs used for GPIO library for initialization purposes 00134 * @{ 00135 */ 00136 00137 /** 00138 * @brief GPIO Mode enumeration 00139 */ 00140 typedef enum { 00141 TM_GPIO_Mode_IN = 0x00, /*!< GPIO Pin as General Purpose Input */ 00142 TM_GPIO_Mode_OUT = 0x01, /*!< GPIO Pin as General Purpose Output */ 00143 TM_GPIO_Mode_AF = 0x02, /*!< GPIO Pin as Alternate Function */ 00144 TM_GPIO_Mode_AN = 0x03, /*!< GPIO Pin as Analog input/output */ 00145 } TM_GPIO_Mode_t; 00146 00147 /** 00148 * @brief GPIO Output type enumeration 00149 */ 00150 typedef enum { 00151 TM_GPIO_OType_PP = 0x00, /*!< GPIO Output Type Push-Pull */ 00152 TM_GPIO_OType_OD = 0x01 /*!< GPIO Output Type Open-Drain */ 00153 } TM_GPIO_OType_t; 00154 00155 /** 00156 * @brief GPIO Speed enumeration 00157 */ 00158 typedef enum { 00159 TM_GPIO_Speed_Low = 0x00, /*!< GPIO Speed Low */ 00160 TM_GPIO_Speed_Medium = 0x01, /*!< GPIO Speed Medium */ 00161 TM_GPIO_Speed_Fast = 0x02, /*!< GPIO Speed Fast, not available on STM32F0xx devices */ 00162 TM_GPIO_Speed_High = 0x03 /*!< GPIO Speed High */ 00163 } TM_GPIO_Speed_t; 00164 00165 /** 00166 * @brief GPIO pull resistors enumeration 00167 */ 00168 typedef enum { 00169 TM_GPIO_PuPd_NOPULL = 0x00, /*!< No pull resistor */ 00170 TM_GPIO_PuPd_UP = 0x01, /*!< Pull up resistor enabled */ 00171 TM_GPIO_PuPd_DOWN = 0x02 /*!< Pull down resistor enabled */ 00172 } TM_GPIO_PuPd_t; 00173 00174 /** 00175 * @} TM_GPIO_Typedefs 00176 */ 00177 00178 /** 00179 * @defgroup TM_GPIO_Functions 00180 * @brief GPIO Functions 00181 * @{ 00182 */ 00183 00184 /** 00185 * @brief Initializes GPIO pins(s) 00186 * @note This function also enables clock for GPIO port 00187 * @param GPIOx: Pointer to GPIOx port you will use for initialization 00188 * @param GPIO_Pin: GPIO pin(s) you will use for initialization 00189 * @param GPIO_Mode: Select GPIO mode. This parameter can be a value of @ref TM_GPIO_Mode_t enumeration 00190 * @param GPIO_OType: Select GPIO Output type. This parameter can be a value of @ref TM_GPIO_OType_t enumeration 00191 * @param GPIO_PuPd: Select GPIO pull resistor. This parameter can be a value of @ref TM_GPIO_PuPd_t enumeration 00192 * @param GPIO_Speed: Select GPIO speed. This parameter can be a value of @ref TM_GPIO_Speed_t enumeration 00193 * @retval None 00194 */ 00195 void TM_GPIO_Init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, TM_GPIO_Mode_t GPIO_Mode, TM_GPIO_OType_t GPIO_OType, TM_GPIO_PuPd_t GPIO_PuPd, TM_GPIO_Speed_t GPIO_Speed); 00196 00197 /** 00198 * @brief Initializes GPIO pins(s) as alternate function 00199 * @note This function also enables clock for GPIO port 00200 * @param GPIOx: Pointer to GPIOx port you will use for initialization 00201 * @param GPIO_Pin: GPIO pin(s) you will use for initialization 00202 * @param GPIO_OType: Select GPIO Output type. This parameter can be a value of @ref TM_GPIO_OType_t enumeration 00203 * @param GPIO_PuPd: Select GPIO pull resistor. This parameter can be a value of @ref TM_GPIO_PuPd_t enumeration 00204 * @param GPIO_Speed: Select GPIO speed. This parameter can be a value of @ref TM_GPIO_Speed_t enumeration 00205 * @param Alternate: Alternate function you will use 00206 * @retval None 00207 */ 00208 void TM_GPIO_InitAlternate(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, TM_GPIO_OType_t GPIO_OType, TM_GPIO_PuPd_t GPIO_PuPd, TM_GPIO_Speed_t GPIO_Speed, uint8_t Alternate); 00209 00210 /** 00211 * @brief Deinitializes pin(s) 00212 * @note Pins(s) will be set as analog mode to get low power consumption 00213 * @param GPIOx: GPIOx PORT where you want to set pin as input 00214 * @param GPIO_Pin: Select GPIO pin(s). You can select more pins with | (OR) operator to set them as input 00215 * @retval None 00216 */ 00217 void TM_GPIO_DeInit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 00218 00219 /** 00220 * @brief Sets pin(s) as input 00221 * @note Pins HAVE to be initialized first using @ref TM_GPIO_Init() or @ref TM_GPIO_InitAlternate() function 00222 * @note This is just an option for fast input mode 00223 * @param GPIOx: GPIOx PORT where you want to set pin as input 00224 * @param GPIO_Pin: Select GPIO pin(s). You can select more pins with | (OR) operator to set them as input 00225 * @retval None 00226 */ 00227 void TM_GPIO_SetPinAsInput(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 00228 00229 /** 00230 * @brief Sets pin(s) as output 00231 * @note Pins HAVE to be initialized first using @ref TM_GPIO_Init() or @ref TM_GPIO_InitAlternate() function 00232 * @note This is just an option for fast output mode 00233 * @param GPIOx: GPIOx PORT where you want to set pin as output 00234 * @param GPIO_Pin: Select GPIO pin(s). You can select more pins with | (OR) operator to set them as output 00235 * @retval None 00236 */ 00237 void TM_GPIO_SetPinAsOutput(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 00238 00239 /** 00240 * @brief Sets pin(s) as analog 00241 * @note Pins HAVE to be initialized first using @ref TM_GPIO_Init() or @ref TM_GPIO_InitAlternate() function 00242 * @note This is just an option for fast analog mode 00243 * @param GPIOx: GPIOx PORT where you want to set pin as analog 00244 * @param GPIO_Pin: Select GPIO pin(s). You can select more pins with | (OR) operator to set them as analog 00245 * @retval None 00246 */ 00247 void TM_GPIO_SetPinAsAnalog(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 00248 00249 /** 00250 * @brief Sets pin(s) as alternate function 00251 * @note For proper alternate function, you should first init pin using @ref TM_GPIO_InitAlternate() function. 00252 * This functions is only used for changing GPIO mode 00253 * @param GPIOx: GPIOx PORT where you want to set pin as alternate 00254 * @param GPIO_Pin: Select GPIO pin(s). You can select more pins with | (OR) operator to set them as alternate 00255 * @retval None 00256 */ 00257 void TM_GPIO_SetPinAsAlternate(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 00258 00259 /** 00260 * @brief Sets pull resistor settings to GPIO pin(s) 00261 * @note Pins HAVE to be initialized first using @ref TM_GPIO_Init() or @ref TM_GPIO_InitAlternate() function 00262 * @param *GPIOx: GPIOx PORT where you want to select pull resistor 00263 * @param GPIO_Pin: Select GPIO pin(s). You can select more pins with | (OR) operator to set them as output 00264 * @param GPIO_PuPd: Pull resistor option. This parameter can be a value of @ref TM_GPIO_PuPd_t enumeration 00265 * @retval None 00266 */ 00267 void TM_GPIO_SetPullResistor(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, TM_GPIO_PuPd_t GPIO_PuPd); 00268 00269 /** 00270 * @brief Sets pin(s) low 00271 * @note Defined as macro to get maximum speed using register access 00272 * @param GPIOx: GPIOx PORT where you want to set pin low 00273 * @param GPIO_Pin: Select GPIO pin(s). You can select more pins with | (OR) operator to set them low 00274 * @retval None 00275 */ 00276 #define TM_GPIO_SetPinLow(GPIOx, GPIO_Pin) ((GPIOx)->BSRR = (uint32_t)((GPIO_Pin) << 16)) 00277 00278 /** 00279 * @brief Sets pin(s) high 00280 * @note Defined as macro to get maximum speed using register access 00281 * @param GPIOx: GPIOx PORT where you want to set pin high 00282 * @param GPIO_Pin: Select GPIO pin(s). You can select more pins with | (OR) operator to set them high 00283 * @retval None 00284 */ 00285 #define TM_GPIO_SetPinHigh(GPIOx, GPIO_Pin) ((GPIOx)->BSRR = (uint32_t)(GPIO_Pin)) 00286 00287 /** 00288 * @brief Sets pin(s) value 00289 * @note Defined as macro to get maximum speed using register access 00290 * @param GPIOx: GPIOx PORT where you want to set pin value 00291 * @param GPIO_Pin: Select GPIO pin(s). You can select more pins with | (OR) operator to set them value 00292 * @param val: If parameter is 0 then pin will be low, otherwise high 00293 * @retval None 00294 */ 00295 #define TM_GPIO_SetPinValue(GPIOx, GPIO_Pin, val) ((val) ? TM_GPIO_SetPinHigh(GPIOx, GPIO_Pin) : TM_GPIO_SetPinLow(GPIOx, GPIO_Pin)) 00296 00297 /** 00298 * @brief Toggles pin(s) 00299 * @note Defined as macro to get maximum speed using register access 00300 * @param GPIOx: GPIOx PORT where you want to toggle pin value 00301 * @param GPIO_Pin: Select GPIO pin(s). You can select more pins with | (OR) operator to toggle them all at a time 00302 * @retval None 00303 */ 00304 #define TM_GPIO_TogglePinValue(GPIOx, GPIO_Pin) ((GPIOx)->ODR ^= (GPIO_Pin)) 00305 00306 /** 00307 * @brief Sets value to entire GPIO PORT 00308 * @note Defined as macro to get maximum speed using register access 00309 * @param GPIOx: GPIOx PORT where you want to set value 00310 * @param value: Value for GPIO OUTPUT data 00311 * @retval None 00312 */ 00313 #define TM_GPIO_SetPortValue(GPIOx, value) ((GPIOx)->ODR = (value)) 00314 00315 /** 00316 * @brief Gets input data bit 00317 * @note Defined as macro to get maximum speed using register access 00318 * @param GPIOx: GPIOx PORT where you want to read input bit value 00319 * @param GPIO_Pin: GPIO pin where you want to read value 00320 * @retval 1 in case pin is high, or 0 if low 00321 */ 00322 #define TM_GPIO_GetInputPinValue(GPIOx, GPIO_Pin) (((GPIOx)->IDR & (GPIO_Pin)) == 0 ? 0 : 1) 00323 00324 /** 00325 * @brief Gets output data bit 00326 * @note Defined as macro to get maximum speed using register access 00327 * @param GPIOx: GPIOx PORT where you want to read output bit value 00328 * @param GPIO_Pin: GPIO pin where you want to read value 00329 * @retval 1 in case pin is high, or 0 if low 00330 */ 00331 #define TM_GPIO_GetOutputPinValue(GPIOx, GPIO_Pin) (((GPIOx)->ODR & (GPIO_Pin)) == 0 ? 0 : 1) 00332 00333 /** 00334 * @brief Gets input value from entire GPIO PORT 00335 * @note Defined as macro to get maximum speed using register access 00336 * @param GPIOx: GPIOx PORT where you want to read input data value 00337 * @retval Entire PORT INPUT register 00338 */ 00339 #define TM_GPIO_GetPortInputValue(GPIOx) ((GPIOx)->IDR) 00340 00341 /** 00342 * @brief Gets output value from entire GPIO PORT 00343 * @note Defined as macro to get maximum speed using register access 00344 * @param GPIOx: GPIOx PORT where you want to read output data value 00345 * @retval Entire PORT OUTPUT register 00346 */ 00347 #define TM_GPIO_GetPortOutputValue(GPIOx) ((GPIOx)->ODR) 00348 00349 /** 00350 * @brief Gets port source from desired GPIOx PORT 00351 * @note Meant for private use, unless you know what are you doing 00352 * @param GPIOx: GPIO PORT for calculating port source 00353 * @retval Calculated port source for GPIO 00354 */ 00355 uint16_t TM_GPIO_GetPortSource(GPIO_TypeDef* GPIOx); 00356 00357 /** 00358 * @brief Gets pin source from desired GPIO pin 00359 * @note Meant for private use, unless you know what are you doing 00360 * @param GPIO_Pin: GPIO pin for calculating port source 00361 * @retval Calculated pin source for GPIO pin 00362 */ 00363 uint16_t TM_GPIO_GetPinSource(uint16_t GPIO_Pin); 00364 00365 /** 00366 * @brief Locks GPIOx register for future changes 00367 * @note You are not able to config GPIO registers until new MCU reset occurs 00368 * @param *GPIOx: GPIOx PORT where you want to lock config registers 00369 * @param GPIO_Pin: GPIO pin(s) where you want to lock config registers 00370 * @retval None 00371 */ 00372 void TM_GPIO_Lock(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 00373 00374 /** 00375 * @brief Gets bit separated pins which were used at least once in library and were not deinitialized 00376 * @param *GPIOx: Pointer to GPIOx peripheral where to check used GPIO pins 00377 * @retval Bit values for used pins 00378 */ 00379 uint16_t TM_GPIO_GetUsedPins(GPIO_TypeDef* GPIOx); 00380 00381 /** 00382 * @brief Gets bit separated pins which were not used at in library or were deinitialized 00383 * @param *GPIOx: Pointer to GPIOx peripheral where to check used GPIO pins 00384 * @retval Bit values for free pins 00385 */ 00386 uint16_t TM_GPIO_GetFreePins(GPIO_TypeDef* GPIOx); 00387 00388 /** 00389 * @} 00390 */ 00391 /** 00392 * @} 00393 */ 00394 /** 00395 * @} 00396 */ 00397 00398 /* C++ detection */ 00399 #ifdef __cplusplus 00400 } 00401 #endif 00402 00403 #endif
Generated on Tue Jul 12 2022 21:40:04 by 1.7.2