19#include "pw_bytes/span.h"
20#include "pw_spi/chip_selector.h"
21#include "pw_spi/initiator.h"
22#include "pw_status/status.h"
23#include "pw_status/try.h"
24#include "pw_sync/borrow.h"
63 : initiator_(initiator), config_(config), selector_(selector) {}
123 if ((selector_ !=
nullptr) &&
124 (behavior_ == ChipSelectBehavior::kPerTransaction) &&
125 (!first_write_read_)) {
133 : initiator_(std::move(other.initiator_)),
134 config_(other.config_),
135 selector_(other.selector_),
136 behavior_(other.behavior_),
137 first_write_read_(other.first_write_read_) {
138 other.selector_ =
nullptr;
142 initiator_ = std::move(other.initiator_);
143 config_ = other.config_;
144 selector_ = other.selector_;
145 other.selector_ =
nullptr;
146 behavior_ = other.behavior_;
147 first_write_read_ = other.first_write_read_;
151 Transaction(
const Transaction&) =
delete;
152 Transaction& operator=(
const Transaction&) =
delete;
184 if (first_write_read_) {
185 PW_TRY(initiator_->Configure(config_));
188 if ((behavior_ == ChipSelectBehavior::kPerWriteRead) ||
189 (first_write_read_)) {
191 first_write_read_ =
false;
194 auto status = initiator_->WriteRead(write_buffer, read_buffer);
196 if (behavior_ == ChipSelectBehavior::kPerWriteRead) {
209 : initiator_(std::move(initiator)),
211 selector_(&selector),
213 first_write_read_(true) {}
219 bool first_write_read_;
232 return Transaction(initiator_.acquire(), config_, selector_, behavior);
constexpr void IgnoreError() const
Definition: status.h:283
Definition: chip_selector.h:49
Status Deactivate()
Definition: chip_selector.h:93
Status Activate()
Definition: chip_selector.h:80
Transaction(Transaction &&other)
Transaction objects are moveable but not copyable.
Definition: device.h:132
Status Write(ConstByteSpan write_buffer)
Definition: device.h:166
Status WriteRead(ConstByteSpan write_buffer, ByteSpan read_buffer)
Definition: device.h:181
Status Read(ByteSpan read_buffer)
Definition: device.h:159
Status Write(ConstByteSpan write_buffer)
Definition: device.h:90
Transaction StartTransaction(ChipSelectBehavior behavior)
Definition: device.h:231
Status Read(ByteSpan read_buffer)
Definition: device.h:78
Status WriteRead(ConstByteSpan write_buffer, ByteSpan read_buffer)
Definition: device.h:110
ChipSelectBehavior
Definition: chip_selector.h:30
#define PW_TRY(expr)
Returns early if expr is a non-OK Status or Result.
Definition: try.h:27
Definition: initiator.h:67