1.多任務運行說明
此次測試是在之前MultiTimer的基礎上增加ILI9341 TFT屏驅動,并同時運行led燈閃+串口打印+TFT屏顯示三個任務,看起來像是同時運行的,實際上是利用了MultiTimer的功能進行時間片輪詢操作。
2.TFT屏驅動移植
TFT屏驅動采用GDF310的硬件SPI,IO口接法如下;由于都是數據往屏幕寫,沒有涉及返回的數據,實際上PA6<--SPI0_MISO可以不接;另外就是注意PA5只連到了JP2的中間腳,如果接線到JP7或者JP8上的PA5,需要在JP2上街跳線帽;我的線是接到JP8的PA5腳的,因此用跳線帽將JP2的PA5與Dx相連;
PA5 SPI0_SCK
PA6 SPI0_MISO
PA7 SPI0_MOSI
PB5 LCD_CS
PB4 LCD_RST
PB3 LCD_D/C
驅動代碼我參考了GD32F150R的SPI_TFT_LCD_Driver,運氣比較好,拿過來小改了一下就可以跑了;以下是屏幕測試代碼,
void tft_test_func(void) { switch(tft_test.state) { case 0: num_test2(); break; case 1: font_test2_1(); break; case 2: font_test2_2(); break; case 3: color_test2(BLUE,YELLOW,"Yellow"); break; case 4: color_test2(BLACK,WHITE,"White"); break; case 5: color_test2(WHITE,BLACK,"Black"); break; case 6: color_test2(WHITE,RED,"Red"); break; case 7: color_test2(BLUE,GREEN,"Green"); break; case 8: color_test2(YELLOW,BLUE,"Blue"); break; case 9: draw_test2(); break; default: break; } tft_test.state++; if(tft_test.state >= 10) { tft_test.state = 0; } }
3.主函數部分
總共創建了4個任務,全部由MultiTimerYield()進行調度運行,主程序部分代碼如下,可以看到液晶屏顯示的任務是放到exampleTimer1Callback()中運行了,定時周期為2s。
#include #include "gd32f3x0.h" #include "gd32f310k_start.h" #include "systick.h" #include "MultiTimer.h" #include "app.h" #include "hal_uart.h" #include "tft_test.h" #include "lcd_driver.h" MultiTimer timer1; MultiTimer timer2; MultiTimer timer3; MultiTimer timer4; void exampleTimer1Callback(MultiTimer* timer, void *userData) { printf("exampleTimer1Callback-> %s.rn", (char*)userData); MultiTimerStart(timer, 2000, exampleTimer1Callback, userData); // gpio_bit_toggle(GPIOA, GPIO_PIN_8); tft_test_func(); } void exampleTimer2Callback(MultiTimer* timer, void *userData) { printf("exampleTimer2Callback-> %s.rn", (char*)userData); } void exampleTimer3Callback(MultiTimer* timer, void *userData) { printf("exampleTimer3Callback-> %s.rn", (char*)userData); MultiTimerStart(timer, 4567, exampleTimer3Callback, userData); } void exampleTimer4Callback(MultiTimer* timer, void *userData) { MultiTimerStart(timer, 500, exampleTimer4Callback, userData); gpio_bit_toggle(GPIOA, GPIO_PIN_8); } /*! brief main function param[in] none param[out] none retval none */ int main(void) { systick_config(); /* enable the LED GPIO clock */ rcu_periph_clock_enable(RCU_GPIOA); rcu_periph_clock_enable(RCU_GPIOB); /* configure led GPIO port */ gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_8); gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_8); gpio_bit_reset(GPIOA, GPIO_PIN_8); /* initilize the com */ usart0_gpio_config(); usart0_config(); /* initialize lcd */ lcd_init(); MultiTimerInstall(PlatformTicksGetFunc); MultiTimerStart(&timer1, 2000, exampleTimer1Callback, "2000ms CYCLE timer"); MultiTimerStart(&timer2, 5000, exampleTimer2Callback, "5000ms ONCE timer"); MultiTimerStart(&timer3, 3456, exampleTimer3Callback, "3456ms delay start, 4567ms CYCLE timer"); MultiTimerStart(&timer4, 1000, exampleTimer4Callback, "500ms CYCLE timer"); while(1){ MultiTimerYield(); } }
審核編輯:劉清
-
SPI
+關注
關注
17文章
1701瀏覽量
91339 -
TFT
+關注
關注
10文章
384瀏覽量
110964 -
ILI9341
+關注
關注
3文章
32瀏覽量
26977
發布評論請先 登錄
相關推薦
評論