From fb2a43bae4d14a232738eab42e2119ec29dfbaee Mon Sep 17 00:00:00 2001 From: Pascal Engeler <engelerp@phys.ethz.ch> Date: Fri, 9 Jun 2023 23:30:26 +0200 Subject: [PATCH] Added utility functionality --- firmware/drivers/utility/utility.cpp | 23 +++++++++++++++++++++++ firmware/drivers/utility/utility.hpp | 18 ++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 firmware/drivers/utility/utility.cpp create mode 100644 firmware/drivers/utility/utility.hpp diff --git a/firmware/drivers/utility/utility.cpp b/firmware/drivers/utility/utility.cpp new file mode 100644 index 0000000..c2b7c5e --- /dev/null +++ b/firmware/drivers/utility/utility.cpp @@ -0,0 +1,23 @@ +#include <utility.hpp> +#include <ad7124_4.hpp> +#include <ad7124_registers.hpp> + +std::array<double,5> Temperatures::temperatures = {0., 0., 0., 0., 0.}; + +Adc_data readAdc(Ad7124_4* device){ + Adc_data data; + data.valid = false; + Spi_selecta::select_device(device); + if(device->data_available()){ + Spi_selecta::deselect_device(); + Spi_selecta::select_device(device); + data.channel = device->read_register(REG_Status, 1); + Spi_selecta::deselect_device(); + Spi_selecta::select_device(device); + data.data = device->get_data() & 0x00FFFFFF; + Spi_selecta::deselect_device(); + data.valid = true; + } + Spi_selecta::deselect_device(); + return data; +} diff --git a/firmware/drivers/utility/utility.hpp b/firmware/drivers/utility/utility.hpp new file mode 100644 index 0000000..c413546 --- /dev/null +++ b/firmware/drivers/utility/utility.hpp @@ -0,0 +1,18 @@ +#ifndef UTILITY_HPP_INCLUDED +#define UTILITY_HPP_INCLUDED +#include <ad7124_4.hpp> + +struct Adc_data{ + bool valid; + uint32_t channel; + uint32_t data; +}; + +Adc_Data readAdc(Ad7124_4* device); + +struct Temperatures{ + /*The 0th temperature shall always be the loop, the others the out-of-loops*/ + static std::array<double, 5> temperatures; +}; + +#endif -- GitLab