mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-29 15:43:35 +08:00
px4fmu: add support for write() interface for PWM output
this matches the PX4IO interface
This commit is contained in:
@@ -85,6 +85,7 @@ public:
|
|||||||
~PX4FMU();
|
~PX4FMU();
|
||||||
|
|
||||||
virtual int ioctl(file *filp, int cmd, unsigned long arg);
|
virtual int ioctl(file *filp, int cmd, unsigned long arg);
|
||||||
|
virtual ssize_t write(file *filp, const char *buffer, size_t len);
|
||||||
|
|
||||||
virtual int init();
|
virtual int init();
|
||||||
|
|
||||||
@@ -651,6 +652,30 @@ PX4FMU::pwm_ioctl(file *filp, int cmd, unsigned long arg)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
this implements PWM output via a write() method, for compatibility
|
||||||
|
with px4io
|
||||||
|
*/
|
||||||
|
ssize_t
|
||||||
|
PX4FMU::write(file *filp, const char *buffer, size_t len)
|
||||||
|
{
|
||||||
|
unsigned count = len / 2;
|
||||||
|
uint16_t values[4];
|
||||||
|
|
||||||
|
if (count > 4) {
|
||||||
|
// we only have 4 PWM outputs on the FMU
|
||||||
|
count = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// allow for misaligned values
|
||||||
|
memcpy(values, buffer, count*2);
|
||||||
|
|
||||||
|
for (uint8_t i=0; i<count; i++) {
|
||||||
|
up_pwm_servo_set(i, values[i]);
|
||||||
|
}
|
||||||
|
return count * 2;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PX4FMU::gpio_reset(void)
|
PX4FMU::gpio_reset(void)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user