转自http://blog.csdn.net/qwertyuiop159158/article/details/47957429

1.驱动移植
 将wk2xxx_i2c.c wk2xxx.h 放到lichee\linux-3.4\drivers\hwmon目录下
1.makefile
obj-$(CONFIG_SERIAL_I2C_WK2XXX) += wk2xxx_i2c.o
2. kconfig
 config SERIAL_I2C_WK2XXX
tristate "i2c to 4 uart for wk2xxx chips "
select I2C  
select SERIAL_CORE
depends on HWMON
default m
help
i2c to 4 uart for wk2xxx chips
说明:由于是串口扩展,所以需要选择 SERIAL_CORE,基于i2c,所以要select i2c

3.i2c irq中断配置
在sysconfig.fex中添加相关的io配置
;-------------------------------------------------------------------------------
;wk2 irq configuration
;-------------------------------------------------------------------------------
[wk2_para]
wk2_used            = 1
wk2_twi_id          = 1
wk2_twi_addr        = 0x10
wk2_freq            = 400000
wk2_irq_port        = port:PI16<6><default><default><default>

4.驱动代码的移植
4.1. init函数
在这个函数中首先要获取sysconfig中的相关的配置,同时将设备注册到相应的i2c总线上
int ret;
printk("wk2xxx_init-------------------------\n");
        int retval;
ret=wk2xxx_fetch_sysconfig_para();

if(ret < 0){
printk("wk2xxx_fetch_sysconfig_para failed in init \n");
}
// wk2xxx_i2c_driver.detect = wk2xxx_detect;
        struct i2c_board_info info;
      struct i2c_adapter *adapter;
      struct i2c_client *client;
 memset(&info, 0, sizeof(struct i2c_board_info));
 info.addr = 0x10;
  strlcpy(info.type, "wk2xxx_i2c", I2C_NAME_SIZE);
  adapter = i2c_get_adapter(1);

if (!adapter) {
  printk("*******get_adapter error!********\n");
  }
  client = i2c_new_device(adapter, &info);
 wk2xxx_detect(client, &info);

/*   i2c_add_driver(&msg21xx_ts_driver);
  if (msg21xx_device_check == 0) {
  i2c_del_driver(&msg21xx_ts_driver);
  printk("msg21xx_device_check is 0 =========================\n");
  }
  return ret;
struct i2c_board_info bi = {I2C_BOARD_INFO("wk2xxx_i2c", 0x10),};
i2c_new_device(i2c_get_adapter( wk2xxx_i2c_pdata.bus_num), &bi);
*/    
 retval = i2c_add_driver(&wk2xxx_i2c_driver);
if (retval !=0)
{
printk("======wk2xxx_i2c_driver init fail, ret=0x%x======\n", retval);
i2c_del_driver(&wk2xxx_i2c_driver);
return ret;
}

static int wk2xxx_detect(struct i2c_client *client, struct i2c_board_info *info)
{
printk("wk2xxx_detect-----\n");
struct i2c_adapter *adapter = client->adapter;
int ret;

if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
                return -ENODEV;

if(twi_id == adapter->nr){
                printk("%s: addr= %x\n",__func__,client->addr);
               ret = i2c_test(client);
                if(!ret){
        printk("%s:I2C connection might be something wrong \n",__func__);
        return -ENODEV;
        
}else{
strlcpy(info->type, "wk2xxx_i2c", I2C_NAME_SIZE);
return 0;
       }

}else{
return -ENODEV;
}
}

4.2 获取配置文件相关信息函数

static int wk2xxx_fetch_sysconfig_para(void){
printk("wk2xxx_fetch_sysconfig_para-------------------\n");
int ret =  -1;
int i = -1;
int device_used = -1;
script_item_u val;
script_item_value_type_e  type;
type = script_get_item("wk2_para", "wk2_used", &val);
 if(SCIRPT_ITEM_VALUE_TYPE_INT != type){
  printk("%s, type err device_used =%d \n", __func__, val.val);
goto script_get_err;
  }
device_used = val.val;
if(1 == device_used){
type = script_get_item("wk2_para", "wk2_twi_id", &val);

if(SCIRPT_ITEM_VALUE_TYPE_INT != type){
printk("%s: type err twi_id = %d. \n", __func__, val.val);
goto script_get_err;
  }
  wk2xxx_i2c_pdata.bus_num = val.val;
printk("wk2xxx_i2c_pdata.bus_num =%d\n",wk2xxx_i2c_pdata.bus_num);
  
  type = script_get_item("wk2_para", "wk2_twi_addr", &val);

if(SCIRPT_ITEM_VALUE_TYPE_INT != type){
printk("%s: type err twi_id = %d. \n", __func__, val.val);
goto script_get_err;
  }
  wk2xxx_i2c_pdata.slave_addr = val.val;   
  
  printk("wk2xxx_i2c_pdata.slave_addr =%d\n",wk2xxx_i2c_pdata.slave_addr);

type = script_get_item("wk2_para", "wk2_freq", &val);
  
  if(SCIRPT_ITEM_VALUE_TYPE_INT != type){
printk("%s: type err twi_id = %d. \n", __func__, val.val);
  goto script_get_err;
 }
 wk2xxx_i2c_pdata.frequency = val.val;

printk("wk2 frequency=%d\n",wk2xxx_i2c_pdata.frequency);
 
type = script_get_item("wk2_para", "wk2_irq_port", &val);
if (type != SCIRPT_ITEM_VALUE_TYPE_PIO) {
printk("get uarts IO(uart_irq) failed\n");
goto script_get_err;
}
                      int_number= val.gpio.gpio;
printk("wk2 int_number=%d\n",int_number);
/* i =  i2c_register_board_info( wk2xxx_i2c_pdata.bus_num, wk2xxx_i2c_board_info,
 ARRAY_SIZE(wk2xxx_i2c_board_info));
if(i < 0){
printk("wk2 register i2c device failed \n");
goto script_get_err;
}*/
printk("wk2xxx_fetch_sysconfig_para--is ok----------\n");
  return 0;
  
  }else{

printk("wk2xxx get sysconfig failed \n");
ret = -1;
  }
script_get_err:
printk("get erro");
return ret;

}

4.3 构建board info
static struct wk2xxx_platform_data  wk2xxx_i2c_pdata = {
.flag  = 0,
};

4.4 中断函数的修改
由于a20对中断函数进行了重新的封装,所以要对应平台函数为
 if(sw_gpio_irq_request(s->port.irq, TRIG_EDGE_NEGATIVE , (peint_handle)wk2xxx_irq, s) <0)
同时使能和关闭中断函数也要分别进行修改
 //disable_irq_nosync(s->port.irq);
      --------》  sw_gpio_eint_set_enable(s->port.irq, 0);

//enable_irq(s->port.irq);
 ===========》           sw_gpio_eint_set_enable(s->port.irq, 1);

/static irqreturn_t wk2xxx_irq(int irq, void *dev_id)//
----------------》static u32 wk2xxx_irq(struct wk2xxx_port  *dev_id){
return 0;
}

4.5 还有就是一些头文件的修改了

4.6 编译成ko 或者build-in都ok,如果是ko,在android init 的时候记得要insod

5.总结的关键点
1.a20的对中断函数进行了重新的封装,对应于代码中要注意这一系列函数的参数以及
返回值的使用
2.其他就是一些细节问题了
3.最开始调试的是uart to uart 但是datasheet对于寄存器的设置流程基本无描述。
所以这个是非常难的一个部分

android 串口扩展(wk2xxx)移植相关推荐

  1. Android串口通信实例分析【附源码】

    Android 串口通信实例分析,用的时开源的android-serialport-api 这个是用android ndk实现的串口通信,我把他做了一个简化,适合于一般的程序的串口通信移植,欢迎拍砖- ...

  2. 基于一款 wk2168芯片的串口扩展

    串口扩展芯片应用介绍 一. 概述 随着嵌入式系统的功能越来越强大,搭载的外围设备也不断的增加,为了方便系统的集成,现在的外围设备通常都提供了标准的通信接口.在这些标准接口当中最常用的就是我们比较熟悉的 ...

  3. CH340与Android串口通信

    CH340与Android串口通信 为何要将CH340的ATD+Eclipse上的安卓工程移植到AndroidStudio 移植的具体步骤 CH340串口通信驱动函数 通信过程中重难点 还存在的问题 ...

  4. 快速使用Android串口

    天下武功,唯快不破 有多快?只需要一招!引入第三方库就可以快速开发和使用Android串口,毕竟我们站在了巨人的肩膀上. 第一步导包,也就只有这一步了 // 在项目根目录的build.gradle文件 ...

  5. modbus协议使用【android串口通信】

    modbus协议使用[android串口通信] 本文的目的是android端与上位机之间使用modbus协议进行串口通信.通过串口与其他设备进行通信,传递数据.可以理解为电脑和键盘.鼠标通信. 关于m ...

  6. 基于MT6752/32平台 Android L版本驱动移植步骤

    基于MT6752/32平台 Android L版本驱动移植步骤 根据MK官网所述,在Android L 版本上Turnkey ABS 架构将会phase out,而Mediatek Turnkey架构 ...

  7. adb shell 调试 Android 串口

    Android手机上很多外设是串口连接到AP的,如modem,gps.为了调试这些串口,通常需要将它们飞线接出来,用pc的串口连接调试.这样比较麻烦. 在adb  shell里是可以直接调试串口的,就 ...

  8. SJXXX串口扩展芯片 4串口芯片 UART串口芯片

    SJXX串口扩展芯片 1 概述 SJ000是一款具备I2C总线/SPI总线/UART接口的四通道异步收发器件,通过模式选择使得该器件工作于以上任何一种主接口模式下.器件的四个通道UART可提供高达2M ...

  9. Android串口通信apk源码

    1.SerialPortHelper「Android串口通信」介绍 原项目地址 https://github.com/freyskill/SerialPortHelper Android串口通讯助手可 ...

最新文章

  1. lisp修改天正标高值_【求教】如何批量修改天正字体
  2. nginx 修复固定链接404
  3. 安装opencv3.0.0与配置Visual studio 2008
  4. hdu 5203(枚举)
  5. Install Cloud foundry MTA plugin
  6. CF1392G-Omkar and Pies【dp】
  7. python decimal用法_Python decimal模块使用方法详解
  8. Silverlight实用窍门系列:43.Silverlight从ListBox拖拽图标到另一ListBox
  9. 荣耀 MagicBook 14 2022配置怎么样 值不值得买
  10. JavaScript键盘鼠标事件处理
  11. 优达笔记-安然数据分析 异常值处理
  12. 用深度学习做命名实体识别(四)——模型训练
  13. Unix时间戳1970Java与Unix时间戳互转
  14. 多传感器融合定位六-惯性导航原理及误差分析
  15. 华软mysql考试_在广州大学华软软件学院就读是怎样一番体验?
  16. 基于指纹的原则,具体的音乐检索
  17. Python爬虫:制作一个属于自己的IP代理模块2
  18. 历年计算机一级考试原题,全国计算机等级考试一级历年上机真题.doc
  19. 干货丨大数据基础术语精粹来袭
  20. 面向对象思想在UnityUI控制背景音乐音效大小开关中的运用

热门文章

  1. 【原创】i.MXRT J-Flash烧写算法使能eFuse熔丝位写入
  2. 亲测的一款在线作图神器:ProcessOn
  3. “Project2.exe”(Win32): 已加载“C:\Windows\SysWOW64\msvcp120d.dll”。无法查找或打开 PDB 文件。
  4. VC6 到 VS2008 的问题
  5. CapitalOne - Artifactory高可用集群的自动化部署实践
  6. GitLab安装以及汉化
  7. springboot打成jar包后linux服务器上无法读取resources资源文件里文件路径的问题
  8. PTE两周速成指南及江西考点初体验
  9. 毁约典型案例分析(准备毁约的同学请务必谨慎)
  10. 在mysql命令行中输入字符串提示 Incorrect string value: '\xC4\xE3' for column 'name' 出现异常