1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#![no_std]
#![no_main]
use core::env;
use esp_backtrace as _; // panic_handler
use esp_hal::{
interrupt::software::SoftwareInterruptControl, rmt::Rmt, time::Rate, timer::timg::TimerGroup,
};
use esp_hal_smartled::{SmartLedsAdapter, smart_led_buffer};
use esp_radio::wifi;
use smart_leds::RGB;
use esp32c6_play::{connect_wifi, init, mk_wifi_config, sin, wait_ms, write_rgb};
// This creates a default app-descriptor required by the esp-idf bootloader.
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
esp_bootloader_esp_idf::esp_app_desc!();
#[esp_hal::main]
fn main() -> ! {
// initialize peripherals and logging
let peripherals = init();
// initialize heap
esp_alloc::heap_allocator!(size: 64 * 1024);
// initialize esp-rtos as scheduler for esp-radio
let timg0 = TimerGroup::new(peripherals.TIMG0);
let software_interrupt = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
esp_rtos::start(timg0.timer0, software_interrupt.software_interrupt0);
// initialize wifi
let radio_controller = esp_radio::init().expect("failed to init radio controller");
let (mut wifi_controller, _) =
wifi::new(&radio_controller, peripherals.WIFI, wifi::Config::default())
.expect("failed to init wifi controller");
let wifi_config = mk_wifi_config();
connect_wifi(&mut wifi_controller, &wifi_config);
// initialize rgb led
let mut led_buffer = smart_led_buffer!(1 /* # of leds */);
let mut rgb_led = {
let frequency = Rate::from_mhz(80); // max frequency of RMT
let rmt = Rmt::new(peripherals.RMT, frequency).expect("failed to initialize rmt");
SmartLedsAdapter::new(rmt.channel0, peripherals.GPIO8, &mut led_buffer)
};
// red led and waiting message
write_rgb(&mut rgb_led, RGB::new(255, 20, 20));
log::info!("connecting...");
while !wifi_controller
.is_connected()
.expect("failed to check connection status")
{
wait_ms(100);
}
log::info!("connected to the access point");
loop {
for i in 0..255 {
let r: u8 = i;
let g: u8 = i + 255 / 3; // phase shifted a third
let b: u8 = i + 2 * (255 / 3); // phase shifted two thirds
write_rgb(&mut rgb_led, RGB::new(sin(r), sin(g), sin(b)));
wait_ms(8);
}
}
}
|