Change main

This commit is contained in:
Connie 2024-05-02 20:00:02 -04:00
parent d9eebf70eb
commit af16954157

View File

@ -20,31 +20,70 @@ fn i2c_init() -> (I2c, I2c) {
let i2c_minus = I2c::new(i2c_config_minus).unwrap(); let i2c_minus = I2c::new(i2c_config_minus).unwrap();
(i2c_plus, i2c_minus) (i2c_plus, i2c_minus)
} }
fn switch_led_setup() -> ( gpio::GpioPort, gpio::GpioPort, gpio::GpioPort,
gpio::GpioPort, gpio::GpioPort, gpio::GpioPort, gpio::GpioPort){
let red: gpio::GpioPort = gpio::PB7;
let green: gpio::GpioPort = gpio::PB8;
let s1: gpio::GpioPort = gpio::PA9;
let s2: gpio::GpioPort = gpio::PA10;
let s3: gpio::GpioPort = gpio::PB4;
let s4: gpio::GpioPort = gpio::PB5;
let s5: gpio::GpioPort = gpio::PA5;
green.setup();
red.setup();
s1.setup();
s2.setup();
s3.setup();
s4.setup();
s5.setup();
(green, red, s1, s2, s3,s4,s5)
}
fn i2c_send( i2c:&mut I2c, addr: u16, mut data: [u8; 2]) {
let i2c_message = i2c::I2cMessage {
addr,
data:&mut data,
};
i2c.send(&i2c_message).unwrap();
}
const POS_DAC_1_ADDR: u16 = 0x20;
const DAC_REG_BASE: u8 = 0xF8;
const DAC_REG_1: u8 = 0xF8;
const DAC_REG_2: u8 = 0xF9;
const DAC_REG_3: u8 = 0xFA;
const DAC_REG_4: u8 = 0xFB;
#[task] #[task]
async fn async_main(spawner: Spawner) { async fn async_main(spawner: Spawner) {
// be careful, if the dbg is not enabled, but using deep sleep. This framework will not able to connect to chip. // be careful, if the dbg is not enabled, but using deep sleep. This framework will not able to connect to chip.
// stm32cube programmer, stmcubeide can be used to program the chip, then this framework can be used to debug. // stm32cube programmer, stmcubeide can be used to program the chip, then this framework can be used to debug.
clock::init_clock(false, true, 16_000_000, true, clock::ClockFreqs::KernelFreq4Mhz); clock::init_clock(false, true, 16_000_000, true, clock::ClockFreqs::KernelFreq160Mhz);
no_deep_sleep_request(); no_deep_sleep_request();
defmt::info!("setup led finished!"); defmt::info!("setup led finished!");
let red: gpio::GpioPort = gpio::PB7; let (green, red, s1, s2, s3, s4, s5) = switch_led_setup();
let green: gpio::GpioPort = gpio::PB8; s1.set_low();
green.setup(); s2.set_high();
red.setup(); s3.set_low();
s4.set_high();
s5.set_low();
let (mut i2c_plus, mut i2c_minus) = i2c_init(); let (mut i2c_plus, mut i2c_minus) = i2c_init();
// let i2c_message = i2c::I2cMessage { for i in 0..4{
// addr: 0x68, i2c_send(&mut i2c_plus, POS_DAC_1_ADDR, [DAC_REG_BASE + i, 0x50]);
// data: &mut [0x75], }
// }; for i in 0..4 {
// i2c_plus.send(&i2c_message).unwrap(); i2c_send(&mut i2c_minus, POS_DAC_1_ADDR, [DAC_REG_BASE + i, 0x50]);
defmt::info!("i2c init finished!"); }
defmt::info!("i2c finished!");
loop { loop {
// exti::EXTI13_PC13.wait_for_raising().await;
green.toggle(); green.toggle();
red.toggle(); // red.toggle();
delay_ms(500); // delay_ms(1000);
defmt::info!("toggle leds"); // defmt::info!("toggle leds");
} }
} }