Skip to content

Commit ff3936b

Browse files
committed
Added timer implmentations for tim15/16. Added stm32 capacitance notes to stop of tsc mod
1 parent 30e39c7 commit ff3936b

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

src/serial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ macro_rules! hal {
103103
// TODO implement pin remaping
104104

105105
// disable hardware flow control
106-
// TODO enable DMA
107106
// usart.cr3.write(|w| w.rtse().clear_bit().ctse().clear_bit());
107+
108108
usart.cr3.write(|w| w.dmat().set_bit().dmar().set_bit()); // enable DMA transfers
109109

110110
let brr = clocks.$pclkX().0 / baud_rate.0;

src/timer.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
use cast::{u16, u32};
44
use hal::timer::{CountDown, Periodic};
55
use nb;
6-
use stm32l4::stm32l4x2::{TIM2, /* TODO TIM3 ,*/ TIM6, TIM7};
6+
use stm32l4::stm32l4x2::{TIM2, TIM6, TIM7, TIM15, TIM16};
77
use void::Void;
88

9-
use rcc::{APB1R1, Clocks};
9+
use rcc::{APB1R1, Clocks, APB2};
1010
use time::Hertz;
1111

1212
/// Hardware timers
@@ -23,7 +23,7 @@ pub enum Event {
2323
}
2424

2525
macro_rules! hal {
26-
($($TIM:ident: ($tim:ident, $timXen:ident, $timXrst:ident),)+) => {
26+
($($TIM:ident: ($tim:ident, $timXen:ident, $timXrst:ident, $apb:ident),)+) => {
2727
$(
2828
impl Periodic for Timer<$TIM> {}
2929

@@ -73,14 +73,14 @@ macro_rules! hal {
7373
// even if the `$TIM` are non overlapping (compare to the `free` function below
7474
// which just works)
7575
/// Configures a TIM peripheral as a periodic count down timer
76-
pub fn $tim<T>(tim: $TIM, timeout: T, clocks: Clocks, apb1: &mut APB1R1) -> Self
76+
pub fn $tim<T>(tim: $TIM, timeout: T, clocks: Clocks, apb: &mut $apb) -> Self
7777
where
7878
T: Into<Hertz>,
7979
{
8080
// enable and reset peripheral to a clean slate state
81-
apb1.enr().modify(|_, w| w.$timXen().set_bit());
82-
apb1.rstr().modify(|_, w| w.$timXrst().set_bit());
83-
apb1.rstr().modify(|_, w| w.$timXrst().clear_bit());
81+
apb.enr().modify(|_, w| w.$timXen().set_bit());
82+
apb.rstr().modify(|_, w| w.$timXrst().set_bit());
83+
apb.rstr().modify(|_, w| w.$timXrst().clear_bit());
8484

8585
let mut timer = Timer {
8686
clocks,
@@ -123,14 +123,10 @@ macro_rules! hal {
123123
}
124124
}
125125

126-
/*
127-
TODO Untested
128-
*/
129-
130126
hal! {
131-
TIM2: (tim2, tim2en, tim2rst),
132-
// TODO fix TIM3
133-
// TIM3: (tim3, tim3en, tim3rst),
134-
TIM6: (tim6, tim6en, tim6rst),
135-
TIM7: (tim7, tim7en, tim7rst),
127+
TIM2: (tim2, tim2en, tim2rst, APB1R1),
128+
TIM6: (tim6, tim6en, tim6rst, APB1R1),
129+
TIM7: (tim7, tim7en, tim7rst, APB1R1),
130+
TIM15: (tim15, tim15en, tim15rst, APB2),
131+
TIM16: (tim16, tim16en, tim16rst, APB2),
136132
}

src/tsc.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
//! Touch sense controller
2+
//!
3+
//! From STM32 (https://www.st.com/content/ccc/resource/technical/document/application_note/9d/be/03/8c/5d/8c/49/50/DM00088471.pdf/files/DM00088471.pdf/jcr:content/translations/en.DM00088471.pdf):
4+
//!
5+
//! The Cs capacitance is a key parameter for sensitivity. For touchkey sensors, the Cs value is
6+
//! usually comprised between 8.7nF to 22nF. For linear and rotary touch sensors, the value is
7+
//! usually comprised between 47nF and 100nF. These values are given as reference for an
8+
//! electrode fitting a human finger tip size across a few millimeters dielectric panel.
29
310
use rcc::AHB1;
411
use stm32l4::stm32l4x2::{TSC};
@@ -21,7 +28,6 @@ pub enum Error {
2128
InvalidPin
2229
}
2330

24-
// TODO macro to impl all possible channel/sample pin combinations
2531
pub trait SamplePin<TSC> {
2632
const GROUP: u32;
2733
const OFFSET: u32;
@@ -65,10 +71,8 @@ impl ChannelPin<TSC> for PB7<Alternate<AF9, Output<PushPull>>> {
6571
}
6672

6773

68-
// TODO currently requires all the pins even if a user wants one channel, fix
6974
pub struct Tsc<SPIN> {
7075
sample_pin: SPIN,
71-
// pins: PINS,
7276
tsc: TSC
7377
}
7478

@@ -102,8 +106,6 @@ impl<SPIN> Tsc<SPIN> {
102106
.tsce()
103107
.set_bit()
104108
});
105-
106-
// TODO allow configuration
107109

108110
let bit_pos = SPIN::OFFSET + (4 * (SPIN::GROUP - 1));
109111

0 commit comments

Comments
 (0)