nrf52832/
interrupt_service.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2022.
4
5use nrf52::chip::Nrf52DefaultPeripherals;
6
7/// This struct, when initialized, instantiates all peripheral drivers for the nrf52840.
8///
9/// If a board wishes to use only a subset of these peripherals, this
10/// should not be used or imported, and a modified version should be
11/// constructed manually in main.rs.
12pub struct Nrf52832DefaultPeripherals<'a> {
13    pub nrf52: Nrf52DefaultPeripherals<'a>,
14    pub gpio_port: crate::gpio::Port<'a, { crate::gpio::NUM_PINS }>,
15}
16impl Nrf52832DefaultPeripherals<'_> {
17    pub unsafe fn new() -> Self {
18        Self {
19            nrf52: Nrf52DefaultPeripherals::new(),
20            gpio_port: crate::gpio::nrf52832_gpio_create(),
21        }
22    }
23    // Necessary for setting up circular dependencies
24    pub fn init(&'static self) {
25        self.nrf52.init();
26    }
27}
28impl kernel::platform::chip::InterruptService for Nrf52832DefaultPeripherals<'_> {
29    unsafe fn service_interrupt(&self, interrupt: u32) -> bool {
30        match interrupt {
31            nrf52::peripheral_interrupts::GPIOTE => self.gpio_port.handle_interrupt(),
32            _ => return self.nrf52.service_interrupt(interrupt),
33        }
34        true
35    }
36}