6#include "dawn/io/pwm.hxx"
18 for (
size_t i = 0; i < desc.
getSize(); i++)
38 DAWNERR(
"invalid PWM frequency config size %d\n", item->
cfgid.
s.
size);
42 freq = *
reinterpret_cast<const uint32_t *
>(&item->
data);
45 DAWNERR(
"PWM frequency must be > 0\n");
55 DAWNERR(
"Unsupported PWM config 0x%08" PRIx32
"\n", item->
cfgid.
v);
65 DAWNERR(
"Unsupported PWM config 0x%08" PRIx32
"\n", item->
cfgid.
v);
89 DAWNERR(
"PWM configure failed (error %d)\n", ret);
97 DAWNERR(
"PWM device number not configured\n");
101 snprintf(path,
sizeof(path), PWM_PATH_FMT,
getCmnDevno());
108 DAWNERR(
"failed to open file %d\n", -errno);
122 DAWNERR(
"failed to allocate PWM channel info\n");
131 for (i = 0; i < channels; i++)
133 info->channels[i].channel = i + 1;
143 DAWNERR(
"PWM requires DTYPE_UINT32\n");
152 ::operator
delete(info);
166 uint32_t *tmp =
static_cast<uint32_t *
>(data.
getDataPtr());
176 for (
int i = 0; i < channels; i++)
186 info->channels[i].duty = tmp[i];
187 info->channels[i].channel = i + 1;
192 ret = pwm_write(fd, info);
195 DAWNERR(
"pwm_write failed %d\n", ret);
199#ifdef CONFIG_DAWN_IO_TIMESTAMP
211 return pwm_start(fd);
221 DAWNERR(
"CIOPwm::trigger not implemented\n");
235 if (len != 1 || data ==
nullptr || data[0] == 0)
246 oldFreq = info->freq;
247 info->freq = data[0];
251 ret = pwm_write(fd, info);
254 info->freq = oldFreq;
255 DAWNERR(
"pwm frequency update failed %d\n", ret);
266 return sizeof(uint32_t) * channels;
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.
uint64_t getTimestamp()
Get current timestamp.
bool isTimestamp() const
Check if I/O supports timestamp.
int getCmnDevno() const
Get device number for this I/O.
size_t cfgCmnOffset(const SObjectCfg::SObjectCfgItem *cfg)
Get offset of configuration item in descriptor.
@ IO_CLASS_PWM
PWM output.
@ IO_CLASS_ANY
Any I/O class.
@ IO_PWM_CFG_FREQ
PWM frequency configuration.
int configure()
Configure object from descriptor data.
int init()
One-time initialize object after bindings are resolved.
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
int onSetObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len)
Pre-update hook for runtime configuration writes.
size_t getDataSize() const
Get data size in bytes.
int doStart()
Start implementation hook.
int deinit()
De-initialize object.
int trigger(uint8_t cmd)
Execute a trigger command.
int doStop()
Stop implementation hook.
size_t getDataDim() const
Get data vector dimension.
CDescObject & getDesc()
Get descriptor object for this object.
uint8_t getDtype() const
Get data type field.
uint32_t ObjectCfgId
ConfigID type - single 32-bit value.
static uint8_t objectCfgGetId(const ObjectCfgId objcfg)
Extract configuration identifier from ConfigID.
Out-of-tree user-extension hooks for Dawn.
Base interface for I/O data buffers (static and dynamic).
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).
Single configuration item within object.
ObjectCfgData_t data[]
Configuration data array (flexible, size from cfgid.s.size).
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
@ DTYPE_UINT32
Unsigned 32-bit integer (0 to 4294967295).
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
uint32_t cls
Object class (bits 21-29, max 511).
uint32_t id
Configuration identifier (bits 0-4, max 31).
uint32_t size
Configuration data size in 32-bit words (bits 5-14, max 1023).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.