|
4 | 4 |
|
5 | 5 |
|
6 | 6 | #define WAKE_PIN A3
|
7 |
| -#define SLEEP_PIN 0 |
| 7 | +#define GOTO_SLEEP_PIN 0 |
8 | 8 |
|
9 |
| -volatile bool sleepFlag = false; |
| 9 | +volatile bool shouldGoToSleep = false; |
10 | 10 |
|
11 |
| -PowerManagement manager; |
12 | 11 | Board board;
|
13 | 12 | Charger charger;
|
14 | 13 |
|
15 | 14 | void setup() {
|
| 15 | + board = Board(); |
| 16 | + charger = Charger(); |
| 17 | + board.begin(); |
| 18 | + charger.begin(); |
16 | 19 |
|
17 |
| - |
18 |
| - |
19 |
| - manager = PowerManagement(); |
20 |
| - manager.begin(); |
21 |
| - board = manager.getBoard(); |
22 |
| - charger = manager.getCharger(); |
23 |
| - |
24 |
| - attachInterrupt(digitalPinToInterrupt(SLEEP_PIN), goToSleep, RISING); |
| 20 | + // Allows to use a button to put the device into sleep mode |
| 21 | + attachInterrupt(digitalPinToInterrupt(GOTO_SLEEP_PIN), goToSleep, RISING); |
25 | 22 |
|
26 | 23 | #if defined(ARDUINO_PORTENTA_C33)
|
27 |
| - board.enableWakeupFromPin(WAKE_PIN, RISING); |
| 24 | + // On Portenta C33, you can specify which pin to use to wake up the device from sleep mode |
| 25 | + // Please read the documentation to understand which pins can be used to wake up the device. |
| 26 | + board.enableWakeupFromPin(WAKE_UP_PIN, RISING); |
28 | 27 | #elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_NICLA_VISION)
|
| 28 | + // On Portenta only pin GPIO0 can be used to wake up the device from sleep mode |
29 | 29 | board.enableWakeupFromPin();
|
30 | 30 | #endif
|
31 | 31 |
|
32 |
| - |
| 32 | + // TODO why is this needed? Why true? |
33 | 33 | board.setAllPeripheralsPower(true);
|
34 |
| - charger.disable(); |
| 34 | + // TODO why is this needed? |
| 35 | + charger.setEnabled(false); |
35 | 36 |
|
36 | 37 | pinMode(LEDB, OUTPUT);
|
37 | 38 | }
|
38 | 39 |
|
39 | 40 | void goToSleep(){
|
40 |
| - sleepFlag = true; |
| 41 | + shouldGoToSleep = true; |
41 | 42 | }
|
42 | 43 |
|
43 | 44 | void loop() {
|
44 |
| - if(sleepFlag){ |
45 |
| - sleepFlag = false; |
| 45 | + if(shouldGoToSleep){ |
| 46 | + shouldGoToSleep = false; |
46 | 47 |
|
| 48 | + // TODO why is this here? |
47 | 49 | //board.setAllPeripheralsPower(false);
|
48 | 50 | board.standByUntilWakeupEvent();
|
49 | 51 | } else {
|
50 |
| - |
| 52 | + // Show that the board is awake by blinking the LED |
51 | 53 | digitalWrite(LEDB, HIGH);
|
52 | 54 | delay(1000);
|
53 | 55 | digitalWrite(LEDB, LOW);
|
|
0 commit comments