Navigation

    全志在线开发者论坛

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • 在线文档
    • 社区主页

    MQ-T113使用xboot驱动GT911时中断无法使用

    爱搞机专区
    3
    11
    4649
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      Ary_Ye LV 5 last edited by

      大佬们好,我使用xboot主线里的gt911驱动,发现无法使用触摸屏(在tina里面是可以用的),后来用逻辑分析仪发现rst和int的启动时序和tina里面的不一样,我猜测是启动时序出了问题,因为我也没自己写过gt911的驱动,麻烦各位大佬帮我看看启动时序有啥问题。

      	gpio_set_cfg(rst, rstcfg);
      	gpio_set_pull(rst, GPIO_PULL_UP);
      	gpio_set_direction(rst, GPIO_DIRECTION_OUTPUT);
      
      	gpio_set_value(rst, 0);
      	mdelay(10);
      	gpio_set_pull(gpio, GPIO_PULL_UP);
      	gpio_set_direction(gpio, GPIO_DIRECTION_OUTPUT);
      	gpio_set_value(gpio, 1);
      	udelay(100);
      	gpio_set_value(rst, 1);
      	mdelay(5);
      

      逻辑分析仪结果如下,触摸时没有变化
      QQ20230602-162203.png
      我改成了

      		gpio_set_cfg(rst, rstcfg);
      			
      		gpio_set_direction(rst,GPIO_DIRECTION_OUTPUT);
      		gpio_set_direction(gpio,GPIO_DIRECTION_OUTPUT);
      
      		gpio_set_value(rst,0);
      		gpio_set_value(gpio,1);
      		udelay(200);
      
      		gpio_set_value(rst,1);
      		mdelay(6);
      
      		gpio_set_value(gpio,0);
      		mdelay(55);
      
      		gpio_set_direction(gpio, GPIO_DIRECTION_INPUT);
      		gpio_set_pull(gpio, GPIO_PULL_NONE);
      		mdelay(50);
      

      时序如下,感觉出现了异常,我尝试根据网上的程序修改,但是并没有驱动成功,求求大佬们看看是哪里出了问题。
      QQ20230602-150257.png

      steward 1 Reply Last reply Reply Quote Share 0
      • steward
        司徒 LV 6 @Ary_Ye last edited by

        @ary_ye 這邊是愛搞機器的專區, 可以請問你這個是什麼遊戲機嗎?

        A 1 Reply Last reply Reply Quote Share 0
        • A
          Ary_Ye LV 5 @steward last edited by

          @steward 不好意思,我这边是驱动出问题了,想问一下但是又不懂在哪个分区:(

          1 Reply Last reply Reply Quote Share 0
          • steward
            司徒 LV 6 last edited by

            目前 XBOOT 有支援 GT-911 的平台如下:

            ./src/arch/riscv64/mach-f133/driver/ts-gt911.c
            ./src/arch/arm32/mach-t113s3jd/driver/ts-gt911.c
            ./src/arch/arm32/mach-t113s3/driver/ts-gt911.c
            ./src/arch/arm32/mach-z11s/driver/ts-gt911.c
            

            手上剛好有 F133 板子, 但是我沒有 GT-911 觸控板, 如果需要或許可以用 Arduino 模擬~
            1.jpg

            不過, 找問題的方式應該大同小異, 因此, 我用 F133 說一下,
            json 檔案確定有設定成 okay

            "ts-f133@0x02009c00": {
                    "clock-name": "link-tpadc",
                    "interrupt": 78, 
                    "reset": 1136,
                    "median-filter-length": 5,
                    "mean-filter-length": 5,
                    "calibration": [168012, -57, -137136144, -344, 8674, -2840431, 65536],
                    "status": "okay"
                },  
            
                "ts-gt911": {
                    "i2c-bus": "i2c-f133.2",
                    "slave-address": 20, 
                    "interrupt-gpio": 35, 
                    "interrupt-gpio-config": 14, 
                    "reset-gpio": 34, 
                    "reset-gpio-config": 1,
                    "status": "okay"
                }, 
            

            然後埋一些 LOG, 先確定觸控板有被正確配置

            static bool_t gt911_initial(struct i2c_device_t * dev)
            {
                u8_t cfg;
                u8_t id[4];
                u8_t ver[2];
            
                if(!gt911_read(dev, GT911_CONFIG_DATA, &cfg, 1)) {
                    LOG("GT911: failed to read config data\n");
                    return FALSE;
                }   
                if(!gt911_read(dev, GT911_PRODUCT_ID, &id[0], 4)) {
                    LOG("GT911: failed to read product id\n");
                    return FALSE;
                }   
                if(!gt911_read(dev, GT911_FIRMWARE_VERSION, &ver[0], 2)) {
                    LOG("GT911: failed to read firmware version\n");
                    return FALSE;
                }   
            
                LOG("GT911 Version: %c%c%c%c(0x%02x%02x)(0x%02x)", id[0], id[1], id[2], id[3], ver[1], ver[0], cfg);
                return gt911_send_cfg(dev, (u8_t *)gt911_config_data, ARRAY_SIZE(gt911_config_data));
            }
            

            埋好 LOG 之後, 下載測試

            $ make CROSS_COMPILE=/opt/f133/bin/riscv64-unknown-linux-gnu- PLATFORM=riscv64-f133
            $ xfel ddr f133 && xfel write 0x40000000 output/xboot.bin && xfel exec 0x40000000
            

            因為沒有連接 GT-911, 因此, 在讀取 config data 時就會出錯

            [    0.261738]GT911: failed to read config data
            

            因此, 幾個找問題的方式提供給你參考 (跟著訊號的方向找問題就可以)

            1. 確定觸控的資訊可以被正確讀取到, 你應該可以從 UART 看到 "GT911 Version: xxx"
            2. 如果可以讀取到觸控資訊, 那可以往中斷腳位的方向找問題, 例如:沒接好或者被拉高拉低等問題
            A 1 Reply Last reply Reply Quote Share 1
            • A
              Ary_Ye LV 5 @steward last edited by

              @steward 感谢大佬的回答:),触控的信息是可以读取的,现在正打算用单片机发送这些数据看看能不能正常工作@_@

              steward 1 Reply Last reply Reply Quote Share 1
              • steward
                司徒 LV 6 @Ary_Ye last edited by

                @ary_ye 不過, 從你的圖片看來, 這個 I2C 訊號也不太像是 SCL, SDA 的訊號 ? 這樣你還可以從 xboot 拿到觸控的資料 ?

                A 1 Reply Last reply Reply Quote Share 0
                • A
                  Ary_Ye LV 5 @steward last edited by

                  @steward 是RST和INT引脚的时序,我直接用XBOOT主线上的程序调不通,网络上有说这两个引脚的时序问题会影响GT911的启动,现在我主要是排查I2C通信的问题,发现读触摸数据寄存器也读不通😵还是在排查过程中,不过还是你的谢谢回答 👼

                  1 Reply Last reply Reply Quote Share 0
                  • steward
                    司徒 LV 6 last edited by

                    @Ary_Ye XBoot在T113-S3上的中斷設定確實有問題, 分析如下:

                    文章有點長,可以直接拉到底下看workaround方式 💃💃💃

                    司徒終於從冰箱找到芒果派T113-S3開發板
                    1.jpg

                    司徒手上並沒有GT911觸控板,因此,司徒使用Arduino Micro模擬GT911訊號
                    2.jpg

                    Arduino腳位:
                    3.jpg

                    T113-S3腳位:
                    4.jpg

                    司徒將GT911 I2C訊號接到T113-S3 I2C-2,GT911的中斷則是接到T113-S3 PB6(手動觸發)
                    5.jpg

                    杜邦線連接
                    6.jpg

                    Arduino模擬GT911程式

                    #include <Wire.h>
                     
                    unsigned short rx = 0;
                    void receiveEvent(int howMany) {
                      if(howMany == 2){
                        rx = Wire.read();
                        rx<<= 8;
                        rx|= Wire.read();
                      }
                      else{
                        while (Wire.available()) {
                          Wire.read();
                        }
                      }
                      Serial.print("howMany:");
                      Serial.print(howMany);
                      Serial.print("\n");
                      Serial.print("0x");
                      Serial.print(rx, HEX);
                      Serial.print("\n");
                    }
                     
                    unsigned short x = 0;
                    unsigned short y = 0;
                    void requestEvent() {
                      switch(rx){
                      case 0x8047:
                        Wire.write(byte(0x01));
                        break;
                      case 0x8140:
                        Wire.write('A');
                        Wire.write('B');
                        Wire.write('C');
                        Wire.write('D');
                        break;
                      case 0x8144:
                        Wire.write(byte(0x12));
                        Wire.write(byte(0x34));
                        break;
                      case 0x814e:
                        Wire.write(byte(0x80 | 1));
                        break;
                      case 0x814f:
                        Wire.write(byte(0x01));
                        Wire.write(byte(x));
                        Wire.write(byte(x >> 8));
                        Wire.write(byte(y));
                        Wire.write(byte(y >> 8));
                        Wire.write(byte(0x00));
                        Wire.write(byte(0x00));
                        Wire.write(byte(0x00));
                        x+= 1;
                        y+= 1;
                        break;
                      }
                      rx = 0;
                    }
                     
                    void setup() {
                      Wire.begin(20);
                      Wire.onReceive(receiveEvent);
                      Wire.onRequest(requestEvent);
                      Serial.begin(115200);
                     
                    }
                     
                    void loop() {
                      delay(100);
                    }
                    

                    src/arch/arm32/mach-t113s3/romdisk/boot/mangopi.json

                    524     "i2c-t113:2@0x02502800": {
                    525         "clock-name": "bus-i2c2",
                    526         "clock-frequency": 400000,
                    527         "reset": 466,
                    528         "sda-gpio": 133,
                    529         "sda-gpio-config": 4,
                    530         "scl-gpio": 132,
                    531         "scl-gpio-config": 4
                    532     },
                    
                    662     "ts-gt911": {
                    663         "i2c-bus": "i2c-t113.2",
                    664         "slave-address": 20,
                    665         "interrupt-gpio": 38,
                    666         "interrupt-gpio-config": 14,
                    667         "reset-gpio": 34,
                    668         "reset-gpio-config": 1
                    669     },
                    

                    src/arch/arm32/mach-t113s3/driver/ts-gt911.c

                     75 static bool_t gt911_write(struct i2c_device_t * dev, u16_t reg, u8_t * buf, int len)
                     76 {
                     77     struct i2c_msg_t msg;
                     78     u8_t mbuf[256];
                     79
                     80     if(len > sizeof(mbuf) - 1)
                     81         len = sizeof(mbuf) - 1;
                     82     mbuf[0] = (reg >> 8) & 0xff;
                     83     mbuf[1] = (reg >> 0) & 0xff;
                     84     memcpy(&mbuf[2], buf, len);
                     85
                     86     msg.addr = dev->addr;
                     87     msg.flags = 0;
                     88     msg.len = 32;//len + 2;
                     89     msg.buf = &mbuf[0];
                     90
                     91     if(i2c_transfer(dev->i2c, &msg, 1) != 1)
                     92         return FALSE;
                     93     return TRUE;
                     94 }
                    
                    134 static bool_t gt911_initial(struct i2c_device_t * dev)
                    135 {
                    136     u8_t cfg;
                    137     u8_t id[4];
                    138     u8_t ver[2];
                    139
                    140     if(!gt911_read(dev, GT911_CONFIG_DATA, &cfg, 1))
                    141         return FALSE;
                    142     if(!gt911_read(dev, GT911_PRODUCT_ID, &id[0], 4))
                    143         return FALSE;
                    144     if(!gt911_read(dev, GT911_FIRMWARE_VERSION, &ver[0], 2))
                    145         return FALSE;
                    146
                    147     LOG("GT911 Version: %c%c%c%c(0x%02x%02x)(0x%02x)\r\n", id[0], id[1], id[2], id[3], ver[1], ver[0], cfg);
                    148     return gt911_send_cfg(dev, (u8_t *)gt911_config_data, ARRAY_SIZE(gt911_config_data));
                    149 }
                    
                    151 static void gt911_interrupt(void * data)
                    152 {
                    153     struct input_t * input = (struct input_t *)data;
                    154     struct ts_gt911_pdata_t * pdat = (struct ts_gt911_pdata_t *)input->priv;
                    155     u8_t status, buf[40];
                    156     u8_t * p;
                    157     int count, i;
                    158     int id, x, y;
                    159
                    160     LOG("%s++\r\n", __func__);
                    161     disable_irq(pdat->irq);
                    162     for(i = 0; i < 5; i++)
                    163     {
                    164         pdat->node[i].valid = 0;
                    165     }
                    166     if(gt911_read(pdat->dev, GT911_STATUS, &status, 1) && (status & (1 << 7)))
                    167     {
                    168         count = status & 0x0f;
                    169         if(count > 0 && count < 5)
                    170         {
                    171             if(gt911_read(pdat->dev, GT911_COOR_ADDR, &buf[0], count << 3))
                    172             {
                    173                 for(i = 0; i < count; i++)
                    174                 {
                    175                     p = &buf[i << 3];
                    176                     id = p[0];
                    177                     x = (p[2] << 8) | (p[1] << 0);
                    178                     y = (p[4] << 8) | (p[3] << 0);
                    179                     LOG("%s, count:%d, x:%d, y:%d\r\n", __func__, count, x, y);
                    ...
                    209     enable_irq(pdat->irq);
                    210     LOG("%s--\r\n", __func__);
                    211 }
                    

                    編譯、下載

                    $ make CROSS_COMPILE=arm-linux-gnueabihf- PLATFORM=arm32-t113s3
                    $ xfel ddr t113-s3
                    $ xfel write 0x40000000 output/xboot.bin
                    $ xfel exec 0x40000000
                    

                    Arduino GT911可以正常工作,但是,中斷PB6無法被觸發

                    [    0.260214]GT911 Version: ABCD(0x3412)(0x01)
                    [    0.287074]Probe device 'ts-gt911.0' with ts-gt911
                    

                    為了方便測試,司徒將PB6加上提昇電阻並且改成Falling中斷觸發

                    282     LOG("%s, gpio:%d, gpiocfg:%d, irqnum:%d\r\n", __func__, gpio, gpiocfg, irq);
                    283     if(gpio >= 0)
                    284     {
                    285         if(gpiocfg >= 0)
                    286             gpio_set_cfg(gpio, gpiocfg);
                    287         gpio_set_pull(gpio, GPIO_PULL_UP);
                    288     }
                    289     request_irq(pdat->irq, gt911_interrupt, IRQ_TYPE_EDGE_FALLING, input);
                    

                    PB6=GPIO38、GPIOCFG=14、IRQ=262,這個IRQ應該是抓錯了?

                    [    0.266982]ts_gt911_probe, gpio:38, gpiocfg:14, irqnum:262
                    

                    7.jpg

                    src/arch/arm32/mach-t113s3/romdisk/boot/mangopi.json

                    388     "irq-gic400@0x03020000": { "interrupt-base": 32, "interrupt-count": 224 },
                    389     "irq-t113-gpio@0x02000220": { "interrupt-base": 224, "interrupt-count":  8, "interrupt-parent":  101 },
                    390     "irq-t113-gpio@0x02000240": { "interrupt-base": 256, "interrupt-count":  8, "interrupt-parent":  103 },
                    391     "irq-t113-gpio@0x02000260": { "interrupt-base": 288, "interrupt-count": 23, "interrupt-parent":  105 },
                    392     "irq-t113-gpio@0x02000280": { "interrupt-base": 320, "interrupt-count": 14, "interrupt-parent":  107 },
                    393     "irq-t113-gpio@0x020002a0": { "interrupt-base": 352, "interrupt-count":  7, "interrupt-parent":  109 },
                    394     "irq-t113-gpio@0x020002c0": { "interrupt-base": 384, "interrupt-count": 16, "interrupt-parent":  111 },
                    

                    src/driver/interrupt/interrupt.c

                    191 bool_t request_irq(int irq, void (*func)(void *), enum irq_type_t type, void * data)
                    192 {
                    193     struct irqchip_t * chip;
                    194     int offset;
                    195
                    196     if(!func)
                    197         return FALSE;
                    198
                    199     chip = search_irqchip(irq);
                    200     if(!chip)
                    201         return FALSE;
                    202
                    203     offset = irq - chip->base;
                    204     if(chip->handler[offset].func != null_interrupt_function) {
                    205         return FALSE;
                    206     }
                    207
                    208     LOG("%s, irq:%d, chip->base:%d, offset:%d\r\n", __func__, irq, chip->base, offset);
                    

                    XBoot修改到的中斷地址是屬於PC6,但是司徒的中斷是設定成PB6

                    [    0.272634]request_irq, irq:262, chip->base:256, offset:6
                    

                    src/arch/arm32/mach-t113s3/driver/irq-t113-gpio.c

                     92     addr = pdat->virt + GPIO_INT_CFG0 + ((offset >> 3) << 2);
                     93     val = read32(addr);
                     94     val &= ~(0xf << ((offset & 0x7) << 2));
                     95     val |= ((cfg & 0x7) << ((offset & 0x7) << 2));
                     96     write32(addr, val);
                     97
                     98     LOG("%s, addr:%p, type:%d, offset:%d\r\n", __func__, addr, type, offset);
                    

                    果然修改到PC6 0x02000240

                    [    0.268151]ts_gt911_probe, gpio:38, gpiocfg:14, irqnum:262
                    [    0.273812]request_irq, irq:262, chip->base:256, offset:6
                    [    0.279202]irq_t113_gpio_settype, addr:0x02000240, type:3, offset:6
                    [    0.285373]Probe device 'ts-gt911.0' with ts-gt911
                    

                    PB6是位於0x02000230
                    8.jpg

                    Workaround (src/driver/interrupt/interrupt.c)

                     62 static struct irqchip_t * search_irqchip(int irq)
                     63 {
                     64     struct device_t * pos, * n;
                     65     struct irqchip_t * chip;
                     66
                     67     list_for_each_entry_safe(pos, n, &__device_head[DEVICE_TYPE_IRQCHIP], head)
                     68     {
                     69         chip = (struct irqchip_t *)(pos->priv);
                     70         if(irq == 230){
                     71             if(chip->base == 224){
                     72                 return chip;
                     73             }
                     74             continue;
                     75         }
                     76         if((irq >= chip->base) && (irq < (chip->base + chip->nirq)))
                     77             return chip;
                     78     }
                     79     return NULL;
                     80 }
                    
                    191 bool_t request_irq(int irq, void (*func)(void *), enum irq_type_t type, void * data)
                    192 {
                    193     struct irqchip_t * chip;
                    194     int offset;
                    195
                    196     if(!func)
                    197         return FALSE;
                    198
                    199     if(irq == 262){
                    200         irq-= 32;
                    201     }
                    

                    修改後,就可以正常中斷觸發並且回報觸控點

                    [    0.260653]GT911 Version: ABCD(0x3412)(0x01)
                    [    0.266935]ts_gt911_probe, gpio:38, gpiocfg:14, irqnum:262
                    [    0.272326]request_irq, irq:230, chip->base:224, offset:6
                    [    0.277959]irq_t113_gpio_settype, addr:0x02000220, type:3, offset:6
                    [    0.299301]Probe device 'ts-gt911.0' with ts-gt911
                    [    0.304091]Probe device 'g2d-t113.0' with g2d-t113
                    [    0.310178]Probe device 'fb-t113-rgb.0' with fb-t113-rgb
                    [    0.315658]Probe device 'console-uart.0' with console-uart
                    [    0.322001]mount /private with 'ram' filesystem
                    Press any key to stop auto boot:  0.000
                    xboot: /# 
                    [    5.434256]gt911_interrupt++
                    [    5.440101]gt911_interrupt, count:1, x:1, y:1
                    [    5.446270]gt911_interrupt--
                    [    9.054572]gt911_interrupt++
                    [    9.060405]gt911_interrupt, count:1, x:2, y:2
                    [    9.066782]gt911_interrupt--
                    
                    A 1 Reply Last reply Reply Quote Share 1
                    • A
                      Ary_Ye LV 5 @steward last edited by

                      @steward 啊啊啊,谢谢你的解决方法,我一直没怀疑是xboot中断设置问题,还在抓I2C信号,感谢你的解决方法,真心感谢XD

                      1 Reply Last reply Reply Quote Share 1
                      • steward
                        司徒 LV 6 last edited by

                        @Ary_Ye
                        I2C 訊號需要先確定再去看中斷問題, 就我的測試, I2C 應該是可以正常工作, 所以你可以往硬件問題排錯, 例如:I2C 上拉電阻等問題, 或者延長 XBoot 對 GT911 的 Reset 時間~

                        T 1 Reply Last reply Reply Quote Share 0
                        • T
                          tripod9 LV 5 @steward last edited by

                          @steward 感谢司徒的研究,发现了一个大BUG,中断号偏移计算错误,现已修复,打补丁如下:

                          diff --git a/src/arch/arm32/mach-t113s3/romdisk/boot/mangopi.json b/src/arch/arm32/mach-t113s3/romdisk/boot/mangopi.json
                          index 0f1f34283..4bc02d253 100644
                          --- a/src/arch/arm32/mach-t113s3/romdisk/boot/mangopi.json
                          +++ b/src/arch/arm32/mach-t113s3/romdisk/boot/mangopi.json
                          @@ -386,12 +386,12 @@
                           	"reset-t113@0x02001d0c": { "reset-base": 1184, "reset-count": 32 },
                           
                           	"irq-gic400@0x03020000": { "interrupt-base": 32, "interrupt-count": 224 },
                          -	"irq-t113-gpio@0x02000220": { "interrupt-base": 224, "interrupt-count":  8, "interrupt-parent":  101 },
                          -	"irq-t113-gpio@0x02000240": { "interrupt-base": 256, "interrupt-count":  8, "interrupt-parent":  103 },
                          -	"irq-t113-gpio@0x02000260": { "interrupt-base": 288, "interrupt-count": 23, "interrupt-parent":  105 },
                          -	"irq-t113-gpio@0x02000280": { "interrupt-base": 320, "interrupt-count": 14, "interrupt-parent":  107 },
                          -	"irq-t113-gpio@0x020002a0": { "interrupt-base": 352, "interrupt-count":  7, "interrupt-parent":  109 },
                          -	"irq-t113-gpio@0x020002c0": { "interrupt-base": 384, "interrupt-count": 16, "interrupt-parent":  111 },
                          +	"irq-t113-gpio@0x02000220": { "interrupt-base": 256, "interrupt-count":  8, "interrupt-parent":  101 },
                          +	"irq-t113-gpio@0x02000240": { "interrupt-base": 288, "interrupt-count":  8, "interrupt-parent":  103 },
                          +	"irq-t113-gpio@0x02000260": { "interrupt-base": 320, "interrupt-count": 23, "interrupt-parent":  105 },
                          +	"irq-t113-gpio@0x02000280": { "interrupt-base": 352, "interrupt-count": 14, "interrupt-parent":  107 },
                          +	"irq-t113-gpio@0x020002a0": { "interrupt-base": 384, "interrupt-count":  7, "interrupt-parent":  109 },
                          +	"irq-t113-gpio@0x020002c0": { "interrupt-base": 416, "interrupt-count": 16, "interrupt-parent":  111 },
                           
                           	"gpio-t113@0x02000030": { "gpio-base":  32, "gpio-count":  8, "interrupt-offset": 256 },
                           	"gpio-t113@0x02000060": { "gpio-base":  64, "gpio-count":  8, "interrupt-offset": 288 },
                          

                          完整补丁见这个链接
                          https://github.com/xboot/xboot/commit/4e502b7ad6e4f589832d36a4513de00f0cb8de07

                          1 Reply Last reply Reply Quote Share 1
                          • 1 / 1
                          • First post
                            Last post

                          Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号

                          行为准则 | 用户协议 | 隐私权政策