-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
duff2013
committed
Nov 23, 2016
1 parent
08a5035
commit 6a8dac1
Showing
64 changed files
with
4,241 additions
and
4,599 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,156 +1,124 @@ | ||
#Snooze v5.5.3 | ||
# Snooze v6.2.3 | ||
|
||
<h1>General Usage</h1> | ||
####This going to be replaced with a new [Version 6](https://github.com/duff2013/Snooze_V6_Beta), this is still is beta but should be mostly fully functional now. While the API has changed somewhat refer to readme for the changes. | ||
--- | ||
For those using v5 of Snooze the reason for the change is that new Teensy's are in the pipeline and updating this fairly extensive library became to difficult because each new processor introduced has its own set of Low Power functionality. Now the library is divided into three classes:<br> | ||
![alt text](https://github.com/duff2013/Snooze_V6_Beta/blob/master/images/Snooze_Class_Layout/Slide1.png "Snooze Class Layout")<br> | ||
As you can see the Drivers are now separated from the SnoozeBlock Class. Before these drivers where part of the SnoozeBlock which made it difficult to add new functionalities. Each Teensy can now have driver classes designed specifically for them. Users can install their own drivers also if they wish also, see the skeltonClass example. Snooze uses something similar to the Audio library's conventions for adding drivers. As an added benefit, only the drivers that are installed are called, before all drivers where called just not used if not configured, this should add some performance benefits. | ||
|
||
####Teensyduino 1.29 [beta4](https://forum.pjrc.com/threads/35315-Teensyduino-1-29-Beta-4-Available) and above only. This will be the last v5 update, [Version 6] will be actively developed for now on and will be merged into this branch when not beta. | ||
<h3>SnoozeBlock -</h3> | ||
```SnoozeBlock class is used to configure what wakeups you want. You can define many SnoozeBlocks classes for different configurations.``` | ||
Here are some new features and enhancments over Version 5: | ||
* Three teir class structure now means easier and faster debug and development of Snooze. | ||
* All core drivers save and restore all relevent registers and such before/after sleeping. So things like HardwareSerial will just work if using one of its pins as a digital wakeup event. | ||
* Millis is updated when using Timer driver wakeup. Might implement this for other wakeup drivers also. | ||
* Audio library plays nice with Snooze now by using the SnoozeAudio core driver. | ||
* REDUCED_CPU_BLOCK does not mess up the millis anymore. | ||
* Add and subtract drivers from SnoozeBlock(s), now you can get creative with SnoozeBlocks! | ||
|
||
Function | about | | ||
-----------------------------| ---------------------------- | | ||
pinMode | Setting Pin, Comapre, TSI wakeups. Pins include type/mode and interrupt kind: RISING,FALLING,CHANGE,LOW,HIGH. Comapre is voltage crossing wakeup. TSI is capacentance threshold. | | ||
setTimer | Low Power Timer: 1ms to 65535ms in 1ms granulity. | | ||
setAlarm | RTC, can set seconds, minutes and hours til wake. | | ||
setLowVoltage | Wakeup teensy if low voltage detected, not implemented yet. | | ||
setPeripheral | Turn on/off modules, adc/serial/usb etc... | | ||
___ | ||
<h3>Snooze -</h3> | ||
```Snooze class is the different sleep modes offered``` | ||
--- | ||
Here is a basic example of the new api. As you can see we load three of Core Driver Classes - touch, digital, timer.<br> | ||
What are the Core Drivers?<br> | ||
Core Drivers configure wakeup events, Drivers are further explained later.<br> | ||
|
||
Function | about | | ||
----------------- | ---------------------------- | | ||
debug | Library source code serial debug, not implemented yet. | | ||
idle | Spin loop power reduction, puts the cpu in wait mode until the next systick isr. Use in waiting loop. | | ||
sleep | Most versiatle "sleep mode", use a SnoozeBlock or any interrupt to wake processor. This puts the cpu into VLPW mode. | | ||
deepSleep | Limited pin wakeups defined by LLWU. | | ||
hibernate | Same as deepSleep but the USB regualtor is put into low power state. Only limited current can be source from 3.3v output and the voltage will drop to ~2.7v. | | ||
___ | ||
<h5>pinMode: Digital, Touch Sense pins</h5> | ||
```c | ||
/** | ||
* pinMode - Configures either a digital pin or tsi pin as a wakeup source. | ||
* | ||
* Teensy 3.x (digital pin) | ||
* @param pin - sleep pins(1-33), deepSleep, hibernate pins (2,4,6,7,9,10,11,13,16,21,22,26,30,33) | ||
* @param mode - |INPUT|INPUT_PULLUP|OUTPUT| | ||
* @param val - |HIGH|LOW|RISING|FALLING|CHANGE| | ||
* | ||
* Teensy 3.x (tsi pin) | ||
* @param pin - sleep pins(does not work), deepSleep, hibernate pins (0,1,15,16,17,18,19,22,23,25,32,33) | ||
* @param mode - |TSI| | ||
* @param val - threshold capacitance value, greater than this value wakes. | ||
* | ||
* Teensy LC (digital pin) | ||
* @param pin - sleep pins(1-23), deepSleep, hibernate pins (2,4,6,7,9,10,11,13,16,21,22) | ||
* @param mode - |INPUT|INPUT_PULLUP|OUTPUT| | ||
* @param val - |HIGH|LOW|RISING|FALLING|CHANGE| | ||
1. touch - Using the Kinetis touch module to wake your Teensy. | ||
2. digital - Wake your Teensy with a RISING or FALLING event on a certian pin. | ||
3. timer - Use the Low Power timer in milliseconds to wake your Teensy, | ||
4. alarm - Use the RTC clock to wake your Teensy. | ||
5. compare - Setup a volatgae crossing to wake your Teensy. | ||
|
||
Next we see the SnoozeBlock only has the timer and digital drivers installed. Even though the Touch driver is loaded it is not installed so it won't get called. In this example either the timer expires or the digital pin is lifted will wake the Teensy up.<br> | ||
```c++ | ||
#include <Snooze.h> | ||
// Load drivers | ||
SnoozeTouch touch; | ||
SnoozeDigital digital; | ||
SnoozeTimer timer; | ||
|
||
// install drivers to a SnoozeBlock | ||
SnoozeBlock config(timer, digital); | ||
|
||
void setup() { | ||
pinMode(LED_BUILTIN, OUTPUT); | ||
/******************************************************** | ||
* Set Low Power Timer wake up in milliseconds. | ||
********************************************************/ | ||
timer.setTimer(5000);// milliseconds | ||
/******************************************************** | ||
* Define digital pins for waking the teensy up. This | ||
* combines pinMode and attachInterrupt in one function. | ||
* | ||
* Teensy LC (tsi pin) | ||
* @param pin - sleep pins(does not work), deepSleep, hibernate pins (0,1,3,4,15,16,17,18,19,22,23) | ||
* @param mode - |TSI| | ||
* @param val - threshold capacitance value, greater than this value wakes. | ||
*/ | ||
void SnoozeBlock::pinMode( int pin, int mode, int val ); | ||
``` | ||
___ | ||
<h5>pinMode: Compare pins</h5> | ||
```c | ||
/** | ||
* pinMode - Configures compare wakeup source. | ||
* Teensy 3.x | ||
* Digital pins: 2,4,6,7,9,10,11,13,16,21,22,26,30,33 | ||
* | ||
* @param pin either pin 11 or 12 can be used | ||
* @param mode |CMP| | ||
* @param type |RISING|FALLING| | ||
* @param val threshold crossing value in volts. | ||
*/ | ||
void SnoozeBlock::pinMode( int pin, int mode, int type, double val ); | ||
* Teensy LC | ||
* Digital pins: 2,6,7,9,10,11,16,21,22 | ||
********************************************************/ | ||
digital.pinMode(21, INPUT_PULLUP, RISING);//pin, mode, type | ||
digital.pinMode(22, INPUT_PULLUP, RISING);//pin, mode, type | ||
} | ||
|
||
void loop() { | ||
/******************************************************** | ||
* feed the sleep function its wakeup parameters. Then go | ||
* to deepSleep. | ||
********************************************************/ | ||
int who = Snooze.deepSleep( config );// return module that woke processor | ||
digitalWrite(LED_BUILTIN, HIGH); | ||
delay(100); | ||
digitalWrite(LED_BUILTIN, LOW); | ||
} | ||
``` | ||
___ | ||
<h5>setTimer: Low Power Timer</h5> | ||
```c | ||
/** | ||
* setTimer - wake up period in milli seconds in 1ms granularity. | ||
* | ||
* @param period 1ms to 65535ms | ||
*/ | ||
void SnoozeBlock::setTimer( uint16_t period ); | ||
<b>Lets break out each part out so we can see what is going on here:</b><br> | ||
1. Include the Snooze library header. This brings in Snooze, SnoozeBlock, Core Driver Classes.<br> | ||
```#include <Snooze.h>```<br> | ||
2. Next we load the drivers classes we want visible to install.<br> | ||
``` | ||
___ | ||
<h5>setAlarm: RTC</h5> | ||
```c | ||
/** | ||
* setAlarm - Configures RTC wakeup source. hr, min and sec will be added for the total time. | ||
* | ||
* @param hours number of hours in the future. | ||
* @param minutes number of minutes in the future. | ||
* @param seconds number of seconds in the future. | ||
*/ | ||
void SnoozeBlock::setAlarm( uint8_t hours, uint8_t minutes, uint8_t seconds ); | ||
SnoozeTouch touch; | ||
SnoozeDigital digital; | ||
SnoozeTimer timer; | ||
``` | ||
___ | ||
<h5>source: </h5> | ||
```c | ||
/** | ||
* source - returns the wakeup source. | ||
* | ||
* @return Digital pins return pin number, CMP - 34, RTC - 35, LPTMR - 36, TSI - 37. | ||
*/ | ||
int SnoozeClass::source( void ); | ||
<br> | ||
3. Here we install only the Timer and Digital drivers to the SnoozeBlock. | ||
<br> | ||
``` | ||
___ | ||
<h5>idle: </h5> | ||
```c | ||
/** | ||
* idle - puts processor into wait mode until next interrupt typically systick. | ||
*/ | ||
void SnoozeClass::idle( void ); | ||
SnoozeBlock config(timer, digital); | ||
``` | ||
___ | ||
<h5>sleep: </h5> | ||
```c | ||
/** | ||
* sleep - most versatile sleep mode. SnoozeBlock configuration or any interrupt can wake the processor. | ||
* | ||
* @param configuration SnoozeBlock class config. | ||
* | ||
* @return wakeup source | ||
*/ | ||
int SnoozeClass::sleep( SnoozeBlock &configuration ); | ||
<br> | ||
4. Now we configure the Drivers, typically drivers have some way of changing certain parameters.<br> | ||
``` | ||
___ | ||
<h5>deepSleep: </h5> | ||
```c | ||
/** | ||
* deepSleep - LLWU is used to handle interrupts that wake. USB regulator is enabled and 3.3V output pin can supply full current (100mA MAX). | ||
* | ||
* @param configuration SnoozeBlock class config. | ||
* @param mode |LLS|VLLS3|VLLS2|VLLS1| | ||
* | ||
* @return wakeup source | ||
*/ | ||
int SnoozeClass::deepSleep( SnoozeBlock &configuration, SLEEP_MODE mode ); | ||
timer.setTimer(5000);// milliseconds | ||
digital.pinMode(21, INPUT_PULLUP, RISING);//pin, mode, type | ||
digital.pinMode(22, INPUT_PULLUP, RISING);//pin, mode, type | ||
``` | ||
___ | ||
<h5>hibernate: </h5> | ||
```c | ||
/** | ||
* hibernate - LLWU is used to handle interrupts that wake. USB regulator is disabled and 3.3V output pin can only supply limited current and voltage drops to ~2.7V. | ||
* | ||
* @param configuration SnoozeBlock class config. | ||
* @param mode |LLS|VLLS3|VLLS2|VLLS1| | ||
* | ||
* @return wakeup source | ||
*/ | ||
int SnoozeClass::hibernate( SnoozeBlock &configuration, SLEEP_MODE mode ); | ||
<br> | ||
5. Lastly we supply the SnoozeBlock to whatever sleep function you want to use from the Snooze class. We still have the same three sleep modes<br> | ||
``` | ||
___ | ||
<h5>setPeripheral: </h5> | ||
```c | ||
/** | ||
* Allows you to turn off/on clocks for different hardware on teensy. | ||
*/ | ||
periph_t setPeripheral; | ||
Snooze.sleep( config ); | ||
Snooze.deepSleep( config ); | ||
Snooze.hibernate( config ); | ||
``` | ||
<br> | ||
[Version 6](https://github.com/duff2013/Snooze_V6_Beta) | ||
--- | ||
Now that was easy enough lets take deeper look at the library structure.<br> | ||
![alt text](https://github.com/duff2013/Snooze_V6_Beta/blob/master/images/Snooze_Class_Layout/Slide3.png "Snooze Library Layout") | ||
<br> | ||
As you can see Snooze library has only one Snooze Class but can have mulitple SnoozeBlocks which have mulitiple Drivers. Refferring to the first graphic Snooze is 3 Tier Class structure: | ||
1. Snooze Class | ||
2. SnoozeBlock Class | ||
3. Drivers | ||
<h4> Snooze Class:</h4> | ||
... | ||
<h4> SnoozeBlock Class:</h4> | ||
... | ||
<h4> Driver Class:</h4> | ||
... | ||
--- | ||
<br> | ||
![alt text](https://github.com/duff2013/Snooze_V6_Beta/blob/master/images/Snooze_Class_Layout/Slide4.png "Snooze Library Layout") | ||
<br> | ||
![alt text](https://github.com/duff2013/Snooze_V6_Beta/blob/master/images/Snooze_Class_Layout/Slide5.png "Snooze Library Layout") | ||
<br> | ||
![alt text](https://github.com/duff2013/Snooze_V6_Beta/blob/master/images/Snooze_Class_Layout/Slide6.png "Snooze Library Layout") | ||
<br> | ||
![alt text](https://github.com/duff2013/Snooze_V6_Beta/blob/master/images/Snooze_Class_Layout/Slide7.png "Snooze Library Layout") | ||
<br> |
Oops, something went wrong.