12#ifndef AT25040B_TYPES_HPP
13#define AT25040B_TYPES_HPP
19#include "at25040b_version.h"
36enum class [[nodiscard]]
Error : uint8_t {
83 return "NotInitialized";
85 return "InvalidArgument";
91 return "DeviceIdMismatch";
105 return "WriteProtected";
107 return "BlockProtected";
109 return "WriteMismatch";
131 [[nodiscard]]
constexpr bool ok() const noexcept {
132 return error == Error::Ok;
135 constexpr explicit operator bool() const noexcept {
145 return {v, Error::Ok};
163 [[nodiscard]]
constexpr bool ok() const noexcept {
164 return error == Error::Ok;
167 constexpr explicit operator bool() const noexcept {
276 "a chunk is a whole number of pages, so a page read back fits in one READ");
280 "the status poll counts whole intervals up to the timeout");
313 return size - (size / 4U);
381 if (!detail::IsEnumerator(config.variant)) {
391static_assert(
Validate(Config{}) ==
Error::Ok,
"the default configuration is valid");
395 return AT25040B_VERSION_STRING;
399 return AT25040B_VERSION_MAJOR;
403 return AT25040B_VERSION_MINOR;
407 return AT25040B_VERSION_PATCH;
Compile-time helpers of the AT25040B driver: exact hook matching, typed register fields and enumerati...
constexpr Error Validate(const Config &config) noexcept
Check a configuration without touching the chip.
Definition at25040b_types.hpp:380
constexpr uint32_t kPollIntervalUs
Time between two status reads while the driver waits for a write cycle, in microseconds.
Definition at25040b_types.hpp:269
constexpr std::size_t kPageSizeBytes
Bytes per page: a WRITE never crosses an 8-byte page (section 6, "Write Sequence").
Definition at25040b_types.hpp:243
constexpr const char * GetDriverVersion() noexcept
Definition at25040b_types.hpp:394
constexpr std::size_t CapacityBytes(Variant variant) noexcept
Array size of a variant.
Definition at25040b_types.hpp:287
Error
Why a call failed. Every call of the driver returns one of these in its Result.
Definition at25040b_types.hpp:36
Verify
Extra verification for one Read() or Write() call, chosen per call.
Definition at25040b_types.hpp:226
LogLevel
Severity passed to the optional Log() hook.
Definition at25040b_types.hpp:186
constexpr std::size_t ProtectedFrom(Variant variant, BlockProtect level) noexcept
First protected address of a protection level (Table 6-4).
Definition at25040b_types.hpp:307
constexpr std::size_t kMaxTransferBytes
Longest transfer the driver asks of the port: opcode, address byte and kReadChunkBytes.
Definition at25040b_types.hpp:265
constexpr uint32_t kWriteCycleMaxUs
Longest self-timed write cycle t_WC, in microseconds (Table 4-3, maximum, every supply).
Definition at25040b_types.hpp:267
constexpr uint32_t GetDriverVersionPatch() noexcept
Definition at25040b_types.hpp:406
constexpr std::size_t kReadChunkBytes
Data bytes per READ transfer: Read() splits longer requests into transfers of at most this many data ...
Definition at25040b_types.hpp:263
constexpr uint32_t GetDriverVersionMinor() noexcept
Definition at25040b_types.hpp:402
constexpr uint32_t kWriteTimeoutMaxUs
Longest Config::write_timeout_us the driver accepts, in microseconds (one second).
Definition at25040b_types.hpp:271
constexpr std::size_t kIdentityReadBytes
Bytes from address 0 that EnsureInitialized() reads twice when check_write_enable is off.
Definition at25040b_types.hpp:273
BlockProtect
Block write protection level, BP1:BP0 in the status register (Table 6-4).
Definition at25040b_types.hpp:212
constexpr const char * ToString(Error error) noexcept
The name of an error, for logs.
Definition at25040b_types.hpp:76
constexpr uint32_t GetDriverVersionMajor() noexcept
Definition at25040b_types.hpp:398
Variant
Which part of the family is fitted. The chip cannot tell its size, so it is configured.
Definition at25040b_types.hpp:200
@ InvalidArgument
An argument or a Config field is out of range; nothing was sent.
@ Crc
Not returned by this driver (the chip sends no CRC).
@ Bus
A transfer hook (Transfer(), EnsureInitialized()) returned false.
@ DeviceFault
Not returned by this driver (the chip reports no faults).
@ NotInitialized
EnsureInitialized() has not succeeded, or Deinitialize() ran since.
@ Unsupported
Not returned by this driver.
@ Busy
Not returned by this driver: every call waits for a write cycle.
@ Warning
Something unexpected that the driver recovered from.
@ Info
Lifecycle events: initialised.
@ Debug
Detail for bring-up.
@ UpperQuarter
01: the top quarter is read-only (0x180 to 0x1FF on the AT25040B).
@ None
BP1:BP0 = 00: nothing protected. The value of a new part.
@ All
11: the whole array is read-only.
@ UpperHalf
10: the top half is read-only (0x100 to 0x1FF on the AT25040B).
@ At25040b
512 bytes (4 Kbit), A8 in the opcode. The default.
@ At25020b
256 bytes (2 Kbit).
@ At25010b
128 bytes (1 Kbit).
The AT25040B driver: everything it declares lives here; internals in detail.
Definition at25040b.hpp:30
What the driver is told about the board. The chip itself has nothing to configure: its only setting,...
Definition at25040b_types.hpp:361
Variant variant
Definition at25040b_types.hpp:362
bool check_write_enable
Definition at25040b_types.hpp:369
uint32_t write_timeout_us
Longest wait for a write cycle to end, in microseconds; at least kWriteCycleMaxUs.
Definition at25040b_types.hpp:371
constexpr bool ok() const noexcept
Definition at25040b_types.hpp:163
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition at25040b_types.hpp:180
static constexpr Result Success() noexcept
Definition at25040b_types.hpp:172
The value of a call, or why there is none.
Definition at25040b_types.hpp:126
static constexpr Result Success(T v) noexcept
A successful result.
Definition at25040b_types.hpp:144
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition at25040b_types.hpp:152
constexpr bool ok() const noexcept
Definition at25040b_types.hpp:131
The status register, decoded (Tables 6-2 and 6-3).
Definition at25040b_types.hpp:234
bool busy
A write cycle runs: every bit reads 1, the other fields mean nothing.
Definition at25040b_types.hpp:236
BlockProtect block_protect
BP1:BP0.
Definition at25040b_types.hpp:238
bool write_enabled
WEN: the write enable latch is set.
Definition at25040b_types.hpp:237
uint8_t raw
The byte RDSR returned.
Definition at25040b_types.hpp:235