libDaisy
adc.h
1#pragma once
2#ifndef DSY_ADC_H
3#define DSY_ADC_H
4#include <stdint.h>
5#include <stdlib.h>
6#include "daisy_core.h"
7#include "per/gpio.h"
8
9#define DSY_ADC_MAX_CHANNELS 16
11namespace daisy
12{
17/* While there may not be many configuration options here,
18using a struct like this allows us to add more configuration
19later without breaking existing functionality.
20*/
21
24{
26 enum MuxPin
27 {
32 };
33
38
51 void InitMux(dsy_gpio_pin adc_pin,
52 size_t mux_channels,
53 dsy_gpio_pin mux_0,
54 dsy_gpio_pin mux_1 = {DSY_GPIOX, 0},
55 dsy_gpio_pin mux_2 = {DSY_GPIOX, 0});
56
59 uint8_t mux_channels_;
60};
61
66{
67 public:
70 {
82 };
83
84 AdcHandle() {}
85 ~AdcHandle() {}
92 void
93 Init(AdcChannelConfig *cfg, size_t num_channels, OverSampling ovs = OVS_32);
94
96 void Start();
97
99 void Stop();
100
106 uint16_t Get(uint8_t chn) const;
107
113 uint16_t *GetPtr(uint8_t chn) const;
114
120 float GetFloat(uint8_t chn) const;
121
128 uint16_t GetMux(uint8_t chn, uint8_t idx) const;
129
136 uint16_t *GetMuxPtr(uint8_t chn, uint8_t idx) const;
137
144 float GetMuxFloat(uint8_t chn, uint8_t idx) const;
145
146 private:
147 OverSampling oversampling_;
148 size_t num_channels_;
149};
150
152} // namespace daisy
153
154#endif // DSY_ADC_H
Definition: adc.h:66
uint16_t * GetMuxPtr(uint8_t chn, uint8_t idx) const
float GetMuxFloat(uint8_t chn, uint8_t idx) const
float GetFloat(uint8_t chn) const
void Init(AdcChannelConfig *cfg, size_t num_channels, OverSampling ovs=OVS_32)
uint16_t GetMux(uint8_t chn, uint8_t idx) const
OverSampling
Definition: adc.h:70
@ OVS_512
Definition: adc.h:79
@ OVS_32
Definition: adc.h:75
@ OVS_16
Definition: adc.h:74
@ OVS_4
Definition: adc.h:72
@ OVS_1024
Definition: adc.h:80
@ OVS_128
Definition: adc.h:77
@ OVS_LAST
Definition: adc.h:81
@ OVS_256
Definition: adc.h:78
@ OVS_64
Definition: adc.h:76
@ OVS_NONE
Definition: adc.h:71
@ OVS_8
Definition: adc.h:73
uint16_t Get(uint8_t chn) const
uint16_t * GetPtr(uint8_t chn) const
Hardware defines and helpers for daisy field platform.
Definition: daisy_field.h:11
Definition: adc.h:24
void InitSingle(dsy_gpio_pin pin)
uint8_t mux_channels_
Definition: adc.h:59
dsy_gpio pin_
Definition: adc.h:57
dsy_gpio mux_pin_[MUX_SEL_LAST]
Definition: adc.h:58
void InitMux(dsy_gpio_pin adc_pin, size_t mux_channels, dsy_gpio_pin mux_0, dsy_gpio_pin mux_1={DSY_GPIOX, 0}, dsy_gpio_pin mux_2={DSY_GPIOX, 0})
MuxPin
Definition: adc.h:27
@ MUX_SEL_LAST
Definition: adc.h:31
@ MUX_SEL_1
Definition: adc.h:29
@ MUX_SEL_0
Definition: adc.h:28
@ MUX_SEL_2
Definition: adc.h:30
Definition: daisy_core.h:194
Definition: gpio.h:36