Numworks Epsilon  1.4.1
Graphing Calculator Operating System
wakeup.cpp
Go to the documentation of this file.
1 #include "wakeup.h"
2 #include "regs/regs.h"
3 #include "battery.h"
4 #include "usb.h"
5 #include "keyboard.h"
6 
7 namespace Ion {
8 namespace WakeUp {
9 namespace Device {
10 
13 
14  /* Warning: pins with the same number in different groups cannot be set as
15  * source input for EXTI at the same time. Here, EXTICR1 register is filled
16  * between position 0-3 (charging pin = 0) with
17  * 0000 (ChargingGPIO = group A). */
19 
21 
22  /* We need to detect when the battery stops charging. We set the
23  * wake up event on the rising edge. */
25 }
26 
27 void onUSBPlugging() {
29  /* Here, EXTICR3 register is filled between position 4-7 (Vbus pin = 9) with
30  * 0000 (Vbus GPIO = group A). */
31  SYSCFG.EXTICR3()->setEXTI(USB::Device::VbusPin.pin(), USB::Device::VbusPin.group());
32 
33  EXTI.EMR()->set(USB::Device::VbusPin.pin(), true);
34 #if LED_WHILE_CHARGING
35  EXTI.FTSR()->set(USB::Device::VbusPin.pin(), true);
36 #endif
37  EXTI.RTSR()->set(USB::Device::VbusPin.pin(), true);
38 }
39 
40 
46  Keyboard::Device::RowGPIO.ODR()->set(rowPin, 0);
47 
49  uint8_t columnPin = Keyboard::Device::ColumnPins[column];
50 
53 
54  /* Here, EXTICR1 register is filled between position 4-7 (column pin = 1) with
55  * 0010 (ColumnGPIO = group C). */
56 
58 
59  EXTI.EMR()->set(columnPin, true);
60 
61  /* When the key is pressed, it will go from 1 (because it's pulled up) to
62  * zero (because it's connected to the open-drain output. In other words,
63  * we're waiting for a falling edge. */
64  EXTI.FTSR()->set(columnPin, true);
65 }
66 
67 }
68 }
69 }
void onUSBPlugging()
Definition: wakeup.cpp:27
void onChargingEvent()
Definition: wakeup.cpp:11
constexpr uint8_t ChargingPin
Definition: battery.h:22
Definition: exti.h:6
Definition: syscfg.h:8
unsigned char uint8_t
Definition: stdint.h:4
Definition: gpio.h:47
void setType(int index, Type type) volatile
Definition: gpio.h:27
void set(int index, bool state) volatile
Definition: exti.h:11
uint8_t columnForKey(Key key)
Definition: keyboard.h:45
constexpr GPIO ChargingGPIO
Definition: battery.h:21
void initGPIO()
Definition: usb.cpp:61
void onPowerKeyDown()
Definition: wakeup.cpp:41
void setEXTI(int index, GPIO gpio) volatile
Definition: syscfg.h:21
void setPull(int index, Pull pull) volatile
Definition: gpio.h:39
void setEXTI(int index, GPIO gpio) volatile
Definition: syscfg.h:29
constexpr GPIO ColumnGPIO
Definition: keyboard.h:38
constexpr uint8_t RowPins[numberOfRows]
Definition: keyboard.h:36
constexpr uint8_t ColumnPins[numberOfColumns]
Definition: keyboard.h:40
Definition: exti.h:15
void setMode(int index, Mode mode) volatile
Definition: gpio.h:17
Definition: backlight.h:6
uint8_t rowForKey(Key key)
Definition: keyboard.h:42
void set(int index, bool state) volatile
Definition: gpio.h:50
constexpr GPIO RowGPIO
Definition: keyboard.h:34