| 1 | //! The one owned `Board`, built in `main` from `Peripherals::take()`. |
| 2 | //! |
| 3 | //! It owns the shared buses and the peripheral/pin handles that later phases |
| 4 | //! consume (radios, CC1101, WiFi/BLE modem). Display and Buttons are built as |
| 5 | //! siblings in `main` and reach apps via `AppCtx`, not through `Board`. |
| 6 | //! |
| 7 | //! The shared I2C lives behind a `'static` `RefCell` so SSD1306 (always-on) and |
| 8 | //! PN532 can both hold `RefCellDevice`s over it without re-initialising the bus. |
| 9 | |
| 10 | use core::cell::RefCell; |
| 11 | |
| 12 | use esp_idf_hal::gpio::AnyIOPin; |
| 13 | use esp_idf_hal::i2c::I2cDriver; |
| 14 | use esp_idf_hal::modem::Modem; |
| 15 | use esp_idf_hal::spi::{SPI2, SPI3}; |
| 16 | |
| 17 | /// Shared handle to the I2C0 bus (OLED + PN532). Leaked to `'static` in `main` |
| 18 | /// because the display is always on for the lifetime of the program. |
| 19 | pub type SharedI2c = &'static RefCell<I2cDriver<'static>>; |
| 20 | |
| 21 | /// NRF24 bus + control pins (SPI2). Consumed in Phase 4. |
| 22 | pub struct NrfPins { |
| 23 | pub sck: AnyIOPin<'static>, |
| 24 | pub miso: AnyIOPin<'static>, |
| 25 | pub mosi: AnyIOPin<'static>, |
| 26 | pub ce1: AnyIOPin<'static>, |
| 27 | pub csn1: AnyIOPin<'static>, |
| 28 | pub ce2: AnyIOPin<'static>, |
| 29 | pub csn2: AnyIOPin<'static>, |
| 30 | } |
| 31 | |
| 32 | /// CC1101 bus + control pins (SPI3). Consumed in Phase 4. |
| 33 | pub struct Cc1101Pins { |
| 34 | pub sck: AnyIOPin<'static>, |
| 35 | pub miso: AnyIOPin<'static>, |
| 36 | pub mosi: AnyIOPin<'static>, |
| 37 | pub cs: AnyIOPin<'static>, |
| 38 | pub gdo0: AnyIOPin<'static>, |
| 39 | pub gdo2: AnyIOPin<'static>, |
| 40 | } |
| 41 | |
| 42 | /// Owns the peripherals and bus handles not already consumed by the display and |
| 43 | /// buttons. Passed `&mut` into every app via `AppCtx`. |
| 44 | pub struct Board { |
| 45 | /// Shared I2C0 bus (OLED is live; PN532 joins in Phase 4). |
| 46 | pub i2c: SharedI2c, |
| 47 | /// WiFi/BLE radio — acquired/released by one app at a time (Phase 2/3). |
| 48 | pub modem: Modem<'static>, |
| 49 | /// SPI2 host for the two NRF24 radios (Phase 4). |
| 50 | pub spi2: SPI2<'static>, |
| 51 | /// SPI3 host for the CC1101 (Phase 4). |
| 52 | pub spi3: SPI3<'static>, |
| 53 | pub nrf: NrfPins, |
| 54 | pub cc1101: Cc1101Pins, |
| 55 | } |