|
| 1 | +/* |
| 2 | + ******************************************************************************* |
| 3 | + * Copyright (c) 2017, 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 | + */ |
| 30 | + |
| 31 | + #ifndef _PINAF_STM32F1_H |
| 32 | + #define _PINAF_STM32F1_H |
| 33 | + |
| 34 | + #include "Arduino.h" |
| 35 | + |
| 36 | + #ifdef __cplusplus |
| 37 | + extern "C" { |
| 38 | + #endif |
| 39 | + |
| 40 | + static inline void pin_SetF1AFPin(uint32_t afnum) |
| 41 | + { |
| 42 | + // Enable AFIO clock |
| 43 | + __HAL_RCC_AFIO_CLK_ENABLE(); |
| 44 | + |
| 45 | + if (afnum > 0) { |
| 46 | + switch (afnum) { |
| 47 | + case 1: // Remap SPI1 |
| 48 | + __HAL_AFIO_REMAP_SPI1_ENABLE(); |
| 49 | + break; |
| 50 | + case 2: // Remap I2C1 |
| 51 | + __HAL_AFIO_REMAP_I2C1_ENABLE(); |
| 52 | + break; |
| 53 | + case 3: // Remap USART1 |
| 54 | + __HAL_AFIO_REMAP_USART1_ENABLE(); |
| 55 | + break; |
| 56 | + case 4: // Remap USART2 |
| 57 | + __HAL_AFIO_REMAP_USART2_ENABLE(); |
| 58 | + break; |
| 59 | + case 5: // Partial Remap USART3 |
| 60 | + __HAL_AFIO_REMAP_USART3_PARTIAL(); |
| 61 | + break; |
| 62 | + case 6: // Partial Remap TIM1 |
| 63 | + __HAL_AFIO_REMAP_TIM1_PARTIAL(); |
| 64 | + break; |
| 65 | + case 7: // Partial Remap TIM3 |
| 66 | + __HAL_AFIO_REMAP_TIM3_PARTIAL(); |
| 67 | + break; |
| 68 | + case 8: // Full Remap TIM2 |
| 69 | + __HAL_AFIO_REMAP_TIM2_ENABLE(); |
| 70 | + break; |
| 71 | + case 9: // Full Remap TIM3 |
| 72 | + __HAL_AFIO_REMAP_TIM3_ENABLE(); |
| 73 | + break; |
| 74 | + #if defined(AFIO_MAPR_CAN_REMAP_REMAP1) |
| 75 | + case 10: // CAN_RX mapped to PB8, CAN_TX mapped to PB9 |
| 76 | + __HAL_AFIO_REMAP_CAN1_2(); |
| 77 | + break; |
| 78 | + case 11: // CAN_RX mapped to PB8, CAN_TX mapped to PB9 |
| 79 | + __HAL_AFIO_REMAP_CAN1_3(); |
| 80 | + break; |
| 81 | + #endif |
| 82 | + case 12: // Full Remap USART3 |
| 83 | + __HAL_AFIO_REMAP_USART3_ENABLE(); |
| 84 | + break; |
| 85 | + case 13: // Full Remap TIM1 |
| 86 | + __HAL_AFIO_REMAP_TIM1_ENABLE(); |
| 87 | + break; |
| 88 | + case 14: // Full Remap TIM4 |
| 89 | + __HAL_AFIO_REMAP_TIM4_ENABLE(); |
| 90 | + break; |
| 91 | + default: |
| 92 | + break; |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + #ifdef __cplusplus |
| 98 | + } |
| 99 | + #endif |
| 100 | + |
| 101 | + #endif /* _PINAF_STM32F1_H */ |
0 commit comments