STM32 电容触摸屏I2C转USB实现

最近有个需求要把一个电容式触摸屏转为标准USB HID TP设备,同时需要把TP数据通过串口输出到MCU。市面方案大多采用CH554E做I2C USB转换,没有多余的UART口。问了几家供应商都说做不了,只好自己搞了。

能偷懒就偷懒,下载USBlyzer,把原屏的ReportDescriptor抓下来直接用了:

STM32 电容触摸屏I2C转USB实现

然后跟供应商要到接口文档和初始化寄存器配置:

STM32 电容触摸屏I2C转USB实现STM32 电容触摸屏I2C转USB实现

STM32 电容触摸屏I2C转USB实现

 

配置ConfigDescriptor:

 

 

STM32 电容触摸屏I2C转USB实现

 

用USBlyzer抓了下触摸数据:

STM32 电容触摸屏I2C转USB实现

与ReportDescriptor一致

    Usage (Finger) 09 22 
    Collection (Logical) A1 02 
        Usage (Tip Switch) 09 42 
        Logical Minimum (0) 15 00 
        Logical Maximum (1) 25 01 
        Report Size (1) 75 01 
        Report Count (1) 95 01 
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02 
        Report Count (1) 95 01 
        Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03 
        Report Count (6) 95 06 
        Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03 
        Report Size (8) 75 08 
        Usage (Contact Identifier) 09 51 
        Report Count (1) 95 01 
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02 
        Usage Page (Generic Desktop) 05 01 
        Logical Maximum (2048) 26 00 08 
        Report Size (16) 75 10 
        Unit Exponent (-2) 55 0E 
        Unit (SI Lin: Length (cm)) 65 11 
        Usage (X) 09 30 
        Physical Minimum (0) 35 00 
        Physical Maximum (2169) 46 79 08 
        Report Count (1) 95 01 
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02 
        Physical Minimum (1) 35 01 
        Physical Minimum (0) 35 00 
        Physical Maximum (1356) 46 4C 05 
        Logical Maximum (2048) 26 00 08 
        Usage (Y) 09 31 
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02 
        Physical Minimum (1) 35 01 
        Physical Minimum (0) 35 00 
        Usage Page (Digitizer) 05 0D 
        Logical Maximum (255) 26 FF 00 
        Physical Maximum (255) 46 FF 00 
        Report Count (1) 95 01 
        Usage (Width) 09 48 
        Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02 
    End Collection C0 

把TP的I2C接口调好就OK了,测试了一下OK。

下一步是把程序移植到STM32F070,价格不错,比汇顶提供的CH554还要便宜!