fosmometer/firmware/src/main.rs

59 lines
1.3 KiB
Rust
Raw Normal View History

2024-01-08 13:52:39 +01:00
#![no_std]
#![no_main]
mod fusb302;
2024-01-08 13:52:39 +01:00
use ch32v00x_hal as hal;
use core::cell::Cell;
use fusb302::{Fusb302, Variant};
2024-01-09 01:46:20 +01:00
use hal::debug::SDIPrint;
use hal::gpio::PinState;
use hal::i2c::{I2c, I2cConfig};
use hal::pac::Peripherals;
use hal::prelude::*;
use hal::serial::Config as SerialConfig;
2024-01-08 13:52:39 +01:00
use panic_halt as _;
#[qingke_rt::entry]
fn main() -> ! {
2024-01-09 01:46:20 +01:00
SDIPrint::enable();
let p = Peripherals::take().unwrap();
let mut rcc = p.RCC.constrain();
let clocks = rcc.config.freeze();
let gpioa = p.GPIOA.split(&mut rcc);
let mut _fan = gpioa.pa2.into_push_pull_output_in_state(PinState::High);
let gpioc = p.GPIOC.split(&mut rcc);
let i2c = Cell::new(Some(I2c::i2c1(
2024-01-09 01:46:20 +01:00
p.I2C1,
gpioc.pc2.into_alternate_open_drain(),
gpioc.pc1.into_alternate_open_drain(),
I2cConfig::fast_mode(),
&mut rcc,
&clocks,
)));
2024-01-09 01:46:20 +01:00
let mut _tec = gpioc.pc4.into_push_pull_output();
let gpiod = p.GPIOD.split(&mut rcc);
let mut _usart = p.USART1.usart(
gpiod.pd5.into_alternate(),
gpiod.pd6.into_floating_input(),
SerialConfig::default(),
&mut rcc,
&clocks,
);
let mut fusb302 = Fusb302::new(i2c.replace(None).unwrap(), Variant::B);
fusb302.reset().unwrap();
let _ = i2c.replace(Some(fusb302.release()));
2024-01-08 13:52:39 +01:00
loop {}
}