Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
7306387
QDEC changes initial
mmurray22 Jan 29, 2020
48e8d02
pair programming updates
hudson-ayers Jan 30, 2020
7746864
addl changes to configure pins
hudson-ayers Feb 13, 2020
14a06fb
New changes to QDEC
mmurray22 Feb 13, 2020
6d2805b
Merged conflicts?
mmurray22 Feb 13, 2020
4e4238f
Enables the pins at the beginning
mmurray22 Feb 13, 2020
f522a26
QDEC is responding to input!
mmurray22 Feb 13, 2020
cbbd06a
Issue with OptionalCell and accessing the Pinmux u32 value in enable …
mmurray22 Feb 14, 2020
f782d7d
fix pin setting by moving it into initialization so pin collisions ar…
hudson-ayers Feb 14, 2020
5830fd0
Updated QDEC hil and capsule. Almost done-one compiler error
mmurray22 Feb 18, 2020
389edde
All changes compile and general structure locked in.
mmurray22 Feb 24, 2020
1174a6c
Added interrupts. Next step is creating userprog
mmurray22 Feb 24, 2020
1c20e76
Interrupts seem to work now!
mmurray22 Feb 25, 2020
3c95a1e
I believe these are all the latest changes. Working on sampling accur…
mmurray22 Mar 23, 2020
2219956
qdec changes
mmurray22 Apr 2, 2020
4dec2ed
Kernel hil seems complete.
mmurray22 Apr 9, 2020
69d0f54
Edits to capsule-seems sufficient?
mmurray22 Apr 9, 2020
4d93ab9
Changes to driver-1/2 done
mmurray22 Apr 9, 2020
7aa0aca
chips and capsule code updated-need to test functionality
mmurray22 Apr 9, 2020
57038af
Final changes before very first commit
mmurray22 Apr 12, 2020
926a4f9
First rough draft PR suggestions
mmurray22 Apr 14, 2020
0239252
Some more PR changes
mmurray22 Apr 14, 2020
6210fcf
Merge branch 'master' into qdec
mmurray22 Apr 14, 2020
7315b2d
Resolving a lot of issues-still some compilation errors
mmurray22 Apr 16, 2020
71ed2ab
All compiles!
mmurray22 Apr 23, 2020
92507c2
changes
mmurray22 Apr 30, 2020
5907026
Qdec edits + starting to add new event ACCOF
mmurray22 May 5, 2020
d15b57d
changes for qdec
mmurray22 May 12, 2020
c0e9b07
In kernel tests work, other things do not, not ready to be used with …
mmurray22 May 21, 2020
8dbc97f
Qdec interrupts are maybe on their way to working again?
mmurray22 May 28, 2020
8c7ed3a
Changes to the kernel-interrupts not fully working
mmurray22 Jun 1, 2020
b1f0fa5
cleanup
hudson-ayers Jun 1, 2020
9576f6c
Takes away debug statements filling debug buffer
mmurray22 Aug 16, 2020
50e2e44
Callbacks are fully functional!
mmurray22 Sep 15, 2020
d78dd94
Cleans up part of the qdec codebase
mmurray22 Sep 15, 2020
dcd14d7
Cleans up qdec code further
mmurray22 Sep 15, 2020
575ee3b
Formats all the files
mmurray22 Sep 15, 2020
91624db
Update kernel/src/hil/qdec.rs
mmurray22 Sep 15, 2020
a302da0
Repsonds to PR comments
mmurray22 Sep 15, 2020
74c8a28
Merges with changes in master
mmurray22 Sep 15, 2020
55612aa
Removes unneeded comments in chips
mmurray22 Sep 15, 2020
2ca257f
Reformatted some files
mmurray22 Sep 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion boards/nordic/nrf52840dk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ use kernel::component::Component;
#[allow(unused_imports)]
use kernel::{debug, debug_gpio, debug_verbose, static_init};
use nrf52840::gpio::Pin;
use nrf52dk_base::{SpiMX25R6435FPins, SpiPins, UartPins};

use nrf52dk_base::{QdecPins, SpiMX25R6435FPins, SpiPins, UartPins};

// The nRF52840DK LEDs (see back of board)
const LED1_PIN: Pin = Pin::P0_13;
Expand Down Expand Up @@ -96,6 +97,9 @@ const SPI_MX25R6435F_CHIP_SELECT: Pin = Pin::P0_17;
const SPI_MX25R6435F_WRITE_PROTECT_PIN: Pin = Pin::P0_22;
const SPI_MX25R6435F_HOLD_PIN: Pin = Pin::P0_23;

const QDEC_PIN_A: Pin = Pin::P0_02;
const QDEC_PIN_B: Pin = Pin::P0_29;

/// UART Writer
pub mod io;

Expand Down Expand Up @@ -212,6 +216,7 @@ pub unsafe fn reset_handler() {
FAULT_RESPONSE,
nrf52840::uicr::Regulator0Output::DEFAULT,
false,
&QdecPins::new(QDEC_PIN_A, QDEC_PIN_B),
chip,
);
}
41 changes: 38 additions & 3 deletions boards/nordic/nrf52dk_base/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Shared setup for nrf52dk boards.

#![no_std]

#[allow(unused_imports)]
use kernel::{create_capability, debug, debug_gpio, debug_verbose, static_init};

Expand All @@ -12,10 +11,10 @@ use kernel::capabilities;
use kernel::common::dynamic_deferred_call::{DynamicDeferredCall, DynamicDeferredCallClientState};
use kernel::component::Component;
use kernel::hil;
use kernel::hil::gpio::{Configure, FloatingState};
use nrf52::gpio::Pin;
use nrf52::rtc::Rtc;
use nrf52::uicr::Regulator0Output;

pub mod nrf52_components;
use nrf52_components::ble::BLEComponent;
use nrf52_components::ieee802154::Ieee802154Component;
Expand Down Expand Up @@ -71,6 +70,19 @@ impl UartPins {
}
}

/// Pins for the QDEC
#[derive(Debug)]
pub struct QdecPins {
pin_a: Pin,
pin_b: Pin,
}

impl QdecPins {
pub fn new(pin_a: Pin, pin_b: Pin) -> Self {
Self { pin_a, pin_b }
}
}

/// Supported drivers by the platform
pub struct Platform {
ble_radio: &'static capsules::ble_advertising_driver::BLE<
Expand All @@ -96,6 +108,7 @@ pub struct Platform {
'static,
capsules::virtual_alarm::VirtualMuxAlarm<'static, nrf52::rtc::Rtc<'static>>,
>,
qdec: &'static capsules::qdec::QdecInterface<'static>,
// The nRF52dk does not have the flash chip on it, so we make this optional.
nonvolatile_storage:
Option<&'static capsules::nonvolatile_storage_driver::NonvolatileStorage<'static>>,
Expand All @@ -113,6 +126,7 @@ impl kernel::Platform for Platform {
capsules::led::DRIVER_NUM => f(Some(self.led)),
capsules::button::DRIVER_NUM => f(Some(self.button)),
capsules::rng::DRIVER_NUM => f(Some(self.rng)),
capsules::qdec::DRIVER_NUM => f(Some(self.qdec)),
capsules::ble_advertising_driver::DRIVER_NUM => f(Some(self.ble_radio)),
capsules::ieee802154::DRIVER_NUM => match self.ieee802154_radio {
Some(radio) => f(Some(radio)),
Expand Down Expand Up @@ -150,6 +164,7 @@ pub unsafe fn setup_board<I: nrf52::interrupt_service::InterruptService>(
app_fault_response: kernel::procs::FaultResponse,
reg_vout: Regulator0Output,
nfc_as_gpios: bool,
qdec_pins: &QdecPins,
chip: &'static nrf52::chip::NRF52<I>,
) {
// Make non-volatile memory writable and activate the reset button
Expand Down Expand Up @@ -412,6 +427,26 @@ pub unsafe fn setup_board<I: nrf52::interrupt_service::InterruptService>(
);
DynamicDeferredCall::set_global_instance(dynamic_deferred_call);

//START: QDEC INITIALIZATION
gpio_port[qdec_pins.pin_a].make_input();
gpio_port[qdec_pins.pin_b].make_input();
gpio_port[qdec_pins.pin_a].set_floating_state(FloatingState::PullUp);
gpio_port[qdec_pins.pin_b].set_floating_state(FloatingState::PullUp);

let qdec_nrf52 = &mut nrf52::qdec::QDEC;
qdec_nrf52.set_pins(
nrf52::pinmux::Pinmux::new(qdec_pins.pin_a as u32),
nrf52::pinmux::Pinmux::new(qdec_pins.pin_b as u32),
);
let qdec = static_init!(
capsules::qdec::QdecInterface<'static>,
capsules::qdec::QdecInterface::new(
qdec_nrf52,
board_kernel.create_grant(&memory_allocation_capability)
)
);
kernel::hil::qdec::QdecDriver::set_client(&nrf52::qdec::QDEC, qdec);

let platform = Platform {
button: button,
ble_radio: ble_radio,
Expand All @@ -425,6 +460,7 @@ pub unsafe fn setup_board<I: nrf52::interrupt_service::InterruptService>(
alarm: alarm,
analog_comparator: analog_comparator,
nonvolatile_storage: nonvolatile_storage,
qdec: qdec,
ipc: kernel::ipc::IPC::new(board_kernel, &memory_allocation_capability),
};

Expand All @@ -445,6 +481,5 @@ pub unsafe fn setup_board<I: nrf52::interrupt_service::InterruptService>(
app_fault_response,
&process_management_capability,
);

board_kernel.kernel_loop(&platform, chip, Some(&platform.ipc), &main_loop_capability);
}
2 changes: 1 addition & 1 deletion capsules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ These capsules provide a `Driver` interface for common MCU peripherals.
- **[I2C_MASTER_SLAVE](src/i2c_master_slave_driver.rs)**: I2C master and slave access.
- **[RNG](src/rng.rs)**: Random number generation.
- **[SPI](src/spi.rs)**: SPI master and slave.

- **[QDEC](src/qdec.rs)**: Quadrature DECoder for quadrature-encoded sensor signals

### Helpful Userspace Capsules

Expand Down
1 change: 1 addition & 0 deletions capsules/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ pub enum NUM {

// Misc
Buzzer = 0x90000,
Qdec = 0x90001,
}
}
1 change: 1 addition & 0 deletions capsules/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub mod nonvolatile_to_pages;
pub mod nrf51822_serialization;
pub mod pca9544a;
pub mod process_console;
pub mod qdec;
pub mod rf233;
pub mod rf233_const;
pub mod rng;
Expand Down
108 changes: 108 additions & 0 deletions capsules/src/qdec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//! Provides userspace access to the Qdec on a board.
//!
//! Usage
//! -----
//!
//! ````
//! let qdec = static_init!(
//! capsules::qdec::Qdec<'static>,
//! capsules::qdec::QdecInterface::new(&nrf52::qdec::QDEC,
//! kernel::Grant::create())
//! );
//! kernel::hil::QdecDriver.set_client(qdec);
//! ````
//! #Interrupt Spurred Readings versus Regular Readings
//! An application can either enable interrupts to get the
//! accumulation value or manually read it whenever it wants

use crate::driver;
use kernel::hil;
use kernel::{AppId, Callback, Driver, Grant, ReturnCode};

pub const DRIVER_NUM: usize = driver::NUM::Qdec as usize;

/// This struct contains the resources necessary for the QdecInterface
pub struct QdecInterface<'a> {
driver: &'a dyn hil::qdec::QdecDriver,
apps: Grant<App>,
}

#[derive(Default)]
/// This struct contains the necessary fields for an app
pub struct App {
callback: Option<Callback>,
pos: u32,
}

impl QdecInterface<'a> {
/// Create a new instance of the QdecInterface
pub fn new(driver: &'a dyn hil::qdec::QdecDriver, grant: Grant<App>) -> QdecInterface<'a> {
QdecInterface {
driver: driver,
apps: grant,
}
}

fn configure_callback(&self, callback: Option<Callback>, app_id: AppId) -> ReturnCode {
self.apps
.enter(app_id, |app, _| {
app.callback = callback;
ReturnCode::SUCCESS
})
.unwrap_or_else(|err| err.into())
}
}

impl hil::qdec::QdecClient for QdecInterface<'a> {
/// Goes through all the apps and if the app is
/// subscribed then it sends back the acc value
fn sample_ready(&self) {
for cntr in self.apps.iter() {
cntr.enter(|app, _| {
app.pos = app.pos + self.driver.get_acc();
app.callback
.map(|mut cb| cb.schedule(app.pos as usize, 0, 0));
});
}
}

/// Goes through all the apps and if the app recently
/// had an overflow, it records the occurance
fn overflow(&self) {
/*for now, we do not handle overflows*/
}
}

impl Driver for QdecInterface<'a> {
/// Subscribes a client to (newly enabled) interrupts
fn subscribe(
&self,
subscribe_num: usize,
callback: Option<Callback>,
app_id: AppId,
) -> ReturnCode {
match subscribe_num {
0 => self.configure_callback(callback, app_id),
_ => ReturnCode::ENOSUPPORT,
}
}

/// Command switch statement for various essential processes
/// 0 is a sanity check for the switch statement
/// 1 enables the qdec
/// 2 checks that the qdec is enabled
/// 3 enables inerrupts
/// 4 gets the current displacement stored in the QDEC
fn command(&self, command_num: usize, _: usize, _: usize, _app_id: AppId) -> ReturnCode {
match command_num {
0 => ReturnCode::SUCCESS,
1 => self.driver.enable_qdec(),
2 => self.driver.enabled(),
3 => self.driver.enable_interrupts(),
4 => ReturnCode::SuccessWithValue {
value: self.driver.get_acc() as usize,
},
_ => ReturnCode::ENOSUPPORT,
}
}
}
2 changes: 2 additions & 0 deletions chips/nrf52/src/interrupt_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::ble_radio;
use crate::i2c;
use crate::ieee802154_radio;
use crate::power;
use crate::qdec;
use crate::spi;
use crate::uart;
use kernel::debug;
Expand Down Expand Up @@ -123,6 +124,7 @@ impl InterruptService for Nrf52InterruptService {
}
peripheral_interrupts::SPIM2_SPIS2_SPI2 => spi::SPIM2.handle_interrupt(),
peripheral_interrupts::ADC => adc::ADC.handle_interrupt(),
peripheral_interrupts::QDEC => qdec::QDEC.handle_interrupt(),
_ => return false,
}
true
Expand Down
1 change: 1 addition & 0 deletions chips/nrf52/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod nvmc;
pub mod power;
pub mod ppi;
pub mod pwm;
pub mod qdec;
pub mod spi;
pub mod uart;
pub mod uicr;
Expand Down
Loading