Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nano33 apds9960 #2091

Merged
merged 25 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b951c12
Finish APDS9960 implementation
arjundeopujari Jul 3, 2020
57fcb07
nano33: add apds9960 to board file
bradjc Jul 6, 2020
5d7be2d
debugging, add id get
bradjc Jul 6, 2020
667a6da
Add persistence to apds-9960
arjundeopujari Jul 17, 2020
4f6d9b1
APDS-9960 Driver: Add proximity gain setter and remove endless interr…
arjundeopujari Jul 20, 2020
82a8fbe
Add take_measurement() to hil proximity interface
arjundeopujari Jul 28, 2020
aa0f213
Take out HIGH_THRESH and LOW_THRESH
arjundeopujari Aug 3, 2020
03c0d80
Implement proximity.rs
arjundeopujari Aug 4, 2020
c4e425a
Add callbacks to proximityGain() and interruptthresholds commands
arjundeopujari Aug 4, 2020
5355e4b
Change Driver::NUM::Proximity
arjundeopujari Aug 8, 2020
d44b634
Change user proximity interface
arjundeopujari Aug 15, 2020
8a5dd23
Clean up proximity.rs logic
arjundeopujari Aug 16, 2020
9b099d4
Nano33ble main.rs: Add init and code for the apds9960 proximity sensor
arjundeopujari Aug 18, 2020
52a1e37
Clean up code
arjundeopujari Aug 31, 2020
41e55d5
Fix apds9960.take_measurement()
arjundeopujari Aug 31, 2020
e64830e
Delete superfluous debug statements
arjundeopujari Aug 31, 2020
b05f71c
cargo fmt
arjundeopujari Aug 31, 2020
cc23a83
Address review feedback
arjundeopujari Sep 20, 2020
5d760b8
Address review comments (2/2) and cargo fmt
arjundeopujari Sep 21, 2020
b37445a
Address Review Comments: nano33ble
arjundeopujari Sep 24, 2020
5703fd2
Address merge issues
arjundeopujari Sep 25, 2020
79357c3
Merge branch 'master' into nano33-apds9960
arjundeopujari Sep 25, 2020
f11f18a
apds9960: Add lifetime specifiers to gpio
arjundeopujari Sep 25, 2020
e8a9584
Address ci-job-clippy error
arjundeopujari Sep 26, 2020
3975ede
Remove unused attribute
arjundeopujari Sep 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions boards/nano33ble/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ pub unsafe fn reset_handler() {

kernel::hil::sensors::ProximityDriver::set_client(apds9960, proximity);

// apds9960.take_measurement();

//--------------------------------------------------------------------------
// WIRELESS
//--------------------------------------------------------------------------
Expand Down Expand Up @@ -334,8 +332,6 @@ pub unsafe fn reset_handler() {

debug!("Initialization complete. Entering main loop.");

// apds9960.take_measurement();

//--------------------------------------------------------------------------
// PROCESSES AND MAIN LOOP
//--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion capsules/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub enum NUM {
Humidity = 0x60001,
AmbientLight = 0x60002,
NINEDOF = 0x60004,
Proximity = 0x60003,
Proximity = 0x60005,

// Sensor ICs
Tsl2561 = 0x70000,
Expand Down
34 changes: 20 additions & 14 deletions capsules/src/proximity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<'a> ProximitySensor<'a> {
let r: ReturnCode = self
.apps
.enter(appid, |app, _| {
// Return busy if same app attempts to enqueue second command before first one is callbacked
// Return busy if same app attempts to enqueue second command before first one is "callbacked"
if app.subscribed {
return ReturnCode::EBUSY;
}
Expand Down Expand Up @@ -159,15 +159,11 @@ impl<'a> ProximitySensor<'a> {
// run it
match app.enqueued_command_type {
ProximityCommand::ReadProximity => {
self.call_driver(app.enqueued_command_type, 0, 0);
self.driver.read_proximity();
}
ProximityCommand::ReadProximityOnInterrupt => {
let t: Thresholds = self.find_thresholds();
self.call_driver(
app.enqueued_command_type,
t.lower as usize,
t.upper as usize,
);
self.driver.read_proximity_on_interrupt(t.lower, t.upper);
}
_ => {}
}
Expand Down Expand Up @@ -233,13 +229,14 @@ impl hil::sensors::ProximityClient for ProximitySensor<'_> {
fn callback(&self, temp_val: usize, command_type: usize) {
// Here we callback the values only to the apps which are relevant for the callback
// We also dequeue any command for a callback so as to remove it from the wait list and add other commands to continue

match command_type {
command_type if command_type == ProximityCommand::ReadProximity as usize => {
// Schedule callbacks for appropriate apps
for cntr in self.apps.iter() {
cntr.enter(|app, _| {
if app.subscribed
&& (command_type == (ProximityCommand::ReadProximity as usize))
&& (app.enqueued_command_type == ProximityCommand::ReadProximity)
{
app.callback.map(|mut cb| cb.schedule(temp_val, 0, 0));
app.subscribed = false; // dequeue
Expand All @@ -249,17 +246,26 @@ impl hil::sensors::ProximityClient for ProximitySensor<'_> {
}

command_type if command_type == ProximityCommand::ReadProximityOnInterrupt as usize => {
// Schedule callbacks for appropriate apps
// Schedule callbacks for appropriate apps (any apps waiting for a proximity command)
for cntr in self.apps.iter() {
cntr.enter(|app, _| {
if app.subscribed
&& (command_type
== (ProximityCommand::ReadProximityOnInterrupt as usize))
&& ((app.enqueued_command_type
== ProximityCommand::ReadProximityOnInterrupt)
|| (app.enqueued_command_type == ProximityCommand::ReadProximity))
hudson-ayers marked this conversation as resolved.
Show resolved Hide resolved
{
// Only callback to those apps which we expect would want to know about this threshold reading
if ((temp_val as u8) > app.upper_proximity)
|| ((temp_val as u8) < app.lower_proximity)
if app.enqueued_command_type
== ProximityCommand::ReadProximityOnInterrupt
{
// Only callback to those apps which we expect would want to know about this threshold reading for readproximityoninterrupt readings
if ((temp_val as u8) > app.upper_proximity)
|| ((temp_val as u8) < app.lower_proximity)
{
app.callback.map(|mut cb| cb.schedule(temp_val, 0, 0));
app.subscribed = false; // dequeue
}
} else {
// callback to all apps waiting on readproximity
app.callback.map(|mut cb| cb.schedule(temp_val, 0, 0));
app.subscribed = false; // dequeue
}
Expand Down
1 change: 1 addition & 0 deletions doc/syscalls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ _Note:_ GPIO is slated for re-numbering in Tock 2.0.
| ✓ | 0x60002 | [Luminance](60002_luminance.md) | Ambient Light Sensor (lumens) |
| | 0x60003 | Pressure | Pressure sensor |
| | 0x60004 | Ninedof | Virtualized accelerometer/magnetometer/gyroscope |
| | 0x60005 | Proximity | Proximity Sensor |

### Sensor ICs

Expand Down
17 changes: 14 additions & 3 deletions kernel/src/hil/sensors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,23 @@ pub trait HumidityClient {
/// A basic interface for a proximity sensor
pub trait ProximityDriver<'a> {
fn set_client(&self, client: &'a dyn ProximityClient);
fn read_proximity(&self) -> ReturnCode; // Instantaneous proximity reading
fn read_proximity_on_interrupt(&self, low: u8, high: u8) -> ReturnCode; // Proximity reading returned only after interrupt is detected
/// Callback issued after sensor reads proximity value
fn read_proximity(&self) -> ReturnCode;
/// Callback issued after sensor reads proximity value greater than 'high_threshold' or less than 'low_threshold'
///
/// To elaborate, the callback is not issued by the driver until (prox_reading >= high_threshold || prox_reading <= low_threshold).
/// When (prox_reading >= high_threshold || prox_reading <= low_threshold) is read by the sensor, an I2C interrupt is generated and sent to the kernel
/// which prompts the driver to collect the proximity reading from the sensor and perform the callback.
/// Any apps issuing this command will have to wait for the proximity reading to fall within the aforementioned ranges in order to received a callback.
/// Threshold: A value of range [0 , 255] which represents at what proximity reading ranges an interrupt will occur.
fn read_proximity_on_interrupt(&self, low_threshold: u8, high_threshold: u8) -> ReturnCode;
}

pub trait ProximityClient {
/// Called when proximity reading has completed (`command_type` is used by proximity.rs to match callbacks to the apps issuing the appropriate commands)
/// Called when a proximity reading has completed.
///
/// - `value`: the most recently read proximity value which ranges [0 , 255] where 255 -> object is closest readable distance, 0 -> object is farthest readable distance.
/// - 'command_type': callback is being issued after driver serviced this type of command (1 -> read_proximity, 2 -> read_proximity_on_interrupt)
hudson-ayers marked this conversation as resolved.
Show resolved Hide resolved
fn callback(&self, value: usize, command_type: usize);
}

Expand Down