main.rs (3122B)
1 #![no_std] 2 #![no_main] 3 #![deny( 4 clippy::mem_forget, 5 reason = "mem::forget is generally not safe to do with esp_hal types, especially those \ 6 holding buffers for the duration of a data transfer." 7 )] 8 #![deny(clippy::large_stack_frames)] 9 10 use defmt::info; 11 use embassy_executor::Spawner; 12 use embassy_time::{Duration, Timer}; 13 use esp_hal::{ 14 delay::Delay, 15 clock::CpuClock, 16 timer::timg::TimerGroup, 17 gpio::{Level, Flex, 18 Output, OutputConfig, 19 Input, InputConfig, 20 DriveMode, 21 Pull 22 } 23 24 }; 25 26 use onewire::OneWire; 27 28 use esp_radio::ble::controller::BleConnector; 29 use panic_rtt_target as _; 30 31 extern crate alloc; 32 33 // This creates a default app-descriptor required by the esp-idf bootloader. 34 // For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description> 35 esp_bootloader_esp_idf::esp_app_desc!(); 36 37 #[allow( 38 clippy::large_stack_frames, 39 reason = "it's not unusual to allocate larger buffers etc. in main" 40 )] 41 #[esp_rtos::main] 42 async fn main(spawner: Spawner) -> ! { 43 // generator version: 1.3.0 44 // generator parameters: --chip esp32c3 -o alloc -o unstable-hal -o wifi -o ble-bleps -o embassy -o probe-rs -o defmt -o panic-rtt-target -o embedded-test 45 46 rtt_target::rtt_init_defmt!(); 47 48 let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max()); 49 let peripherals = esp_hal::init(config); 50 51 esp_alloc::heap_allocator!(#[esp_hal::ram(reclaimed)] size: 66320); 52 // COEX needs more RAM - so we've added some more 53 esp_alloc::heap_allocator!(size: 64 * 1024); 54 55 let timg0 = TimerGroup::new(peripherals.TIMG0); 56 let sw_interrupt = 57 esp_hal::interrupt::software::SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); 58 esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0); 59 60 info!("Embassy initialized!"); 61 62 let (mut _wifi_controller, _interfaces) = 63 esp_radio::wifi::new(peripherals.WIFI, Default::default()) 64 .expect("Failed to initialize Wi-Fi controller"); 65 let _connector = BleConnector::new(peripherals.BT, Default::default()); 66 67 // TODO: Spawn some tasks 68 let _ = spawner; 69 70 let in_config = InputConfig::default().with_pull(Pull::Up); 71 72 let out_config = OutputConfig::default() 73 .with_drive_mode(DriveMode::OpenDrain) 74 .with_pull(Pull::None); // Use an external 4.7k pull-up resistor 75 76 let mut flex = Flex::new(peripherals.GPIO3); 77 flex.apply_input_config(&in_config); 78 flex.apply_output_config(&out_config); 79 flex.set_input_enable(true); 80 flex.set_output_enable(true); 81 82 let mut wire = OneWire::new(&mut flex, false); 83 let mut delay = Delay::new(); 84 85 info!("{:?}", wire.reset(&mut delay)); 86 87 let mut led = Output::new(peripherals.GPIO8, Level::Low, OutputConfig::default()); 88 led.set_high(); 89 90 loop { 91 info!("Hello world!"); 92 delay.delay_millis(500); 93 led.toggle(); 94 } 95 96 // for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.1.0/examples 97 }