Dawn Framework 1.0
Universal data acquisition framework for embedded systems
pwm.hxx
1// dawn/include/dawn/io/pwm.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include "dawn/io/common.hxx"
9#include "dawn/porting/config.hxx"
10#include "dawn/porting/pwm.hxx"
11
12namespace dawn
13{
20class CIOPwm : public CIOCommon
21{
22public:
23 enum
24 {
29 IO_PWM_CFG_LAST = 31
30 };
31
32 explicit CIOPwm(CDescObject &desc)
33 : CIOCommon(desc)
34 , path()
35 , fd(-1)
36 , channels(CONFIG_PWM_NCHANNELS)
37 , freq(CONFIG_DAWN_IO_PWM_DEFAULT_FREQ)
38 , info(nullptr)
39 {
40 }
41
42 ~CIOPwm() override;
43
44#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
45 const char *getClassNameStr() const override
46 {
47 return "pwm";
48 }
49#endif
50
51 int configure() override;
52 int init() override;
53 int deinit() override;
54 int setDataImpl(IODataCmn &data) override;
55 int doStart() override;
56 int doStop() override;
57 int trigger(uint8_t cmd) override;
58 size_t getDataSize() const override;
59 size_t getDataDim() const override;
60
61 bool isRead() const override
62 {
63 return false;
64 };
65
66 bool isWrite() const override
67 {
68 return true;
69 };
70
71 bool isNotify() const override
72 {
73 return false;
74 };
75
76 bool isBatch() const override
77 {
78 return false;
79 };
80
82
83 constexpr static SObjectId::ObjectId objectId(bool ts, uint16_t inst)
84 {
85 return ObjectIdHelper::create(ts, inst);
86 }
87
88 constexpr static SObjectCfg::ObjectCfgId cfgId(bool rw, uint8_t dtype, uint8_t size, uint8_t id)
89 {
92 }
93
94 constexpr static SObjectCfg::ObjectCfgId cfgIdFreq(bool rw = false)
95 {
96 return CIOPwm::cfgId(rw, SObjectId::DTYPE_UINT32, 1, IO_PWM_CFG_FREQ);
97 }
98
99protected:
100 int onSetObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len) override;
101
102private:
103 char path[PATH_MAX];
104 int fd;
105 uint8_t channels;
106 uint32_t freq;
107#ifdef CONFIG_DAWN_IO_TIMESTAMP
108 uint64_t ts;
109#endif
111
112 int configureDesc(const CDescObject &desc);
113};
114} // Namespace dawn
Descriptor wrapper for individual object configuration.
Template helper for creating ObjectIDs for I/O types.
Definition common.hxx:236
static SObjectId::ObjectId create(bool ts, uint16_t inst)
Create ObjectID with default data type.
Definition common.hxx:246
Base class for all I/O objects.
Definition common.hxx:27
@ IO_CLASS_PWM
PWM output.
Definition common.hxx:172
Pulse Width Modulation (PWM) output I/O type.
Definition pwm.hxx:21
@ IO_PWM_CFG_POL
PWM polarity configuration.
Definition pwm.hxx:28
@ IO_PWM_CFG_FREQ
PWM frequency configuration.
Definition pwm.hxx:26
@ IO_PWM_CFG_DT
PWM dead time configuration.
Definition pwm.hxx:27
@ IO_PWM_CFG_LAST
Last config ID marker (reserved).
Definition pwm.hxx:29
@ IO_PWM_CFG_FIRST
First config ID (reserved).
Definition pwm.hxx:25
int configure()
Configure object from descriptor data.
Definition pwm.cxx:79
bool isRead() const
Check if IO supports read operations.
Definition pwm.hxx:61
int init()
One-time initialize object after bindings are resolved.
Definition pwm.cxx:139
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
Definition pwm.cxx:164
bool isBatch() const
Check if IO supports batch operations.
Definition pwm.hxx:76
int onSetObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len)
Pre-update hook for runtime configuration writes.
Definition pwm.cxx:225
size_t getDataSize() const
Get data size in bytes.
Definition pwm.cxx:264
bool isWrite() const
Check if IO supports write operations.
Definition pwm.hxx:66
int doStart()
Start implementation hook.
Definition pwm.cxx:209
int deinit()
De-initialize object.
Definition pwm.cxx:150
int trigger(uint8_t cmd)
Execute a trigger command.
Definition pwm.cxx:219
bool isNotify() const
Check if IO supports notifications.
Definition pwm.hxx:71
int doStop()
Stop implementation hook.
Definition pwm.cxx:214
size_t getDataDim() const
Get data vector dimension.
Definition pwm.cxx:269
static ObjectCfgId objectCfg(uint8_t type, uint16_t cls, uint8_t dtype, bool rw, uint16_t size, uint8_t id)
Construct 32-bit ConfigID from component fields.
uint32_t ObjectCfgId
ConfigID type - single 32-bit value.
Definition objectcfg.hxx:60
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
@ OBJTYPE_IO
Input/Output object type.
Definition objectid.hxx:184
@ DTYPE_UINT32
Unsigned 32-bit integer (0 to 4294967295).
Definition objectid.hxx:96
uint32_t ObjectId
ObjectID type - single 32-bit value.
Definition objectid.hxx:44
PWM write data.
Definition pwm.hxx:22