@@ -24,9 +24,16 @@ pub struct ExclusiveDevice<BUS, CS, D> {
2424
2525impl < BUS , CS , D > ExclusiveDevice < BUS , CS , D > {
2626 /// 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.
2730 #[ 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 } )
3037 }
3138
3239 /// Returns a reference to the underlying bus object.
@@ -45,6 +52,9 @@ impl<BUS, CS, D> ExclusiveDevice<BUS, CS, D> {
4552impl < BUS , CS > ExclusiveDevice < BUS , CS , super :: NoDelay > {
4653 /// Create a new [`ExclusiveDevice`] without support for in-transaction delays.
4754 ///
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+ ///
4858 /// **Warning**: The returned instance *technically* doesn't comply with the `SpiDevice`
4959 /// contract, which mandates delay support. It is relatively rare for drivers to use
5060 /// 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> {
6070 /// The returned device will panic if you try to execute a transaction
6171 /// that contains any operations of type [`Operation::DelayNs`].
6272 #[ 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 {
6579 bus,
6680 cs,
6781 delay : super :: NoDelay ,
68- }
82+ } )
6983 }
7084}
7185
0 commit comments