mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 06:03:33 +08:00
drv_pwm_servo provide the simplified interface for OneShot
1) Validate timer paramater before using it.
2) Allow rate of 0 to enter Oneshot mode
At first blush this seamed like a hack, but at Mark
pointed out to me, Onshot PWM does not have a rate
So this is a realy a clever and beautiful simplification
on his part!
3) Exposes up_pwm_update that runs io_timer_trigger
Which trigger all timer's channels in Oneshot mode to
fire the oneshots with updated values.
This commit is contained in:
committed by
Lorenz Meier
parent
938824500c
commit
30c8e6efac
@@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012 PX4 Development Team. All rights reserved.
|
* Copyright (C) 2012, 2017 PX4 Development Team. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@@ -76,9 +76,7 @@ servo_position_t up_pwm_servo_get(unsigned channel)
|
|||||||
int up_pwm_servo_init(uint32_t channel_mask)
|
int up_pwm_servo_init(uint32_t channel_mask)
|
||||||
{
|
{
|
||||||
/* Init channels */
|
/* Init channels */
|
||||||
io_timer_channel_mode_t chmode = IOTimerChanMode_PWMOut;
|
uint32_t current = io_timer_get_mode_channels(IOTimerChanMode_PWMOut);
|
||||||
|
|
||||||
uint32_t current = io_timer_get_mode_channels(chmode);
|
|
||||||
|
|
||||||
// First free the current set of PWMs
|
// First free the current set of PWMs
|
||||||
|
|
||||||
@@ -100,13 +98,8 @@ int up_pwm_servo_init(uint32_t channel_mask)
|
|||||||
io_timer_free_channel(channel);
|
io_timer_free_channel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (io_timer_get_freq(timer_io_channels[channel].timer_index) == 8) {
|
io_timer_channel_init(channel, IOTimerChanMode_PWMOut, NULL, NULL);
|
||||||
chmode = IOTimerChanMode_OneShot;
|
|
||||||
}
|
|
||||||
|
|
||||||
io_timer_channel_init(channel, chmode, NULL, NULL);
|
|
||||||
channel_mask &= ~(1 << channel);
|
channel_mask &= ~(1 << channel);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,33 +114,32 @@ void up_pwm_servo_deinit(void)
|
|||||||
|
|
||||||
int up_pwm_servo_set_rate_group_update(unsigned group, unsigned rate)
|
int up_pwm_servo_set_rate_group_update(unsigned group, unsigned rate)
|
||||||
{
|
{
|
||||||
if (rate == 0) {
|
|
||||||
/* configure this group for OneShot125 PWM */
|
|
||||||
io_timer_set_oneshot_mode(group);
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* limit update rate to 1..10000Hz; somewhat arbitrary but safe */
|
|
||||||
if (rate < 1) {
|
|
||||||
return -ERANGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rate > 10000) {
|
|
||||||
return -ERANGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((group >= MAX_IO_TIMERS) || (io_timers[group].base == 0)) {
|
if ((group >= MAX_IO_TIMERS) || (io_timers[group].base == 0)) {
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
io_timer_set_rate(group, rate);
|
/* Allow a rate of 0 to enter onshot mode */
|
||||||
|
|
||||||
|
if (rate != 0) {
|
||||||
|
|
||||||
|
/* limit update rate to 1..10000Hz; somewhat arbitrary but safe */
|
||||||
|
|
||||||
|
if (rate < 1) {
|
||||||
|
return -ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rate > 10000) {
|
||||||
|
return -ERANGE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
io_timer_set_rate(group, rate);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void up_pwm_force_update(void)
|
void up_pwm_update(void)
|
||||||
{
|
{
|
||||||
io_timer_force_update();
|
io_timer_trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
int up_pwm_servo_set_rate(unsigned rate)
|
int up_pwm_servo_set_rate(unsigned rate)
|
||||||
|
|||||||
Reference in New Issue
Block a user