和菜鸟一起学android4.0.3源码之touchscreen配置+调试记录

2019-04-15 13:10发布

        http://blog.csdn.net/eastmoon502136/article/details/7697434
        记得应该是上上周了,终于毕业了,离开了学校,就得面对现实的社会,以前学校实验室里,老师给了钥匙,那电脑随便用,那元器件随便玩,什么51单片机啊,PIC单片机啊,FPGA啊,arm11啊什么的。想着做什么就直接万用版+电烙铁什么的一起搞定。调试,写程序,焊板子都是自己一手操办啊,多么自由啊。到了公司,可不依你,对于上市公司来说,管理什么的总归还是有些规范化的。
        对于嵌入式,虽然早有所耳闻,大三也玩过arm7,编了几个基于GUI的贪吃蛇啊,黑白棋啊,连连看啊什么的。自己也买来arm11,烧写linux系统,搭建环境,最终也成功完成了hello world驱动模块。待以后有时间再好好整理整理。废话不多说了,既然是anrdroid下的touchscreen的配置,那就专心点,不东扯西扯了。
     都说android4.0.3的touchscreen有了很大的变化,菜鸟也不知道这么庞大的代码,各个功能模块式干嘛的。只能找找资料,瞎折腾了。公司的任务,触摸屏得上了,android的东西,只用鼠标可不好玩啊。开始调试SPI模式的ads7846的电阻屏,板子没有SPI接口,于是就用GPIO模拟SPI的方式来实现SPI的功能,在此要说明下,这个嵌入式的板子就是和51,PIC的板子用起来不一样啊,什么工作队列,什么中断下半部分工作,什么总线啊,I2C啊,SPI啊,I2S啊,USB啊,都这么纠结,顿时觉得学得好少啊,自己又有点懒,什么都想学,至于什么也没学好。调试好驱动后,总算是完成了一半的工作,接着,是否要直接上android去跑呢?android里什么机制都不知道额,虽然一开始android中实现鼠标的时候小研究过android下的input那个框架,不过只是模模糊糊的概念,根本就没有弄清楚。看来得下点功夫啊,要不然怎么混啊。又偏题了,额,正题,正题。。
         直接上android了,突然发现出现了一个小圈圈。向鼠标一样的。貌似触摸屏变成了鼠标了。觉得太怪了,怎么可以这样?肯定那里有问题的,找了好久的资料,终于找到了,原来是android4.0.3,他的touchscreen是需要配置文件的。只要直接创建一个“设备名.idc”的文件,直接放到/system/usr/idc/目录下,就可以了,设备名是驱动中定义的,在android中的Eventhub中也是可以加打印在logcat中看出来的。 [html] view plaincopy
  1. # Basic Parameters  
  2.   touch.deviceType = touchScreen  
  3.   touch.orientationAware = 1  
  4.   
  5.   # Size  
  6.   touch.size.calibration = diameter  
  7.   touch.size.scale = 10  
  8.   touch.size.bias = 0  
  9.   touch.size.isSummed = 0  
  10.   
  11.   # Pressure  
  12.   # Driver reports signal strength as pressure.  
  13.   #  
  14.   # A normal thumb touch typically registers about 200 signal strength  
  15.   # units although we don't expect these values to be accurate.  
  16.   touch.pressure.calibration = amplitude  
  17.   touch.pressure.scale = 0.005  
  18.   
  19.   # Orientation  
  20.   touch.orientation.calibration = none  

        但是就知道了这个配置文件,具体那里实现的呢?怎么配置进去的呢?怎么看着你个是touch.deviceType = touchScreen这个决定的。不多说来代码
frameworks/base/services/input/InputReader.cpp [html] view plaincopy
  1. void TouchInputMapper::configureParameters() {  
  2.     // Use the pointer presentation mode for devices that do not support distinct  
  3.     // multitouch.  The spot-based presentation relies on being able to accurately  
  4.     // locate two or more fingers on the touch pad.  
  5.     mParameters.gestureMode = getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_SEMI_MT)  
  6.             ? Parameters::GESTURE_MODE_POINTER : Parameters::GESTURE_MODE_SPOTS;  
  7.   
  8.     String8 gestureModeString;  
  9.     if (getDevice()->getConfiguration().tryGetProperty(String8("touch.gestureMode"),  
  10.             gestureModeString)) {  
  11.         if (gestureModeString == "pointer") {  
  12.             mParameters.gestureMode = Parameters::GESTURE_MODE_POINTER;  
  13.         } else if (gestureModeString == "spots") {  
  14.             mParameters.gestureMode = Parameters::GESTURE_MODE_SPOTS;  
  15.         } else if (gestureModeString != "default") {  
  16.             LOGW("Invalid value for touch.gestureMode: '%s'", gestureModeString.string());  
  17.         }  
  18.     }  
  19.   
  20.     if (getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_DIRECT)) {  
  21.         // The device is a touch screen.  
  22.         mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_SCREEN;  
  23.     } else if (getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_POINTER)) {  
  24.         // The device is a pointing device like a track pad.  
  25.         mParameters.deviceType = Parameters::DEVICE_TYPE_POINTER;  
  26.     } else if (getEventHub()->hasRelativeAxis(getDeviceId(), REL_X)  
  27.             || getEventHub()->hasRelativeAxis(getDeviceId(), REL_Y)) {  
  28.         // The device is a cursor device with a touch pad attached.  
  29.         // By default don't use the touch pad to move the pointer.  
  30.         mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_PAD;  
  31.     } else {  
  32.         // The device is a touch pad of unknown purpose.  
  33.         mParameters.deviceType = Parameters::DEVICE_TYPE_POINTER;  
  34.     }  
  35.   
  36.     String8 deviceTypeString;  
  37.     if (getDevice()->getConfiguration().tryGetProperty(String8("touch.deviceType"),  
  38.             deviceTypeString)) {  
  39.         if (deviceTypeString == "touchScreen") {  
  40.             mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_SCREEN;  
  41.         } else if (deviceTypeString == "touchPad") {  
  42.             mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_PAD;  
  43.         } else if (deviceTypeString == "pointer") {  
  44.             mParameters.deviceType = Parameters::DEVICE_TYPE_POINTER;  
  45.         } else if (deviceTypeString != "default") {  
  46.             LOGW("Invalid value for touch.deviceType: '%s'", deviceTypeString.string());  
  47.         }  
  48.     }  
  49.   
  50.     mParameters.orientationAware = mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN;  
  51.     getDevice()->getConfiguration().tryGetProperty(String8("touch.orientationAware"),  
  52.             mParameters.orientationAware);  
  53.   
  54.     mParameters.associatedDisplayId = -1;  
  55.     mParameters.associatedDisplayIsExternal = false;  
  56.     if (mParameters.orientationAware  
  57.             || mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN  
  58.             || mParameters.deviceType == Parameters::DEVICE_TYPE_POINTER) {  
  59.         mParameters.associatedDisplayIsExternal =  
  60.                 mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN  
  61.                         && getDevice()->isExternal();  
  62.         mParameters.associatedDisplayId = 0;  
  63.     }  
  64. }  

     还是英文呢,看到第一行,如果没有配置的话,那就是pointer,pointer不就是鼠标吗?只有定义deviceType为touchScreen,那才是我们要的啊。看来英文真的好重要好重 要啊。那到底是那里去获取配置文件的呢?不是一般都是EventHub下打开什么文件吗?走,咱们去seesee。
frameworks/base/services/input/EventHub.cpp [html] view plaincopy
  1. void EventHub::loadConfigurationLocked(Device* device) {  
  2.     device->configurationFile = getInputDeviceConfigurationFilePathByDeviceIdentifier(  
  3.             device->identifier, INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION);  
  4.     if (device->configurationFile.isEmpty()) {  
  5.         LOGD("No input device configuration file found for device '%s'.",  
  6.                 device->identifier.name.string());  
  7.     } else {  
  8.         status_t status = PropertyMap::load(device->configurationFile,  
  9.              &