Dependents:   serial_connected_mcu_nucleo rotary_encoder_mbed serial_connected_mcu_nucleo omuni_speed_pid ... more

Fork of rotary_encoder by tarou yamada

このライブラリは以下のプログラムに基いています https://developer.mbed.org/users/gregeric/code/Nucleo_Hello_Encoder/

Committer:
inst
Date:
Sat Jun 25 05:40:31 2016 +0000
Revision:
10:684e1604e5ea
Parent:
9:d1e6284a13ab
add read() to rotary_encoder;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
inst 9:d1e6284a13ab 1 #include "mbed.h"
inst 9:d1e6284a13ab 2 /*
inst 9:d1e6284a13ab 3 * HAL_TIM_Encoder_MspInit()
inst 9:d1e6284a13ab 4 * Overrides the __weak function stub in stm32f4xx_hal_tim.h
inst 9:d1e6284a13ab 5 *
inst 9:d1e6284a13ab 6 * Edit the below for your preferred pin wiring & pullup/down
inst 9:d1e6284a13ab 7 * I have encoder common at 3V3, using GPIO_PULLDOWN on inputs.
inst 9:d1e6284a13ab 8 * Encoder A&B outputs connected directly to GPIOs.
inst 9:d1e6284a13ab 9 *
inst 9:d1e6284a13ab 10 * http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00108832.pdf
inst 9:d1e6284a13ab 11 * Table 15 has GPIOx AFx pinouts
inst 9:d1e6284a13ab 12 *
inst 9:d1e6284a13ab 13 * TIM1_CH1: AF1 @ PA8, PE9
inst 9:d1e6284a13ab 14 * TIM1_CH2: AF1 @ PA9, PE11
inst 9:d1e6284a13ab 15 *
inst 9:d1e6284a13ab 16 * TIM2_CH1: AF1 @ PA0, PA5, PA15
inst 9:d1e6284a13ab 17 * TIM2_CH2: AF1 @ PA1, PB3
inst 9:d1e6284a13ab 18 *
inst 9:d1e6284a13ab 19 * TIM3_CH1: AF2 @ PA6, PB4, PC6, PE3
inst 9:d1e6284a13ab 20 * TIM3_CH2: AF2 @ PA7, PB5, PC7, PE4
inst 9:d1e6284a13ab 21 *
inst 9:d1e6284a13ab 22 * TIM4_CH1: AF2 @ PB6, PD12
inst 9:d1e6284a13ab 23 * TIM4_CH2: AF2 @ PB7, PD13
inst 9:d1e6284a13ab 24 *
inst 9:d1e6284a13ab 25 * TIM5_CH1: AF2 @ PA0, PF6
inst 9:d1e6284a13ab 26 * TIM5_CH2: AF2 @ PA1, PF7
inst 9:d1e6284a13ab 27 *
inst 9:d1e6284a13ab 28 */
inst 9:d1e6284a13ab 29
inst 9:d1e6284a13ab 30 #ifdef TARGET_STM32L4
inst 9:d1e6284a13ab 31 void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
inst 9:d1e6284a13ab 32 {
inst 9:d1e6284a13ab 33 GPIO_InitTypeDef GPIO_InitStruct;
inst 9:d1e6284a13ab 34
inst 9:d1e6284a13ab 35 if (htim->Instance == TIM1) { //PA8 PA9 = Nucleo D7 D8
inst 9:d1e6284a13ab 36 __TIM1_CLK_ENABLE();
inst 9:d1e6284a13ab 37 __GPIOA_CLK_ENABLE();
inst 9:d1e6284a13ab 38 GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9;
inst 9:d1e6284a13ab 39 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
inst 9:d1e6284a13ab 40 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
inst 9:d1e6284a13ab 41 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
inst 9:d1e6284a13ab 42 GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
inst 9:d1e6284a13ab 43 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
inst 9:d1e6284a13ab 44 }
inst 9:d1e6284a13ab 45 else if (htim->Instance == TIM2) { //PA0 PA1 = Nucleo A0 A1
inst 9:d1e6284a13ab 46 __TIM2_CLK_ENABLE();
inst 9:d1e6284a13ab 47 __GPIOA_CLK_ENABLE();
inst 9:d1e6284a13ab 48 GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1;
inst 9:d1e6284a13ab 49 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
inst 9:d1e6284a13ab 50 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
inst 9:d1e6284a13ab 51 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
inst 9:d1e6284a13ab 52 GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
inst 9:d1e6284a13ab 53 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
inst 9:d1e6284a13ab 54 }
inst 9:d1e6284a13ab 55 else if (htim->Instance == TIM3) { //PB4 PB5 = Nucleo D5 D4
inst 9:d1e6284a13ab 56 __TIM3_CLK_ENABLE();
inst 9:d1e6284a13ab 57 __GPIOB_CLK_ENABLE();
inst 9:d1e6284a13ab 58 GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5;
inst 9:d1e6284a13ab 59 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
inst 9:d1e6284a13ab 60 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
inst 9:d1e6284a13ab 61 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
inst 9:d1e6284a13ab 62 GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
inst 9:d1e6284a13ab 63 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
inst 9:d1e6284a13ab 64 }
inst 9:d1e6284a13ab 65 else if (htim->Instance == TIM4) { // PB6 PB7 = Nucleo D10 MORPHO_PB7
inst 9:d1e6284a13ab 66 __TIM4_CLK_ENABLE();
inst 9:d1e6284a13ab 67 __GPIOB_CLK_ENABLE();
inst 9:d1e6284a13ab 68 GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7;
inst 9:d1e6284a13ab 69 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
inst 9:d1e6284a13ab 70 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
inst 9:d1e6284a13ab 71 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
inst 9:d1e6284a13ab 72 GPIO_InitStruct.Alternate = GPIO_AF2_TIM4;
inst 9:d1e6284a13ab 73 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
inst 9:d1e6284a13ab 74 }
inst 9:d1e6284a13ab 75 else if (htim->Instance == TIM5) { // here for completeness, mbed sytem timer uses this
inst 9:d1e6284a13ab 76 __TIM5_CLK_ENABLE();
inst 9:d1e6284a13ab 77 __GPIOA_CLK_ENABLE();
inst 9:d1e6284a13ab 78 GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1;
inst 9:d1e6284a13ab 79 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
inst 9:d1e6284a13ab 80 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
inst 9:d1e6284a13ab 81 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
inst 9:d1e6284a13ab 82 GPIO_InitStruct.Alternate = GPIO_AF2_TIM5;
inst 9:d1e6284a13ab 83 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
inst 9:d1e6284a13ab 84 }
inst 9:d1e6284a13ab 85 }
inst 9:d1e6284a13ab 86 #endif