mirror of
https://github.com/taigrr/arduinolibs
synced 2025-01-18 04:33:12 -08:00
403 lines
32 KiB
HTML
403 lines
32 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://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"/>
|
|
<title>ArduinoLibs: DMD.cpp Source File</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<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"/>
|
|
</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">
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<td style="padding-left: 0.5em;">
|
|
<div id="projectname">ArduinoLibs</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div id="navrow1" class="tabs">
|
|
<ul class="tablist">
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<li><a href="pages.html"><span>Related Pages</span></a></li>
|
|
<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">
|
|
<div id="MSearchBox" class="MSearchBoxInactive">
|
|
<span class="left">
|
|
<img id="MSearchSelect" src="search/mag_sel.png"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
alt=""/>
|
|
<input type="text" id="MSearchField" value="Search" accesskey="S"
|
|
onfocus="searchBox.OnSearchFieldFocus(true)"
|
|
onblur="searchBox.OnSearchFieldFocus(false)"
|
|
onkeyup="searchBox.OnSearchFieldChange(event)"/>
|
|
</span><span class="right">
|
|
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
|
|
</span>
|
|
</div>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div id="navrow2" class="tabs2">
|
|
<ul class="tablist">
|
|
<li><a href="files.html"><span>File List</span></a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">DMD.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 "DMD.h"</span>
|
|
<a name="l00024"></a>00024 <span class="preprocessor">#if defined(ARDUINO) && ARDUINO >= 100</span>
|
|
<a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#include <Arduino.h></span>
|
|
<a name="l00026"></a>00026 <span class="preprocessor">#else</span>
|
|
<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#include <WProgram.h></span>
|
|
<a name="l00028"></a>00028 <span class="preprocessor">#endif</span>
|
|
<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include <pins_arduino.h></span>
|
|
<a name="l00030"></a>00030 <span class="preprocessor">#include <avr/io.h></span>
|
|
<a name="l00031"></a>00031 <span class="preprocessor">#include <avr/interrupt.h></span>
|
|
<a name="l00032"></a>00032 <span class="preprocessor">#include <string.h></span>
|
|
<a name="l00033"></a>00033 <span class="preprocessor">#include <stdlib.h></span>
|
|
<a name="l00034"></a>00034
|
|
<a name="l00192"></a>00192 <span class="comment">// Pins on the DMD connector board.</span>
|
|
<a name="l00193"></a>00193 <span class="preprocessor">#define DMD_PIN_PHASE_LSB 6 // A</span>
|
|
<a name="l00194"></a>00194 <span class="preprocessor"></span><span class="preprocessor">#define DMD_PIN_PHASE_MSB 7 // B</span>
|
|
<a name="l00195"></a>00195 <span class="preprocessor"></span><span class="preprocessor">#define DMD_PIN_LATCH 8 // SCLK</span>
|
|
<a name="l00196"></a>00196 <span class="preprocessor"></span><span class="preprocessor">#define DMD_PIN_OUTPUT_ENABLE 9 // nOE</span>
|
|
<a name="l00197"></a>00197 <span class="preprocessor"></span><span class="preprocessor">#define DMD_PIN_SPI_SS SS // SPI Slave Select</span>
|
|
<a name="l00198"></a>00198 <span class="preprocessor"></span><span class="preprocessor">#define DMD_PIN_SPI_MOSI MOSI // SPI Master Out, Slave In (R)</span>
|
|
<a name="l00199"></a>00199 <span class="preprocessor"></span><span class="preprocessor">#define DMD_PIN_SPI_MISO MISO // SPI Master In, Slave Out</span>
|
|
<a name="l00200"></a>00200 <span class="preprocessor"></span><span class="preprocessor">#define DMD_PIN_SPI_SCK SCK // SPI Serial Clock (CLK)</span>
|
|
<a name="l00201"></a>00201 <span class="preprocessor"></span>
|
|
<a name="l00202"></a>00202 <span class="comment">// Dimension information for the display.</span>
|
|
<a name="l00203"></a>00203 <span class="preprocessor">#define DMD_NUM_COLUMNS 32 // Number of columns in a panel.</span>
|
|
<a name="l00204"></a>00204 <span class="preprocessor"></span><span class="preprocessor">#define DMD_NUM_ROWS 16 // Number of rows in a panel.</span>
|
|
<a name="l00205"></a>00205 <span class="preprocessor"></span>
|
|
<a name="l00206"></a>00206 <span class="comment">// Refresh times.</span>
|
|
<a name="l00207"></a>00207 <span class="preprocessor">#define DMD_REFRESH_MS 5</span>
|
|
<a name="l00208"></a>00208 <span class="preprocessor"></span><span class="preprocessor">#define DMD_REFRESH_US 5000</span>
|
|
<a name="l00209"></a>00209 <span class="preprocessor"></span>
|
|
<a name="l00219"></a><a class="code" href="classDMD.html#affd37accffe951c8878434dfa1245809">00219</a> <a class="code" href="classDMD.html#affd37accffe951c8878434dfa1245809" title="Constructs a new dot matrix display handler for a display that is widthPanels x heightPanels in size...">DMD::DMD</a>(<span class="keywordtype">int</span> widthPanels, <span class="keywordtype">int</span> heightPanels)
|
|
<a name="l00220"></a>00220 : <a class="code" href="classBitmap.html" title="Represents a monochrome bitmap within main memory.">Bitmap</a>(widthPanels * DMD_NUM_COLUMNS, heightPanels * DMD_NUM_ROWS)
|
|
<a name="l00221"></a>00221 , _doubleBuffer(false)
|
|
<a name="l00222"></a>00222 , phase(0)
|
|
<a name="l00223"></a>00223 , fb0(0)
|
|
<a name="l00224"></a>00224 , fb1(0)
|
|
<a name="l00225"></a>00225 , displayfb(0)
|
|
<a name="l00226"></a>00226 , lastRefresh(millis())
|
|
<a name="l00227"></a>00227 {
|
|
<a name="l00228"></a>00228 <span class="comment">// Both rendering and display are to fb0 initially.</span>
|
|
<a name="l00229"></a>00229 fb0 = displayfb = fb;
|
|
<a name="l00230"></a>00230
|
|
<a name="l00231"></a>00231 <span class="comment">// Initialize SPI to MSB-first, mode 0, clock divider = 2.</span>
|
|
<a name="l00232"></a>00232 pinMode(DMD_PIN_SPI_SCK, OUTPUT);
|
|
<a name="l00233"></a>00233 pinMode(DMD_PIN_SPI_MOSI, OUTPUT);
|
|
<a name="l00234"></a>00234 pinMode(DMD_PIN_SPI_SS, OUTPUT);
|
|
<a name="l00235"></a>00235 digitalWrite(DMD_PIN_SPI_SCK, LOW);
|
|
<a name="l00236"></a>00236 digitalWrite(DMD_PIN_SPI_MOSI, LOW);
|
|
<a name="l00237"></a>00237 digitalWrite(DMD_PIN_SPI_SS, HIGH);
|
|
<a name="l00238"></a>00238 SPCR |= _BV(MSTR);
|
|
<a name="l00239"></a>00239 SPCR |= _BV(SPE);
|
|
<a name="l00240"></a>00240 SPCR &= ~(_BV(DORD)); <span class="comment">// MSB-first</span>
|
|
<a name="l00241"></a>00241 SPCR &= ~0x0C; <span class="comment">// Mode 0</span>
|
|
<a name="l00242"></a>00242 SPCR &= ~0x03; <span class="comment">// Clock divider rate 2</span>
|
|
<a name="l00243"></a>00243 SPSR |= 0x01; <span class="comment">// MSB of clock divider rate</span>
|
|
<a name="l00244"></a>00244
|
|
<a name="l00245"></a>00245 <span class="comment">// Initialize the DMD-specific pins.</span>
|
|
<a name="l00246"></a>00246 pinMode(DMD_PIN_PHASE_LSB, OUTPUT);
|
|
<a name="l00247"></a>00247 pinMode(DMD_PIN_PHASE_MSB, OUTPUT);
|
|
<a name="l00248"></a>00248 pinMode(DMD_PIN_LATCH, OUTPUT);
|
|
<a name="l00249"></a>00249 pinMode(DMD_PIN_OUTPUT_ENABLE, OUTPUT);
|
|
<a name="l00250"></a>00250 digitalWrite(DMD_PIN_PHASE_LSB, LOW);
|
|
<a name="l00251"></a>00251 digitalWrite(DMD_PIN_PHASE_MSB, LOW);
|
|
<a name="l00252"></a>00252 digitalWrite(DMD_PIN_LATCH, LOW);
|
|
<a name="l00253"></a>00253 digitalWrite(DMD_PIN_OUTPUT_ENABLE, LOW);
|
|
<a name="l00254"></a>00254 digitalWrite(DMD_PIN_SPI_MOSI, HIGH);
|
|
<a name="l00255"></a>00255 }
|
|
<a name="l00256"></a>00256
|
|
<a name="l00260"></a><a class="code" href="classDMD.html#a7b37e05584d3e0308163700920df99b2">00260</a> <a class="code" href="classDMD.html#a7b37e05584d3e0308163700920df99b2" title="Destroys this dot matrix display handler.">DMD::~DMD</a>()
|
|
<a name="l00261"></a>00261 {
|
|
<a name="l00262"></a>00262 <span class="keywordflow">if</span> (fb0)
|
|
<a name="l00263"></a>00263 free(fb0);
|
|
<a name="l00264"></a>00264 <span class="keywordflow">if</span> (fb1)
|
|
<a name="l00265"></a>00265 free(fb1);
|
|
<a name="l00266"></a>00266 fb = 0; <span class="comment">// Don't free the buffer again in the base class.</span>
|
|
<a name="l00267"></a>00267 }
|
|
<a name="l00268"></a>00268
|
|
<a name="l00296"></a><a class="code" href="classDMD.html#a6fbdcf8832f91d02500cb7a9b84d2723">00296</a> <span class="keywordtype">void</span> <a class="code" href="classDMD.html#a6fbdcf8832f91d02500cb7a9b84d2723" title="Enables or disables double-buffering according to doubleBuffer.">DMD::setDoubleBuffer</a>(<span class="keywordtype">bool</span> doubleBuffer)
|
|
<a name="l00297"></a>00297 {
|
|
<a name="l00298"></a>00298 <span class="keywordflow">if</span> (doubleBuffer != _doubleBuffer) {
|
|
<a name="l00299"></a>00299 _doubleBuffer = <a class="code" href="classDMD.html#aab1f3ba29c053d630ae12865d22166ec" title="Returns true if the display is double-buffered; false if single-buffered. The default is false...">doubleBuffer</a>;
|
|
<a name="l00300"></a>00300 <span class="keywordflow">if</span> (doubleBuffer) {
|
|
<a name="l00301"></a>00301 <span class="comment">// Allocate a new back buffer.</span>
|
|
<a name="l00302"></a>00302 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size = _stride * _height;
|
|
<a name="l00303"></a>00303 fb1 = (uint8_t *)malloc(size);
|
|
<a name="l00304"></a>00304
|
|
<a name="l00305"></a>00305 <span class="comment">// Clear the new back buffer and then switch to it, leaving</span>
|
|
<a name="l00306"></a>00306 <span class="comment">// the current contents of fb0 on the screen.</span>
|
|
<a name="l00307"></a>00307 <span class="keywordflow">if</span> (fb1) {
|
|
<a name="l00308"></a>00308 memset(fb1, 0xFF, size);
|
|
<a name="l00309"></a>00309 cli();
|
|
<a name="l00310"></a>00310 fb = fb1;
|
|
<a name="l00311"></a>00311 displayfb = fb0;
|
|
<a name="l00312"></a>00312 sei();
|
|
<a name="l00313"></a>00313 } <span class="keywordflow">else</span> {
|
|
<a name="l00314"></a>00314 <span class="comment">// Failed to allocate the memory, so revert to single-buffered.</span>
|
|
<a name="l00315"></a>00315 _doubleBuffer = <span class="keyword">false</span>;
|
|
<a name="l00316"></a>00316 }
|
|
<a name="l00317"></a>00317 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (fb1) {
|
|
<a name="l00318"></a>00318 <span class="comment">// Disabling double-buffering, so forcibly switch to fb0.</span>
|
|
<a name="l00319"></a>00319 cli();
|
|
<a name="l00320"></a>00320 fb = fb0;
|
|
<a name="l00321"></a>00321 displayfb = fb0;
|
|
<a name="l00322"></a>00322 sei();
|
|
<a name="l00323"></a>00323
|
|
<a name="l00324"></a>00324 <span class="comment">// Free the unnecessary buffer.</span>
|
|
<a name="l00325"></a>00325 free(fb1);
|
|
<a name="l00326"></a>00326 fb1 = 0;
|
|
<a name="l00327"></a>00327 }
|
|
<a name="l00328"></a>00328 }
|
|
<a name="l00329"></a>00329 }
|
|
<a name="l00330"></a>00330
|
|
<a name="l00345"></a><a class="code" href="classDMD.html#a80269ccd44b3ef9ee15f0a1009b7a60a">00345</a> <span class="keywordtype">void</span> <a class="code" href="classDMD.html#a80269ccd44b3ef9ee15f0a1009b7a60a" title="Swaps the buffers that are used for rendering to the display.">DMD::swapBuffers</a>()
|
|
<a name="l00346"></a>00346 {
|
|
<a name="l00347"></a>00347 <span class="keywordflow">if</span> (_doubleBuffer) {
|
|
<a name="l00348"></a>00348 <span class="comment">// Turn off interrupts while swapping buffers so that we don't</span>
|
|
<a name="l00349"></a>00349 <span class="comment">// accidentally try to refresh() in the middle of this code.</span>
|
|
<a name="l00350"></a>00350 cli();
|
|
<a name="l00351"></a>00351 <span class="keywordflow">if</span> (fb == fb0) {
|
|
<a name="l00352"></a>00352 fb = fb1;
|
|
<a name="l00353"></a>00353 displayfb = fb0;
|
|
<a name="l00354"></a>00354 } <span class="keywordflow">else</span> {
|
|
<a name="l00355"></a>00355 fb = fb0;
|
|
<a name="l00356"></a>00356 displayfb = fb1;
|
|
<a name="l00357"></a>00357 }
|
|
<a name="l00358"></a>00358 sei();
|
|
<a name="l00359"></a>00359 }
|
|
<a name="l00360"></a>00360 }
|
|
<a name="l00361"></a>00361
|
|
<a name="l00378"></a><a class="code" href="classDMD.html#a0b1771cf790b2b62eea55e56b02e3736">00378</a> <span class="keywordtype">void</span> <a class="code" href="classDMD.html#a0b1771cf790b2b62eea55e56b02e3736" title="Swaps the buffers that are used for rendering to the display and copies the former back buffer conten...">DMD::swapBuffersAndCopy</a>()
|
|
<a name="l00379"></a>00379 {
|
|
<a name="l00380"></a>00380 <a class="code" href="classDMD.html#a80269ccd44b3ef9ee15f0a1009b7a60a" title="Swaps the buffers that are used for rendering to the display.">swapBuffers</a>();
|
|
<a name="l00381"></a>00381 <span class="keywordflow">if</span> (_doubleBuffer)
|
|
<a name="l00382"></a>00382 memcpy(fb, displayfb, _stride * _height);
|
|
<a name="l00383"></a>00383 }
|
|
<a name="l00384"></a>00384
|
|
<a name="l00402"></a><a class="code" href="classDMD.html#a2c74a0845ef6080056b972d490648114">00402</a> <span class="keywordtype">void</span> <a class="code" href="classDMD.html#a2c74a0845ef6080056b972d490648114" title="Performs regular display refresh activities from the application's main loop.">DMD::loop</a>()
|
|
<a name="l00403"></a>00403 {
|
|
<a name="l00404"></a>00404 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> currentTime = millis();
|
|
<a name="l00405"></a>00405 <span class="keywordflow">if</span> ((currentTime - lastRefresh) >= DMD_REFRESH_MS) {
|
|
<a name="l00406"></a>00406 lastRefresh = currentTime;
|
|
<a name="l00407"></a>00407 <a class="code" href="classDMD.html#a9e4bf2a9d247312d35c1401ff61261c8" title="Refresh the display.">refresh</a>();
|
|
<a name="l00408"></a>00408 }
|
|
<a name="l00409"></a>00409 }
|
|
<a name="l00410"></a>00410
|
|
<a name="l00411"></a>00411 <span class="comment">// Send a single byte via SPI.</span>
|
|
<a name="l00412"></a>00412 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spiSend(byte value)
|
|
<a name="l00413"></a>00413 {
|
|
<a name="l00414"></a>00414 SPDR = value;
|
|
<a name="l00415"></a>00415 <span class="keywordflow">while</span> (!(SPSR & _BV(SPIF)))
|
|
<a name="l00416"></a>00416 ; <span class="comment">// Wait for the transfer to complete.</span>
|
|
<a name="l00417"></a>00417 }
|
|
<a name="l00418"></a>00418
|
|
<a name="l00419"></a>00419 <span class="comment">// Flip the bits in a byte. Table generated by genflip.c</span>
|
|
<a name="l00420"></a>00420 <span class="keyword">static</span> <span class="keyword">const</span> uint8_t flipBits[256] PROGMEM = {
|
|
<a name="l00421"></a>00421 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0,
|
|
<a name="l00422"></a>00422 0x30, 0xB0, 0x70, 0xF0, 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
|
|
<a name="l00423"></a>00423 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, 0x04, 0x84, 0x44, 0xC4,
|
|
<a name="l00424"></a>00424 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
|
|
<a name="l00425"></a>00425 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC,
|
|
<a name="l00426"></a>00426 0x3C, 0xBC, 0x7C, 0xFC, 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
|
|
<a name="l00427"></a>00427 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, 0x0A, 0x8A, 0x4A, 0xCA,
|
|
<a name="l00428"></a>00428 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
|
|
<a name="l00429"></a>00429 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6,
|
|
<a name="l00430"></a>00430 0x36, 0xB6, 0x76, 0xF6, 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
|
|
<a name="l00431"></a>00431 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, 0x01, 0x81, 0x41, 0xC1,
|
|
<a name="l00432"></a>00432 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
|
|
<a name="l00433"></a>00433 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9,
|
|
<a name="l00434"></a>00434 0x39, 0xB9, 0x79, 0xF9, 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
|
|
<a name="l00435"></a>00435 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, 0x0D, 0x8D, 0x4D, 0xCD,
|
|
<a name="l00436"></a>00436 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
|
|
<a name="l00437"></a>00437 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3,
|
|
<a name="l00438"></a>00438 0x33, 0xB3, 0x73, 0xF3, 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
|
|
<a name="l00439"></a>00439 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, 0x07, 0x87, 0x47, 0xC7,
|
|
<a name="l00440"></a>00440 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
|
|
<a name="l00441"></a>00441 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF,
|
|
<a name="l00442"></a>00442 0x3F, 0xBF, 0x7F, 0xFF
|
|
<a name="l00443"></a>00443 };
|
|
<a name="l00444"></a>00444
|
|
<a name="l00460"></a><a class="code" href="classDMD.html#a9e4bf2a9d247312d35c1401ff61261c8">00460</a> <span class="keywordtype">void</span> <a class="code" href="classDMD.html#a9e4bf2a9d247312d35c1401ff61261c8" title="Refresh the display.">DMD::refresh</a>()
|
|
<a name="l00461"></a>00461 {
|
|
<a name="l00462"></a>00462 <span class="comment">// Bail out if there is a conflict on the SPI bus.</span>
|
|
<a name="l00463"></a>00463 <span class="keywordflow">if</span> (!digitalRead(DMD_PIN_SPI_SS))
|
|
<a name="l00464"></a>00464 <span class="keywordflow">return</span>;
|
|
<a name="l00465"></a>00465
|
|
<a name="l00466"></a>00466 <span class="comment">// Transfer the data for the next group of interleaved rows.</span>
|
|
<a name="l00467"></a>00467 <span class="keywordtype">int</span> stride4 = _stride * 4;
|
|
<a name="l00468"></a>00468 uint8_t *data0;
|
|
<a name="l00469"></a>00469 uint8_t *data1;
|
|
<a name="l00470"></a>00470 uint8_t *data2;
|
|
<a name="l00471"></a>00471 uint8_t *data3;
|
|
<a name="l00472"></a>00472 <span class="keywordtype">bool</span> flipRow = ((_height & 0x10) == 0);
|
|
<a name="l00473"></a>00473 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> y = 0; y < _height; y += 16) {
|
|
<a name="l00474"></a>00474 <span class="keywordflow">if</span> (!flipRow) {
|
|
<a name="l00475"></a>00475 <span class="comment">// The panels in this row are the right way up.</span>
|
|
<a name="l00476"></a>00476 data0 = displayfb + _stride * (y + phase);
|
|
<a name="l00477"></a>00477 data1 = data0 + stride4;
|
|
<a name="l00478"></a>00478 data2 = data1 + stride4;
|
|
<a name="l00479"></a>00479 data3 = data2 + stride4;
|
|
<a name="l00480"></a>00480 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> x = _stride; x > 0; --x) {
|
|
<a name="l00481"></a>00481 spiSend(*data3++);
|
|
<a name="l00482"></a>00482 spiSend(*data2++);
|
|
<a name="l00483"></a>00483 spiSend(*data1++);
|
|
<a name="l00484"></a>00484 spiSend(*data0++);
|
|
<a name="l00485"></a>00485 }
|
|
<a name="l00486"></a>00486 flipRow = <span class="keyword">true</span>;
|
|
<a name="l00487"></a>00487 } <span class="keywordflow">else</span> {
|
|
<a name="l00488"></a>00488 <span class="comment">// The panels in this row are upside-down and reversed.</span>
|
|
<a name="l00489"></a>00489 data0 = displayfb + _stride * (y + 16 - phase) - 1;
|
|
<a name="l00490"></a>00490 data1 = data0 - stride4;
|
|
<a name="l00491"></a>00491 data2 = data1 - stride4;
|
|
<a name="l00492"></a>00492 data3 = data2 - stride4;
|
|
<a name="l00493"></a>00493 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> x = _stride; x > 0; --x) {
|
|
<a name="l00494"></a>00494 spiSend(pgm_read_byte(&(flipBits[*data3--])));
|
|
<a name="l00495"></a>00495 spiSend(pgm_read_byte(&(flipBits[*data2--])));
|
|
<a name="l00496"></a>00496 spiSend(pgm_read_byte(&(flipBits[*data1--])));
|
|
<a name="l00497"></a>00497 spiSend(pgm_read_byte(&(flipBits[*data0--])));
|
|
<a name="l00498"></a>00498 }
|
|
<a name="l00499"></a>00499 flipRow = <span class="keyword">false</span>;
|
|
<a name="l00500"></a>00500 }
|
|
<a name="l00501"></a>00501 }
|
|
<a name="l00502"></a>00502
|
|
<a name="l00503"></a>00503 <span class="comment">// Latch the data from the shift registers onto the actual display.</span>
|
|
<a name="l00504"></a>00504 digitalWrite(DMD_PIN_OUTPUT_ENABLE, LOW);
|
|
<a name="l00505"></a>00505 digitalWrite(DMD_PIN_LATCH, HIGH);
|
|
<a name="l00506"></a>00506 digitalWrite(DMD_PIN_LATCH, LOW);
|
|
<a name="l00507"></a>00507 <span class="keywordflow">if</span> (phase & 0x02)
|
|
<a name="l00508"></a>00508 digitalWrite(DMD_PIN_PHASE_MSB, HIGH);
|
|
<a name="l00509"></a>00509 <span class="keywordflow">else</span>
|
|
<a name="l00510"></a>00510 digitalWrite(DMD_PIN_PHASE_MSB, LOW);
|
|
<a name="l00511"></a>00511 <span class="keywordflow">if</span> (phase & 0x01)
|
|
<a name="l00512"></a>00512 digitalWrite(DMD_PIN_PHASE_LSB, HIGH);
|
|
<a name="l00513"></a>00513 <span class="keywordflow">else</span>
|
|
<a name="l00514"></a>00514 digitalWrite(DMD_PIN_PHASE_LSB, LOW);
|
|
<a name="l00515"></a>00515 digitalWrite(DMD_PIN_OUTPUT_ENABLE, HIGH);
|
|
<a name="l00516"></a>00516 phase = (phase + 1) & 0x03;
|
|
<a name="l00517"></a>00517 }
|
|
<a name="l00518"></a>00518
|
|
<a name="l00545"></a><a class="code" href="classDMD.html#a4c3b04b384f3d656a9b59690836775e2">00545</a> <span class="keywordtype">void</span> <a class="code" href="classDMD.html#a4c3b04b384f3d656a9b59690836775e2" title="Enables Timer1 overflow interrupts for updating this display.">DMD::enableTimer1</a>()
|
|
<a name="l00546"></a>00546 {
|
|
<a name="l00547"></a>00547 <span class="comment">// Number of CPU cycles in the display's refresh period.</span>
|
|
<a name="l00548"></a>00548 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> numCycles = (F_CPU / 2000000) * DMD_REFRESH_US;
|
|
<a name="l00549"></a>00549
|
|
<a name="l00550"></a>00550 <span class="comment">// Determine the prescaler to be used.</span>
|
|
<a name="l00551"></a>00551 <span class="preprocessor"> #define TIMER1_RESOLUTION 65536UL</span>
|
|
<a name="l00552"></a>00552 <span class="preprocessor"></span> uint8_t prescaler;
|
|
<a name="l00553"></a>00553 <span class="keywordflow">if</span> (numCycles < TIMER1_RESOLUTION) {
|
|
<a name="l00554"></a>00554 <span class="comment">// No prescaling required.</span>
|
|
<a name="l00555"></a>00555 prescaler = _BV(CS10);
|
|
<a name="l00556"></a>00556 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (numCycles < TIMER1_RESOLUTION * 8) {
|
|
<a name="l00557"></a>00557 <span class="comment">// Prescaler = 8.</span>
|
|
<a name="l00558"></a>00558 prescaler = _BV(CS11);
|
|
<a name="l00559"></a>00559 numCycles >>= 3;
|
|
<a name="l00560"></a>00560 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (numCycles < TIMER1_RESOLUTION * 64) {
|
|
<a name="l00561"></a>00561 <span class="comment">// Prescaler = 64.</span>
|
|
<a name="l00562"></a>00562 prescaler = _BV(CS11) | _BV(CS10);
|
|
<a name="l00563"></a>00563 numCycles >>= 6;
|
|
<a name="l00564"></a>00564 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (numCycles < TIMER1_RESOLUTION * 256) {
|
|
<a name="l00565"></a>00565 <span class="comment">// Prescaler = 256.</span>
|
|
<a name="l00566"></a>00566 prescaler = _BV(CS12);
|
|
<a name="l00567"></a>00567 numCycles >>= 8;
|
|
<a name="l00568"></a>00568 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (numCycles < TIMER1_RESOLUTION * 1024) {
|
|
<a name="l00569"></a>00569 <span class="comment">// Prescaler = 1024.</span>
|
|
<a name="l00570"></a>00570 prescaler = _BV(CS12) | _BV(CS10);
|
|
<a name="l00571"></a>00571 numCycles >>= 10;
|
|
<a name="l00572"></a>00572 } <span class="keywordflow">else</span> {
|
|
<a name="l00573"></a>00573 <span class="comment">// Too long, so set the maximum timeout.</span>
|
|
<a name="l00574"></a>00574 prescaler = _BV(CS12) | _BV(CS10);
|
|
<a name="l00575"></a>00575 numCycles = TIMER1_RESOLUTION - 1;
|
|
<a name="l00576"></a>00576 }
|
|
<a name="l00577"></a>00577
|
|
<a name="l00578"></a>00578 <span class="comment">// Configure Timer1 for the period we want.</span>
|
|
<a name="l00579"></a>00579 TCCR1A = 0;
|
|
<a name="l00580"></a>00580 TCCR1B = _BV(WGM13);
|
|
<a name="l00581"></a>00581 uint8_t saveSREG = SREG;
|
|
<a name="l00582"></a>00582 cli();
|
|
<a name="l00583"></a>00583 ICR1 = numCycles;
|
|
<a name="l00584"></a>00584 SREG = saveSREG; <span class="comment">// Implicit sei() if interrupts were on previously.</span>
|
|
<a name="l00585"></a>00585 TCCR1B = (TCCR1B & ~(_BV(CS12) | _BV(CS11) | _BV(CS10))) | prescaler;
|
|
<a name="l00586"></a>00586
|
|
<a name="l00587"></a>00587 <span class="comment">// Turn on the Timer1 overflow interrupt.</span>
|
|
<a name="l00588"></a>00588 TIMSK1 |= _BV(TOIE1);
|
|
<a name="l00589"></a>00589 }
|
|
<a name="l00590"></a>00590
|
|
<a name="l00596"></a><a class="code" href="classDMD.html#a39af27e216f654ecc7e60b0614cb6b33">00596</a> <span class="keywordtype">void</span> <a class="code" href="classDMD.html#a39af27e216f654ecc7e60b0614cb6b33" title="Disables Timer1 overflow interrupts.">DMD::disableTimer1</a>()
|
|
<a name="l00597"></a>00597 {
|
|
<a name="l00598"></a>00598 <span class="comment">// Turn off the Timer1 overflow interrupt.</span>
|
|
<a name="l00599"></a>00599 TIMSK1 &= ~_BV(TOIE1);
|
|
<a name="l00600"></a>00600 }
|
|
<a name="l00601"></a>00601
|
|
<a name="l00612"></a><a class="code" href="classDMD.html#a557412f734fc4596e1102bf71e110ea0">00612</a> <a class="code" href="classBitmap.html#a88d386944a7017aa776a177b10d8b2ba" title="Type that represents the color of a pixel in a bitmap.">DMD::Color</a> <a class="code" href="classDMD.html#a557412f734fc4596e1102bf71e110ea0" title="Converts an RGB value into a pixel color value.">DMD::fromRGB</a>(uint8_t r, uint8_t g, uint8_t b)
|
|
<a name="l00613"></a>00613 {
|
|
<a name="l00614"></a>00614 <span class="keywordflow">if</span> (r || g || b)
|
|
<a name="l00615"></a>00615 <span class="keywordflow">return</span> <a class="code" href="classBitmap.html#a39b6754cfe50a457bbfdb1980fd87eb7" title="Color value corresponding to "white". If the bitmap is displayed on a LED array, then it may have a d...">White</a>;
|
|
<a name="l00616"></a>00616 <span class="keywordflow">else</span>
|
|
<a name="l00617"></a>00617 <span class="keywordflow">return</span> <a class="code" href="classBitmap.html#a2c7faeeb89d3624b5bbca58871785adc" title="Color value corresponding to "black".">Black</a>;
|
|
<a name="l00618"></a>00618 }
|
|
</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>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="javascript:void(0)" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
<hr class="footer"/><address class="footer"><small>Generated on Tue May 29 2012 15:23:58 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>
|
|
</body>
|
|
</html>
|