REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
front_panel.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 "bus/bus.h"
9#include "entity/entity.h"
10
11#include "chips/AD9834.h"
12#include "chips/DAC60508.h"
13#include "chips/SR74HCT595.h"
14
15namespace platform {
16
27public:
28 // Entity hardware identifier information.
30
31 static LUCIDACFrontPanel *from_entity_classifier(entities::EntityClassifier classifier,
32 __attribute__((__unused__)) bus::addr_t block_address);
33
34 std::array<uint8_t, 8> get_entity_eui() const override;
35
36 utils::status config_self_from_json(JsonObjectConst cfg) override;
37
38 Entity *get_child_entity(const std::string &child_id) override { return nullptr; }
39
40 std::vector<Entity *> get_child_entities() override { return {}; };
41
42protected:
43 utils::status _config_leds_from_json(const JsonVariantConst &cfg);
44 utils::status _config_signal_generator_from_json(const JsonVariantConst &cfg);
45 void config_self_to_json(JsonObject &cfg) override;
46
47public:
48 static constexpr uint8_t FUNCTION_GENERATOR_IDX = 2;
49 static constexpr uint8_t DAC_IDX = 3;
50 static constexpr uint8_t LED_REGISTER_IDX = 4;
51 static constexpr uint8_t LED_REGISTER_STORE_IDX = 5;
52 static constexpr uint8_t LED_REGISTER_RESET_IDX = 6;
53
54 static constexpr uint8_t DAC_AMPLITUDE_CH = 0;
55 static constexpr uint8_t DAC_SQUARE_HIGH_CH = 1;
56 static constexpr uint8_t DAC_SQUARE_LOW_CH = 2;
57 static constexpr uint8_t DAC_OFFSET_CH = 3;
58 static constexpr uint8_t DAC_OUT0_CH = 4;
59 static constexpr uint8_t DAC_OUT1_CH = 5;
60
62
64 bool init();
65
67 void reset(entities::ResetAction action);
68
70 // Error codes:
71 // 0 LED register failed in pedantic mode
72 // -1 Signal generator amplitude chanel
73 // -2 Signal generator square low chanel
74 // -3 Signal generator square high chanel
75 // -4 Signal generator offset chanel
76 // -5 Signal generator dac0 chanel
77 // -6 Signal generator dac1 chanel
79
80 class LEDs {
81 public:
82 LEDs();
83
85 bool set(const uint8_t led, bool on);
87 void set_all(const uint8_t states);
89 void reset();
90
92 uint8_t get_all() const;
93
95
96 private:
97 const functions::SR74HCT595 led_register;
98 const functions::TriggerFunction led_register_store;
99 const functions::TriggerFunction led_register_reset;
100
101 uint8_t led_states = 0;
103
105 public:
108 bool init();
109
112 bool is_installed() const { return installed; }
113
116 void set_frequency(float frequency);
119 void set_phase(float phase);
124 bool set_amplitude(float amplitude);
127 bool set_square_voltage_levels(float low, float high);
130 bool set_square_voltage_low(float low);
133 bool set_square_voltage_high(float high);
136 bool set_offset(float offset);
137
139 float get_real_frequency() const;
142 float get_real_phase() const;
143
144 float get_frequency() const;
145 float get_phase() const;
147 float get_amplitude() const;
148 float get_square_voltage_low() const;
149 float get_square_voltage_high() const;
150 float get_offset() const;
151 bool get_sleep() const;
152
153 float get_dac_out0() const;
154 float get_dac_out1() const;
155
158 void sleep();
161 void awake();
162
164 bool set_dac_out0(float value);
166 bool set_dac_out1(float value);
167
169
170 private:
171 const functions::DAC60508 digital_analog_converter;
172 functions::AD9834 function_generator;
173
175 static constexpr float _map_dac_levelshift(float x) {
176 return (x + 2.0f) * (0.0f - 2.5f) / (2.0f + 2.0f) + 2.5f;
177 }
178
179 float _frequency;
180 float _phase;
182 float _amplitude;
183 float _square_low_voltage;
184 float _square_high_voltage;
185 float _offset;
186 float _dac_out0;
187 float _dac_out1;
188
189 bool _sleep = true;
190
191 bool installed = false;
192
193 friend LUCIDACFrontPanel;
194
196};
197} // namespace platform
EntityClassifier classifier
Definition base.h:217
Entity()=default
The DAC60508 is the 12-Bit 8-channel DAC, used in the MInt-Block for the initial conditions.
Definition DAC60508.h:17
The SR74HCT595 is an 8-Bit Shift Register with 3-State Output Registers.
Definition SR74HCT595.h:16
A trigger function exploits the fact that setting an address on the bus triggers an action (TODO: Is ...
Definition functions.h:33
utils::status write_to_hardware() const
void set_all(const uint8_t states)
Sets all eight front leds at once.
void reset()
Disables all eight front leds.
uint8_t get_all() const
Returns the current state of the front leds.
bool set(const uint8_t led, bool on)
Sets specified front led to the specified value.
void awake()
Resumes outputs of the function generator to regular operation, according to the previously specified...
bool set_dac_out1(float value)
Writes the DACout1 constant voltage output. Possible values are: [-2V, 2V].
float get_real_phase() const
Returns the actually set phase of the function generator, containing rounding errors.
void sleep()
Sets the sine / triangle output of the function generator to zero.
void set_frequency(float frequency)
Sets the frequency of the sine / triangle output in Hz.
bool is_installed() const
Returns wether an signal generator module is actually installed and active.
void set_wave_form(functions::AD9834::WaveForm wave_form)
Sets the wave form of the function generator output.
bool init()
Initializes the signal generator and puts it to sleep.
void set_phase(float phase)
Sets the phase of the frequency outputs synchronised to the reset pin.
bool set_square_voltage_high(float high)
Sets the upper value of the square output in machine units.
float get_real_frequency() const
Returns the actually set frequency of the function generator, containing rounding errors.
bool set_offset(float offset)
Sets the constant offset of the sine or triangle output in machine units.
bool set_dac_out0(float value)
Writes the DACout0 constant voltage output. Possible values are: [-2V, 2V].
bool set_square_voltage_low(float low)
Sets the lower value of the square output in machine units.
bool set_amplitude(float amplitude)
Sets the amplitude of the sine or triangle wave in machine units.
functions::AD9834::WaveForm get_wave_form() const
bool set_square_voltage_levels(float low, float high)
Sets the lower and upper value of the square output in machine units.
The Lucidac Front Panel is represented by this class.
Definition front_panel.h:26
utils::status write_to_hardware() override
Writes the hardware state of the LEDs and the signal generator.
utils::status _config_leds_from_json(const JsonVariantConst &cfg)
utils::status config_self_from_json(JsonObjectConst cfg) override
Deserialize a new configuration for this entity from a JsonObject.
void reset(entities::ResetAction action)
Resets the front panel to default state e.g. all LEDs off and signal generator sleeping.
static constexpr uint8_t DAC_OUT0_CH
Definition front_panel.h:58
static constexpr uint8_t DAC_AMPLITUDE_CH
Definition front_panel.h:54
std::vector< Entity * > get_child_entities() override
Definition front_panel.h:40
static constexpr uint8_t LED_REGISTER_IDX
Definition front_panel.h:50
class platform::LUCIDACFrontPanel::SignalGenerator signal_generator
class platform::LUCIDACFrontPanel::LEDs leds
static constexpr uint8_t DAC_SQUARE_LOW_CH
Definition front_panel.h:56
utils::status _config_signal_generator_from_json(const JsonVariantConst &cfg)
static constexpr uint8_t FUNCTION_GENERATOR_IDX
Definition front_panel.h:48
static constexpr uint8_t LED_REGISTER_RESET_IDX
Definition front_panel.h:52
void config_self_to_json(JsonObject &cfg) override
Serialize the configuration of this entity to a JsonObject.
static constexpr uint8_t DAC_SQUARE_HIGH_CH
Definition front_panel.h:55
static constexpr uint8_t LED_REGISTER_STORE_IDX
Definition front_panel.h:51
bool init()
Initializes the front panel and puts the signal generator to sleep.
static constexpr uint8_t DAC_IDX
Definition front_panel.h:49
static constexpr auto CLASS_
Definition front_panel.h:29
static constexpr uint8_t DAC_OFFSET_CH
Definition front_panel.h:57
std::array< uint8_t, 8 > get_entity_eui() const override
static LUCIDACFrontPanel * from_entity_classifier(entities::EntityClassifier classifier, __attribute__((__unused__)) bus::addr_t block_address)
static constexpr uint8_t DAC_OUT1_CH
Definition front_panel.h:59
Entity * get_child_entity(const std::string &child_id) override
Definition front_panel.h:38
A recoverable error, inspired from https://abseil.io/docs/cpp/guides/status and https://github....
Definition error.h:35
__attribute__((section(".fastrun"), noinline, noclone, optimize("Os"))) int flash_sector_not_erased(uint32_t address)
Definition flasher.cpp:114
uint16_t addr_t
Definition bus.h:27
This concept of Backpanel / Backplane refers to the address decoder and periphery reachable by every ...
Definition cblock.h:15