Basic example showing how to use the sleep/deepsleep modes on the DISCO_L476VG board.

Dependencies:   BSP_DISCO_L476VG LCD_DISCO_L476VG mbed

Committer:
jeromecoutant
Date:
Thu Jul 06 13:57:53 2017 +0000
Revision:
2:3201a7da544e
Parent:
0:e99d70686026
Update after MBED rev145; (new L4 cube version);

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:e99d70686026 1 #include "mbed.h"
bcostm 0:e99d70686026 2 #include "LCD_DISCO_L476VG.h"
bcostm 0:e99d70686026 3
bcostm 0:e99d70686026 4 LCD_DISCO_L476VG lcd;
bcostm 0:e99d70686026 5
bcostm 0:e99d70686026 6 DigitalOut led_green(LED1);
bcostm 0:e99d70686026 7 DigitalOut led_red(LED2);
bcostm 0:e99d70686026 8
bcostm 0:e99d70686026 9 InterruptIn joy_down(JOYSTICK_DOWN);
bcostm 0:e99d70686026 10 InterruptIn joy_up(JOYSTICK_UP);
jeromecoutant 2:3201a7da544e 11 InterruptIn joy_center(JOYSTICK_CENTER);
bcostm 0:e99d70686026 12
jeromecoutant 2:3201a7da544e 13 #define MODE_WAKEUP 0 // IDD=19mA
jeromecoutant 2:3201a7da544e 14 #define MODE_SLEEP 1 // IDD=10mA
jeromecoutant 2:3201a7da544e 15 #define MODE_DEEP_SLEEP 2 // IDD= 1mA
bcostm 0:e99d70686026 16
jeromecoutant 2:3201a7da544e 17 static int deepsleep_mode = MODE_WAKEUP;
bcostm 0:e99d70686026 18
jeromecoutant 2:3201a7da544e 19 // Used to enter in wake up mode
bcostm 0:e99d70686026 20 void wakeup_tasks()
bcostm 0:e99d70686026 21 {
bcostm 0:e99d70686026 22 led_green = 1;
jeromecoutant 2:3201a7da544e 23 led_red = 1;
bcostm 0:e99d70686026 24 lcd.Clear();
jeromecoutant 2:3201a7da544e 25 printf("WAKEUP\n");
bcostm 0:e99d70686026 26 lcd.DisplayString((uint8_t *)"WAKEUP");
jeromecoutant 2:3201a7da544e 27 deepsleep_mode = MODE_WAKEUP;
bcostm 0:e99d70686026 28 }
bcostm 0:e99d70686026 29
bcostm 0:e99d70686026 30 // Used to enter in deepsleep mode
bcostm 0:e99d70686026 31 void joy_down_pressed()
bcostm 0:e99d70686026 32 {
jeromecoutant 2:3201a7da544e 33 deepsleep_mode = MODE_DEEP_SLEEP;
bcostm 0:e99d70686026 34 }
bcostm 0:e99d70686026 35
jeromecoutant 2:3201a7da544e 36 // Used to enter in sleep mode
bcostm 0:e99d70686026 37 void joy_up_pressed()
bcostm 0:e99d70686026 38 {
jeromecoutant 2:3201a7da544e 39 deepsleep_mode = MODE_SLEEP;
bcostm 0:e99d70686026 40 }
bcostm 0:e99d70686026 41
bcostm 0:e99d70686026 42 int main()
bcostm 0:e99d70686026 43 {
bcostm 0:e99d70686026 44 led_green = 1;
bcostm 0:e99d70686026 45 led_red = 1;
bcostm 0:e99d70686026 46 lcd.Clear();
jeromecoutant 2:3201a7da544e 47 printf("HELLO\n");
bcostm 0:e99d70686026 48 lcd.DisplayString((uint8_t *)"HELLO");
bcostm 0:e99d70686026 49
bcostm 0:e99d70686026 50 // Configure the buttons
bcostm 0:e99d70686026 51 joy_down.rise(&joy_down_pressed);
bcostm 0:e99d70686026 52 joy_down.mode(PullDown);
bcostm 0:e99d70686026 53 joy_up.rise(&joy_up_pressed);
bcostm 0:e99d70686026 54 joy_up.mode(PullDown);
jeromecoutant 2:3201a7da544e 55 joy_center.rise(&wakeup_tasks);
jeromecoutant 2:3201a7da544e 56 joy_center.mode(PullDown);
bcostm 0:e99d70686026 57
bcostm 0:e99d70686026 58 while(1) {
bcostm 0:e99d70686026 59
jeromecoutant 2:3201a7da544e 60 if (deepsleep_mode == MODE_SLEEP) {
jeromecoutant 2:3201a7da544e 61 lcd.Clear();
jeromecoutant 2:3201a7da544e 62 printf("SLEEP\n");
bcostm 0:e99d70686026 63 lcd.DisplayString((uint8_t *)"SLEEP");
jeromecoutant 2:3201a7da544e 64 led_red = 0;
jeromecoutant 2:3201a7da544e 65 wait(1);
bcostm 0:e99d70686026 66 sleep();
jeromecoutant 2:3201a7da544e 67 wakeup_tasks();
jeromecoutant 2:3201a7da544e 68 }
jeromecoutant 2:3201a7da544e 69 if (deepsleep_mode == MODE_DEEP_SLEEP) {
jeromecoutant 2:3201a7da544e 70 lcd.Clear();
jeromecoutant 2:3201a7da544e 71 printf("DEEP_SLEEP\n");
jeromecoutant 2:3201a7da544e 72 lcd.DisplayString((uint8_t *)"DEEP");
jeromecoutant 2:3201a7da544e 73 led_green = 0;
jeromecoutant 2:3201a7da544e 74 wait(.1);
bcostm 0:e99d70686026 75 deepsleep();
jeromecoutant 2:3201a7da544e 76 wakeup_tasks();
bcostm 0:e99d70686026 77 }
bcostm 0:e99d70686026 78 }
bcostm 0:e99d70686026 79 }