Skip to content

Commit 7d460da

Browse files
committed
新增 添加所有
1 parent 1dafaf5 commit 7d460da

File tree

320 files changed

+28603
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

320 files changed

+28603
-0
lines changed

32/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.pio

32/README.md

Whitespace-only changes.

32/include/README

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

32/lib/README

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in a an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html

32/lib/driver/include/Button.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef BUTTON_H
2+
#define BUTTON_H
3+
4+
#include "stm32f10x.h"
5+
#include "Util.h"
6+
7+
namespace teaheart {
8+
class Button {
9+
private:
10+
GPIO_TypeDef *GPIO;
11+
uint16_t pin;
12+
public:
13+
Button(GPIO_TypeDef *GPIO, uint16_t pin) : GPIO(GPIO), pin(pin) {}
14+
15+
BitAction getStatus() {
16+
return GPIO_ReadInputDataBit(GPIO, pin) == Bit_RESET ? Bit_RESET : Bit_SET;
17+
}
18+
};
19+
}
20+
21+
#endif //BUTTON_H

32/lib/driver/include/Buzzer.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef BUZZER_H
2+
#define BUZZER_H
3+
4+
#include "stm32f10x.h"
5+
6+
namespace teaheart {
7+
class Buzzer {
8+
private:
9+
GPIO_TypeDef *GPIO;
10+
uint16_t pin;
11+
public:
12+
Buzzer(GPIO_TypeDef *GPIO, uint16_t pin) : GPIO(GPIO), pin(pin) {
13+
off();
14+
}
15+
16+
void on() {
17+
GPIO_ResetBits(GPIO, pin);
18+
}
19+
20+
void off() {
21+
GPIO_SetBits(GPIO, pin);
22+
}
23+
24+
void toggle() {
25+
if (GPIO_ReadOutputDataBit(GPIO, pin) == Bit_RESET) {
26+
off();
27+
} else {
28+
on();
29+
}
30+
}
31+
32+
BitAction getStatus() {
33+
return GPIO_ReadOutputDataBit(GPIO, pin) == Bit_RESET ? Bit_RESET : Bit_SET;
34+
}
35+
36+
void setStatus(BitAction action) {
37+
GPIO_WriteBit(GPIO, pin, action);
38+
}
39+
};
40+
}
41+
42+
#endif //BUZZER_H

32/lib/driver/include/Delay.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef DELAY_H
2+
#define DELAY_H
3+
4+
#include "stm32f10x.h"
5+
6+
namespace teaheart {
7+
class Delay {
8+
public:
9+
/**
10+
* @brief 微秒延时
11+
* @param duration 持续时长 [0, 233015]
12+
*/
13+
static void microsecond(uint32_t duration) {
14+
SysTick->LOAD = 72 * duration; // 设置定时器重装值
15+
SysTick->VAL = 0x00000000; // 清空当前计数值
16+
SysTick->CTRL = 0x00000005; // 设置时钟源为HCLK, 启动定时器
17+
while ((SysTick->CTRL & 0x00010000) == 0); // 等待计数到0
18+
SysTick->CTRL = 0x00000004; // 关闭定时器
19+
}
20+
21+
/**
22+
* @brief 毫秒延时
23+
* @param duration 持续时长
24+
*/
25+
static void millisecond(uint32_t duration) {
26+
while (duration-- != 0) {
27+
microsecond(1000);
28+
}
29+
}
30+
31+
/**
32+
* @brief 秒级延时
33+
* @param duration 持续时长
34+
*/
35+
static void second(uint32_t duration) {
36+
while (duration-- != 0) {
37+
millisecond(1000);
38+
}
39+
}
40+
};
41+
}
42+
43+
#endif //DELAY_H

32/lib/driver/include/I2C.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#ifndef I2C_H
2+
#define I2C_H
3+
4+
#include "stm32f10x.h"
5+
6+
namespace teaheart {
7+
class I2C {
8+
private:
9+
GPIO_TypeDef *GPIO;
10+
uint16_t SCL;
11+
uint16_t SDA;
12+
13+
void writeSCL(BitAction action) {
14+
GPIO_WriteBit(GPIO, SCL, action);
15+
}
16+
17+
void writeSDA(BitAction action) {
18+
GPIO_WriteBit(GPIO, SDA, action);
19+
}
20+
21+
public:
22+
explicit I2C(GPIO_TypeDef *GPIO, uint16_t SCL, uint16_t SDA) : GPIO(GPIO), SCL(SCL), SDA(SDA) {
23+
writeSCL(Bit_SET);
24+
writeSDA(Bit_SET);
25+
}
26+
27+
void start() {
28+
writeSDA(Bit_SET);
29+
writeSCL(Bit_SET);
30+
writeSDA(Bit_RESET);
31+
writeSCL(Bit_RESET);
32+
}
33+
34+
void stop() {
35+
writeSDA(Bit_RESET);
36+
writeSCL(Bit_SET);
37+
writeSDA(Bit_SET);
38+
}
39+
40+
void sendByte(uint8_t byte) {
41+
for (uint8_t i = 0x80; i != 0x00; i >>= 1) {
42+
writeSDA((byte & i) != 0 ? Bit_SET : Bit_RESET);
43+
writeSCL(Bit_SET);
44+
writeSCL(Bit_RESET);
45+
}
46+
writeSCL(Bit_SET);
47+
writeSCL(Bit_RESET);
48+
}
49+
};
50+
}
51+
52+
#endif //I2C_H

32/lib/driver/include/LED.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef LED_H
2+
#define LED_H
3+
4+
#include "stm32f10x.h"
5+
6+
namespace teaheart {
7+
class LED {
8+
private:
9+
GPIO_TypeDef *GPIO;
10+
uint16_t pin;
11+
public:
12+
LED(GPIO_TypeDef *GPIO, uint16_t pin) : GPIO(GPIO), pin(pin) {
13+
off();
14+
}
15+
16+
void on() {
17+
GPIO_ResetBits(GPIO, pin);
18+
}
19+
20+
void off() {
21+
GPIO_SetBits(GPIO, pin);
22+
}
23+
24+
void toggle() {
25+
if (GPIO_ReadOutputDataBit(GPIO, pin) == Bit_RESET) {
26+
off();
27+
} else {
28+
on();
29+
}
30+
}
31+
32+
BitAction getStatus() {
33+
return GPIO_ReadOutputDataBit(GPIO, pin) == Bit_RESET ? Bit_RESET : Bit_SET;
34+
}
35+
36+
void setStatus(BitAction action) {
37+
GPIO_WriteBit(GPIO, pin, action);
38+
}
39+
};
40+
}
41+
42+
#endif //LED_H

32/lib/driver/include/LightSensor.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef LIGHT_SENSOR_H
2+
#define LIGHT_SENSOR_H
3+
4+
#include "stm32f10x.h"
5+
6+
namespace teaheart {
7+
class LightSensor {
8+
private:
9+
GPIO_TypeDef *GPIO;
10+
uint16_t pin;
11+
public:
12+
LightSensor(GPIO_TypeDef *GPIO, uint16_t pin) : GPIO(GPIO), pin(pin) {}
13+
14+
BitAction getStatus() {
15+
return GPIO_ReadInputDataBit(GPIO, pin) == Bit_RESET ? Bit_RESET : Bit_SET;
16+
}
17+
};
18+
}
19+
20+
#endif //LIGHT_SENSOR_H

0 commit comments

Comments
 (0)