adds cell for fetching the RPM
This commit is contained in:
parent
6c38cd59ee
commit
47f224055b
2 changed files with 21 additions and 6 deletions
|
|
@ -4,7 +4,7 @@ use esp_hal::{
|
|||
gpio::Level,
|
||||
rmt::{Channel, PulseCode, SingleShotTxTransaction},
|
||||
};
|
||||
use core::{cell::{Ref, RefCell}, ops::Index};
|
||||
use core::{cell::{self, Cell, Ref, RefCell}, ops::Index};
|
||||
use num_traits::float::FloatCore;
|
||||
use rtt_target::{rprint, rprintln};
|
||||
|
||||
|
|
@ -12,6 +12,10 @@ fn calculate_crc(frame: u16) -> u16 {
|
|||
(0xffff ^ (frame ^ (frame >> 4) ^ (frame >> 8))) & 0xF
|
||||
}
|
||||
|
||||
/*https://de.aliexpress.com/item/1005009484033753.html?spm=a2g0o.productlist.main.2.6389651cV8lVw8&algo_pvid=9cfe024b-8aff-49ea-981b-824f392de976&algo_exp_id=9cfe024b-8aff-49ea-981b-824f392de976-1&pdp_ext_f=%7B%22order%22%3A%2232%22%2C%22eval%22%3A%221%22%2C%22fromPage%22%3A%22search%22%7D&pdp_npi=6%40dis%21EUR%2111.99%2111.99%21%21%2113.55%2113.55%21%40211b813b17620408595223963e91a7%2112000049243823801%21sea%21DE%212739924950%21X%211%210%21n_tag%3A-29919%3Bd%3Abce7cd6%3Bm03_new_user%3A-29895&curPageLogUid=GNUFzsTU8oDr&utparam-url=scene%3Asearch%7Cquery_from%3A%7Cx_object_id%3A1005009484033753%7C_p_origin_prod%3A
|
||||
IFlight XING-E Pro 2207 2750KV
|
||||
*/
|
||||
const XING_EPRO_22_COILS: u32 = 12;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[allow(non_camel_case_types)]
|
||||
|
|
@ -196,7 +200,7 @@ pub struct DShot<'a> {
|
|||
rx_channel: RefCell<&'a mut Channel<'static, esp_hal::Blocking, esp_hal::rmt::Rx>>,
|
||||
speed: DShotSpeed,
|
||||
bit_ticks: BitTicks,
|
||||
|
||||
rpm: Cell<Option<u32>>,
|
||||
pulses: RefCell<[u32; 17]>,
|
||||
requested_throttle: RefCell<u16>,
|
||||
current_tx: RefCell<Option<SingleShotTxTransaction<'a, 'a, u32>>>,
|
||||
|
|
@ -215,20 +219,25 @@ 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);
|
||||
|
||||
let cell = Cell::new(None);
|
||||
let txc = tx_channel.reborrow().transmit(&[0u32]).unwrap();
|
||||
Self {
|
||||
rx_channel: RefCell::new(rx_channel),
|
||||
speed,
|
||||
bit_ticks,
|
||||
|
||||
rpm: cell,
|
||||
pulses: RefCell::new([0u32; 17]),
|
||||
requested_throttle: RefCell::new(0),
|
||||
current_tx: RefCell::new(Some(txc)),
|
||||
current_tx_done_at: RefCell::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_rpm(&self,new_rpm:u32){
|
||||
self.rpm.set(Some(new_rpm));
|
||||
}
|
||||
pub fn get_rpm(&self) -> Option<u32> {
|
||||
self.rpm.get()
|
||||
}
|
||||
pub fn create_frame(value: u16, telemetry: bool) -> u16 {
|
||||
// Mask to 11 bits (0-2047 range) and set telemetry bit
|
||||
let frame = ((value & 0x07FF) << 1) | telemetry as u16;
|
||||
|
|
@ -301,7 +310,9 @@ impl<'a> DShot<'a> {
|
|||
// Fucking got it.
|
||||
let exp = data >> 9;
|
||||
let mantissa = data & 0b111111111;
|
||||
let rpm = mantissa << exp;
|
||||
let mut rpm: u32 = (mantissa << exp).into();
|
||||
rpm = (rpm*1000);
|
||||
|
||||
rprintln!("RPM: {}", rpm);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,6 +100,10 @@ fn main() -> ! {
|
|||
loop {
|
||||
dshot_esc.process();
|
||||
dshot_esc.set_throttle(150);
|
||||
match dshot_esc.get_rpm() {
|
||||
Some(x) => {rprintln!("GOT RPM {}",x)},
|
||||
None => {rprintln!("NO RPM!")}
|
||||
}
|
||||
}
|
||||
|
||||
// rprintln!("RMT SENT!");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue