summaryrefslogtreecommitdiffstats
path: root/group__app.html
blob: a2cea10c177303b2b60a0e857c54dbb7d29f2c97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Sensor Watch: Application Framework</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Sensor Watch
   &#160;<span id="projectnumber">0.0.0</span>
   </div>
   <div id="projectbrief">A board replacement for the classic Casio F-91W wristwatch, powered by a Microchip SAM L22 microcontroller.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Application Framework</div>  </div>
</div><!--header-->
<div class="contents">

<p>This section covers the functions that you will implement in your app.c file when designing a Sensor Watch app.  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:gadd3190cf715f513666f4be42874d91e2"><td class="memItemLeft" align="right" valign="top"><a id="gadd3190cf715f513666f4be42874d91e2"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__app.html#gadd3190cf715f513666f4be42874d91e2">app_init</a> (void)</td></tr>
<tr class="memdesc:gadd3190cf715f513666f4be42874d91e2"><td class="mdescLeft">&#160;</td><td class="mdescRight">A function you will implement to initialize your application state. The app_init function is called before anything else. Use it to set up any internal data structures or application state required by your app, but don't configure any peripherals just yet. <br /></td></tr>
<tr class="separator:gadd3190cf715f513666f4be42874d91e2"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gab6a9f08ba879ce8d28fb19ca2882890a"><td class="memItemLeft" align="right" valign="top"><a id="gab6a9f08ba879ce8d28fb19ca2882890a"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__app.html#gab6a9f08ba879ce8d28fb19ca2882890a">app_wake_from_backup</a> (void)</td></tr>
<tr class="memdesc:gab6a9f08ba879ce8d28fb19ca2882890a"><td class="mdescLeft">&#160;</td><td class="mdescRight">A function you will implement to wake from BACKUP mode, which wipes the system's RAM, and with it, your application's state. You may have chosen to store some important application state in the RTC's backup registers prior to entering this mode. You may restore that state here. <br /></td></tr>
<tr class="separator:gab6a9f08ba879ce8d28fb19ca2882890a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gacce192accedbd296eb8d2182f8101f16"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__app.html#gacce192accedbd296eb8d2182f8101f16">app_setup</a> (void)</td></tr>
<tr class="memdesc:gacce192accedbd296eb8d2182f8101f16"><td class="mdescLeft">&#160;</td><td class="mdescRight">A function you will implement to set up your application. The app_setup function is like setup() in Arduino. It is called once when the program begins. You should set pin modes and enable any peripherals you want to set up (real-time clock, I2C, etc.) Depending on your application, you may or may not want to configure sensors on your sensor board here. For example, a low-power accelerometer that will run at all times should be configured here, whereas you may want to enable a more power-hungry sensor only when you need it.  <a href="group__app.html#gacce192accedbd296eb8d2182f8101f16">More...</a><br /></td></tr>
<tr class="separator:gacce192accedbd296eb8d2182f8101f16"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gad1cfce0ef962cd2afe2d8b2d2d13482a"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__app.html#gad1cfce0ef962cd2afe2d8b2d2d13482a">app_loop</a> (void)</td></tr>
<tr class="memdesc:gad1cfce0ef962cd2afe2d8b2d2d13482a"><td class="mdescLeft">&#160;</td><td class="mdescRight">A function you will implement to serve as the app's main run loop. This method will be called repeatedly, or if you enter STANDBY mode, as soon as the device wakes from sleep.  <a href="group__app.html#gad1cfce0ef962cd2afe2d8b2d2d13482a">More...</a><br /></td></tr>
<tr class="separator:gad1cfce0ef962cd2afe2d8b2d2d13482a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaee30a1614f76afc41117f7176fb30165"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__app.html#gaee30a1614f76afc41117f7176fb30165">app_prepare_for_standby</a> (void)</td></tr>
<tr class="memdesc:gaee30a1614f76afc41117f7176fb30165"><td class="mdescLeft">&#160;</td><td class="mdescRight">A function you will implement to prepare to enter STANDBY mode. The app_prepare_for_standby function is called after your app_loop function returns true, and just before the watch enters STANDBY mode. In this mode most peripherals are shut down, and no code will run until the watch receives an interrupt (generally either the 1Hz tick or a press on one of the buttons).  <a href="group__app.html#gaee30a1614f76afc41117f7176fb30165">More...</a><br /></td></tr>
<tr class="separator:gaee30a1614f76afc41117f7176fb30165"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gacc7e7ff6108524545ab4183110811874"><td class="memItemLeft" align="right" valign="top"><a id="gacc7e7ff6108524545ab4183110811874"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__app.html#gacc7e7ff6108524545ab4183110811874">app_wake_from_standby</a> (void)</td></tr>
<tr class="memdesc:gacc7e7ff6108524545ab4183110811874"><td class="mdescLeft">&#160;</td><td class="mdescRight">A method you will implement to configure the app after waking from STANDBY mode. <br /></td></tr>
<tr class="separator:gacc7e7ff6108524545ab4183110811874"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>This section covers the functions that you will implement in your app.c file when designing a Sensor Watch app. </p>
<p>You should be able to write a watch app by simply implementing these functions and declaring callbacks for various GPIO and peripheral interrupts. The main.c file takes care of calling these functions for you. The general flow:</p>
<ol type="1">
<li>Your <a class="el" href="group__app.html#gadd3190cf715f513666f4be42874d91e2" title="A function you will implement to initialize your application state. The app_init function is called b...">app_init()</a> function is called.<ul>
<li>This method should only be used to set your initial application state.</li>
</ul>
</li>
<li>If your app is waking from BACKUP, <a class="el" href="group__app.html#gab6a9f08ba879ce8d28fb19ca2882890a" title="A function you will implement to wake from BACKUP mode, which wipes the system&#39;s RAM,...">app_wake_from_backup()</a> is called.<ul>
<li>If you saved state in the RTC's backup registers, you can restore it here.</li>
</ul>
</li>
<li>Your <a class="el" href="group__app.html#gacce192accedbd296eb8d2182f8101f16" title="A function you will implement to set up your application. The app_setup function is like setup() in A...">app_setup()</a> method is called.<ul>
<li>You may wish to enable some functionality and peripherals here.</li>
<li>You should definitely set up some interrupts here.</li>
</ul>
</li>
<li>The main run loop begins: your <a class="el" href="group__app.html#gad1cfce0ef962cd2afe2d8b2d2d13482a" title="A function you will implement to serve as the app&#39;s main run loop. This method will be called repeate...">app_loop()</a> function is called.<ul>
<li>Run code and update your UI here.</li>
<li>Return true if your app is prepared to enter STANDBY mode.</li>
</ul>
</li>
<li>This step differs depending on the value returned by app_loop:<ul>
<li>If you returned false, execution resumes at (4).</li>
<li>If you returned true, <a class="el" href="group__app.html#gaee30a1614f76afc41117f7176fb30165" title="A function you will implement to prepare to enter STANDBY mode. The app_prepare_for_standby function ...">app_prepare_for_standby()</a> is called; execution moves on to (6).</li>
</ul>
</li>
<li>The microcontroller enters STANDBY mode.<ul>
<li>No user code will run, and the watch will enter a low power mode.</li>
<li>The watch will remain in this state until an interrupt wakes it.</li>
</ul>
</li>
<li>Once woken from STANDBY, your <a class="el" href="group__app.html#gacc7e7ff6108524545ab4183110811874" title="A method you will implement to configure the app after waking from STANDBY mode.">app_wake_from_standby()</a> function is called.<ul>
<li>After this, execution resumes at (4). </li>
</ul>
</li>
</ol>
<h2 class="groupheader">Function Documentation</h2>
<a id="gad1cfce0ef962cd2afe2d8b2d2d13482a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gad1cfce0ef962cd2afe2d8b2d2d13482a">&#9670;&nbsp;</a></span>app_loop()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool app_loop </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>A function you will implement to serve as the app's main run loop. This method will be called repeatedly, or if you enter STANDBY mode, as soon as the device wakes from sleep. </p>
<dl class="section return"><dt>Returns</dt><dd>You should return true if your app is prepared to enter STANDBY mode. If you return false, your app's app_loop method will be called again immediately. Note that in STANDBY mode, the watch will consume only about 95 microamperes of power, whereas if you return false and keep the app awake, it will consume about 355 microamperes. This is the difference between months of battery life and days. As much as possible, you should limit the amount of time your app spends awake. </dd></dl>
<dl class="section note"><dt>Note</dt><dd>Only the RTC, the segment LCD controller and the external interrupt controller run in STANDBY mode. If you are using, e.g. the PWM function to set a custom LED color, you should return false here until you are finished with that operation. Note however that the peripherals will continue running after waking up, so e.g. the I2C controller, if configured, will sleep in STANDBY. But you can use it again as soon as your app wakes up. </dd></dl>

</div>
</div>
<a id="gaee30a1614f76afc41117f7176fb30165"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaee30a1614f76afc41117f7176fb30165">&#9670;&nbsp;</a></span>app_prepare_for_standby()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void app_prepare_for_standby </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>A function you will implement to prepare to enter STANDBY mode. The app_prepare_for_standby function is called after your app_loop function returns true, and just before the watch enters STANDBY mode. In this mode most peripherals are shut down, and no code will run until the watch receives an interrupt (generally either the 1Hz tick or a press on one of the buttons). </p>
<dl class="section note"><dt>Note</dt><dd>If you are PWM'ing the LED or playing a sound on the buzzer, the TC/TCC peripherals that drive those operations will not run in STANDBY. BUT! the output pins will retain the state they had when entering standby. This means you could end up entering standby with an LED on and draining power, or with a DC potential across the piezo buzzer that could damage it if left in this state. If your app_loop does not prevent sleep during these activities, you should make sure to disable these outputs in app_prepare_for_standby. </dd></dl>

</div>
</div>
<a id="gacce192accedbd296eb8d2182f8101f16"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gacce192accedbd296eb8d2182f8101f16">&#9670;&nbsp;</a></span>app_setup()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void app_setup </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>A function you will implement to set up your application. The app_setup function is like setup() in Arduino. It is called once when the program begins. You should set pin modes and enable any peripherals you want to set up (real-time clock, I2C, etc.) Depending on your application, you may or may not want to configure sensors on your sensor board here. For example, a low-power accelerometer that will run at all times should be configured here, whereas you may want to enable a more power-hungry sensor only when you need it. </p>
<dl class="section note"><dt>Note</dt><dd>If your app enters the ultra-low power BACKUP sleep mode, this function will be called again when it wakes from that deep sleep state. In this state, the RTC will still be configured with the correct date and time. </dd></dl>

</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1
</small></address>
</body>
</html>