-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from MabezDev/touch-sense-controller
Touch sense controller * Move semantics on the sample pin means only that pin and the other pins in the group * Blocking api with `acquire` * Event driven with `listen` & `start`
- Loading branch information
Showing
11 changed files
with
382 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//! Test the serial interface | ||
//! | ||
//! This example requires you to short (connect) the TX and RX pins. | ||
#![deny(unsafe_code)] | ||
// #![deny(warnings)] | ||
#![no_main] | ||
#![no_std] | ||
|
||
extern crate cortex_m; | ||
#[macro_use(entry, exception)] | ||
extern crate cortex_m_rt as rt; | ||
extern crate panic_semihosting; | ||
|
||
extern crate stm32l432xx_hal as hal; | ||
|
||
|
||
use hal::prelude::*; | ||
use hal::stm32l4::stm32l4x2; | ||
use hal::tsc::Tsc; | ||
use rt::ExceptionFrame; | ||
|
||
entry!(main); | ||
|
||
fn main() -> ! { | ||
let p = stm32l4x2::Peripherals::take().unwrap(); | ||
// let cp = cortex_m::Peripherals::take().unwrap(); | ||
|
||
let mut flash = p.FLASH.constrain(); | ||
let mut rcc = p.RCC.constrain(); | ||
// let mut gpioa = p.GPIOA.split(&mut rcc.ahb2); | ||
let mut gpiob = p.GPIOB.split(&mut rcc.ahb2); | ||
|
||
// clock configuration using the default settings (all clocks run at 8 MHz) | ||
let _clocks = rcc.cfgr.freeze(&mut flash.acr); | ||
// TRY this alternate clock configuration (clocks run at nearly the maximum frequency) | ||
// let clocks = rcc.cfgr.sysclk(64.mhz()).pclk1(32.mhz()).freeze(&mut flash.acr); | ||
|
||
// let mut delay = Delay::new(cp.SYST, clocks); | ||
let mut led = gpiob.pb3.into_push_pull_output(&mut gpiob.moder, &mut gpiob.otyper); | ||
|
||
let sample_pin = gpiob.pb4.into_touch_sample(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl); | ||
let mut c1 = gpiob.pb5.into_touch_channel(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl); | ||
let mut c2 = gpiob.pb6.into_touch_channel(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl); | ||
// let mut c3 = gpiob.pb7.into_touch_channel(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl); | ||
|
||
// , (c1, c2, c3) | ||
let tsc = Tsc::tsc(p.TSC, sample_pin, &mut rcc.ahb1); | ||
|
||
let baseline = tsc.acquire(&mut c1).unwrap(); | ||
let threshold = (baseline / 100) * 60; | ||
|
||
loop { | ||
let touched = tsc.acquire(&mut c1).unwrap(); | ||
let _touched_c2 = tsc.acquire(&mut c2).unwrap(); | ||
if touched < threshold { | ||
led.set_high(); | ||
} else { | ||
led.set_low(); | ||
} | ||
} | ||
} | ||
|
||
exception!(HardFault, hard_fault); | ||
|
||
fn hard_fault(ef: &ExceptionFrame) -> ! { | ||
panic!("{:#?}", ef); | ||
} | ||
|
||
exception!(*, default_handler); | ||
|
||
fn default_handler(irqn: i16) { | ||
panic!("Unhandled exception (IRQn = {})", irqn); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//! Direct Memory Access Engine | ||
#![allow(dead_code)] | ||
|
||
use core::marker::PhantomData; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//! Power management | ||
use rcc::{APB1R1}; | ||
use stm32l4::stm32l4x2::{pwr, PWR}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/// RTC peripheral abstraction | ||
//! RTC peripheral abstraction | ||
use datetime::*; | ||
use rcc::{BDCR, APB1R1}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.