RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
dev_i2c.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2006-2024 RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2012-04-25 weety first version
9 * 2021-04-20 RiceChen added support for bus control api
10 */
11
12#ifndef __DEV_I2C_H__
13#define __DEV_I2C_H__
14
15#include <rtthread.h>
174
179#ifdef __cplusplus
180extern "C" {
181#endif
182
183#define RT_I2C_WR 0x0000
184#define RT_I2C_RD (1u << 0)
185#define RT_I2C_ADDR_10BIT (1u << 2)
186#define RT_I2C_NO_START (1u << 4)
187#define RT_I2C_IGNORE_NACK (1u << 5)
188#define RT_I2C_NO_READ_ACK (1u << 6) /* when I2C reading, we do not ACK */
189#define RT_I2C_NO_STOP (1u << 7)
190
191#define RT_I2C_DEV_CTRL_10BIT (RT_DEVICE_CTRL_BASE(I2CBUS) + 0x01)
192#define RT_I2C_DEV_CTRL_ADDR (RT_DEVICE_CTRL_BASE(I2CBUS) + 0x02)
193#define RT_I2C_DEV_CTRL_TIMEOUT (RT_DEVICE_CTRL_BASE(I2CBUS) + 0x03)
194#define RT_I2C_DEV_CTRL_RW (RT_DEVICE_CTRL_BASE(I2CBUS) + 0x04)
195#define RT_I2C_DEV_CTRL_CLK (RT_DEVICE_CTRL_BASE(I2CBUS) + 0x05)
196#define RT_I2C_DEV_CTRL_UNLOCK (RT_DEVICE_CTRL_BASE(I2CBUS) + 0x06)
197#define RT_I2C_DEV_CTRL_GET_STATE (RT_DEVICE_CTRL_BASE(I2CBUS) + 0x07)
198#define RT_I2C_DEV_CTRL_GET_MODE (RT_DEVICE_CTRL_BASE(I2CBUS) + 0x08)
199#define RT_I2C_DEV_CTRL_GET_ERROR (RT_DEVICE_CTRL_BASE(I2CBUS) + 0x09)
200
209
220
221struct rt_i2c_bus_device;
222
227{
229 struct rt_i2c_msg msgs[],
230 rt_uint32_t num);
232 struct rt_i2c_msg msgs[],
233 rt_uint32_t num);
235 int cmd,
236 void *args);
237};
238
252
257{
258#ifdef RT_USING_DM
259 struct rt_device parent;
260
261 const char *name;
262 const struct rt_i2c_device_id *id;
263 const struct rt_ofw_node_id *ofw_id;
264#endif
267};
268
269#ifdef RT_USING_DM
270struct rt_i2c_device_id
271{
272 char name[20];
273 void *data;
274};
275
276struct rt_i2c_driver
277{
278 struct rt_driver parent;
279
280 const struct rt_i2c_device_id *ids;
281 const struct rt_ofw_node_id *ofw_ids;
282
283 rt_err_t (*probe)(struct rt_i2c_client *client);
284 rt_err_t (*remove)(struct rt_i2c_client *client);
285 rt_err_t (*shutdown)(struct rt_i2c_client *client);
286};
287
288rt_err_t rt_i2c_driver_register(struct rt_i2c_driver *driver);
289rt_err_t rt_i2c_device_register(struct rt_i2c_client *client);
290
291#define RT_I2C_DRIVER_EXPORT(driver) RT_DRIVER_EXPORT(driver, i2c, BUILIN)
292#endif /* RT_USING_DM */
293
303 const char *name);
304
314 const char *bus_name);
315
323struct rt_i2c_bus_device *rt_i2c_bus_device_find(const char *bus_name);
324
335 struct rt_i2c_msg msgs[],
336 rt_uint32_t num);
337
348 int cmd,
349 void *args);
350
363 rt_uint16_t addr,
365 const rt_uint8_t *buf,
366 rt_uint32_t count);
367
380 rt_uint16_t addr,
382 rt_uint8_t *buf,
383 rt_uint32_t count);
384
386{
387 return rt_mutex_take(&bus->lock, timeout);
388}
389
391{
392 return rt_mutex_release(&bus->lock);
393}
394
395#ifdef __cplusplus
396}
397#endif
398
400
401#endif
rt_err_t rt_i2c_bus_device_register(struct rt_i2c_bus_device *bus, const char *bus_name)
I2C Bus Device Register
rt_err_t rt_i2c_bus_device_device_init(struct rt_i2c_bus_device *bus, const char *name)
I2C Bus Device Initialization
rt_ssize_t rt_i2c_master_send(struct rt_i2c_bus_device *bus, rt_uint16_t addr, rt_uint16_t flags, const rt_uint8_t *buf, rt_uint32_t count)
I2C Master Send
rt_ssize_t rt_i2c_master_recv(struct rt_i2c_bus_device *bus, rt_uint16_t addr, rt_uint16_t flags, rt_uint8_t *buf, rt_uint32_t count)
I2C Master Receive
struct rt_i2c_bus_device * rt_i2c_bus_device_find(const char *bus_name)
I2C Bus Device Find
rt_err_t rt_i2c_control(struct rt_i2c_bus_device *bus, int cmd, void *args)
I2C Control
rt_ssize_t rt_i2c_transfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg msgs[], rt_uint32_t num)
I2C data transmission.
rt_inline rt_err_t rt_i2c_bus_unlock(struct rt_i2c_bus_device *bus)
rt_inline rt_err_t rt_i2c_bus_lock(struct rt_i2c_bus_device *bus, rt_tick_t timeout)
rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time)
定义 ipc.c:1537
rt_err_t rt_mutex_release(rt_mutex_t mutex)
This function will release a mutex. If there is thread suspended on the mutex, the thread will be res...
定义 ipc.c:1589
rt_base_t rt_ssize_t
rt_base_t rt_err_t
unsigned char rt_uint8_t
unsigned short rt_uint16_t
rt_uint32_t rt_tick_t
rt_ubase_t rt_size_t
unsigned int rt_uint32_t
I2C Bus Device Operations
rt_err_t(* i2c_bus_control)(struct rt_i2c_bus_device *bus, int cmd, void *args)
rt_ssize_t(* master_xfer)(struct rt_i2c_bus_device *bus, struct rt_i2c_msg msgs[], rt_uint32_t num)
rt_ssize_t(* slave_xfer)(struct rt_i2c_bus_device *bus, struct rt_i2c_msg msgs[], rt_uint32_t num)
I2C Bus Device
const struct rt_i2c_bus_device_ops * ops
struct rt_device parent
rt_uint32_t retries
struct rt_mutex lock
rt_uint32_t timeout
rt_uint16_t client_addr
struct rt_i2c_bus_device * bus
I2C Message
rt_uint16_t addr
rt_uint16_t flags
rt_uint16_t len
rt_uint8_t * buf
I2C Private Data
struct rt_i2c_msg * msgs