test
targets/TARGET_STM/TARGET_STM32F7/pin_device.h@2:4364577b5ad8, 2020-11-09 (annotated)
- Committer:
- elijahsj
- Date:
- Mon Nov 09 00:33:19 2020 -0500
- Revision:
- 2:4364577b5ad8
- Parent:
- 1:8a094db1347f
copied mbed library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elijahsj | 1:8a094db1347f | 1 | /* mbed Microcontroller Library |
elijahsj | 1:8a094db1347f | 2 | ******************************************************************************* |
elijahsj | 1:8a094db1347f | 3 | * Copyright (c) 2016, STMicroelectronics |
elijahsj | 1:8a094db1347f | 4 | * All rights reserved. |
elijahsj | 1:8a094db1347f | 5 | * |
elijahsj | 1:8a094db1347f | 6 | * Redistribution and use in source and binary forms, with or without |
elijahsj | 1:8a094db1347f | 7 | * modification, are permitted provided that the following conditions are met: |
elijahsj | 1:8a094db1347f | 8 | * |
elijahsj | 1:8a094db1347f | 9 | * 1. Redistributions of source code must retain the above copyright notice, |
elijahsj | 1:8a094db1347f | 10 | * this list of conditions and the following disclaimer. |
elijahsj | 1:8a094db1347f | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
elijahsj | 1:8a094db1347f | 12 | * this list of conditions and the following disclaimer in the documentation |
elijahsj | 1:8a094db1347f | 13 | * and/or other materials provided with the distribution. |
elijahsj | 1:8a094db1347f | 14 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
elijahsj | 1:8a094db1347f | 15 | * may be used to endorse or promote products derived from this software |
elijahsj | 1:8a094db1347f | 16 | * without specific prior written permission. |
elijahsj | 1:8a094db1347f | 17 | * |
elijahsj | 1:8a094db1347f | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
elijahsj | 1:8a094db1347f | 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
elijahsj | 1:8a094db1347f | 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
elijahsj | 1:8a094db1347f | 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
elijahsj | 1:8a094db1347f | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
elijahsj | 1:8a094db1347f | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
elijahsj | 1:8a094db1347f | 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
elijahsj | 1:8a094db1347f | 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
elijahsj | 1:8a094db1347f | 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
elijahsj | 1:8a094db1347f | 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
elijahsj | 1:8a094db1347f | 28 | ******************************************************************************* |
elijahsj | 1:8a094db1347f | 29 | */ |
elijahsj | 1:8a094db1347f | 30 | #ifndef MBED_PIN_DEVICE_H |
elijahsj | 1:8a094db1347f | 31 | #define MBED_PIN_DEVICE_H |
elijahsj | 1:8a094db1347f | 32 | |
elijahsj | 1:8a094db1347f | 33 | #include "cmsis.h" |
elijahsj | 1:8a094db1347f | 34 | |
elijahsj | 1:8a094db1347f | 35 | // when LL is available, below include can be used |
elijahsj | 1:8a094db1347f | 36 | // #include "stm32f7xx_ll_gpio.h" |
elijahsj | 1:8a094db1347f | 37 | // until then let's define locally the required functions |
elijahsj | 1:8a094db1347f | 38 | #define LL_GPIO_PIN_0 GPIO_BSRR_BS_0 /*!< Select pin 0 */ |
elijahsj | 1:8a094db1347f | 39 | #define LL_GPIO_PIN_1 GPIO_BSRR_BS_1 /*!< Select pin 1 */ |
elijahsj | 1:8a094db1347f | 40 | #define LL_GPIO_PIN_2 GPIO_BSRR_BS_2 /*!< Select pin 2 */ |
elijahsj | 1:8a094db1347f | 41 | #define LL_GPIO_PIN_3 GPIO_BSRR_BS_3 /*!< Select pin 3 */ |
elijahsj | 1:8a094db1347f | 42 | #define LL_GPIO_PIN_4 GPIO_BSRR_BS_4 /*!< Select pin 4 */ |
elijahsj | 1:8a094db1347f | 43 | #define LL_GPIO_PIN_5 GPIO_BSRR_BS_5 /*!< Select pin 5 */ |
elijahsj | 1:8a094db1347f | 44 | #define LL_GPIO_PIN_6 GPIO_BSRR_BS_6 /*!< Select pin 6 */ |
elijahsj | 1:8a094db1347f | 45 | #define LL_GPIO_PIN_7 GPIO_BSRR_BS_7 /*!< Select pin 7 */ |
elijahsj | 1:8a094db1347f | 46 | #define LL_GPIO_PIN_8 GPIO_BSRR_BS_8 /*!< Select pin 8 */ |
elijahsj | 1:8a094db1347f | 47 | #define LL_GPIO_PIN_9 GPIO_BSRR_BS_9 /*!< Select pin 9 */ |
elijahsj | 1:8a094db1347f | 48 | #define LL_GPIO_PIN_10 GPIO_BSRR_BS_10 /*!< Select pin 10 */ |
elijahsj | 1:8a094db1347f | 49 | #define LL_GPIO_PIN_11 GPIO_BSRR_BS_11 /*!< Select pin 11 */ |
elijahsj | 1:8a094db1347f | 50 | #define LL_GPIO_PIN_12 GPIO_BSRR_BS_12 /*!< Select pin 12 */ |
elijahsj | 1:8a094db1347f | 51 | #define LL_GPIO_PIN_13 GPIO_BSRR_BS_13 /*!< Select pin 13 */ |
elijahsj | 1:8a094db1347f | 52 | #define LL_GPIO_PIN_14 GPIO_BSRR_BS_14 /*!< Select pin 14 */ |
elijahsj | 1:8a094db1347f | 53 | #define LL_GPIO_PIN_15 GPIO_BSRR_BS_15 /*!< Select pin 15 */ |
elijahsj | 1:8a094db1347f | 54 | |
elijahsj | 1:8a094db1347f | 55 | #define LL_GPIO_MODE_INPUT ((uint32_t)0x00000000U) /*!< Select input mode */ |
elijahsj | 1:8a094db1347f | 56 | #define LL_GPIO_MODE_OUTPUT GPIO_MODER_MODER0_0 /*!< Select output mode */ |
elijahsj | 1:8a094db1347f | 57 | #define LL_GPIO_MODE_ALTERNATE GPIO_MODER_MODER0_1 /*!< Select alternate function mode */ |
elijahsj | 1:8a094db1347f | 58 | #define LL_GPIO_MODE_ANALOG GPIO_MODER_MODER0 /*!< Select analog mode */ |
elijahsj | 1:8a094db1347f | 59 | |
elijahsj | 1:8a094db1347f | 60 | #define LL_GPIO_OUTPUT_PUSHPULL ((uint32_t)0x00000000U) /*!< Select push-pull as output type */ |
elijahsj | 1:8a094db1347f | 61 | #define LL_GPIO_OUTPUT_OPENDRAIN GPIO_OTYPER_OT_0 /*!< Select open-drain as output type */ |
elijahsj | 1:8a094db1347f | 62 | |
elijahsj | 1:8a094db1347f | 63 | #define LL_GPIO_PULL_NO ((uint32_t)0x00000000U) /*!< Select I/O no pull */ |
elijahsj | 1:8a094db1347f | 64 | #define LL_GPIO_PULL_UP GPIO_PUPDR_PUPDR0_0 /*!< Select I/O pull up */ |
elijahsj | 1:8a094db1347f | 65 | #define LL_GPIO_PULL_DOWN GPIO_PUPDR_PUPDR0_1 /*!< Select I/O pull down */ |
elijahsj | 1:8a094db1347f | 66 | |
elijahsj | 1:8a094db1347f | 67 | #define LL_GPIO_SPEED_FREQ_LOW ((uint32_t)0x00000000U) /*!< Select I/O low output speed */ |
elijahsj | 1:8a094db1347f | 68 | #define LL_GPIO_SPEED_FREQ_MEDIUM GPIO_OSPEEDER_OSPEEDR0_0 /*!< Select I/O medium output speed */ |
elijahsj | 1:8a094db1347f | 69 | #define LL_GPIO_SPEED_FREQ_HIGH GPIO_OSPEEDER_OSPEEDR0_1 /*!< Select I/O fast output speed */ |
elijahsj | 1:8a094db1347f | 70 | #define LL_GPIO_SPEED_FREQ_VERY_HIGH GPIO_OSPEEDER_OSPEEDR0 /*!< Select I/O high output speed */ |
elijahsj | 1:8a094db1347f | 71 | |
elijahsj | 1:8a094db1347f | 72 | |
elijahsj | 1:8a094db1347f | 73 | __STATIC_INLINE void LL_GPIO_SetAFPin_0_7(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Alternate) |
elijahsj | 1:8a094db1347f | 74 | { |
elijahsj | 1:8a094db1347f | 75 | MODIFY_REG(GPIOx->AFR[0], (0xFU << (POSITION_VAL(Pin) * 4U)), |
elijahsj | 1:8a094db1347f | 76 | (Alternate << (POSITION_VAL(Pin) * 4U))); |
elijahsj | 1:8a094db1347f | 77 | } |
elijahsj | 1:8a094db1347f | 78 | |
elijahsj | 1:8a094db1347f | 79 | __STATIC_INLINE void LL_GPIO_SetAFPin_8_15(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Alternate) |
elijahsj | 1:8a094db1347f | 80 | { |
elijahsj | 1:8a094db1347f | 81 | MODIFY_REG(GPIOx->AFR[1], (0xFU << (POSITION_VAL(Pin >> 8U) * 4U)), |
elijahsj | 1:8a094db1347f | 82 | (Alternate << (POSITION_VAL(Pin >> 8U) * 4U))); |
elijahsj | 1:8a094db1347f | 83 | } |
elijahsj | 1:8a094db1347f | 84 | __STATIC_INLINE void LL_GPIO_SetPinMode(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Mode) |
elijahsj | 1:8a094db1347f | 85 | { |
elijahsj | 1:8a094db1347f | 86 | MODIFY_REG(GPIOx->MODER, (GPIO_MODER_MODER0 << (POSITION_VAL(Pin) * 2U)), (Mode << (POSITION_VAL(Pin) * 2U))); |
elijahsj | 1:8a094db1347f | 87 | } |
elijahsj | 1:8a094db1347f | 88 | __STATIC_INLINE uint32_t LL_GPIO_GetPinMode(GPIO_TypeDef *GPIOx, uint32_t Pin) |
elijahsj | 1:8a094db1347f | 89 | { |
elijahsj | 1:8a094db1347f | 90 | return (uint32_t)(READ_BIT(GPIOx->MODER, ((Pin * Pin) * GPIO_MODER_MODER0)) / (Pin * Pin)); |
elijahsj | 1:8a094db1347f | 91 | } |
elijahsj | 1:8a094db1347f | 92 | __STATIC_INLINE void LL_GPIO_SetPinPull(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Pull) |
elijahsj | 1:8a094db1347f | 93 | { |
elijahsj | 1:8a094db1347f | 94 | MODIFY_REG(GPIOx->PUPDR, (GPIO_PUPDR_PUPDR0 << (POSITION_VAL(Pin) * 2U)), (Pull << (POSITION_VAL(Pin) * 2U))); |
elijahsj | 1:8a094db1347f | 95 | } |
elijahsj | 1:8a094db1347f | 96 | __STATIC_INLINE void LL_GPIO_SetPinOutputType(GPIO_TypeDef *GPIOx, uint32_t PinMask, uint32_t OutputType) |
elijahsj | 1:8a094db1347f | 97 | { |
elijahsj | 1:8a094db1347f | 98 | MODIFY_REG(GPIOx->OTYPER, PinMask, (PinMask * OutputType)); |
elijahsj | 1:8a094db1347f | 99 | } |
elijahsj | 1:8a094db1347f | 100 | __STATIC_INLINE void LL_GPIO_SetPinSpeed(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Speed) |
elijahsj | 1:8a094db1347f | 101 | { |
elijahsj | 1:8a094db1347f | 102 | MODIFY_REG(GPIOx->OSPEEDR, (GPIO_OSPEEDER_OSPEEDR0 << (POSITION_VAL(Pin) * 2U)), |
elijahsj | 1:8a094db1347f | 103 | (Speed << (POSITION_VAL(Pin) * 2U))); |
elijahsj | 1:8a094db1347f | 104 | } |
elijahsj | 1:8a094db1347f | 105 | // Above lines shall be defined in LL when available |
elijahsj | 1:8a094db1347f | 106 | |
elijahsj | 1:8a094db1347f | 107 | extern const uint32_t ll_pin_defines[16]; |
elijahsj | 1:8a094db1347f | 108 | |
elijahsj | 1:8a094db1347f | 109 | /* Family specific implementations */ |
elijahsj | 1:8a094db1347f | 110 | static inline void stm_pin_DisconnectDebug(PinName pin) |
elijahsj | 1:8a094db1347f | 111 | { |
elijahsj | 1:8a094db1347f | 112 | /* empty for now */ |
elijahsj | 1:8a094db1347f | 113 | } |
elijahsj | 1:8a094db1347f | 114 | |
elijahsj | 1:8a094db1347f | 115 | static inline void stm_pin_PullConfig(GPIO_TypeDef *gpio, uint32_t ll_pin, uint32_t pull_config) |
elijahsj | 1:8a094db1347f | 116 | { |
elijahsj | 1:8a094db1347f | 117 | switch (pull_config) { |
elijahsj | 1:8a094db1347f | 118 | case GPIO_PULLUP: |
elijahsj | 1:8a094db1347f | 119 | LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_UP); |
elijahsj | 1:8a094db1347f | 120 | break; |
elijahsj | 1:8a094db1347f | 121 | case GPIO_PULLDOWN: |
elijahsj | 1:8a094db1347f | 122 | LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN); |
elijahsj | 1:8a094db1347f | 123 | break; |
elijahsj | 1:8a094db1347f | 124 | default: |
elijahsj | 1:8a094db1347f | 125 | LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_NO); |
elijahsj | 1:8a094db1347f | 126 | break; |
elijahsj | 1:8a094db1347f | 127 | } |
elijahsj | 1:8a094db1347f | 128 | } |
elijahsj | 1:8a094db1347f | 129 | |
elijahsj | 1:8a094db1347f | 130 | static inline void stm_pin_SetAFPin( GPIO_TypeDef *gpio, PinName pin, uint32_t afnum) |
elijahsj | 1:8a094db1347f | 131 | { |
elijahsj | 1:8a094db1347f | 132 | uint32_t ll_pin = ll_pin_defines[STM_PIN(pin)]; |
elijahsj | 1:8a094db1347f | 133 | |
elijahsj | 1:8a094db1347f | 134 | if (STM_PIN(pin) > 7) |
elijahsj | 1:8a094db1347f | 135 | LL_GPIO_SetAFPin_8_15(gpio, ll_pin, afnum); |
elijahsj | 1:8a094db1347f | 136 | else |
elijahsj | 1:8a094db1347f | 137 | LL_GPIO_SetAFPin_0_7(gpio, ll_pin, afnum); |
elijahsj | 1:8a094db1347f | 138 | } |
elijahsj | 1:8a094db1347f | 139 | |
elijahsj | 1:8a094db1347f | 140 | #endif |