{"id":9286,"date":"2025-01-03T22:46:40","date_gmt":"2025-01-03T14:46:40","guid":{"rendered":"http:\/\/www.hellofpga.com\/?p=9286"},"modified":"2025-01-03T22:46:40","modified_gmt":"2025-01-03T14:46:40","slug":"sp_sl_lcd_touch_panel_demo-2","status":"publish","type":"post","link":"http:\/\/www.hellofpga.com\/index.php\/2025\/01\/03\/sp_sl_lcd_touch_panel_demo-2\/","title":{"rendered":"\u57fa\u4e8eLemon ZYNQ\u7684PS\u5b9e\u9a8c \u4e8c\u5341\u4e09 5\u5bf8RGB\u5c4f\u5b9e\u9a8c\uff1a \u7535\u5bb9\u89e6\u6478\u90e8\u5206DEMO"},"content":{"rendered":"\n<p>\u672c\u8282\u4f5c\u4e3a\u524d\u4e24\u8282\u7684\u8865\u5145\uff0c\u4ecb\u7ecd\u5982\u4f55\u9a71\u52a8\u6211\u4eec5\u5bf8\u5c4f\u4e0a\u7684\u7535\u5bb9\u89e6\u6478\u529f\u80fd\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6b64\u7ae0\u8282\u5185\u5bb9\u9002\u7528\u4e8eLemon ZYNQ\u4e3b\u677f\uff0c\u5982\u662f\u5176\u4ed6\u677f\u5b50\u8bf7\u770b\u5bf9\u5e94\u677f\u5b50\u76ee\u5f55<\/strong><\/li>\n\n\n\n<li><strong>\u672c\u6587\u5728 vivado2018.3\u7248\u672c\u4e0a\u6f14\u793a<\/strong><\/li>\n\n\n\n<li><strong>\u5907\u6ce8Lemon ZYNQ \u7684PS\u8f93\u5165\u65f6\u949f\u662f50M\uff0c\u8fd9\u91cc\u548c\u5176\u4ed6\u5e38\u89c1\u7684ZYNQ\u4e3b\u677f\u4e0d\u540c<\/strong><\/li>\n<\/ul>\n\n\n\n<p>\u672c\u6b21\u5b9e\u9a8c\u9700\u8981\u5916\u63a5\u672c\u7ad9\u76845\u5bf8IPS \u5c4f\u5e55\u6a21\u5757\uff0c\u6709\u5173\u672c\u6b21\u5b9e\u9a8c\u7684 RGB\u5c4f\u7684\u539f\u7406\u56fe\u624b\u518c\u4ee5\u53ca\u5176\u4ed6\u4f8b\u7a0b\u8d44\u6599\u53ef\u4ee5\u53c2\u770b\u4e0b\u9762\u6c47\u603b\u8d34\uff1a<a href=\"http:\/\/www.hellofpga.com\/index.php\/2024\/12\/08\/hf_lcd_d50s01\/\">5\u5bf8IPS 800X480 RGB\u63a5\u53e3LCD\u5c4f\u5e55\u6a21\u5757<\/a><\/p>\n\n\n\n<p>\u89e6\u6478\u5c4f\u63a5\u53e3\u90e8\u5206\u5165\u4e0b\u56fe\u6240\u793a\uff0c\u53ef\u4ee5\u770b\u51fa\u89e6\u6478\u90e8\u5206\u7684\u786c\u4ef6\u5305\u542b\u4e00\u8defI2C\uff0c\u4e00\u8defreset\u590d\u4f4d\u4fe1\u53f7\uff0c\u548c\u4e00\u8defINT\u4e2d\u65ad\u4fe1\u53f7<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"698\" src=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-36-1024x698.png\" alt=\"\" class=\"wp-image-8980\" srcset=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-36-1024x698.png 1024w, http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-36-300x204.png 300w, http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-36-768x523.png 768w, http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-36.png 1155w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5b9e\u9a8c\u5185\u5bb9\uff1a<\/strong><\/h2>\n\n\n\n<p>\u672c\u6b21\u5b9e\u9a8c\u5c06\u91c7\u96c6\u89e6\u6478\u5c4f\u7684\u89e6\u6478\u6570\u636e\uff0c\u5e76\u5229\u7528VDMA\u5c06\u89e6\u6478\u70b9\u7684\u5185\u5bb9\u5b9e\u65f6\u7ed8\u5236\u5230LCD\u5c4f\u5e55\u4e0a\u3002\u6bcf\u6b21\u89e6\u6478\u70b9\u7684\u5750\u6807\u901a\u8fc7VDMA\u9ad8\u6548\u5730\u4ece\u5185\u5b58\u4f20\u8f93\u5230\u5c4f\u5e55\uff0c\u5b9e\u73b0\u4e86\u6d41\u7545\u7684\u89e6\u6478\u6570\u636e\u663e\u793a\u548c\u5b9e\u65f6\u66f4\u65b0\u3002<\/p>\n\n\n\n<p>\u672c\u6587\u7684\u5de5\u7a0b\u5c06\u4f1a\u5728\u524d\u4e00\u7ae0\u7684\u5de5\u7a0b\u4e0a\u76f4\u63a5\u4fee\u6539\u6dfb\u52a0\u89e6\u6478\u529f\u80fd\uff0c\u5173\u4e8eVDMA LCD\u90e8\u5206\u53ef\u4ee5\u53c2\u8003\u524d\u4e00\u7ae0\u7684\u5185\u5bb9\uff0c<a href=\"http:\/\/www.hellofpga.com\/index.php\/2025\/01\/03\/hf_lcd_d50s01-2\/\">\u57fa\u4e8eLemon ZYNQ\u7684PS\u5b9e\u9a8c \u4e8c\u5341\u4e00 5\u5bf8RGB\u5c4f\u5b9e\u9a8c\uff1a\u7528VDMA\u6a21\u5757\u6765\u7f13\u5b58\u56fe\u50cf\u5e76\u5728LCD\u4e0a\u663e\u793a\uff08\u4e00\uff09PS\u7aef\u5f69\u6761\u7eb9\u7684\u663e\u793a<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e00\u3001VIVADO\u5de5\u7a0b\u7684\u4fee\u6539<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>VIVADO\u7684\u5de5\u7a0b\u6211\u4eec\u9700\u8981\u589e\u52a0\u4e0b\u9762\u51e0\u4e2a\u5730\u65b9\uff1a\n<ul class=\"wp-block-list\">\n<li>\u589e\u52a0\u4e00\u8defIIC(EMIO\u65b9\u5f0f)\u7528\u4e8e\u8fde\u63a5\u89e6\u6478\u5c4f\u7684 TOUCH_SDA,TOUCH_SCL<\/li>\n\n\n\n<li>\u589e\u52a0\u4e24\u8defGPIO(EMIO\u65b9\u5f0f)\u7528\u4e8e\u8fde\u63a5\u89e6\u6478\u5c4f\u7684 TOUCH_INT \u548cTOUCH_RESET<\/li>\n\n\n\n<li>\u589e\u52a0\u4e00\u8defGPIO(EMIO\u65b9\u5f0f)\u7528\u4e8e\u8fde\u63a5\u6309\u952e\uff0c\u7528\u6765\u6e05\u5c4f\u7528<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1\uff09 \u5bf9Block Design \u90e8\u5206\u8fdb\u884c\u4fee\u6539<\/strong><\/h4>\n\n\n\n<p>a) \u4f7f\u80fdI2C 0 \u5e76\u9009\u62e9EMIO<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"858\" height=\"331\" src=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-38.png\" alt=\"\" class=\"wp-image-8988\" srcset=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-38.png 858w, http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-38-300x116.png 300w, http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-38-768x296.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p>b) \u5728GPIO\u7684\u5730\u65b9\u6dfb\u52a03\u8defEMIO GPIO<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"765\" height=\"415\" src=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-37.png\" alt=\"\" class=\"wp-image-8986\" srcset=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-37.png 765w, http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-37-300x163.png 300w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/figure>\n\n\n\n<p>c) \u4e4b\u540e\u56de\u5230 Block Design \u754c\u9762\uff0c \u5206\u522b\u53f3\u952e GPIO_0 \u548c IIC_0 \u9009\u4e2dMake External \u5f15\u51fa\u8fd9\u4e24\u7ec4\u4fe1\u53f7\u63a5\u53e3<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"927\" height=\"569\" src=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-39.png\" alt=\"\" class=\"wp-image-8989\" srcset=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-39.png 927w, http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-39-300x184.png 300w, http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-39-768x471.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p>d) \u5b8c\u6210\u4e4b\u540e\u70b9\u9009\u4fdd\u5b58<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2 ) \u5bf9\u9876\u5c42\u6587\u4ef6TOP_MODULE\u8fdb\u884c\u4fee\u6539<\/strong>(\u589e\u52a0 I2C \u548c3\u8defEMIO\u589e\u52a0\u7684\u5185\u5bb9)<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/www.hellofpga.com<br>`timescale 1ns \/ 1ps<br>module Top_Module(<br>    output [7:0] LCD_R,<br>    output [7:0] LCD_G,<br>    output [7:0] LCD_B,<br>    output LCD_HS,<br>    output LCD_VS,<br>    output LCD_DE,<br>    output LCD_CLK,<br>    output LCD_BL,<br><strong>    inout  KEY,<br>    inout  TOUCH_RESET,<br>    inout  TOUCH_INT,<br>    inout  TOUCH_SDA,<br>    inout  TOUCH_SCL<\/strong><br>    <br>);<br>    <br>assign LCD_BL=1'b1;<br>    <br>ZYNQ_CORE_wrapper u1(<br>    .lcd_clk(LCD_CLK),<br>    .lcd_data({LCD_R,LCD_G,LCD_B}),<br>    .lcd_de(LCD_DE),<br>    .lcd_hsync(LCD_HS),<br>    .lcd_vsync(LCD_VS),<br><strong>    .GPIO_0_0_tri_io({KEY,TOUCH_RESET,TOUCH_INT}),<br>    .IIC_0_0_scl_io(TOUCH_SCL),<br>    .IIC_0_0_sda_io(TOUCH_SDA)<\/strong><br>    );<br><br><br>endmodule<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3\uff09 \u5bf9\u7ba1\u811a\u7ea6\u675f\u90e8\u5206\u8fdb\u884c\u4fee\u6539\uff0c\u589e\u52a0\u4e0a\u8ff0\u4fe1\u53f7<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">#lemon_zynq<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_R[0]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_R[1]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_R[2]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_R[3]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_R[4]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_R[5]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_R[6]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_R[7]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_G[0]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_G[1]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_G[2]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_G[3]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_G[4]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_G[5]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_G[6]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_G[7]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_B[0]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_B[1]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_B[2]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_B[3]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_B[4]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_B[5]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_B[6]}]<br>set_property IOSTANDARD LVCMOS33 [get_ports {LCD_B[7]}]<br><br>set_property IOSTANDARD LVCMOS33 [get_ports LCD_VS]<br>set_property IOSTANDARD LVCMOS33 [get_ports LCD_HS]<br>set_property IOSTANDARD LVCMOS33 [get_ports LCD_BL]<br>set_property IOSTANDARD LVCMOS33 [get_ports LCD_DE]<br>set_property IOSTANDARD LVCMOS33 [get_ports LCD_CLK]<br><br><br><br>set_property PACKAGE_PIN U17 [get_ports {LCD_R[0]}]<br>set_property PACKAGE_PIN T16 [get_ports {LCD_R[1]}]<br>set_property PACKAGE_PIN W15 [get_ports {LCD_R[2]}]<br>set_property PACKAGE_PIN V15 [get_ports {LCD_R[3]}]<br>set_property PACKAGE_PIN V18 [get_ports {LCD_R[4]}]<br>set_property PACKAGE_PIN V17 [get_ports {LCD_R[5]}]<br>set_property PACKAGE_PIN R17 [get_ports {LCD_R[6]}]<br>set_property PACKAGE_PIN R16 [get_ports {LCD_R[7]}]<br>set_property PACKAGE_PIN P18 [get_ports {LCD_G[0]}]<br>set_property PACKAGE_PIN N17 [get_ports {LCD_G[1]}]<br>set_property PACKAGE_PIN P16 [get_ports {LCD_G[2]}]<br>set_property PACKAGE_PIN P15 [get_ports {LCD_G[3]}]<br>set_property PACKAGE_PIN W13 [get_ports {LCD_G[4]}]<br>set_property PACKAGE_PIN V12 [get_ports {LCD_G[5]}]<br>set_property PACKAGE_PIN W16 [get_ports {LCD_G[6]}]<br>set_property PACKAGE_PIN V16 [get_ports {LCD_G[7]}]<br>set_property PACKAGE_PIN T10 [get_ports {LCD_B[0]}]<br>set_property PACKAGE_PIN T11 [get_ports {LCD_B[1]}]<br>set_property PACKAGE_PIN Y14 [get_ports {LCD_B[2]}]<br>set_property PACKAGE_PIN W14 [get_ports {LCD_B[3]}]<br>set_property PACKAGE_PIN W19 [get_ports {LCD_B[4]}]<br>set_property PACKAGE_PIN W18 [get_ports {LCD_B[5]}]<br>set_property PACKAGE_PIN U19 [get_ports {LCD_B[6]}]<br>set_property PACKAGE_PIN U18 [get_ports {LCD_B[7]}]<br><br>set_property PACKAGE_PIN Y16 [get_ports LCD_HS]<br>set_property PACKAGE_PIN Y19 [get_ports LCD_VS]<br>set_property PACKAGE_PIN T14 [get_ports LCD_BL]<br>set_property PACKAGE_PIN Y18 [get_ports LCD_DE]<br>set_property PACKAGE_PIN Y17 [get_ports LCD_CLK]<br><br>set_property IOSTANDARD LVCMOS33 [get_ports TOUCH_RESET]<br>set_property IOSTANDARD LVCMOS33 [get_ports TOUCH_SDA]<br>set_property IOSTANDARD LVCMOS33 [get_ports TOUCH_SCL]<br>set_property IOSTANDARD LVCMOS33 [get_ports TOUCH_INT]<br><br>set_property PACKAGE_PIN T15 [get_ports TOUCH_RESET]<br>set_property PACKAGE_PIN U13 [get_ports TOUCH_SDA]<br>set_property PACKAGE_PIN V13 [get_ports TOUCH_SCL]<br>set_property PACKAGE_PIN T12 [get_ports TOUCH_INT]<br><br>set_property PACKAGE_PIN D19 [get_ports KEY]<br>set_property IOSTANDARD LVCMOS33 [get_ports KEY]<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>4\uff09 \u4e4b\u540e\u5bf9\u5de5\u7a0b\u8fdb\u884c\u518d\u6b21\u7684\u7f16\u8bd1\u548c\u7efc\u5408\uff0c \u968f\u540e\u91cd\u65b0Export hardware \uff08\u8be6\u7ec6\u64cd\u4f5c\u53ef\u53c2\u8003\u4e4b\u524dLCD\u7684 VDMA\u7ae0\u8282\u5185\u5bb9\uff09<\/strong>\uff08\u6700\u597d\u5bf9SDK\u4e0b\u7684bsp\u90fd\u53f3\u952erefresh\u4e00\u4e0b\uff09<\/h4>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e8c\u3001SDK\u90e8\u5206\u7684\u4fee\u6539<\/strong><\/h2>\n\n\n\n<p><strong>1 \uff09 \u5728\u539f\u5148SRC\u76ee\u5f55\u4e0b\u6dfb\u52a0 gt911.c \u548cgt911.h\u5185\u5bb9\u5206\u522b\u5982\u4e0b\uff1a<\/strong><\/p>\n\n\n\n<p>gt911.c: (\u5305\u542b\u89e6\u6478\u5c4f\u521d\u59cb\u5316\uff0c\u4ee5\u53ca\u89e6\u6478\u5c4f\u5bc4\u5b58\u5668\u7684\u8bfb\u5199\u7b49\u64cd\u4f5c)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><br>\/\/www.hellofpga.com<br>#include \"xgpiops.h\"<br>#include \"xiicps.h\"<br>#include \"sleep.h\"<br><br>#define RESET_PIN 55<br>#define INT_PIN   54<br><br>#define Slave_Address (0xBA&gt;&gt;1)<br><br>static XIicPs i2c;<br>extern XGpioPs  Gpio;<br><br>int gt911_read_reg(uint16_t addr, uint8_t *buf, int len) {<br>    uint8_t send_buf[2];<br>    int status;<br><br>    \/\/ Set the high and low bytes of the register address<br>    send_buf[0] = (uint8_t)(addr &gt;&gt; 8);<br>    send_buf[1] = (uint8_t)(addr &amp; 0xFF);<br><br>    \/\/ Send the read command<br>    status = XIicPs_MasterSendPolled(&amp;i2c, send_buf, 2, Slave_Address);<br>    if (status != XST_SUCCESS) {<br>        return status;<br>    }<br><br>    \/\/ Wait for the I2C bus to be idle<br>    while (XIicPs_BusIsBusy(&amp;i2c));<br><br>    \/\/ Receive data from the I2C bus<br>    status = XIicPs_MasterRecvPolled(&amp;i2c, buf, len, Slave_Address);<br>    if (status != XST_SUCCESS) {<br>        return status;<br>    }<br><br>    \/\/ Wait for the I2C bus to be idle again<br>    while (XIicPs_BusIsBusy(&amp;i2c));<br><br>    return XST_SUCCESS;<br>}<br><br>int gt911_write_reg(uint16_t addr, uint8_t *buf, int len) {<br>    uint8_t send_buf[256] = {0};<br>    int status;<br><br>    \/\/ Set the high and low bytes of the register address<br>    send_buf[0] = (uint8_t)(addr &gt;&gt; 8);<br>    send_buf[1] = (uint8_t)(addr &amp; 0xFF);<br><br>    \/\/ Copy the data from the buffer into send_buf starting at index 2<br>    memcpy(&amp;send_buf[2], buf, len);<br><br>    \/\/ Send the write command<br>    status = XIicPs_MasterSendPolled(&amp;i2c, send_buf, len + 2, Slave_Address);<br>    if (status != XST_SUCCESS) {<br>        return status;<br>    }<br><br>    \/\/ Wait for the I2C bus to be idle<br>    while (XIicPs_BusIsBusy(&amp;i2c));<br><br>    return XST_SUCCESS;<br>}<br><br>int gt911_init(void)<br>{<br>    XIicPs_Config *i2cConfig;<br>    uint8_t buffer[5] = {0};<br><br>    i2cConfig = XIicPs_LookupConfig(XPAR_XIICPS_0_DEVICE_ID);<br>    XIicPs_CfgInitialize(&amp;i2c, i2cConfig, i2cConfig-&gt;BaseAddress);<br>    XIicPs_SetSClk(&amp;i2c, 200000);<br><br>    XGpioPs_SetDirectionPin(&amp;Gpio, RESET_PIN, 1);<br>    XGpioPs_SetDirectionPin(&amp;Gpio, INT_PIN, 1);<br>    XGpioPs_SetOutputEnablePin(&amp;Gpio, RESET_PIN, 1);<br>    XGpioPs_SetOutputEnablePin(&amp;Gpio, INT_PIN, 1);<br><br>    \/\/SET 0XBA\/0XBB<br>    XGpioPs_WritePin(&amp;Gpio, RESET_PIN, 0);<br>    XGpioPs_WritePin(&amp;Gpio, INT_PIN, 0);<br>    usleep(200);    \/\/200us<br>    XGpioPs_WritePin(&amp;Gpio, RESET_PIN, 1);<br>    usleep(55000);  \/\/55ms<br>    XGpioPs_SetDirectionPin(&amp;Gpio, INT_PIN, 0);\/\/input_floating<br><br>    \/\/READ ID<br>    gt911_read_reg(0x8140, buffer, 4);<br>    buffer[3]='\\0';<br>\t\/\/xil_printf(\"CTP ID:%s\\r\\n\", buffer);<br><br>\tif(strcmp((char*)buffer,\"911\")==0){<br>\t\treturn 0;<br>\t}<br>\t\treturn 1;<br>}<br><br><br>int gt911_read(int16_t *x, int16_t *y)<br>{<br>    uint8_t buf[7] = {0};<br><br>    \/\/ Read coordinate data<br>    gt911_read_reg(0x814E, buf, 6);<br><br>    \/\/ Clear the touch state<br>    buf[6] = 0x0;<br>    gt911_write_reg(0x814E, &amp;buf[6], 1);<br><br>    \/\/ Check if a touch event is detected<br>    \/\/ The high bit of buf[0] (0x80) indicates touch validity,<br>    \/\/ and the lower four bits (0x0F) indicate the number of touch points<br>    if ((buf[0] &amp; 0x80) &amp;&amp; (buf[0] &amp; 0x0F)) {<br>        \/\/ Extract coordinates (16-bit)<br>        *x = (buf[3] &lt;&lt; 8) | buf[2];  \/\/ X coordinate<br>        *y = (buf[5] &lt;&lt; 8) | buf[4];  \/\/ Y coordinate<br>        return 1;  \/\/ Successfully read coordinates<br>    }<br>    return 0;  \/\/ No touch detected<br>}<\/pre>\n\n\n\n<p>gt911.h<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/www.hellofpga.com<br>#ifndef __GT911_H<br>#define __GT911_H<br><br>int gt911_read(int16_t *x, int16_t *y);<br>int gt911_init();<br><br>#endif<\/pre>\n\n\n\n<p><strong>2 \uff09\u4fee\u6539main.c\u7684\u5185\u5bb9<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/www.hellofpga.com<br>#include &lt;stdio.h><br>#include &lt;stdlib.h><br>#include &lt;string.h><br>#include \"xil_types.h\"<br>#include \"xil_cache.h\"<br>#include \"xparameters.h\"<br>#include \"xaxivdma.h\"<br>#include \"xaxivdma_i.h\"<br>#include \"sleep.h\"<br>#include \"xgpiops.h\"<br>#include \"gt911.h\"<br><br>#define WIDTH  800<br>#define HEIGHT 480<br><br>#define VDMA_BASEADDR\tXPAR_AXI_VDMA_0_BASEADDR<br>#define VIDEO_BASEADDR0 0x01000000<br>uint8_t *frame_buffer0 = (uint8_t *)VIDEO_BASEADDR0;<br><br>#define GPIO_DEVICE_ID  \tXPAR_XGPIOPS_0_DEVICE_ID<br>XGpioPs Gpio;<br><br>#define KEY 56<br><br><br>void Gpio_Init(){<br>\tXGpioPs_Config *ConfigPtr;<br>\tConfigPtr = XGpioPs_LookupConfig(GPIO_DEVICE_ID);<br>\tXGpioPs_CfgInitialize(&amp;Gpio, ConfigPtr,ConfigPtr->BaseAddr);<br>\tXGpioPs_SetDirectionPin(&amp;Gpio, KEY, 0);<br>}<br><br><br>void VDMA_init(){<br>  Xil_Out32((VDMA_BASEADDR + 0x000), 0x00000001);<br>  Xil_Out32((VDMA_BASEADDR + 0x05c), VIDEO_BASEADDR0);<br>  Xil_Out32((VDMA_BASEADDR + 0x058), (WIDTH*3));<br>  Xil_Out32((VDMA_BASEADDR + 0x054), (WIDTH*3));<br>  Xil_Out32((VDMA_BASEADDR + 0x050),  HEIGHT);<br>  Xil_Out32((VDMA_BASEADDR + 0x028),  0X00000000);<br>}<br><br><br>void clear_screen(void) {<br>  unsigned int i, j;<br>  for (i = 0; i &lt; WIDTH; i++) {<br>    for (j = 0; j &lt; HEIGHT; j++) {<br>      frame_buffer0[(j * WIDTH + i) * 3 + 2] = 0x00;<br>      frame_buffer0[(j * WIDTH + i) * 3 + 1] = 0x00;<br>      frame_buffer0[(j * WIDTH + i) * 3 + 0] = 0x00;<br>    }<br>  }<br>  Xil_DCacheFlush();<br>}<br><br>void write_pixel_to_frame_buffer(int16_t pos_x, int16_t pos_y) {<br>  if (pos_x >= 0 &amp;&amp; pos_x &lt; WIDTH &amp;&amp; pos_y >= 0 &amp;&amp; pos_y &lt; HEIGHT) {<br>    frame_buffer0[(pos_y * WIDTH + pos_x) * 3 + 2] = 0xFF;<br>    frame_buffer0[(pos_y * WIDTH + pos_x) * 3 + 1] = 0xFF;<br>    frame_buffer0[(pos_y * WIDTH + pos_x) * 3 + 0] = 0xFF;<br>    Xil_DCacheFlush();<br>  }<br>}<br><br><br>int main(void) {<br>  int16_t pos_x, pos_y;<br><br>  Gpio_Init();<br>  VDMA_init();<br>  gt911_init();<br>  clear_screen();<br><br>  while (1) {<br>    if (XGpioPs_ReadPin(&amp;Gpio, KEY) == 1)<br>      clear_screen();<br>    else if (gt911_read(&amp;pos_x, &amp;pos_y)) {<br>      write_pixel_to_frame_buffer(pos_x, pos_y);<br>    }<br>    usleep(1000); \/\/ 1ms<br>  }<br>}<\/pre>\n\n\n\n<p><strong>3 \uff09 \u7a0b\u5e8f\u89e3\u8bfb<\/strong>\uff1a<\/p>\n\n\n\n<p>a ) \u9996\u5148\u662fVDMA_init\uff08\uff09\uff0c\u8fd9\u4e2a\u5728\u524d\u4e24\u7ae0\u5185\u5bb9\u4e2d\u6709\u63d0\u5230\uff0c\u8fd9\u91cc\u4e3b\u8981\u662f\u8bbe\u7f6e\u4e86\u7f13\u5b58\u533a\u7684\u5730\u5740\u4e3a VIDEO_BASEADDR0\uff0c\uff08\u5907\u6ce8\u867d\u7136\u6211\u4eec\u7684vdma\u8bbe\u7f6e\u4e86\u4e09\u5e27\u7f13\u5b58\uff0c\u4f46\u662f\u672c\u6b21\u5de5\u7a0b\u6211\u4eec\u5b9e\u9645\u53ea\u7528\u4e86\u4e00\u5e27\u8fdb\u884c\u6f14\u793a\uff09\uff0c\u8fd9\u91cc\u6211\u4eec\u901a\u8fc7\u914d\u7f6e028h\u76844-0bit\u6765\u8ba9vdma\u505c\u7559\u5728\u6211\u4eec\u6307\u5b9a\u7684\u7f13\u5b58\u5e270\u4e0a(\u524d\u6587\u4e2d\u5df2\u5c06vdma \u914d\u7f6e\u5728\u975e\u5faa\u73af\u72b6\u6001\u4e0b\uff0cPark Mode)<\/p>\n\n\n\n<p>b )&nbsp;<strong><code>write_pixel_to_frame_buffer<\/code><\/strong>\uff1a\u6839\u636e\u4f20\u5165\u7684\u5750\u6807\uff08<code>pos_x<\/code>,&nbsp;<code>pos_y<\/code>\uff09\u5c06\u8be5\u4f4d\u7f6e\u7684\u50cf\u7d20\u989c\u8272\u8bbe\u7f6e\u4e3a\u767d\u8272\u3002<\/p>\n\n\n\n<p><code>c)<\/code><strong><code>&nbsp;clear_screen<\/code><\/strong>\uff1a\u6e05\u7a7a\u5c4f\u5e55\uff08\u5c06\u6bcf\u4e2a\u50cf\u7d20\u7684\u989c\u8272\u8bbe\u7f6e\u4e3a\u9ed1\u8272\uff09\u3002\u6bcf\u4e2a\u50cf\u7d20\u4f7f\u7528 3 \u5b57\u8282\u8868\u793a RGB \u989c\u8272\uff0c\u6bcf\u6b21\u5faa\u73af\u5c06\u6bcf\u4e2a\u50cf\u7d20\u7684 RGB \u503c\u90fd\u8bbe\u7f6e\u4e3a&nbsp;<code>0x00<\/code>\u3002<\/p>\n\n\n\n<p>d) main\u51fd\u6570\uff1a \u5148\u521d\u59cb\u5316GPIO\u3001VDMA\u3001GT911\u89e6\u6478\u5c4f\u63a7\u5236\u5668\uff0c\u5e76\u901a\u8fc7&nbsp;<code>clear_screen()<\/code>&nbsp;\u6e05\u7a7a\u5c4f\u5e55\u3002<\/p>\n\n\n\n<p>e ) \u5728\u4e3b\u5faa\u73af\u4e2d\uff0c\u68c0\u67e5\u6309\u952eBTN0\u72b6\u6001\uff0c\u5982\u679c\u6309\u952e\u6309\u4e0b\u5219\u6e05\u7a7a\u5c4f\u5e55\uff1b\u5982\u679c\u89e6\u6478\u5c4f\u6709\u89e6\u6478\u4e8b\u4ef6\uff0c\u5219\u83b7\u53d6\u89e6\u6478\u5750\u6807\u5e76\u66f4\u65b0\u663e\u793a\u5c4f\u4e0a\u7684\u50cf\u7d20\u3002\u8fd9\u91cc\u7684\u5ef6\u65f6\u5fc5\u987b\u52a0\uff0c\u5426\u5219\u4f1a\u56e0\u4e3a\u4e0d\u505c\u7684\u626b\u63cf\u53cd\u800c\u9020\u6210\u626b\u63cf\u5361\u4f4f\u7684\u60c5\u51b5<strong>(\u6ce8\u610fLemon ZYNQ  \u6309\u4e0b\u6309\u952e\u540e\u4e3a\u9ad8\u7535\u5e73)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">  while (1) {<br>    if (XGpioPs_ReadPin(&amp;Gpio, KEY) == 1)<br>      clear_screen();<br>    else if (gt911_read(&amp;pos_x, &amp;pos_y)) {<br>      write_pixel_to_frame_buffer(pos_x, pos_y);<br>    }<br>    usleep(1000); \/\/ 1ms<br>  }<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e09\u3001\u5b9e\u673a\u8c03\u8bd5:<\/strong><\/h2>\n\n\n\n<p>\u56de\u5230SDK\u754c\u9762\uff0c\u5bf9\u7a0b\u5e8f\u8fdb\u884c\u6b63\u5e38\u7f16\u8bd1\uff0c\u5e76debug\uff0c\u8fd9\u65f6\u5019\u5c4f\u5e55\u4f1a\u663e\u793a\u9ed1\u8272\u80cc\u666f\uff0c\u6b64\u65f6\u6211\u4eec\u7528\u624b\u6307\u5212\u8fc7\u5c4f\u5e55\uff0c\u53ef\u4ee5\u5728\u5c4f\u5e55\u4e0a\u770b\u5230\u6211\u4eec\u5212\u8fc7\u7684\u8f68\u8ff9\u90fd\u4f1a\u88ab\u767d\u8272\u7684\u70b9\u8986\u76d6\uff0c \u8bc1\u660e\u6211\u4eec\u7684\u7a0b\u5e8f\u8fd0\u884c\u6210\u529f\u3002\uff08\u5f53\u6211\u4eec\u6309\u4e0b\u4e3b\u677f\u4e0a\u7684KEY2\u952e\uff0c \u56fe\u50cf\u4f1a\u88ab\u91cd\u65b0\u6e05\u7a7a\uff09<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"621\" src=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-40.png\" alt=\"\" class=\"wp-image-8995\" srcset=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-40.png 1024w, http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-40-300x182.png 300w, http:\/\/www.hellofpga.com\/wp-content\/uploads\/2024\/12\/image-40-768x466.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5199\u5728\u540e\u9762\uff1a<\/strong><\/h2>\n\n\n\n<p>GT911\u5176\u5b9e\u53ef\u4ee5\u652f\u63015\u70b9\u540c\u65f6\u89e6\u63a7\u7684\uff0c\u8fd9\u91cc\u7684\u7a0b\u5e8f\u53ea\u6f14\u793a\u4e86\u4e00\u4e2a\u70b9\u7684\u8bfb\u53d6\uff0c\u5927\u5bb6\u5982\u679c\u5bf95\u4e2a\u70b9\u7684\u89e6\u6478\u65b9\u5f0f\u611f\u5174\u8da3\u53ef\u4ee5\u81ea\u884c\u5c1d\u8bd5\u4fee\u6539\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u672c\u6587\u7684\u5b8c\u6574\u5de5\u7a0b\u4e0b\u8f7d\uff1a<a href=\"http:\/\/www.hellofpga.com\/wp-content\/uploads\/2025\/01\/23_VDMA_5INCH_LCD_TOUCH_PANEL_DEMO.zip\">23_VDMA_5INCH_LCD_TOUCH_PANEL_DEMO<\/a><\/strong><\/li>\n\n\n\n<li><strong>VIVADO\u7684\u7248\u672c\uff1a2018.3<\/strong><\/li>\n\n\n\n<li><strong>\u5de5\u7a0b\u521b\u5efa\u76ee\u5f55\uff1aE:\\Lemon_ZYNQ\\SDK\\23_VDMA_5INCH_LCD_TOUCH_PANEL_DEMO<\/strong><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u8282\u4f5c\u4e3a\u524d\u4e24\u8282\u7684\u8865\u5145\uff0c\u4ecb\u7ecd\u5982\u4f55\u9a71\u52a8\u6211\u4eec5\u5bf8\u5c4f\u4e0a\u7684\u7535\u5bb9\u89e6\u6478\u529f\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[],"class_list":["post-9286","post","type-post","status-publish","format-standard","hentry","category-lemon-zynq"],"views":947,"_links":{"self":[{"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/posts\/9286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/comments?post=9286"}],"version-history":[{"count":9,"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/posts\/9286\/revisions"}],"predecessor-version":[{"id":9324,"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/posts\/9286\/revisions\/9324"}],"wp:attachment":[{"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/media?parent=9286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/categories?post=9286"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.hellofpga.com\/index.php\/wp-json\/wp\/v2\/tags?post=9286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}