Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2018, STMicroelectronics - All Rights Reserved |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 7 | #ifndef STM32_GPIO_H |
| 8 | #define STM32_GPIO_H |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 9 | |
| 10 | #include <utils_def.h> |
| 11 | |
| 12 | #define STM32_GPIOA_BANK U(0x50002000) |
| 13 | #define STM32_GPIOZ_BANK U(0x54004000) |
| 14 | #define STM32_GPIO_BANK_OFFSET U(0x1000) |
| 15 | |
| 16 | #define GPIO_MODE_OFFSET U(0x00) |
| 17 | #define GPIO_TYPE_OFFSET U(0x04) |
| 18 | #define GPIO_SPEED_OFFSET U(0x08) |
| 19 | #define GPIO_PUPD_OFFSET U(0x0C) |
| 20 | #define GPIO_BSRR_OFFSET U(0x18) |
| 21 | #define GPIO_AFRL_OFFSET U(0x20) |
| 22 | #define GPIO_AFRH_OFFSET U(0x24) |
| 23 | |
| 24 | #define GPIO_ALT_LOWER_LIMIT U(0x08) |
| 25 | |
| 26 | #define GPIO_BANK_A U(0x00) |
| 27 | #define GPIO_BANK_B U(0x01) |
| 28 | #define GPIO_BANK_C U(0x02) |
| 29 | #define GPIO_BANK_D U(0x03) |
| 30 | #define GPIO_BANK_E U(0x04) |
| 31 | #define GPIO_BANK_F U(0x05) |
| 32 | #define GPIO_BANK_G U(0x06) |
| 33 | #define GPIO_BANK_H U(0x07) |
| 34 | #define GPIO_BANK_I U(0x08) |
| 35 | #define GPIO_BANK_J U(0x09) |
| 36 | #define GPIO_BANK_K U(0x0A) |
| 37 | #define GPIO_BANK_Z U(0x19) |
| 38 | |
| 39 | #define GPIO_PIN_0 U(0x00) |
| 40 | #define GPIO_PIN_1 U(0x01) |
| 41 | #define GPIO_PIN_2 U(0x02) |
| 42 | #define GPIO_PIN_3 U(0x03) |
| 43 | #define GPIO_PIN_4 U(0x04) |
| 44 | #define GPIO_PIN_5 U(0x05) |
| 45 | #define GPIO_PIN_6 U(0x06) |
| 46 | #define GPIO_PIN_7 U(0x07) |
| 47 | #define GPIO_PIN_8 U(0x08) |
| 48 | #define GPIO_PIN_9 U(0x09) |
| 49 | #define GPIO_PIN_10 U(0x0A) |
| 50 | #define GPIO_PIN_11 U(0x0B) |
| 51 | #define GPIO_PIN_12 U(0x0C) |
| 52 | #define GPIO_PIN_13 U(0x0D) |
| 53 | #define GPIO_PIN_14 U(0x0E) |
| 54 | #define GPIO_PIN_15 U(0x0F) |
| 55 | #define GPIO_PIN_MAX GPIO_PIN_15 |
| 56 | |
| 57 | #define GPIO_ALTERNATE_0 0x00 |
| 58 | #define GPIO_ALTERNATE_1 0x01 |
| 59 | #define GPIO_ALTERNATE_2 0x02 |
| 60 | #define GPIO_ALTERNATE_3 0x03 |
| 61 | #define GPIO_ALTERNATE_4 0x04 |
| 62 | #define GPIO_ALTERNATE_5 0x05 |
| 63 | #define GPIO_ALTERNATE_6 0x06 |
| 64 | #define GPIO_ALTERNATE_7 0x07 |
| 65 | #define GPIO_ALTERNATE_8 0x08 |
| 66 | #define GPIO_ALTERNATE_9 0x09 |
| 67 | #define GPIO_ALTERNATE_10 0x0A |
| 68 | #define GPIO_ALTERNATE_11 0x0B |
| 69 | #define GPIO_ALTERNATE_12 0x0C |
| 70 | #define GPIO_ALTERNATE_13 0x0D |
| 71 | #define GPIO_ALTERNATE_14 0x0E |
| 72 | #define GPIO_ALTERNATE_15 0x0F |
| 73 | #define GPIO_ALTERNATE_MASK U(0x0F) |
| 74 | |
| 75 | #define GPIO_MODE_INPUT 0x00 |
| 76 | #define GPIO_MODE_OUTPUT 0x01 |
| 77 | #define GPIO_MODE_ALTERNATE 0x02 |
| 78 | #define GPIO_MODE_ANALOG 0x03 |
| 79 | #define GPIO_MODE_MASK U(0x03) |
| 80 | |
| 81 | #define GPIO_OPEN_DRAIN U(0x10) |
| 82 | |
| 83 | #define GPIO_SPEED_LOW 0x00 |
| 84 | #define GPIO_SPEED_MEDIUM 0x01 |
| 85 | #define GPIO_SPEED_FAST 0x02 |
| 86 | #define GPIO_SPEED_HIGH 0x03 |
| 87 | #define GPIO_SPEED_MASK U(0x03) |
| 88 | |
| 89 | #define GPIO_NO_PULL 0x00 |
| 90 | #define GPIO_PULL_UP 0x01 |
| 91 | #define GPIO_PULL_DOWN 0x02 |
| 92 | #define GPIO_PULL_MASK U(0x03) |
| 93 | |
| 94 | #ifndef __ASSEMBLY__ |
| 95 | #include <stdint.h> |
| 96 | |
| 97 | void set_gpio(uint32_t bank, uint32_t pin, uint32_t mode, uint32_t speed, |
| 98 | uint32_t pull, uint32_t alternate); |
| 99 | #endif /*__ASSEMBLY__*/ |
| 100 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 101 | #endif /* STM32_GPIO_H */ |