• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eldruin / mcp4x-rs / 12241440399

09 Dec 2024 05:57PM UTC coverage: 74.227% (-25.8%) from 100.0%
12241440399

Pull #4

github

web-flow
Merge 7eae9cc67 into 6701d772e
Pull Request #4: Support for MCP4017/18/19 I2C potentiometers

17 of 36 new or added lines in 2 files covered. (47.22%)

6 existing lines in 1 file now uncovered.

72 of 97 relevant lines covered (74.23%)

4.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.0
/src/interface.rs
1
//! SPI interface
2

3
use crate::{private, Command, Error};
4
use embedded_hal::i2c::I2c;
5
use embedded_hal::spi::SpiDevice;
6

7
/// SPI interface
8
#[derive(Debug, Default)]
9
pub struct SpiInterface<SPI> {
10
    pub(crate) spi: SPI,
11
}
12

13
/// I2C interface
14
#[derive(Debug, Default)]
15
pub struct I2cInterface<I2C> {
16
    pub(crate) i2c: I2C,
17
}
18

19
/// Perform a command
20
pub trait WriteCommand: private::Sealed {
21
    /// Error type
22
    type Error;
23

24
    /// Command
25
    fn write_command(&mut self, command: Command) -> Result<(), Self::Error>;
26
}
27

28
impl<SPI, E> WriteCommand for SpiInterface<SPI>
29
where
30
    SPI: SpiDevice<Error = E>,
31
{
32
    type Error = Error<E>;
33

34
    fn write_command(&mut self, command: Command) -> Result<(), Self::Error> {
10✔
35
        let payload: [u8; 2] = [command.get_command_byte(), command.get_data_byte()];
10✔
36
        self.spi.write(&payload).map_err(Error::Comm)
10✔
37
    }
10✔
38
}
39

40
impl<I2C, E> WriteCommand for I2cInterface<I2C>
41
where
42
    I2C: I2c<Error = E>,
43
{
44
    type Error = Error<E>;
45

NEW
46
    fn write_command(&mut self, command: Command) -> Result<(), Self::Error> {
×
47
        const ADDRESS: u8 = 0b0101111;
NEW
48
        match command {
×
NEW
49
            Command::SetPosition(_, position) => {
×
NEW
50
                self.i2c.write(ADDRESS, &[position]).map_err(Error::Comm)
×
51
            }
NEW
52
            Command::Shutdown(_) => Err(Error::Unsupported),
×
53
        }
NEW
54
    }
×
55
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc