aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 37b413cdb22bbe902dd62c82ad2de60133aa9984 (plain) (blame)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#![no_std]
#![no_main]
#![feature(impl_trait_in_assoc_type)]

use molybdos::{
    embassy_embedded_hal::shared_bus::asynch::spi::SpiDevice,
    embassy_rp::{
        i2c::{
            self,
            I2c,
        },
        peripherals::{
            I2C0,
            SPI0,
            SPI1,
        },
        spi::{
            self,
            Spi,
        },
    },
    embassy_sync::{
        blocking_mutex::raw::CriticalSectionRawMutex,
        pubsub,
    },
    embedded_sdmmc_async::{
        VolumeIdx,
        VolumeManager,
    },
    genlog,
    genlog::defmt,
    pal::StaticOutput,
};

mod bringup;
mod usb;

pub type BMESpi = Spi<'static, SPI1, spi::Async>;
pub type BMESpiDev = SpiDevice<'static, CriticalSectionRawMutex, BMESpi, StaticOutput>;
pub type SdSpi = Spi<'static, SPI0, spi::Async>;
pub type SdSpiDev = SpiDevice<'static, CriticalSectionRawMutex, SdSpi, StaticOutput>;

pub type SensorI2c = I2c<'static, I2C0, i2c::Async>;

#[embassy_executor::main]
async fn main(spawner: embassy_executor::Spawner) {
    molybdos::pal::heap::init();

    genlog::info!("boot");

    let bringup::Split {
        sd_spi,
        sd_cs,
        bme_spi,
        bme_cs,
        wdt,
        usb,
        ..
    } = bringup::split(Default::default());

    // spawner.must_spawn(molybdos::pal::watchdog(wdt));

    let (acm,) = molybdos::lib::usb::bringup!(
        spawn,
        usb,
        molybdos::pal::UsbDriver,
        molybdos::lib::usb::config("npry", "ocularium", 0x8888, 0x0011),
        endpoints = {
            acm => |builder| molybdos::lib::usb::acm!(builder),
        }
    );

    molybdos::lib::usb::start!(molybdos::pal::UsbDriver, acm, &usb::UPLINK, &usb::DOWNLINK);

    molybdos::lib::util::cobs::start!(
        ocularium::Uplink,
        &usb::UPLINK,
        &usb::COBS_UPLINK,
        ocularium::Downlink,
        &usb::DOWNLINK,
        &usb::COBS_DOWNLINK
    );

    #[cfg(not(feature = "disable_sd"))]
    {
        let vm = molybdos::rt::sd::bringup!(sd_spi, SdSpi, sd_cs);

        {
            let vol = VolumeManager::open_volume(vm, VolumeIdx(0)).await.expect("opening volume");
        }

        // spawner.must_spawn(sd::run_sd(vm, pubsub::LED.sender().into()));
    }

    loop {
        molybdos::embassy_time::Timer::after(molybdos::embassy_time::Duration::from_secs(1)).await;
    }
}