Skip to content

Commit

Permalink
bm13xx-chain: impl poll_response() and use it in enumerate()
Browse files Browse the repository at this point in the history
  • Loading branch information
Georges760 committed Jan 5, 2025
1 parent 0311183 commit 87ca98b
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 77 deletions.
8 changes: 4 additions & 4 deletions bm1366/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,18 +458,18 @@ impl Asic for BM1366 {
BM1366_CHIP_ID
}

/// ## Has Version Rolling in chip
/// ## Is Hardware Version Rolling enabled
///
/// ### Example
/// ```
/// use bm1366::BM1366;
/// use bm13xx_asic::Asic;
///
/// let bm1366 = BM1366::default();
/// assert!(bm1366.has_version_rolling());
/// assert!(!bm1366.version_rolling_enabled());
/// ```
fn has_version_rolling(&self) -> bool {
true
fn version_rolling_enabled(&self) -> bool {
self.version_rolling_enabled
}

/// ## Init the Chip command list
Expand Down
8 changes: 4 additions & 4 deletions bm1370/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,18 +487,18 @@ impl Asic for BM1370 {
BM1370_CHIP_ID
}

/// ## Has Version Rolling in chip
/// ## Is Hardware Version Rolling enabled
///
/// ### Example
/// ```
/// use bm1370::BM1370;
/// use bm13xx_asic::Asic;
///
/// let bm1370 = BM1370::default();
/// assert!(bm1370.has_version_rolling());
/// assert!(!bm1370.version_rolling_enabled());
/// ```
fn has_version_rolling(&self) -> bool {
true
fn version_rolling_enabled(&self) -> bool {
self.version_rolling_enabled
}

/// ## Init the Chip command list
Expand Down
6 changes: 3 additions & 3 deletions bm1397/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,17 +365,17 @@ impl Asic for BM1397 {
BM1397_CHIP_ID
}

/// ## Has Version Rolling in chip
/// ## Is Hardware Version Rolling enabled
///
/// ### Example
/// ```
/// use bm1397::BM1397;
/// use bm13xx_asic::Asic;
///
/// let bm1397 = BM1397::default();
/// assert!(!bm1397.has_version_rolling());
/// assert!(!bm1397.version_rolling_enabled());
/// ```
fn has_version_rolling(&self) -> bool {
fn version_rolling_enabled(&self) -> bool {
false
}

Expand Down
2 changes: 1 addition & 1 deletion bm13xx-asic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum SequenceStep {
pub trait Asic {
fn reset(&mut self);
fn chip_id(&self) -> u16;
fn has_version_rolling(&self) -> bool;
fn version_rolling_enabled(&self) -> bool;
fn init_next(&mut self, diffculty: u32) -> Option<CmdDelay>;
fn set_baudrate_next(
&mut self,
Expand Down
10 changes: 8 additions & 2 deletions bm13xx-chain/examples/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ async fn main() -> Result<(), Box<dyn Error>> {

let builder = tokio_serial::new(port, 115_200).timeout(Duration::from_millis(50));
let serial = SerialStream::open(&builder)?;
let adapter = FromTokio::new(serial);
let uart = FromTokio::new(serial);

let bm1366 = BM1366::default();
let fake_busy = SysfsPin::new(127);
let fake_reset = SysfsPin::new(128);

let mut chain = Chain::new(1, bm1366, 1, adapter, fake_busy, fake_reset, Delay);
let mut chain = Chain::new(1, bm1366, 1, uart, fake_busy, fake_reset, Delay);
chain.enumerate().await?;
println!("Enumerated {} asics", chain.asic_cnt);
println!("Interval: {}", chain.asic_addr_interval);
Expand Down Expand Up @@ -99,6 +99,12 @@ mod tokio_adapter {
type Error = std::io::Error;
}

impl<T: tokio::io::AsyncRead + Unpin + ?Sized> embedded_io_async::ReadReady for FromTokio<T> {
fn read_ready(&mut self) -> Result<bool, Self::Error> {
Ok(true) // TODO: fix this
}
}

impl<T: tokio::io::AsyncRead + Unpin + ?Sized> embedded_io_async::Read for FromTokio<T> {
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
// The current tokio implementation (https://github.com/tokio-rs/tokio/blob/tokio-1.33.0/tokio/src/io/poll_evented.rs#L165)
Expand Down
4 changes: 2 additions & 2 deletions bm13xx-chain/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bm13xx_asic::register::ChipIdentification;
use bm13xx_protocol::response::RegisterResponse;
use bm13xx_protocol::response::{RegisterResponse, ResponseType};
use derive_more::From;

pub type Result<T, IO, G> = core::result::Result<T, Error<IO, G>>;
Expand All @@ -8,7 +8,7 @@ pub type Result<T, IO, G> = core::result::Result<T, Error<IO, G>>;
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
pub enum Error<IO, G> {
/// We received a response from ASIC which does not correspond to the command sent
UnexpectedResponse { resp: [u8; 9] },
UnexpectedResponse { resp: ResponseType },
/// We received a register response which does not correspond to the register read command
BadRegisterResponse { reg_resp: RegisterResponse },
/// We enumerated an ASIC which does not correspond to the chip we are looking for
Expand Down
Loading

0 comments on commit 87ca98b

Please sign in to comment.