Skip to content

Commit ccf158c

Browse files
author
luo jiao
committed
delete needless readme.md and change some code
1 parent d7b19b4 commit ccf158c

File tree

17 files changed

+155
-172
lines changed

17 files changed

+155
-172
lines changed

README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,10 @@
88

99
| 目录 | 例程 |
1010
| ---------------- | ------------------------------- |
11-
| block | 块设备的使用 |
12-
| can | can 设备的使用 |
13-
| ethernet | ethernet 设备的使用 |
14-
| i2c | i2c 设备的使用 |
15-
| pin | pin 设备的使用 |
16-
| pwm | pwm 设备的使用 |
17-
| serial | serial 设备的使用 |
18-
| spi | spi 设备的使用 |
19-
| usb | usb 设备的使用 |
11+
| i2c | i2c 设备的使用 |
12+
| pin | pin 设备的使用 |
13+
| serial | serial 设备的使用 |
14+
| spi | spi 设备的使用 |
2015

2116
### 1.2 许可证
2217

SConscript

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@ group = []
88
CPPPATH = []
99

1010
# add kernel samples.
11-
if GetDepend('PERIPHERAL_SAMPLES_USING_BLOCK'):
12-
src += Glob('block/*.c')
13-
CPPPATH += [cwd + '/block']
14-
15-
if GetDepend('PERIPHERAL_SAMPLES_USING_CAN'):
16-
src += Glob('can/*.c')
17-
CPPPATH += [cwd + '/can']
18-
19-
if GetDepend('PERIPHERAL_SAMPLES_USING_ETHERNET'):
20-
src += Glob('ethernet/*.c')
21-
CPPPATH += [cwd + '/ethernet']
2211

2312
if GetDepend('PERIPHERAL_SAMPLES_USING_I2C'):
2413
src += Glob('i2c/*.c')
@@ -28,10 +17,6 @@ if GetDepend('PERIPHERAL_SAMPLES_USING_PIN'):
2817
src += Glob('pin/*.c')
2918
CPPPATH += [cwd + '/pin']
3019

31-
if GetDepend('PERIPHERAL_SAMPLES_USING_PWM'):
32-
src += Glob('pwm/*.c')
33-
CPPPATH += [cwd + '/pwm']
34-
3520
if GetDepend('PERIPHERAL_SAMPLES_USING_SERIAL'):
3621
src += Glob('serial/*.c')
3722
CPPPATH += [cwd + '/serial']
@@ -40,10 +25,6 @@ if GetDepend('PERIPHERAL_SAMPLES_USING_SPI'):
4025
src += Glob('spi/*.c')
4126
CPPPATH += [cwd + '/spi']
4227

43-
if GetDepend('PERIPHERAL_SAMPLES_USING_USB'):
44-
src += Glob('usb/*.c')
45-
CPPPATH += [cwd + '/usb']
46-
4728
group = DefineGroup('peripheral-samples', src, depend = ['PKG_USING_PERIPHERAL_SAMPLES'], CPPPATH = CPPPATH)
4829

4930
Return('group')

block/README.md

Whitespace-only changes.

can/README.md

Whitespace-only changes.

ethernet/README.md

Whitespace-only changes.

i2c/README.md

Whitespace-only changes.
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@
1010

1111
#include <rtthread.h>
1212
#include <rtdevice.h>
13+
#include <stdbool.h>
1314

1415
#define AHT10_ADDR 0x38
1516
#define AHT10_CALIBRATION_CMD 0xE1 /* 校准命令 */
1617
#define AHT10_NORMAL_CMD 0xA8 /* 一般命令 */
1718
#define AHT10_GET_DATA 0xAC /* 获取数据命令 */
18-
#define I2C_BUS_NAME "i2c1" /* 传感器连接的I2C总线设备名称 */
19+
#ifndef AHT10_I2C_BUS_NAME
20+
#define AHT10_I2C_BUS_NAME "i2c1" /* 传感器连接的I2C总线设备名称 */
21+
#endif
1922

2023
static struct rt_i2c_bus_device *i2c_bus = RT_NULL;
21-
static rt_uint8_t init_flag = 0; /* 0:传感器没有初始化,1:传感器已经初始化 */
24+
static bool initialized = false; /* 传感器初始化状态 */
2225

2326
/* 写 传感器寄存器 */
2427
static rt_err_t write_reg(struct rt_i2c_bus_device *bus, rt_uint8_t reg, rt_uint8_t *data)
@@ -71,39 +74,39 @@ static void aht10_init(void)
7174
rt_uint8_t temp[2] = {0, 0};
7275

7376
/* 查找I2C总线设备,获取I2C总线设备句柄 */
74-
i2c_bus = rt_i2c_bus_device_find(I2C_BUS_NAME);
77+
i2c_bus = rt_i2c_bus_device_find(AHT10_I2C_BUS_NAME);
7578

7679
if (i2c_bus == RT_NULL)
7780
{
78-
rt_kprintf("can't find %s device", I2C_BUS_NAME);
81+
rt_kprintf("can't find %s device", AHT10_I2C_BUS_NAME);
7982
}
8083
else
8184
{
8285
write_reg(i2c_bus, AHT10_NORMAL_CMD, temp);
83-
rt_thread_delay(rt_tick_from_millisecond(600)); /* at least 300 ms */
86+
rt_thread_mdelay(600); /* at least 300 ms */
8487

8588
temp[0] = 0x08;
8689
temp[1] = 0x00;
8790
write_reg(i2c_bus, AHT10_CALIBRATION_CMD, temp);
88-
rt_thread_delay(rt_tick_from_millisecond(600)); /* at least 300 ms */
91+
rt_thread_mdelay(600); /* at least 300 ms */
8992

90-
init_flag = 1;
93+
initialized = true;
9194
}
9295
}
9396

94-
static void i2c_sample(void)
97+
static void i2c_aht10_sample(void)
9598
{
9699
float humidity, temperature;
97100

98101
humidity = 0.0;
99102
temperature = 0.0;
100103

101-
if (0 == init_flag)
104+
if (!initialized)
102105
{
103106
/* 传感器初始化 */
104107
aht10_init();
105108
}
106-
if (1 == init_flag)
109+
if (initialized)
107110
{
108111
/* 读取温湿度数据 */
109112
read_temp_humi(&temperature, &humidity);
@@ -113,11 +116,8 @@ static void i2c_sample(void)
113116
}
114117
else
115118
{
116-
rt_kprintf("init sensor failed\n");
119+
rt_kprintf("initialize sensor failed\n");
117120
}
118121
}
119122
/* 导出到 msh 命令列表中 */
120-
MSH_CMD_EXPORT(i2c_sample, i2c device sample);
121-
122-
123-
123+
MSH_CMD_EXPORT(i2c_aht10_sample, i2c aht10 sample);

pin/README.md

Whitespace-only changes.

pin/pin_beep_sample.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2006-2018, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2018-08-15 misonyo first implementation.
9+
*/
10+
11+
#include <rtthread.h>
12+
#include <rtdevice.h>
13+
14+
/* 引脚编号,通过查看drv_gpio.c确定 */
15+
#ifndef BEEP_PIN_NUM
16+
#define BEEP_PIN_NUM 37 /* PB2 */
17+
#endif
18+
#ifndef KEY0_PIN_NUM
19+
#define KEY0_PIN_NUM 55 /* PD8 */
20+
#endif
21+
#ifndef KEY1_PIN_NUM
22+
#define KEY1_PIN_NUM 56 /* PD9 */
23+
#endif
24+
25+
void beep_on(void *args)
26+
{
27+
rt_kprintf("turn on beep!\n");
28+
29+
rt_pin_write(BEEP_PIN_NUM, PIN_HIGH);
30+
}
31+
32+
void beep_off(void *args)
33+
{
34+
rt_kprintf("turn off beep!\n");
35+
36+
rt_pin_write(BEEP_PIN_NUM, PIN_LOW);
37+
}
38+
39+
static void pin_sample(void)
40+
{
41+
/* 按键0引脚为输入模式 */
42+
rt_pin_mode(KEY0_PIN_NUM, PIN_MODE_INPUT_PULLUP);
43+
/* 绑定中断,上升沿模式,回调函数名为beep_on */
44+
rt_pin_attach_irq(KEY0_PIN_NUM, PIN_IRQ_MODE_FALLING, beep_on, RT_NULL);
45+
/* 使能中断 */
46+
rt_pin_irq_enable(KEY0_PIN_NUM, PIN_IRQ_ENABLE);
47+
48+
/* 按键1引脚为输入模式 */
49+
rt_pin_mode(KEY1_PIN_NUM, PIN_MODE_INPUT_PULLUP);
50+
/* 绑定中断,上升沿模式,回调函数名为beep_off */
51+
rt_pin_attach_irq(KEY1_PIN_NUM, PIN_IRQ_MODE_FALLING, beep_off, RT_NULL);
52+
/* 使能中断 */
53+
rt_pin_irq_enable(KEY1_PIN_NUM, PIN_IRQ_ENABLE);
54+
/* 蜂鸣器引脚为输出模式 */
55+
rt_pin_mode(BEEP_PIN_NUM, PIN_MODE_OUTPUT);
56+
57+
}
58+
/* 导出到 msh 命令列表中 */
59+
MSH_CMD_EXPORT(pin_beep_sample, pin beep sample);

pin/pin_sample.c

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)