REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
EEPROM25AA02.h
Go to the documentation of this file.
1// Copyright (c) 2024 anabrid GmbH
2// Contact: https://www.anabrid.com/licensing/
3//
4// SPDX-License-Identifier: MIT OR GPL-2.0-or-later
5
6#pragma once
7
8#include <algorithm>
9#include <bus/functions.h>
10
11namespace functions {
12
13class EEPROM25AA02 : public DataFunction {
14protected:
15 static constexpr uint8_t COMMAND_READ = 0b0000'0011;
16 static constexpr uint8_t COMMAND_READ_STATUS_REGISTER = 0b0000'0101;
17 static constexpr uint8_t COMMAND_WRITE = 0b0000'0010;
18 static constexpr uint8_t COMMAND_WRITE_STATUS_REGISTER = 0b0000'0001;
19 static constexpr uint8_t COMMAND_WRITE_ENABLE = 0b0000'0110;
20 static constexpr uint8_t COMMAND_WRITE_DISABLE = 0b0000'0100;
21
22 static constexpr uint8_t ADRESS_MASK = 0x0f;
23
24 static constexpr size_t MAX_ADDRESS = 255;
25
26 static constexpr bool _is_address_valid(size_t address) { return address <= MAX_ADDRESS; };
27
28public:
29 static const SPISettings DEFAULT_SPI_SETTINGS;
30 static constexpr uint8_t ADDRESS_UUID = 0xF8;
31
32 class Status {
33 private:
34 uint8_t data;
35
36 public:
37 explicit Status(const uint8_t data_) : data(data_ & 0b0000'1111) {}
38
39 explicit operator uint8_t() const { return data; }
40
41 bool is_write_in_progress() const { return data & 0b0000'0001; };
42
43 bool is_write_enabled() const { return data & 0b0000'0010; };
44
45 bool is_block_zero_protected() const { return data & 0b0000'0100; };
46
47 void set_block_zero_protection(bool on = true) {
48 if (on)
49 data |= 0b0000'0100;
50 else
51 data &= ~0b0000'0100;
52 }
53
54 bool is_block_one_protected() const { return data & 0b0000'1000; };
55
56 void set_block_one_protection(bool on = true) {
57 if (on)
58 data |= 0b0000'1000;
59 else
60 data &= ~0b0000'1000;
61 }
62
63 void set_block_protection(bool on = true) {
66 }
67
69
71 };
72
74
75 Status read_status_register() const;
76 bool write_status_register(const Status status) const;
77
80 size_t read(size_t address, size_t length, uint8_t *buffer) const;
82 bool read8(size_t address, uint8_t *data_out) const;
84 bool read16(size_t address, uint16_t *data_out) const;
86 bool read32(size_t address, uint32_t *data_out) const;
87
90 size_t write(size_t address, size_t length, const uint8_t *buffer) const;
92 bool write8(size_t address, uint8_t data) const;
94 bool write16(size_t address, uint16_t data) const;
96 bool write32(size_t address, uint32_t data) const;
97
98protected:
99 void set_write_enable() const;
100 void unset_write_enable() const;
101 bool await_write_complete() const;
102};
103
104} // namespace functions
A DataFunction class wraps SPI communication over the digital bus.
Definition functions.h:47
void set_block_protection(bool on=true)
Status(const uint8_t data_)
void set_block_one_protection(bool on=true)
void set_block_zero_protection(bool on=true)
bool await_write_complete() const
EEPROM25AA02(bus::addr_t address)
static constexpr uint8_t ADRESS_MASK
static constexpr bool _is_address_valid(size_t address)
void set_write_enable() const
static const SPISettings DEFAULT_SPI_SETTINGS
Definition EEPROM25AA02.h:8
bool read8(size_t address, uint8_t *data_out) const
Reads one byte at the specified address into the provided pointer. Returns 0 on failure.
bool read16(size_t address, uint16_t *data_out) const
Reads two bytes starting at the specified address into the provided pointer. Returns 0 on failure.
static constexpr size_t MAX_ADDRESS
static constexpr uint8_t COMMAND_WRITE_DISABLE
Status read_status_register() const
void unset_write_enable() const
static constexpr uint8_t COMMAND_READ
bool write16(size_t address, uint16_t data) const
Writes two bytes starting at the specified address Returns 0 on failure.
bool write_status_register(const Status status) const
size_t read(size_t address, size_t length, uint8_t *buffer) const
Reads the specified number of bytes starting at address into the specified buffer....
static constexpr uint8_t COMMAND_WRITE_STATUS_REGISTER
bool read32(size_t address, uint32_t *data_out) const
Reads four bytes starting at the specified address into the provided pointer. Returns 0 on failure.
static constexpr uint8_t COMMAND_READ_STATUS_REGISTER
size_t write(size_t address, size_t length, const uint8_t *buffer) const
Writes the specified number of bytes starting at address into the specified buffer....
bool write32(size_t address, uint32_t data) const
Writes four bytes starting at the specified address Returns 0 on failure.
static constexpr uint8_t ADDRESS_UUID
static constexpr uint8_t COMMAND_WRITE_ENABLE
static constexpr uint8_t COMMAND_WRITE
bool write8(size_t address, uint8_t data) const
Writes one byte at the specified address Returns 0 on failure.
const bus::addr_t address
Definition functions.h:23
utils::status status
Definition daq.h:21
uint32_t
Definition flasher.cpp:195
namespace for internal helpers
Definition icmd.h:6