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 stm32f1xx_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/CD00161566.pdf
inst 9:d1e6284a13ab 11 * Table 5 has GPIO alternate function pinout mappings.
inst 9:d1e6284a13ab 12 *
inst 9:d1e6284a13ab 13 * TIM1_CH1: default PA_8, remap PE_9
inst 9:d1e6284a13ab 14 * TIM1_CH2: default PA_9, remap PE_11
inst 9:d1e6284a13ab 15 *
inst 9:d1e6284a13ab 16 * TIM2_CH1: default PA_0
inst 9:d1e6284a13ab 17 * TIM2_CH2: default PA_1, remap PB_3
inst 9:d1e6284a13ab 18 *
inst 9:d1e6284a13ab 19 * TIM3_CH1: default PA_6, remap PB_4, PC_6
inst 9:d1e6284a13ab 20 * TIM3_CH2: default PA_7, remap PB_5, PC_7
inst 9:d1e6284a13ab 21 *
inst 9:d1e6284a13ab 22 * TIM4_CH1: default PB_6, remap PD_12
inst 9:d1e6284a13ab 23 * TIM4_CH2: default PB_7, remap PD_13
inst 9:d1e6284a13ab 24 *
inst 9:d1e6284a13ab 25 * NB one of these timers will be the employed by mbed as systick, unavailable as encoder.
inst 9:d1e6284a13ab 26 */
inst 9:d1e6284a13ab 27
inst 9:d1e6284a13ab 28 #ifdef TARGET_STM32F1
inst 9:d1e6284a13ab 29 void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
inst 9:d1e6284a13ab 30 {
inst 9:d1e6284a13ab 31 GPIO_InitTypeDef GPIO_InitStruct;
inst 9:d1e6284a13ab 32
inst 9:d1e6284a13ab 33 if (htim->Instance == TIM1) { //PA8 PA9 = Nucleo D7 D8
inst 9:d1e6284a13ab 34 __TIM1_CLK_ENABLE();
inst 9:d1e6284a13ab 35 __GPIOA_CLK_ENABLE();
inst 9:d1e6284a13ab 36 GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9;
inst 9:d1e6284a13ab 37 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
inst 9:d1e6284a13ab 38 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
inst 9:d1e6284a13ab 39 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
inst 9:d1e6284a13ab 40 // GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
inst 9:d1e6284a13ab 41 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
inst 9:d1e6284a13ab 42 }
inst 9:d1e6284a13ab 43 else if (htim->Instance == TIM2) { //PA0 PA1 = Nucleo A0 A1
inst 9:d1e6284a13ab 44 __TIM2_CLK_ENABLE();
inst 9:d1e6284a13ab 45 __GPIOA_CLK_ENABLE();
inst 9:d1e6284a13ab 46 GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1;
inst 9:d1e6284a13ab 47 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
inst 9:d1e6284a13ab 48 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
inst 9:d1e6284a13ab 49 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
inst 9:d1e6284a13ab 50 // GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
inst 9:d1e6284a13ab 51 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
inst 9:d1e6284a13ab 52 }
inst 9:d1e6284a13ab 53 else if (htim->Instance == TIM3) { //PA6 PA7 = Nucleo D12 D11
inst 9:d1e6284a13ab 54 __TIM3_CLK_ENABLE();
inst 9:d1e6284a13ab 55 __GPIOA_CLK_ENABLE();
inst 9:d1e6284a13ab 56 GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7;
inst 9:d1e6284a13ab 57 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
inst 9:d1e6284a13ab 58 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
inst 9:d1e6284a13ab 59 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
inst 9:d1e6284a13ab 60 // GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
inst 9:d1e6284a13ab 61 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
inst 9:d1e6284a13ab 62 }
inst 9:d1e6284a13ab 63 else if (htim->Instance == TIM4) { // PB6 PB7 = Nucleo D10 MORPHO PB7
inst 9:d1e6284a13ab 64 __TIM4_CLK_ENABLE();
inst 9:d1e6284a13ab 65 __GPIOB_CLK_ENABLE();
inst 9:d1e6284a13ab 66 GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7;
inst 9:d1e6284a13ab 67 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
inst 9:d1e6284a13ab 68 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
inst 9:d1e6284a13ab 69 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
inst 9:d1e6284a13ab 70 // GPIO_InitStruct.Alternate = GPIO_AF2_TIM4;
inst 9:d1e6284a13ab 71 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
inst 9:d1e6284a13ab 72 }
inst 9:d1e6284a13ab 73 }
inst 9:d1e6284a13ab 74 #endif