REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
cblock.h
Go to the documentation of this file.
1// Copyright (c) 2024 anabrid GmbH
2// Contact: https://www.anabrid.com/licensing/
3// SPDX-License-Identifier: MIT OR GPL-2.0-or-later
4
5#pragma once
6
7#include <array>
8#include <cstdint>
9
10#include "block/base.h"
11#include "bus/bus.h"
12#include "chips/AD5452.h"
13#include "chips/SR74HCT595.h"
14
15namespace platform {
16class Calibration;
17}
18
19namespace blocks {
20
21// ██ ██ █████ ██
22// ██ ██ ██ ██ ██
23// ███████ ███████ ██
24// ██ ██ ██ ██ ██
25// ██ ██ ██ ██ ███████
26
28public:
29 virtual bool write_factor(uint8_t idx, float value) = 0;
30};
31
32class CBlockHALDummy : public CBlockHAL {
33public:
34 bool write_factor(uint8_t idx, float value) override { return true; }
35
36 metadata::eui_t get_entity_eui() const override { return {}; }
37};
38
40protected:
41 std::array<const functions::AD5452, 32> f_coeffs;
43
44public:
45 static std::array<const functions::AD5452, 32> make_f_coeffs(bus::addr_t block_address,
46 std::array<const uint8_t, 32> f_coeffs_cs);
47
48 CBlockHAL_Common(bus::addr_t block_address, std::array<const uint8_t, 32> f_coeffs_cs);
49
50 bool write_factor(uint8_t idx, float value) override;
51
52 metadata::eui_t get_entity_eui() const override { return f_meta.read_eui(); }
53};
54
56public:
57 explicit CBlockHAL_V_1_1_X(bus::addr_t block_address);
58};
59
61public:
62 explicit CBlockHAL_V_1_0_X(bus::addr_t block_address);
63};
64
65// ██████ █████ ███████ ███████ ██████ ██ █████ ███████ ███████
66// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
67// ██████ ███████ ███████ █████ ██ ██ ███████ ███████ ███████
68// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
69// ██████ ██ ██ ███████ ███████ ██████ ███████ ██ ██ ███████ ███████
70
83class CBlock : public FunctionBlock {
84public:
85 // Entity hardware identifier information.
86 // For CBlocks, there is only one entity type possible currently.
87 static constexpr auto CLASS_ = entities::EntityClass::C_BLOCK;
88 static constexpr uint8_t TYPE = 1;
89
90 static CBlock *from_entity_classifier(entities::EntityClassifier classifier, bus::addr_t block_address);
91
92public:
93 static constexpr uint8_t BLOCK_IDX = bus::C_BLOCK_IDX;
94
95 static constexpr uint8_t COEFF_BASE_FUNC_IDX = 1;
96
97 static constexpr uint8_t NUM_COEFF = 32;
98
99 static constexpr std::array<uint8_t, NUM_COEFF> INPUT_IDX_RANGE() {
100 return {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
101 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
102 };
103
104 static constexpr std::array<uint8_t, NUM_COEFF> OUTPUT_IDX_RANGE() {
105 return {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
106 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
107 };
108
109 static constexpr float MIN_FACTOR = -1.01f;
110 static constexpr float MAX_FACTOR = +1.01f;
111 static constexpr float MAX_GAIN_CORRECTION_ABS = 0.1f;
112
113protected:
115
116 std::array<float, NUM_COEFF> factors_{{1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
117 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
118 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}};
119 std::array<float, NUM_COEFF> gain_corrections_{
120 {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
121 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}};
122
123 [[nodiscard]] bool write_factors_to_hardware();
124
125public:
127 CBlock();
128
129 metadata::eui_t get_entity_eui() const override;
130
131 // Variants exist, force them to differentiate themselves
132 // TODO: This is now handled via sub classes of CBlockHAL
133 // uint8_t get_entity_variant() const override = 0;
134
149 float get_factor(uint8_t idx);
150 const std::array<float, NUM_COEFF> &get_factors() const;
151
152 void set_factors(const std::array<float, NUM_COEFF> &factors);
153 [[nodiscard]] bool set_factor(uint8_t idx, float factor);
154
155 float get_gain_correction(uint8_t idx) const;
156 const std::array<float, NUM_COEFF> &get_gain_corrections() const;
157
158 bool set_gain_correction(uint8_t coeff_idx, const float correction);
159 void set_gain_corrections(const std::array<float, NUM_COEFF> &corrections);
160
162
163 [[nodiscard]] utils::status write_to_hardware() override;
164 void reset(entities::ResetAction action) override;
165
166 utils::status config_self_from_json(JsonObjectConst cfg) override;
167
168protected:
169 void config_self_to_json(JsonObject &cfg) override;
170
171 utils::status _config_elements_form_json(const JsonVariantConst &cfg);
172
173 friend class ::platform::Calibration;
174};
175
176} // namespace blocks
metadata::eui_t get_entity_eui() const override
Definition cblock.h:36
bool write_factor(uint8_t idx, float value) override
Definition cblock.h:34
const metadata::MetadataEditor f_meta
Definition cblock.h:42
CBlockHAL_Common(bus::addr_t block_address, std::array< const uint8_t, 32 > f_coeffs_cs)
Definition cblock.cpp:219
static std::array< const functions::AD5452, 32 > make_f_coeffs(bus::addr_t block_address, std::array< const uint8_t, 32 > f_coeffs_cs)
Definition cblock.cpp:184
bool write_factor(uint8_t idx, float value) override
Definition cblock.cpp:223
std::array< const functions::AD5452, 32 > f_coeffs
Definition cblock.h:41
metadata::eui_t get_entity_eui() const override
Definition cblock.h:52
CBlockHAL_V_1_0_X(bus::addr_t block_address)
Definition cblock.cpp:242
CBlockHAL_V_1_1_X(bus::addr_t block_address)
Definition cblock.cpp:231
virtual bool write_factor(uint8_t idx, float value)=0
The Lucidac Coefficient Block (C-Block) is represented by this class.
Definition cblock.h:83
static constexpr std::array< uint8_t, NUM_COEFF > INPUT_IDX_RANGE()
Definition cblock.h:99
utils::status write_to_hardware() override
returns true in case of success
Definition cblock.cpp:43
static constexpr uint8_t TYPE
Definition cblock.h:88
void config_self_to_json(JsonObject &cfg) override
Serialize the configuration of this entity to a JsonObject.
Definition cblock.cpp:153
static constexpr uint8_t BLOCK_IDX
Definition cblock.h:93
void set_factors(const std::array< float, NUM_COEFF > &factors)
Definition cblock.cpp:41
const std::array< float, NUM_COEFF > & get_gain_corrections() const
Definition cblock.cpp:76
static constexpr std::array< uint8_t, NUM_COEFF > OUTPUT_IDX_RANGE()
Definition cblock.h:104
static constexpr uint8_t NUM_COEFF
Definition cblock.h:97
const std::array< float, NUM_COEFF > & get_factors() const
Definition cblock.cpp:27
bool set_gain_correction(uint8_t coeff_idx, const float correction)
Definition cblock.cpp:88
bool write_factors_to_hardware()
Definition cblock.cpp:51
static constexpr auto CLASS_
Definition cblock.h:87
void reset(entities::ResetAction action) override
Definition cblock.cpp:59
std::array< float, NUM_COEFF > factors_
Definition cblock.h:116
utils::status config_self_from_json(JsonObjectConst cfg) override
Deserialize a new configuration for this entity from a JsonObject.
Definition cblock.cpp:98
void set_gain_corrections(const std::array< float, NUM_COEFF > &corrections)
Definition cblock.cpp:84
static constexpr float MIN_FACTOR
Definition cblock.h:109
float get_gain_correction(uint8_t idx) const
Definition cblock.cpp:70
static constexpr float MAX_FACTOR
Definition cblock.h:110
void reset_gain_corrections()
Definition cblock.cpp:80
utils::status _config_elements_form_json(const JsonVariantConst &cfg)
Definition cblock.cpp:114
static CBlock * from_entity_classifier(entities::EntityClassifier classifier, bus::addr_t block_address)
Definition cblock.cpp:161
bool set_factor(uint8_t idx, float factor)
Definition cblock.cpp:31
static constexpr uint8_t COEFF_BASE_FUNC_IDX
Definition cblock.h:95
float get_factor(uint8_t idx)
Set a particular digital potentiometer.
Definition cblock.cpp:15
static constexpr float MAX_GAIN_CORRECTION_ABS
Definition cblock.h:111
CBlockHAL * hardware
Definition cblock.h:114
std::array< float, NUM_COEFF > gain_corrections_
Definition cblock.h:119
metadata::eui_t get_entity_eui() const override
Definition cblock.cpp:21
A function block represents one module in a cluster, such as an M-Block, C-Block, I-Block or U-Block.
Definition base.h:29
EntityClassifier classifier
Definition base.h:217
eui_t read_eui() const
Definition entity.h:42
A recoverable error, inspired from https://abseil.io/docs/cpp/guides/status and https://github....
Definition error.h:35
Definition base.h:10
constexpr uint8_t C_BLOCK_IDX
Definition bus.h:57
uint16_t addr_t
Definition bus.h:27
std::array< uint8_t, 8 > eui_t
Definition base.h:20
This concept of Backpanel / Backplane refers to the address decoder and periphery reachable by every ...
Definition cblock.h:15