libepaper 2.0.0
A C++23 library for controlling Waveshare e-paper displays on Raspberry Pi, featuring transparent sleep/wake management and a fluent builder API.
Loading...
Searching...
No Matches
mock_spi.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "epaper/hal/spi.hpp"
4#include <cstddef>
5#include <cstdint>
6#include <deque>
7#include <span>
8#include <vector>
9
10namespace epaper::hal {
11
28public:
37 auto transfer(std::uint8_t byte) -> std::uint8_t {
38 sent_bytes_.push_back(byte);
39 if (!response_queue_.empty()) {
40 auto response = response_queue_.front();
41 response_queue_.pop_front();
42 return response;
43 }
44 return 0x00; // Default response
45 }
46
54 auto write(std::span<const std::byte> data) -> void {
55 for (auto byte : data) {
56 sent_bytes_.push_back(static_cast<std::uint8_t>(byte));
57 }
58 }
59
64 [[nodiscard]] auto sent_bytes() const -> const std::vector<std::uint8_t> & { return sent_bytes_; }
65
70 [[nodiscard]] auto transfer_count() const -> std::size_t { return sent_bytes_.size(); }
71
76 auto queue_response(std::uint8_t byte) -> void { response_queue_.push_back(byte); }
77
81 auto reset() -> void {
82 sent_bytes_.clear();
83 response_queue_.clear();
84 }
85
86private:
87 std::vector<std::uint8_t> sent_bytes_;
88 std::deque<std::uint8_t> response_queue_;
89};
90
91static_assert(SpiBus<MockSpiBus>, "MockSpiBus must satisfy SpiBus concept");
92
93} // namespace epaper::hal
Definition mock_spi.hpp:27
auto sent_bytes() const -> const std::vector< std::uint8_t > &
Get vector of all bytes sent via transfer() and write().
Definition mock_spi.hpp:64
auto reset() -> void
Reset bus state for new test.
Definition mock_spi.hpp:81
auto transfer(std::uint8_t byte) -> std::uint8_t
Full-duplex byte transfer.
Definition mock_spi.hpp:37
auto transfer_count() const -> std::size_t
Get total number of bytes transferred.
Definition mock_spi.hpp:70
auto queue_response(std::uint8_t byte) -> void
Queue a response byte for next transfer() call.
Definition mock_spi.hpp:76
auto write(std::span< const std::byte > data) -> void
Bulk write operation.
Definition mock_spi.hpp:54
Definition gpio.hpp:62
SPI bus concept for hardware abstraction.