update all esp-idf and embedded-svc deps, build and test

This commit is contained in:
Evan Feenstra
2023-04-03 14:30:28 -07:00
parent dcd6798504
commit dc468b4f30
18 changed files with 864 additions and 364 deletions

875
factory/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -8,11 +8,11 @@ edition = "2021"
pio = ["esp-idf-sys/pio"]
[dependencies]
esp-idf-sys = { version = "0.31.8", features = ["binstart"] }
esp-idf-svc = { version = "0.42.3", features = ["experimental", "alloc"] }
esp-idf-hal = "0.38.1"
esp-idf-sys = { version = "0.32.1", features = ["binstart"] }
esp-idf-svc = { version = "0.45.0", features = ["experimental", "alloc"] }
esp-idf-hal = "0.40.1"
embedded-svc = "0.24.0"
embedded-hal = "0.2.7"
embedded-svc = "0.22.1"
anyhow = { version = "1.0.65", features = ["backtrace"] }
rand = "0.8.5"
log = "0.4.17"

View File

@@ -1,33 +1,35 @@
use embedded_hal::blocking::delay::DelayMs;
use esp_idf_hal::delay::Ets;
use esp_idf_hal::delay::FreeRtos;
use esp_idf_hal::peripherals::Peripherals;
use esp_idf_hal::rmt::config::TransmitConfig;
use esp_idf_hal::rmt::{FixedLengthSignal, PinState, Pulse, Transmit};
use esp_idf_hal::rmt::*;
use std::time::Duration;
pub fn set_ota_led() {
pub fn set_ota_led() -> anyhow::Result<()> {
let peripherals = Peripherals::take().unwrap();
let led = peripherals.pins.gpio0.into_output().unwrap();
let led = peripherals.pins.gpio0;
let channel = peripherals.rmt.channel0;
let config = TransmitConfig::new().clock_divider(1);
let mut tx = Transmit::new(led, channel, &config).unwrap();
let mut tx = TxRmtDriver::new(channel, led, &config).unwrap();
let rgb = 0xffa500; // Orange
neopixel(
RGB {
r: 255,
g: 55,
b: 00,
},
&mut tx,
)?;
FreeRtos::delay_ms(10);
let ticks_hz = tx.counter_clock().unwrap();
let t0h = Pulse::new_with_duration(ticks_hz, PinState::High, &ns(350)).unwrap();
let t0l = Pulse::new_with_duration(ticks_hz, PinState::Low, &ns(800)).unwrap();
let t1h = Pulse::new_with_duration(ticks_hz, PinState::High, &ns(700)).unwrap();
let t1l = Pulse::new_with_duration(ticks_hz, PinState::Low, &ns(600)).unwrap();
Ok(())
}
let mut signal = FixedLengthSignal::<24>::new();
for i in 0..24 {
let bit = 2_u32.pow(i) & rotate_rgb(rgb) != 0;
let (high_pulse, low_pulse) = if bit { (t1h, t1l) } else { (t0h, t0l) };
signal.set(i as usize, &(high_pulse, low_pulse)).unwrap();
}
tx.start_blocking(&signal).unwrap();
Ets.delay_ms(10u8);
struct RGB {
r: u8,
g: u8,
b: u8,
}
fn ns(nanos: u64) -> Duration {
@@ -39,3 +41,26 @@ fn rotate_rgb(rgb: u32) -> u32 {
let blue = (rgb & b_mask) << 16;
blue | (rgb >> 8)
}
fn neopixel(rgb: RGB, tx: &mut TxRmtDriver) -> anyhow::Result<()> {
// e.g. rgb: (1,2,4)
// G R B
// 7 0 7 0 7 0
// 00000010 00000001 00000100
let color: u32 = ((rgb.g as u32) << 16) | ((rgb.r as u32) << 8) | rgb.b as u32;
let ticks_hz = tx.counter_clock()?;
let t0h = Pulse::new_with_duration(ticks_hz, PinState::High, &ns(350))?;
let t0l = Pulse::new_with_duration(ticks_hz, PinState::Low, &ns(800))?;
let t1h = Pulse::new_with_duration(ticks_hz, PinState::High, &ns(700))?;
let t1l = Pulse::new_with_duration(ticks_hz, PinState::Low, &ns(600))?;
let mut signal = FixedLengthSignal::<24>::new();
for i in (0..24).rev() {
let p = 2_u32.pow(i);
let bit = p & color != 0;
let (high_pulse, low_pulse) = if bit { (t1h, t1l) } else { (t0h, t0l) };
signal.set(23 - i as usize, &(high_pulse, low_pulse))?;
}
tx.start_blocking(&signal)?;
Ok(())
}

View File

@@ -1,5 +1,5 @@
use bitflags::bitflags;
use esp_idf_sys::c_types::c_char;
use core::ffi::c_char;
use esp_idf_sys::{
esp, esp_vfs_fat_sdmmc_mount_config_t, esp_vfs_fat_sdspi_mount, gpio_num_t, sdmmc_card_t,
sdmmc_host_t, sdspi_device_config_t, spi_bus_config_t, spi_bus_initialize, spi_host_device_t,