Skip to content

Commit d0cd890

Browse files
Update some modules documentation (#1726)
* docs: Add inverting documentation and examples * docs: Update I2C mod docs * docs: Update LEDC documentation * docs: FIx format * Fix a typo in docstring in `esp-hal/src/uart.rs` --------- Co-authored-by: Jesse Braham <[email protected]>
1 parent 565faf7 commit d0cd890

File tree

5 files changed

+102
-24
lines changed

5 files changed

+102
-24
lines changed

esp-hal/src/i2c.rs

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,60 @@
1-
//! # I2C Driver
1+
//! # Inter-Integrated Circuit (I2C)
22
//!
3-
//! ## Overview
4-
//! The I2C Peripheral Driver for ESP chips is a software module that
5-
//! facilitates communication with I2C devices using ESP microcontroller chips.
6-
//! It provides an interface to initialize, configure, and perform read and
7-
//! write operations over the I2C bus.
3+
//! I2C is a serial, synchronous, multi-device, half-duplex communication
4+
//! protocol that allows co-existence of multiple masters and slaves on the
5+
//! same bus. I2C uses two bidirectional open-drain lines: serial data line
6+
//! (SDA) and serial clock line (SCL), pulled up by resistors.
87
//!
9-
//! The driver supports features such as handling transmission errors,
10-
//! asynchronous operations, and interrupt-based communication, also supports
11-
//! multiple I2C peripheral instances on `ESP32`, `ESP32H2`, `ESP32S2`, and
12-
//! `ESP32S3` chips
8+
//! Espressif devices sometimes have more than one I2C controller (also called
9+
//! port), responsible for handling communication on the I2C bus. A single I2C
10+
//! controller can be a master or a slave.
1311
//!
14-
//! ## Example
15-
//! Following code shows how to read data from a BMP180 sensor using I2C.
12+
//! Typically, an I2C slave device has a 7-bit address or 10-bit address.
13+
//! Espressif devices supports both I2C Standard-mode (Sm) and Fast-mode
14+
//! (Fm) which can go up to 100KHz and 400KHz respectively.
1615
//!
16+
//! ## Configuration
17+
//!
18+
//! Each I2C controller is individually configurable, and the usual setting
19+
//! such as frequency, timeout, and SDA/SCL pins can easily be configured.
20+
//!
21+
//! ```rust, no_run
22+
#![doc = crate::before_snippet!()]
23+
//! # use esp_hal::i2c::I2C;
24+
//! # use esp_hal::gpio::Io;
25+
//! # use core::option::Option::None;
26+
//! # use crate::esp_hal::prelude::_fugit_RateExtU32;
27+
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
28+
//! // Create a new peripheral object with the described wiring
29+
//! // and standard I2C clock speed
30+
//! let mut i2c = I2C::new(
31+
//! peripherals.I2C0,
32+
//! io.pins.gpio1,
33+
//! io.pins.gpio2,
34+
//! 100.kHz(),
35+
//! &clocks,
36+
//! None,
37+
//! );
38+
//! # }
39+
//! ```
40+
//!
41+
//! ## Usage
42+
//!
43+
//! The I2C driver implements a number of third-party traits, with the
44+
//! intention of making the HAL inter-compatible with various device drivers
45+
//! from the community. This includes the [embedded-hal] for both 0.2.x and
46+
//! 1.x.x versions.
47+
//!
48+
//! ### Examples
49+
//!
50+
//! #### Read Data from a BMP180 Sensor
1751
//! ```rust, no_run
1852
#![doc = crate::before_snippet!()]
1953
//! # use esp_hal::i2c::I2C;
2054
//! # use esp_hal::gpio::Io;
2155
//! # use core::option::Option::None;
2256
//! # use crate::esp_hal::prelude::_fugit_RateExtU32;
23-
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
57+
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
2458
//! // Create a new peripheral object with the described wiring
2559
//! // and standard I2C clock speed
2660
//! let mut i2c = I2C::new(

esp-hal/src/ledc/mod.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
//! # LEDC (LED PWM Controller) peripheral control
1+
//! # LED Controller (LEDC)
22
//!
3-
//! Currently only supports fixed-frequency output. Interrupts are not currently
4-
//! implemented. High Speed channels are available for the ESP32 only, while Low
5-
//! Speed channels are available for all supported chips.
3+
//! The LED control (LEDC) peripheral is primarily designed to control the
4+
//! intensity of LEDs, although it can also be used to generate PWM signals for
5+
//! other purposes. It has multiple channels which can generate independent
6+
//! waveforms that can be used, for example, to drive RGB LED devices.
67
//!
7-
//! # LowSpeed Example:
8+
//! The PWM controller can automatically increase or decrease the duty cycle
9+
//! gradually, allowing for fades without any processor interference.
10+
//!
11+
//! ## Configuration
12+
//!
13+
//! Currently only supports fixed-frequency output. High Speed channels are
14+
//! available for the ESP32 only, while Low Speed channels are available for all
15+
//! supported chips.
16+
//!
17+
//! ### Examples
18+
//!
19+
//! #### Low Speed Channel
820
//!
921
//! The following will configure the Low Speed Channel0 to 24kHz output with
1022
//! 10% duty using the ABPClock
@@ -47,7 +59,8 @@
4759
//! # }
4860
//! ```
4961
//!
50-
//! # Unsupported
62+
//! ## Unsupported
63+
//!
5164
//! - Source clock selection
5265
//! - Interrupts
5366

esp-hal/src/parl_io.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! # Parallel IO
22
//!
3-
//! ## Overview
43
//! The Parallel IO peripheral is a general purpose parallel interface that can
54
//! be used to connect to external devices such as LED matrix, LCD display,
65
//! Printer and Camera. The peripheral has independent TX and RX units. Each

esp-hal/src/uart.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Universal Asynchronous Receiver/Transmitter (UART)
1+
//! # Universal Asynchronous Receiver/Transmitter (UART)
22
//!
33
//! The UART is a hardware peripheral which handles communication using serial
44
//! communication interfaces, such as RS232 and RS485. This peripheral provides
@@ -15,8 +15,8 @@
1515
//!
1616
//! Each UART controller is individually configurable, and the usual setting
1717
//! such as baud rate, data bits, parity, and stop bits can easily be
18-
//! configured. Additionally, the transmit (TX) and receive (RX) pins can be
19-
//! specified.
18+
//! configured. Additionally, the transmit (TX) and receive (RX) pins need to
19+
//! be specified.
2020
//!
2121
//! ```rust, no_run
2222
#![doc = crate::before_snippet!()]
@@ -30,6 +30,10 @@
3030
//! # }
3131
//! ```
3232
//!
33+
//! The UART controller can be configured to invert the polarity of the pins.
34+
//! This is achived by inverting the desired pins, and then constucting the
35+
//! UART instance using the inverted pins.
36+
//!
3337
//! ## Usage
3438
//!
3539
//! The UART driver implements a number of third-party traits, with the
@@ -86,6 +90,33 @@
8690
//! # }
8791
//! ```
8892
//!
93+
//! #### Inverting TX and RX Pins
94+
//! ```rust, no_run
95+
#![doc = crate::before_snippet!()]
96+
//! # use esp_hal::uart::{config::Config, Uart};
97+
//! use esp_hal::gpio::{Io, any_pin::AnyPin};
98+
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
99+
//!
100+
//! let tx = AnyPin::new_inverted(io.pins.gpio1);
101+
//! let rx = AnyPin::new_inverted(io.pins.gpio2);
102+
//! let mut uart1 = Uart::new(peripherals.UART1, &clocks, tx, rx).unwrap();
103+
//! # }
104+
//! ```
105+
//!
106+
//! #### Constructing TX and RX Components
107+
//! ```rust, no_run
108+
#![doc = crate::before_snippet!()]
109+
//! # use esp_hal::uart::{config::Config, UartTx, UartRx};
110+
//! use esp_hal::gpio::{Io, any_pin::AnyPin};
111+
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
112+
//!
113+
//! let tx = UartTx::new(peripherals.UART0, &clocks, None,
114+
//! io.pins.gpio1).unwrap();
115+
//! let rx = UartRx::new(peripherals.UART1, &clocks, None,
116+
//! io.pins.gpio2).unwrap();
117+
//! # }
118+
//! ```
119+
//!
89120
//! [embedded-hal]: https://docs.rs/embedded-hal/latest/embedded_hal/
90121
//! [embedded-io]: https://docs.rs/embedded-io/latest/embedded_io/
91122
//! [embedded-hal-async]: https://docs.rs/embedded-hal-async/latest/embedded_hal_async/

hil-test/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Our self hosted runners have the following setup:
9292

9393
[`hil.yml`]: https://github.com/esp-rs/esp-hal/blob/main/.github/workflows/hil.yml
9494

95-
#### VM Setup
95+
#### RPi Setup
9696
```bash
9797
# Install Rust:
9898
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain stable -y --profile minimal
@@ -123,4 +123,5 @@ sudo reboot
123123
//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
124124
```
125125
If the test is supported by all the targets, you can omit the header.
126+
126127
6. Write some documentation at the top of the `tests/$PERIPHERAL.rs` file with the pins being used and the required connections, if applicable.

0 commit comments

Comments
 (0)