-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmemory.h
33 lines (23 loc) · 754 Bytes
/
memory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// (C) 2018-2024 by Folkert van Heusden
// Released under MIT license
#pragma once
#include "gen.h"
#include <ArduinoJson.h>
#include <cstdint>
class memory
{
private:
const uint32_t size { 0 };
uint8_t *m { nullptr };
public:
memory(const uint32_t size);
~memory();
uint32_t get_memory_size() const { return size; }
void reset();
JsonDocument serialize() const;
static memory *deserialize(const JsonVariantConst j);
uint16_t read_byte(const uint32_t a) const { return m[a]; }
void write_byte(const uint32_t a, const uint16_t v) { m[a] = v; }
uint16_t read_word(const uint32_t a) const { return m[a] | (m[a + 1] << 8); }
void write_word(const uint32_t a, const uint16_t v) { m[a] = v; m[a + 1] = v >> 8; }
};