AT25040B Driver 0.1.0
API reference
Loading...
Searching...
No Matches
at25040b_registers.hpp
Go to the documentation of this file.
1
10#ifndef AT25040B_REGISTERS_HPP
11#define AT25040B_REGISTERS_HPP
12
13#include <cstdint>
14
15#include "at25040b_detail.hpp"
16
18namespace at25040b::reg {
19
20using detail::operator""_u8;
21
22// Instructions (Table 6-1). Every opcode is `0000 xyyy`; bit 3 ("X") is a don't-care for the first
23// four and carries address bit A8 of READ and WRITE on the AT25040B (Table 6-1, note 1).
24inline constexpr uint8_t kWren = 0x06;
25inline constexpr uint8_t kWrdi = 0x04;
26inline constexpr uint8_t kRdsr = 0x05;
27inline constexpr uint8_t kWrsr = 0x01;
28inline constexpr uint8_t kRead = 0x03;
29inline constexpr uint8_t kWrite = 0x02;
30
32inline constexpr uint8_t kOpcodeA8 = 0x08;
34inline constexpr uint16_t kAddressA8 = 0x100;
36inline constexpr uint16_t kAddressLowMask = 0xFF;
38inline constexpr uint16_t kAddressMax = 0x1FF;
39
40// Status register (Tables 6-2 and 6-3).
41inline constexpr uint8_t kStatusRdy = 0x01;
42inline constexpr uint8_t kStatusWen = 0x02;
43inline constexpr uint8_t kStatusBp0 = 0x04;
44inline constexpr uint8_t kStatusBp1 = 0x08;
45inline constexpr uint8_t kStatusBpMask = 0x0C;
46inline constexpr uint8_t kStatusBpShift = 2;
47inline constexpr uint8_t kStatusUnused = 0xF0;
48inline constexpr uint8_t kStatusBusyByte = 0xFF;
49
51using StatusBp = detail::Field<uint8_t, kStatusBpShift, 2U>;
52static_assert(StatusBp::kMask == kStatusBpMask, "BP1:BP0 are bits 3 and 2 (Table 6-2)");
53static_assert((static_cast<uint32_t>(kStatusBp0) | static_cast<uint32_t>(kStatusBp1)) ==
54 static_cast<uint32_t>(kStatusBpMask));
55
62constexpr bool IsIdleStatus(uint8_t status) noexcept {
63 return (static_cast<uint32_t>(status) &
64 (static_cast<uint32_t>(kStatusUnused) | static_cast<uint32_t>(kStatusRdy))) == 0U;
65}
66
67static_assert(IsIdleStatus(0x00_u8) && IsIdleStatus(0x0E_u8),
68 "WEN and BP1:BP0 may be set when idle");
69static_assert(!IsIdleStatus(kStatusBusyByte) && !IsIdleStatus(kRdsr) && !IsIdleStatus(0x10_u8),
70 "busy, an echoed RDSR opcode and a set unused bit are not idle");
71
72} // namespace at25040b::reg
73
74#endif // AT25040B_REGISTERS_HPP
Compile-time helpers of the AT25040B driver: exact hook matching, typed register fields and enumerati...
Opcodes and bit masks of the chip, as constexpr values.
Definition at25040b_registers.hpp:18
constexpr uint8_t kWrite
WRITE: write data to the array.
Definition at25040b_registers.hpp:29
constexpr uint8_t kRdsr
RDSR: read the status register.
Definition at25040b_registers.hpp:26
constexpr uint8_t kStatusBpMask
BP1 and BP0 together.
Definition at25040b_registers.hpp:45
constexpr uint8_t kStatusRdy
RDY: 1 while a write cycle runs.
Definition at25040b_registers.hpp:41
detail::Field< uint8_t, kStatusBpShift, 2U > StatusBp
BP1:BP0 as a field of the status byte (Table 6-4): two bits from bit 2.
Definition at25040b_registers.hpp:51
constexpr uint8_t kStatusBpShift
Position of BP0.
Definition at25040b_registers.hpp:46
constexpr uint8_t kStatusBp0
BP0: block protection, low bit.
Definition at25040b_registers.hpp:43
constexpr uint16_t kAddressMax
The highest address any part of the family decodes (A8 to A0, AT25040B).
Definition at25040b_registers.hpp:38
constexpr uint16_t kAddressLowMask
Address bits A7 to A0: the address byte of READ and WRITE (Figures 7-6 and 7-7).
Definition at25040b_registers.hpp:36
constexpr uint16_t kAddressA8
Address bit that goes into the opcode instead of the address byte.
Definition at25040b_registers.hpp:34
constexpr uint8_t kOpcodeA8
Bit of a READ or WRITE opcode that carries address bit A8 (AT25040B only, Table 6-1 note 1).
Definition at25040b_registers.hpp:32
constexpr uint8_t kRead
READ: read data from the array.
Definition at25040b_registers.hpp:28
constexpr uint8_t kWrdi
WRDI: reset the write enable latch.
Definition at25040b_registers.hpp:25
constexpr uint8_t kStatusUnused
Bits 7 to 4: 0 when no write cycle runs.
Definition at25040b_registers.hpp:47
constexpr bool IsIdleStatus(uint8_t status) noexcept
True for a status byte an idle chip can return: bits 7 to 4 clear and RDY clear (Table 6-3)....
Definition at25040b_registers.hpp:62
constexpr uint8_t kStatusBp1
BP1: block protection, high bit.
Definition at25040b_registers.hpp:44
constexpr uint8_t kWrsr
WRSR: write the status register (BP1, BP0).
Definition at25040b_registers.hpp:27
constexpr uint8_t kStatusWen
WEN: 1 when the write enable latch is set.
Definition at25040b_registers.hpp:42
constexpr uint8_t kStatusBusyByte
Every bit reads 1 during a write cycle.
Definition at25040b_registers.hpp:48
constexpr uint8_t kWren
WREN: set the write enable latch.
Definition at25040b_registers.hpp:24