first commit
This commit is contained in:
21
libraries/Rocket_Scream_LowPowerAVRZero/LICENSE.md
Normal file
21
libraries/Rocket_Scream_LowPowerAVRZero/LICENSE.md
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 Rocket Scream Electronics
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
3
libraries/Rocket_Scream_LowPowerAVRZero/README.md
Normal file
3
libraries/Rocket_Scream_LowPowerAVRZero/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# LowPowerAVRZero
|
||||
A minimalistic low power management library for the megaAVR 0-series MCU.
|
||||
This library can be used in conjuction with the RTCAVRZero library for complete low power application with megaAVR 0-series MCU.
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <RocketScream_LowPowerAVRZero.h>
|
||||
|
||||
/* Example on a 32-pin ATMega4808, LED on pin D7 */
|
||||
const uint8_t unusedPins[] = {0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13,
|
||||
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};
|
||||
void setup()
|
||||
{
|
||||
uint8_t index;
|
||||
|
||||
/* Ensure unused pins are not floating */
|
||||
for (index = 0; index < sizeof(unusedPins); index++)
|
||||
{
|
||||
pinMode(unusedPins[index], INPUT_PULLUP);
|
||||
LowPower.disablePinISC(unusedPins[index]);
|
||||
}
|
||||
|
||||
/* LED is connected to D7 */
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
LowPower.powerDown();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#include <RocketScream_LowPowerAVRZero.h>
|
||||
|
||||
/* Example on a 32-pin ATMega4808, LED on pin D7 */
|
||||
const uint8_t unusedPins[] = {0, 1, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13,
|
||||
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};
|
||||
volatile bool awake = false;
|
||||
|
||||
void setup()
|
||||
{
|
||||
uint8_t index;
|
||||
|
||||
/* Ensure unused pins are not floating */
|
||||
for (index = 0; index < sizeof(unusedPins); index++)
|
||||
{
|
||||
pinMode(unusedPins[index], INPUT_PULLUP);
|
||||
LowPower.disablePinISC(unusedPins[index]);
|
||||
}
|
||||
|
||||
/* LED is connected to D7 */
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
pinMode(2, INPUT_PULLUP);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
/* Only asynchronous input pin can be used as wake up source during power */
|
||||
/* down. Pin D2, D6, D14, D16, D18, D22 on 32-pin ATMega4808 */
|
||||
attachInterrupt(2, wakeUp, LOW);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
LowPower.powerDown();
|
||||
if (awake)
|
||||
{
|
||||
awake = false;
|
||||
digitalWrite(LED_BUILTIN, CHANGE);
|
||||
}
|
||||
}
|
||||
|
||||
void wakeUp(void)
|
||||
{
|
||||
awake = true;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <RocketScream_LowPowerAVRZero.h>
|
||||
#include <RocketScream_RTCAVRZero.h>
|
||||
|
||||
/* Example on a 32-pin ATMega4808, LED on pin D7, using internal ULP OSC32K */
|
||||
const uint8_t unusedPins[] = {0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13,
|
||||
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};
|
||||
|
||||
void setup()
|
||||
{
|
||||
uint8_t index;
|
||||
|
||||
for (index = 0; index < sizeof(unusedPins); index++)
|
||||
{
|
||||
pinMode(unusedPins[index], INPUT_PULLUP);
|
||||
LowPower.disablePinISC(unusedPins[index]);
|
||||
}
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
/* true: external 32.768 kHz crystal */
|
||||
/* false: internal 32.768 kHz ULP oscillator */
|
||||
RTCAVRZero.begin(false);
|
||||
/* Time in seconds, true: repeat, false: once */
|
||||
RTCAVRZero.enableAlarm(5, true);
|
||||
RTCAVRZero.attachInterrupt(toggle);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
/* RTC works down to standby mode only. In power down, PIT is required */
|
||||
LowPower.standby();
|
||||
}
|
||||
|
||||
void toggle(void)
|
||||
{
|
||||
digitalWrite(LED_BUILTIN, CHANGE);
|
||||
}
|
||||
23
libraries/Rocket_Scream_LowPowerAVRZero/keywords.txt
Normal file
23
libraries/Rocket_Scream_LowPowerAVRZero/keywords.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For LowPowerAVRZero
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
LowPower KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
idle KEYWORD2
|
||||
standby KEYWORD2
|
||||
powerDown KEYWORD2
|
||||
disablePinISC KEYWORD2
|
||||
enablePinISC KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
@@ -0,0 +1,9 @@
|
||||
name=Rocket Scream LowPowerAVRZero
|
||||
version=1.0.0
|
||||
author=Rocket Scream Electronics
|
||||
maintainer=rocketscream <support@rocketscream.com>
|
||||
sentence=Low power management for MegaAVR 0-series MCU.
|
||||
paragraph=Low power management for MegaAVR 0-series MCU.
|
||||
category=Device Control
|
||||
url=https://github.com/rocketscream/RocketScream_LowPowerAVRZero
|
||||
architectures=megaavr
|
||||
@@ -0,0 +1,76 @@
|
||||
#include <avr/io.h>
|
||||
#include <avr/sleep.h>
|
||||
#include "RocketScream_LowPowerAVRZero.h"
|
||||
|
||||
/*! \brief Put MCU into idle mode.
|
||||
*
|
||||
*/
|
||||
void RocketScream_LowPowerAVRZeroClass::idle(void)
|
||||
{
|
||||
set_sleep_mode(SLEEP_MODE_IDLE);
|
||||
sleep();
|
||||
}
|
||||
|
||||
/*! \brief Put MCU into standby mode.
|
||||
*
|
||||
*/
|
||||
void RocketScream_LowPowerAVRZeroClass::standby(void)
|
||||
{
|
||||
set_sleep_mode(SLEEP_MODE_STANDBY);
|
||||
sleep();
|
||||
}
|
||||
|
||||
/*! \brief Put MCU into power down mode.
|
||||
*
|
||||
*/
|
||||
void RocketScream_LowPowerAVRZeroClass::powerDown(void)
|
||||
{
|
||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
||||
sleep();
|
||||
}
|
||||
|
||||
/*! \brief Enable sleep mode.
|
||||
*
|
||||
*/
|
||||
void RocketScream_LowPowerAVRZeroClass::sleep(void)
|
||||
{
|
||||
cli();
|
||||
sleep_enable();
|
||||
sei();
|
||||
sleep_cpu();
|
||||
}
|
||||
|
||||
/*! \brief Disable pin ISC.
|
||||
*
|
||||
*/
|
||||
void RocketScream_LowPowerAVRZeroClass::disablePinISC(uint8_t pin)
|
||||
{
|
||||
PORT_t *port = digitalPinToPortStruct(pin);
|
||||
/* Get bit position for getting pin ctrl reg */
|
||||
uint8_t bit_pos = digitalPinToBitPosition(pin);
|
||||
|
||||
/* Calculate where pin control register is */
|
||||
volatile uint8_t *pin_ctrl_reg = getPINnCTRLregister(port, bit_pos);
|
||||
|
||||
/* Disable ISC */
|
||||
*pin_ctrl_reg = PORT_ISC_INPUT_DISABLE_gc;
|
||||
}
|
||||
|
||||
/*! \brief Enable pin ISC.
|
||||
*
|
||||
*/
|
||||
void RocketScream_LowPowerAVRZeroClass::enablePinISC(uint8_t pin)
|
||||
{
|
||||
PORT_t *port = digitalPinToPortStruct(pin);
|
||||
/* Get bit position for getting pin ctrl reg */
|
||||
uint8_t bit_pos = digitalPinToBitPosition(pin);
|
||||
|
||||
/* Calculate where pin control register is */
|
||||
volatile uint8_t *pin_ctrl_reg = getPINnCTRLregister(port, bit_pos);
|
||||
|
||||
/* Default configuration is enable ISC without interrupt */
|
||||
*pin_ctrl_reg = PORT_ISC_INTDISABLE_gc;
|
||||
}
|
||||
|
||||
RocketScream_LowPowerAVRZeroClass LowPower;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef RocketScream_LowPowerAVRZero_h
|
||||
#define RocketScream_LowPowerAVRZero_h
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
class RocketScream_LowPowerAVRZeroClass
|
||||
{
|
||||
public:
|
||||
void idle(void);
|
||||
void standby(void);
|
||||
void powerDown(void);
|
||||
void disablePinISC(uint8_t pin);
|
||||
void enablePinISC(uint8_t pin);
|
||||
|
||||
private:
|
||||
void sleep(void);
|
||||
};
|
||||
|
||||
extern RocketScream_LowPowerAVRZeroClass LowPower;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user