Created
July 19, 2019 00:10
-
-
Save surinoel/4c46a87dcff7228036eb38852f9fc4ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Includes ------------------------------------------------------------------*/ | |
#include "main.h" | |
/* Private includes ----------------------------------------------------------*/ | |
/* USER CODE BEGIN Includes */ | |
#include "lcd_ili9341.h" | |
#include "stm32f429i_discovery_ts.h" | |
#include <stdio.h> | |
/* USER CODE END Includes */ | |
/* Private typedef -----------------------------------------------------------*/ | |
/* USER CODE BEGIN PTD */ | |
/* USER CODE END PTD */ | |
/* Private define ------------------------------------------------------------*/ | |
/* USER CODE BEGIN PD */ | |
/* USER CODE END PD */ | |
/* Private macro -------------------------------------------------------------*/ | |
/* USER CODE BEGIN PM */ | |
/* USER CODE END PM */ | |
/* Private variables ---------------------------------------------------------*/ | |
I2C_HandleTypeDef hi2c3; | |
LTDC_HandleTypeDef hltdc; | |
SPI_HandleTypeDef hspi5; | |
UART_HandleTypeDef huart1; | |
/* USER CODE BEGIN PV */ | |
/* USER CODE END PV */ | |
/* Private function prototypes -----------------------------------------------*/ | |
void SystemClock_Config(void); | |
static void MX_GPIO_Init(void); | |
static void MX_LTDC_Init(void); | |
static void MX_SPI5_Init(void); | |
static void MX_USART1_UART_Init(void); | |
static void MX_I2C3_Init(void); | |
/* USER CODE BEGIN PFP */ | |
int _write(int file, char *ptr, int len) | |
{ | |
HAL_UART_Transmit(&huart1, (uint8_t *)ptr, len, 0xFFFFFFFF); | |
return len; | |
} | |
/* USER CODE END PFP */ | |
/* Private user code ---------------------------------------------------------*/ | |
/* USER CODE BEGIN 0 */ | |
#define LCD_FRAMEBUFFER_SIZE (LCD_PIXEL_WIDTH * LCD_PIXEL_HEIGHT) | |
uint16_t frame_buffer[LCD_FRAMEBUFFER_SIZE]; | |
/* USER CODE END 0 */ | |
/** | |
* @brief The application entry point. | |
* @retval int | |
*/ | |
int main(void) | |
{ | |
/* USER CODE BEGIN 1 */ | |
int idx = -1; | |
int flag = 0; | |
int color[] = { | |
LCD_COLOR_WHITE, | |
LCD_COLOR_BLACK, | |
LCD_COLOR_GREY, | |
LCD_COLOR_BLUE, | |
LCD_COLOR_BLUE2, | |
LCD_COLOR_RED, | |
LCD_COLOR_MAGENTA, | |
LCD_COLOR_GREEN, | |
LCD_COLOR_CYAN, | |
LCD_COLOR_YELLOW | |
}; | |
/* USER CODE END 1 */ | |
/* MCU Configuration--------------------------------------------------------*/ | |
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */ | |
HAL_Init(); | |
/* USER CODE BEGIN Init */ | |
/* USER CODE END Init */ | |
/* Configure the system clock */ | |
SystemClock_Config(); | |
/* USER CODE BEGIN SysInit */ | |
TS_StateTypeDef stTouch; | |
BSP_TS_Init(240, 320); | |
/* USER CODE END SysInit */ | |
/* Initialize all configured peripherals */ | |
MX_GPIO_Init(); | |
MX_LTDC_Init(); | |
MX_SPI5_Init(); | |
MX_USART1_UART_Init(); | |
MX_I2C3_Init(); | |
/* USER CODE BEGIN 2 */ | |
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, GPIO_PIN_SET); | |
LCD_PowerOn(); | |
HAL_LTDC_SetAddress(&hltdc, (uint32_t)frame_buffer, 0); | |
/* USER CODE END 2 */ | |
/* Infinite loop */ | |
/* USER CODE BEGIN WHILE */ | |
while (1) | |
{ | |
/* USER CODE END WHILE */ | |
/* USER CODE BEGIN 3 */ | |
BSP_TS_GetState(&stTouch); | |
if(stTouch.TouchDetected) { | |
if(!flag) { | |
flag = 1; | |
printf("X : %d\r\n", stTouch.X); | |
printf("Y : %d\r\n", stTouch.Y); | |
if(++idx == 11) { | |
idx = 0; | |
} | |
for(int j=0; j<LCD_FRAMEBUFFER_SIZE; j++) { | |
frame_buffer[j] = color[idx]; | |
} | |
HAL_Delay(200); | |
} | |
} | |
else { | |
flag = 0; | |
} | |
} | |
/* USER CODE END 3 */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment