Skip to content

Commit 29287a3

Browse files
author
luo jiao
committed
add code illustration
1 parent ccf158c commit 29287a3

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

i2c/i2c_aht10_sample.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,29 @@
77
* Date Author Notes
88
* 2018-08-15 misonyo first implementation.
99
*/
10+
/*
11+
* 程序清单:这是一个 I2C 设备使用例程
12+
* 例程导出了 i2c_aht10_sample 命令到控制终端
13+
* 命令调用格式:i2c_aht10_sample
14+
* 程序功能:通过 I2C 设备读取温湿度传感器 aht10 的温湿度数据并打印
15+
*/
1016

1117
#include <rtthread.h>
1218
#include <rtdevice.h>
1319
#include <stdbool.h>
1420

21+
#ifndef AHT10_I2C_BUS_NAME
22+
#define AHT10_I2C_BUS_NAME "i2c1" /* 传感器连接的I2C总线设备名称 */
23+
#endif
1524
#define AHT10_ADDR 0x38
1625
#define AHT10_CALIBRATION_CMD 0xE1 /* 校准命令 */
1726
#define AHT10_NORMAL_CMD 0xA8 /* 一般命令 */
1827
#define AHT10_GET_DATA 0xAC /* 获取数据命令 */
19-
#ifndef AHT10_I2C_BUS_NAME
20-
#define AHT10_I2C_BUS_NAME "i2c1" /* 传感器连接的I2C总线设备名称 */
21-
#endif
2228

2329
static struct rt_i2c_bus_device *i2c_bus = RT_NULL;
24-
static bool initialized = false; /* 传感器初始化状态 */
30+
static bool initialized = false; /* 传感器初始化状态 */
2531

26-
/* 写 传感器寄存器 */
32+
/* 写传感器寄存器 */
2733
static rt_err_t write_reg(struct rt_i2c_bus_device *bus, rt_uint8_t reg, rt_uint8_t *data)
2834
{
2935
rt_uint8_t buf[3];
@@ -39,7 +45,7 @@ static rt_err_t write_reg(struct rt_i2c_bus_device *bus, rt_uint8_t reg, rt_uint
3945
return -RT_ERROR;
4046
}
4147

42-
/* 读 传感器寄存器数据 */
48+
/* 读传感器寄存器数据 */
4349
static rt_err_t read_regs(struct rt_i2c_bus_device *bus, rt_uint8_t len, rt_uint8_t *buf)
4450
{
4551
struct rt_i2c_msg msgs;

pin/pin_beep_sample.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
* Date Author Notes
88
* 2018-08-15 misonyo first implementation.
99
*/
10+
/*
11+
* 程序清单:这是一个 PIN 设备使用例程
12+
* 例程导出了 pin_beep_sample 命令到控制终端
13+
* 命令调用格式:pin_beep_sample
14+
* 程序功能:通过按键控制蜂鸣器对应引脚的电平状态控制蜂鸣器
15+
*/
1016

1117
#include <rtthread.h>
1218
#include <rtdevice.h>

serial/uart_sample.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
* Date Author Notes
88
* 2018-08-15 misonyo first implementation.
99
*/
10+
/*
11+
* 程序清单:这是一个 串口 设备使用例程
12+
* 例程导出了 uart_sample 命令到控制终端
13+
* 命令调用格式:uart_sample
14+
* 程序功能:通过串口输出字符串"hello RT-Thread!",然后错位输出输入的字符
15+
*/
1016

1117
#include <rtthread.h>
1218

spi/spi_w25q_sample.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
* Date Author Notes
88
* 2018-08-15 misonyo first implementation.
99
*/
10+
/*
11+
* 程序清单:这是一个 SPI 设备使用例程
12+
* 例程导出了 spi_w25q_sample 命令到控制终端
13+
* 命令调用格式:spi_w25q_sample
14+
* 程序功能:通过SPI设备读取 w25q 的 ID 数据
15+
*/
1016

1117
#include <rtthread.h>
1218
#include <rtdevice.h>

0 commit comments

Comments
 (0)