void TEST_fillPrimitives(u16 step) { LCD_fillScreen(BLACK); u16 halfStep = (u16) (step / 2), quartStep = (u16) (halfStep / 2), halfQuartStep = (u16) (quartStep / 2); u16 w = LCD_getWidth(), h = LCD_getHeight(); for (u16 x = 0; x < w; x += step) { LCD_drawFastVLine(x, 0, h, DGRAY); } for (u16 y = 0; y < h; y += step) { LCD_drawFastHLine(0, y, w, DGRAY); } for (u16 x = 0; x < w; x += step) { for (u16 y = 0; y < h; y += step) { LCD_drawRect(x, y, halfStep, halfStep, DGREEN); LCD_fillRect(x + halfStep, y + halfStep, halfStep, halfStep, GREENYELLOW); LCD_drawCircle(x + quartStep, y + quartStep, halfQuartStep, GREENYELLOW); LCD_fillCircle(x + halfStep + quartStep, y + halfStep + quartStep, halfQuartStep, DGREEN); LCD_putPixel(x + quartStep, y + quartStep, YELLOW); LCD_drawLine(x + halfStep, y + halfStep, x + step, y + step, WHITE); } } }
int main(void) { char cmd, subcmd, x, y, v, w, r; //variables used for loops, buffering of command bytes, counters etc. uint16_t color; //counters for long stuff that may go over 256 uint8_t pressureThreshhold = 10; TouchScreen_init(); USART_set_baud(6); LCD_init(); //flush any received chars USART_flush(); LCD_drawString("Ready For Command", 0, 10, 1, WHITE, USART_recv); /* Replace with your application code */ while (1) { if(!RX_available()) { TSPoint p = TouchScreen_getPoint(); if(p.z > pressureThreshhold) { USART_printf("X = %d\r\n", p.x); USART_printf("Y = %d\r\n", p.y); USART_printf("Pressure = %d\r\n", p.z); } } else { cmd = USART_recv(); switch(cmd) { case 124: subcmd = USART_recv(); switch(subcmd) { case 1: //clear screen LCD_paint_screen_black(); break; //************************************************************************************************************ case 3: //draw circle x = USART_recv(); y = USART_recv(); r = USART_recv(); // get integer color color = USART_recv(); color = color << 8; color |= USART_recv(); LCD_drawCircle(x, y, r, color); break; case 4: x = USART_recv(); y = USART_recv(); r = USART_recv(); // get integer color color = USART_recv(); //store it and increment RX_read color = color << 8; color |= USART_recv(); LCD_fillCircle(x, y, r, color); break; case 12: //line x = USART_recv(); y = USART_recv(); v = USART_recv(); w = USART_recv(); // get integer color color = USART_recv(); color = color << 8; color |= USART_recv(); LCD_drawLine(x, y, v, w, color); break; //************************************************************************************************************ case 15: x = USART_recv(); y = USART_recv(); v = USART_recv(); w = USART_recv(); // get integer color color = USART_recv(); color = color << 8; color |= USART_recv(); LCD_drawRectangle(x, y, v, w, color); break; //************************************************************************************************************ case 16: //set pixel x = USART_recv(); y = USART_recv(); color = USART_recv(); color = color << 8; color |= USART_recv(); LCD_setPixel(x, y, color); break; case 18: x = USART_recv(); y = USART_recv(); v = USART_recv(); w = USART_recv(); // get integer color color = USART_recv(); color = color << 8; color |= USART_recv(); LCD_fillRectangle(x, y, v, w, color); break; case 20: // draw text x = USART_recv(); y = USART_recv(); // size r = USART_recv(); // get integer color color = USART_recv(); //store it and increment RX_read color = color << 8; color |= USART_recv(); // send string end with 0 LCD_drawString(NULL, x, y, r, color, USART_recv); break; } break; } } } }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_FSMC_Init(); MX_SPI1_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ LCD_Init(LCD_ORIENTATION_PORTRAIT); LCD_setFont(SmallFont); LCD_setBackColor(VGA_BLACK); LCD_fillScr(VGA_BLACK); TSC2046_Init(); TSC2046_Calibration(); LCD_fillScr(VGA_BLACK); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ char buf[100]; int16_t xpos, ypos; while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ LCD_setColor(VGA_BLUE); LCD_drawRect(0, 0, 10, 10); while(!Is_Touhcing()); while (Is_Touhcing()) { // read xpos = TSC2046_Get_Position_X(); ypos = TSC2046_Get_Position_Y(); // clear if (xpos > LCD_WIDTH - 20 && ypos > LCD_HEIGHT - 20) { LCD_fillScr(VGA_BLACK); } // print sprintf(buf, "(x,y)=(%04d, %04d)", xpos, ypos); LCD_setColor(VGA_RED); LCD_setBackColor(VGA_BLACK); LCD_print(buf, 20, 300, 0); // draw pen LCD_setColor(rand() | 0b0111101111101111); LCD_fillCircle(xpos, ypos, 3); // clear button LCD_setColor(VGA_WHITE); LCD_fillRect(LCD_WIDTH - 20, LCD_HEIGHT - 20, LCD_WIDTH - 1, LCD_HEIGHT - 1); // pen indicator LCD_setColor(VGA_GREEN); LCD_drawRect(0, 0, 10, 10); } } /* USER CODE END 3 */ }