first commit
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
// **** INCLUDES *****
|
||||
#include "LowPower.h"
|
||||
|
||||
void setup()
|
||||
{
|
||||
// No setup is required for this library
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Enter idle state for 8 s with the rest of peripherals turned off
|
||||
// Each microcontroller comes with different number of peripherals
|
||||
// Comment off line of code where necessary
|
||||
|
||||
// ATmega328P, ATmega168
|
||||
LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF,
|
||||
SPI_OFF, USART0_OFF, TWI_OFF);
|
||||
|
||||
// ATmega32U4
|
||||
//LowPower.idle(SLEEP_8S, ADC_OFF, TIMER4_OFF, TIMER3_OFF, TIMER1_OFF,
|
||||
// TIMER0_OFF, SPI_OFF, USART1_OFF, TWI_OFF, USB_OFF);
|
||||
|
||||
// ATmega2560
|
||||
//LowPower.idle(SLEEP_8S, ADC_OFF, TIMER5_OFF, TIMER4_OFF, TIMER3_OFF,
|
||||
// TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF, USART3_OFF,
|
||||
// USART2_OFF, USART1_OFF, USART0_OFF, TWI_OFF);
|
||||
|
||||
// ATmega256RFR2
|
||||
//LowPower.idle(SLEEP_8S, ADC_OFF, TIMER5_OFF, TIMER4_OFF, TIMER3_OFF,
|
||||
// TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF,
|
||||
// USART1_OFF, USART0_OFF, TWI_OFF);
|
||||
|
||||
// Do something here
|
||||
// Example: Read sensor, data logging, data transmission.
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// **** INCLUDES *****
|
||||
#include "LowPower.h"
|
||||
|
||||
// Use pin 2 as wake up pin
|
||||
const int wakeUpPin = 2;
|
||||
|
||||
void wakeUp()
|
||||
{
|
||||
// Just a handler for the pin interrupt.
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Configure wake up pin as input.
|
||||
// This will consumes few uA of current.
|
||||
pinMode(wakeUpPin, INPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Allow wake up pin to trigger interrupt on low.
|
||||
attachInterrupt(0, wakeUp, LOW);
|
||||
|
||||
// Enter power down state with ADC and BOD module disabled.
|
||||
// Wake up when wake up pin is low.
|
||||
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
|
||||
|
||||
// Disable external pin interrupt on wake up pin.
|
||||
detachInterrupt(0);
|
||||
|
||||
// Do something here
|
||||
// Example: Read sensor, data logging, data transmission.
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// **** INCLUDES *****
|
||||
#include "LowPower.h"
|
||||
|
||||
void setup()
|
||||
{
|
||||
// No setup is required for this library
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Enter power down state for 8 s with ADC and BOD module disabled
|
||||
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
|
||||
|
||||
// Do something here
|
||||
// Example: Read sensor, data logging, data transmission.
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// **** INCLUDES *****
|
||||
#include "LowPower.h"
|
||||
|
||||
// External interrupt on pin 0 (use pin 0 to 24, except pin 4 on Arduino Zero)
|
||||
const int pin = 0;
|
||||
unsigned char count = 10;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Wait for serial USB port to open
|
||||
while(!SerialUSB);
|
||||
SerialUSB.println("***** ATSAMD21 Standby Mode Example *****");
|
||||
|
||||
// ***** IMPORTANT *****
|
||||
// Delay is required to allow the USB interface to be active during
|
||||
// sketch upload process
|
||||
SerialUSB.println("Entering standby mode in:");
|
||||
for (count; count > 0; count--)
|
||||
{
|
||||
SerialUSB.print(count);
|
||||
SerialUSB.println(" s");
|
||||
delay(1000);
|
||||
}
|
||||
// *********************
|
||||
|
||||
// External interrupt on pin (example: press of an active low button)
|
||||
// A pullup resistor is used to hold the signal high when no button press
|
||||
attachInterrupt(pin, blink, LOW);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
SerialUSB.println("Entering standby mode.");
|
||||
SerialUSB.println("Apply low signal to wake the processor.");
|
||||
SerialUSB.println("Zzzz...");
|
||||
// Detach USB interface
|
||||
USBDevice.detach();
|
||||
// Enter standby mode
|
||||
LowPower.standby();
|
||||
// Attach USB interface
|
||||
USBDevice.attach();
|
||||
// Wait for serial USB port to open
|
||||
while(!SerialUSB);
|
||||
// Serial USB is blazing fast, you might miss the messages
|
||||
delay(1000);
|
||||
SerialUSB.println("Awake!");
|
||||
SerialUSB.println("Send any character to enter standby mode again");
|
||||
// Wait for user response
|
||||
while(!SerialUSB.available());
|
||||
while(SerialUSB.available() > 0)
|
||||
{
|
||||
SerialUSB.read();
|
||||
}
|
||||
}
|
||||
|
||||
void blink(void)
|
||||
{
|
||||
|
||||
}
|
||||
1182
libraries/Low-Power/LowPower.cpp
Normal file
1182
libraries/Low-Power/LowPower.cpp
Normal file
File diff suppressed because it is too large
Load Diff
173
libraries/Low-Power/LowPower.h
Normal file
173
libraries/Low-Power/LowPower.h
Normal file
@@ -0,0 +1,173 @@
|
||||
#ifndef LowPower_h
|
||||
#define LowPower_h
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
enum period_t
|
||||
{
|
||||
SLEEP_15MS,
|
||||
SLEEP_30MS,
|
||||
SLEEP_60MS,
|
||||
SLEEP_120MS,
|
||||
SLEEP_250MS,
|
||||
SLEEP_500MS,
|
||||
SLEEP_1S,
|
||||
SLEEP_2S,
|
||||
SLEEP_4S,
|
||||
SLEEP_8S,
|
||||
SLEEP_FOREVER
|
||||
};
|
||||
|
||||
enum bod_t
|
||||
{
|
||||
BOD_OFF,
|
||||
BOD_ON
|
||||
};
|
||||
|
||||
enum adc_t
|
||||
{
|
||||
ADC_OFF,
|
||||
ADC_ON
|
||||
};
|
||||
|
||||
enum timer5_t
|
||||
{
|
||||
TIMER5_OFF,
|
||||
TIMER5_ON
|
||||
};
|
||||
|
||||
enum timer4_t
|
||||
{
|
||||
TIMER4_OFF,
|
||||
TIMER4_ON
|
||||
};
|
||||
|
||||
enum timer3_t
|
||||
{
|
||||
TIMER3_OFF,
|
||||
TIMER3_ON
|
||||
};
|
||||
|
||||
enum timer2_t
|
||||
{
|
||||
TIMER2_OFF,
|
||||
TIMER2_ON
|
||||
};
|
||||
|
||||
enum timer1_t
|
||||
{
|
||||
TIMER1_OFF,
|
||||
TIMER1_ON
|
||||
};
|
||||
|
||||
enum timer0_t
|
||||
{
|
||||
TIMER0_OFF,
|
||||
TIMER0_ON
|
||||
};
|
||||
|
||||
enum spi_t
|
||||
{
|
||||
SPI_OFF,
|
||||
SPI_ON
|
||||
};
|
||||
|
||||
enum usart0_t
|
||||
{
|
||||
USART0_OFF,
|
||||
USART0_ON
|
||||
};
|
||||
|
||||
enum usart1_t
|
||||
{
|
||||
USART1_OFF,
|
||||
USART1_ON
|
||||
};
|
||||
|
||||
enum usart2_t
|
||||
{
|
||||
USART2_OFF,
|
||||
USART2_ON
|
||||
};
|
||||
|
||||
enum usart3_t
|
||||
{
|
||||
USART3_OFF,
|
||||
USART3_ON
|
||||
};
|
||||
|
||||
enum twi_t
|
||||
{
|
||||
TWI_OFF,
|
||||
TWI_ON
|
||||
};
|
||||
|
||||
enum usb_t
|
||||
{
|
||||
USB_OFF,
|
||||
USB_ON
|
||||
};
|
||||
|
||||
enum idle_t
|
||||
{
|
||||
IDLE_0,
|
||||
IDLE_1,
|
||||
IDLE_2
|
||||
};
|
||||
|
||||
class LowPowerClass
|
||||
{
|
||||
public:
|
||||
#if defined (__AVR__)
|
||||
|
||||
#if defined (__AVR_ATmega328P__) || defined (__AVR_ATmega168__) || defined (__AVR_ATmega168P__) || defined (__AVR_ATmega88__)
|
||||
void idle(period_t period, adc_t adc, timer2_t timer2,
|
||||
timer1_t timer1, timer0_t timer0, spi_t spi,
|
||||
usart0_t usart0, twi_t twi);
|
||||
#elif defined __AVR_ATmega644P__ || defined (__AVR_ATmega1284P__)
|
||||
void idle(period_t period, adc_t adc, timer2_t timer2,
|
||||
timer1_t timer1, timer0_t timer0, spi_t spi,
|
||||
usart1_t usart1, usart0_t usart0, twi_t twi);
|
||||
#elif defined __AVR_ATmega2560__
|
||||
void idle(period_t period, adc_t adc, timer5_t timer5,
|
||||
timer4_t timer4, timer3_t timer3, timer2_t timer2,
|
||||
timer1_t timer1, timer0_t timer0, spi_t spi,
|
||||
usart3_t usart3, usart2_t usart2, usart1_t usart1,
|
||||
usart0_t usart0, twi_t twi);
|
||||
#elif defined __AVR_ATmega256RFR2__
|
||||
void idle(period_t period, adc_t adc, timer5_t timer5,
|
||||
timer4_t timer4, timer3_t timer3, timer2_t timer2,
|
||||
timer1_t timer1, timer0_t timer0, spi_t spi,
|
||||
usart1_t usart1,
|
||||
usart0_t usart0, twi_t twi);
|
||||
#elif defined __AVR_ATmega32U4__
|
||||
void idle(period_t period, adc_t adc, timer4_t timer4,
|
||||
timer3_t timer3, timer1_t timer1, timer0_t timer0,
|
||||
spi_t spi, usart1_t usart1, twi_t twi, usb_t usb);
|
||||
#else
|
||||
#error "Please ensure chosen MCU is either 88, 168, 168P, 328P, 32U4, 2560 or 256RFR2."
|
||||
#endif
|
||||
void adcNoiseReduction(period_t period, adc_t adc, timer2_t timer2) __attribute__((optimize("-O1")));
|
||||
void powerDown(period_t period, adc_t adc, bod_t bod) __attribute__((optimize("-O1")));
|
||||
void powerSave(period_t period, adc_t adc, bod_t bod, timer2_t timer2) __attribute__((optimize("-O1")));
|
||||
void powerStandby(period_t period, adc_t adc, bod_t bod) __attribute__((optimize("-O1")));
|
||||
void powerExtStandby(period_t period, adc_t adc, bod_t bod, timer2_t timer2) __attribute__((optimize("-O1")));
|
||||
|
||||
#elif defined (__arm__)
|
||||
|
||||
#if defined (__SAMD21G18A__)
|
||||
void idle(idle_t idleMode);
|
||||
void standby();
|
||||
#else
|
||||
#error "Please ensure chosen MCU is ATSAMD21G18A."
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#error "Processor architecture is not supported."
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
extern LowPowerClass LowPower;
|
||||
#endif
|
||||
21
libraries/Low-Power/README.md
Normal file
21
libraries/Low-Power/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
### Low-Power
|
||||
Lightweight low power library for Arduino.
|
||||
|
||||
Version: 1.81
|
||||
|
||||
Date: 21-01-2020
|
||||
|
||||
Devices Supported:
|
||||
* ATMega88
|
||||
* ATMega168
|
||||
* ATMega168P
|
||||
* ATMega328P
|
||||
* ATMega32U4
|
||||
* ATMega644P
|
||||
* ATMega1284P
|
||||
* ATMega2560
|
||||
* ATMega256RFR2
|
||||
* ATSAMD21G18A
|
||||
|
||||
####Notes:
|
||||
External interrupt during standby on ATSAMD21G18A requires a patch to the <a href="https://github.com/arduino/ArduinoCore-samd">Arduino SAMD Core</a> in order for it to work. Fix is provided by this particular <a href="https://github.com/arduino/ArduinoCore-samd/pull/90">pull request</a>.
|
||||
72
libraries/Low-Power/keywords.txt
Normal file
72
libraries/Low-Power/keywords.txt
Normal file
@@ -0,0 +1,72 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map LowPower
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
idle KEYWORD2
|
||||
adcNoiseReduction KEYWORD2
|
||||
powerDown KEYWORD2
|
||||
powerSave KEYWORD2
|
||||
powerStandby KEYWORD2
|
||||
powerExtStandby KEYWORD2
|
||||
standby KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Instances (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
LowPower KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
SLEEP_15MS LITERAL1
|
||||
SLEEP_30MS LITERAL1
|
||||
SLEEP_60MS LITERAL1
|
||||
SLEEP_120MS LITERAL1
|
||||
SLEEP_250MS LITERAL1
|
||||
SLEEP_500MS LITERAL1
|
||||
SLEEP_1S LITERAL1
|
||||
SLEEP_2S LITERAL1
|
||||
SLEEP_4S LITERAL1
|
||||
SLEEP_8S LITERAL1
|
||||
SLEEP_FOREVER LITERAL1
|
||||
ADC_OFF LITERAL1
|
||||
ADC_ON LITERAL1
|
||||
BOD_OFF LITERAL1
|
||||
BOD_ON LITERAL1
|
||||
TIMER4_OFF LITERAL1
|
||||
TIMER4_ON LITERAL1
|
||||
TIMER3_OFF LITERAL1
|
||||
TIMER3_ON LITERAL1
|
||||
TIMER2_OFF LITERAL1
|
||||
TIMER2_ON LITERAL1
|
||||
TIMER1_OFF LITERAL1
|
||||
TIMER1_ON LITERAL1
|
||||
TIMER0_OFF LITERAL1
|
||||
TIMER0_ON LITERAL1
|
||||
USART3_OFF LITERAL1
|
||||
USART3_ON LITERAL1
|
||||
USART2_OFF LITERAL1
|
||||
USART2_ON LITERAL1
|
||||
USART1_OFF LITERAL1
|
||||
USART1_ON LITERAL1
|
||||
USART0_OFF LITERAL1
|
||||
USART0_ON LITERAL1
|
||||
SPI_OFF LITERAL1
|
||||
SPI_ON LITERAL1
|
||||
TWI_OFF LITERAL1
|
||||
TWI_ON LITERAL1
|
||||
USB_OFF LITERAL1
|
||||
USB_ON LITERAL1
|
||||
IDLE_0 LITERAL1
|
||||
IDLE_1 LITERAL1
|
||||
IDLE_2 LITERAL1
|
||||
9
libraries/Low-Power/library.properties
Normal file
9
libraries/Low-Power/library.properties
Normal file
@@ -0,0 +1,9 @@
|
||||
name=Low-Power
|
||||
version=1.81
|
||||
author=Rocket Scream Electronics
|
||||
maintainer=Rocket Scream Electronics
|
||||
sentence=Lightweight power management library
|
||||
paragraph=Lightweight power management library
|
||||
category=Other
|
||||
url=https://github.com/rocketscream/Low-Power
|
||||
architectures=avr,samd
|
||||
Reference in New Issue
Block a user