Skip to content

Commit

Permalink
update to [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankurte committed Apr 17, 2024
1 parent b0d5c73 commit 00fbee3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 30 deletions.
File renamed without changes.
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ description = "libusb based driver for the CP2130 USB-SPI bridge by Silicon Labs
repository = "https://github.com/ryankurte/rust-driver-cp2130"
keywords = [ "driver", "cp2130", "usb", "spi", "embedded" ]
license = "MPL-2.0"
edition = "2018"
edition = "2021"

[features]
util = [ "clap", "simplelog", "rand", "hex" ]
examples = []
default = [ "util" ]

[dependencies]
embedded-hal = { version = "1.0.0-rc.1" }
embedded-hal = { version = "1.0.0" }

libc = "0.2.66"
log = "0.4.8"
bitflags = "1.2.1"
byteorder = "1.3.2"
lazy_static = "1.4.0"
failure = "0.1.7"
thiserror = "1.0.58"
rusb = "0.9.0"

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

[dev-dependencies]
ssd1306 = "0.7.0"
embedded-graphics = "0.7.1"
linux-embedded-hal = "0.3.0"
embedded-hal-compat = "0.4.0"
ssd1306 = "0.8.4"
embedded-graphics = "0.8.1"
linux-embedded-hal = "0.4.0"
#embedded-hal-compat = "0.12.0"

[[bin]]
name = "cp2130-util"
Expand Down
5 changes: 3 additions & 2 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::str::FromStr;

use byteorder::{LE, BE, ByteOrder};
use bitflags::bitflags;
use log::{trace, debug, error};

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

Expand Down Expand Up @@ -155,7 +156,7 @@ pub(crate) struct Inner {
/// TODO: given it's one device this could all be hard-coded
#[derive(Debug)]
struct Endpoints {
control: Endpoint,
_control: Endpoint,
read: Endpoint,
write: Endpoint,
}
Expand Down Expand Up @@ -328,7 +329,7 @@ impl Inner {
handle.set_active_configuration(read.config)?;

// Build endpoints
let endpoints = Endpoints{control, write, read};
let endpoints = Endpoints{_control: control, write, read};
Ok((Inner{_device: device, handle, endpoints, gpio_allocated: [false; 11], spi_clock: SpiClock::Clock12Mhz}, info))
}
}
Expand Down
32 changes: 12 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@

use std::{sync::{Arc, Mutex}, time::{Instant, Duration}};

#[macro_use]
extern crate log;

#[macro_use]
extern crate lazy_static;

use failure::Fail;

pub use embedded_hal::spi::{Mode as SpiMode};
use rusb::{Device as UsbDevice, Context as UsbContext, DeviceDescriptor};

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


#[derive(Debug, Fail)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
// Io(IoError),
#[fail(display = "USB error: {:?}", 0)]
#[error("USB error: {0}")]
Usb(rusb::Error),

#[fail(display = "No matching endpoint languages found")]
#[error("No matching endpoint languages found")]
NoLanguages,

#[fail(display = "No valid endpoint configuration found")]
#[error("No valid endpoint configuration found")]
Configurations,
#[fail(display = "No matching endpoint found")]
#[error("No matching endpoint found")]
Endpoint,
#[fail(display = "GPIO pin already in use")]
#[error("GPIO pin already in use")]
GpioInUse,
#[fail(display = "Invalid SPI index")]
#[error("Invalid SPI index")]
InvalidIndex,
#[fail(display = "Invalid SPI baud rate")]
#[error("Invalid SPI baud rate")]
InvalidBaud,
}

Expand Down Expand Up @@ -200,9 +192,9 @@ impl embedded_hal::spi::SpiDevice<u8> for Spi {
SpiOp::Transfer(r, w) => self.transfer(r, w)?,
SpiOp::TransferInPlace(b) => self.transfer_in_place(b)?,
SpiOp::Read(r) => self.read(r)?,
SpiOp::DelayUs(us) => {
SpiOp::DelayNs(ns) => {
let now = Instant::now();
while now.elapsed() < Duration::from_micros(*us as u64) {}
while now.elapsed() < Duration::from_nanos(*ns as u64) {}
}
}
}
Expand Down Expand Up @@ -250,11 +242,11 @@ pub struct InputPin {
}

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

fn is_low(&self) -> Result<bool, Self::Error> {
fn is_low(&mut self) -> Result<bool, Self::Error> {
let v = self.is_high()?;
Ok(!v)
}
Expand Down
4 changes: 3 additions & 1 deletion src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ use std::num::ParseIntError;
#[cfg(feature = "clap")]
use clap::Parser;

use log::{trace, debug, error};

use crate::Error;
use crate::device::{VID, PID};

lazy_static!{
lazy_static::lazy_static!{
// LibUSB context created automagically
static ref CONTEXT: UsbContext = {
UsbContext::new().unwrap()
Expand Down

0 comments on commit 00fbee3

Please sign in to comment.