@@ -24,9 +24,16 @@ pub struct ExclusiveDevice<BUS, CS, D> {
24
24
25
25
impl < BUS , CS , D > ExclusiveDevice < BUS , CS , D > {
26
26
/// Create a new [`ExclusiveDevice`].
27
+ ///
28
+ /// This sets the `cs` pin high, and returns an error if that fails. It is recommended
29
+ /// to set the pin high the moment it's configured as an output, to avoid glitches.
27
30
#[ inline]
28
- pub fn new ( bus : BUS , cs : CS , delay : D ) -> Self {
29
- Self { bus, cs, delay }
31
+ pub fn new ( bus : BUS , mut cs : CS , delay : D ) -> Result < Self , CS :: Error >
32
+ where
33
+ CS : OutputPin ,
34
+ {
35
+ cs. set_high ( ) ?;
36
+ Ok ( Self { bus, cs, delay } )
30
37
}
31
38
32
39
/// Returns a reference to the underlying bus object.
@@ -45,6 +52,9 @@ impl<BUS, CS, D> ExclusiveDevice<BUS, CS, D> {
45
52
impl < BUS , CS > ExclusiveDevice < BUS , CS , super :: NoDelay > {
46
53
/// Create a new [`ExclusiveDevice`] without support for in-transaction delays.
47
54
///
55
+ /// This sets the `cs` pin high, and returns an error if that fails. It is recommended
56
+ /// to set the pin high the moment it's configured as an output, to avoid glitches.
57
+ ///
48
58
/// **Warning**: The returned instance *technically* doesn't comply with the `SpiDevice`
49
59
/// contract, which mandates delay support. It is relatively rare for drivers to use
50
60
/// in-transaction delays, so you might still want to use this method because it's more practical.
@@ -60,12 +70,16 @@ impl<BUS, CS> ExclusiveDevice<BUS, CS, super::NoDelay> {
60
70
/// The returned device will panic if you try to execute a transaction
61
71
/// that contains any operations of type [`Operation::DelayNs`].
62
72
#[ inline]
63
- pub fn new_no_delay ( bus : BUS , cs : CS ) -> Self {
64
- Self {
73
+ pub fn new_no_delay ( bus : BUS , mut cs : CS ) -> Result < Self , CS :: Error >
74
+ where
75
+ CS : OutputPin ,
76
+ {
77
+ cs. set_high ( ) ?;
78
+ Ok ( Self {
65
79
bus,
66
80
cs,
67
81
delay : super :: NoDelay ,
68
- }
82
+ } )
69
83
}
70
84
}
71
85
0 commit comments