2021-07-19 23:54:18 +02:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
use defmt::*;
|
2022-08-17 23:40:16 +02:00
|
|
|
use embassy_executor::Spawner;
|
2021-07-19 23:54:18 +02:00
|
|
|
use embassy_rp::spi::Spi;
|
2022-08-17 18:49:55 +02:00
|
|
|
use embassy_rp::{gpio, spi};
|
2021-07-19 23:54:18 +02:00
|
|
|
use gpio::{Level, Output};
|
2022-06-12 22:15:44 +02:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
2022-04-02 04:35:06 +02:00
|
|
|
|
2022-07-29 21:58:35 +02:00
|
|
|
#[embassy_executor::main]
|
2022-08-17 18:49:55 +02:00
|
|
|
async fn main(_spawner: Spawner) {
|
|
|
|
let p = embassy_rp::init(Default::default());
|
2021-07-19 23:54:18 +02:00
|
|
|
info!("Hello World!");
|
|
|
|
|
|
|
|
// Example for resistive touch sensor in Waveshare Pico-ResTouch
|
|
|
|
|
|
|
|
let miso = p.PIN_12;
|
|
|
|
let mosi = p.PIN_11;
|
|
|
|
let clk = p.PIN_10;
|
|
|
|
let touch_cs = p.PIN_16;
|
|
|
|
|
|
|
|
// create SPI
|
|
|
|
let mut config = spi::Config::default();
|
|
|
|
config.frequency = 2_000_000;
|
2022-02-12 01:34:41 +01:00
|
|
|
let mut spi = Spi::new(p.SPI1, clk, mosi, miso, config);
|
2021-07-19 23:54:18 +02:00
|
|
|
|
|
|
|
// Configure CS
|
|
|
|
let mut cs = Output::new(touch_cs, Level::Low);
|
|
|
|
|
|
|
|
loop {
|
|
|
|
cs.set_low();
|
|
|
|
let mut buf = [0x90, 0x00, 0x00, 0xd0, 0x00, 0x00];
|
2022-02-15 17:28:48 +01:00
|
|
|
spi.blocking_transfer_in_place(&mut buf).unwrap();
|
2021-07-19 23:54:18 +02:00
|
|
|
cs.set_high();
|
|
|
|
|
|
|
|
let x = (buf[1] as u32) << 5 | (buf[2] as u32) >> 3;
|
|
|
|
let y = (buf[4] as u32) << 5 | (buf[5] as u32) >> 3;
|
|
|
|
|
|
|
|
info!("touch: {=u32} {=u32}", x, y);
|
|
|
|
}
|
|
|
|
}
|