LEDs write correctly and mulitcore now
This commit is contained in:
parent
040c0fd353
commit
d581195df7
@ -1,5 +1,5 @@
|
||||
[alias]
|
||||
esp32 = "run --release --features=esp32 --target=xtensa-esp32-none-elf"
|
||||
esp32 = "run --release --features=esp32 --target=xtensa-esp32-none-elf"
|
||||
esp32c2 = "run --release --features=esp32c2 --target=riscv32imc-unknown-none-elf"
|
||||
esp32c3 = "run --release --features=esp32c3 --target=riscv32imc-unknown-none-elf"
|
||||
esp32c6 = "run --release --features=esp32c6 --target=riscv32imac-unknown-none-elf"
|
||||
@ -8,18 +8,17 @@ esp32s2 = "run --release --features=esp32s2 --target=xtensa-esp32s2-none-elf"
|
||||
esp32s3 = "run --release --features=esp32s3 --target=xtensa-esp32s3-none-elf"
|
||||
|
||||
[target.'cfg(target_arch = "riscv32")']
|
||||
runner = "espflash flash --monitor"
|
||||
rustflags = [
|
||||
"-C", "link-arg=-Tlinkall.x",
|
||||
"-C", "force-frame-pointers",
|
||||
]
|
||||
runner = "espflash flash --monitor"
|
||||
rustflags = ["-C", "link-arg=-Tlinkall.x", "-C", "force-frame-pointers"]
|
||||
|
||||
[target.'cfg(target_arch = "xtensa")']
|
||||
runner = "espflash flash --monitor"
|
||||
runner = "espflash flash --monitor"
|
||||
rustflags = [
|
||||
# GNU LD
|
||||
"-C", "link-arg=-Wl,-Tlinkall.x",
|
||||
"-C", "link-arg=-nostartfiles",
|
||||
"-C",
|
||||
"link-arg=-Wl,-Tlinkall.x",
|
||||
"-C",
|
||||
"link-arg=-nostartfiles",
|
||||
|
||||
# LLD
|
||||
# "-C", "link-arg=-Tlinkall.x",
|
||||
@ -28,8 +27,9 @@ rustflags = [
|
||||
|
||||
[env]
|
||||
ESP_LOG = "info"
|
||||
SSID = "SSID"
|
||||
PASSWORD = "PASSWORD"
|
||||
SSID = "925511496560803"
|
||||
PASSWORD = ")~Y!zEycpx=gPeE0D%\\y<B.TpW2`JQTYKaj8H/l$cP%f$f^;V<9O?_wd}"
|
||||
CLIENT_ID = "1234"
|
||||
STATIC_IP = "1.1.1.1 "
|
||||
GATEWAY_IP = "1.1.1.1"
|
||||
HOST_IP = "1.1.1.1"
|
||||
|
||||
@ -1,80 +1,156 @@
|
||||
[package]
|
||||
name = "examples"
|
||||
name = "examples"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
license = "MIT OR Apache-2.0"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
aligned = { version = "0.4.2", optional = true }
|
||||
bleps = { git = "https://github.com/bjoernQ/bleps", package = "bleps", rev = "a5148d8ae679e021b78f53fd33afb8bb35d0b62e", features = [ "macros", "async"] }
|
||||
aligned = { version = "0.4.2", optional = true }
|
||||
bleps = { git = "https://github.com/bjoernQ/bleps", package = "bleps", rev = "a5148d8ae679e021b78f53fd33afb8bb35d0b62e", features = [
|
||||
"macros",
|
||||
"async",
|
||||
] }
|
||||
blocking-network-stack = { git = "https://github.com/bjoernQ/blocking-network-stack.git", rev = "b3ecefc222d8806edd221f266999ca339c52d34e" }
|
||||
bt-hci = "0.1.1"
|
||||
cfg-if = "1.0.0"
|
||||
critical-section = "1.1.3"
|
||||
embassy-executor = { version = "0.6.0", features = ["task-arena-size-20480"] }
|
||||
embassy-futures = "0.1.1"
|
||||
embassy-net = { version = "0.5.0", features = [ "tcp", "udp", "dhcpv4", "medium-ethernet"] }
|
||||
embassy-sync = "0.6.0"
|
||||
embassy-time = "0.3.2"
|
||||
embassy-usb = { version = "0.2.0", default-features = false }
|
||||
embedded-can = "0.4.1"
|
||||
embedded-hal-async = "1.0.0"
|
||||
embedded-io = { version = "0.6.1", default-features = false }
|
||||
embedded-io-async = "0.6.1"
|
||||
embedded-storage = "0.3.1"
|
||||
esp-alloc = { path = "../esp-alloc" }
|
||||
esp-backtrace = { path = "../esp-backtrace", features = ["exception-handler", "panic-handler", "println"] }
|
||||
esp-hal = { path = "../esp-hal", features = ["log"] }
|
||||
esp-hal-embassy = { path = "../esp-hal-embassy", optional = true }
|
||||
esp-ieee802154 = { path = "../esp-ieee802154", optional = true }
|
||||
esp-println = { path = "../esp-println", features = ["log"] }
|
||||
esp-storage = { path = "../esp-storage", optional = true }
|
||||
esp-wifi = { path = "../esp-wifi", features = ["log"], optional = true }
|
||||
fugit = "0.3.7"
|
||||
heapless = "0.8.0"
|
||||
hmac = { version = "0.12.1", default-features = false }
|
||||
ieee80211 = { version = "0.4.0", default-features = false }
|
||||
ieee802154 = "0.6.1"
|
||||
log = "0.4.22"
|
||||
nb = "1.1.0"
|
||||
portable-atomic = { version = "1.9.0", default-features = false }
|
||||
sha2 = { version = "0.10.8", default-features = false }
|
||||
smoltcp = { version = "0.12.0", default-features = false, features = [ "medium-ethernet", "socket-raw"] }
|
||||
embedded-time = "=0.12.1"
|
||||
static_cell = { version = "2.1.0", features = ["nightly"] }
|
||||
trouble-host = { git = "https://github.com/embassy-rs/trouble", package = "trouble-host", rev = "4f1114ce58e96fe54f5ed7e726f66e1ad8d9ce54", features = [ "log", "gatt" ] }
|
||||
usb-device = "0.3.2"
|
||||
usbd-serial = "0.2.2"
|
||||
bt-hci = "0.1.1"
|
||||
cfg-if = "1.0.0"
|
||||
critical-section = "1.1.3"
|
||||
embassy-executor = { version = "0.6.0", features = ["task-arena-size-20480"] }
|
||||
embassy-futures = "0.1.1"
|
||||
embassy-net = { version = "0.5.0", features = [
|
||||
"tcp",
|
||||
"udp",
|
||||
"dhcpv4",
|
||||
"medium-ethernet",
|
||||
] }
|
||||
embassy-sync = "0.6.0"
|
||||
embassy-time = "0.3.2"
|
||||
embassy-usb = { version = "0.2.0", default-features = false }
|
||||
embedded-can = "0.4.1"
|
||||
embedded-hal-async = "1.0.0"
|
||||
embedded-io = { version = "0.6.1", default-features = false }
|
||||
embedded-io-async = "0.6.1"
|
||||
embedded-storage = "0.3.1"
|
||||
esp-alloc = { path = "../esp-alloc" }
|
||||
esp-backtrace = { path = "../esp-backtrace", features = [
|
||||
"exception-handler",
|
||||
"panic-handler",
|
||||
"println",
|
||||
] }
|
||||
esp-hal = { path = "../esp-hal", features = ["log", "unstable"] }
|
||||
esp-hal-embassy = { path = "../esp-hal-embassy", optional = true }
|
||||
esp-ieee802154 = { path = "../esp-ieee802154", optional = true }
|
||||
esp-println = { path = "../esp-println", features = ["log"] }
|
||||
esp-storage = { path = "../esp-storage", optional = true }
|
||||
esp-wifi = { path = "../esp-wifi", features = ["log"], optional = true }
|
||||
fugit = "0.3.7"
|
||||
heapless = "0.8.0"
|
||||
hmac = { version = "0.12.1", default-features = false }
|
||||
ieee80211 = { version = "0.4.0", default-features = false }
|
||||
ieee802154 = "0.6.1"
|
||||
log = "0.4.22"
|
||||
nb = "1.1.0"
|
||||
portable-atomic = { version = "1.9.0", default-features = false }
|
||||
sha2 = { version = "0.10.8", default-features = false }
|
||||
smoltcp = { version = "0.12.0", default-features = false, features = [
|
||||
"medium-ethernet",
|
||||
"socket-raw",
|
||||
] }
|
||||
embedded-time = "=0.12.1"
|
||||
static_cell = { version = "2.1.0", features = ["nightly"] }
|
||||
trouble-host = { git = "https://github.com/embassy-rs/trouble", package = "trouble-host", rev = "4f1114ce58e96fe54f5ed7e726f66e1ad8d9ce54", features = [
|
||||
"log",
|
||||
"gatt",
|
||||
] }
|
||||
usb-device = "0.3.2"
|
||||
usbd-serial = "0.2.2"
|
||||
edge-dhcp = "0.3.0"
|
||||
edge-raw = "0.3.0"
|
||||
edge-nal = "0.3.0"
|
||||
edge-nal-embassy = "0.3.0"
|
||||
bincode = { version = "2.0.0-rc.3", default-features = false, features = [
|
||||
"alloc",
|
||||
"derive",
|
||||
] }
|
||||
ws2812-async = { git = "https://github.com/kalkyl/ws2812-async" }
|
||||
smart-leds = "0.4"
|
||||
assign-resources = "0.4"
|
||||
|
||||
[features]
|
||||
esp32 = ["esp-hal/esp32", "esp-backtrace/esp32", "esp-hal-embassy?/esp32", "esp-println/esp32", "esp-storage?/esp32", "esp-wifi?/esp32"]
|
||||
esp32c2 = ["esp-hal/esp32c2", "esp-backtrace/esp32c2", "esp-hal-embassy?/esp32c2", "esp-println/esp32c2", "esp-storage?/esp32c2", "esp-wifi?/esp32c2", ]
|
||||
esp32c3 = ["esp-hal/esp32c3", "esp-backtrace/esp32c3", "esp-hal-embassy?/esp32c3", "esp-println/esp32c3", "esp-storage?/esp32c3", "esp-wifi?/esp32c3"]
|
||||
esp32c6 = ["esp-hal/esp32c6", "esp-backtrace/esp32c6", "esp-hal-embassy?/esp32c6", "esp-println/esp32c6", "esp-storage?/esp32c6", "esp-wifi?/esp32c6", "esp-ieee802154?/esp32c6"]
|
||||
esp32h2 = ["esp-hal/esp32h2", "esp-backtrace/esp32h2", "esp-hal-embassy?/esp32h2", "esp-println/esp32h2", "esp-storage?/esp32h2", "esp-wifi?/esp32h2", "esp-ieee802154?/esp32h2"]
|
||||
esp32s2 = ["esp-hal/esp32s2", "esp-backtrace/esp32s2", "esp-hal-embassy?/esp32s2", "esp-println/esp32s2", "esp-storage?/esp32s2", "esp-wifi?/esp32s2"]
|
||||
esp32s3 = ["esp-hal/esp32s3", "esp-backtrace/esp32s3", "esp-hal-embassy?/esp32s3", "esp-println/esp32s3", "esp-storage?/esp32s3", "esp-wifi?/esp32s3"]
|
||||
esp32 = [
|
||||
"esp-hal/esp32",
|
||||
"esp-backtrace/esp32",
|
||||
"esp-hal-embassy?/esp32",
|
||||
"esp-println/esp32",
|
||||
"esp-storage?/esp32",
|
||||
"esp-wifi?/esp32",
|
||||
]
|
||||
esp32c2 = [
|
||||
"esp-hal/esp32c2",
|
||||
"esp-backtrace/esp32c2",
|
||||
"esp-hal-embassy?/esp32c2",
|
||||
"esp-println/esp32c2",
|
||||
"esp-storage?/esp32c2",
|
||||
"esp-wifi?/esp32c2",
|
||||
]
|
||||
esp32c3 = [
|
||||
"esp-hal/esp32c3",
|
||||
"esp-backtrace/esp32c3",
|
||||
"esp-hal-embassy?/esp32c3",
|
||||
"esp-println/esp32c3",
|
||||
"esp-storage?/esp32c3",
|
||||
"esp-wifi?/esp32c3",
|
||||
]
|
||||
esp32c6 = [
|
||||
"esp-hal/esp32c6",
|
||||
"esp-backtrace/esp32c6",
|
||||
"esp-hal-embassy?/esp32c6",
|
||||
"esp-println/esp32c6",
|
||||
"esp-storage?/esp32c6",
|
||||
"esp-wifi?/esp32c6",
|
||||
"esp-ieee802154?/esp32c6",
|
||||
]
|
||||
esp32h2 = [
|
||||
"esp-hal/esp32h2",
|
||||
"esp-backtrace/esp32h2",
|
||||
"esp-hal-embassy?/esp32h2",
|
||||
"esp-println/esp32h2",
|
||||
"esp-storage?/esp32h2",
|
||||
"esp-wifi?/esp32h2",
|
||||
"esp-ieee802154?/esp32h2",
|
||||
]
|
||||
esp32s2 = [
|
||||
"esp-hal/esp32s2",
|
||||
"esp-backtrace/esp32s2",
|
||||
"esp-hal-embassy?/esp32s2",
|
||||
"esp-println/esp32s2",
|
||||
"esp-storage?/esp32s2",
|
||||
"esp-wifi?/esp32s2",
|
||||
]
|
||||
esp32s3 = [
|
||||
"esp-hal/esp32s3",
|
||||
"esp-backtrace/esp32s3",
|
||||
"esp-hal-embassy?/esp32s3",
|
||||
"esp-println/esp32s3",
|
||||
"esp-storage?/esp32s3",
|
||||
"esp-wifi?/esp32s3",
|
||||
]
|
||||
|
||||
esp-wifi = ["dep:esp-wifi"]
|
||||
|
||||
embassy = ["dep:esp-hal-embassy"]
|
||||
embassy = ["dep:esp-hal-embassy"]
|
||||
embassy-generic-timers = ["embassy-time/generic-queue-8"]
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
debug = 2
|
||||
codegen-units = 1
|
||||
debug = 2
|
||||
debug-assertions = true
|
||||
incremental = false
|
||||
opt-level = 3
|
||||
incremental = false
|
||||
opt-level = 3
|
||||
lto = 'fat'
|
||||
overflow-checks = false
|
||||
overflow-checks = false
|
||||
|
||||
[patch.crates-io]
|
||||
# Patch until https://github.com/ivmarkov/edge-net/pull/50 is merged
|
||||
edge-nal = { git = "https://github.com/ivmarkov/edge-net", rev = "5a85bcc8b8726e8b7044e9526f01cdba1fd684da"}
|
||||
edge-nal-embassy = { git = "https://github.com/ivmarkov/edge-net", rev = "5a85bcc8b8726e8b7044e9526f01cdba1fd684da"}
|
||||
edge-nal = { git = "https://github.com/ivmarkov/edge-net", rev = "5a85bcc8b8726e8b7044e9526f01cdba1fd684da" }
|
||||
edge-nal-embassy = { git = "https://github.com/ivmarkov/edge-net", rev = "5a85bcc8b8726e8b7044e9526f01cdba1fd684da" }
|
||||
|
||||
359
examples/src/bin/cat.rs
Normal file
359
examples/src/bin/cat.rs
Normal file
@ -0,0 +1,359 @@
|
||||
//! Embassy DHCP Example
|
||||
//!
|
||||
//!
|
||||
//! Set SSID and PASSWORD env variable before running this example.
|
||||
//!
|
||||
//! This gets an ip address via DHCP then performs an HTTP get request to some "random" server
|
||||
//!
|
||||
//! Because of the huge task-arena size configured this won't work on ESP32-S2
|
||||
|
||||
//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/wifi esp-wifi/utils esp-wifi/esp-now esp-hal/unstable
|
||||
//% CHIPS: esp32c6
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use core::net::Ipv4Addr;
|
||||
|
||||
use bincode::Decode;
|
||||
// use cyw43::JoinOptions;
|
||||
// use cyw43_pio::PioSpi;
|
||||
use embassy_net::udp::{PacketMetadata, UdpSocket};
|
||||
use embassy_net::{tcp::TcpSocket, Runner, StackResources};
|
||||
use embassy_executor::Spawner;
|
||||
|
||||
use blocking_network_stack::Stack;
|
||||
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embassy_sync::{blocking_mutex::raw::NoopRawMutex, mutex::Mutex};
|
||||
use embassy_futures::select::{select, Either};
|
||||
use esp_alloc as _;
|
||||
use esp_backtrace as _;
|
||||
use esp_hal::{clock::CpuClock,
|
||||
rng::Rng,
|
||||
timer::timg::TimerGroup,
|
||||
delay::Delay,
|
||||
interrupt::{software::SoftwareInterruptControl, Priority},
|
||||
entry,
|
||||
peripheral::Peripheral,
|
||||
spi::{
|
||||
master::{Config, Spi},
|
||||
Mode,
|
||||
},
|
||||
time::RateExtU32,
|
||||
gpio::{Level, Output},
|
||||
};
|
||||
use esp_hal::timer::systimer::SystemTimer;
|
||||
use esp_hal_embassy::InterruptExecutor;
|
||||
use esp_println::println;
|
||||
use esp_wifi::{
|
||||
init,
|
||||
wifi::{
|
||||
ClientConfiguration,
|
||||
Configuration,
|
||||
WifiController,
|
||||
WifiDevice,
|
||||
WifiEvent,
|
||||
WifiStaDevice,
|
||||
WifiState,
|
||||
},
|
||||
EspWifiController,
|
||||
};
|
||||
use esp_println::print;
|
||||
use smoltcp::{
|
||||
iface::{SocketSet, SocketStorage},
|
||||
wire::{DhcpOption, IpAddress},
|
||||
};
|
||||
|
||||
use ws2812_async::{ColorOrder, Ws2812};
|
||||
|
||||
use smart_leds::RGB8;
|
||||
use static_cell::StaticCell;
|
||||
|
||||
const SSID: &str = env!("SSID");
|
||||
const PASSWORD: &str = env!("PASSWORD");
|
||||
const NUM_LEDS: usize = 100;
|
||||
const CLIENT_ID: &str = env!("CLIENT_ID");
|
||||
|
||||
//static mut LEDSTRIP: &mut [u8] = &mut [0u8; NUM_LEDS * 3];
|
||||
|
||||
static mut RGBARRAY: [RGB8; NUM_LEDS] = [RGB8::new(0, 0, 0); NUM_LEDS];
|
||||
|
||||
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
|
||||
macro_rules! mk_static {
|
||||
($t:ty,$val:expr) => {{
|
||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
||||
#[deny(unused_attributes)]
|
||||
let x = STATIC_CELL.uninit().write(($val));
|
||||
x
|
||||
}};
|
||||
}
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(spawner: Spawner) -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
println!("Init!");
|
||||
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
// let sclk = peripherals.GPIO0;
|
||||
// let miso = peripherals.GPIO2;
|
||||
// let mosi = peripherals.GPIO4;
|
||||
// let cs = peripherals.GPIO5;
|
||||
|
||||
let sclk = Output::new(peripherals.GPIO0, Level::Low);
|
||||
let miso = Output::new(peripherals.GPIO2, Level::Low);
|
||||
let mosi = Output::new(peripherals.GPIO4, Level::Low); // only mosi is used for ws28*
|
||||
let cs = Output::new(peripherals.GPIO5, Level::Low);
|
||||
|
||||
let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
|
||||
|
||||
esp_alloc::heap_allocator!(72 * 1024);
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
|
||||
let mut rng = Rng::new(peripherals.RNG);
|
||||
|
||||
let init = &*mk_static!(
|
||||
EspWifiController<'static>,
|
||||
init(timg0.timer0, rng.clone(), peripherals.RADIO_CLK).unwrap()
|
||||
);
|
||||
|
||||
static EXECUTOR: StaticCell<InterruptExecutor<2>> = StaticCell::new();
|
||||
let executor = InterruptExecutor::new(sw_ints.software_interrupt2);
|
||||
let executor = EXECUTOR.init(executor);
|
||||
|
||||
// let spawner = executor.start(Priority::Priority3);
|
||||
// spawner.must_spawn(led_ctrl_core_task(sclk, miso, mosi, cs, peripherals.SPI2));
|
||||
|
||||
/////////////////////////// WIFI ////////////////////////////////
|
||||
|
||||
let wifi = peripherals.WIFI;
|
||||
let (wifi_interface, controller) =
|
||||
esp_wifi::wifi::new_with_mode(&init, wifi, WifiStaDevice).unwrap();
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "esp32")] {
|
||||
let timg1 = TimerGroup::new(peripherals.TIMG1);
|
||||
esp_hal_embassy::init(timg1.timer0);
|
||||
} else {
|
||||
use esp_hal::timer::systimer::SystemTimer;
|
||||
let systimer = SystemTimer::new(peripherals.SYSTIMER);
|
||||
esp_hal_embassy::init(systimer.alarm0);
|
||||
}
|
||||
}
|
||||
|
||||
let config = embassy_net::Config::dhcpv4(Default::default());
|
||||
|
||||
let seed = (rng.random() as u64) << 32 | rng.random() as u64;
|
||||
|
||||
// Init network stack
|
||||
let (stack, runner) = embassy_net::new(
|
||||
wifi_interface,
|
||||
config,
|
||||
mk_static!(StackResources<3>, StackResources::<3>::new()),
|
||||
seed,
|
||||
);
|
||||
|
||||
spawner.spawn(connection(controller)).ok();
|
||||
spawner.spawn(net_task(runner)).ok();
|
||||
spawner.spawn(led_ctrl_core_task(sclk, miso, mosi, cs, peripherals.SPI2)).ok();
|
||||
|
||||
let mut rx_buffer = [0; 4096];
|
||||
let mut tx_buffer = [0; 4096];
|
||||
|
||||
loop {
|
||||
if stack.is_link_up() {
|
||||
break;
|
||||
}
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
}
|
||||
|
||||
println!("Waiting to get IP address...");
|
||||
loop {
|
||||
if let Some(config) = stack.config_v4() {
|
||||
println!("Got IP: {}", config.address);
|
||||
break;
|
||||
}
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
}
|
||||
|
||||
loop {
|
||||
Timer::after(Duration::from_millis(1_000)).await;
|
||||
|
||||
let mut socket = TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer);
|
||||
|
||||
socket.set_timeout(Some(embassy_time::Duration::from_secs(10)));
|
||||
|
||||
let remote_endpoint = (Ipv4Addr::new(142, 250, 185, 115), 80);
|
||||
println!("connecting...");
|
||||
let r = socket.connect(remote_endpoint).await;
|
||||
if let Err(e) = r {
|
||||
println!("connect error: {:?}", e);
|
||||
continue;
|
||||
}
|
||||
println!("connected!");
|
||||
let mut buf = [0; 1024];
|
||||
loop {
|
||||
use embedded_io_async::Write;
|
||||
let r = socket
|
||||
.write_all(b"GET / HTTP/1.0\r\nHost: www.mobile-j.de\r\n\r\n")
|
||||
.await;
|
||||
if let Err(e) = r {
|
||||
println!("write error: {:?}", e);
|
||||
break;
|
||||
}
|
||||
let n = match socket.read(&mut buf).await {
|
||||
Ok(0) => {
|
||||
println!("read EOF");
|
||||
break;
|
||||
}
|
||||
Ok(n) => n,
|
||||
Err(e) => {
|
||||
println!("read error: {:?}", e);
|
||||
break;
|
||||
}
|
||||
};
|
||||
println!("{}", core::str::from_utf8(&buf[..n]).unwrap());
|
||||
}
|
||||
Timer::after(Duration::from_millis(3000)).await;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// highest priority task
|
||||
#[embassy_executor::task]
|
||||
async fn led_ctrl_core_task(sclk: Output<'static>, miso: Output<'static>, mosi: Output<'static>, cs: Output<'static>, spi2: esp_hal::peripherals::SPI2) {
|
||||
esp_println::println!("Hello world from embassy using esp-hal-async!");
|
||||
|
||||
// Spi configuration for the neopixel
|
||||
// let mut spi_config = Config::default();
|
||||
// spi_config.frequency = 3_800_000;
|
||||
|
||||
//let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let mut spi = Spi::new(
|
||||
spi2,
|
||||
Config::default()
|
||||
.with_frequency(3_800.kHz())
|
||||
.with_mode(Mode::_0),
|
||||
)
|
||||
.unwrap()
|
||||
.with_sck(sclk)
|
||||
.with_miso(miso) // order matters
|
||||
.with_mosi(mosi) // order matters
|
||||
.with_cs(cs)
|
||||
.into_async();
|
||||
|
||||
let mut np: Ws2812<_, { 12 * NUM_LEDS }> = Ws2812::new(spi);
|
||||
np.set_color_order(ColorOrder::GRB);
|
||||
|
||||
let mut data = [RGB8::default(); NUM_LEDS];
|
||||
|
||||
loop {
|
||||
println!("Writing led!");
|
||||
for led in data.iter_mut().step_by(1) {
|
||||
led.r = 0; // blue
|
||||
led.g = 0; // red
|
||||
led.b = 20; // green
|
||||
}
|
||||
|
||||
np.write(data.iter().cloned()).await.ok();
|
||||
|
||||
Timer::after(embassy_time::Duration::from_millis(5)).await;
|
||||
|
||||
for led in data.iter_mut().step_by(1) {
|
||||
led.r = 20; // blue
|
||||
led.g = 0; // red
|
||||
led.b = 0; // green
|
||||
}
|
||||
|
||||
np.write(data.iter().cloned()).await.ok();
|
||||
|
||||
Timer::after(embassy_time::Duration::from_millis(5)).await;
|
||||
|
||||
for led in data.iter_mut().step_by(1) {
|
||||
led.r = 0; // blue
|
||||
led.g = 20; // red
|
||||
led.b = 0; // green
|
||||
}
|
||||
|
||||
np.write(data.iter().cloned()).await.ok();
|
||||
|
||||
Timer::after(embassy_time::Duration::from_millis(5)).await;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn connection(mut controller: WifiController<'static>) {
|
||||
println!("start connection task");
|
||||
println!("Device capabilities: {:?}", controller.capabilities());
|
||||
loop {
|
||||
match esp_wifi::wifi::wifi_state() {
|
||||
WifiState::StaConnected => {
|
||||
// wait until we're no longer connected
|
||||
controller.wait_for_event(WifiEvent::StaDisconnected).await;
|
||||
Timer::after(Duration::from_millis(5000)).await
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if !matches!(controller.is_started(), Ok(true)) {
|
||||
let client_config = Configuration::Client(ClientConfiguration {
|
||||
ssid: SSID.try_into().unwrap(),
|
||||
password: PASSWORD.try_into().unwrap(),
|
||||
..Default::default()
|
||||
});
|
||||
controller.set_configuration(&client_config).unwrap();
|
||||
println!("Starting wifi");
|
||||
controller.start_async().await.unwrap();
|
||||
println!("Wifi started!");
|
||||
}
|
||||
println!("About to connect...");
|
||||
|
||||
match controller.connect_async().await {
|
||||
Ok(_) => println!("Wifi connected!"),
|
||||
Err(e) => {
|
||||
println!("Failed to connect to wifi: {e:?}");
|
||||
Timer::after(Duration::from_millis(5000)).await
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn net_task(mut runner: Runner<'static, WifiDevice<'static, WifiStaDevice>>) {
|
||||
runner.run().await
|
||||
}
|
||||
|
||||
#[derive(Debug, Decode, Clone, Copy, PartialEq)]
|
||||
struct Led {
|
||||
r: u8,
|
||||
g: u8,
|
||||
b: u8,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Decode, PartialEq)]
|
||||
pub struct LedStrip {
|
||||
leds: [Led; NUM_LEDS],
|
||||
}
|
||||
|
||||
impl LedStrip {
|
||||
// naive inital start with uniform colour on entire strip
|
||||
pub fn new(_r: u8) -> Self {
|
||||
let arr: [Led; NUM_LEDS] = [Led { r: 0, g: 0, b: 0 }; NUM_LEDS];
|
||||
|
||||
LedStrip { leds: arr }
|
||||
}
|
||||
pub fn to_array(&self) {
|
||||
for i in 0..NUM_LEDS {
|
||||
unsafe { RGBARRAY[i] = RGB8::new(self.leds[i].g, self.leds[i].r, self.leds[i].b) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Decode, PartialEq)]
|
||||
pub struct LedContainer {
|
||||
message_count: u32,
|
||||
ledstrip: LedStrip,
|
||||
}
|
||||
@ -12,15 +12,10 @@
|
||||
|
||||
use bleps::{
|
||||
ad_structure::{
|
||||
create_advertising_data,
|
||||
AdStructure,
|
||||
BR_EDR_NOT_SUPPORTED,
|
||||
LE_GENERAL_DISCOVERABLE,
|
||||
create_advertising_data, AdStructure, BR_EDR_NOT_SUPPORTED, LE_GENERAL_DISCOVERABLE,
|
||||
},
|
||||
attribute_server::{AttributeServer, NotificationData, WorkResult},
|
||||
gatt,
|
||||
Ble,
|
||||
HciConnector,
|
||||
gatt, Ble, HciConnector,
|
||||
};
|
||||
use esp_alloc as _;
|
||||
use esp_backtrace as _;
|
||||
|
||||
@ -30,12 +30,8 @@ use esp_println::{print, println};
|
||||
use esp_wifi::{
|
||||
init,
|
||||
wifi::{
|
||||
utils::create_network_interface,
|
||||
AccessPointInfo,
|
||||
ClientConfiguration,
|
||||
Configuration,
|
||||
WifiError,
|
||||
WifiStaDevice,
|
||||
utils::create_network_interface, AccessPointInfo, ClientConfiguration, Configuration,
|
||||
WifiError, WifiStaDevice,
|
||||
},
|
||||
};
|
||||
use smoltcp::{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
[alias]
|
||||
esp32 = "run --release --features=esp32 --target=xtensa-esp32-none-elf"
|
||||
esp32 = "run --release --features=esp32 --target=xtensa-esp32-none-elf"
|
||||
esp32c2 = "run --release --features=esp32c2 --target=riscv32imc-unknown-none-elf"
|
||||
esp32c3 = "run --release --features=esp32c3 --target=riscv32imc-unknown-none-elf"
|
||||
esp32c6 = "run --release --features=esp32c6 --target=riscv32imac-unknown-none-elf"
|
||||
@ -8,18 +8,17 @@ esp32s2 = "run --release --features=esp32s2 --target=xtensa-esp32s2-none-elf"
|
||||
esp32s3 = "run --release --features=esp32s3 --target=xtensa-esp32s3-none-elf"
|
||||
|
||||
[target.'cfg(target_arch = "riscv32")']
|
||||
runner = "espflash flash --monitor"
|
||||
rustflags = [
|
||||
"-C", "link-arg=-Tlinkall.x",
|
||||
"-C", "force-frame-pointers",
|
||||
]
|
||||
runner = "espflash flash --monitor"
|
||||
rustflags = ["-C", "link-arg=-Tlinkall.x", "-C", "force-frame-pointers"]
|
||||
|
||||
[target.'cfg(target_arch = "xtensa")']
|
||||
runner = "espflash flash --monitor"
|
||||
runner = "espflash flash --monitor"
|
||||
rustflags = [
|
||||
# GNU LD
|
||||
"-C", "link-arg=-Wl,-Tlinkall.x",
|
||||
"-C", "link-arg=-nostartfiles",
|
||||
"-C",
|
||||
"link-arg=-Wl,-Tlinkall.x",
|
||||
"-C",
|
||||
"link-arg=-nostartfiles",
|
||||
|
||||
# LLD
|
||||
# "-C", "link-arg=-Tlinkall.x",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user