Skip to content

Commit 00fbee3

Browse files
committed
update to e-h@1.0.0
1 parent b0d5c73 commit 00fbee3

File tree

5 files changed

+25
-30
lines changed

5 files changed

+25
-30
lines changed
File renamed without changes.

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ description = "libusb based driver for the CP2130 USB-SPI bridge by Silicon Labs
66
repository = "https://github.com/ryankurte/rust-driver-cp2130"
77
keywords = [ "driver", "cp2130", "usb", "spi", "embedded" ]
88
license = "MPL-2.0"
9-
edition = "2018"
9+
edition = "2021"
1010

1111
[features]
1212
util = [ "clap", "simplelog", "rand", "hex" ]
1313
examples = []
1414
default = [ "util" ]
1515

1616
[dependencies]
17-
embedded-hal = { version = "1.0.0-rc.1" }
17+
embedded-hal = { version = "1.0.0" }
1818

1919
libc = "0.2.66"
2020
log = "0.4.8"
2121
bitflags = "1.2.1"
2222
byteorder = "1.3.2"
2323
lazy_static = "1.4.0"
24-
failure = "0.1.7"
24+
thiserror = "1.0.58"
2525
rusb = "0.9.0"
2626

2727
clap = { version = "4.4.7", optional = true, features = [ "derive", "env" ] }
@@ -30,10 +30,10 @@ hex = { version = "0.4.2", optional = true }
3030
rand = { version = "0.8.0", optional = true }
3131

3232
[dev-dependencies]
33-
ssd1306 = "0.7.0"
34-
embedded-graphics = "0.7.1"
35-
linux-embedded-hal = "0.3.0"
36-
embedded-hal-compat = "0.4.0"
33+
ssd1306 = "0.8.4"
34+
embedded-graphics = "0.8.1"
35+
linux-embedded-hal = "0.4.0"
36+
#embedded-hal-compat = "0.12.0"
3737

3838
[[bin]]
3939
name = "cp2130-util"

src/device.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::str::FromStr;
88

99
use byteorder::{LE, BE, ByteOrder};
1010
use bitflags::bitflags;
11+
use log::{trace, debug, error};
1112

1213
use rusb::{Device as UsbDevice, Context as UsbContext, DeviceDescriptor, DeviceHandle, Direction, TransferType};
1314

@@ -155,7 +156,7 @@ pub(crate) struct Inner {
155156
/// TODO: given it's one device this could all be hard-coded
156157
#[derive(Debug)]
157158
struct Endpoints {
158-
control: Endpoint,
159+
_control: Endpoint,
159160
read: Endpoint,
160161
write: Endpoint,
161162
}
@@ -328,7 +329,7 @@ impl Inner {
328329
handle.set_active_configuration(read.config)?;
329330

330331
// Build endpoints
331-
let endpoints = Endpoints{control, write, read};
332+
let endpoints = Endpoints{_control: control, write, read};
332333
Ok((Inner{_device: device, handle, endpoints, gpio_allocated: [false; 11], spi_clock: SpiClock::Clock12Mhz}, info))
333334
}
334335
}

src/lib.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@
55
66
use std::{sync::{Arc, Mutex}, time::{Instant, Duration}};
77

8-
#[macro_use]
9-
extern crate log;
10-
11-
#[macro_use]
12-
extern crate lazy_static;
13-
14-
use failure::Fail;
15-
168
pub use embedded_hal::spi::{Mode as SpiMode};
179
use rusb::{Device as UsbDevice, Context as UsbContext, DeviceDescriptor};
1810

@@ -24,24 +16,24 @@ pub use crate::device::{UsbOptions, GpioMode, GpioLevel, SpiConfig, SpiClock};
2416
use crate::device::*;
2517

2618

27-
#[derive(Debug, Fail)]
19+
#[derive(Debug, thiserror::Error)]
2820
pub enum Error {
2921
// Io(IoError),
30-
#[fail(display = "USB error: {:?}", 0)]
22+
#[error("USB error: {0}")]
3123
Usb(rusb::Error),
3224

33-
#[fail(display = "No matching endpoint languages found")]
25+
#[error("No matching endpoint languages found")]
3426
NoLanguages,
3527

36-
#[fail(display = "No valid endpoint configuration found")]
28+
#[error("No valid endpoint configuration found")]
3729
Configurations,
38-
#[fail(display = "No matching endpoint found")]
30+
#[error("No matching endpoint found")]
3931
Endpoint,
40-
#[fail(display = "GPIO pin already in use")]
32+
#[error("GPIO pin already in use")]
4133
GpioInUse,
42-
#[fail(display = "Invalid SPI index")]
34+
#[error("Invalid SPI index")]
4335
InvalidIndex,
44-
#[fail(display = "Invalid SPI baud rate")]
36+
#[error("Invalid SPI baud rate")]
4537
InvalidBaud,
4638
}
4739

@@ -200,9 +192,9 @@ impl embedded_hal::spi::SpiDevice<u8> for Spi {
200192
SpiOp::Transfer(r, w) => self.transfer(r, w)?,
201193
SpiOp::TransferInPlace(b) => self.transfer_in_place(b)?,
202194
SpiOp::Read(r) => self.read(r)?,
203-
SpiOp::DelayUs(us) => {
195+
SpiOp::DelayNs(ns) => {
204196
let now = Instant::now();
205-
while now.elapsed() < Duration::from_micros(*us as u64) {}
197+
while now.elapsed() < Duration::from_nanos(*ns as u64) {}
206198
}
207199
}
208200
}
@@ -250,11 +242,11 @@ pub struct InputPin {
250242
}
251243

252244
impl embedded_hal::digital::InputPin for InputPin {
253-
fn is_high(&self) -> Result<bool, Self::Error> {
245+
fn is_high(&mut self) -> Result<bool, Self::Error> {
254246
self.inner.lock().unwrap().get_gpio_level(self.index)
255247
}
256248

257-
fn is_low(&self) -> Result<bool, Self::Error> {
249+
fn is_low(&mut self) -> Result<bool, Self::Error> {
258250
let v = self.is_high()?;
259251
Ok(!v)
260252
}

src/manager.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ use std::num::ParseIntError;
1111
#[cfg(feature = "clap")]
1212
use clap::Parser;
1313

14+
use log::{trace, debug, error};
15+
1416
use crate::Error;
1517
use crate::device::{VID, PID};
1618

17-
lazy_static!{
19+
lazy_static::lazy_static!{
1820
// LibUSB context created automagically
1921
static ref CONTEXT: UsbContext = {
2022
UsbContext::new().unwrap()

0 commit comments

Comments
 (0)