Skip to content

Commit

Permalink
Merge pull request #28 from cat-in-136/embedded-graphics-0.8
Browse files Browse the repository at this point in the history
Upgrade to embedded graphics 0.8
  • Loading branch information
cat-in-136 authored Jul 10, 2023
2 parents 49e992b + 6aea86a commit 49fbb34
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:

steps:
- name: Install Rust for Xtensa
uses: esp-rs/xtensa-toolchain@v1.2
uses: esp-rs/xtensa-toolchain@v1.5
with:
default: true
version: "1.60.0"
version: "1.70.0"
ldproxy: true
- uses: actions/checkout@v3
with:
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ unstable = []

[dependencies]
smart-leds-trait = { version = "0.2", optional = true }
embedded-graphics-core = { version = "0.3", optional = true }
embedded-graphics-core = { version = "0.4", optional = true }
once_cell = "1"
thiserror = "1"

Expand All @@ -26,10 +26,10 @@ esp-idf-sys = { version = ">=0.32", features = ["binstart"] }

[dev-dependencies]
smart-leds = "0.3"
embedded-graphics = "0.7"
embedded-graphics = "0.8"

[build-dependencies]
embuild = "0.30"
embuild = "0.31"
anyhow = "1"

[profile.release]
Expand Down
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 49fbb34

Please sign in to comment.