1 // Copyright 2023 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 #include "pw_spi_rp2040/initiator.h"
15
16 #include <gtest/gtest.h>
17
18 #include "hardware/spi.h"
19 #include "pw_digital_io/polarity.h"
20 #include "pw_digital_io_rp2040/digital_io.h"
21 #include "pw_spi/chip_selector_digital_out.h"
22 #include "pw_spi/device.h"
23 #include "pw_sync/borrow.h"
24 #include "pw_sync/mutex.h"
25
26 using pw::spi::DigitalOutChipSelector;
27 using pw::spi::Initiator;
28 using pw::spi::Rp2040Initiator;
29
30 namespace pw::spi {
31 namespace {
32
33 constexpr pw::spi::Config kSpiConfig8Bit{
34 .polarity = pw::spi::ClockPolarity::kActiveHigh,
35 .phase = pw::spi::ClockPhase::kFallingEdge,
36 .bits_per_word = pw::spi::BitsPerWord(8),
37 .bit_order = pw::spi::BitOrder::kMsbFirst,
38 };
39
TEST(InitiatorTest,Init)40 TEST(InitiatorTest, Init) {
41 // Simple test only meant to ensure module is compiled.
42 pw::digital_io::Rp2040DigitalInOut display_cs_pin({
43 .pin = 12,
44 .polarity = pw::digital_io::Polarity::kActiveLow,
45 });
46 DigitalOutChipSelector spi_chip_selector(display_cs_pin);
47 Rp2040Initiator spi_initiator(spi0);
48
49 pw::sync::VirtualMutex initiator_mutex;
50 pw::sync::Borrowable<pw::spi::Initiator> borrowable_initiator(
51 spi_initiator, initiator_mutex);
52 pw::spi::Device spi_8_bit(
53 borrowable_initiator, kSpiConfig8Bit, spi_chip_selector);
54 }
55
56 } // namespace
57 } // namespace pw::spi
58