You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/device/adc/adc.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
-
#ADC Device
1
+
@page device_adc ADC Device
2
2
3
-
##An Introduction to ADC
3
+
# An Introduction to ADC
4
4
5
5
An ADC (analog-to-digital converter) is a hardware device that converts continuously changing analog signals to discrete digital signals. Usually, these analog signals include temperature, pressure, sound, video and many other types of signals. Converting them is important, as digital signals are easier to store, process, and transmit. This conversion can be achieved by using an ADC device which is commonly integrated in various platforms. Historically, ADCs were first used to convert received wireless signals to digital signals, for example, television signals, or signals from long-short broadcast stations.
6
6
7
-
###Conversion Process
7
+
## Conversion Process
8
8
9
9
As shown in the figure below, the analog-to-digital conversion generally involves steps of sampling, holding, quantifying, and encoding. In actual circuits, some processes are combined, such as sampling and holding, while quantization and encoding are implemented simultaneously in the conversion process.
10
10
@@ -14,19 +14,19 @@ Sampling is the conversion of analog signals that changes continuously over time
14
14
15
15
The process of converting a numerically continuous analog quantity into a digital quantity is called quantization. Digital signals are discrete numerically. The output voltage of the sample-and-hold circuit also needs to be naturalized to a corresponding discrete level in a similar way, and any digital quantity can only be an integer multiple of a certain minimum quantity unit. The quantized value also requires the encoding process, which is the digital output of the A/D converter.
16
16
17
-
###Resolution
17
+
## Resolution
18
18
19
19
Resolution is represented as binary (or decimal) numbers. Generally, it comes in 8 bits, 10 bits, 12 bits, 16 bits, etc. A larger resolution, in bits, means more accuracy in the conversion of analog to digital signals.
20
20
21
-
###Precision
21
+
## Precision
22
22
23
23
Precision is the maximum error value between analog signals and real ADC device numerical points’ values.An ADC with a high resolution might have a low precision, meaning that factors like noise can affect the numerical ADC reading more than small changes in the input signal.
24
24
25
-
###Conversion Rate
25
+
## Conversion Rate
26
26
27
27
The conversion rate is the reciprocal of time taken for an ADC device to complete conversion from an analog to a digital signal. For example, an ADC device with a conversion rate of 1MHz means that the ADC conversion time is 1 microsecond.
28
28
29
-
##Access ADC Device
29
+
# Access ADC Device
30
30
31
31
The application accesses the ADC hardware through the ADC device management interface provided by RT-Thread. The relevant interfaces are as follows:
32
32
@@ -37,7 +37,7 @@ The application accesses the ADC hardware through the ADC device management inte
37
37
| rt_adc_read() | Read ADC device data |
38
38
| rt_adc_disable() | Close the ADC device |
39
39
40
-
###Find ADC Devices
40
+
## Find ADC Devices
41
41
42
42
The application gets the device handler based on the ADC device name to operate the ADC device. Following is the interface function to find the devices:
Reading the ADC channel sample values can be done by the following function:
97
97
@@ -129,7 +129,7 @@ rt_kprintf("the voltage is :%d.%02d \n", vol / 100, vol % 100);
129
129
130
130
The calculation formula of the actual voltage value is: `sampling value * reference voltage/(1 << resolution digit)`. In the above example, variable *vol* was enlarged 100 times, so finally the integer part of voltage is obtained through *vol / 100*, and the decimal part of voltage is obtained through *vol % 100*.
131
131
132
-
###Disabling the ADC Channel
132
+
## Disabling the ADC Channel
133
133
134
134
An ADC channel can be disabled through the following function:
135
135
@@ -166,7 +166,7 @@ rt_kprintf("the voltage is :%d.%02d \n", vol / 100, vol % 100);
166
166
rt_adc_disable(adc_dev, ADC_DEV_CHANNEL);
167
167
```
168
168
169
-
###FinSH Command
169
+
## FinSH Command
170
170
171
171
To find out the registered device, you can use the command adc probe followed by the registered ADC device name as following,
Copy file name to clipboardExpand all lines: documentation/device/device.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
-
#I/O Device Framework
1
+
@page device_framework I/O Device Framework
2
2
3
3
Most embedded systems include some I/O (Input/Output) devices, data displays on instruments, serial communication on industrial devices, Flash or SD cards for saving data on data acquisition devices,as well as Ethernet interfaces for network devices, are examples of I/O devices that are commonly seen in embedded systems.
4
4
5
5
This chapter describes how RT-Thread manages different I/O devices.
6
6
7
-
##I/O Device Introduction
7
+
# I/O Device Introduction
8
8
9
-
###I/O Device Framework
9
+
## I/O Device Framework
10
10
11
11
RT-Thread provides a set of I/O device framework, as shown in the following figure. It is located between the hardware and the application. It is divided into three layers. From top to bottom, they are I/O device management layer, device driver framework layer, and device driver layer.
12
12
@@ -35,7 +35,7 @@ Usage of Watchdog device:
35
35
36
36

37
37
38
-
###I/O Device Model
38
+
## I/O Device Model
39
39
40
40
The device model of RT-Thread is based on the kernel object model, which is considered a kind of objects and is included in the scope of the object manager. Each device object is derived from the base object. Each concrete device can inherit the properties of its parent class object and derive its own properties. The following figure is a schematic diagram of the inheritance and derivation relationship of device object.
RT-Thread supports multiple I/O device types, the main device types are as follows:
72
72
@@ -95,7 +95,7 @@ A block device transfers one data block at a time, for example 512 bytes data at
95
95
96
96
When the system serves a write operation with a large amount of data, the device driver must first divide the data into multiple packets, each with the data size specified by the device. In the actual process, the last part of the data size may be smaller than the normal device block size. Each block in the above figure is written to the device using a separate write request, and the first three are directly written. However, the last data block size is smaller than the device block size, and the device driver must process the last data block differently than the first 3 blocks. Normally, the device driver needs to first perform a read operation of the corresponding device block, then overwrite the write data onto the read data, and then write the "composited" data block back to the device as a whole block. . For example, for block 4 in the above figure, the driver needs to read out the device block corresponding to block 4, and then overwrite the data to be written to the data read from the device block, and merge them into a new block. Finally write back to the block device.
97
97
98
-
##Create and Register I/O Device
98
+
# Create and Register I/O Device
99
99
100
100
The driver layer is responsible for creating device instances and registering them in the I/O Device Manager. You can create device instances in a statically declared manner or dynamically create them with the following interfaces:
The application accesses the hardware device through the I/O device management interface, which is accessible to the application when the device driver is implemented. The mapping relationship between the I/O device management interface and the operations on the I/O device is as follows:
251
251
252
252

253
253
254
-
###Find Device
254
+
## Find Device
255
255
256
256
The application obtains the device handle based on the device name, which in turn allows the device to operate. To find device, use function below:
>When a device has been successfully initialized, calling this interface will not repeat initialization.
285
285
286
-
###Open and Close Device
286
+
## Open and Close Device
287
287
288
288
Through the device handle, the application can open and close the device. When the device is opened, it will detect whether the device has been initialized. If it is not initialized, it will call the initialization interface to initialize the device by default. Open the device with the following function:
>Device interfaces `rt_device_open()` and `rt_device_close()` need to used in pairs. Open a device requires close the device, so that the device will be completely closed, otherwise the device will remain on.
335
335
336
-
### Control Device
336
+
## Control Device
337
337
338
338
By commanding the control word, the application can also control the device with the following function:
339
339
@@ -362,7 +362,7 @@ The generic device command for the parameter `cmd` can be defined as follows:
362
362
#defineRT_DEVICE_CTRL_GET_INT 0x12 /* obtain interrupt status */
363
363
```
364
364
365
-
###Read and Write Device
365
+
## Read and Write Device
366
366
367
367
Application can read data from the device by the following function:
Calling this function will write the data in the buffer to the *dev* device . The maximum length of the written data is *size*, and *pos* has different meanings depending on the device class.
402
402
403
-
###Data Transceiving and Call-back
403
+
## Data Transceiving and Call-back
404
404
405
405
When the hardware device receives the data, the following function can be used to call back another function to set the data receiving indication to notify the upper application thread that the data arrives:
When this function is called, the callback function is provided by the user. When the hardware device sends the data, the driver calls back the function and passes the sent data block address buffer as a parameter to the upper application. When the upper layer application (thread) receives the indication, it will release the buffer memory block or use it as the buffer for the next write data according to the condition of sending the buffer.
434
434
435
-
###Access Device Sample
435
+
## Access Device Sample
436
436
437
437
The following code is an example of accessing a device. First, find the watchdog device through the `rt_device_find()` port, obtain the device handle, then initialize the device through the `rt_device_init()` port, and set the watchdog device timeout through the `rt_device_control()`port.
Copy file name to clipboardExpand all lines: documentation/device/hwtimer/hwtimer.md
+11-12Lines changed: 11 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,6 @@
1
-
#HWTIMER Device
1
+
@page device_hwtimer HWTIMER Device
2
2
3
-
4
-
## Introduction to the Timer
3
+
# Introduction to the Timer
5
4
6
5
Hardware timers generally have two modes of operation, timer mode and counter mode. No matter which mode is operated, it works by counting the pulse signal counted by the internal counter module. Here are some important concepts of timers.
7
6
@@ -11,7 +10,7 @@ Hardware timers generally have two modes of operation, timer mode and counter mo
11
10
12
11
**Counting frequency**:Since the input frequency is usually fixed, the time it takes for the counter to reach its desired count number can be calculated from just the given frequency - `time = count value / count frequency`. For example, if the counting frequency is 1 MHz, the counter counts once every 1 / 1000000 seconds. That is, every 1 microsecond, the counter is incremented by one (or subtracted by one), at this time, the maximum timing capability of the 16-bit counter is 65535 microseconds, or 65.535 milliseconds.
13
12
14
-
##Access Hardware Timer Device
13
+
# Access Hardware Timer Device
15
14
16
15
The application accesses the hardware timer device through the I/O device management interface provided by RT-Thread. The related interfaces are as follows:
17
16
@@ -25,7 +24,7 @@ The application accesses the hardware timer device through the I/O device manage
25
24
| rt_device_read() | to get the current value of the timer |
26
25
| rt_device_close() | to turn off the timer device. |
27
26
28
-
###Find Timer Device
27
+
## Find Timer Device
29
28
30
29
The application obtains the device handle based on the hardware timer device name, and thus can operate the hardware timer device. The device function is as follows:
With the device handle, the application can open the device. When the device is open, it will detect whether the device has been initialized. If it is not initialized, it will call the initialization interface to initialize the device by default. Open the device with the following function:
Set the timer timeout callback function with the following function - this is the function that will be called when the timer reaches its set count value:
82
81
@@ -117,7 +116,7 @@ static int hwtimer_sample(int argc, char *argv[])
117
116
}
118
117
```
119
118
120
-
###Control the Timer Device
119
+
## Control the Timer Device
121
120
122
121
By sending control words, the application can configure the hardware timer device with the following function:
123
122
@@ -189,7 +188,7 @@ static int hwtimer_sample(int argc, char *argv[])
189
188
}
190
189
```
191
190
192
-
### Set the Timer Timeout Value
191
+
## Set the Timer Timeout Value
193
192
194
193
The timer timeout value can be set by the following function:
195
194
@@ -253,7 +252,7 @@ static int hwtimer_sample(int argc, char *argv[])
253
252
}
254
253
```
255
254
256
-
### Obtain the Current Value of the Timer
255
+
## Obtain the Current Value of the Timer
257
256
258
257
The current value of the timer can be obtained by the following function:
259
258
@@ -279,7 +278,7 @@ rt_hwtimerval_t timeout_s; /* Used to save the time the timer has elapsed *
The timer device can be closed with the following function:
285
284
@@ -310,7 +309,7 @@ rt_device_close(hw_dev);
310
309
311
310
>Timing errors may occur. Assume that the counter has a maximum value of 0xFFFF, a counting frequency of 1Mhz, and a timing time of 1 second and 1 microsecond. Since the timer can only count up to 65535us at a time, the timing requirement for 1000001us can be completed 20 times at 50000us, and the calculation error will be 1us.
312
311
313
-
## Hardware Timer Device Usage Example
312
+
# Hardware Timer Device Usage Example
314
313
315
314
The specific use of the hardware timer device can refer to the following sample code. The main steps of the sample code are as follows:
Copy file name to clipboardExpand all lines: documentation/device/i2c/i2c.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
#I2C Bus Device
1
+
@page device_i2c I2C Bus Device
2
2
3
-
##Introduction of I2C
3
+
# Introduction of I2C
4
4
5
5
The I2C (Inter Integrated Circuit) bus is a half-duplex, bidirectional two-wire synchronous serial bus developed by Philips. The I2C bus has only two signal lines, one is the bidirectional data line SDA (serial data), and the other is the bidirectional clock line SCL (serial clock). Compared to the SPI bus, which has two lines for receiving data and transmitting data between the master and slave devices, the I2C bus uses only one line for data transmission and reception.
6
6
@@ -28,7 +28,7 @@ When the bus is idle, both SDA and SCL are in a high state. When the host wants
28
28
29
29
***Stop Condition:** When SDA is low, the master pulls SCL high and stays high, then pulls SDA high to indicate the end of the transfer.
30
30
31
-
##Access to I2C Bus Devices
31
+
# Access to I2C Bus Devices
32
32
33
33
In general, the MCU's I2C device communicates as a master and slave. In the RT-Thread, the I2C master is virtualized as an I2C bus device. The I2C slave communicates with the I2C bus through the I2C device interface. The related interfaces are as follows:
34
34
@@ -37,7 +37,7 @@ In general, the MCU's I2C device communicates as a master and slave. In the RT-T
37
37
| rt_device_find() | Find device handles based on I2C bus device name |
38
38
| rt_i2c_transfer() | transfer data |
39
39
40
-
###Finding I2C Bus Device
40
+
## Finding I2C Bus Device
41
41
42
42
Before using the I2C bus device, you need to obtain the device handle according to the I2C bus device name, so that you can operate the I2C bus device. The device function is as follows.
0 commit comments