Skip to content

Commit

Permalink
First bus activity!
Browse files Browse the repository at this point in the history
  • Loading branch information
Finomnis committed Dec 9, 2023
1 parent 3eae4e9 commit 69fc170
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/common/lpspi/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ impl<'a, const N: u8> Lpspi<'a, N> {
tx_buffer[i] = data.add(i).read();
}
}

ral::write_reg!(ral::lpspi, self.lpspi(), TDR, u32::from_be_bytes(tx_buffer));
}
}

Expand All @@ -256,8 +258,8 @@ impl<'a, const N: u8> Lpspi<'a, N> {

self.clear_fifos();

let _read_task = async { assert!(!sequence.contains_read_actions()) };
let _write_task = async {
let read_task = async { assert!(!sequence.contains_read_actions()) };
let write_task = async {
unsafe {
let has_phase_1 = sequence.phase1.is_some();
let has_phase_2 = sequence.phase2.is_some();
Expand Down Expand Up @@ -315,7 +317,9 @@ impl<'a, const N: u8> Lpspi<'a, N> {
}
};

Ok(())
futures::join!(read_task, write_task);

self.check_errors()
}

/// Perform a sequence of transfer actions while continuously checking for errors.
Expand Down
10 changes: 8 additions & 2 deletions src/common/lpspi/transfer_actions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use core::{marker::PhantomData, num::NonZeroUsize};

#[derive(Debug)]
pub(crate) struct DualDirectionActions {
read_buf: *mut u8,
write_buf: *const u8,
Expand Down Expand Up @@ -117,21 +118,25 @@ impl Iterator for SingleDirectionWriteActionIter {
}
}

#[derive(Debug)]
pub(crate) struct ReadActions {
read_buf: *mut u8,
len: [usize; 3],
}

#[derive(Debug)]
pub(crate) struct WriteActions {
write_buf: *const u8,
len: [usize; 3],
}

#[derive(Debug)]
pub(crate) struct MaybeWriteActions {
write_buf: Option<*const u8>,
len: [usize; 3],
}

#[derive(Debug)]
pub(crate) enum SingleDirectionActions {
Read(ReadActions),
Write(WriteActions),
Expand Down Expand Up @@ -161,7 +166,7 @@ impl SingleDirectionActions {

/// The order in which the bytes need
/// to be transferred on the bus
#[derive(Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ByteOrder {
/// Bytes need to be transferred in the order
/// that they are in
Expand All @@ -172,12 +177,13 @@ pub enum ByteOrder {
HalfWordReversed,
}

#[derive(Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub(crate) enum TransferDirection {
Read,
Write,
}

#[derive(Debug)]
pub(crate) struct ActionSequence<'a> {
pub(crate) phase1: Option<DualDirectionActions>,
pub(crate) phase2: Option<SingleDirectionActions>,
Expand Down

0 comments on commit 69fc170

Please sign in to comment.