hi

Dependents:   hello_enc_test

Fork of Nucleo_Hello_Encoder by David Lowe

Committer:
gregeric
Date:
Sun Oct 04 11:58:58 2015 +0000
Revision:
1:cd7b42c99ff8
Parent:
0:ee5cb967aa17
Added more targets, use HAL macros to read counter value & direction.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gregeric 0:ee5cb967aa17 1 #include "mbed.h"
gregeric 0:ee5cb967aa17 2 /*
gregeric 0:ee5cb967aa17 3 * HAL_TIM_Encoder_MspInit()
gregeric 1:cd7b42c99ff8 4 * Overrides the __weak function stub in stm32f0xx_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 1:cd7b42c99ff8 10 * http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00088500.pdf
gregeric 1:cd7b42c99ff8 11 * Table 11 has GPIO alternate function pinout mappings.
gregeric 1:cd7b42c99ff8 12 *
gregeric 1:cd7b42c99ff8 13 * TIM1_CH1: AF2 @ PA_8 - TIM1 used as system ticker under mbed, so unavailable
gregeric 1:cd7b42c99ff8 14 * TIM1_CH2: AF2 @ PA_9
gregeric 1:cd7b42c99ff8 15 *
gregeric 1:cd7b42c99ff8 16 * TIM3_CH1: AF1 @ PA_6, PB_4; AF0 @ PC_6* *only for F030xC devices
gregeric 1:cd7b42c99ff8 17 * TIM3_CH2: AF1 @ PA_7, PB_5; AF0 @ PC_7*
gregeric 1:cd7b42c99ff8 18 *
gregeric 0:ee5cb967aa17 19 */
gregeric 0:ee5cb967aa17 20
gregeric 0:ee5cb967aa17 21 #ifdef TARGET_STM32F0
gregeric 0:ee5cb967aa17 22 void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
gregeric 0:ee5cb967aa17 23 {
gregeric 0:ee5cb967aa17 24 GPIO_InitTypeDef GPIO_InitStruct;
gregeric 0:ee5cb967aa17 25
gregeric 1:cd7b42c99ff8 26 if (htim->Instance == TIM3) { //PB_4 PB_5 = Nucleo D5 D4
gregeric 0:ee5cb967aa17 27 __TIM3_CLK_ENABLE();
gregeric 1:cd7b42c99ff8 28 __GPIOB_CLK_ENABLE();
gregeric 1:cd7b42c99ff8 29 GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5;
gregeric 0:ee5cb967aa17 30 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
gregeric 0:ee5cb967aa17 31 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
gregeric 0:ee5cb967aa17 32 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
gregeric 0:ee5cb967aa17 33 GPIO_InitStruct.Alternate = GPIO_AF1_TIM3;
gregeric 1:cd7b42c99ff8 34 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
gregeric 0:ee5cb967aa17 35 }
gregeric 0:ee5cb967aa17 36 }
gregeric 0:ee5cb967aa17 37 #endif