Use interrupt for low power¶
The interrupt pin of the touch controller can be used as a trigger to wake up the system from low power idle mode.
Configure¶
The example below is based on an RTOS and uses a hardware interrupt and an event.
// RTOS library
#include "Galaxia.h"
HWI myHWI;
Event myEvent;
When idle, the RTOS puts the system in low power mode.
// RTOS event and interrupt
myEvent.begin();
myHWI.begin(boardLaunchPad.touchInt, myHWI_ISR, FALLING);
myHWI.enableInterrupt();
When the display is touched, the touch controller generates an interrupt on the boardLaunchPad.touchInt
GPIO. The boardLaunchPad.touchInt
signal triggers the myHWI_ISR()
interrupt service routine. The myHWI_ISR()
interrupt service routine raises the event myEvent
.
void myHWI_ISR()
{
myEvent.send();
}
Finally, the myEvent.waitFor()
catches the event.
Use¶
// Page main loop
myScreen.suspend();
myEvent.waitFor();
myScreen.resume();
Before and after myEvent.waitFor()
, myScreen.suspend()
and myScreen.resume()
ensure the lowest power mode.
-
The function
suspend()
sets all the GPIOs toLOW
and deactivates the SPI bus. -
The function
resume()
restores all the GPIOs and reactivates the SPI bus.
Warning
The functions suspend()
and resume()
should not be used if other devices share the same SPI bus.
Example¶
This is the full code of the example.
The main loop checks the buttons myButtonMore
and myButtonExit
.
-
If
myButtonMore
has been pressed, the counter in incremented and message updated accordingly. -
If
myButtonExit
has been pressed, the system exits.
// SDK
#include "hV_HAL_Peripherals.h"
// Configuration
#include "hV_Configuration.h"
// Screen
#include "PDLS_EXT3_Advanced_Fast.h"
Screen_EPD_EXT3_Fast myScreen(eScreen_EPD_370_PS_0C_Touch, boardLaunchPad);
// Application library
#include "hV_GUI.h"
GUI myGUI(&myScreen);
button myButtonMore;
text myText;
// RTOS library
#include "Galaxia.h"
HWI myHWI;
Event myEvent;
void myHWI_ISR()
{
myEvent.send();
}
void main()
{
hV_HAL_begin();
// Prepare screen and font
myScreen.begin();
fontLarge = myScreen.addFont(Font_DejaVuSans20);
fontLarge -= (fontLarge > 0) ? 1 : 0;
// Prepare GUI
myGUI.begin();
uint16_t x = myScreen.screenSizeX();
uint16_t y = myScreen.screenSizeY();
uint16_t dx = x / 5;
uint16_t dy = y / 5;
// Page setup
myGUI.delegate(false);
item myItemExit = setItem(3, "Exit");
myButtonExit.dDefine(dx * 3, dy * 3, dx, dy * 1, myItemExit, fontLarge);
myButtonExit.draw();
item myItemMore = setItem(1, "More");
myButtonMore.dDefine(dx * 1, dy * 3, dx, dy * 1, myItemMore, fontLarge);
myButtonMore.draw();
myText.dDefine(dx, dy * 1, dx * 3, dy * 1, 0, 0, fontLarge);
myText.draw("Waiting for touch");
myScreen.flushFast();
// RTOS event and interrupt
myEvent.begin();
myHWI.begin(boardLaunchPad.touchInt, myHWI_ISR, FALLING);
myHWI.enableInterrupt();
// Page main loop
myGUI.delegate(true);
uint8_t count = 0;
do
{
myScreen.suspend();
myEvent.waitFor();
myScreen.resume();
if (myButtonMore.check())
{
count += 1;
myText.draw(formatString("Waiting for touch (%i)", count));
}
}
while (myButtonExit.check() == false);
// Exit
myHWI.clearInterrupt();
myScreen.regenerate();
hV_HAL_exit(0);
}