Skip to content

Commit

Permalink
WIP: Test pinout compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSprenger committed Jul 7, 2024
1 parent 0251afa commit 66e0da1
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 13 deletions.
15 changes: 9 additions & 6 deletions boards/communication/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Check warning on line 11 in boards/communication/src/communication.rs

View workflow job for this annotation

GitHub Actions / clippy

unused imports: `PB16`, `PB17`

warning: unused imports: `PB16`, `PB17` --> boards/communication/src/communication.rs:11:80 | 11 | Alternate, AlternateI, Disabled, Floating, Pin, I, PA08, PA09, PA22, PA23, PB16, PB17, | ^^^^ ^^^^ | = note: `#[warn(unused_imports)]` on by default
};
use atsamd_hal::pac::CAN0;
use atsamd_hal::pac::MCLK;
use atsamd_hal::pac::SERCOM0;
use atsamd_hal::pac::SERCOM5;

Check warning on line 16 in boards/communication/src/communication.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `atsamd_hal::pac::SERCOM5`

warning: unused import: `atsamd_hal::pac::SERCOM5` --> boards/communication/src/communication.rs:16:5 | 16 | use atsamd_hal::pac::SERCOM5; | ^^^^^^^^^^^^^^^^^^^^^^^^
use atsamd_hal::prelude::_embedded_hal_serial_Read;
use atsamd_hal::sercom;
Expand Down Expand Up @@ -215,18 +218,18 @@ pub struct RadioDevice {

impl RadioDevice {
pub fn new<S>(
radio_token: PclkToken<SERCOM5>,
radio_token: PclkToken<SERCOM0>,
mclk: &MCLK,
sercom: SERCOM5,
rx_pin: Pin<PB17, Disabled<Floating>>,
tx_pin: Pin<PB16, Disabled<Floating>>,
sercom: SERCOM0,
rx_pin: Pin<PA09, Disabled<Floating>>,
tx_pin: Pin<PA08, Disabled<Floating>>,
gclk0: S,
) -> (Self, S::Inc)
where
S: Source<Id = Gclk0Id> + Increment,
{
let (pclk_radio, gclk0) = Pclk::enable(radio_token, gclk0);
let pads = uart::Pads::<sercom::Sercom5, _>::default()
let pads = uart::Pads::<sercom::Sercom0, _>::default()
.rx(rx_pin)
.tx(tx_pin);
let uart = GroundStationUartConfig::new(mclk, sercom, pads, pclk_radio.freq())
Expand Down
43 changes: 43 additions & 0 deletions boards/communication/src/gps.rs
Original file line number Diff line number Diff line change
@@ -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<GpsUartConfig, Duplex>,

Check warning on line 16 in boards/communication/src/gps.rs

View workflow job for this annotation

GitHub Actions / clippy

field `uart` is never read

warning: field `uart` is never read --> boards/communication/src/gps.rs:16:9 | 15 | pub struct GpsDevice { | --------- field in this struct 16 | pub uart: Uart<GpsUartConfig, Duplex>, | ^^^^ | = note: `#[warn(dead_code)]` on by default
}

impl GpsDevice {
pub fn new<S>(
gps_token: PclkToken<SERCOM2>,
mclk: &MCLK,
sercom: SERCOM2,
rx_pin: Pin<PA13, Disabled<Floating>>,
tx_pin: Pin<PA12, Disabled<Floating>>,
gclk0: S,
) -> (Self, S::Inc)
where
S: Source<Id = Gclk0Id> + Increment,
{
let (pclk_gps, gclk0) = Pclk::enable(gps_token, gclk0);
let pads = uart::Pads::<sercom::Sercom2, _>::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)
}
}
26 changes: 21 additions & 5 deletions boards/communication/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

mod communication;
mod data_manager;
mod gps;
mod health;
mod types;

Expand Down Expand Up @@ -57,6 +58,7 @@ mod app {
#[local]
struct Local {
led: Pin<PA05, PushPullOutput>,
gps_device: gps::GpsDevice,

Check warning on line 61 in boards/communication/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

field `gps_device` is never read

warning: field `gps_device` is never read --> boards/communication/src/main.rs:61:9 | 61 | gps_device: gps::GpsDevice, | ^^^^^^^^^^ ... 86 | fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { | ----- field in this struct
sd_manager: SdManager<
Spi<
Config<
Expand Down Expand Up @@ -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::<Sercom4, IoSet1>::default()
Expand Down Expand Up @@ -189,7 +201,11 @@ mod app {
radio_manager,
can0,
},
Local { led, sd_manager },
Local {
led,
gps_device,
sd_manager,
},
init::Monotonics(mono),
)
}
Expand Down
10 changes: 8 additions & 2 deletions boards/communication/src/types.rs
Original file line number Diff line number Diff line change
@@ -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};

Check warning on line 3 in boards/communication/src/types.rs

View workflow job for this annotation

GitHub Actions / clippy

unused imports: `IoSet3`, `Sercom4`, `Sercom5`

warning: unused imports: `IoSet3`, `Sercom4`, `Sercom5` --> boards/communication/src/types.rs:3:40 | 3 | use atsamd_hal::sercom::{uart, IoSet1, IoSet3, Sercom0, Sercom2, Sercom4, Sercom5}; | ^^^^^^ ^^^^^^^ ^^^^^^^
use messages::node::Node;
use messages::node::Node::CommunicationBoard;

Expand All @@ -12,5 +12,11 @@ pub static COM_ID: Node = CommunicationBoard;
// -------
// Ground Station
// -------
pub type GroundStationPads = uart::PadsFromIds<Sercom5, IoSet1, PB17, PB16>;
pub type GroundStationPads = uart::PadsFromIds<Sercom0, IoSet1, PA09, PA08>;
pub type GroundStationUartConfig = uart::Config<GroundStationPads, EightBit>;

// -------
// GPS
// -------
pub type GpsPads = uart::PadsFromIds<Sercom2, IoSet1, PA13, PA12>;
pub type GpsUartConfig = uart::Config<GpsPads, EightBit>;

0 comments on commit 66e0da1

Please sign in to comment.