From 0fde1b98eee06eda8333ae4099a6731a05a14482 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 12 Nov 2020 09:45:16 -0500 Subject: firmware reorganize; added more sample rates --- source/adc.hpp | 57 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 17 deletions(-) (limited to 'source/adc.hpp') diff --git a/source/adc.hpp b/source/adc.hpp index 1431aa1..a739059 100644 --- a/source/adc.hpp +++ b/source/adc.hpp @@ -14,29 +14,52 @@ #include "hal.h" -namespace adc +#include + +class ADC { - using operation_t = void (*)(adcsample_t *buffer, size_t count); +public: + using Operation = void (*)(adcsample_t *buffer, size_t count); - enum class rate : unsigned int { + enum class Rate : int { + //R8K = 0, R16K = 0, + R20K, + R32K, R48K, - R96K, - R100K, - R400K, - R1M, - R2M + R60K, + R96K }; - void init(); - void set_rate(rate new_rate); - unsigned int get_rate(); - unsigned int get_gpt_divisor(); - adcsample_t *read(adcsample_t *buffer, size_t count); - void read_start(operation_t operation_func, adcsample_t *buffer, size_t count); - void read_set_operation_func(operation_t operation_func); - void read_stop(); -} + static void begin(); + + static void start(adcsample_t *buffer, size_t count, Operation operation); + static void stop(); + + static void setRate(Rate rate); + static void setOperation(Operation operation); + + static int getRate(); + static unsigned int getTimerDivisor(); + +private: + static ADCDriver *m_driver; + static GPTDriver *m_timer; + + static const ADCConfig m_config; + static /*const*/ ADCConversionGroup m_group_config; + static const GPTConfig m_timer_config; + + static std::array, 6> m_rate_presets; + + static adcsample_t *m_current_buffer; + static size_t m_current_buffer_size; + static Operation m_operation; + + static unsigned int m_timer_divisor; + + static void conversionCallback(ADCDriver *); +}; #endif // STMDSP_ADC_HPP_ -- cgit v1.2.3