Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link Board GPS Module #113

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions boards/communication/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
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;
use atsamd_hal::sercom::uart;
Expand Down Expand Up @@ -59,26 +62,26 @@
}

pub struct CanDevice0 {
pub can: Can<
'static,
Can0,
Dependencies<Can0, Gclk0Id, Pin<PA23, Alternate<I>>, Pin<PA22, Alternate<I>>, CAN0>,
Capacities,
>,

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

View workflow job for this annotation

GitHub Actions / clippy

very complex type used. Consider factoring parts into `type` definitions

warning: very complex type used. Consider factoring parts into `type` definitions --> boards/communication/src/communication.rs:65:14 | 65 | pub can: Can< | ______________^ 66 | | 'static, 67 | | Can0, 68 | | Dependencies<Can0, Gclk0Id, Pin<PA23, Alternate<I>>, Pin<PA22, Alternate<I>>, CAN0>, 69 | | Capacities, 70 | | >, | |_____^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity = note: `#[warn(clippy::type_complexity)]` on by default
line_interrupts: OwnedInterruptSet<Can0, EnabledLine0>,
}

impl CanDevice0 {
pub fn new<S>(
can_rx: Pin<PA23, AlternateI>,
can_tx: Pin<PA22, AlternateI>,
pclk_can: Pclk<Can0, Gclk0Id>,
ahb_clock: AhbClk<Can0>,
peripheral: CAN0,
gclk0: S,
can_memory: &'static mut SharedMemory<Capacities>,
loopback: bool,
) -> (Self, S::Inc)

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

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> boards/communication/src/communication.rs:75:5 | 75 | / pub fn new<S>( 76 | | can_rx: Pin<PA23, AlternateI>, 77 | | can_tx: Pin<PA22, AlternateI>, 78 | | pclk_can: Pclk<Can0, Gclk0Id>, ... | 83 | | loopback: bool, 84 | | ) -> (Self, S::Inc) | |_______________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default
where
S: Source<Id = Gclk0Id> + Increment,
{
Expand Down Expand Up @@ -215,18 +218,18 @@

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 Expand Up @@ -296,16 +299,16 @@
// Do we need the header?
match msg {
mavlink::uorocketry::MavMessage::POSTCARD_MESSAGE(msg) => {
return Ok(postcard::from_bytes::<Message>(&msg.message)?);

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

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> boards/communication/src/communication.rs:302:21 | 302 | return Ok(postcard::from_bytes::<Message>(&msg.message)?); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return = note: `#[warn(clippy::needless_return)]` on by default help: remove `return` | 302 - return Ok(postcard::from_bytes::<Message>(&msg.message)?); 302 + Ok(postcard::from_bytes::<Message>(&msg.message)?) |
// weird Ok syntax to coerce to hydra error type.
}
_ => {
herror!(Error, ErrorContext::UnkownPostcardMessage);
return Err(mavlink::error::MessageReadError::Io.into());

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

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> boards/communication/src/communication.rs:307:21 | 307 | return Err(mavlink::error::MessageReadError::Io.into()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return help: remove `return` | 307 - return Err(mavlink::error::MessageReadError::Io.into()); 307 + Err(mavlink::error::MessageReadError::Io.into()) |
}
}
} else {
return Err(mavlink::error::MessageReadError::Io.into());

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

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> boards/communication/src/communication.rs:311:13 | 311 | return Err(mavlink::error::MessageReadError::Io.into()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return help: remove `return` | 311 - return Err(mavlink::error::MessageReadError::Io.into()); 311 + Err(mavlink::error::MessageReadError::Io.into()) |
}
}
}
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,21 +58,22 @@
#[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<
Pads<
hal::pac::SERCOM4,
IoSet1,
Pin<PB15, Alternate<C>>,
Pin<PB12, Alternate<C>>,
Pin<PB13, Alternate<C>>,
>,
>,
Duplex,
>,
Pin<PB14, Output<PushPull>>,
>,

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

View workflow job for this annotation

GitHub Actions / clippy

very complex type used. Consider factoring parts into `type` definitions

warning: very complex type used. Consider factoring parts into `type` definitions --> boards/communication/src/main.rs:62:21 | 62 | sd_manager: SdManager< | _____________________^ 63 | | Spi< 64 | | Config< 65 | | Pads< ... | 75 | | Pin<PB14, Output<PushPull>>, 76 | | >, | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity
}

#[monotonic(binds = SysTick, default = true)]
Expand Down Expand Up @@ -121,16 +123,26 @@

/* 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 @@
radio_manager,
can0,
},
Local { led, sd_manager },
Local {
led,
gps_device,
sd_manager,
},
init::Monotonics(mono),
)
}
Expand All @@ -197,7 +213,7 @@
/// Idle task for when no other tasks are running.
#[idle]
fn idle(_: idle::Context) -> ! {
loop {}

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

View workflow job for this annotation

GitHub Actions / clippy

empty `loop {}` wastes CPU cycles

warning: empty `loop {}` wastes CPU cycles --> boards/communication/src/main.rs:216:9 | 216 | loop {} | ^^^^^^^ | = help: you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_loop = note: `#[warn(clippy::empty_loop)]` on by default
}

/// Handles the CAN0 interrupt.
Expand Down Expand Up @@ -247,10 +263,10 @@
let mut buf: [u8; 255] = [0; 255];
let msg_ser = postcard::to_slice_cobs(&m, &mut buf)?;
if let Some(mut file) = manager.file.take() {
manager.write(&mut file, &msg_ser)?;

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

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> boards/communication/src/main.rs:266:42 | 266 | manager.write(&mut file, &msg_ser)?; | ^^^^^^^^ help: change this to: `msg_ser` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default
manager.file = Some(file);
} else if let Ok(mut file) = manager.open_file("log.txt") {
manager.write(&mut file, &msg_ser)?;

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

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> boards/communication/src/main.rs:269:42 | 269 | manager.write(&mut file, &msg_ser)?; | ^^^^^^^^ help: change this to: `msg_ser` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
manager.file = Some(file);
}
Ok(())
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 @@
// -------
// 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>;
Loading