Skip to content

Commit 0281dc8

Browse files
authored
Merge pull request #427 from jpconstantineau/feature-pin-sense
Feature pin sense
2 parents 7ae3dc4 + e58aebb commit 0281dc8

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

cores/nRF5/wiring_constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ extern "C"{
3030
#define OUTPUT (0x1)
3131
#define INPUT_PULLUP (0x2)
3232
#define INPUT_PULLDOWN (0x3)
33+
#define INPUT_PULLUP_SENSE (0x4)
34+
#define INPUT_PULLDOWN_SENSE (0x5)
3335

3436
#define PI 3.1415926535897932384626433832795
3537
#define HALF_PI 1.5707963267948966192313216916398

cores/nRF5/wiring_digital.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ void pinMode( uint32_t ulPin, uint32_t ulMode )
5555
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
5656
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
5757
break;
58+
59+
case INPUT_PULLUP_SENSE:
60+
// Set pin to input mode with pull-up resistor enabled and sense when Low
61+
port->PIN_CNF[ulPin] = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
62+
| ((uint32_t)GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
63+
| ((uint32_t)GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
64+
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
65+
| ((uint32_t)GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos);
66+
break;
5867

5968
case INPUT_PULLDOWN:
6069
// Set pin to input mode with pull-down resistor enabled
@@ -65,6 +74,15 @@ void pinMode( uint32_t ulPin, uint32_t ulMode )
6574
| ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);
6675
break;
6776

77+
case INPUT_PULLDOWN_SENSE:
78+
// Set pin to input mode with pull-down resistor enabled
79+
port->PIN_CNF[ulPin] = ((uint32_t)GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos)
80+
| ((uint32_t)GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
81+
| ((uint32_t)GPIO_PIN_CNF_PULL_Pulldown << GPIO_PIN_CNF_PULL_Pos)
82+
| ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
83+
| ((uint32_t)GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos);
84+
break;
85+
6886
case OUTPUT:
6987
// Set pin to output mode
7088
port->PIN_CNF[ulPin] = ((uint32_t)GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Blink_sleep
3+
Turns on an LED on for one second, then off for one second, until the time to go to sleep runs out.
4+
You can wake up the feather by pressing a key/switch connecting the WAKE_LOW_PIN to GND and the WAKE_HIGH_PIN to 3.3V (VCC)
5+
6+
Based on the blinky arduino example
7+
8+
This example code is in the public domain.
9+
10+
created 19 Jan 2010
11+
by Pierre Constantineau
12+
13+
*/
14+
#include <bluefruit.h>
15+
16+
#define WAKE_LOW_PIN PIN_A0
17+
#define WAKE_HIGH_PIN PIN_A1
18+
19+
#define SLEEPING_DELAY 30000 // sleep after 30 seconds of blinking
20+
21+
void gotoSleep(unsigned long time)
22+
{
23+
// shutdown when time reaches SLEEPING_DELAY ms
24+
if ((time>SLEEPING_DELAY))
25+
{
26+
// to reduce power consumption when sleeping, turn off all your LEDs (and other power hungry devices)
27+
digitalWrite(LED_BUILTIN, LOW);
28+
29+
// setup your wake-up pins.
30+
pinMode(WAKE_LOW_PIN, INPUT_PULLUP_SENSE); // this pin (WAKE_LOW_PIN) is pulled up and wakes up the feather when externally connected to ground.
31+
pinMode(WAKE_HIGH_PIN, INPUT_PULLDOWN_SENSE); // this pin (WAKE_HIGH_PIN) is pulled down and wakes up the feather when externally connected to 3.3v.
32+
33+
// power down nrf52.
34+
sd_power_system_off(); // this function puts the whole nRF52 to deep sleep (no Bluetooth). If no sense pins are setup (or other hardware interrupts), the nrf52 will not wake up.
35+
}
36+
}
37+
38+
// the setup function runs once when you press reset or power the board
39+
void setup() {
40+
Bluefruit.begin(); // Sleep functions need the softdevice to be active.
41+
42+
// initialize digital pin LED_BUILTIN as an output.
43+
pinMode(LED_BUILTIN, OUTPUT);
44+
}
45+
46+
// the loop function runs over and over again forever
47+
void loop() {
48+
digitalToggle(LED_BUILTIN); // turn the LED on (HIGH is the voltage level)
49+
gotoSleep(millis()); // call millis() and pass it to the sleep function. On wake-up, millis will start at 0 again.
50+
delay(1000); // wait for a second
51+
}

0 commit comments

Comments
 (0)