Skip to content

Commit 96f8f61

Browse files
Merge #104
104: Add constants for various 'SPI mode numbers' r=therealprof a=RandomInsano I found myself being pretty confused by the terminology within the HAL for SPI configuration as it seems the terms are ST-specific. Through some Googling I figured out what the modes *should* be, but I'm a hobbyist and would welcome a second opinion. Hopefully these static constants help others figure it out faster. Feedback welcome! Co-authored-by: Edwin Amsler <[email protected]>
2 parents f91fc4b + 14160d3 commit 96f8f61

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/spi.rs

+24
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,27 @@ pub struct Mode {
5252
/// Clock phase
5353
pub phase: Phase,
5454
}
55+
56+
/// Helper for CPOL = 0, CPHA = 0
57+
pub const MODE_0: Mode = Mode {
58+
polarity: Polarity::IdleLow,
59+
phase: Phase::CaptureOnFirstTransition,
60+
};
61+
62+
/// Helper for CPOL = 0, CPHA = 1
63+
pub const MODE_1: Mode = Mode {
64+
polarity: Polarity::IdleLow,
65+
phase: Phase::CaptureOnSecondTransition,
66+
};
67+
68+
/// Helper for CPOL = 1, CPHA = 0
69+
pub const MODE_2: Mode = Mode {
70+
polarity: Polarity::IdleHigh,
71+
phase: Phase::CaptureOnFirstTransition,
72+
};
73+
74+
/// Helper for CPOL = 1, CPHA = 1
75+
pub const MODE_3: Mode = Mode {
76+
polarity: Polarity::IdleHigh,
77+
phase: Phase::CaptureOnSecondTransition,
78+
};

0 commit comments

Comments
 (0)