Dawn Framework 1.0
Universal data acquisition framework for embedded systems
adc_fetch.cxx
1// dawn/src/io/adc_fetch.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/io/adc_fetch.hxx"
7
8using namespace dawn;
9
10int CIOAdcFetch::getDataImpl(IODataCmn &data, size_t len)
11{
12 auto *ptr = reinterpret_cast<dawn::porting::adc_read_s *>(data.getDataPtr());
13 int ret;
14
15 if (len != 1)
16 {
17 return -ENOTSUP;
18 }
19
20 if (data.getItems() < getChans())
21 {
22 return -ENOMEM;
23 }
24
25 ret = adc_start(getFdInternal());
26 if (ret < 0)
27 {
28 return ret;
29 }
30
31 ret = adc_read(getFdInternal(), ptr, data.getDataSize());
32 if (ret < 0)
33 {
34 return ret;
35 }
36
37#ifdef CONFIG_DAWN_IO_TIMESTAMP
38 if (isTimestamp())
39 {
40 data.getTs() = getTimestamp();
41 }
42#endif
43
44 return OK;
45}
46
48{
49 return OK;
50}
51
53{
54 return OK;
55}
56
57int CIOAdcFetch::trigger(uint8_t cmd)
58{
59 UNUSED(cmd);
60 return adc_start(getFdInternal());
61}
int trigger(uint8_t cmd)
Execute a trigger command.
Definition adc_fetch.cxx:57
int doStop()
Stop implementation hook.
Definition adc_fetch.cxx:52
int doStart()
Start implementation hook.
Definition adc_fetch.cxx:47
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
Definition adc_fetch.cxx:10
uint64_t getTimestamp()
Get current timestamp.
Definition common.cxx:194
bool isTimestamp() const
Check if I/O supports timestamp.
Definition common.cxx:189
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
Base interface for I/O data buffers (static and dynamic).
Definition idata.hxx:21
virtual size_t getItems()=0
Get number of items per batch.
virtual void * getDataPtr(size_t batch=0)=0
Get pointer to data only (skips timestamp if present).
virtual uint64_t & getTs(size_t batch=0)=0
Get timestamp reference for batch.
virtual size_t getDataSize()=0
Get data size in bytes.
ADC read data.
Definition adc.hxx:23