diff options
| author | Chuck Davis <[email protected]> | 2022-10-08 14:38:41 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-10-08 14:38:41 -0500 |
| commit | 3d0ba58b2d337ca74c5ae7d1d594af21f4b5ff8c (patch) | |
| tree | 9678b1475cdf69abbf5e795da33184ed25a167de /examples/rp/src | |
| parent | f554962f54b9f9e8f85a0dd099635619bd1acd1d (diff) | |
| parent | f8fd6ab208fd09142ab9789078e9b23ba8c3e6a9 (diff) | |
Merge branch 'embassy-rs:master' into master
Diffstat (limited to 'examples/rp/src')
| -rw-r--r-- | examples/rp/src/bin/i2c_blocking.rs | 70 | ||||
| -rw-r--r-- | examples/rp/src/bin/spi_display.rs | 12 |
2 files changed, 76 insertions, 6 deletions
diff --git a/examples/rp/src/bin/i2c_blocking.rs b/examples/rp/src/bin/i2c_blocking.rs new file mode 100644 index 000000000..7623e33c8 --- /dev/null +++ b/examples/rp/src/bin/i2c_blocking.rs | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::*; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_rp::i2c::{self, Config}; | ||
| 8 | use embassy_time::{Duration, Timer}; | ||
| 9 | use embedded_hal_1::i2c::I2c; | ||
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 11 | |||
| 12 | #[allow(dead_code)] | ||
| 13 | mod mcp23017 { | ||
| 14 | pub const ADDR: u8 = 0x20; // default addr | ||
| 15 | |||
| 16 | pub const IODIRA: u8 = 0x00; | ||
| 17 | pub const IPOLA: u8 = 0x02; | ||
| 18 | pub const GPINTENA: u8 = 0x04; | ||
| 19 | pub const DEFVALA: u8 = 0x06; | ||
| 20 | pub const INTCONA: u8 = 0x08; | ||
| 21 | pub const IOCONA: u8 = 0x0A; | ||
| 22 | pub const GPPUA: u8 = 0x0C; | ||
| 23 | pub const INTFA: u8 = 0x0E; | ||
| 24 | pub const INTCAPA: u8 = 0x10; | ||
| 25 | pub const GPIOA: u8 = 0x12; | ||
| 26 | pub const OLATA: u8 = 0x14; | ||
| 27 | pub const IODIRB: u8 = 0x01; | ||
| 28 | pub const IPOLB: u8 = 0x03; | ||
| 29 | pub const GPINTENB: u8 = 0x05; | ||
| 30 | pub const DEFVALB: u8 = 0x07; | ||
| 31 | pub const INTCONB: u8 = 0x09; | ||
| 32 | pub const IOCONB: u8 = 0x0B; | ||
| 33 | pub const GPPUB: u8 = 0x0D; | ||
| 34 | pub const INTFB: u8 = 0x0F; | ||
| 35 | pub const INTCAPB: u8 = 0x11; | ||
| 36 | pub const GPIOB: u8 = 0x13; | ||
| 37 | pub const OLATB: u8 = 0x15; | ||
| 38 | } | ||
| 39 | |||
| 40 | #[embassy_executor::main] | ||
| 41 | async fn main(_spawner: Spawner) { | ||
| 42 | let p = embassy_rp::init(Default::default()); | ||
| 43 | |||
| 44 | let sda = p.PIN_14; | ||
| 45 | let scl = p.PIN_15; | ||
| 46 | |||
| 47 | info!("set up i2c "); | ||
| 48 | let mut i2c = i2c::I2c::new_blocking(p.I2C1, scl, sda, Config::default()); | ||
| 49 | |||
| 50 | use mcp23017::*; | ||
| 51 | |||
| 52 | info!("init mcp23017 config for IxpandO"); | ||
| 53 | // init - a outputs, b inputs | ||
| 54 | i2c.write(ADDR, &[IODIRA, 0x00]).unwrap(); | ||
| 55 | i2c.write(ADDR, &[IODIRB, 0xff]).unwrap(); | ||
| 56 | i2c.write(ADDR, &[GPPUB, 0xff]).unwrap(); // pullups | ||
| 57 | |||
| 58 | let mut val = 0xaa; | ||
| 59 | loop { | ||
| 60 | let mut portb = [0]; | ||
| 61 | |||
| 62 | i2c.write(mcp23017::ADDR, &[GPIOA, val]).unwrap(); | ||
| 63 | i2c.write_read(mcp23017::ADDR, &[GPIOB], &mut portb).unwrap(); | ||
| 64 | |||
| 65 | info!("portb = {:02x}", portb[0]); | ||
| 66 | val = !val; | ||
| 67 | |||
| 68 | Timer::after(Duration::from_secs(1)).await; | ||
| 69 | } | ||
| 70 | } | ||
diff --git a/examples/rp/src/bin/spi_display.rs b/examples/rp/src/bin/spi_display.rs index 23cd4355e..778cad3fa 100644 --- a/examples/rp/src/bin/spi_display.rs +++ b/examples/rp/src/bin/spi_display.rs | |||
| @@ -108,9 +108,9 @@ mod shared_spi { | |||
| 108 | use core::cell::RefCell; | 108 | use core::cell::RefCell; |
| 109 | use core::fmt::Debug; | 109 | use core::fmt::Debug; |
| 110 | 110 | ||
| 111 | use embedded_hal_1::digital::blocking::OutputPin; | 111 | use embedded_hal_1::digital::OutputPin; |
| 112 | use embedded_hal_1::spi; | 112 | use embedded_hal_1::spi; |
| 113 | use embedded_hal_1::spi::blocking::SpiDevice; | 113 | use embedded_hal_1::spi::SpiDevice; |
| 114 | 114 | ||
| 115 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] | 115 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] |
| 116 | pub enum SpiDeviceWithCsError<BUS, CS> { | 116 | pub enum SpiDeviceWithCsError<BUS, CS> { |
| @@ -153,7 +153,7 @@ mod shared_spi { | |||
| 153 | 153 | ||
| 154 | impl<'a, BUS, CS> SpiDevice for SpiDeviceWithCs<'a, BUS, CS> | 154 | impl<'a, BUS, CS> SpiDevice for SpiDeviceWithCs<'a, BUS, CS> |
| 155 | where | 155 | where |
| 156 | BUS: spi::blocking::SpiBusFlush, | 156 | BUS: spi::SpiBusFlush, |
| 157 | CS: OutputPin, | 157 | CS: OutputPin, |
| 158 | { | 158 | { |
| 159 | type Bus = BUS; | 159 | type Bus = BUS; |
| @@ -182,7 +182,7 @@ mod shared_spi { | |||
| 182 | 182 | ||
| 183 | /// Driver for the XPT2046 resistive touchscreen sensor | 183 | /// Driver for the XPT2046 resistive touchscreen sensor |
| 184 | mod touch { | 184 | mod touch { |
| 185 | use embedded_hal_1::spi::blocking::{SpiBus, SpiBusRead, SpiBusWrite, SpiDevice}; | 185 | use embedded_hal_1::spi::{SpiBus, SpiBusRead, SpiBusWrite, SpiDevice}; |
| 186 | 186 | ||
| 187 | struct Calibration { | 187 | struct Calibration { |
| 188 | x1: i32, | 188 | x1: i32, |
| @@ -246,8 +246,8 @@ mod touch { | |||
| 246 | 246 | ||
| 247 | mod my_display_interface { | 247 | mod my_display_interface { |
| 248 | use display_interface::{DataFormat, DisplayError, WriteOnlyDataCommand}; | 248 | use display_interface::{DataFormat, DisplayError, WriteOnlyDataCommand}; |
| 249 | use embedded_hal_1::digital::blocking::OutputPin; | 249 | use embedded_hal_1::digital::OutputPin; |
| 250 | use embedded_hal_1::spi::blocking::{SpiBusWrite, SpiDevice}; | 250 | use embedded_hal_1::spi::{SpiBusWrite, SpiDevice}; |
| 251 | 251 | ||
| 252 | /// SPI display interface. | 252 | /// SPI display interface. |
| 253 | /// | 253 | /// |
