summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorandromeda <andromeda@lenovo>2026-04-06 21:51:13 +0200
committerandromeda <andromeda@lenovo>2026-04-06 21:51:13 +0200
commitc085c1ab360750b5522d1fa8fde0e0ed5c5aeb53 (patch)
treed14aa619c581c359e151cd4eefd0a3660a58aab7 /src/lib.rs
parentae793c14be863a8e50df08068fb0be9b014217d3 (diff)
initialize wifi two-way
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index a721c77..a7006ad 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,10 +1,14 @@
#![no_std]
+extern crate alloc;
+use alloc::string::String;
+use core::env;
use esp_hal::{
clock::CpuClock,
time::{Duration, Instant},
};
use esp_hal_smartled::SmartLedsAdapter;
+use esp_radio::wifi;
use smart_leds::{RGB, SmartLedsWrite as _, brightness};
// default brightness level of RGB led, used by write_rgb
@@ -38,6 +42,33 @@ pub fn init() -> esp_hal::peripherals::Peripherals {
peripherals
}
+pub fn mk_wifi_config() -> wifi::ModeConfig {
+ let access_point_config = wifi::AccessPointConfig::default()
+ .with_auth_method(wifi::AuthMethod::WpaWpa2Personal)
+ .with_ssid(String::from("esp32c6"))
+ .with_password(String::from("password"));
+ let client_config = wifi::ClientConfig::default()
+ .with_auth_method(wifi::AuthMethod::WpaWpa2Personal)
+ .with_ssid(String::from(env!("ACCESS_POINT_SSID")))
+ .with_password(String::from(env!("ACCESS_POINT_PASS")));
+ wifi::ModeConfig::ApSta(client_config, access_point_config)
+}
+
+pub fn connect_wifi(
+ wifi_controller: &mut wifi::WifiController,
+ wifi_config: &wifi::ModeConfig,
+) -> () {
+ wifi_controller
+ .set_config(wifi_config)
+ .expect("failed to set wifi config");
+ wifi_controller
+ .start()
+ .expect("failed to start wifi controller");
+ wifi_controller
+ .connect()
+ .expect("failed to attempt to connect wifi controller to access point");
+}
+
// used the site https://deepbluembedded.com/sine-lookup-table-generator-calculator/ to generate
const SIN_LOOKUP_U8: [u8; 256] = [
128, 131, 134, 137, 140, 143, 146, 149, 152, 155, 158, 162, 165, 167, 170, 173, 176, 179, 182,