• 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 #include <array>
16 #include <optional>
17 
18 #include "gtest/gtest.h"
19 #include "pw_spi/chip_selector.h"
20 #include "pw_spi/device.h"
21 #include "pw_spi/initiator.h"
22 #include "pw_status/status.h"
23 #include "pw_sync/borrow.h"
24 #include "pw_sync/mutex.h"
25 
26 namespace pw::spi {
27 namespace {
28 
29 const pw::spi::Config kConfig = {.polarity = ClockPolarity::kActiveHigh,
30                                  .phase = ClockPhase::kFallingEdge,
31                                  .bits_per_word = BitsPerWord(8),
32                                  .bit_order = BitOrder::kMsbFirst};
33 
34 class SpiTestDevice : public ::testing::Test {
35  public:
SpiTestDevice()36   SpiTestDevice()
37       : initiator_(),
38         chip_selector_(),
39         initiator_lock_(),
40         borrowable_initiator_(initiator_, initiator_lock_),
41         device_(borrowable_initiator_, kConfig, chip_selector_) {}
42 
43  private:
44   // Stub SPI Initiator/ChipSelect objects, used to exercise public API surface.
45   class TestInitiator : public Initiator {
46    public:
Configure(const Config &)47     Status Configure(const Config& /*config */) override { return OkStatus(); }
WriteRead(ConstByteSpan,ByteSpan)48     Status WriteRead(ConstByteSpan /* write_buffer */,
49                      ByteSpan /* read_buffer */) override {
50       return OkStatus();
51     }
52   };
53 
54   class TestChipSelector : public ChipSelector {
55    public:
SetActive(bool)56     Status SetActive(bool /*active*/) override { return OkStatus(); }
57   };
58 
59   TestInitiator initiator_;
60   TestChipSelector chip_selector_;
61   sync::VirtualMutex initiator_lock_;
62   sync::Borrowable<Initiator> borrowable_initiator_;
63   Device device_;
64 };
65 
66 // Simple test ensuring the SPI HAL compiles
TEST_F(SpiTestDevice,CompilationSucceeds)67 TEST_F(SpiTestDevice, CompilationSucceeds) {
68   // arrange
69   // act
70   // assert
71   EXPECT_TRUE(true);
72 }
73 
74 }  // namespace
75 }  // namespace pw::spi
76