From 66e0da1d7337bfb3d5cfb1e408daf12907516651 Mon Sep 17 00:00:00 2001 From: Noah Sprenger Date: Sun, 7 Jul 2024 19:59:47 -0400 Subject: [PATCH] WIP: Test pinout compatibility. --- boards/communication/src/communication.rs | 15 ++++---- boards/communication/src/gps.rs | 43 +++++++++++++++++++++++ boards/communication/src/main.rs | 26 +++++++++++--- boards/communication/src/types.rs | 10 ++++-- 4 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 boards/communication/src/gps.rs diff --git a/boards/communication/src/communication.rs b/boards/communication/src/communication.rs index bdee0df0..738481f4 100644 --- a/boards/communication/src/communication.rs +++ b/boards/communication/src/communication.rs @@ -7,9 +7,12 @@ use atsamd_hal::clock::v2::pclk::Pclk; use atsamd_hal::clock::v2::pclk::PclkToken; use atsamd_hal::clock::v2::types::Can0; use atsamd_hal::clock::v2::Source; -use atsamd_hal::gpio::{Alternate, AlternateI, Disabled, Floating, Pin, I, PA22, PA23, PB16, PB17}; +use atsamd_hal::gpio::{ + Alternate, AlternateI, Disabled, Floating, Pin, I, PA08, PA09, PA22, PA23, PB16, PB17, +}; use atsamd_hal::pac::CAN0; use atsamd_hal::pac::MCLK; +use atsamd_hal::pac::SERCOM0; use atsamd_hal::pac::SERCOM5; use atsamd_hal::prelude::_embedded_hal_serial_Read; use atsamd_hal::sercom; @@ -215,18 +218,18 @@ pub struct RadioDevice { impl RadioDevice { pub fn new( - radio_token: PclkToken, + radio_token: PclkToken, mclk: &MCLK, - sercom: SERCOM5, - rx_pin: Pin>, - tx_pin: Pin>, + sercom: SERCOM0, + rx_pin: Pin>, + tx_pin: Pin>, gclk0: S, ) -> (Self, S::Inc) where S: Source + Increment, { let (pclk_radio, gclk0) = Pclk::enable(radio_token, gclk0); - let pads = uart::Pads::::default() + let pads = uart::Pads::::default() .rx(rx_pin) .tx(tx_pin); let uart = GroundStationUartConfig::new(mclk, sercom, pads, pclk_radio.freq()) diff --git a/boards/communication/src/gps.rs b/boards/communication/src/gps.rs new file mode 100644 index 00000000..5c126fa4 --- /dev/null +++ b/boards/communication/src/gps.rs @@ -0,0 +1,43 @@ +use crate::types::*; +use atsamd_hal::clock::v2::gclk::Gclk0Id; +use atsamd_hal::clock::v2::pclk::Pclk; +use atsamd_hal::clock::v2::pclk::PclkToken; +use atsamd_hal::clock::v2::Source; +use atsamd_hal::gpio::{Disabled, Floating, Pin, PA12, PA13}; +use atsamd_hal::pac::{MCLK, SERCOM2}; +use atsamd_hal::typelevel::Increment; +use atsamd_hal::{ + sercom, + sercom::{uart, uart::Duplex, uart::Uart}, +}; +use systick_monotonic::fugit::RateExtU32; + +pub struct GpsDevice { + pub uart: Uart, +} + +impl GpsDevice { + pub fn new( + gps_token: PclkToken, + mclk: &MCLK, + sercom: SERCOM2, + rx_pin: Pin>, + tx_pin: Pin>, + gclk0: S, + ) -> (Self, S::Inc) + where + S: Source + Increment, + { + let (pclk_gps, gclk0) = Pclk::enable(gps_token, gclk0); + let pads = uart::Pads::::default() + .rx(rx_pin) + .tx(tx_pin); + let uart = GpsUartConfig::new(mclk, sercom, pads, pclk_gps.freq()) + .baud( + 57600.Hz(), // check this + uart::BaudMode::Fractional(uart::Oversampling::Bits16), + ) + .enable(); + (GpsDevice { uart }, gclk0) + } +} diff --git a/boards/communication/src/main.rs b/boards/communication/src/main.rs index dcd1ea95..73994593 100644 --- a/boards/communication/src/main.rs +++ b/boards/communication/src/main.rs @@ -3,6 +3,7 @@ mod communication; mod data_manager; +mod gps; mod health; mod types; @@ -57,6 +58,7 @@ mod app { #[local] struct Local { led: Pin, + gps_device: gps::GpsDevice, sd_manager: SdManager< Spi< Config< @@ -121,16 +123,26 @@ mod app { /* Radio config */ let (radio, gclk0) = RadioDevice::new( - tokens.pclks.sercom5, + tokens.pclks.sercom0, &mclk, - peripherals.SERCOM5, - pins.pb17, - pins.pb16, + peripherals.SERCOM0, + pins.pa09, + pins.pa08, gclk0, ); let radio_manager = RadioManager::new(radio); + /* GPS config */ + let (gps_device, gclk0) = gps::GpsDevice::new( + tokens.pclks.sercom2, + &mclk, + peripherals.SERCOM2, + pins.pa13, + pins.pa12, + gclk0, + ); + /* SD config */ let (pclk_sd, gclk0) = Pclk::enable(tokens.pclks.sercom4, gclk0); let pads_spi = spi::Pads::::default() @@ -189,7 +201,11 @@ mod app { radio_manager, can0, }, - Local { led, sd_manager }, + Local { + led, + gps_device, + sd_manager, + }, init::Monotonics(mono), ) } diff --git a/boards/communication/src/types.rs b/boards/communication/src/types.rs index 34315d1c..7fb09ecc 100644 --- a/boards/communication/src/types.rs +++ b/boards/communication/src/types.rs @@ -1,6 +1,6 @@ use atsamd_hal::gpio::*; use atsamd_hal::sercom::uart::EightBit; -use atsamd_hal::sercom::{uart, IoSet1, Sercom5}; +use atsamd_hal::sercom::{uart, IoSet1, IoSet3, Sercom0, Sercom2, Sercom4, Sercom5}; use messages::node::Node; use messages::node::Node::CommunicationBoard; @@ -12,5 +12,11 @@ pub static COM_ID: Node = CommunicationBoard; // ------- // Ground Station // ------- -pub type GroundStationPads = uart::PadsFromIds; +pub type GroundStationPads = uart::PadsFromIds; pub type GroundStationUartConfig = uart::Config; + +// ------- +// GPS +// ------- +pub type GpsPads = uart::PadsFromIds; +pub type GpsUartConfig = uart::Config;