mirror of
https://github.com/taigrr/arduinolibs
synced 2025-01-18 04:33:12 -08:00
Update docs
This commit is contained in:
@@ -2,29 +2,37 @@
|
||||
<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"/>
|
||||
<title>ArduinoLibs: EEPROM24.cpp Source File</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/search.js"></script>
|
||||
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() { searchBox.OnSelectItem(0); });
|
||||
</script>
|
||||
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
<body onload='searchBox.OnSelectItem(0);'>
|
||||
<!-- Generated by Doxygen 1.7.4 -->
|
||||
<script type="text/javascript"><!--
|
||||
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
--></script>
|
||||
<div id="top">
|
||||
<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 style="padding-left: 0.5em;">
|
||||
<div id="projectname">ArduinoLibs</div>
|
||||
<div id="projectname">ArduinoLibs
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- end header part -->
|
||||
<!-- Generated by Doxygen 1.8.1.2 -->
|
||||
<script type="text/javascript">
|
||||
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
</script>
|
||||
<div id="navrow1" class="tabs">
|
||||
<ul class="tablist">
|
||||
<li><a href="index.html"><span>Main Page</span></a></li>
|
||||
@@ -32,7 +40,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
<li><a href="modules.html"><span>Modules</span></a></li>
|
||||
<li><a href="annotated.html"><span>Classes</span></a></li>
|
||||
<li class="current"><a href="files.html"><span>Files</span></a></li>
|
||||
<li id="searchli">
|
||||
<li>
|
||||
<div id="MSearchBox" class="MSearchBoxInactive">
|
||||
<span class="left">
|
||||
<img id="MSearchSelect" src="search/mag_sel.png"
|
||||
@@ -55,198 +63,12 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
<li><a href="files.html"><span>File List</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="header">
|
||||
<div class="headertitle">
|
||||
<div class="title">EEPROM24.cpp</div> </div>
|
||||
</div>
|
||||
<div class="contents">
|
||||
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
|
||||
<a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2012 Southern Storm Software, Pty Ltd.</span>
|
||||
<a name="l00003"></a>00003 <span class="comment"> *</span>
|
||||
<a name="l00004"></a>00004 <span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</span>
|
||||
<a name="l00005"></a>00005 <span class="comment"> * copy of this software and associated documentation files (the "Software"),</span>
|
||||
<a name="l00006"></a>00006 <span class="comment"> * to deal in the Software without restriction, including without limitation</span>
|
||||
<a name="l00007"></a>00007 <span class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</span>
|
||||
<a name="l00008"></a>00008 <span class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</span>
|
||||
<a name="l00009"></a>00009 <span class="comment"> * Software is furnished to do so, subject to the following conditions:</span>
|
||||
<a name="l00010"></a>00010 <span class="comment"> *</span>
|
||||
<a name="l00011"></a>00011 <span class="comment"> * The above copyright notice and this permission notice shall be included</span>
|
||||
<a name="l00012"></a>00012 <span class="comment"> * in all copies or substantial portions of the Software.</span>
|
||||
<a name="l00013"></a>00013 <span class="comment"> *</span>
|
||||
<a name="l00014"></a>00014 <span class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS</span>
|
||||
<a name="l00015"></a>00015 <span class="comment"> * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
|
||||
<a name="l00016"></a>00016 <span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
|
||||
<a name="l00017"></a>00017 <span class="comment"> * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
|
||||
<a name="l00018"></a>00018 <span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</span>
|
||||
<a name="l00019"></a>00019 <span class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</span>
|
||||
<a name="l00020"></a>00020 <span class="comment"> * DEALINGS IN THE SOFTWARE.</span>
|
||||
<a name="l00021"></a>00021 <span class="comment"> */</span>
|
||||
<a name="l00022"></a>00022
|
||||
<a name="l00023"></a>00023 <span class="preprocessor">#include "EEPROM24.h"</span>
|
||||
<a name="l00024"></a>00024 <span class="preprocessor">#include "I2CMaster.h"</span>
|
||||
<a name="l00025"></a>00025
|
||||
<a name="l00095"></a><a class="code" href="classEEPROM24.html#ae8547f6ff7711496e1959ee24a142995">00095</a> <a class="code" href="classEEPROM24.html#ae8547f6ff7711496e1959ee24a142995" title="Constructs a new EEPROM access object on bus for an EEPROM of the specified type.">EEPROM24::EEPROM24</a>(<a class="code" href="classI2CMaster.html" title="Abstract base class for I2C master implementations.">I2CMaster</a> &bus, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> type, uint8_t bank)
|
||||
<a name="l00096"></a>00096 : _bus(&bus)
|
||||
<a name="l00097"></a>00097 , _size((type & 0xFFFF) * ((type >> 16) & 0x0FFF))
|
||||
<a name="l00098"></a>00098 , _pageSize((type >> 16) & 0x0FFF)
|
||||
<a name="l00099"></a>00099 , _mode((uint8_t)((type >> 28) & 0x0F))
|
||||
<a name="l00100"></a>00100 , i2cAddress(0x50)
|
||||
<a name="l00101"></a>00101 {
|
||||
<a name="l00102"></a>00102 <span class="comment">// Adjust the I2C address for the memory bank of the chip.</span>
|
||||
<a name="l00103"></a>00103 <span class="keywordflow">switch</span> (_mode) {
|
||||
<a name="l00104"></a>00104 <span class="keywordflow">case</span> EE_BSEL_NONE:
|
||||
<a name="l00105"></a>00105 i2cAddress += (bank & 0x07);
|
||||
<a name="l00106"></a>00106 <span class="keywordflow">break</span>;
|
||||
<a name="l00107"></a>00107 <span class="keywordflow">case</span> EE_BSEL_8BIT_ADDR: {
|
||||
<a name="l00108"></a>00108 uint8_t addrBits = 8;
|
||||
<a name="l00109"></a>00109 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <a class="code" href="classEEPROM24.html#aa544875cef9bd05bf71d6c19be06cf7c" title="Returns the size of the EEPROM in bytes.">size</a> = 0x0100;
|
||||
<a name="l00110"></a>00110 <span class="keywordflow">while</span> (size < _size) {
|
||||
<a name="l00111"></a>00111 ++addrBits;
|
||||
<a name="l00112"></a>00112 size <<= 1;
|
||||
<a name="l00113"></a>00113 }
|
||||
<a name="l00114"></a>00114 <span class="keywordflow">if</span> (addrBits < 11)
|
||||
<a name="l00115"></a>00115 i2cAddress += ((bank << (addrBits - 8)) & 0x07);
|
||||
<a name="l00116"></a>00116 <span class="keywordflow">break</span>; }
|
||||
<a name="l00117"></a>00117 <span class="keywordflow">case</span> EE_BSEL_17BIT_ADDR:
|
||||
<a name="l00118"></a>00118 i2cAddress += ((bank << 1) & 0x06);
|
||||
<a name="l00119"></a>00119 <span class="keywordflow">break</span>;
|
||||
<a name="l00120"></a>00120 <span class="keywordflow">case</span> EE_BSEL_17BIT_ADDR_ALT:
|
||||
<a name="l00121"></a>00121 i2cAddress += bank & 0x03;
|
||||
<a name="l00122"></a>00122 <span class="keywordflow">break</span>;
|
||||
<a name="l00123"></a>00123 }
|
||||
<a name="l00124"></a>00124 }
|
||||
<a name="l00125"></a>00125
|
||||
<a name="l00152"></a><a class="code" href="classEEPROM24.html#af8b70971d882b06de3fc6644a8ece3cf">00152</a> <span class="keywordtype">bool</span> <a class="code" href="classEEPROM24.html#af8b70971d882b06de3fc6644a8ece3cf" title="Returns true if the EEPROM is available on the I2C bus; false otherwise.">EEPROM24::available</a>()
|
||||
<a name="l00153"></a>00153 {
|
||||
<a name="l00154"></a>00154 <span class="comment">// Perform a "Current Address Read" on the EEPROM. We don't care about</span>
|
||||
<a name="l00155"></a>00155 <span class="comment">// the returned byte. We only care if the read request was ACK'ed or not.</span>
|
||||
<a name="l00156"></a>00156 <span class="keywordflow">if</span> (!_bus-><a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(i2cAddress, 1))
|
||||
<a name="l00157"></a>00157 <span class="keywordflow">return</span> <span class="keyword">false</span>;
|
||||
<a name="l00158"></a>00158 _bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>();
|
||||
<a name="l00159"></a>00159 <span class="keywordflow">return</span> <span class="keyword">true</span>;
|
||||
<a name="l00160"></a>00160 }
|
||||
<a name="l00161"></a>00161
|
||||
<a name="l00167"></a><a class="code" href="classEEPROM24.html#a960971377d4decb122ff38d12603e586">00167</a> uint8_t <a class="code" href="classEEPROM24.html#a960971377d4decb122ff38d12603e586" title="Reads a single byte from the EEPROM at address.">EEPROM24::read</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> address)
|
||||
<a name="l00168"></a>00168 {
|
||||
<a name="l00169"></a>00169 <span class="keywordflow">if</span> (address >= _size)
|
||||
<a name="l00170"></a>00170 <span class="keywordflow">return</span> 0;
|
||||
<a name="l00171"></a>00171 writeAddress(address);
|
||||
<a name="l00172"></a>00172 <span class="keywordflow">if</span> (!_bus-><a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(i2cAddress, 1))
|
||||
<a name="l00173"></a>00173 <span class="keywordflow">return</span> 0;
|
||||
<a name="l00174"></a>00174 <span class="keywordflow">return</span> _bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>();
|
||||
<a name="l00175"></a>00175 }
|
||||
<a name="l00176"></a>00176
|
||||
<a name="l00187"></a><a class="code" href="classEEPROM24.html#a63e23dc014415f947975359ac09f627e">00187</a> <span class="keywordtype">size_t</span> <a class="code" href="classEEPROM24.html#a960971377d4decb122ff38d12603e586" title="Reads a single byte from the EEPROM at address.">EEPROM24::read</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> address, <span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> length)
|
||||
<a name="l00188"></a>00188 {
|
||||
<a name="l00189"></a>00189 <span class="keywordflow">if</span> (address >= _size || !length)
|
||||
<a name="l00190"></a>00190 <span class="keywordflow">return</span> 0;
|
||||
<a name="l00191"></a>00191 <span class="keywordflow">if</span> ((address + length) > _size)
|
||||
<a name="l00192"></a>00192 length = (size_t)(_size - address);
|
||||
<a name="l00193"></a>00193 writeAddress(address);
|
||||
<a name="l00194"></a>00194 <span class="keywordflow">if</span> (!_bus-><a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(i2cAddress, length))
|
||||
<a name="l00195"></a>00195 <span class="keywordflow">return</span> 0;
|
||||
<a name="l00196"></a>00196 uint8_t *d = (uint8_t *)data;
|
||||
<a name="l00197"></a>00197 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> count = 0;
|
||||
<a name="l00198"></a>00198 <span class="keywordflow">while</span> (_bus-><a class="code" href="classI2CMaster.html#a6458fa99cfd9e6270ae6dff993955833" title="Returns the number of bytes that are still available for reading.">available</a>()) {
|
||||
<a name="l00199"></a>00199 *d++ = _bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>();
|
||||
<a name="l00200"></a>00200 ++count;
|
||||
<a name="l00201"></a>00201 }
|
||||
<a name="l00202"></a>00202 <span class="keywordflow">return</span> count;
|
||||
<a name="l00203"></a>00203 }
|
||||
<a name="l00204"></a>00204
|
||||
<a name="l00213"></a><a class="code" href="classEEPROM24.html#a9e017772e3459ee4ab987e27d78937f8">00213</a> <span class="keywordtype">bool</span> <a class="code" href="classEEPROM24.html#a9e017772e3459ee4ab987e27d78937f8" title="Writes a byte value to address in the EEPROM.">EEPROM24::write</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> address, uint8_t value)
|
||||
<a name="l00214"></a>00214 {
|
||||
<a name="l00215"></a>00215 <span class="keywordflow">if</span> (address >= _size)
|
||||
<a name="l00216"></a>00216 <span class="keywordflow">return</span> <span class="keyword">false</span>;
|
||||
<a name="l00217"></a>00217 writeAddress(address);
|
||||
<a name="l00218"></a>00218 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(value);
|
||||
<a name="l00219"></a>00219 <span class="keywordflow">return</span> waitForWrite();
|
||||
<a name="l00220"></a>00220 }
|
||||
<a name="l00221"></a>00221
|
||||
<a name="l00235"></a><a class="code" href="classEEPROM24.html#a3d918ed34da7ca6d21a776c0614eebf3">00235</a> <span class="keywordtype">size_t</span> <a class="code" href="classEEPROM24.html#a9e017772e3459ee4ab987e27d78937f8" title="Writes a byte value to address in the EEPROM.">EEPROM24::write</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> address, <span class="keyword">const</span> <span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> length)
|
||||
<a name="l00236"></a>00236 {
|
||||
<a name="l00237"></a>00237 <span class="keywordflow">if</span> (address >= _size)
|
||||
<a name="l00238"></a>00238 <span class="keywordflow">return</span> 0;
|
||||
<a name="l00239"></a>00239 <span class="keywordflow">if</span> ((address + length) > _size)
|
||||
<a name="l00240"></a>00240 length = (size_t)(_size - address);
|
||||
<a name="l00241"></a>00241 <span class="keywordtype">bool</span> needAddress = <span class="keyword">true</span>;
|
||||
<a name="l00242"></a>00242 <span class="keywordtype">size_t</span> result = 0;
|
||||
<a name="l00243"></a>00243 <span class="keywordtype">size_t</span> page = 0;
|
||||
<a name="l00244"></a>00244 <span class="keyword">const</span> uint8_t *d = (<span class="keyword">const</span> uint8_t *)data;
|
||||
<a name="l00245"></a>00245 <span class="keywordflow">while</span> (length > 0) {
|
||||
<a name="l00246"></a>00246 <span class="keywordflow">if</span> (needAddress) {
|
||||
<a name="l00247"></a>00247 writeAddress(address);
|
||||
<a name="l00248"></a>00248 needAddress = <span class="keyword">false</span>;
|
||||
<a name="l00249"></a>00249 }
|
||||
<a name="l00250"></a>00250 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(*d++);
|
||||
<a name="l00251"></a>00251 ++address;
|
||||
<a name="l00252"></a>00252 ++page;
|
||||
<a name="l00253"></a>00253 <span class="keywordflow">if</span> ((address & (_pageSize - 1)) == 0) {
|
||||
<a name="l00254"></a>00254 <span class="comment">// At the end of a page, so perform a flush.</span>
|
||||
<a name="l00255"></a>00255 <span class="keywordflow">if</span> (!waitForWrite())
|
||||
<a name="l00256"></a>00256 <span class="keywordflow">return</span> result; <span class="comment">// Could not write this page.</span>
|
||||
<a name="l00257"></a>00257 needAddress = <span class="keyword">true</span>;
|
||||
<a name="l00258"></a>00258 result += page;
|
||||
<a name="l00259"></a>00259 page = 0;
|
||||
<a name="l00260"></a>00260 }
|
||||
<a name="l00261"></a>00261 --length;
|
||||
<a name="l00262"></a>00262 }
|
||||
<a name="l00263"></a>00263 <span class="keywordflow">if</span> (!needAddress) {
|
||||
<a name="l00264"></a>00264 <span class="keywordflow">if</span> (!waitForWrite())
|
||||
<a name="l00265"></a>00265 <span class="keywordflow">return</span> result; <span class="comment">// Could not write the final page.</span>
|
||||
<a name="l00266"></a>00266 }
|
||||
<a name="l00267"></a>00267 <span class="keywordflow">return</span> result + page;
|
||||
<a name="l00268"></a>00268 }
|
||||
<a name="l00269"></a>00269
|
||||
<a name="l00270"></a>00270 <span class="keywordtype">void</span> EEPROM24::writeAddress(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> address)
|
||||
<a name="l00271"></a>00271 {
|
||||
<a name="l00272"></a>00272 <span class="keywordflow">switch</span> (_mode) {
|
||||
<a name="l00273"></a>00273 <span class="keywordflow">case</span> EE_BSEL_NONE:
|
||||
<a name="l00274"></a>00274 _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(i2cAddress);
|
||||
<a name="l00275"></a>00275 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>((uint8_t)(address >> 8));
|
||||
<a name="l00276"></a>00276 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>((uint8_t)address);
|
||||
<a name="l00277"></a>00277 <span class="keywordflow">break</span>;
|
||||
<a name="l00278"></a>00278 <span class="keywordflow">case</span> EE_BSEL_8BIT_ADDR:
|
||||
<a name="l00279"></a>00279 _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(i2cAddress | (((uint8_t)(address >> 8)) & 0x07));
|
||||
<a name="l00280"></a>00280 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>((uint8_t)address);
|
||||
<a name="l00281"></a>00281 <span class="keywordflow">break</span>;
|
||||
<a name="l00282"></a>00282 <span class="keywordflow">case</span> EE_BSEL_17BIT_ADDR:
|
||||
<a name="l00283"></a>00283 _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(i2cAddress | (((uint8_t)(address >> 16)) & 0x01));
|
||||
<a name="l00284"></a>00284 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>((uint8_t)(address >> 8));
|
||||
<a name="l00285"></a>00285 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>((uint8_t)address);
|
||||
<a name="l00286"></a>00286 <span class="keywordflow">break</span>;
|
||||
<a name="l00287"></a>00287 <span class="keywordflow">case</span> EE_BSEL_17BIT_ADDR_ALT:
|
||||
<a name="l00288"></a>00288 _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(i2cAddress | (((uint8_t)(address >> 14)) & 0x04));
|
||||
<a name="l00289"></a>00289 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>((uint8_t)(address >> 8));
|
||||
<a name="l00290"></a>00290 _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>((uint8_t)address);
|
||||
<a name="l00291"></a>00291 <span class="keywordflow">break</span>;
|
||||
<a name="l00292"></a>00292 }
|
||||
<a name="l00293"></a>00293 }
|
||||
<a name="l00294"></a>00294
|
||||
<a name="l00295"></a>00295 <span class="keywordtype">bool</span> EEPROM24::waitForWrite()
|
||||
<a name="l00296"></a>00296 {
|
||||
<a name="l00297"></a>00297 <span class="comment">// 1000 iterations is going to be approximately 100ms when the I2C</span>
|
||||
<a name="l00298"></a>00298 <span class="comment">// clock is 100 kHz. If there has been no response in that time</span>
|
||||
<a name="l00299"></a>00299 <span class="comment">// then we assume that the write has failed and timeout.</span>
|
||||
<a name="l00300"></a>00300 <span class="keywordflow">if</span> (!_bus-><a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>())
|
||||
<a name="l00301"></a>00301 <span class="keywordflow">return</span> <span class="keyword">false</span>;
|
||||
<a name="l00302"></a>00302 <span class="keywordtype">unsigned</span> count = 1000;
|
||||
<a name="l00303"></a>00303 <span class="keywordflow">while</span> (count > 0) {
|
||||
<a name="l00304"></a>00304 _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(i2cAddress);
|
||||
<a name="l00305"></a>00305 <span class="keywordflow">if</span> (_bus-><a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>())
|
||||
<a name="l00306"></a>00306 <span class="keywordflow">return</span> <span class="keyword">true</span>;
|
||||
<a name="l00307"></a>00307 --count;
|
||||
<a name="l00308"></a>00308 }
|
||||
<a name="l00309"></a>00309 <span class="keywordflow">return</span> <span class="keyword">false</span>;
|
||||
<a name="l00310"></a>00310 }
|
||||
</pre></div></div>
|
||||
</div>
|
||||
<!-- window showing the filter options -->
|
||||
<div id="MSearchSelectWindow"
|
||||
onmouseover="return searchBox.OnSearchSelectShow()"
|
||||
onmouseout="return searchBox.OnSearchSelectHide()"
|
||||
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
||||
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerator</a></div>
|
||||
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark"> </span>Pages</a></div>
|
||||
|
||||
<!-- iframe showing the search results (closed by default) -->
|
||||
<div id="MSearchResultsWindow">
|
||||
@@ -255,8 +77,201 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
</iframe>
|
||||
</div>
|
||||
|
||||
<hr class="footer"/><address class="footer"><small>Generated on Mon Jun 18 2012 11:02:51 for ArduinoLibs by 
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
||||
<div id="nav-path" class="navpath">
|
||||
<ul>
|
||||
<li class="navelem"><a class="el" href="dir_bc0718b08fb2015b8e59c47b2805f60c.html">libraries</a></li><li class="navelem"><a class="el" href="dir_f9b96888882c2691b8eeaeafd1b9501d.html">I2C</a></li> </ul>
|
||||
</div>
|
||||
</div><!-- top -->
|
||||
<div class="header">
|
||||
<div class="headertitle">
|
||||
<div class="title">EEPROM24.cpp</div> </div>
|
||||
</div><!--header-->
|
||||
<div class="contents">
|
||||
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="comment">/*</span></div>
|
||||
<div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="comment"> * Copyright (C) 2012 Southern Storm Software, Pty Ltd.</span></div>
|
||||
<div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment"> *</span></div>
|
||||
<div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</span></div>
|
||||
<div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="comment"> * copy of this software and associated documentation files (the "Software"),</span></div>
|
||||
<div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="comment"> * to deal in the Software without restriction, including without limitation</span></div>
|
||||
<div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</span></div>
|
||||
<div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</span></div>
|
||||
<div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="comment"> * Software is furnished to do so, subject to the following conditions:</span></div>
|
||||
<div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="comment"> *</span></div>
|
||||
<div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="comment"> * The above copyright notice and this permission notice shall be included</span></div>
|
||||
<div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment"> * in all copies or substantial portions of the Software.</span></div>
|
||||
<div class="line"><a name="l00013"></a><span class="lineno"> 13</span> <span class="comment"> *</span></div>
|
||||
<div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS</span></div>
|
||||
<div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="comment"> * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span></div>
|
||||
<div class="line"><a name="l00016"></a><span class="lineno"> 16</span> <span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span></div>
|
||||
<div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="comment"> * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span></div>
|
||||
<div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</span></div>
|
||||
<div class="line"><a name="l00019"></a><span class="lineno"> 19</span> <span class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</span></div>
|
||||
<div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="comment"> * DEALINGS IN THE SOFTWARE.</span></div>
|
||||
<div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="comment"> */</span></div>
|
||||
<div class="line"><a name="l00022"></a><span class="lineno"> 22</span> </div>
|
||||
<div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="preprocessor">#include "EEPROM24.h"</span></div>
|
||||
<div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="preprocessor">#include "I2CMaster.h"</span></div>
|
||||
<div class="line"><a name="l00025"></a><span class="lineno"> 25</span> </div>
|
||||
<div class="line"><a name="l00095"></a><span class="lineno"><a class="code" href="classEEPROM24.html#ae8547f6ff7711496e1959ee24a142995"> 95</a></span> <a class="code" href="classEEPROM24.html#ae8547f6ff7711496e1959ee24a142995" title="Constructs a new EEPROM access object on bus for an EEPROM of the specified type.">EEPROM24::EEPROM24</a>(<a class="code" href="classI2CMaster.html" title="Abstract base class for I2C master implementations.">I2CMaster</a> &bus, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> type, uint8_t bank)</div>
|
||||
<div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  : _bus(&bus)</div>
|
||||
<div class="line"><a name="l00097"></a><span class="lineno"> 97</span>  , _size((type & 0xFFFF) * ((type >> 16) & 0x0FFF))</div>
|
||||
<div class="line"><a name="l00098"></a><span class="lineno"> 98</span>  , _pageSize((type >> 16) & 0x0FFF)</div>
|
||||
<div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  , _mode((uint8_t)((type >> 28) & 0x0F))</div>
|
||||
<div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  , i2cAddress(0x50)</div>
|
||||
<div class="line"><a name="l00101"></a><span class="lineno"> 101</span> {</div>
|
||||
<div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  <span class="comment">// Adjust the I2C address for the memory bank of the chip.</span></div>
|
||||
<div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  <span class="keywordflow">switch</span> (_mode) {</div>
|
||||
<div class="line"><a name="l00104"></a><span class="lineno"> 104</span>  <span class="keywordflow">case</span> EE_BSEL_NONE:</div>
|
||||
<div class="line"><a name="l00105"></a><span class="lineno"> 105</span>  i2cAddress += (bank & 0x07);</div>
|
||||
<div class="line"><a name="l00106"></a><span class="lineno"> 106</span>  <span class="keywordflow">break</span>;</div>
|
||||
<div class="line"><a name="l00107"></a><span class="lineno"> 107</span>  <span class="keywordflow">case</span> EE_BSEL_8BIT_ADDR: {</div>
|
||||
<div class="line"><a name="l00108"></a><span class="lineno"> 108</span>  uint8_t addrBits = 8;</div>
|
||||
<div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <a class="code" href="classEEPROM24.html#aa544875cef9bd05bf71d6c19be06cf7c" title="Returns the size of the EEPROM in bytes.">size</a> = 0x0100;</div>
|
||||
<div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  <span class="keywordflow">while</span> (size < _size) {</div>
|
||||
<div class="line"><a name="l00111"></a><span class="lineno"> 111</span>  ++addrBits;</div>
|
||||
<div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  size <<= 1;</div>
|
||||
<div class="line"><a name="l00113"></a><span class="lineno"> 113</span>  }</div>
|
||||
<div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  <span class="keywordflow">if</span> (addrBits < 11)</div>
|
||||
<div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  i2cAddress += ((bank << (addrBits - 8)) & 0x07);</div>
|
||||
<div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  <span class="keywordflow">break</span>; }</div>
|
||||
<div class="line"><a name="l00117"></a><span class="lineno"> 117</span>  <span class="keywordflow">case</span> EE_BSEL_17BIT_ADDR:</div>
|
||||
<div class="line"><a name="l00118"></a><span class="lineno"> 118</span>  i2cAddress += ((bank << 1) & 0x06);</div>
|
||||
<div class="line"><a name="l00119"></a><span class="lineno"> 119</span>  <span class="keywordflow">break</span>;</div>
|
||||
<div class="line"><a name="l00120"></a><span class="lineno"> 120</span>  <span class="keywordflow">case</span> EE_BSEL_17BIT_ADDR_ALT:</div>
|
||||
<div class="line"><a name="l00121"></a><span class="lineno"> 121</span>  i2cAddress += bank & 0x03;</div>
|
||||
<div class="line"><a name="l00122"></a><span class="lineno"> 122</span>  <span class="keywordflow">break</span>;</div>
|
||||
<div class="line"><a name="l00123"></a><span class="lineno"> 123</span>  }</div>
|
||||
<div class="line"><a name="l00124"></a><span class="lineno"> 124</span> }</div>
|
||||
<div class="line"><a name="l00125"></a><span class="lineno"> 125</span> </div>
|
||||
<div class="line"><a name="l00152"></a><span class="lineno"><a class="code" href="classEEPROM24.html#af8b70971d882b06de3fc6644a8ece3cf"> 152</a></span> <span class="keywordtype">bool</span> <a class="code" href="classEEPROM24.html#af8b70971d882b06de3fc6644a8ece3cf" title="Returns true if the EEPROM is available on the I2C bus; false otherwise.">EEPROM24::available</a>()</div>
|
||||
<div class="line"><a name="l00153"></a><span class="lineno"> 153</span> {</div>
|
||||
<div class="line"><a name="l00154"></a><span class="lineno"> 154</span>  <span class="comment">// Perform a "Current Address Read" on the EEPROM. We don't care about</span></div>
|
||||
<div class="line"><a name="l00155"></a><span class="lineno"> 155</span>  <span class="comment">// the returned byte. We only care if the read request was ACK'ed or not.</span></div>
|
||||
<div class="line"><a name="l00156"></a><span class="lineno"> 156</span>  <span class="keywordflow">if</span> (!_bus-><a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(i2cAddress, 1))</div>
|
||||
<div class="line"><a name="l00157"></a><span class="lineno"> 157</span>  <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
|
||||
<div class="line"><a name="l00158"></a><span class="lineno"> 158</span>  _bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>();</div>
|
||||
<div class="line"><a name="l00159"></a><span class="lineno"> 159</span>  <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
|
||||
<div class="line"><a name="l00160"></a><span class="lineno"> 160</span> }</div>
|
||||
<div class="line"><a name="l00161"></a><span class="lineno"> 161</span> </div>
|
||||
<div class="line"><a name="l00167"></a><span class="lineno"><a class="code" href="classEEPROM24.html#a960971377d4decb122ff38d12603e586"> 167</a></span> uint8_t <a class="code" href="classEEPROM24.html#a960971377d4decb122ff38d12603e586" title="Reads a single byte from the EEPROM at address.">EEPROM24::read</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> address)</div>
|
||||
<div class="line"><a name="l00168"></a><span class="lineno"> 168</span> {</div>
|
||||
<div class="line"><a name="l00169"></a><span class="lineno"> 169</span>  <span class="keywordflow">if</span> (address >= _size)</div>
|
||||
<div class="line"><a name="l00170"></a><span class="lineno"> 170</span>  <span class="keywordflow">return</span> 0;</div>
|
||||
<div class="line"><a name="l00171"></a><span class="lineno"> 171</span>  writeAddress(address);</div>
|
||||
<div class="line"><a name="l00172"></a><span class="lineno"> 172</span>  <span class="keywordflow">if</span> (!_bus-><a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(i2cAddress, 1))</div>
|
||||
<div class="line"><a name="l00173"></a><span class="lineno"> 173</span>  <span class="keywordflow">return</span> 0;</div>
|
||||
<div class="line"><a name="l00174"></a><span class="lineno"> 174</span>  <span class="keywordflow">return</span> _bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>();</div>
|
||||
<div class="line"><a name="l00175"></a><span class="lineno"> 175</span> }</div>
|
||||
<div class="line"><a name="l00176"></a><span class="lineno"> 176</span> </div>
|
||||
<div class="line"><a name="l00187"></a><span class="lineno"><a class="code" href="classEEPROM24.html#a63e23dc014415f947975359ac09f627e"> 187</a></span> <span class="keywordtype">size_t</span> <a class="code" href="classEEPROM24.html#a960971377d4decb122ff38d12603e586" title="Reads a single byte from the EEPROM at address.">EEPROM24::read</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> address, <span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> length)</div>
|
||||
<div class="line"><a name="l00188"></a><span class="lineno"> 188</span> {</div>
|
||||
<div class="line"><a name="l00189"></a><span class="lineno"> 189</span>  <span class="keywordflow">if</span> (address >= _size || !length)</div>
|
||||
<div class="line"><a name="l00190"></a><span class="lineno"> 190</span>  <span class="keywordflow">return</span> 0;</div>
|
||||
<div class="line"><a name="l00191"></a><span class="lineno"> 191</span>  <span class="keywordflow">if</span> ((address + length) > _size)</div>
|
||||
<div class="line"><a name="l00192"></a><span class="lineno"> 192</span>  length = (size_t)(_size - address);</div>
|
||||
<div class="line"><a name="l00193"></a><span class="lineno"> 193</span>  writeAddress(address);</div>
|
||||
<div class="line"><a name="l00194"></a><span class="lineno"> 194</span>  <span class="keywordflow">if</span> (!_bus-><a class="code" href="classI2CMaster.html#a4e5f1a1a4c2242699be5a35fc4872fde" title="Starts a read operation for count bytes by sending the start condition and the I2C control byte...">startRead</a>(i2cAddress, length))</div>
|
||||
<div class="line"><a name="l00195"></a><span class="lineno"> 195</span>  <span class="keywordflow">return</span> 0;</div>
|
||||
<div class="line"><a name="l00196"></a><span class="lineno"> 196</span>  uint8_t *d = (uint8_t *)data;</div>
|
||||
<div class="line"><a name="l00197"></a><span class="lineno"> 197</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> count = 0;</div>
|
||||
<div class="line"><a name="l00198"></a><span class="lineno"> 198</span>  <span class="keywordflow">while</span> (_bus-><a class="code" href="classI2CMaster.html#a6458fa99cfd9e6270ae6dff993955833" title="Returns the number of bytes that are still available for reading.">available</a>()) {</div>
|
||||
<div class="line"><a name="l00199"></a><span class="lineno"> 199</span>  *d++ = _bus-><a class="code" href="classI2CMaster.html#a49eeebb57f6bc06de39973fe836369cd" title="Reads a single byte from the I2C bus.">read</a>();</div>
|
||||
<div class="line"><a name="l00200"></a><span class="lineno"> 200</span>  ++count;</div>
|
||||
<div class="line"><a name="l00201"></a><span class="lineno"> 201</span>  }</div>
|
||||
<div class="line"><a name="l00202"></a><span class="lineno"> 202</span>  <span class="keywordflow">return</span> count;</div>
|
||||
<div class="line"><a name="l00203"></a><span class="lineno"> 203</span> }</div>
|
||||
<div class="line"><a name="l00204"></a><span class="lineno"> 204</span> </div>
|
||||
<div class="line"><a name="l00213"></a><span class="lineno"><a class="code" href="classEEPROM24.html#a9e017772e3459ee4ab987e27d78937f8"> 213</a></span> <span class="keywordtype">bool</span> <a class="code" href="classEEPROM24.html#a9e017772e3459ee4ab987e27d78937f8" title="Writes a byte value to address in the EEPROM.">EEPROM24::write</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> address, uint8_t value)</div>
|
||||
<div class="line"><a name="l00214"></a><span class="lineno"> 214</span> {</div>
|
||||
<div class="line"><a name="l00215"></a><span class="lineno"> 215</span>  <span class="keywordflow">if</span> (address >= _size)</div>
|
||||
<div class="line"><a name="l00216"></a><span class="lineno"> 216</span>  <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
|
||||
<div class="line"><a name="l00217"></a><span class="lineno"> 217</span>  writeAddress(address);</div>
|
||||
<div class="line"><a name="l00218"></a><span class="lineno"> 218</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(value);</div>
|
||||
<div class="line"><a name="l00219"></a><span class="lineno"> 219</span>  <span class="keywordflow">return</span> waitForWrite();</div>
|
||||
<div class="line"><a name="l00220"></a><span class="lineno"> 220</span> }</div>
|
||||
<div class="line"><a name="l00221"></a><span class="lineno"> 221</span> </div>
|
||||
<div class="line"><a name="l00235"></a><span class="lineno"><a class="code" href="classEEPROM24.html#a3d918ed34da7ca6d21a776c0614eebf3"> 235</a></span> <span class="keywordtype">size_t</span> <a class="code" href="classEEPROM24.html#a9e017772e3459ee4ab987e27d78937f8" title="Writes a byte value to address in the EEPROM.">EEPROM24::write</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> address, <span class="keyword">const</span> <span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> length)</div>
|
||||
<div class="line"><a name="l00236"></a><span class="lineno"> 236</span> {</div>
|
||||
<div class="line"><a name="l00237"></a><span class="lineno"> 237</span>  <span class="keywordflow">if</span> (address >= _size)</div>
|
||||
<div class="line"><a name="l00238"></a><span class="lineno"> 238</span>  <span class="keywordflow">return</span> 0;</div>
|
||||
<div class="line"><a name="l00239"></a><span class="lineno"> 239</span>  <span class="keywordflow">if</span> ((address + length) > _size)</div>
|
||||
<div class="line"><a name="l00240"></a><span class="lineno"> 240</span>  length = (size_t)(_size - address);</div>
|
||||
<div class="line"><a name="l00241"></a><span class="lineno"> 241</span>  <span class="keywordtype">bool</span> needAddress = <span class="keyword">true</span>;</div>
|
||||
<div class="line"><a name="l00242"></a><span class="lineno"> 242</span>  <span class="keywordtype">size_t</span> result = 0;</div>
|
||||
<div class="line"><a name="l00243"></a><span class="lineno"> 243</span>  <span class="keywordtype">size_t</span> page = 0;</div>
|
||||
<div class="line"><a name="l00244"></a><span class="lineno"> 244</span>  <span class="keyword">const</span> uint8_t *d = (<span class="keyword">const</span> uint8_t *)data;</div>
|
||||
<div class="line"><a name="l00245"></a><span class="lineno"> 245</span>  <span class="keywordflow">while</span> (length > 0) {</div>
|
||||
<div class="line"><a name="l00246"></a><span class="lineno"> 246</span>  <span class="keywordflow">if</span> (needAddress) {</div>
|
||||
<div class="line"><a name="l00247"></a><span class="lineno"> 247</span>  writeAddress(address);</div>
|
||||
<div class="line"><a name="l00248"></a><span class="lineno"> 248</span>  needAddress = <span class="keyword">false</span>;</div>
|
||||
<div class="line"><a name="l00249"></a><span class="lineno"> 249</span>  }</div>
|
||||
<div class="line"><a name="l00250"></a><span class="lineno"> 250</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>(*d++);</div>
|
||||
<div class="line"><a name="l00251"></a><span class="lineno"> 251</span>  ++address;</div>
|
||||
<div class="line"><a name="l00252"></a><span class="lineno"> 252</span>  ++page;</div>
|
||||
<div class="line"><a name="l00253"></a><span class="lineno"> 253</span>  <span class="keywordflow">if</span> ((address & (_pageSize - 1)) == 0) {</div>
|
||||
<div class="line"><a name="l00254"></a><span class="lineno"> 254</span>  <span class="comment">// At the end of a page, so perform a flush.</span></div>
|
||||
<div class="line"><a name="l00255"></a><span class="lineno"> 255</span>  <span class="keywordflow">if</span> (!waitForWrite())</div>
|
||||
<div class="line"><a name="l00256"></a><span class="lineno"> 256</span>  <span class="keywordflow">return</span> result; <span class="comment">// Could not write this page.</span></div>
|
||||
<div class="line"><a name="l00257"></a><span class="lineno"> 257</span>  needAddress = <span class="keyword">true</span>;</div>
|
||||
<div class="line"><a name="l00258"></a><span class="lineno"> 258</span>  result += page;</div>
|
||||
<div class="line"><a name="l00259"></a><span class="lineno"> 259</span>  page = 0;</div>
|
||||
<div class="line"><a name="l00260"></a><span class="lineno"> 260</span>  }</div>
|
||||
<div class="line"><a name="l00261"></a><span class="lineno"> 261</span>  --length;</div>
|
||||
<div class="line"><a name="l00262"></a><span class="lineno"> 262</span>  }</div>
|
||||
<div class="line"><a name="l00263"></a><span class="lineno"> 263</span>  <span class="keywordflow">if</span> (!needAddress) {</div>
|
||||
<div class="line"><a name="l00264"></a><span class="lineno"> 264</span>  <span class="keywordflow">if</span> (!waitForWrite())</div>
|
||||
<div class="line"><a name="l00265"></a><span class="lineno"> 265</span>  <span class="keywordflow">return</span> result; <span class="comment">// Could not write the final page.</span></div>
|
||||
<div class="line"><a name="l00266"></a><span class="lineno"> 266</span>  }</div>
|
||||
<div class="line"><a name="l00267"></a><span class="lineno"> 267</span>  <span class="keywordflow">return</span> result + page;</div>
|
||||
<div class="line"><a name="l00268"></a><span class="lineno"> 268</span> }</div>
|
||||
<div class="line"><a name="l00269"></a><span class="lineno"> 269</span> </div>
|
||||
<div class="line"><a name="l00270"></a><span class="lineno"> 270</span> <span class="keywordtype">void</span> EEPROM24::writeAddress(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> address)</div>
|
||||
<div class="line"><a name="l00271"></a><span class="lineno"> 271</span> {</div>
|
||||
<div class="line"><a name="l00272"></a><span class="lineno"> 272</span>  <span class="keywordflow">switch</span> (_mode) {</div>
|
||||
<div class="line"><a name="l00273"></a><span class="lineno"> 273</span>  <span class="keywordflow">case</span> EE_BSEL_NONE:</div>
|
||||
<div class="line"><a name="l00274"></a><span class="lineno"> 274</span>  _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(i2cAddress);</div>
|
||||
<div class="line"><a name="l00275"></a><span class="lineno"> 275</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>((uint8_t)(address >> 8));</div>
|
||||
<div class="line"><a name="l00276"></a><span class="lineno"> 276</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>((uint8_t)address);</div>
|
||||
<div class="line"><a name="l00277"></a><span class="lineno"> 277</span>  <span class="keywordflow">break</span>;</div>
|
||||
<div class="line"><a name="l00278"></a><span class="lineno"> 278</span>  <span class="keywordflow">case</span> EE_BSEL_8BIT_ADDR:</div>
|
||||
<div class="line"><a name="l00279"></a><span class="lineno"> 279</span>  _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(i2cAddress | (((uint8_t)(address >> 8)) & 0x07));</div>
|
||||
<div class="line"><a name="l00280"></a><span class="lineno"> 280</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>((uint8_t)address);</div>
|
||||
<div class="line"><a name="l00281"></a><span class="lineno"> 281</span>  <span class="keywordflow">break</span>;</div>
|
||||
<div class="line"><a name="l00282"></a><span class="lineno"> 282</span>  <span class="keywordflow">case</span> EE_BSEL_17BIT_ADDR:</div>
|
||||
<div class="line"><a name="l00283"></a><span class="lineno"> 283</span>  _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(i2cAddress | (((uint8_t)(address >> 16)) & 0x01));</div>
|
||||
<div class="line"><a name="l00284"></a><span class="lineno"> 284</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>((uint8_t)(address >> 8));</div>
|
||||
<div class="line"><a name="l00285"></a><span class="lineno"> 285</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>((uint8_t)address);</div>
|
||||
<div class="line"><a name="l00286"></a><span class="lineno"> 286</span>  <span class="keywordflow">break</span>;</div>
|
||||
<div class="line"><a name="l00287"></a><span class="lineno"> 287</span>  <span class="keywordflow">case</span> EE_BSEL_17BIT_ADDR_ALT:</div>
|
||||
<div class="line"><a name="l00288"></a><span class="lineno"> 288</span>  _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(i2cAddress | (((uint8_t)(address >> 14)) & 0x04));</div>
|
||||
<div class="line"><a name="l00289"></a><span class="lineno"> 289</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>((uint8_t)(address >> 8));</div>
|
||||
<div class="line"><a name="l00290"></a><span class="lineno"> 290</span>  _bus-><a class="code" href="classI2CMaster.html#a0bf6b84cb1e2b3a37a4a0260d0b6f960" title="Writes a single byte value on the I2C bus.">write</a>((uint8_t)address);</div>
|
||||
<div class="line"><a name="l00291"></a><span class="lineno"> 291</span>  <span class="keywordflow">break</span>;</div>
|
||||
<div class="line"><a name="l00292"></a><span class="lineno"> 292</span>  }</div>
|
||||
<div class="line"><a name="l00293"></a><span class="lineno"> 293</span> }</div>
|
||||
<div class="line"><a name="l00294"></a><span class="lineno"> 294</span> </div>
|
||||
<div class="line"><a name="l00295"></a><span class="lineno"> 295</span> <span class="keywordtype">bool</span> EEPROM24::waitForWrite()</div>
|
||||
<div class="line"><a name="l00296"></a><span class="lineno"> 296</span> {</div>
|
||||
<div class="line"><a name="l00297"></a><span class="lineno"> 297</span>  <span class="comment">// 1000 iterations is going to be approximately 100ms when the I2C</span></div>
|
||||
<div class="line"><a name="l00298"></a><span class="lineno"> 298</span>  <span class="comment">// clock is 100 kHz. If there has been no response in that time</span></div>
|
||||
<div class="line"><a name="l00299"></a><span class="lineno"> 299</span>  <span class="comment">// then we assume that the write has failed and timeout.</span></div>
|
||||
<div class="line"><a name="l00300"></a><span class="lineno"> 300</span>  <span class="keywordflow">if</span> (!_bus-><a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>())</div>
|
||||
<div class="line"><a name="l00301"></a><span class="lineno"> 301</span>  <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
|
||||
<div class="line"><a name="l00302"></a><span class="lineno"> 302</span>  <span class="keywordtype">unsigned</span> count = 1000;</div>
|
||||
<div class="line"><a name="l00303"></a><span class="lineno"> 303</span>  <span class="keywordflow">while</span> (count > 0) {</div>
|
||||
<div class="line"><a name="l00304"></a><span class="lineno"> 304</span>  _bus-><a class="code" href="classI2CMaster.html#a01960fc821cb25e4c88c26d2c6107e35" title="Starts a write operation by sending a start condition and the I2C control byte.">startWrite</a>(i2cAddress);</div>
|
||||
<div class="line"><a name="l00305"></a><span class="lineno"> 305</span>  <span class="keywordflow">if</span> (_bus-><a class="code" href="classI2CMaster.html#ab29f63551ddeb032a91505d1c0b8ac41" title="Ends the current write operation.">endWrite</a>())</div>
|
||||
<div class="line"><a name="l00306"></a><span class="lineno"> 306</span>  <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
|
||||
<div class="line"><a name="l00307"></a><span class="lineno"> 307</span>  --count;</div>
|
||||
<div class="line"><a name="l00308"></a><span class="lineno"> 308</span>  }</div>
|
||||
<div class="line"><a name="l00309"></a><span class="lineno"> 309</span>  <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
|
||||
<div class="line"><a name="l00310"></a><span class="lineno"> 310</span> }</div>
|
||||
</div><!-- fragment --></div><!-- contents -->
|
||||
<!-- start footer part -->
|
||||
<hr class="footer"/><address class="footer"><small>
|
||||
Generated on Sun Sep 29 2013 09:30:46 for ArduinoLibs by  <a href="http://www.doxygen.org/index.html">
|
||||
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
||||
</a> 1.8.1.2
|
||||
</small></address>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user