aboutsummaryrefslogtreecommitdiff
path: root/examples/mimxrt6/src/bin/spi.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/mimxrt6/src/bin/spi.rs')
-rw-r--r--examples/mimxrt6/src/bin/spi.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/examples/mimxrt6/src/bin/spi.rs b/examples/mimxrt6/src/bin/spi.rs
new file mode 100644
index 000000000..4854432e8
--- /dev/null
+++ b/examples/mimxrt6/src/bin/spi.rs
@@ -0,0 +1,51 @@
1#![no_std]
2#![no_main]
3
4use defmt::info;
5use embassy_executor::Spawner;
6use embassy_imxrt::flexcomm::spi::Spi;
7use embassy_imxrt::gpio;
8use embassy_time::{Delay, Timer};
9use embedded_hal_bus::spi::ExclusiveDevice;
10use is31fl3743b_driver::{CSy, Is31fl3743b, SWx};
11use {defmt_rtt as _, embassy_imxrt_examples as _, panic_probe as _};
12
13#[embassy_executor::main]
14async fn main(_spawner: Spawner) {
15 let p = embassy_imxrt::init(Default::default());
16
17 info!("Initializing SPI");
18
19 let cs = gpio::Output::new(
20 p.PIO1_6,
21 gpio::Level::Low,
22 gpio::DriveMode::PushPull,
23 gpio::DriveStrength::Normal,
24 gpio::SlewRate::Standard,
25 );
26
27 let spi = Spi::new_blocking(p.FLEXCOMM5, p.PIO1_3, p.PIO1_5, p.PIO1_4, Default::default());
28 let delay = Delay;
29
30 // One SPI device only on the SPI bus
31 let spi_dev = ExclusiveDevice::new(spi, cs, delay).unwrap();
32
33 // Instantiate IS31FL3743B device
34 let mut driver = Is31fl3743b::new(spi_dev).unwrap();
35
36 // Enable phase delay to help reduce power noise
37 let _ = driver.enable_phase_delay();
38 // Set global current, check method documentation for more info
39 let _ = driver.set_global_current(90);
40
41 let _ = driver.set_led_peak_current_bulk(SWx::SW1, CSy::CS1, &[100; 11 * 18]);
42
43 // Driver is fully set up, we can now start turning on LEDs!
44 // Create a white breathing effect
45 loop {
46 for brightness in (0..=255_u8).chain((0..=255).rev()) {
47 let _ = driver.set_led_brightness_bulk(SWx::SW1, CSy::CS1, &[brightness; 11 * 18]);
48 Timer::after_micros(1).await;
49 }
50 }
51}