diff --git a/spinnyboy_rust/shell.nix b/spinnyboy_rust/shell.nix index c4f8346..f09fec4 100644 --- a/spinnyboy_rust/shell.nix +++ b/spinnyboy_rust/shell.nix @@ -7,10 +7,10 @@ let # 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" ]; extensions = [ "rust-src" "llvm-tools-preview" ]; - }); + }; in pkgs.mkShell { nativeBuildInputs = [ diff --git a/spinnyboy_rust/src/bin/dc_driver/dshot.rs b/spinnyboy_rust/src/bin/dc_driver/dshot.rs index d746a7d..54dc764 100644 --- a/spinnyboy_rust/src/bin/dc_driver/dshot.rs +++ b/spinnyboy_rust/src/bin/dc_driver/dshot.rs @@ -5,6 +5,7 @@ use esp_hal::{ rmt::{Channel, PulseCode, Rx, Tx, TxChannelCreator}, }; use num_traits::float::FloatCore; +use rtt_target::{rprint, rprintln}; #[allow(dead_code)] #[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_divider = clk_divider.unwrap_or(1); 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 { rx_channel: rx_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] { let frame = Self::create_frame(throttle_value, telemetry); let mut pulses = [0; 17]; + rprintln!("CREATING NEW FRAME!"); + rprintln!("--------------------"); for i in 0..16 { let bit = (frame >> (15 - i)) & 1; - + pulses[i] = if bit == 1 { + rprint!("1"); PulseCode::new( Level::High, self.bit_ticks.t1_h, @@ -177,6 +182,7 @@ impl<'a> DShot<'a> { ) .into() } else { + rprint!("0"); PulseCode::new( Level::High, self.bit_ticks.t0_h, @@ -186,14 +192,10 @@ impl<'a> DShot<'a> { .into() }; } + rprintln!(""); + rprintln!("--------------------"); - pulses[16] = PulseCode::new( - Level::Low, - self.bit_ticks.t1_h * 2, - Level::Low, - 0, - ) - .into(); + pulses[16] =0; pulses } diff --git a/spinnyboy_rust/src/bin/main.rs b/spinnyboy_rust/src/bin/main.rs index 962c731..61589fb 100644 --- a/spinnyboy_rust/src/bin/main.rs +++ b/spinnyboy_rust/src/bin/main.rs @@ -57,6 +57,9 @@ const DEFAULT_SPIN_TIME: u32 = 10; // For more information see: esp_bootloader_esp_idf::esp_app_desc!(); use crate::peripherals::Command; +use esp_hal::gpio::Output; +use esp_hal::gpio::Level; +use esp_hal::gpio::OutputConfig; #[main] fn main() -> ! { @@ -88,14 +91,19 @@ fn main() -> ! { let rmt = Rmt::new(peripherals.RMT, freq).expect("CAN NOT SET FREQUENCY"); let rx_config = RxChannelConfig::default().with_clk_divider(1); let tx_config = TxChannelConfig::default().with_clk_divider(1); - - let mut tx_channel = unsafe{rmt.channel0.configure_tx(peripherals.GPIO11,tx_config ).unwrap()}; - let mut rx_channel = rmt.channel3.configure_rx(peripherals.GPIO12,rx_config).unwrap(); + let mut toggle_pin = Output::new(peripherals.GPIO2, Level::Low, OutputConfig::default()); + 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.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)); rprintln!("SENDING RMT"); - dshot_esc.arm(&mut delay); - dshot_esc.write_throttle(20, false); - rprintln!("RMT SENT!"); + loop{ + delay.delay_millis(1000); + 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);; // esc.set_timestamp(1000); // delay.delay_millis(3000);