Skip to content
This repository has been archived by the owner on May 9, 2019. It is now read-only.

Commit

Permalink
refs #17 Add ADC driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
yoos committed Feb 10, 2015
1 parent 70e299a commit a60c6aa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/drivers/adc_device.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef ADC_DEVICE_HPP_
#define ADC_DEVICE_HPP_

#include <array>
#include <cstdint>

#include "hal.h"

template <std::size_t num_ch, std::size_t buf_depth>
class ADCDevice {
public:
ADCDevice(ADCDriver *adcd, const ADCConversionGroup *adcgrpcfg, std::array<adcsample_t, num_ch*buf_depth> *samples, std::array<adcsample_t, num_ch> *avg_ch);

protected:
void update(void);

ADCDriver *adcd;
const ADCConversionGroup *adcgrpcfg;
std::array<adcsample_t, num_ch*buf_depth> *samples;
std::array<adcsample_t, num_ch> *avg_ch;
};

#include "drivers/adc_device.tpp"

#endif // ADC_DEVICE_HPP_
11 changes: 11 additions & 0 deletions src/drivers/adc_device.tpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
template <std::size_t num_ch, std::size_t buf_depth>
ADCDevice<num_ch, buf_depth>::ADCDevice(ADCDriver *adcd, const ADCConversionGroup *adcgrpcfg, std::array<adcsample_t, num_ch*buf_depth> *samples, std::array<adcsample_t, num_ch> *avg_ch)
: adcd(adcd), adcgrpcfg(adcgrpcfg), samples(samples), avg_ch(avg_ch) {
}

template <std::size_t num_ch, std::size_t buf_depth>
void ADCDevice<num_ch, buf_depth>::update(void) {
chSysLockFromIsr();
adcStartConversionI(adcd, adcgrpcfg, reinterpret_cast<adcsample_t*>(samples), buf_depth);
chSysUnlockFromIsr();
}

0 comments on commit a60c6aa

Please sign in to comment.