Numworks Epsilon
1.4.1
Graphing Calculator Operating System
power.cpp
Go to the documentation of this file.
1
#include <
ion.h
>
2
#include "
battery.h
"
3
#include "
device.h
"
4
#include "
display.h
"
5
#include "
keyboard.h
"
6
#include "
led.h
"
7
#include "
usb.h
"
8
#include "
wakeup.h
"
9
#include "
regs/regs.h
"
10
11
void
Ion::Power::suspend
(
bool
checkIfPowerKeyReleased) {
12
if
(checkIfPowerKeyReleased) {
13
/* Wait until power is released to avoid restarting just after suspending */
14
bool
isPowerDown =
true
;
15
while
(isPowerDown) {
16
Keyboard::State
scan
=
Keyboard::scan
();
17
isPowerDown =
scan
.
keyDown
(Keyboard::Key::B2);
18
}
19
}
20
Device::shutdownPeripherals
();
21
22
PWR
.
CR
()->setLPDS(
true
);
// Turn the regulator off. Takes longer to wake up.
23
PWR
.
CR
()->setFPDS(
true
);
// Put the flash to sleep. Takes longer to wake up.
24
CM4
.
SCR
()->setSLEEPDEEP(
true
);
25
26
WakeUp::Device::onUSBPlugging
();
27
#if LED_WHILE_CHARGING
28
WakeUp::Device::onChargingEvent
();
29
#endif
30
while
(1) {
31
#if LED_WHILE_CHARGING
32
/* Update LEDS
33
* if the standby mode was stopped due to a "stop charging" event, we wait
34
* a while to be sure that the plug state of the USB is up-to-date. */
35
msleep
(200);
36
LED::Device::enforceState
(
Battery::isCharging
(),
USB::isPlugged
(),
false
);
37
#endif
38
39
WakeUp::Device::onPowerKeyDown
();
40
41
Device::shutdownClocks
();
42
43
/* To enter sleep, we need to issue a WFE instruction, which waits for the
44
* event flag to be set and then clears it. However, the event flag might
45
* already be on. So the safest way to make sure we actually wait for a new
46
* event is to force the event flag to on (SEV instruction), use a first WFE
47
* to clear it, and then a second WFE to wait for a _new_ event. */
48
asm
(
"sev"
);
49
asm
(
"wfe"
);
50
msleep
(1);
51
asm
(
"wfe"
);
52
53
Device::initClocks
();
54
55
Keyboard::Device::init
();
56
Keyboard::State
scan
=
Keyboard::scan
();
57
Keyboard::Device::shutdown
();
58
59
Ion::Keyboard::State
OnlyPowerKeyDown =
Keyboard::State
(Keyboard::Key::B2);
60
if
(
scan
== OnlyPowerKeyDown ||
USB::isPlugged
()) {
61
// Wake up
62
break
;
63
}
64
}
65
Device::initClocks
();
66
67
Device::initPeripherals
();
68
}
Ion::USB::isPlugged
bool isPlugged()
Definition:
usb.cpp:12
Ion::Device::shutdownClocks
void shutdownClocks()
Definition:
device.cpp:276
Ion::WakeUp::Device::onUSBPlugging
void onUSBPlugging()
Definition:
wakeup.cpp:27
PWR
Definition:
pwr.h:6
ion.h
Ion::Battery::isCharging
bool isCharging()
Definition:
battery.cpp:16
Ion::LED::Device::enforceState
void enforceState(bool red, bool green, bool blue)
Definition:
led.cpp:89
Ion::WakeUp::Device::onChargingEvent
void onChargingEvent()
Definition:
wakeup.cpp:11
Ion::msleep
void msleep(long ms)
Definition:
ion.cpp:4
usb.h
CM4
Definition:
cm4.h:6
Ion::Device::initClocks
void initClocks()
Definition:
device.cpp:186
battery.h
Ion::Backlight::Device::shutdown
void shutdown()
Definition:
backlight.cpp:41
Ion::Keyboard::State::keyDown
bool keyDown(Key k) const
Definition:
keyboard.h:47
Ion::WakeUp::Device::onPowerKeyDown
void onPowerKeyDown()
Definition:
wakeup.cpp:41
Ion::Backlight::Device::init
void init()
Definition:
backlight.cpp:35
Ion::Device::shutdownPeripherals
void shutdownPeripherals()
Definition:
device.cpp:172
led.h
keyboard.h
Ion::Keyboard::scan
State scan()
Definition:
keyboard.cpp:50
Ion::Device::initPeripherals
void initPeripherals()
Definition:
device.cpp:158
PWR::CR
Definition:
pwr.h:8
device.h
regs.h
CM4::SCR
Definition:
cm4.h:38
Ion::Keyboard::State
Definition:
keyboard.h:36
wakeup.h
display.h
Ion::Power::suspend
void suspend(bool checkIfPowerKeyReleased=false)
Definition:
power.cpp:11
epsilon
ion
src
device
power.cpp
Generated by
1.8.14