aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/dsihost.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32/src/dsihost.rs')
-rw-r--r--embassy-stm32/src/dsihost.rs31
1 files changed, 11 insertions, 20 deletions
diff --git a/embassy-stm32/src/dsihost.rs b/embassy-stm32/src/dsihost.rs
index deda956af..b8945820c 100644
--- a/embassy-stm32/src/dsihost.rs
+++ b/embassy-stm32/src/dsihost.rs
@@ -5,17 +5,10 @@ use core::marker::PhantomData;
5use embassy_hal_internal::PeripheralType; 5use embassy_hal_internal::PeripheralType;
6 6
7//use crate::gpio::{AnyPin, SealedPin}; 7//use crate::gpio::{AnyPin, SealedPin};
8use crate::block_for_us;
8use crate::gpio::{AfType, AnyPin, OutputType, Speed}; 9use crate::gpio::{AfType, AnyPin, OutputType, Speed};
9use crate::rcc::{self, RccPeripheral}; 10use crate::rcc::{self, RccPeripheral};
10use crate::{peripherals, Peri}; 11use crate::{Peri, peripherals};
11
12/// Performs a busy-wait delay for a specified number of microseconds.
13pub fn blocking_delay_ms(ms: u32) {
14 #[cfg(feature = "time")]
15 embassy_time::block_for(embassy_time::Duration::from_millis(ms as u64));
16 #[cfg(not(feature = "time"))]
17 cortex_m::asm::delay(unsafe { crate::rcc::get_freqs() }.sys.to_hertz().unwrap().0 / 1_000 * ms);
18}
19 12
20/// PacketTypes extracted from CubeMX 13/// PacketTypes extracted from CubeMX
21#[repr(u8)] 14#[repr(u8)]
@@ -121,17 +114,15 @@ impl<'d, T: Instance> DsiHost<'d, T> {
121 114
122 /// DCS or Generic short/long write command 115 /// DCS or Generic short/long write command
123 pub fn write_cmd(&mut self, channel_id: u8, address: u8, data: &[u8]) -> Result<(), Error> { 116 pub fn write_cmd(&mut self, channel_id: u8, address: u8, data: &[u8]) -> Result<(), Error> {
124 assert!(data.len() > 0); 117 match data.len() {
125 118 0 => self.short_write(channel_id, PacketType::DcsShortPktWriteP0, address, 0),
126 if data.len() == 1 { 119 1 => self.short_write(channel_id, PacketType::DcsShortPktWriteP1, address, data[0]),
127 self.short_write(channel_id, PacketType::DcsShortPktWriteP1, address, data[0]) 120 _ => self.long_write(
128 } else {
129 self.long_write(
130 channel_id, 121 channel_id,
131 PacketType::DcsLongPktWrite, // FIXME: This might be a generic long packet, as well... 122 PacketType::DcsLongPktWrite, // FIXME: This might be a generic long packet, as well...
132 address, 123 address,
133 data, 124 data,
134 ) 125 ),
135 } 126 }
136 } 127 }
137 128
@@ -336,7 +327,7 @@ impl<'d, T: Instance> DsiHost<'d, T> {
336 if T::regs().gpsr().read().cmdfe() { 327 if T::regs().gpsr().read().cmdfe() {
337 return Ok(()); 328 return Ok(());
338 } 329 }
339 blocking_delay_ms(1); 330 block_for_us(1_000);
340 } 331 }
341 Err(Error::FifoTimeout) 332 Err(Error::FifoTimeout)
342 } 333 }
@@ -347,7 +338,7 @@ impl<'d, T: Instance> DsiHost<'d, T> {
347 if !T::regs().gpsr().read().cmdff() { 338 if !T::regs().gpsr().read().cmdff() {
348 return Ok(()); 339 return Ok(());
349 } 340 }
350 blocking_delay_ms(1); 341 block_for_us(1_000);
351 } 342 }
352 Err(Error::FifoTimeout) 343 Err(Error::FifoTimeout)
353 } 344 }
@@ -358,7 +349,7 @@ impl<'d, T: Instance> DsiHost<'d, T> {
358 if !self.read_busy() { 349 if !self.read_busy() {
359 return Ok(()); 350 return Ok(());
360 } 351 }
361 blocking_delay_ms(1); 352 block_for_us(1_000);
362 } 353 }
363 Err(Error::ReadTimeout) 354 Err(Error::ReadTimeout)
364 } 355 }
@@ -369,7 +360,7 @@ impl<'d, T: Instance> DsiHost<'d, T> {
369 if !T::regs().gpsr().read().prdfe() { 360 if !T::regs().gpsr().read().prdfe() {
370 return Ok(()); 361 return Ok(());
371 } 362 }
372 blocking_delay_ms(1); 363 block_for_us(1_000);
373 } 364 }
374 Err(Error::FifoTimeout) 365 Err(Error::FifoTimeout)
375 } 366 }