Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
Make sure the docs.rs documentation shows the features required for the
various backend. Also fix some doc lint issue due to better
autoresolving in rustdoc
  • Loading branch information
sjoerdsimons committed Oct 19, 2024
1 parent 7c6bcbf commit 4dd4641
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@1.81
- run: cargo test --all-targets --all-features
- run: cargo test --docs --all-features

fmt:
name: cargo fmt
Expand All @@ -33,7 +34,7 @@ jobs:
- uses: dtolnay/rust-toolchain@1.81
with:
components: clippy
- run: cargo clippy --all-targets -- -D warnings
- run: cargo clippy --all-targets --all-features -- -D warnings

allgreen:
if: always()
Expand Down
4 changes: 4 additions & 0 deletions rockusb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ futures = { version = "0.3.31", features = ["compat", "io-compat"]}
tokio-util = { version = "0.7.12", features = ["compat"] }
async-compression = { version = "0.4.5", features = ["gzip", "futures-io"] }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[[example]]
name="rockusb"
required-features = ["libusb"]
Expand Down
32 changes: 23 additions & 9 deletions rockusb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,29 @@

Rockchip bootroms and early loaders implement an USB protocol to help loader
early firmware, flashing persistant storage etc. This crate contains a sans-io
implementation of that protocol as well as an optional (enabled by default)
implementation of IO using libusb
implementation of that protocol as well as an optional implementations of IO
using libusb or nusb.

Printing chip info using libusb backend:
```rust,no_run
fn main() -> anyhow::Result<()> {
let devices = rockusb::libusb::Devices::new()?;
let mut transport = devices.iter().next()
.ok_or_else(|| anyhow::anyhow!("No Device found"))??;
println!("Chip Info: {:0x?}", transport.chip_info()?);
Ok(())
}
# fn main() -> anyhow::Result<()> {
let devices = rockusb::libusb::Devices::new()?;
let mut transport = devices.iter().next()
.ok_or_else(|| anyhow::anyhow!("No Device found"))??;
println!("Chip Info: {:0x?}", transport.chip_info()?);
Ok(())
# }
```

Printing chip info using nusb backend:
```rust,no_run
# #[tokio::main]
# async fn main() -> anyhow::Result<()> {
let mut devices = rockusb::nusb::devices()?;
let info = devices.next()
.ok_or_else(|| anyhow::anyhow!("No Device found"))?;
let mut transport = rockusb::nusb::Transport::from_usb_device_info(info)?;
println!("Chip Info: {:0x?}", transport.chip_info().await?);
Ok(())
# }
```
3 changes: 2 additions & 1 deletion rockusb/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc = include_str!("../README.md")]

/// libusb transport implementation
Expand All @@ -6,7 +7,7 @@ pub mod libusb;
/// nusb transport implementation
#[cfg(feature = "nusb")]
pub mod nusb;
/// sans-io protocol implementationsss
/// sans-io protocol implementations
///
/// This module contains all protocol logic; Each operation implements the [operation::OperationSteps]
/// trait which gives a transport a series of [operation::UsbStep] to execute to complete an
Expand Down
19 changes: 9 additions & 10 deletions rockusb/src/libusb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ impl Transport {
})
}

/// Create an IO object which implements [Read](std::io::Read), [Write](std::io::Write) and
/// [Seek](std::io::Seek)
/// Create an IO object which implements [Read], [Write] and
/// [Seek]
pub fn io(&mut self) -> Result<TransportIO<&mut Self>> {
TransportIO::new(self)
}

/// Convert into an IO object which implements [Read](std::io::Read), [Write](std::io::Write) and
/// [Seek](std::io::Seek)
/// Convert into an IO object which implements [Read], [Write] and
/// [Seek]
pub fn into_io(self) -> Result<TransportIO<Self>> {
TransportIO::new(self)
}
Expand Down Expand Up @@ -230,17 +230,17 @@ impl Transport {

/// read from the flash
///
/// start_sector with [SECTOR_SIZE](crate::protocol::SECTOR_SIZE) sectors. the data to be read
/// must be a multiple of [SECTOR_SIZE](crate::protocol::SECTOR_SIZE) bytes
/// start_sector with [SECTOR_SIZE] sectors. the data to be read
/// must be a multiple of [SECTOR_SIZE] bytes
pub fn read_lba(&mut self, start_sector: u32, read: &mut [u8]) -> Result<u32> {
self.handle_operation(crate::operation::read_lba(start_sector, read))
.map(|t| t.into())
}

/// Create operation to read an lba from the flash
///
/// start_sector based on [SECTOR_SIZE](crate::protocol::SECTOR_SIZE) sectors. the data to be
/// written must be a multiple of [SECTOR_SIZE](crate::protocol::SECTOR_SIZE) bytes
/// start_sector based on [SECTOR_SIZE] sectors. the data to be
/// written must be a multiple of [SECTOR_SIZE] bytes
pub fn write_lba(&mut self, start_sector: u32, write: &[u8]) -> Result<u32> {
self.handle_operation(crate::operation::write_lba(start_sector, write))
.map(|t| t.into())
Expand All @@ -258,8 +258,7 @@ impl Transport {
}
}

/// IO object which implements [Read](std::io::Read), [Write](std::io::Write) and
/// [Seek](std::io::Seek)
/// IO object which implements [Read], [Write] and [Seek]
pub struct TransportIO<T> {
transport: T,
size: u64,
Expand Down
15 changes: 7 additions & 8 deletions rockusb/src/nusb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ impl Transport {
})
}

/// Convert into an IO object which implements [AsyncRead](futures::io::AsyncRead),
/// [AsyncWrite](futures::io::AsyncWrite) and [AsyncSeek](futures::io::AsyncSeek)
/// Convert into an IO object which implements [AsyncRead],
/// [AsyncWrite] and [AsyncSeek]
pub async fn into_io(self) -> Result<TransportIO> {
TransportIO::new(self).await
}
Expand Down Expand Up @@ -178,8 +178,8 @@ impl Transport {

/// read from the flash
///
/// start_sector with [SECTOR_SIZE](crate::protocol::SECTOR_SIZE) sectors. the data to be read
/// must be a multiple of [SECTOR_SIZE](crate::protocol::SECTOR_SIZE) bytes
/// start_sector with [SECTOR_SIZE] sectors. the data to be read
/// must be a multiple of [SECTOR_SIZE] bytes
pub async fn read_lba(&mut self, start_sector: u32, read: &mut [u8]) -> Result<u32> {
self.handle_operation(crate::operation::read_lba(start_sector, read))
.await
Expand All @@ -188,8 +188,8 @@ impl Transport {

/// Create operation to read an lba from the flash
///
/// start_sector based on [SECTOR_SIZE](crate::protocol::SECTOR_SIZE) sectors. the data to be
/// written must be a multiple of [SECTOR_SIZE](crate::protocol::SECTOR_SIZE) bytes
/// start_sector based on [SECTOR_SIZE] sectors. the data to be
/// written must be a multiple of [SECTOR_SIZE] bytes
pub async fn write_lba(&mut self, start_sector: u32, write: &[u8]) -> Result<u32> {
self.handle_operation(crate::operation::write_lba(start_sector, write))
.await
Expand Down Expand Up @@ -228,8 +228,7 @@ struct TransportIOInner {
state: BufferState,
}

/// IO object which implements [AsyncRead](futures::io::AsyncRead),
/// [AsyncWrite](futures::io::AsyncWrite) and [AsyncSeek](futures::io::AsyncSeek)
/// IO object which implements [AsyncRead], [AsyncWrite] and [AsyncSeek]
pub struct TransportIO {
// io execution state
io_state: IoState,
Expand Down

0 comments on commit 4dd4641

Please sign in to comment.