-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework to accommodate changes in the Linux subsystem by #49.
- Loading branch information
1 parent
e699d6d
commit f34bdd9
Showing
6 changed files
with
127 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,45 @@ | ||
const NODE_COUNT: u8 = 4; | ||
|
||
/// small helper macro which handles the code duplication of declaring gpio lines. | ||
#[macro_export] | ||
macro_rules! gpio_output_lines { | ||
($chip:ident, $direction:expr, $output:expr) => { | ||
($chip:ident, $output:expr) => { | ||
$chip | ||
.request_lines(gpiod::Options::output($output).active($direction)) | ||
.request_lines(gpiod::Options::output($output)) | ||
.context(concat!("error initializing pin ", stringify!($output)))? | ||
}; | ||
} | ||
|
||
/// uses [`gpio_output_lines`] to declare an array of `gpiod::Lines` objects | ||
#[macro_export] | ||
macro_rules! gpio_output_array { | ||
($chip:ident, $direction:expr, $($pin:ident),+) => { | ||
($chip:ident, $($pin:ident),+) => { | ||
[ | ||
$( | ||
$crate::gpio_output_lines!($chip, $direction, [$pin]) | ||
$crate::gpio_output_lines!($chip, [$pin]) | ||
),* | ||
] | ||
}; | ||
} | ||
|
||
/// Helper function that converts a bitfield + mask into an iterator. This | ||
/// iterator iterates over each bit, and skips the bits that are not set in the | ||
/// nodes_mask. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `node_states` bit-field where each bit represents a node on the | ||
/// turing-pi board, if bit(n) = 1 equals 'select' and bit(n) = 0 equals | ||
/// 'unselect'. | ||
/// * `node_mask` mask which bits to select. | ||
/// | ||
/// # Returns | ||
/// | ||
/// iterator returns a tuple containing the index of a bit + the new value. | ||
pub fn bit_iterator(nodes_state: u8, nodes_mask: u8) -> impl Iterator<Item = (usize, u8)> { | ||
(0..NODE_COUNT).filter_map(move |n| { | ||
let mask = nodes_mask & (1 << n); | ||
let state = (nodes_state & mask) >> n; | ||
(mask != 0).then_some((n as usize, state)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.