Modified Bob Stone's code for ILI9341 QVGA TFT's without touch capability. Navigation is now done with rotary encoders - two for position, & one setting the maxiterations.

Dependencies:   SPI_TFT_ILI9341 TFT_fonts mbed

Fork of Mandelbrot by Bob Stone

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EncoderMspInitF4.cpp Source File

EncoderMspInitF4.cpp

00001 #include "mbed.h"
00002 /*
00003  * HAL_TIM_Encoder_MspInit()
00004  * Overrides the __weak function stub in stm32f4xx_hal_tim.h
00005  *
00006  * Edit the below for your preferred pin wiring & pullup/down
00007  * I have encoder common at 3V3, using GPIO_PULLDOWN on inputs.
00008  * Encoder A&B outputs connected directly to GPIOs.
00009  *
00010  */
00011 
00012 #ifdef TARGET_STM32F4
00013 void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
00014 {
00015     GPIO_InitTypeDef GPIO_InitStruct;
00016 
00017     if (htim->Instance == TIM1) { //PA8 PA9 = Nucleo D7 D8, poss PB0 PB1 usable too (complementary?)
00018         __TIM1_CLK_ENABLE();
00019         __GPIOA_CLK_ENABLE();
00020         GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9;
00021         GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
00022         GPIO_InitStruct.Pull = GPIO_PULLDOWN;
00023         GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
00024         GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
00025         HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
00026     }
00027     else if (htim->Instance == TIM2) { //PA0 PA1 = Nucleo A0 A1, PA5 PB3 = D13 D3 poss too
00028         __TIM2_CLK_ENABLE();
00029         __GPIOA_CLK_ENABLE();
00030         GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1;
00031         GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
00032         GPIO_InitStruct.Pull = GPIO_PULLDOWN;
00033         GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
00034         GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
00035         HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
00036     }
00037     else if (htim->Instance == TIM3) { //PB4 PB5 = Nucleo D5 D4, PA6 PA7 & PC6 PC7 also an option for Nucleo
00038         __TIM3_CLK_ENABLE();
00039         __GPIOB_CLK_ENABLE();
00040         GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5;
00041         GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
00042         GPIO_InitStruct.Pull = GPIO_PULLDOWN;
00043         GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
00044         GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
00045         HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
00046     }
00047     else if (htim->Instance == TIM4) { // PB6 PB7 = Nucleo D10 MORPHO_PB7
00048         __TIM4_CLK_ENABLE();
00049         __GPIOB_CLK_ENABLE();
00050         GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7;
00051         GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
00052         GPIO_InitStruct.Pull = GPIO_PULLDOWN;
00053         GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
00054         GPIO_InitStruct.Alternate = GPIO_AF2_TIM4;
00055         HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
00056     }
00057     else if (htim->Instance == TIM5) { // here for completeness, mbed sytem timer uses this
00058         __TIM5_CLK_ENABLE();
00059         __GPIOA_CLK_ENABLE();
00060         GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1;
00061         GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
00062         GPIO_InitStruct.Pull = GPIO_PULLDOWN;
00063         GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
00064         GPIO_InitStruct.Alternate = GPIO_AF2_TIM5;
00065         HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
00066     }
00067 }
00068 #endif