Skip to content

Commit 928fde9

Browse files
authored
Merge pull request #91 from SummerGGift/update_doc
【完善】以潘多拉开发板为例更新例程,同时修改文档以便于生成的 PDF 更加美观
2 parents 4c78ab9 + e0f3714 commit 928fde9

File tree

10 files changed

+37
-31
lines changed

10 files changed

+37
-31
lines changed

docs/04-Hardware_Control_Module/01-machine.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
**machine** 模块包含与特定开发板上的硬件相关的特定函数。 在这个模块中的大多数功能允许实现直接和不受限制地访问和控制系统上的硬件块(如CPU,定时器,总线等)。如果使用不当,会导致故障,死机,崩溃,在极端的情况下,硬件会损坏。
44

5+
需要注意的是,由于不同开发板的硬件资源不同,MicroPython 移植所能控制的硬件也是不一样的。因此对于控制硬件的例程来说,在使用前需要修改相关的配置参数来适配不同的开发板,或者直接运行已经对某一开发板适配好的 MicroPython 示例程序。本文档中的例程都是基于 RT-Thread IoT Board 潘多拉开发板而讲解的。
6+
57
### 函数
68

79
#### 复位相关函数

docs/04-Hardware_Control_Module/02-machine-Pin.md

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

55
`Pin` 对象用于控制输入/输出引脚(也称为 `GPIO`)。`Pin` 对象通常与一个物理引脚相关联,他可以驱动输出电压和读取输入电压。Pin 类中有设置引脚模式(输入/输出)的方法,也有获取和设置数字逻辑(`0``1`)的方法。
66

7-
一个 `Pin` 对象是通过一个标识符来构造的,它明确地指定了一个特定的输入输出。标识符的形式和物理引脚的映射是特定于一次移植的。标识符可以是整数,字符串或者是一个带有端口和引脚号码的元组。在 RT-Thread MicroPython 中,引脚标识符是一个由代号和引脚号组成的元组,如 `Pin(("X1", 33), Pin.OUT_PP)` 中的` ("X1", 33)`
7+
一个 `Pin` 对象是通过一个标识符来构造的,它明确地指定了一个特定的输入输出。标识符的形式和物理引脚的映射是特定于一次移植的。标识符可以是整数,字符串或者是一个带有端口和引脚号码的元组。在 RT-Thread MicroPython 中,引脚标识符是一个由代号和引脚号组成的元组,如 `Pin(("PB15", 31), Pin.OUT_PP)` 中的` ("PB15", 31)`
88

99
### 构造函数
1010

1111
在 RT-Thread MicroPython 中 `Pin` 对象的构造函数如下:
1212

1313
#### **class machine.Pin**( id, mode = -1, pull = -1,value)
14-
- **id** :由用户自定义的引脚名和 `Pin` 设备引脚号组成,如("X1", 33),"X1" 为用户自定义的引脚名,`33``RT-Thread Pin` 设备驱动在本次移植中的引脚号。
14+
- **id** :由用户自定义的引脚名和 `Pin` 设备引脚号组成,如 ("PB15", 31),"PB15" 为用户自定义的引脚名,`31``RT-Thread Pin` 设备驱动在本次移植中的引脚号。
1515

1616
- **mode** : 指定引脚模式,可以是以下几种:
1717
- **Pin.IN** :输入模式
@@ -55,14 +55,17 @@
5555
### 示例
5656

5757
```
58-
>>> from machine import Pin
59-
>>>
60-
>>> p_out = Pin(("X1", 33), Pin.OUT_PP)
61-
>>> p_out.value(1) # set io high
62-
>>> p_out.value(0) # set io low
63-
>>>
64-
>>> p_in = Pin(("X2", 32), Pin.IN, Pin.PULL_UP)
65-
>>> p_in.value() # get value, 0 or 1
58+
from machine import Pin
59+
60+
PIN_OUT = 31
61+
PIN_IN = 58
62+
63+
p_out = Pin(("PB15", PIN_OUT), Pin.OUT_PP)
64+
p_out.value(1) # set io high
65+
p_out.value(0) # set io low
66+
67+
p_in = Pin(("key_0", PIN_IN), Pin.IN, Pin.PULL_UP)
68+
print(p_in.value() ) # get value, 0 or 1
6669
```
6770

6871
更多内容可参考 [machine.Pin](http://docs.micropython.org/en/latest/pyboard/library/machine.Pin.html)

docs/04-Hardware_Control_Module/03-machine-I2C.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@
7878
### 示例
7979

8080
#### `软件模拟 I2C `
81-
```
81+
```python
8282
>>> from machine import Pin, I2C
83-
>>> clk = Pin(("clk", 43), Pin.OUT_OD) # Select the 43 pin device as the clock
84-
>>> sda = Pin(("sda", 44), Pin.OUT_OD) # Select the 44 pin device as the data line
83+
>>> clk = Pin(("clk", 29), Pin.OUT_OD) # Select the 29 pin device as the clock
84+
>>> sda = Pin(("sda", 30), Pin.OUT_OD) # Select the 30 pin device as the data line
8585
>>> i2c = I2C(-1, clk, sda, freq=100000) # create I2C peripheral at frequency of 100kHz
8686
>>> i2c.scan() # scan for slaves, returning a list of 7-bit addresses
8787
[81] # Decimal representation
@@ -100,11 +100,12 @@ b'\x12' # starting at memory-address 8 in the slav
100100
需要先开启 `I2C` 设备驱动,查找设备可以在 `msh` 中输入`list_device` 命令。
101101
在构造函数的第一个参数传入 `0`,系统就会搜索名为 `i2c0` 的设备,找到之后使用这个设备来构建 `I2C` 对象:
102102

103-
```
103+
```python
104104
>>> from machine import Pin, I2C
105-
>>> i2c = I2C(0) # create I2C peripheral at frequency of 100kHz
105+
>>> i2c = I2C(0) # create I2C peripheral at frequency of 100kHz
106106
>>> i2c.scan() # scan for slaves, returning a list of 7-bit addresses
107107
[81] # Decimal representation
108108
```
109109

110110
更多内容可参考 [machine.I2C](http://docs.micropython.org/en/latest/pyboard/library/machine.I2C.html)
111+

docs/04-Hardware_Control_Module/04-machine-SPI.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@
6565
#### `软件模拟 SPI `
6666
```
6767
>>> from machine import Pin, SPI
68-
>>> clk = Pin(("clk", 43), Pin.OUT_PP)
69-
>>> mosi = Pin(("mosi", 44), Pin.OUT_PP)
70-
>>> miso = Pin(("miso", 45), Pin.IN)
68+
>>> clk = Pin(("clk", 26), Pin.OUT_PP)
69+
>>> mosi = Pin(("mosi", 27), Pin.OUT_PP)
70+
>>> miso = Pin(("miso", 28), Pin.IN)
7171
>>> spi = SPI(-1, 500000, polarity = 0, phase = 0, bits = 8, firstbit = 0, sck = clk, mosi = mosi, miso = miso)
7272
>>> print(spi)
7373
SoftSPI(baudrate=500000, polarity=0, phase=0, sck=clk, mosi=mosi, miso=miso)

docs/04-Hardware_Control_Module/05-machine-UART.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848

4949
```python
5050
from machine import UART
51-
uart = UART(1, 9600) # init with given baudrate
52-
uart.init(9600, bits=8, parity=None, stop=1) # init with given parameters
51+
uart = UART(1, 115200) # init with given baudrate
52+
uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters
5353
uart.read(10) # read 10 characters, returns a bytes object
5454
uart.read() # read all available characters
5555
uart.readline() # read a line

docs/04-Hardware_Control_Module/08-machine-PWM.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@
4545

4646
``` python
4747
>>> from machine import PWM # 从 machine 导入 PWM 类
48-
>>> pwm = PWM(1, 4, 1000, 100) # 创建 PWM 对象,当前使用编号为 1 的 PWM 设备的 4 通道,初始化的频率为 1000Hz,占空比数值为 100(占空比为 100/255 = 39.22%)
48+
>>> pwm = PWM(3, 3, 1000, 100) # 创建 PWM 对象,当前使用编号为 1 的 PWM 设备的 4 通道,初始化的频率为 1000Hz,占空比数值为 100(占空比为 100/255 = 39.22%)
4949
>>> pwm.freq(2000) # 设置 PWM 对象频率
5050
>>> pwm.freq() # 获取 PWM 对象频率
5151
2000
5252
>>> pwm.duty(200) # 设置 PWM 对象占空比数值
5353
>>> pwm.duty() # 获取 PWM 对象占空比数值
5454
200
5555
>>> pwm.deinit() # 关闭 PWM 对象
56-
>>> pwm.init(4, 1000, 100) # 开启并重新配置 PWM 对象
56+
>>> pwm.init(3, 1000, 100) # 开启并重新配置 PWM 对象
5757
```

docs/04-Hardware_Control_Module/09-machine-ADC.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
### 示例
3636

3737
``` python
38-
>>> from machine import ADC # 从 machine 导入 ADC 类
39-
>>> adc = ADC(2, 5) # 创建 ADC 对象,当前使用编号为 2 的 ADC 设备的 5 通道
40-
>>> adc.read() # 获取 ADC 对象采样值
38+
>>> from machine import ADC # 从 machine 导入 ADC 类
39+
>>> adc = ADC(1, 13) # 创建 ADC 对象,当前使用编号为 1 的 ADC 设备的 13 通道
40+
>>> adc.read() # 获取 ADC 对象采样值
4141
4095
42-
>>> adc.deinit() # 关闭 ADC 对象
43-
>>> adc.init(5) # 开启并重新配置 ADC 对象
42+
>>> adc.deinit() # 关闭 ADC 对象
43+
>>> adc.init(13) # 开启并重新配置 ADC 对象
4444
```

docs/04-Hardware_Control_Module/11-machine-Timer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def callback_test(device): # 回调函数有且只有一个入参,为
3838
该函数使用方式如下示例所示:
3939

4040
```python
41-
timer.init(wdt.PERIOD,5000,callback_test) # 设置定时器模式为周期性执行,超时时间为 5 秒, 超时函数为 callback_test
41+
timer.init(wdt.PERIOD, 5000, callback_test) # 设置定时器模式为周期性执行,超时时间为 5 秒, 超时函数为 callback_test
4242
```
4343
#### **Timer.deinit**()
4444

@@ -56,7 +56,7 @@ timer.init(wdt.PERIOD,5000,callback_test) # 设置定时器模式为周期性
5656

5757
```python
5858
>>> from machine import Timer # 从 machine 导入 Timer 类
59-
>>> timer = Timer(11) # 创建 Timer 对象,当前设备编号为 11
59+
>>> timer = Timer(15) # 创建 Timer 对象,当前设备编号为 11
6060
>>> # 进入粘贴模式
6161
paste mode; Ctrl-C to cancel, Ctrl-D to finish
6262
=== def callback_test(device): # 定义超时回调函数

docs/05-System_Module/01-uos.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## **uos**基本的"操作系统"服务
1+
## **uos**基本的操作系统服务
22

33
`uos` 模块包含了对文件系统的访问操作,是对应 CPython 模块的一个子集。
44

docs/05-System_Module/05-_thread.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## **_thread** – 多线程支持
1+
## _thread – 多线程支持
22

33
`_thread` 模块提供了用于处理多线程的基本方法——多个控制线程共享它们的全局数据空间。为了实现同步,提供了简单的锁(也称为互斥锁或二进制信号量)。
44

0 commit comments

Comments
 (0)