• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #pragma once
16 
17 #include <cstdint>
18 
19 #include "pw_status/status.h"
20 
21 namespace pw::spi {
22 
23 // Configuration data used to determine how the Chip Select signal is controlled
24 // throughout a transaction.
25 // `kPerWriteRead` indicates that the chip-select signal should be
26 // activated/deactivated between calls to WriteRead()
27 enum class ChipSelectBehavior : uint8_t {
28   kPerWriteRead,
29   kPerTransaction,
30 };
31 
32 // The ChipSelector class provides an abstract interface for controlling the
33 // chip-select signal associated with a specific SPI peripheral.
34 class ChipSelector {
35  public:
36   virtual ~ChipSelector() = default;
37 
38   // SetActive sets the state of the chip-select signal to the value represented
39   // by the `active` parameter.  Passing a value of `true` will activate the
40   // chip-select signal, and `false` will deactive the chip-select signal.
41   // Returns OkStatus() on success, and implementation-specific values on
42   // failure.
43   virtual Status SetActive(bool active) = 0;
44 
45   // Helper method to activate the chip-select signal
46   // Returns OkStatus() on success, and implementation-specific values on
47   // failure.
Activate()48   Status Activate() { return SetActive(true); }
49 
50   // Helper method to deactivate the chip-select signal
51   // Returns OkStatus() on success, and implementation-specific values on
52   // failure.
Deactivate()53   Status Deactivate() { return SetActive(false); }
54 };
55 
56 }  // namespace pw::spi
57