Skip to content

Commit

Permalink
AP_HAL_ChibiOS: correct neopixel bitwidth
Browse files Browse the repository at this point in the history
Use 64-bit timestamps for dshot send checks
  • Loading branch information
andyp1per authored and tridge committed Nov 14, 2023
1 parent ef5eccd commit 7639761
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions libraries/AP_HAL_ChibiOS/RCOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@ void RCOutput::set_group_mode(pwm_group &group)
#if HAL_SERIALLED_ENABLED
{
uint8_t bits_per_pixel = 24;
uint32_t bit_width = NEOP_BIT_WIDTH_TICKS;
bool active_high = true;

if (!start_led_thread()) {
Expand All @@ -1080,6 +1081,7 @@ void RCOutput::set_group_mode(pwm_group &group)

if (group.current_mode == MODE_PROFILED) {
bits_per_pixel = 25;
bit_width = PROFI_BIT_WIDTH_TICKS;
active_high = false;
}

Expand All @@ -1094,7 +1096,7 @@ void RCOutput::set_group_mode(pwm_group &group)
// calculate min time between pulses taking into account the DMAR parallelism
const uint32_t pulse_time_us = 1000000UL * bit_length / rate;

if (!setup_group_DMA(group, rate, NEOP_BIT_WIDTH_TICKS, active_high, buffer_length, pulse_time_us, false)) {
if (!setup_group_DMA(group, rate, bit_width, active_high, buffer_length, pulse_time_us, false)) {
group.current_mode = MODE_PWM_NONE;
break;
}
Expand Down Expand Up @@ -1698,7 +1700,8 @@ bool RCOutput::serial_led_send(pwm_group &group)
}

#if HAL_DSHOT_ENABLED
if (soft_serial_waiting() || (group.dshot_state != DshotState::IDLE && group.dshot_state != DshotState::RECV_COMPLETE)) {
if (soft_serial_waiting() || (group.dshot_state != DshotState::IDLE && group.dshot_state != DshotState::RECV_COMPLETE)
|| AP_HAL::micros64() - group.last_dmar_send_us < (group.dshot_pulse_time_us + 50)) {
// doing serial output or DMAR input, don't send DShot pulses
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_HAL_ChibiOS/RCOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ class ChibiOS::RCOutput : public AP_HAL::RCOutput
#endif // HAL_WITH_BIDIR_DSHOT
// are we safe to send another pulse?
bool can_send_dshot_pulse() const {
return is_dshot_protocol(current_mode) && AP_HAL::micros() - last_dmar_send_us > (dshot_pulse_time_us + 50);
return is_dshot_protocol(current_mode) && AP_HAL::micros64() - last_dmar_send_us > (dshot_pulse_time_us + 50);
}

// return whether the group channel is both enabled in the group and for output
Expand Down

0 comments on commit 7639761

Please sign in to comment.