From 824945195b88a99fe0e96aa94ea66e2544009717 Mon Sep 17 00:00:00 2001
From: jonathan <jonathantbrouwer@gmail.com>
Date: Fri, 10 Mar 2023 20:26:39 +0100
Subject: [PATCH] For mathijs
---
src/battery.rs | 5 ++++-
src/motor.rs | 5 +++++
src/time.rs | 6 ++++++
src/twi.rs | 7 ++++++-
src/uart.rs | 5 +++++
5 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/src/battery.rs b/src/battery.rs
index b0a0ac2..083f395 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,13 @@ 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..3408f9f 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,12 @@ 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 +270,5 @@ 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..c623aa2 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,8 @@ 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 +180,9 @@ 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/twi.rs b/src/twi.rs
index 6ebdcc2..56502fb 100644
--- a/src/twi.rs
+++ b/src/twi.rs
@@ -3,7 +3,7 @@ use crate::once_cell::OnceCell;
use core::sync::atomic::{AtomicBool, Ordering};
use cortex_m::peripheral::NVIC;
use nrf51_hal::gpio::p0::{P0_02, P0_04};
-use nrf51_hal::gpio::{Disconnected, Pin};
+use nrf51_hal::gpio::{Disconnected, Level, Pin};
use nrf51_hal::twi::Error;
use nrf51_pac::interrupt;
use nrf51_pac::twi0::frequency::FREQUENCY_A;
@@ -230,6 +230,8 @@ pub(crate) fn initialize(
#[interrupt]
unsafe fn SPI0_TWI0() {
+ let _ = unsafe { nrf51_hal::gpio::p0::Parts::new(nrf51_pac::Peripherals::steal().GPIO).p0_19.into_push_pull_output(Level::High) };
+
// Safety: interrupts are already turned off here, since we are inside an interrupt
// We might be accessing the hardware while the interrupted code also wants to, this is fine since we're only touching the EVENT registers which are not touched by the other code
let twi = unsafe { TWI.no_critical_section_lock_mut() };
@@ -254,4 +256,7 @@ unsafe fn SPI0_TWI0() {
.write(|w| w.anack().clear_bit().overrun().clear_bit()); // Clear error source
twi.twi.events_error.reset();
}
+
+ let _ = unsafe { nrf51_hal::gpio::p0::Parts::new(nrf51_pac::Peripherals::steal().GPIO).p0_19.into_push_pull_output(Level::Low) };
+
}
diff --git a/src/uart.rs b/src/uart.rs
index c74c069..b8053c2 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,8 @@ 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 +141,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