Skip to content

Commit

Permalink
refactor by clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
cat-in-136 committed Jul 3, 2023
1 parent b296180 commit 6aea86a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
16 changes: 12 additions & 4 deletions src/driver/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,18 @@ impl<
#[inline]
fn new_with_rgbw(r: u8, g: u8, b: u8, w: u8) -> Self {
let mut array = [0; N];
array.get_mut(R_ORDER).and_then(|v| Some(*v = r));
array.get_mut(G_ORDER).and_then(|v| Some(*v = g));
array.get_mut(B_ORDER).and_then(|v| Some(*v = b));
array.get_mut(W_ORDER).and_then(|v| Some(*v = w));
if let Some(v) = array.get_mut(R_ORDER) {
*v = r;
}
if let Some(v) = array.get_mut(G_ORDER) {
*v = g;
}
if let Some(v) = array.get_mut(B_ORDER) {
*v = b;
}
if let Some(v) = array.get_mut(W_ORDER) {
*v = w;
}
Self(array)
}

Expand Down
14 changes: 7 additions & 7 deletions src/driver/esp32_rmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ impl Ws2812Esp32RmtItemEncoder {
let mut clock_hz = 0u32;
esp!(unsafe { rmt_get_counter_clock(channel, &mut clock_hz as *mut u32) })?;
let clock_hz = clock_hz as u64;
let to0h_clk = ((WS2812_TO0H_NS as u64) * clock_hz.clone() / 1000_000_000) as u32;
let to0l_clk = ((WS2812_TO0L_NS as u64) * clock_hz.clone() / 1000_000_000) as u32;
let to1h_clk = ((WS2812_TO1H_NS as u64) * clock_hz.clone() / 1000_000_000) as u32;
let to1l_clk = ((WS2812_TO1L_NS as u64) * clock_hz.clone() / 1000_000_000) as u32;
let bit0 = to0h_clk | (1 << 15) | (to0l_clk << 16) | (0 << 31);
let bit1 = to1h_clk | (1 << 15) | (to1l_clk << 16) | (0 << 31);
let to0h_clk = ((WS2812_TO0H_NS as u64) * clock_hz / 1_000_000_000) as u32;
let to0l_clk = ((WS2812_TO0L_NS as u64) * clock_hz / 1_000_000_000) as u32;
let to1h_clk = ((WS2812_TO1H_NS as u64) * clock_hz / 1_000_000_000) as u32;
let to1l_clk = ((WS2812_TO1L_NS as u64) * clock_hz / 1_000_000_000) as u32;
let bit0 = to0h_clk | (1 << 15) | (to0l_clk << 16);
let bit1 = to1h_clk | (1 << 15) | (to1l_clk << 16);
Ok(Self { bit0, bit1 })
}

Expand Down Expand Up @@ -58,7 +58,7 @@ unsafe extern "C" fn ws2812_rmt_adapter(
return;
}

let src_len = min(src_size, wanted_num / 8) as usize;
let src_len = min(src_size, wanted_num / 8);
let src_slice = std::slice::from_raw_parts(src as *const u8, src_len);
let dest_slice = std::slice::from_raw_parts_mut(dest, src_slice.len() * 8);

Expand Down

0 comments on commit 6aea86a

Please sign in to comment.