Skip to content

Commit

Permalink
Extract the esp-hal-smartled package (#429)
Browse files Browse the repository at this point in the history
* Extract the `esp-hal-smartled` package

This (finally) eliminates the `esp_hal_common::utils` module!

* Remove all references to the old `smartled` feature from CI
  • Loading branch information
jessebraham authored Mar 10, 2023
1 parent c1fa400 commit 5747dde
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 85 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
# Subsequent steps can just check the examples instead, as we're already
# confident that they link.
- name: check esp32-hal (common features)
run: cd esp32-hal/ && cargo check --examples --features=eh1,smartled,ufmt
run: cd esp32-hal/ && cargo check --examples --features=eh1,ufmt
- name: check esp32-hal (async)
run: cd esp32-hal/ && cargo check --example=embassy_hello_world --features=embassy,embassy-time-timg0
- name: check esp32-hal (async, gpio)
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
# Subsequent steps can just check the examples instead, as we're already
# confident that they link.
- name: check esp32c3-hal (common features)
run: cd esp32c3-hal/ && cargo check --examples --features=eh1,smartled,ufmt
run: cd esp32c3-hal/ && cargo check --examples --features=eh1,ufmt
- name: check esp32c3-hal (async, systick)
run: cd esp32c3-hal/ && cargo check --example=embassy_hello_world --features=embassy,embassy-time-systick
- name: check esp32c3-hal (async, timg0)
Expand Down Expand Up @@ -140,7 +140,7 @@ jobs:
# Subsequent steps can just check the examples instead, as we're already
# confident that they link.
- name: check esp32c6-hal (common features)
run: cd esp32c6-hal/ && cargo check --examples --features=eh1,smartled,ufmt
run: cd esp32c6-hal/ && cargo check --examples --features=eh1,ufmt
- name: check esp32c6-hal (async, systick)
run: cd esp32c6-hal/ && cargo check --example=embassy_hello_world --features=embassy,embassy-time-systick
- name: check esp32c6-hal (async, timg0)
Expand Down Expand Up @@ -169,7 +169,7 @@ jobs:
# Subsequent steps can just check the examples instead, as we're already
# confident that they link.
- name: check esp32s2-hal (common features)
run: cd esp32s2-hal/ && cargo check --examples --features=eh1,smartled,ufmt
run: cd esp32s2-hal/ && cargo check --examples --features=eh1,ufmt
# FIXME: `time-systick` feature disabled for now, see 'esp32s2-hal/Cargo.toml'.
# - name: check esp32s2-hal (async, systick)
# run: cd esp32s2-hal/ && cargo check --example=embassy_hello_world --features=embassy,embassy-time-systick
Expand Down Expand Up @@ -203,7 +203,7 @@ jobs:
# Subsequent steps can just check the examples instead, as we're already
# confident that they link.
- name: check esp32s3-hal (common features)
run: cd esp32s3-hal/ && cargo check --examples --features=eh1,smartled,ufmt
run: cd esp32s3-hal/ && cargo check --examples --features=eh1,ufmt
- name: check esp32s3-hal (async, systick)
run: cd esp32s3-hal/ && cargo check --example=embassy_hello_world --features=embassy,embassy-time-systick
- name: check esp32s3-hal (async, timg0)
Expand All @@ -230,9 +230,9 @@ jobs:
- name: msrv (esp32c2-hal)
run: cd esp32c2-hal/ && cargo check --features=eh1,ufmt
- name: msrv (esp32c3-hal)
run: cd esp32c3-hal/ && cargo check --features=eh1,ufmt,smartled
run: cd esp32c3-hal/ && cargo check --features=eh1,ufmt
- name: msrv (esp32c6-hal)
run: cd esp32c6-hal/ && cargo check --features=eh1,ufmt,smartled
run: cd esp32c6-hal/ && cargo check --features=eh1,ufmt

msrv-xtensa:
runs-on: ubuntu-latest
Expand All @@ -247,11 +247,11 @@ jobs:

# Verify the MSRV for all Xtensa chips.
- name: msrv (esp32-hal)
run: cd esp32-hal/ && cargo check --features=eh1,ufmt,smartled
run: cd esp32-hal/ && cargo check --features=eh1,ufmt
- name: msrv (esp32s2-hal)
run: cd esp32s2-hal/ && cargo check --features=eh1,ufmt,smartled
run: cd esp32s2-hal/ && cargo check --features=eh1,ufmt
- name: msrv (esp32s3-hal)
run: cd esp32s3-hal/ && cargo check --features=eh1,ufmt,smartled
run: cd esp32s3-hal/ && cargo check --features=eh1,ufmt

# --------------------------------------------------------------------------
# Lint
Expand Down Expand Up @@ -327,4 +327,4 @@ jobs:
- name: rustfmt (esp32s2-hal)
run: cargo fmt --all --manifest-path=esp32s2-hal/Cargo.toml -- --check
- name: rustfmt (esp32s3-hal)
run: cargo fmt --all --manifest-path=esp32s3-hal/Cargo.toml -- --check
run: cargo fmt --all --manifest-path=esp32s3-hal/Cargo.toml -- --check
6 changes: 0 additions & 6 deletions esp-hal-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ riscv-atomic-emulation-trap = { version = "0.4.0", optional = true }
xtensa-lx = { version = "0.8.0", optional = true }
xtensa-lx-rt = { version = "0.15.0", optional = true }

# Smart-LED (e.g., WS2812/SK68XX) support
smart-leds-trait = { version = "0.2.1", optional = true }

# Part of `ufmt` containing only `uWrite` trait
ufmt-write = { version = "0.1.0", optional = true }

Expand Down Expand Up @@ -76,9 +73,6 @@ esp32c2_26mhz = []
# Implement the `embedded-hal==1.0.0-alpha.x` traits
eh1 = ["embedded-hal-1", "embedded-hal-nb", "embedded-can"]

# To use the external `smart_led` crate
smartled = ["smart-leds-trait"]

# To support `ufmt`
ufmt = ["ufmt-write"]

Expand Down
2 changes: 0 additions & 2 deletions esp-hal-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ pub mod twai;
pub mod uart;
#[cfg(usb_serial_jtag)]
pub mod usb_serial_jtag;
#[cfg(rmt)]
pub mod utils;

/// State of the CPU saved when entering exception or interrupt
pub mod trapframe {
Expand Down
12 changes: 0 additions & 12 deletions esp-hal-common/src/utils/mod.rs

This file was deleted.

22 changes: 22 additions & 0 deletions esp-hal-smartled/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "esp-hal-smartled"
version = "0.1.0"
edition = "2021"
description = "RMT adapter for smartleds"
repository = "https://github.com/esp-rs/esp-hal"
license = "MIT OR Apache-2.0"

[dependencies]
esp-hal-common = { version = "0.7.1", features = [], path = "../esp-hal-common" }
fugit = "0.3.6"
smart-leds-trait = "0.2.1"

[features]
esp32 = ["esp-hal-common/esp32"]
esp32c3 = ["esp-hal-common/esp32c3"]
esp32c6 = ["esp-hal-common/esp32c6"]
esp32s2 = ["esp-hal-common/esp32s2"]
esp32s3 = ["esp-hal-common/esp32s3"]

esp32_26mhz = ["esp-hal-common/esp32_26mhz"]
esp32_40mhz = ["esp-hal-common/esp32_40mhz"]
27 changes: 27 additions & 0 deletions esp-hal-smartled/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# esp-hal-smartled

[![Crates.io](https://img.shields.io/crates/v/esp-hal-smartled?labelColor=1C2C2E&color=C96329&logo=Rust&style=flat-square)](https://crates.io/crates/esp-hal-smartled)
[![docs.rs](https://img.shields.io/docsrs/esp-hal-smartled?labelColor=1C2C2E&color=C96329&logo=rust&style=flat-square)](https://docs.rs/esp-hal-smartled)
![Crates.io](https://img.shields.io/crates/l/esp-hal-smartled?labelColor=1C2C2E&style=flat-square)
[![Matrix](https://img.shields.io/matrix/esp-rs:matrix.org?label=join%20matrix&labelColor=1C2C2E&color=BEC5C9&logo=matrix&style=flat-square)](https://matrix.to/#/#esp-rs:matrix.org)

This adapter allows for the use of an RMT output channel to easily interact with RGB LEDs and use the convenience functions of the [`smart-leds`](https://crates.io/crates/smart-leds) crate.

## [Documentation]

[documentation]: https://docs.rs/esp-hal-smartled/

## License

Licensed under either of:

- Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](../LICENSE-MIT) or http://opensource.org/licenses/MIT)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in
the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without
any additional terms or conditions.
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
//! # Smart-LEDs RMT Adapter
//!
//! This adapter allows for the use of an RMT output channel to easily interact
//! with RGB LEDs and use the convenience functions of the external
//! with RGB LEDs and use the convenience functions of the
//! [`smart-leds`](https://crates.io/crates/smart-leds) crate.
//!
//! _This is a simple implementation where every LED is adressed in an
//! individual RMT operation. This is working perfectly fine in blocking mode,
//! but in case this is used in combination with interrupts that might disturb
//! the sequential sending, an alternative implementation (addressing the LEDs
//! in a sequence in a single RMT send operation) might be required!_
#![no_std]
#![deny(missing_docs)]

use core::slice::IterMut;

use fugit::NanosDuration;
use smart_leds_trait::{SmartLedsWrite, RGB8};

#[cfg(any(esp32, esp32s2))]
use crate::pulse_control::ClockSource;
use crate::{
#[cfg(any(feature = "esp32", feature = "esp32s2"))]
use esp_hal_common::pulse_control::ClockSource;
use esp_hal_common::{
gpio::OutputPin,
peripheral::Peripheral,
pulse_control::{ConfiguredChannel, OutputChannel, PulseCode, RepeatMode, TransmissionError},
};
use fugit::NanosDuration;
use smart_leds_trait::{SmartLedsWrite, RGB8};

// Specifies what clock frequency we're using for the RMT peripheral (if
// properly configured)
//
// TODO: Factor in clock configuration, this needs to be revisited once #24 and
// #44 have been addressed.
#[cfg(esp32c3)]
#[cfg(feature = "esp32")]
const SOURCE_CLK_FREQ: u32 = 40_000_000;
#[cfg(esp32c6)]
#[cfg(feature = "esp32c3")]
const SOURCE_CLK_FREQ: u32 = 40_000_000;
#[cfg(esp32s2)]
#[cfg(feature = "esp32c6")]
const SOURCE_CLK_FREQ: u32 = 40_000_000;
#[cfg(esp32)]
#[cfg(feature = "esp32s2")]
const SOURCE_CLK_FREQ: u32 = 40_000_000;
#[cfg(esp32s3)]
#[cfg(feature = "esp32s3")]
const SOURCE_CLK_FREQ: u32 = 40_000_000;

const SK68XX_CODE_PERIOD: u32 = 1200;
Expand Down Expand Up @@ -101,14 +102,14 @@ where
where
UnconfiguredChannel: OutputChannel<ConfiguredChannel<'d, O> = CHANNEL>,
{
#[cfg(any(esp32c3, esp32c6, esp32s3))]
#[cfg(not(any(feature = "esp32", feature = "esp32s2")))]
channel
.set_idle_output_level(false)
.set_carrier_modulation(false)
.set_channel_divider(1)
.set_idle_output(true);

#[cfg(any(esp32, esp32s2))]
#[cfg(any(feature = "esp32", feature = "esp32s2"))]
channel
.set_idle_output_level(false)
.set_carrier_modulation(false)
Expand Down
3 changes: 3 additions & 0 deletions esp-hal.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
{
"path": "esp-hal-procmacros"
},
{
"path": "esp-hal-smartled"
},
{
"path": "esp32-hal"
},
Expand Down
26 changes: 11 additions & 15 deletions esp32-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ critical-section = "1.1.1"
embassy-executor = { package = "embassy-executor", git = "https://github.com/embassy-rs/embassy/", rev = "cd9a65b", features = ["nightly", "integrated-timers"] }
embedded-graphics = "0.7.1"
esp-backtrace = { version = "0.6.0", features = ["esp32", "panic-handler", "exception-handler", "print-uart"] }
esp-hal-smartled = { version = "0.1.0", features = ["esp32"], path = "../esp-hal-smartled" }
esp-println = { version = "0.3.1", features = ["esp32"] }
sha2 = { version = "0.10.6", default-features = false}
smart-leds = "0.3.0"
Expand All @@ -45,22 +46,17 @@ static_cell = "1.0.0"
aes = "0.8.2"

[features]
default = ["rt", "vectored", "xtal40mhz"]
bluetooth = []
eh1 = ["esp-hal-common/eh1", "dep:embedded-hal-1", "dep:embedded-hal-nb"]
rt = []
smartled = ["esp-hal-common/smartled"]
ufmt = ["esp-hal-common/ufmt"]
vectored = ["esp-hal-common/vectored"]
async = ["esp-hal-common/async", "embedded-hal-async"]
embassy = ["esp-hal-common/embassy"]
default = ["rt", "vectored", "xtal40mhz"]
bluetooth = []
eh1 = ["esp-hal-common/eh1", "dep:embedded-hal-1", "dep:embedded-hal-nb"]
rt = []
ufmt = ["esp-hal-common/ufmt"]
vectored = ["esp-hal-common/vectored"]
async = ["esp-hal-common/async", "embedded-hal-async"]
embassy = ["esp-hal-common/embassy"]
embassy-time-timg0 = ["esp-hal-common/embassy-time-timg0", "embassy-time/tick-hz-1_000_000"]
xtal40mhz = ["esp-hal-common/esp32_40mhz"]
xtal26mhz = ["esp-hal-common/esp32_26mhz"]

[[example]]
name = "hello_rgb"
required-features = ["smartled"]
xtal40mhz = ["esp-hal-common/esp32_40mhz"]
xtal26mhz = ["esp-hal-common/esp32_26mhz"]

[[example]]
name = "spi_eh1_loopback"
Expand Down
2 changes: 1 addition & 1 deletion esp32-hal/examples/hello_rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ use esp32_hal::{
peripherals,
prelude::*,
timer::TimerGroup,
utils::{smartLedAdapter, SmartLedsAdapter},
Delay,
PulseControl,
Rtc,
IO,
};
#[allow(unused_imports)]
use esp_backtrace as _;
use esp_hal_smartled::{smartLedAdapter, SmartLedsAdapter};
use smart_leds::{
brightness,
gamma,
Expand Down
6 changes: 1 addition & 5 deletions esp32c3-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ critical-section = "1.1.1"
embassy-executor = { package = "embassy-executor", git = "https://github.com/embassy-rs/embassy/", rev = "cd9a65b", features = ["nightly", "integrated-timers"] }
embedded-graphics = "0.7.1"
esp-backtrace = { version = "0.6.0", features = ["esp32c3", "panic-handler", "exception-handler", "print-uart"] }
esp-hal-smartled = { version = "0.1.0", features = ["esp32c3"], path = "../esp-hal-smartled" }
esp-println = { version = "0.3.1", features = ["esp32c3"] }
sha2 = { version = "0.10.6", default-features = false}
smart-leds = "0.3.0"
Expand All @@ -53,7 +54,6 @@ mcu-boot = []
direct-boot = []
eh1 = ["esp-hal-common/eh1", "dep:embedded-hal-1", "dep:embedded-hal-nb", "dep:embedded-can"]
rt = []
smartled = ["esp-hal-common/smartled"]
ufmt = ["esp-hal-common/ufmt"]
vectored = ["esp-hal-common/vectored"]
allow-opt-level-z = []
Expand All @@ -62,10 +62,6 @@ embassy = ["esp-hal-common/embassy"]
embassy-time-systick = ["esp-hal-common/embassy-time-systick", "embassy-time/tick-hz-16_000_000"]
embassy-time-timg0 = ["esp-hal-common/embassy-time-timg0", "embassy-time/tick-hz-1_000_000"]

[[example]]
name = "hello_rgb"
required-features = ["smartled"]

[[example]]
name = "spi_eh1_loopback"
required-features = ["eh1"]
Expand Down
2 changes: 1 addition & 1 deletion esp32c3-hal/examples/hello_rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ use esp32c3_hal::{
prelude::*,
pulse_control::ClockSource,
timer::TimerGroup,
utils::{smartLedAdapter, SmartLedsAdapter},
Delay,
PulseControl,
Rtc,
IO,
};
#[allow(unused_imports)]
use esp_backtrace as _;
use esp_hal_smartled::{smartLedAdapter, SmartLedsAdapter};
use smart_leds::{
brightness,
gamma,
Expand Down
6 changes: 1 addition & 5 deletions esp32c6-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ critical-section = "1.1.1"
embassy-executor = { package = "embassy-executor", git = "https://github.com/embassy-rs/embassy/", rev = "cd9a65b", features = ["nightly", "integrated-timers"] }
embedded-graphics = "0.7.1"
esp-backtrace = { version = "0.6.0", features = ["esp32c6", "panic-handler", "exception-handler", "print-uart"] }
esp-hal-smartled = { version = "0.1.0", features = ["esp32c6"], path = "../esp-hal-smartled" }
esp-println = { version = "0.4.0", features = ["esp32c6"] }
sha2 = { version = "0.10.6", default-features = false}
smart-leds = "0.3.0"
Expand All @@ -53,18 +54,13 @@ default = ["rt", "vectored"]
direct-boot = []
eh1 = ["esp-hal-common/eh1", "dep:embedded-hal-1", "dep:embedded-hal-nb", "dep:embedded-can"]
rt = []
smartled = ["esp-hal-common/smartled"]
ufmt = ["esp-hal-common/ufmt"]
vectored = ["esp-hal-common/vectored"]
async = ["esp-hal-common/async", "embedded-hal-async"]
embassy = ["esp-hal-common/embassy"]
embassy-time-systick = ["esp-hal-common/embassy-time-systick", "embassy-time/tick-hz-16_000_000"]
embassy-time-timg0 = ["esp-hal-common/embassy-time-timg0", "embassy-time/tick-hz-1_000_000"]

[[example]]
name = "hello_rgb"
required-features = ["smartled"]

[[example]]
name = "spi_eh1_loopback"
required-features = ["eh1"]
Expand Down
2 changes: 1 addition & 1 deletion esp32c6-hal/examples/hello_rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ use esp32c6_hal::{
prelude::*,
pulse_control::ClockSource,
timer::TimerGroup,
utils::{smartLedAdapter, SmartLedsAdapter},
Delay,
PulseControl,
Rtc,
IO,
};
use esp_backtrace as _;
use esp_hal_smartled::{smartLedAdapter, SmartLedsAdapter};
use smart_leds::{
brightness,
gamma,
Expand Down
Loading

0 comments on commit 5747dde

Please sign in to comment.