safety commit
This commit is contained in:
parent
5f9e718f86
commit
3e5a905544
2 changed files with 53 additions and 19 deletions
|
|
@ -5,10 +5,8 @@
|
|||
reason = "mem::forget is generally not safe to do with esp_hal types, especially those \
|
||||
holding buffers for the duration of a data transfer."
|
||||
)]
|
||||
use core::fmt::Write;
|
||||
use alloc::string::ToString;
|
||||
use esp_hal::uart::{Config, Uart};
|
||||
|
||||
use esp_hal::clock::CpuClock;
|
||||
use esp_hal::delay::Delay;
|
||||
use esp_hal::main;
|
||||
|
|
@ -18,7 +16,7 @@ use esp_hal::gpio::{Input, InputConfig};
|
|||
use esp_hal::mcpwm::operator::PwmPinConfig;
|
||||
use esp_hal::mcpwm::timer::PwmWorkingMode;
|
||||
use esp_hal::time::Rate;
|
||||
|
||||
use esp_hal::rmt::{Rmt, TxChannelConfig, TxChannelCreator};
|
||||
use esp_hal::handler;
|
||||
|
||||
use core::cell::RefCell;
|
||||
|
|
@ -28,10 +26,19 @@ use esp_hal::time::{Duration, Instant};
|
|||
use esp_hal::timer::timg::TimerGroup;
|
||||
use rtt_target::rprintln;
|
||||
mod dc_driver;
|
||||
|
||||
mod peripherals;
|
||||
|
||||
use dc_driver::afroesc::AfroEsc;
|
||||
use peripherals::nextion::Nextion;
|
||||
|
||||
//DSHOT via rmt!
|
||||
use dc_driver::dshot::DShot;
|
||||
use dc_driver::dshot::DShotSpeed;
|
||||
|
||||
use esp_hal::rmt::RxChannelCreator;
|
||||
use esp_hal::rmt::RxChannelConfig;
|
||||
use crate::dc_driver::dshot;
|
||||
use crate::peripherals::ErrCommand;
|
||||
#[panic_handler]
|
||||
fn panic(_: &core::panic::PanicInfo) -> ! {
|
||||
|
|
@ -49,6 +56,7 @@ const DEFAULT_SPIN_TIME: u32 = 10;
|
|||
// This creates a default app-descriptor required by the esp-idf bootloader.
|
||||
// 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!();
|
||||
use crate::peripherals::Command;
|
||||
|
||||
#[main]
|
||||
fn main() -> ! {
|
||||
|
|
@ -74,7 +82,21 @@ fn main() -> ! {
|
|||
.timer_clock_with_frequency(19_999, PwmWorkingMode::Increase, Rate::from_hz(50))
|
||||
.unwrap();
|
||||
mcpwm.timer0.start(timer_clock_cfg);
|
||||
// let mut esc = AfroEsc::new(&mut pwm_pin);
|
||||
|
||||
//setup RMT
|
||||
let freq = Rate::from_mhz(80);
|
||||
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 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!");
|
||||
// let mut esc = AfroEsc::new(&mut pwm_pin);;
|
||||
// esc.set_timestamp(1000);
|
||||
// delay.delay_millis(3000);
|
||||
// esc.set_duty_percent(10);
|
||||
|
|
@ -84,7 +106,6 @@ fn main() -> ! {
|
|||
// delay.delay_millis(3000);
|
||||
//gpio 9 is the button
|
||||
let input_config = InputConfig::default().with_pull(esp_hal::gpio::Pull::Up);
|
||||
use crate::peripherals::Command;
|
||||
//let emergency_button = peripherals.GPIO9;
|
||||
let mut emergency_button = Input::new(peripherals.GPIO9, input_config);
|
||||
critical_section::with(|cs| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue