C/C++ API Reference
Loading...
Searching...
No Matches
digital_io_mock.h
1// Copyright 2024 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#pragma once
15
16#include "pw_assert/check.h"
17#include "pw_chrono/system_clock.h"
18#include "pw_containers/inline_deque.h"
19#include "pw_digital_io/digital_io.h"
20#include "pw_result/result.h"
21
22namespace pw::digital_io {
23
25
32 public:
33 using State = ::pw::digital_io::State;
35
36 struct Event {
37 pw::chrono::SystemClock::time_point timestamp;
38 State state;
39 };
40
41 pw::InlineDeque<Event>& events() { return events_; }
42
43 protected:
44 DigitalInOutMockImpl(Clock& clock, pw::InlineDeque<Event>& events);
45
46 private:
47 pw::Status DoEnable(bool) override { return pw::OkStatus(); }
48
50
51 pw::Status DoSetState(State state) override;
52
53 Clock& clock_;
55};
56
57template <size_t kCapacity>
59 public:
60 static_assert(kCapacity > 0);
61
63 DigitalInOutMock(Clock& clock) : DigitalInOutMockImpl(clock, events_) {
64 PW_CHECK_OK(SetState(State::kInactive));
65 }
66
67 private:
69};
70
71} // namespace pw::digital_io
Definition: poll.h:25
Definition: status.h:109
Definition: system_clock.h:179
Definition: digital_io.h:673
Status SetState(State state)
Definition: digital_io.h:120
Definition: digital_io_mock.h:58
Definition: digital_io_mock.h:31
static VirtualClock< SystemClock > & RealClock()
Returns a reference to the real system clock to aid instantiation.
pw::Status DoSetState(State state) override
pw::Result< State > DoGetState() override
pw::Status DoEnable(bool) override
Definition: digital_io_mock.h:47
constexpr Status OkStatus()
Definition: status.h:297
GPIO library.
Definition: digital_io.h:24
Definition: digital_io_mock.h:36