// main.rs核心代码
#![no_std]
#![no_main]

use esp_hal::{
    clock::ClockControl,
    gpio::{GpioDriver, Input, Output, Pin},
    prelude::*,
    Delay,
};
use esp_backtrace as _;
use panic_halt as _;

// 定义LED引脚(以GPIO2为例)
const LED_PIN: Pin = Pin::new(2);

#[entry]
fn main() -> ! {
    // 初始化硬件
    let peripherals = Peripherals::take().unwrap();
    let system = System::new();
    
    // 配置时钟
    let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
    
    // 初始化GPIO
    let gpio = GpioDriver::new(
        peripherals.pins,
        peripherals.gpio,
        &clocks,
    ).unwrap();
    
    // 配置LED引脚为推挽输出
    let mut led = gpio.configure_pin(
        LED_PIN,
        gpio::PinConfig {
            mode: gpio::Mode::Output,
            pull: gpio::Pull::None,
            drive_strength: gpio::DriveStrength::SlewRateControl,
            intr_type: gpio::InterruptType::Disable,
        },
    ).unwrap().into_push_pull_output();
    
    let mut delay = Delay::new();

    loop {
        // 点亮LED
        led.set_high().unwrap();
        delay.delay_ms(500_u32);
        
        // 熄灭LED
        led.set_low().unwrap();
        delay.delay_ms(500_u32);
    }
}