From 7f0e247b3760944f1b9172f47cbff16233d55e32 Mon Sep 17 00:00:00 2001
From: jonathan <jonathantbrouwer@gmail.com>
Date: Tue, 7 Mar 2023 18:25:40 +0100
Subject: [PATCH] For mathijs
---
src/battery.rs | 7 ++++++-
src/motor.rs | 7 +++++++
src/time.rs | 3 +++
src/uart.rs | 4 ++++
4 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/src/battery.rs b/src/battery.rs
index b0a0ac2..2065c0d 100644
--- a/src/battery.rs
+++ b/src/battery.rs
@@ -3,6 +3,7 @@
use crate::mutex::Mutex;
use crate::once_cell::OnceCell;
use cortex_m::peripheral::NVIC;
+use nrf51_hal::gpio::Level;
use nrf51_pac::interrupt;
use nrf51_pac::Interrupt;
@@ -46,11 +47,15 @@ pub(crate) fn initialize(adc: nrf51_pac::ADC, nvic: &mut NVIC) {
#[interrupt]
unsafe fn ADC() {
+ let _ = unsafe { nrf51_hal::gpio::p0::Parts::new(nrf51_pac::Peripherals::steal().GPIO).p0_20.into_push_pull_output(Level::High) };
+
ADC_STATE.modify(|adc| {
adc.adc.events_end.reset();
// Battery voltage = (result*1.2*3/255*2) = RESULT*0.007058824
adc.last_result = adc.adc.result.read().result().bits() * 7;
- })
+ });
+
+ let _ = unsafe { nrf51_hal::gpio::p0::Parts::new(nrf51_pac::Peripherals::steal().GPIO).p0_20.into_push_pull_output(Level::Low) };
}
/// Returns the battery voltage in 10^-2 volt.
diff --git a/src/motor.rs b/src/motor.rs
index 2c95bf2..4c1ca3c 100644
--- a/src/motor.rs
+++ b/src/motor.rs
@@ -1,6 +1,7 @@
use crate::mutex::Mutex;
use crate::once_cell::OnceCell;
use cortex_m::peripheral::NVIC;
+use nrf51_hal::gpio::Level;
use nrf51_pac::{interrupt, Interrupt, GPIOTE, PPI};
struct Motors {
@@ -237,6 +238,7 @@ pub(crate) fn initialize(
#[interrupt]
unsafe fn TIMER2() {
+ let _ = unsafe { nrf51_hal::gpio::p0::Parts::new(nrf51_pac::Peripherals::steal().GPIO).p0_20.into_push_pull_output(Level::High) };
// Safety: interrupts are already turned off here, since we are inside an interrupt
let motors = unsafe { MOTORS.no_critical_section_lock_mut() };
if motors.timer2.events_compare[3].read().bits() != 0 {
@@ -250,10 +252,13 @@ unsafe fn TIMER2() {
motors.timer2.cc[1].write(|w| w.bits(u32::from(1000 + motors.motor_values[3])));
}
}
+
+ let _ = unsafe { nrf51_hal::gpio::p0::Parts::new(nrf51_pac::Peripherals::steal().GPIO).p0_20.into_push_pull_output(Level::Low) };
}
#[interrupt]
unsafe fn TIMER1() {
+ let _ = unsafe { nrf51_hal::gpio::p0::Parts::new(nrf51_pac::Peripherals::steal().GPIO).p0_20.into_push_pull_output(Level::High) };
// Safety: interrupts are already turned off here, since we are inside an interrupt
let motors = unsafe { MOTORS.no_critical_section_lock_mut() };
if motors.timer1.events_compare[3].read().bits() != 0 {
@@ -266,4 +271,6 @@ unsafe fn TIMER1() {
motors.timer1.cc[1].write(|w| w.bits(u32::from(1000 + motors.motor_values[1])));
}
}
+
+ let _ = unsafe { nrf51_hal::gpio::p0::Parts::new(nrf51_pac::Peripherals::steal().GPIO).p0_20.into_push_pull_output(Level::Low) };
}
diff --git a/src/time.rs b/src/time.rs
index 846fa2a..5bead4f 100644
--- a/src/time.rs
+++ b/src/time.rs
@@ -10,6 +10,7 @@ use crate::once_cell::OnceCell;
/// and hard to convert to an exact number of seconds
pub use cortex_m::asm::delay as assembly_delay;
use cortex_m::peripheral::NVIC;
+use nrf51_hal::gpio::Level;
use nrf51_hal::rtc::{RtcCompareReg, RtcInterrupt};
use nrf51_hal::Rtc;
use nrf51_pac::RTC0;
@@ -155,6 +156,7 @@ fn counter_diff(prev: u32, curr: u32) -> u32 {
#[interrupt]
unsafe fn RTC0() {
+ let _ = unsafe { nrf51_hal::gpio::p0::Parts::new(nrf51_pac::Peripherals::steal().GPIO).p0_20.into_push_pull_output(Level::High) };
// SAFETY: we're in an interrupt so this code cannot be run concurrently anyway
let rtc = RTC.no_critical_section_lock_mut();
// SAFETY: we're in an interrupt so this code cannot be run concurrently anyway
@@ -177,6 +179,7 @@ unsafe fn RTC0() {
rtc.reset_event(RtcInterrupt::Compare0);
TIMER_FLAG.store(true, Ordering::SeqCst);
}
+ let _ = unsafe { nrf51_hal::gpio::p0::Parts::new(nrf51_pac::Peripherals::steal().GPIO).p0_20.into_push_pull_output(Level::Low) };
}
/// Wait for the next interrupt configured by `set_interrupt_frequency`.
diff --git a/src/uart.rs b/src/uart.rs
index c74c069..a88d304 100644
--- a/src/uart.rs
+++ b/src/uart.rs
@@ -1,6 +1,7 @@
use crate::mutex::Mutex;
use crate::once_cell::OnceCell;
use cortex_m::peripheral::NVIC;
+use nrf51_hal::gpio::Level;
use nrf51_pac::interrupt;
use ringbuffer::{ConstGenericRingBuffer, RingBuffer, RingBufferRead, RingBufferWrite};
@@ -117,6 +118,7 @@ fn put_byte(uart: &mut OnceCell<UartDriver>, byte: u8) {
/// Interrupt handler for UART0
/// It's called when the enabled interrupts for uart0 are triggered
unsafe fn UART0() {
+ let _ = unsafe { nrf51_hal::gpio::p0::Parts::new(nrf51_pac::Peripherals::steal().GPIO).p0_20.into_push_pull_output(Level::High) };
// Safety: interrupts are already turned off here, since we are inside an interrupt
let uart = unsafe { UART.no_critical_section_lock_mut() };
@@ -138,4 +140,6 @@ unsafe fn UART0() {
if uart.uart.events_error.read().bits() != 0 {
uart.uart.events_error.reset();
}
+
+ let _ = unsafe { nrf51_hal::gpio::p0::Parts::new(nrf51_pac::Peripherals::steal().GPIO).p0_20.into_push_pull_output(Level::Low) };
}
--
GitLab