Remove unecessary code

This commit is contained in:
Rafael Caricio 2020-06-21 13:50:47 +02:00
parent 99d084fdb4
commit 4be24df654
4 changed files with 15 additions and 257 deletions

9
Cargo.lock generated
View file

@ -219,6 +219,8 @@ dependencies = [
[[package]]
name = "cst816s"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "988624bfaeaa34565792f7badc33cd02e84ba51fff4bbc3cd76f59d4af5658e7"
dependencies = [
"cortex-m 0.6.2",
"embedded-hal",
@ -502,6 +504,12 @@ dependencies = [
"autocfg",
]
[[package]]
name = "numtoa"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e521b6adefa0b2c1fa5d2abdf9a5216288686fe6146249215d884c0e5ab320b0"
[[package]]
name = "peeking_take_while"
version = "0.1.2"
@ -520,6 +528,7 @@ dependencies = [
"embedded-hal",
"lvgl",
"nrf52832-hal",
"numtoa",
"shared-bus",
"st7789",
]

View file

@ -15,7 +15,8 @@ nrf52832-hal = {version = "0.8.1", default-features = false, features = ["xxAA-p
shared-bus = {version = "0.1.4", features = ["cortexm"] }
st7789 = { version = "0.2", features = ["graphics", "batch", "buffer"], default-features = false }
cstr_core = "0.2.0"
cst816s = { path = "../cst816s" }
numtoa = "0.2.3"
cst816s = "0.1.4"
lvgl = { path = "../lvgl-rs/lvgl" }
[profile.dev]

View file

@ -3,7 +3,6 @@
mod backlight;
mod delay;
mod monotonic_nrf52;
// use nrf52832_hal::gpio::Level;
// use nrf52832_hal::{self as p_hal, pac};
@ -25,12 +24,12 @@ use lvgl::style::Style;
use lvgl::widgets::{Btn, Label};
use lvgl::{self, Align, Color, Part, State, Widget, UI};
use crate::monotonic_nrf52::Instant;
use core::panic::PanicInfo;
use core::time::Duration;
use embedded_hal::blocking::delay::{DelayMs, DelayUs};
use embedded_hal::digital::v2::OutputPin;
use nrf52832_hal::prelude::ClocksExt;
use numtoa::NumToA;
pub type HalSpimError = p_hal::spim::Error;
@ -190,32 +189,22 @@ fn main() -> ! {
})
.unwrap();
let mut loop_start = Instant::now();
loop {
ui.task_handler();
if let Some(evt) = touchpad.read_one_touch_event(true) {
latest_touch_point = Point::new(evt.x, evt.y);
// Pressed
latest_touch_status = InputData::Touch(latest_touch_point.clone())
.pressed()
.once();
time_lbl
.set_text(CStr::from_bytes_with_nul("PRESSED\0".as_bytes()).unwrap())
.unwrap();
time_lbl
.set_align(&mut button, Align::OutTopMid, 0, -50)
.unwrap();
} else {
// Released
latest_touch_status = InputData::Touch(latest_touch_point.clone())
.released()
.once();
delay_source.delay_us(1u32);
}
ui.tick_inc(Duration::from_millis(100));
//delay_source.delay_ms(2u32);
loop_start = Instant::now();
ui.task_handler();
ui.tick_inc(Duration::from_secs(1));
}
}

View file

@ -1,241 +0,0 @@
//! Using NRF52 as monotonic timer
//!
//! Source:
//! https://github.com/rtfm-rs/rtfm-examples/blob/master/rtfm_v5/monotonic_nrf52/src/monotonic_nrf52.rs
use core::u32;
use core::{
cmp::Ordering,
convert::{Infallible, TryInto},
fmt, ops,
};
use nrf52832_hal::target;
/// A measurement of the counter. Opaque and useful only with `Duration`
///
/// # Correctness
///
/// Adding or subtracting a `Duration` of more than `(1 << 31)` cycles to an `Instant` effectively
/// makes it "wrap around" and creates an incorrect value. This is also true if the operation is
/// done in steps, e.g. `(instant + dur) + dur` where `dur` is `(1 << 30)` ticks.
#[derive(Clone, Copy, Eq, PartialEq)]
pub struct Instant {
inner: i32,
}
impl Instant {
/// Returns an instant corresponding to "now"
pub fn now() -> Self {
let now = {
let timer = unsafe { &*target::TIMER1::ptr() };
timer.tasks_capture[0].write(|w| unsafe { w.bits(1) });
timer.cc[0].read().bits()
};
Instant { inner: now as i32 }
}
/// Returns the amount of time elapsed since this instant was created.
pub fn elapsed(&self) -> Duration {
Instant::now() - *self
}
/// Returns the underlying count
pub fn counts(&self) -> u32 {
self.inner as u32
}
/// Returns the amount of time elapsed from another instant to this one.
pub fn duration_since(&self, earlier: Instant) -> Duration {
let diff = self.inner - earlier.inner;
assert!(diff >= 0, "second instant is later than self");
Duration { inner: diff as u32 }
}
}
impl fmt::Debug for Instant {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("Instant")
.field(&(self.inner as u32))
.finish()
}
}
impl ops::AddAssign<Duration> for Instant {
fn add_assign(&mut self, dur: Duration) {
// NOTE this is a debug assertion because there's no foolproof way to detect a wrap around;
// the user may write `(instant + dur) + dur` where `dur` is `(1<<31)-1` ticks.
debug_assert!(dur.inner < (1 << 31));
self.inner = self.inner.wrapping_add(dur.inner as i32);
}
}
impl ops::Add<Duration> for Instant {
type Output = Self;
fn add(mut self, dur: Duration) -> Self {
self += dur;
self
}
}
impl ops::SubAssign<Duration> for Instant {
fn sub_assign(&mut self, dur: Duration) {
// NOTE see the NOTE in `<Instant as AddAssign<Duration>>::add_assign`
debug_assert!(dur.inner < (1 << 31));
self.inner = self.inner.wrapping_sub(dur.inner as i32);
}
}
impl ops::Sub<Duration> for Instant {
type Output = Self;
fn sub(mut self, dur: Duration) -> Self {
self -= dur;
self
}
}
impl ops::Sub<Instant> for Instant {
type Output = Duration;
fn sub(self, other: Instant) -> Duration {
self.duration_since(other)
}
}
impl Ord for Instant {
fn cmp(&self, rhs: &Self) -> Ordering {
self.inner.wrapping_sub(rhs.inner).cmp(&0)
}
}
impl PartialOrd for Instant {
fn partial_cmp(&self, rhs: &Self) -> Option<Ordering> {
Some(self.cmp(rhs))
}
}
/// A `Duration` type to represent a span of time.
///
/// This data type is only available on ARMv7-M
///
/// # Correctness
///
/// This type is *not* appropriate for representing time spans in the order of, or larger than,
/// seconds because it can hold a maximum of `(1 << 31)` "ticks" where each tick is the inverse of
/// the CPU frequency, which usually is dozens of MHz.
#[derive(Clone, Copy, Default, Eq, Ord, PartialEq, PartialOrd)]
pub struct Duration {
inner: u32,
}
impl Duration {
/// Creates a new `Duration` from the specified number of clock cycles
pub fn from_cycles(cycles: u32) -> Self {
Duration { inner: cycles }
}
/// Returns the total number of clock cycles contained by this `Duration`
pub fn as_cycles(&self) -> u32 {
self.inner
}
}
// Used internally by RTFM to convert the duration into a known type
impl TryInto<u32> for Duration {
type Error = Infallible;
fn try_into(self) -> Result<u32, Infallible> {
Ok(self.as_cycles())
}
}
impl ops::AddAssign for Duration {
fn add_assign(&mut self, dur: Duration) {
self.inner += dur.inner;
}
}
impl ops::Add<Duration> for Duration {
type Output = Self;
fn add(self, other: Self) -> Self {
Duration {
inner: self.inner + other.inner,
}
}
}
impl ops::Mul<u32> for Duration {
type Output = Self;
fn mul(self, other: u32) -> Self {
Duration {
inner: self.inner * other,
}
}
}
impl ops::MulAssign<u32> for Duration {
fn mul_assign(&mut self, other: u32) {
*self = *self * other;
}
}
impl ops::SubAssign for Duration {
fn sub_assign(&mut self, rhs: Duration) {
self.inner -= rhs.inner;
}
}
impl ops::Sub<Duration> for Duration {
type Output = Self;
fn sub(self, rhs: Self) -> Self {
Duration {
inner: self.inner - rhs.inner,
}
}
}
impl From<Duration> for core::time::Duration {
fn from(d: Duration) -> Self {
core::time::Duration::from_micros(d.inner as u64)
}
}
/// Adds the `millis` and `micros` methods to the `u32` type
///
/// This trait is only available on ARMv7-M
pub trait U32Ext {
/// Converts the `u32` value as seconds into ticks
fn secs(self) -> Duration;
/// Converts the `u32` value as milliseconds into ticks
fn millis(self) -> Duration;
/// Converts the `u32` value as microseconds into ticks
fn micros(self) -> Duration;
/// Converts the `u32` value as hertz into ticks
fn hz(self) -> Duration;
}
impl U32Ext for u32 {
fn secs(self) -> Duration {
self.millis() * 1_000
}
fn millis(self) -> Duration {
self.micros() * 1_000
}
fn micros(self) -> Duration {
Duration { inner: self }
}
fn hz(self) -> Duration {
(1_000_000 / self).micros()
}
}