linux i2c ctp核心流程学习


以i2c通信的ctp驱动,本质上是一个i2c驱动,i2c驱动是一个platform型的设备驱动。
platform型驱动主要包含platform device和platform driver,当两者都注册并匹配成功后会触发driver的probe函数。
一般来说i2c device在内核里已经注册,用户的主要工作,是编写i2c的driver,即i2c_driver,进行注册,即可完成工作。


i2c_driver例子:
static struct i2c_driver goodix_ts_driver = {
        .class          = I2C_CLASS_HWMON,
        .probe          = goodix_ts_probe,  //最重要函数
        .remove         = goodix_ts_remove,
#ifndef CONFIG_HAS_EARLYSUSPEND
#ifdef CONFIG_PM
        .suspend        = goodix_ts_suspend,
        .resume         = goodix_ts_resume,
#endif
#endif
        .id_table       = goodix_ts_id,//匹配i2c_board_info里的名字
        .driver = {
                .name   = CTP_NAME,
                .owner  = THIS_MODULE,
        },
        .address_list = normal_i2c,
};

定义:
struct i2c_driver {
unsigned int class;


/* Notifies the driver that a new bus has appeared or is about to be
* removed. You should avoid using this, it will be removed in a
* near future.
*/
int (*attach_adapter)(struct i2c_adapter *) __deprecated;
int (*detach_adapter)(struct i2c_adapter *) __deprecated;


/* Standard driver model interfaces */
int (*probe)(struct i2c_client *, const struct i2c_device_id *);  //probe函数
int (*remove)(struct i2c_client *);


/* driver model interfaces that don't relate to enumeration  */
void (*shutdown)(struct i2c_client *);
int (*suspend)(struct i2c_client *, pm_message_t mesg);
int (*resume)(struct i2c_client *);


/* Alert callback, for example for the SMBus alert protocol.
* The format and meaning of the data value depends on the protocol.
* For the SMBus alert protocol, there is a single bit of data passed
* as the alert response's low bit ("event flag").
*/
void (*alert)(struct i2c_client *, unsigned int data);


/* a ioctl like command that can be used to perform specific functions
* with the device.
*/
int (*command)(struct i2c_client *client, unsigned int cmd, void *arg);


struct device_driver driver;
const struct i2c_device_id *id_table;//匹配i2c_board_info里的名字,新架构里没用到?


/* Device detection callback for automatic device creation */
int (*detect)(struct i2c_client *, struct i2c_board_info *);//检测函数
const unsigned short *address_list;//里面要放iic地址
struct list_head clients;//
};


i2c_board_info,某些平台是
/*ctp info*/
static struct sw_device_info ctps[] = {
        { "ft5x_ts", {      0x38},   0xa3, {0x55,0x08,0x02,0x06,0xa3}, 0},
        {   "gt82x", {      0x5d},  0xf7d, {0x13,0x27,0x28          }, 0},
        { "gslX680", {      0x40},   0x00, {0x00                    }, 0},
        {"gt9xx_ts", {0x14, 0x5d}, 0x8140, {0x39                    }, 0},
        {   "gt811", {      0x5d},  0x715, {0x11                    }, 0},
        { "zet622x", {      0x76},   0x00, {0x00                    }, 0},
};
static struct base_info ctps[] = {
        { "ft5x_ts", {      0x38},   0xa3, {0x55,0x08,0x02,0x06,0xa3}},
        {   "gt82x", {      0x5d},  0xf7d, {0x13,0x27,0x28          }},
        { "gslX680", {      0x40},   0x00, {0x00                    }},
        {"gt9xx_ts", {0x14, 0x5d}, 0x8140, {0x39                    }},
        {   "gt811", {      0x5d},  0x715, {0x11                    }},
};
,这里的name要和i2c_device_id匹配,新架构里没用到?




初始化工作:
1.构建i2c_driver,包括添加detect
2.添加i2c_driver


probe函数进行的重要工作:
1,INIT_WORK(&ts->work, goodix_ts_work_func);//添加工作进队列
2,ret = gtp_request_input_dev(ts);//申请input
3,ret = gtp_request_irq(ts); //申请中断,中断响应函数会调度工作队列goodix_ts_work_func
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux环境下使用C语言来完成ctp期货量化交易系统,首先需要安装相应的开发工具和环境,例如gcc编译器和相关的开发库。然后,可以通过ctp官方提供的API来进行开发。 接下来,需要编写C语言程序来连接ctp交易接口,包括登录行情服务器、连接交易服务器、订阅行情数据、下单交易等相关功能。在编写程序时,需要充分了解ctp交易接口的相关文档和示例代码,以便正确地调用接口函数。 在交易系统的开发过程中,需要考虑到错误处理、数据处理、交易策略的实现等方面。对于错误处理,可以通过编写日志来记录程序的运行情况,以便排查错误。对于数据处理,可以通过编写算法来对行情数据进行分析和处理,以支持量化交易策略的实现。 在编写交易策略时,需要根据具体的量化交易策略来实现相应的买卖逻辑,可以通过编写条件判断语句和相关算法来实现交易决策。 最后,在完成ctp期货量化交易系统的开发后,还需要进行充分的测试和优化。通过模拟交易和回测来验证交易系统的稳定性和盈利性,通过优化代码和算法来提高系统的性能和效率。 总之,在Linux环境下使用C语言完成ctp期货量化交易系统的开发,需要充分的了解ctp接口和API,编写对应的功能程序,实现量化交易策略,并进行测试和优化,以确保系统的稳定性和盈利性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值