1041 views|3 replies

6069

Posts

4

Resources
The OP
 

"RT-Thread Device Driver Development Guide" Reading Notes 3 I2C Driver [Copy link]

This post was last edited by damiaa on 2023-9-16 21:45

"RT-Thread Device Driver Development Guide" Reading Notes 3 I2C Driver

"RT-Thread Device Driver Development Guide" reading notes - serial port driver

"RT-Thread Device Driver Development Guide" Reading Notes 2 After PIN Driver

All device classes of RT-Thread are derived from rt_device. So they have the same inheritance

The same is true for I2C devices. Why do you need to understand I2C drivers? Because many devices use I2C. If you don’t understand I2C when playing with embedded systems, you will have no fun.

Application layer : application code

I2C device driver framework Platform-independent code includes the following two files in components\drivers\i2c

I2c_core.c

i2c_dev.c:

i2c-bit-ops.c If it is simulating i2c, there is this software :

The I 2 C bus device driver layer is device-dependent and is also where we need to do some hands-on work in the porting.

Hardware I2C driver software I2C driver code is located in the bsp directory

Hardware I2C Driver

Need to implement

struct rt_i2c_bus_device_ops

{

rt_size_t (*master_xfer)(struct rt_i2c_bus_device *bus,

struct rt_i2c_msg msgs[],

rt_uint32_t num);

rt_size_t (*slave_xfer)(struct rt_i2c_bus_device *bus,

struct rt_i2c_msg msgs[],

rt_uint32_t num);

rt_err_t (*i2c_bus_control)(struct rt_i2c_bus_device *bus,

rt_uint32_t,

rt_uint32_t);

};

struct rt_i2c_bus_device

{

struct rt_device parent;

const struct rt_i2c_bus_device_ops *ops;

rt_uint16_t flags;

struct rt_mutex lock;

rt_uint32_t timeout;

rt_uint32_t retries;

void *priv;

};

Then call

rt_err_t rt_i2c_bus_device_register ( struct rt_i2c_bus_device *bus, const char *bus_name); function registration

Software I2C Driver

Need to implement

static const struct rt_i2c_bus_device_ops i2c_bit_bus_ops =

{

i2c_bit_xfer,

RT_NULL,

RT_NULL

};

rt_i2c_bit_add_bus(struct rt_i2c_bus_device *bus,const char *bus_name)注册

I won't go into detail about the specific implementation. You can refer to the relevant code experiments.

After the driver development is completed, Kconfig needs to be configured

For example, in: bsp\xxx\drivers\Kconfig

Config BSP_USING_I2C4

bool “Enable I2C4”

select RT_USING_I2C

default y

wait

Verify that the driver can be used in the console :

Run the command msh>list_device to verify. Call the application to conduct further experimental verification.

I will introduce it here based on what I know. Thank you

This post is from Embedded System

Latest reply

Does Teacher Da Mimi still need to learn things of this level?   Details Published on 2023-9-19 17:16

6841

Posts

11

Resources
2
 
After many tests, I found that RTT's hardware I2C was not very easy to use and the software was not fast enough.
This post is from Embedded System
 
 

7462

Posts

2

Resources
3
 

Does Teacher Da Mimi still need to learn things of this level?

This post is from Embedded System

Comments

I feel ashamed. Although I came into contact with I2C many years ago, there are still some differences in the drivers of I2C in various operating systems such as MCU, Arduino, RT-Thread, Linux, etc. It requires a more detailed understanding. I have learned a lot!  Details Published on 2023-9-20 08:36
 
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 

6069

Posts

4

Resources
4
 
freebsder posted on 2023-9-19 17:16 Does Teacher Da Mimi still need to learn something of this level?

I feel ashamed. Although I came into contact with I2C many years ago, there are still some differences in the drivers of I2C in various operating systems such as MCU, Arduino, RT-Thread, Linux, etc. It requires a more detailed understanding. I have learned a lot!

This post is from Embedded System
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list