|
| | AT25040B (Port &port, const Config &config={}) noexcept |
| | Bind the driver to a port and store the configuration. No I/O, cannot fail.
|
| |
|
| AT25040B (const AT25040B &)=delete |
| | One driver object per chip.
|
| |
|
AT25040B & | operator= (const AT25040B &)=delete |
| | One driver object per chip.
|
| |
|
| Result< void > | EnsureInitialized () noexcept |
| | Check that an AT25xxxB answers, once: the only way to initialise the driver.
|
| |
| bool | IsInitialized () const noexcept |
| |
| Result< void > | Deinitialize () noexcept |
| | Leave the chip safe and mark the driver uninitialised: WRDI, then WP parked.
|
| |
|
| Result< void > | ApplyConfig (const Config &config) noexcept |
| | Replace the configuration. Never any I/O: the chip has no setting to write. The variant and the checks apply from the next call; check_write_enable from the next start.
|
| |
| const Config & | GetConfig () const &noexcept |
| |
|
void | GetConfig () const &&=delete |
| | No reference into a temporary driver: it would dangle.
|
| |
| std::size_t | GetCapacityBytes () const noexcept |
| |
|
| Result< void > | Read (uint16_t address, std::span< uint8_t > out, Verify verify=Verify::None) noexcept |
| | Read out.size() bytes from address (sequential READ, section 6, "Read Sequence").
|
| |
| Result< void > | Write (uint16_t address, std::span< const uint8_t > data, Verify verify=Verify::None) noexcept |
| | Write data from address: one WRITE and one write cycle per 8-byte page.
|
| |
|
| Result< Status > | ReadStatus () noexcept |
| | One status read (RDSR), decoded. Does not wait: during a write cycle it returns busy = true.
|
| |
| Result< BlockProtect > | GetBlockProtection () noexcept |
| | The block protection level, from the status (Table 6-4). Waits for a running write cycle first.
|
| |
| Result< void > | SetBlockProtection (BlockProtect level) noexcept |
| | Set BP1:BP0 (WRSR, section 6, "Write Status Register").
|
| |
| uint8_t | GetLastStatusByte () const noexcept |
| | The last status byte the driver read, by any call, for logs: 0xFF before the first. No I/O (handbook KB-CPP-129).
|
| |
| Result< uint8_t > | ReadRawStatus () noexcept |
| | Read the status register once: one RDSR transfer, no wait, no retry, no decoding and no check of the byte (handbook KB-CPP-129).
|
| |
template<SpiPort Port>
class at25040b::AT25040B< Port >
Driver for one AT25010B, AT25020B or AT25040B on a platform port.
Lifecycle: construct with the configuration (no I/O), then EnsureInitialized(), the one way to start (bus up, identity check), use, optionally Deinitialize(). Every call that touches the chip returns Error::NotInitialized until EnsureInitialized() has succeeded; no call starts the chip as a side effect, so a probe happens only when you ask for it.
Every call that reads or writes the array first reads the status and, if a write cycle runs, waits for it (at most Config::write_timeout_us): it never sends an instruction the chip would ignore. Every write and every block-protection change waits for its own write cycle before it returns, so the next call finds the chip ready.
Optional port hooks, found at compile time:
| Hook | Used for | Without it |
bool GpioSet(CtrlPin, GpioSignal) noexcept | WP: released (high) only while a write, a block-protection change or the identity check runs; parked (low) after, on success and failure | WP must be tied high for writes (or low, read-only: set Config::check_write_enable = false) |
void Log(LogLevel, const char* message) noexcept | One line per lifecycle event or failure | Nothing is logged |
A hook declared with the wrong signature (for example void GpioSet(...)) is a compile error. The driver never drives HOLD: tie it high (a HOLD strapped to CS makes every status read fail).
- Template Parameters
-
Check that an AT25xxxB answers, once: the only way to initialise the driver.
Brings the bus up, parks WP (with GpioSet()), then checks the identity, strongest test first: the status is read until it is not busy (a write cycle may still run after an MCU reset), then once more, and both reads must be the same idle status (bits 7 to 4 and RDY clear). With Config::check_write_enable (the default) it then releases WP, clears the latch if it was set (WRDI), sends WREN and reads WEN = 1, sends WRDI and reads WEN = 0, and parks WP: a bus whose MISO floats or is stuck cannot pass this, and nothing is programmed. Without it, the first kIdentityReadBytes are read twice and must be equal. After it succeeds, later calls return Ok at once with no I/O; after it fails, the next call starts again from the beginning.
- Returns
Ok, InvalidArgument (the configuration fails Validate(); no I/O), Bus, Pin (the WP hook failed), NoDevice (status 0xFF throughout Config::write_timeout_us), DeviceIdMismatch or BusNoise.
Write data from address: one WRITE and one write cycle per 8-byte page.
Reads the status first and refuses a range that overlaps the block-protected part (BlockProtected) before sending anything else. Then, with WP released: per page WREN, a status read that must show WEN = 1 (WriteProtected otherwise), the WRITE, a wait for the write cycle (Timeout after Config::write_timeout_us), a status that must show WEN = 0 again (WriteMismatch when the chip ignored the WRITE; this reuses the last poll, no extra transfer) and, with Verify::ReadBack, a read back (WriteMismatch). WP is parked after, on success and failure; a failure after WREN sends WRDI, so the latch is not left set.
Cost with Verify::None: 2 status reads, then per page WREN, RDSR, WRITE and the status polls of the write cycle (at least 2: the idle status is confirmed), so 2 + 5 x pages transfers plus one RDSR per extra 100 µs poll. Verify::ReadBack adds one READ per page.
After a failure, the pages before the failing one hold the new data (and were read back, with Verify::ReadBack); the failing page may hold old, new or, after a failed WRITE transfer, partly written data; nothing after it and nothing outside the range is touched.
- Parameters
-
- Returns
Ok, NotInitialized, InvalidArgument (nothing sent; also for a verify that is not an enumerator), Bus, Pin (the WP hook failed), Timeout, BusNoise, BlockProtected, WriteProtected or WriteMismatch.