hi
Fork of Nucleo_Hello_Encoder by
Encoder/EncoderMspInitL0.cpp@2:8349e61b6152, 2016-09-01 (annotated)
- Committer:
- sakanakuuun
- Date:
- Thu Sep 01 06:37:22 2016 +0000
- Revision:
- 2:8349e61b6152
- Parent:
- 0:ee5cb967aa17
x
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gregeric | 0:ee5cb967aa17 | 1 | #include "mbed.h" |
gregeric | 0:ee5cb967aa17 | 2 | /* |
gregeric | 0:ee5cb967aa17 | 3 | * HAL_TIM_Encoder_MspInit() |
gregeric | 0:ee5cb967aa17 | 4 | * Overrides the __weak function stub in stm32f4xx_hal_tim.h |
gregeric | 0:ee5cb967aa17 | 5 | * |
gregeric | 0:ee5cb967aa17 | 6 | * Edit the below for your preferred pin wiring & pullup/down |
gregeric | 0:ee5cb967aa17 | 7 | * I have encoder common at 3V3, using GPIO_PULLDOWN on inputs. |
gregeric | 0:ee5cb967aa17 | 8 | * Encoder A&B outputs connected directly to GPIOs. |
gregeric | 0:ee5cb967aa17 | 9 | * |
gregeric | 0:ee5cb967aa17 | 10 | */ |
gregeric | 0:ee5cb967aa17 | 11 | |
gregeric | 0:ee5cb967aa17 | 12 | #ifdef TARGET_STM32L0 |
gregeric | 0:ee5cb967aa17 | 13 | void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) |
gregeric | 0:ee5cb967aa17 | 14 | { |
gregeric | 0:ee5cb967aa17 | 15 | GPIO_InitTypeDef GPIO_InitStruct; |
gregeric | 0:ee5cb967aa17 | 16 | |
gregeric | 0:ee5cb967aa17 | 17 | if (htim->Instance == TIM2) { //PA0 PA1 = Nucleo A0 A1 |
gregeric | 0:ee5cb967aa17 | 18 | __TIM2_CLK_ENABLE(); |
gregeric | 0:ee5cb967aa17 | 19 | __GPIOA_CLK_ENABLE(); |
gregeric | 0:ee5cb967aa17 | 20 | GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1; |
gregeric | 0:ee5cb967aa17 | 21 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
gregeric | 0:ee5cb967aa17 | 22 | GPIO_InitStruct.Pull = GPIO_PULLDOWN; |
gregeric | 0:ee5cb967aa17 | 23 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
gregeric | 0:ee5cb967aa17 | 24 | GPIO_InitStruct.Alternate = GPIO_AF1_TIM2; |
gregeric | 0:ee5cb967aa17 | 25 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
gregeric | 0:ee5cb967aa17 | 26 | } |
gregeric | 0:ee5cb967aa17 | 27 | } |
gregeric | 0:ee5cb967aa17 | 28 | #endif |