Dawn Framework 1.0
Universal data acquisition framework for embedded systems
buttons.cxx
1// dawn/src/io/buttons.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/porting/buttons.hxx"
7
8#include "dawn/io/buttons.hxx"
9
10using namespace dawn;
11
12int CIOButtons::configureDesc(const CDescObject &desc)
13{
15 size_t offset = 0;
16
17 for (size_t i = 0; i < desc.getSize(); i++)
18 {
19 item = desc.objectCfgItemAtOffset(offset);
20
22 {
23 DAWNERR("unsupported buttons cfg 0x08%" PRIx32 "\n", item->cfgid.v);
24 return -EINVAL;
25 }
26
27 offset += cfgCmnOffset(item);
28 }
29
30 return OK;
31}
32
33CIOButtons::~CIOButtons()
34{
35 deinit();
36}
37
39{
40 int ret;
41
42 // Configure object
43
44 ret = configureDesc(getDesc());
45 if (ret != OK)
46 {
47 return ret;
48 }
49
50 // Get path to BUTTONS
51
52 if (getCmnDevno() == -1)
53 {
54 DAWNERR("BUTTONS device number not configured\n");
55 return -EINVAL;
56 }
57
58 snprintf(path, sizeof(path), BUTTONS_PATH_FMT, getCmnDevno());
59
60 // Open file
61
62 fd = buttons_open(path);
63 if (fd < 0)
64 {
65 DAWNERR("buttons_open failed %d\n", -errno);
66 return -errno;
67 }
68
69 return OK;
70}
71
73{
74 // Close file
75
76 buttons_close(fd);
77 return OK;
78}
79
80int CIOButtons::getDataImpl(IODataCmn &data, size_t len)
81{
82 uint32_t *tmp = static_cast<uint32_t *>(data.getDataPtr());
83 uint32_t val;
84 int ret;
85
86 // No batch supported
87
88 if (len != 1)
89 {
90 return -ENOTSUP;
91 }
92
93 // Read input
94
95 ret = buttons_read(fd, &val);
96 if (ret < 0)
97 {
98 DAWNERR("buttons_read failed %d\n", ret);
99 return ret;
100 }
101
102 if (isTimestamp())
103 {
104 data.getTs() = getTimestamp();
105 }
106
107 *tmp = (uint32_t)val;
108
109 return OK;
110}
111
112#ifdef CONFIG_DAWN_IO_NOTIFY
113int CIOButtons::getFd() const
114{
115 return fd;
116}
117#endif
118
120{
121 return sizeof(uint32_t);
122}
123
125{
126 return 1;
127}
Descriptor wrapper for individual object configuration.
size_t getSize() const
Get number of configuration items for this object.
SObjectCfg::SObjectCfgItem * objectCfgItemAtOffset(size_t offset) const
Get configuration item at specified offset.
int deinit()
De-initialize object.
Definition buttons.cxx:72
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
Definition buttons.cxx:80
int configure()
Configure object from descriptor data.
Definition buttons.cxx:38
size_t getDataSize() const
Get data size in bytes.
Definition buttons.cxx:119
size_t getDataDim() const
Get data vector dimension.
Definition buttons.cxx:124
virtual int getFd() const
Get file descriptor for notifications.
Definition common.hxx:425
uint64_t getTimestamp()
Get current timestamp.
Definition common.cxx:194
bool isTimestamp() const
Check if I/O supports timestamp.
Definition common.cxx:189
int getCmnDevno() const
Get device number for this I/O.
Definition common.hxx:798
size_t cfgCmnOffset(const SObjectCfg::SObjectCfgItem *cfg)
Get offset of configuration item in descriptor.
Definition common.cxx:144
@ IO_CLASS_ANY
Any I/O class.
Definition common.hxx:86
CDescObject & getDesc()
Get descriptor object for this object.
Definition object.cxx:190
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 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.
Single configuration item within object.
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
Definition objectcfg.hxx:82
uint32_t cls
Object class (bits 21-29, max 511).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.