Skip to content

Commit f15414f

Browse files
authored
Merge pull request #5 from misonyo/master
移除目录
2 parents c0ef7b2 + cb95508 commit f15414f

File tree

6 files changed

+62
-42
lines changed

6 files changed

+62
-42
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
这个软件包包含一些外设设备操作的例程。
66

7-
### 1.1 目录结构
7+
### 1.1 例程说明
88

9-
| 目录 | 例程 |
9+
| 文件 | 说明 |
1010
| ---------------- | ------------------------------- |
11-
| i2c | i2c 设备的使用 |
12-
| pin | pin 设备的使用 |
13-
| serial | serial 设备的使用 |
14-
| spi | spi 设备的使用 |
11+
| i2c_aht10_sample.c | 使用 i2c 设备获取 aht10 温湿度传感器数据 |
12+
| pin_beep_sample.c | 使用 pin 设备控制蜂鸣器 |
13+
| uart_sample.c | 使用 serial 设备收发数据 |
14+
| spi_w25q_sample.c | 使用 spi 设备读取 W25Q ID |
1515

1616
### 1.2 许可证
1717

SConscript

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
1-
21
from building import *
3-
Import('rtconfig')
42

53
src = []
64
cwd = GetCurrentDir()
7-
group = []
8-
CPPPATH = []
5+
include_path = [cwd]
96

107
# add kernel samples.
118

129
if GetDepend('PERIPHERAL_SAMPLES_USING_I2C'):
13-
src += Glob('i2c/*.c')
14-
CPPPATH += [cwd + '/i2c']
10+
src += ['i2c_aht10_sample.c']
1511

1612
if GetDepend('PERIPHERAL_SAMPLES_USING_PIN'):
17-
src += Glob('pin/*.c')
18-
CPPPATH += [cwd + '/pin']
13+
src += Glob('pin_beep_sample.c')
1914

2015
if GetDepend('PERIPHERAL_SAMPLES_USING_SERIAL'):
21-
src += Glob('serial/*.c')
22-
CPPPATH += [cwd + '/serial']
16+
src += Glob('uart_sample.c')
2317

2418
if GetDepend('PERIPHERAL_SAMPLES_USING_SPI'):
25-
src += Glob('spi/*.c')
26-
CPPPATH += [cwd + '/spi']
19+
src += Glob('spi_w25q_sample.c')
2720

28-
group = DefineGroup('peripheral-samples', src, depend = ['PKG_USING_PERIPHERAL_SAMPLES'], CPPPATH = CPPPATH)
21+
group = DefineGroup('peripheral-samples', src, depend = ['PKG_USING_PERIPHERAL_SAMPLES'], CPPPATH = include_path)
2922

3023
Return('group')
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@
1010
/*
1111
* 程序清单:这是一个 I2C 设备使用例程
1212
* 例程导出了 i2c_aht10_sample 命令到控制终端
13-
* 命令调用格式:i2c_aht10_sample
13+
* 命令调用格式:i2c_aht10_sample i2c1
14+
* 命令解释:命令第二个参数是要使用的I2C总线设备名称,为空则使用默认的I2C总线设备
1415
* 程序功能:通过 I2C 设备读取温湿度传感器 aht10 的温湿度数据并打印
1516
*/
1617

1718
#include <rtthread.h>
1819
#include <rtdevice.h>
1920

20-
#ifndef AHT10_I2C_BUS_NAME
2121
#define AHT10_I2C_BUS_NAME "i2c1" /* 传感器连接的I2C总线设备名称 */
22-
#endif
2322
#define AHT10_ADDR 0x38
2423
#define AHT10_CALIBRATION_CMD 0xE1 /* 校准命令 */
2524
#define AHT10_NORMAL_CMD 0xA8 /* 一般命令 */
@@ -74,16 +73,16 @@ static void read_temp_humi(float *cur_temp,float *cur_humi)
7473
*cur_temp = ((temp[3] & 0xf) << 16 | temp[4] << 8 | temp[5]) * 200.0 / (1 << 20) - 50;
7574
}
7675

77-
static void aht10_init(void)
76+
static void aht10_init(const char *name)
7877
{
7978
rt_uint8_t temp[2] = {0, 0};
8079

8180
/* 查找I2C总线设备,获取I2C总线设备句柄 */
82-
i2c_bus = rt_i2c_bus_device_find(AHT10_I2C_BUS_NAME);
81+
i2c_bus = rt_i2c_bus_device_find(name);
8382

8483
if (i2c_bus == RT_NULL)
8584
{
86-
rt_kprintf("can't find %s device", AHT10_I2C_BUS_NAME);
85+
rt_kprintf("can't find %s device!\n", name);
8786
}
8887
else
8988
{
@@ -99,17 +98,27 @@ static void aht10_init(void)
9998
}
10099
}
101100

102-
static void i2c_aht10_sample(void)
101+
static void i2c_aht10_sample(int argc,char *argv[])
103102
{
104103
float humidity, temperature;
104+
char name[RT_NAME_MAX];
105105

106106
humidity = 0.0;
107107
temperature = 0.0;
108108

109+
if (argc == 2)
110+
{
111+
rt_strncpy(name, argv[1], RT_NAME_MAX);
112+
}
113+
else
114+
{
115+
rt_strncpy(name, AHT10_I2C_BUS_NAME, RT_NAME_MAX);
116+
}
117+
rt_kprintf("name is:%s!\n",name);
109118
if (!initialized)
110119
{
111120
/* 传感器初始化 */
112-
aht10_init();
121+
aht10_init(name);
113122
}
114123
if (initialized)
115124
{
@@ -121,7 +130,7 @@ static void i2c_aht10_sample(void)
121130
}
122131
else
123132
{
124-
rt_kprintf("initialize sensor failed\n");
133+
rt_kprintf("i2c sample run failed! initialize sensor failed!\n");
125134
}
126135
}
127136
/* 导出到 msh 命令列表中 */
File renamed without changes.
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,37 @@
1010
/*
1111
* 程序清单:这是一个 SPI 设备使用例程
1212
* 例程导出了 spi_w25q_sample 命令到控制终端
13-
* 命令调用格式:spi_w25q_sample
13+
* 命令调用格式:spi_w25q_sample spi10
14+
* 命令解释:命令第二个参数是要使用的SPI设备名称,为空则使用默认的SPI设备
1415
* 程序功能:通过SPI设备读取 w25q 的 ID 数据
1516
*/
1617

1718
#include <rtthread.h>
1819
#include <rtdevice.h>
1920

20-
#ifndef W25Q_SPI_DEVICE_NAME
2121
#define W25Q_SPI_DEVICE_NAME "qspi10"
22-
#endif
2322

24-
static void spi_w25q_sample(void)
23+
static void spi_w25q_sample(int argc,char *argv[])
2524
{
2625
struct rt_spi_device *spi_dev_w25q;
26+
char name[RT_NAME_MAX];
2727
rt_uint8_t w25x_read_id = 0x90;
2828
rt_uint8_t id[5] = {0};
2929

30-
/* 查找 qspi 设备获取设备句柄 */
31-
spi_dev_w25q = (struct rt_spi_device *)rt_device_find(W25Q_SPI_DEVICE_NAME);
30+
if (argc == 2)
31+
{
32+
rt_strncpy(name, argv[1], RT_NAME_MAX);
33+
}
34+
else
35+
{
36+
rt_strncpy(name, W25Q_SPI_DEVICE_NAME, RT_NAME_MAX);
37+
}
38+
rt_kprintf("name is:%s!\n",name);
39+
/* 查找 spi 设备获取设备句柄 */
40+
spi_dev_w25q = (struct rt_spi_device *)rt_device_find(name);
3241
if (!spi_dev_w25q)
3342
{
34-
rt_kprintf("spi sample run failed! can't find qspi device!");
43+
rt_kprintf("spi sample run failed! can't find %s device!\n", name);
3544
}
3645
else
3746
{
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
/*
1111
* 程序清单:这是一个 串口 设备使用例程
1212
* 例程导出了 uart_sample 命令到控制终端
13-
* 命令调用格式:uart_sample
13+
* 命令调用格式:uart_sample uart2
14+
* 命令解释:命令第二个参数是要使用的串口设备名称,为空则使用默认的串口设备
1415
* 程序功能:通过串口输出字符串"hello RT-Thread!",然后错位输出输入的字符
1516
*/
1617

1718
#include <rtthread.h>
1819

19-
#ifndef SAMPLE_UART_NAME
2020
#define SAMPLE_UART_NAME "uart2"
21-
#endif
21+
2222
/* 用于接收消息的信号量 */
2323
static struct rt_semaphore rx_sem;
24-
24+
static char uart_name[RT_NAME_MAX];
2525
/* 接收数据回调函数 */
2626
static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
2727
{
@@ -38,7 +38,7 @@ static void serial_thread_entry(void* parameter)
3838
char str[] = "hello RT-Thread!\r\n";
3939

4040
/* 查找系统中的串口设备 */
41-
serial = rt_device_find(SAMPLE_UART_NAME);
41+
serial = rt_device_find(uart_name);
4242

4343
if (serial != RT_NULL)
4444
{
@@ -65,12 +65,21 @@ static void serial_thread_entry(void* parameter)
6565
}
6666
else
6767
{
68-
rt_kprintf("open serial failed!\n");
68+
rt_kprintf("uart sample run failed! can't find %s device!\n",uart_name);
6969
}
7070
}
7171

72-
static void uart_sample(void)
72+
static void uart_sample(int argc,char *argv[])
7373
{
74+
if (argc == 2)
75+
{
76+
rt_strncpy(uart_name, argv[1], RT_NAME_MAX);
77+
}
78+
else
79+
{
80+
rt_strncpy(uart_name, SAMPLE_UART_NAME, RT_NAME_MAX);
81+
}
82+
rt_kprintf("name is:%s!\n",uart_name);
7483
/* 创建 serial 线程 */
7584
rt_thread_t thread = rt_thread_create("serial",serial_thread_entry, RT_NULL, 1024, 25, 10);
7685
/* 创建成功则启动线程 */

0 commit comments

Comments
 (0)