|
| 1 | +/* |
| 2 | + ******************************************************************************* |
| 3 | + * Copyright (c) 2018, STMicroelectronics |
| 4 | + * All rights reserved. |
| 5 | + * |
| 6 | + * Redistribution and use in source and binary forms, with or without |
| 7 | + * modification, are permitted provided that the following conditions are met: |
| 8 | + * |
| 9 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 10 | + * this list of conditions and the following disclaimer. |
| 11 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | + * this list of conditions and the following disclaimer in the documentation |
| 13 | + * and/or other materials provided with the distribution. |
| 14 | + * 3. Neither the name of STMicroelectronics nor the names of its contributors |
| 15 | + * may be used to endorse or promote products derived from this software |
| 16 | + * without specific prior written permission. |
| 17 | + * |
| 18 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 22 | + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 24 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 25 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 26 | + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | + ******************************************************************************* |
| 29 | + * Based on mbed-os/target/TARGET_STM/TARGET_STMYY/pin_device.h |
| 30 | + */ |
| 31 | +#ifndef _PINCONFIG_H |
| 32 | +#define _PINCONFIG_H |
| 33 | + |
| 34 | +#include "PinAF_STM32F1.h" |
| 35 | +#include "stm32yyxx_ll_gpio.h" |
| 36 | + |
| 37 | +static inline void pin_DisconnectDebug(PinName pin) |
| 38 | +{ |
| 39 | +#ifdef STM32F1xx |
| 40 | + pinF1_DisconnectDebug(pin); |
| 41 | +#endif /* STM32F1xx */ |
| 42 | +} |
| 43 | + |
| 44 | +static inline void pin_PullConfig(GPIO_TypeDef *gpio, uint32_t ll_pin, uint32_t pull_config) |
| 45 | +{ |
| 46 | +#ifdef STM32F1xx |
| 47 | + uint32_t function = LL_GPIO_GetPinMode(gpio, ll_pin); |
| 48 | +#endif |
| 49 | + |
| 50 | + switch (pull_config) { |
| 51 | + case GPIO_PULLUP: |
| 52 | +#ifdef STM32F1xx |
| 53 | + if (function == LL_GPIO_MODE_FLOATING) { |
| 54 | + LL_GPIO_SetPinMode(gpio, ll_pin, LL_GPIO_MODE_INPUT); |
| 55 | + } |
| 56 | +#endif |
| 57 | + LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_UP); |
| 58 | + break; |
| 59 | + case GPIO_PULLDOWN: |
| 60 | +#ifdef STM32F1xx |
| 61 | + if (function == LL_GPIO_MODE_FLOATING) { |
| 62 | + LL_GPIO_SetPinMode(gpio, ll_pin, LL_GPIO_MODE_INPUT); |
| 63 | + } |
| 64 | +#endif |
| 65 | + LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_DOWN); |
| 66 | + break; |
| 67 | + default: |
| 68 | +#ifdef STM32F1xx |
| 69 | + /* Input+NoPull = Floating for F1 family */ |
| 70 | + if (function == LL_GPIO_MODE_INPUT) { |
| 71 | + LL_GPIO_SetPinMode(gpio, ll_pin, LL_GPIO_MODE_FLOATING); |
| 72 | + } |
| 73 | +#else |
| 74 | + LL_GPIO_SetPinPull(gpio, ll_pin, LL_GPIO_PULL_NO); |
| 75 | +#endif |
| 76 | + break; |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +static inline void pin_SetAFPin(GPIO_TypeDef *gpio, PinName pin, uint32_t afnum) |
| 81 | +{ |
| 82 | +#ifdef STM32F1xx |
| 83 | + UNUSED(gpio); |
| 84 | + UNUSED(pin); |
| 85 | + pin_SetF1AFPin(afnum); |
| 86 | +#else |
| 87 | + uint32_t ll_pin = STM_LL_GPIO_PIN(pin); |
| 88 | + |
| 89 | + if (STM_PIN(pin) > 7) { |
| 90 | + LL_GPIO_SetAFPin_8_15(gpio, ll_pin, afnum); |
| 91 | + } else { |
| 92 | + LL_GPIO_SetAFPin_0_7(gpio, ll_pin, afnum); |
| 93 | + } |
| 94 | +#endif |
| 95 | +} |
| 96 | + |
| 97 | +#endif |
0 commit comments