Skip to content
Snippets Groups Projects
Verified Commit 7f0e247b authored by Jonathan Brouwer's avatar Jonathan Brouwer
Browse files

For mathijs

parent 258bddb5
No related branches found
No related tags found
No related merge requests found
Pipeline #818172 failed
......@@ -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.
......
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) };
}
......@@ -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`.
......
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) };
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment