dshot debugging
This commit is contained in:
parent
3e5a905544
commit
9948a76602
3 changed files with 26 additions and 16 deletions
|
|
@ -7,10 +7,10 @@
|
||||||
|
|
||||||
let
|
let
|
||||||
# Define the specific toolchain with ESP32-C6 support
|
# Define the specific toolchain with ESP32-C6 support
|
||||||
rustToolchain = pkgs.rust-bin.selectLatestNightlyWith(toolchain: toolchain.default.override {
|
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
|
||||||
targets = [ "riscv32imac-unknown-none-elf" ];
|
targets = [ "riscv32imac-unknown-none-elf" ];
|
||||||
extensions = [ "rust-src" "llvm-tools-preview" ];
|
extensions = [ "rust-src" "llvm-tools-preview" ];
|
||||||
});
|
};
|
||||||
in
|
in
|
||||||
pkgs.mkShell {
|
pkgs.mkShell {
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use esp_hal::{
|
||||||
rmt::{Channel, PulseCode, Rx, Tx, TxChannelCreator},
|
rmt::{Channel, PulseCode, Rx, Tx, TxChannelCreator},
|
||||||
};
|
};
|
||||||
use num_traits::float::FloatCore;
|
use num_traits::float::FloatCore;
|
||||||
|
use rtt_target::{rprint, rprintln};
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
|
|
@ -140,6 +141,7 @@ impl<'a> DShot<'a> {
|
||||||
let clk_speed = clk_speed.unwrap_or(80_000_000);
|
let clk_speed = clk_speed.unwrap_or(80_000_000);
|
||||||
let clk_divider = clk_divider.unwrap_or(1);
|
let clk_divider = clk_divider.unwrap_or(1);
|
||||||
let bit_ticks = BitTicks::from_clk(clk_speed, clk_divider, speed.bit_times(),speed);
|
let bit_ticks = BitTicks::from_clk(clk_speed, clk_divider, speed.bit_times(),speed);
|
||||||
|
rprint!("bit_ticks.t1_h:{},t1_l:{},t0_h:{},t0_l{}",bit_ticks.t1_h,bit_ticks.t1_l,bit_ticks.t0_h,bit_ticks.t0_l);
|
||||||
Self {
|
Self {
|
||||||
rx_channel: rx_channel,
|
rx_channel: rx_channel,
|
||||||
tx_channel: tx_channel,
|
tx_channel: tx_channel,
|
||||||
|
|
@ -165,10 +167,13 @@ impl<'a> DShot<'a> {
|
||||||
pub fn create_pulses(&mut self, throttle_value: u16, telemetry: bool) -> [u32; 17] {
|
pub fn create_pulses(&mut self, throttle_value: u16, telemetry: bool) -> [u32; 17] {
|
||||||
let frame = Self::create_frame(throttle_value, telemetry);
|
let frame = Self::create_frame(throttle_value, telemetry);
|
||||||
let mut pulses = [0; 17];
|
let mut pulses = [0; 17];
|
||||||
|
rprintln!("CREATING NEW FRAME!");
|
||||||
|
rprintln!("--------------------");
|
||||||
for i in 0..16 {
|
for i in 0..16 {
|
||||||
let bit = (frame >> (15 - i)) & 1;
|
let bit = (frame >> (15 - i)) & 1;
|
||||||
|
|
||||||
pulses[i] = if bit == 1 {
|
pulses[i] = if bit == 1 {
|
||||||
|
rprint!("1");
|
||||||
PulseCode::new(
|
PulseCode::new(
|
||||||
Level::High,
|
Level::High,
|
||||||
self.bit_ticks.t1_h,
|
self.bit_ticks.t1_h,
|
||||||
|
|
@ -177,6 +182,7 @@ impl<'a> DShot<'a> {
|
||||||
)
|
)
|
||||||
.into()
|
.into()
|
||||||
} else {
|
} else {
|
||||||
|
rprint!("0");
|
||||||
PulseCode::new(
|
PulseCode::new(
|
||||||
Level::High,
|
Level::High,
|
||||||
self.bit_ticks.t0_h,
|
self.bit_ticks.t0_h,
|
||||||
|
|
@ -186,14 +192,10 @@ impl<'a> DShot<'a> {
|
||||||
.into()
|
.into()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
rprintln!("");
|
||||||
|
rprintln!("--------------------");
|
||||||
|
|
||||||
pulses[16] = PulseCode::new(
|
pulses[16] =0;
|
||||||
Level::Low,
|
|
||||||
self.bit_ticks.t1_h * 2,
|
|
||||||
Level::Low,
|
|
||||||
0,
|
|
||||||
)
|
|
||||||
.into();
|
|
||||||
pulses
|
pulses
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,9 @@ const DEFAULT_SPIN_TIME: u32 = 10;
|
||||||
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
|
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
|
||||||
esp_bootloader_esp_idf::esp_app_desc!();
|
esp_bootloader_esp_idf::esp_app_desc!();
|
||||||
use crate::peripherals::Command;
|
use crate::peripherals::Command;
|
||||||
|
use esp_hal::gpio::Output;
|
||||||
|
use esp_hal::gpio::Level;
|
||||||
|
use esp_hal::gpio::OutputConfig;
|
||||||
|
|
||||||
#[main]
|
#[main]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
|
|
@ -88,14 +91,19 @@ fn main() -> ! {
|
||||||
let rmt = Rmt::new(peripherals.RMT, freq).expect("CAN NOT SET FREQUENCY");
|
let rmt = Rmt::new(peripherals.RMT, freq).expect("CAN NOT SET FREQUENCY");
|
||||||
let rx_config = RxChannelConfig::default().with_clk_divider(1);
|
let rx_config = RxChannelConfig::default().with_clk_divider(1);
|
||||||
let tx_config = TxChannelConfig::default().with_clk_divider(1);
|
let tx_config = TxChannelConfig::default().with_clk_divider(1);
|
||||||
|
let mut toggle_pin = Output::new(peripherals.GPIO2, Level::Low, OutputConfig::default());
|
||||||
let mut tx_channel = unsafe{rmt.channel0.configure_tx(peripherals.GPIO11,tx_config ).unwrap()};
|
let mut tx_channel = rmt.channel0.configure_tx(peripherals.GPIO23,tx_config ).expect("creation of TX_CHANNEL FAILED!");
|
||||||
let mut rx_channel = rmt.channel3.configure_rx(peripherals.GPIO12,rx_config).unwrap();
|
let mut rx_channel = rmt.channel3.configure_rx(peripherals.GPIO14,rx_config).unwrap();
|
||||||
let mut dshot_esc = dshot::DShot::new(&mut rx_channel, &mut tx_channel, DShotSpeed::DShot600, Some(80_000_000), Some(1));
|
let mut dshot_esc = dshot::DShot::new(&mut rx_channel, &mut tx_channel, DShotSpeed::DShot600, Some(80_000_000), Some(1));
|
||||||
rprintln!("SENDING RMT");
|
rprintln!("SENDING RMT");
|
||||||
dshot_esc.arm(&mut delay);
|
loop{
|
||||||
dshot_esc.write_throttle(20, false);
|
delay.delay_millis(1000);
|
||||||
rprintln!("RMT SENT!");
|
toggle_pin.set_high();
|
||||||
|
dshot_esc.write_throttle(2047,true);
|
||||||
|
toggle_pin.set_low();
|
||||||
|
|
||||||
|
}
|
||||||
|
// rprintln!("RMT SENT!");
|
||||||
// let mut esc = AfroEsc::new(&mut pwm_pin);;
|
// let mut esc = AfroEsc::new(&mut pwm_pin);;
|
||||||
// esc.set_timestamp(1000);
|
// esc.set_timestamp(1000);
|
||||||
// delay.delay_millis(3000);
|
// delay.delay_millis(3000);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue