XFusion API v1.3.0
载入中...
搜索中...
未找到
xf_main.c
浏览该文件的文档.
1
17/* ==================== [Includes] ========================================== */
18
19#include "xf_hal.h"
20#include "xf_task.h"
21
22/* ==================== [Defines] =========================================== */
23
24#define TAG "i2c_master"
25
26#define DEFAULT_I2C_NUM 1
27#define DEFAULT_I2C_SCL_IO_NUM 16
28#define DEFAULT_I2C_SDA_IO_NUM 15
29#define DEFAULT_I2C_DEV_ADDR 0x23
30#define DEFAULT_I2C_FREQ 400*1000
31
32#define TASK_PRIORITY 5
33#define TASK_DELAY_MS 2000
34
35/* ==================== [Typedefs] ========================================== */
36
37/* ==================== [Static Prototypes] ================================= */
38
39static void i2c_master_init(void);
40static void i2c_task(xf_task_t task);
41
42/* ==================== [Static Variables] ================================== */
43
44/* ==================== [Macros] ============================================ */
45
46/* ==================== [Global Functions] ================================== */
47
53
54/* ==================== [Static Functions] ================================== */
55
64
66{
67 UNUSED(task);
68 int ret = 0;
69 uint8_t wbuf[] = "I M Master";
70 uint8_t rbuf[32] = {0};
71 ret = xf_hal_i2c_write(DEFAULT_I2C_NUM, wbuf, sizeof(wbuf), 200);
72 if (ret < 0) {
73 return;
74 }
75 XF_LOGI(TAG, "WRITE CMPL");
76 ret = xf_hal_i2c_read(DEFAULT_I2C_NUM, rbuf, sizeof(rbuf), 2000);
77 if (ret < 0) {
78 return;
79 }
80 XF_LOGI(TAG, "READ CMPL:%s", rbuf);
81}
82
void xf_main(void)
Definition xf_main.c:28
xf_err_t xf_hal_i2c_set_gpio(xf_i2c_num_t i2c_num, xf_gpio_num_t scl_num, xf_gpio_num_t sda_num)
i2c 设置 gpio。
Definition xf_hal_i2c.c:142
xf_err_t xf_hal_i2c_set_address(xf_i2c_num_t i2c_num, uint16_t address)
i2c 设置 i2c 从机地址。
Definition xf_hal_i2c.c:194
xf_err_t xf_hal_i2c_init(xf_i2c_num_t i2c_num, xf_hal_i2c_hosts_t hosts, uint32_t speed)
i2c 初始化函数。使用 i2c 之前必须要进行初始化。
Definition xf_hal_i2c.c:50
int xf_hal_i2c_write(xf_i2c_num_t i2c_num, const uint8_t *buffer, uint32_t size, uint32_t timeout_ms)
i2c 写入数据。
Definition xf_hal_i2c.c:315
int xf_hal_i2c_read(xf_i2c_num_t i2c_num, uint8_t *buffer, uint32_t size, uint32_t timeout_ms)
i2c 读取数据。
Definition xf_hal_i2c.c:347
xf_err_t xf_hal_i2c_enable(xf_i2c_num_t i2c_num)
i2c 启用函数。i2c 配置好功能后,可以调用 i2c 启用函数进行激活。
Definition xf_hal_i2c.c:92
@ XF_HAL_I2C_HOSTS_MASTER
Definition xf_hal_i2c.h:63
static xf_task_t xf_ttask_create_loop(xf_task_func_t func, void *func_arg, uint16_t priority, uint32_t delay_ms)
在默认的任务管理下,创建 ttask 循环任务。
Definition xf_task.h:162
#define TAG
Definition xf_main.c:24
#define TASK_DELAY_MS
Definition xf_main.c:27
#define TASK_PRIORITY
Definition xf_main.c:26
#define DEFAULT_I2C_SCL_IO_NUM
Definition xf_main.c:27
#define DEFAULT_I2C_FREQ
Definition xf_main.c:30
static void i2c_task(xf_task_t task)
Definition xf_main.c:65
static void i2c_master_init(void)
Definition xf_main.c:56
#define DEFAULT_I2C_NUM
Definition xf_main.c:26
#define DEFAULT_I2C_SDA_IO_NUM
Definition xf_main.c:28
#define DEFAULT_I2C_DEV_ADDR
Definition xf_main.c:29
static void task(xf_task_t task)
Definition xf_main.c:45
#define XF_LOGI(tag, format,...)
void * xf_task_t
任务句柄。
#define UNUSED(_x)