Skip to content

Commit 16ccca4

Browse files
authored
Merge pull request #58 from eldruin/improve-docs
Improve docs
2 parents b6b4065 + 36bb001 commit 16ccca4

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

src/core.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::error::Error;
1515
/// in use and the address of the slave device. The trait is based on the
1616
/// Linux i2cdev interface.
1717
pub trait I2CDevice {
18+
/// Error type
1819
type Error: Error;
1920

2021
/// Read data from the device to fill the provided slice
@@ -128,12 +129,14 @@ pub trait I2CDevice {
128129
/// Typical implementations will store state with references to the bus
129130
/// in use. The trait is based on the Linux i2cdev interface.
130131
pub trait I2CTransfer<'a> {
132+
/// I2C transfer error type
131133
type Error: Error;
134+
/// I2C transfer message type
132135
type Message: I2CMessage<'a>;
133136

134-
// Performs multiple serially chained I2C read/write transactions. On
135-
// success the return code is the number of successfully executed
136-
// transactions
137+
/// Performs multiple serially chained I2C read/write transactions. On
138+
/// success the return code is the number of successfully executed
139+
/// transactions
137140
fn transfer(&mut self, msgs: &'a mut [Self::Message]) -> Result<u32, Self::Error>;
138141
}
139142

src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
9797
#![crate_name = "i2cdev"]
9898
#![crate_type = "lib"]
99+
#![deny(missing_docs)]
99100

100101
#[macro_use]
101102
extern crate bitflags;
@@ -107,8 +108,12 @@ extern crate nix;
107108
#[cfg(any(target_os = "linux", target_os = "android"))]
108109
mod ffi;
109110

111+
/// Core I2C abstractions
110112
pub mod core;
111113

114+
/// Linux I2C device support
112115
#[cfg(any(target_os = "linux", target_os = "android"))]
113116
pub mod linux;
117+
118+
/// Mock I2C device
114119
pub mod mock;

src/linux.rs

+7
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,23 @@ use std::path::Path;
2121
// Expose these core structs from this module
2222
pub use core::I2CMessage;
2323

24+
/// Concrete linux I2C device
2425
pub struct LinuxI2CDevice {
2526
devfile: File,
2627
slave_address: u16,
2728
}
2829

30+
/// Linux I2C bus
2931
pub struct LinuxI2CBus {
3032
devfile: File,
3133
}
3234

35+
/// Linux I2C errors
3336
#[derive(Debug)]
3437
pub enum LinuxI2CError {
38+
/// OS error
3539
Nix(nix::Error),
40+
/// Input/output error
3641
Io(io::Error),
3742
}
3843

@@ -322,6 +327,7 @@ impl<'a> I2CMessage<'a> for LinuxI2CMessage<'a> {
322327
}
323328

324329
impl<'a> LinuxI2CMessage<'a> {
330+
/// Set the target device address for the message
325331
pub fn with_address(self, slave_address: u16) -> Self {
326332
Self {
327333
addr: slave_address,
@@ -331,6 +337,7 @@ impl<'a> LinuxI2CMessage<'a> {
331337
}
332338
}
333339

340+
/// Set optional message flags
334341
pub fn with_flags(self, flags: I2CMessageFlags) -> Self {
335342
Self {
336343
addr: self.addr,

src/mock.rs

+8
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
use core::{I2CDevice, I2CMessage, I2CTransfer};
99
use std::io;
1010

11+
/// I2C mock result type
1112
pub type I2CResult<T> = io::Result<T>;
1213

14+
/// Mock I2C device register map
1315
pub struct I2CRegisterMap {
1416
registers: [u8; 0xFF],
1517
offset: usize,
@@ -22,13 +24,15 @@ impl Default for I2CRegisterMap {
2224
}
2325

2426
impl I2CRegisterMap {
27+
/// Create new mock I2C register map
2528
pub fn new() -> I2CRegisterMap {
2629
I2CRegisterMap {
2730
registers: [0x00; 0xFF],
2831
offset: 0,
2932
}
3033
}
3134

35+
/// Set several registers starting at the given offset
3236
pub fn write_regs(&mut self, offset: usize, data: &[u8]) {
3337
println!("WRITE | 0x{:X} : {:?}", offset, data);
3438
self.registers[offset..(data.len() + offset)].clone_from_slice(&data);
@@ -56,12 +60,15 @@ impl I2CRegisterMap {
5660
}
5761
}
5862

63+
/// Mock I2C device exposing a register map
5964
#[derive(Default)]
6065
pub struct MockI2CDevice {
66+
/// I2C register map
6167
pub regmap: I2CRegisterMap,
6268
}
6369

6470
impl MockI2CDevice {
71+
/// Create a new mock I2C device
6572
pub fn new() -> MockI2CDevice {
6673
MockI2CDevice {
6774
regmap: I2CRegisterMap::new(),
@@ -111,6 +118,7 @@ enum MessageType<'a> {
111118
Read(&'a mut [u8]),
112119
}
113120

121+
/// Mock I2C message
114122
pub struct MockI2CMessage<'a> {
115123
msg_type: MessageType<'a>,
116124
}

0 commit comments

Comments
 (0)