mirror of
https://github.com/taigrr/arduinolibs
synced 2025-01-18 04:33:12 -08:00
432 lines
34 KiB
HTML
432 lines
34 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="l00210"></a>00210 <span class="comment">// Pins on the DMD connector board.</span>
|
|
<a name="l00211"></a>00211 <span class="preprocessor">#define DMD_PIN_PHASE_LSB 6 // A</span>
|
|
<a name="l00212"></a>00212 <span class="preprocessor"></span><span class="preprocessor">#define DMD_PIN_PHASE_MSB 7 // B</span>
|
|
<a name="l00213"></a>00213 <span class="preprocessor"></span><span class="preprocessor">#define DMD_PIN_LATCH 8 // SCLK</span>
|
|
<a name="l00214"></a>00214 <span class="preprocessor"></span><span class="preprocessor">#define DMD_PIN_OUTPUT_ENABLE 9 // nOE</span>
|
|
<a name="l00215"></a>00215 <span class="preprocessor"></span><span class="preprocessor">#define DMD_PIN_SPI_SS SS // SPI Slave Select</span>
|
|
<a name="l00216"></a>00216 <span class="preprocessor"></span><span class="preprocessor">#define DMD_PIN_SPI_MOSI MOSI // SPI Master Out, Slave In (R)</span>
|
|
<a name="l00217"></a>00217 <span class="preprocessor"></span><span class="preprocessor">#define DMD_PIN_SPI_MISO MISO // SPI Master In, Slave Out</span>
|
|
<a name="l00218"></a>00218 <span class="preprocessor"></span><span class="preprocessor">#define DMD_PIN_SPI_SCK SCK // SPI Serial Clock (CLK)</span>
|
|
<a name="l00219"></a>00219 <span class="preprocessor"></span>
|
|
<a name="l00220"></a>00220 <span class="comment">// Dimension information for the display.</span>
|
|
<a name="l00221"></a>00221 <span class="preprocessor">#define DMD_NUM_COLUMNS 32 // Number of columns in a panel.</span>
|
|
<a name="l00222"></a>00222 <span class="preprocessor"></span><span class="preprocessor">#define DMD_NUM_ROWS 16 // Number of rows in a panel.</span>
|
|
<a name="l00223"></a>00223 <span class="preprocessor"></span>
|
|
<a name="l00224"></a>00224 <span class="comment">// Refresh times.</span>
|
|
<a name="l00225"></a>00225 <span class="preprocessor">#define DMD_REFRESH_MS 5</span>
|
|
<a name="l00226"></a>00226 <span class="preprocessor"></span><span class="preprocessor">#define DMD_REFRESH_US 5000</span>
|
|
<a name="l00227"></a>00227 <span class="preprocessor"></span>
|
|
<a name="l00237"></a><a class="code" href="classDMD.html#affd37accffe951c8878434dfa1245809">00237</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="l00238"></a>00238 : <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="l00239"></a>00239 , _doubleBuffer(false)
|
|
<a name="l00240"></a>00240 , phase(0)
|
|
<a name="l00241"></a>00241 , fb0(0)
|
|
<a name="l00242"></a>00242 , fb1(0)
|
|
<a name="l00243"></a>00243 , displayfb(0)
|
|
<a name="l00244"></a>00244 , lastRefresh(millis())
|
|
<a name="l00245"></a>00245 {
|
|
<a name="l00246"></a>00246 <span class="comment">// Both rendering and display are to fb0 initially.</span>
|
|
<a name="l00247"></a>00247 fb0 = displayfb = fb;
|
|
<a name="l00248"></a>00248
|
|
<a name="l00249"></a>00249 <span class="comment">// Initialize SPI to MSB-first, mode 0, clock divider = 2.</span>
|
|
<a name="l00250"></a>00250 pinMode(DMD_PIN_SPI_SCK, OUTPUT);
|
|
<a name="l00251"></a>00251 pinMode(DMD_PIN_SPI_MOSI, OUTPUT);
|
|
<a name="l00252"></a>00252 pinMode(DMD_PIN_SPI_SS, OUTPUT);
|
|
<a name="l00253"></a>00253 digitalWrite(DMD_PIN_SPI_SCK, LOW);
|
|
<a name="l00254"></a>00254 digitalWrite(DMD_PIN_SPI_MOSI, LOW);
|
|
<a name="l00255"></a>00255 digitalWrite(DMD_PIN_SPI_SS, HIGH);
|
|
<a name="l00256"></a>00256 SPCR |= _BV(MSTR);
|
|
<a name="l00257"></a>00257 SPCR |= _BV(SPE);
|
|
<a name="l00258"></a>00258 SPCR &= ~(_BV(DORD)); <span class="comment">// MSB-first</span>
|
|
<a name="l00259"></a>00259 SPCR &= ~0x0C; <span class="comment">// Mode 0</span>
|
|
<a name="l00260"></a>00260 SPCR &= ~0x03; <span class="comment">// Clock divider rate 2</span>
|
|
<a name="l00261"></a>00261 SPSR |= 0x01; <span class="comment">// MSB of clock divider rate</span>
|
|
<a name="l00262"></a>00262
|
|
<a name="l00263"></a>00263 <span class="comment">// Initialize the DMD-specific pins.</span>
|
|
<a name="l00264"></a>00264 pinMode(DMD_PIN_PHASE_LSB, OUTPUT);
|
|
<a name="l00265"></a>00265 pinMode(DMD_PIN_PHASE_MSB, OUTPUT);
|
|
<a name="l00266"></a>00266 pinMode(DMD_PIN_LATCH, OUTPUT);
|
|
<a name="l00267"></a>00267 pinMode(DMD_PIN_OUTPUT_ENABLE, OUTPUT);
|
|
<a name="l00268"></a>00268 digitalWrite(DMD_PIN_PHASE_LSB, LOW);
|
|
<a name="l00269"></a>00269 digitalWrite(DMD_PIN_PHASE_MSB, LOW);
|
|
<a name="l00270"></a>00270 digitalWrite(DMD_PIN_LATCH, LOW);
|
|
<a name="l00271"></a>00271 digitalWrite(DMD_PIN_OUTPUT_ENABLE, LOW);
|
|
<a name="l00272"></a>00272 digitalWrite(DMD_PIN_SPI_MOSI, HIGH);
|
|
<a name="l00273"></a>00273 }
|
|
<a name="l00274"></a>00274
|
|
<a name="l00278"></a><a class="code" href="classDMD.html#a7b37e05584d3e0308163700920df99b2">00278</a> <a class="code" href="classDMD.html#a7b37e05584d3e0308163700920df99b2" title="Destroys this dot matrix display handler.">DMD::~DMD</a>()
|
|
<a name="l00279"></a>00279 {
|
|
<a name="l00280"></a>00280 <span class="keywordflow">if</span> (fb0)
|
|
<a name="l00281"></a>00281 free(fb0);
|
|
<a name="l00282"></a>00282 <span class="keywordflow">if</span> (fb1)
|
|
<a name="l00283"></a>00283 free(fb1);
|
|
<a name="l00284"></a>00284 fb = 0; <span class="comment">// Don't free the buffer again in the base class.</span>
|
|
<a name="l00285"></a>00285 }
|
|
<a name="l00286"></a>00286
|
|
<a name="l00314"></a><a class="code" href="classDMD.html#a6fbdcf8832f91d02500cb7a9b84d2723">00314</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="l00315"></a>00315 {
|
|
<a name="l00316"></a>00316 <span class="keywordflow">if</span> (doubleBuffer != _doubleBuffer) {
|
|
<a name="l00317"></a>00317 _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="l00318"></a>00318 <span class="keywordflow">if</span> (doubleBuffer) {
|
|
<a name="l00319"></a>00319 <span class="comment">// Allocate a new back buffer.</span>
|
|
<a name="l00320"></a>00320 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size = _stride * _height;
|
|
<a name="l00321"></a>00321 fb1 = (uint8_t *)malloc(size);
|
|
<a name="l00322"></a>00322
|
|
<a name="l00323"></a>00323 <span class="comment">// Clear the new back buffer and then switch to it, leaving</span>
|
|
<a name="l00324"></a>00324 <span class="comment">// the current contents of fb0 on the screen.</span>
|
|
<a name="l00325"></a>00325 <span class="keywordflow">if</span> (fb1) {
|
|
<a name="l00326"></a>00326 memset(fb1, 0xFF, size);
|
|
<a name="l00327"></a>00327 cli();
|
|
<a name="l00328"></a>00328 fb = fb1;
|
|
<a name="l00329"></a>00329 displayfb = fb0;
|
|
<a name="l00330"></a>00330 sei();
|
|
<a name="l00331"></a>00331 } <span class="keywordflow">else</span> {
|
|
<a name="l00332"></a>00332 <span class="comment">// Failed to allocate the memory, so revert to single-buffered.</span>
|
|
<a name="l00333"></a>00333 _doubleBuffer = <span class="keyword">false</span>;
|
|
<a name="l00334"></a>00334 }
|
|
<a name="l00335"></a>00335 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (fb1) {
|
|
<a name="l00336"></a>00336 <span class="comment">// Disabling double-buffering, so forcibly switch to fb0.</span>
|
|
<a name="l00337"></a>00337 cli();
|
|
<a name="l00338"></a>00338 fb = fb0;
|
|
<a name="l00339"></a>00339 displayfb = fb0;
|
|
<a name="l00340"></a>00340 sei();
|
|
<a name="l00341"></a>00341
|
|
<a name="l00342"></a>00342 <span class="comment">// Free the unnecessary buffer.</span>
|
|
<a name="l00343"></a>00343 free(fb1);
|
|
<a name="l00344"></a>00344 fb1 = 0;
|
|
<a name="l00345"></a>00345 }
|
|
<a name="l00346"></a>00346 }
|
|
<a name="l00347"></a>00347 }
|
|
<a name="l00348"></a>00348
|
|
<a name="l00363"></a><a class="code" href="classDMD.html#a80269ccd44b3ef9ee15f0a1009b7a60a">00363</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="l00364"></a>00364 {
|
|
<a name="l00365"></a>00365 <span class="keywordflow">if</span> (_doubleBuffer) {
|
|
<a name="l00366"></a>00366 <span class="comment">// Turn off interrupts while swapping buffers so that we don't</span>
|
|
<a name="l00367"></a>00367 <span class="comment">// accidentally try to refresh() in the middle of this code.</span>
|
|
<a name="l00368"></a>00368 cli();
|
|
<a name="l00369"></a>00369 <span class="keywordflow">if</span> (fb == fb0) {
|
|
<a name="l00370"></a>00370 fb = fb1;
|
|
<a name="l00371"></a>00371 displayfb = fb0;
|
|
<a name="l00372"></a>00372 } <span class="keywordflow">else</span> {
|
|
<a name="l00373"></a>00373 fb = fb0;
|
|
<a name="l00374"></a>00374 displayfb = fb1;
|
|
<a name="l00375"></a>00375 }
|
|
<a name="l00376"></a>00376 sei();
|
|
<a name="l00377"></a>00377 }
|
|
<a name="l00378"></a>00378 }
|
|
<a name="l00379"></a>00379
|
|
<a name="l00396"></a><a class="code" href="classDMD.html#a0b1771cf790b2b62eea55e56b02e3736">00396</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="l00397"></a>00397 {
|
|
<a name="l00398"></a>00398 <a class="code" href="classDMD.html#a80269ccd44b3ef9ee15f0a1009b7a60a" title="Swaps the buffers that are used for rendering to the display.">swapBuffers</a>();
|
|
<a name="l00399"></a>00399 <span class="keywordflow">if</span> (_doubleBuffer)
|
|
<a name="l00400"></a>00400 memcpy(fb, displayfb, _stride * _height);
|
|
<a name="l00401"></a>00401 }
|
|
<a name="l00402"></a>00402
|
|
<a name="l00420"></a><a class="code" href="classDMD.html#a2c74a0845ef6080056b972d490648114">00420</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="l00421"></a>00421 {
|
|
<a name="l00422"></a>00422 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> currentTime = millis();
|
|
<a name="l00423"></a>00423 <span class="keywordflow">if</span> ((currentTime - lastRefresh) >= DMD_REFRESH_MS) {
|
|
<a name="l00424"></a>00424 lastRefresh = currentTime;
|
|
<a name="l00425"></a>00425 <a class="code" href="classDMD.html#a9e4bf2a9d247312d35c1401ff61261c8" title="Refresh the display.">refresh</a>();
|
|
<a name="l00426"></a>00426 }
|
|
<a name="l00427"></a>00427 }
|
|
<a name="l00428"></a>00428
|
|
<a name="l00429"></a>00429 <span class="comment">// Send a single byte via SPI.</span>
|
|
<a name="l00430"></a>00430 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> spiSend(byte value)
|
|
<a name="l00431"></a>00431 {
|
|
<a name="l00432"></a>00432 SPDR = value;
|
|
<a name="l00433"></a>00433 <span class="keywordflow">while</span> (!(SPSR & _BV(SPIF)))
|
|
<a name="l00434"></a>00434 ; <span class="comment">// Wait for the transfer to complete.</span>
|
|
<a name="l00435"></a>00435 }
|
|
<a name="l00436"></a>00436
|
|
<a name="l00437"></a>00437 <span class="comment">// Flip the bits in a byte. Table generated by genflip.c</span>
|
|
<a name="l00438"></a>00438 <span class="keyword">static</span> <span class="keyword">const</span> uint8_t flipBits[256] PROGMEM = {
|
|
<a name="l00439"></a>00439 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0,
|
|
<a name="l00440"></a>00440 0x30, 0xB0, 0x70, 0xF0, 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
|
|
<a name="l00441"></a>00441 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, 0x04, 0x84, 0x44, 0xC4,
|
|
<a name="l00442"></a>00442 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
|
|
<a name="l00443"></a>00443 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC,
|
|
<a name="l00444"></a>00444 0x3C, 0xBC, 0x7C, 0xFC, 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
|
|
<a name="l00445"></a>00445 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, 0x0A, 0x8A, 0x4A, 0xCA,
|
|
<a name="l00446"></a>00446 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
|
|
<a name="l00447"></a>00447 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6,
|
|
<a name="l00448"></a>00448 0x36, 0xB6, 0x76, 0xF6, 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
|
|
<a name="l00449"></a>00449 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, 0x01, 0x81, 0x41, 0xC1,
|
|
<a name="l00450"></a>00450 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
|
|
<a name="l00451"></a>00451 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9,
|
|
<a name="l00452"></a>00452 0x39, 0xB9, 0x79, 0xF9, 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
|
|
<a name="l00453"></a>00453 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, 0x0D, 0x8D, 0x4D, 0xCD,
|
|
<a name="l00454"></a>00454 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
|
|
<a name="l00455"></a>00455 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3,
|
|
<a name="l00456"></a>00456 0x33, 0xB3, 0x73, 0xF3, 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
|
|
<a name="l00457"></a>00457 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, 0x07, 0x87, 0x47, 0xC7,
|
|
<a name="l00458"></a>00458 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
|
|
<a name="l00459"></a>00459 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF,
|
|
<a name="l00460"></a>00460 0x3F, 0xBF, 0x7F, 0xFF
|
|
<a name="l00461"></a>00461 };
|
|
<a name="l00462"></a>00462
|
|
<a name="l00478"></a><a class="code" href="classDMD.html#a9e4bf2a9d247312d35c1401ff61261c8">00478</a> <span class="keywordtype">void</span> <a class="code" href="classDMD.html#a9e4bf2a9d247312d35c1401ff61261c8" title="Refresh the display.">DMD::refresh</a>()
|
|
<a name="l00479"></a>00479 {
|
|
<a name="l00480"></a>00480 <span class="comment">// Bail out if there is a conflict on the SPI bus.</span>
|
|
<a name="l00481"></a>00481 <span class="keywordflow">if</span> (!digitalRead(DMD_PIN_SPI_SS))
|
|
<a name="l00482"></a>00482 <span class="keywordflow">return</span>;
|
|
<a name="l00483"></a>00483
|
|
<a name="l00484"></a>00484 <span class="comment">// Transfer the data for the next group of interleaved rows.</span>
|
|
<a name="l00485"></a>00485 <span class="keywordtype">int</span> stride4 = _stride * 4;
|
|
<a name="l00486"></a>00486 uint8_t *data0;
|
|
<a name="l00487"></a>00487 uint8_t *data1;
|
|
<a name="l00488"></a>00488 uint8_t *data2;
|
|
<a name="l00489"></a>00489 uint8_t *data3;
|
|
<a name="l00490"></a>00490 <span class="keywordtype">bool</span> flipRow = ((_height & 0x10) == 0);
|
|
<a name="l00491"></a>00491 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> y = 0; y < _height; y += 16) {
|
|
<a name="l00492"></a>00492 <span class="keywordflow">if</span> (!flipRow) {
|
|
<a name="l00493"></a>00493 <span class="comment">// The panels in this row are the right way up.</span>
|
|
<a name="l00494"></a>00494 data0 = displayfb + _stride * (y + phase);
|
|
<a name="l00495"></a>00495 data1 = data0 + stride4;
|
|
<a name="l00496"></a>00496 data2 = data1 + stride4;
|
|
<a name="l00497"></a>00497 data3 = data2 + stride4;
|
|
<a name="l00498"></a>00498 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> x = _stride; x > 0; --x) {
|
|
<a name="l00499"></a>00499 spiSend(*data3++);
|
|
<a name="l00500"></a>00500 spiSend(*data2++);
|
|
<a name="l00501"></a>00501 spiSend(*data1++);
|
|
<a name="l00502"></a>00502 spiSend(*data0++);
|
|
<a name="l00503"></a>00503 }
|
|
<a name="l00504"></a>00504 flipRow = <span class="keyword">true</span>;
|
|
<a name="l00505"></a>00505 } <span class="keywordflow">else</span> {
|
|
<a name="l00506"></a>00506 <span class="comment">// The panels in this row are upside-down and reversed.</span>
|
|
<a name="l00507"></a>00507 data0 = displayfb + _stride * (y + 16 - phase) - 1;
|
|
<a name="l00508"></a>00508 data1 = data0 - stride4;
|
|
<a name="l00509"></a>00509 data2 = data1 - stride4;
|
|
<a name="l00510"></a>00510 data3 = data2 - stride4;
|
|
<a name="l00511"></a>00511 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> x = _stride; x > 0; --x) {
|
|
<a name="l00512"></a>00512 spiSend(pgm_read_byte(&(flipBits[*data3--])));
|
|
<a name="l00513"></a>00513 spiSend(pgm_read_byte(&(flipBits[*data2--])));
|
|
<a name="l00514"></a>00514 spiSend(pgm_read_byte(&(flipBits[*data1--])));
|
|
<a name="l00515"></a>00515 spiSend(pgm_read_byte(&(flipBits[*data0--])));
|
|
<a name="l00516"></a>00516 }
|
|
<a name="l00517"></a>00517 flipRow = <span class="keyword">false</span>;
|
|
<a name="l00518"></a>00518 }
|
|
<a name="l00519"></a>00519 }
|
|
<a name="l00520"></a>00520
|
|
<a name="l00521"></a>00521 <span class="comment">// Latch the data from the shift registers onto the actual display.</span>
|
|
<a name="l00522"></a>00522 digitalWrite(DMD_PIN_OUTPUT_ENABLE, LOW);
|
|
<a name="l00523"></a>00523 digitalWrite(DMD_PIN_LATCH, HIGH);
|
|
<a name="l00524"></a>00524 digitalWrite(DMD_PIN_LATCH, LOW);
|
|
<a name="l00525"></a>00525 <span class="keywordflow">if</span> (phase & 0x02)
|
|
<a name="l00526"></a>00526 digitalWrite(DMD_PIN_PHASE_MSB, HIGH);
|
|
<a name="l00527"></a>00527 <span class="keywordflow">else</span>
|
|
<a name="l00528"></a>00528 digitalWrite(DMD_PIN_PHASE_MSB, LOW);
|
|
<a name="l00529"></a>00529 <span class="keywordflow">if</span> (phase & 0x01)
|
|
<a name="l00530"></a>00530 digitalWrite(DMD_PIN_PHASE_LSB, HIGH);
|
|
<a name="l00531"></a>00531 <span class="keywordflow">else</span>
|
|
<a name="l00532"></a>00532 digitalWrite(DMD_PIN_PHASE_LSB, LOW);
|
|
<a name="l00533"></a>00533 digitalWrite(DMD_PIN_OUTPUT_ENABLE, HIGH);
|
|
<a name="l00534"></a>00534 phase = (phase + 1) & 0x03;
|
|
<a name="l00535"></a>00535 }
|
|
<a name="l00536"></a>00536
|
|
<a name="l00563"></a><a class="code" href="classDMD.html#a4c3b04b384f3d656a9b59690836775e2">00563</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="l00564"></a>00564 {
|
|
<a name="l00565"></a>00565 <span class="comment">// Number of CPU cycles in the display's refresh period.</span>
|
|
<a name="l00566"></a>00566 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> numCycles = (F_CPU / 2000000) * DMD_REFRESH_US;
|
|
<a name="l00567"></a>00567
|
|
<a name="l00568"></a>00568 <span class="comment">// Determine the prescaler to be used.</span>
|
|
<a name="l00569"></a>00569 <span class="preprocessor"> #define TIMER1_RESOLUTION 65536UL</span>
|
|
<a name="l00570"></a>00570 <span class="preprocessor"></span> uint8_t prescaler;
|
|
<a name="l00571"></a>00571 <span class="keywordflow">if</span> (numCycles < TIMER1_RESOLUTION) {
|
|
<a name="l00572"></a>00572 <span class="comment">// No prescaling required.</span>
|
|
<a name="l00573"></a>00573 prescaler = _BV(CS10);
|
|
<a name="l00574"></a>00574 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (numCycles < TIMER1_RESOLUTION * 8) {
|
|
<a name="l00575"></a>00575 <span class="comment">// Prescaler = 8.</span>
|
|
<a name="l00576"></a>00576 prescaler = _BV(CS11);
|
|
<a name="l00577"></a>00577 numCycles >>= 3;
|
|
<a name="l00578"></a>00578 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (numCycles < TIMER1_RESOLUTION * 64) {
|
|
<a name="l00579"></a>00579 <span class="comment">// Prescaler = 64.</span>
|
|
<a name="l00580"></a>00580 prescaler = _BV(CS11) | _BV(CS10);
|
|
<a name="l00581"></a>00581 numCycles >>= 6;
|
|
<a name="l00582"></a>00582 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (numCycles < TIMER1_RESOLUTION * 256) {
|
|
<a name="l00583"></a>00583 <span class="comment">// Prescaler = 256.</span>
|
|
<a name="l00584"></a>00584 prescaler = _BV(CS12);
|
|
<a name="l00585"></a>00585 numCycles >>= 8;
|
|
<a name="l00586"></a>00586 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (numCycles < TIMER1_RESOLUTION * 1024) {
|
|
<a name="l00587"></a>00587 <span class="comment">// Prescaler = 1024.</span>
|
|
<a name="l00588"></a>00588 prescaler = _BV(CS12) | _BV(CS10);
|
|
<a name="l00589"></a>00589 numCycles >>= 10;
|
|
<a name="l00590"></a>00590 } <span class="keywordflow">else</span> {
|
|
<a name="l00591"></a>00591 <span class="comment">// Too long, so set the maximum timeout.</span>
|
|
<a name="l00592"></a>00592 prescaler = _BV(CS12) | _BV(CS10);
|
|
<a name="l00593"></a>00593 numCycles = TIMER1_RESOLUTION - 1;
|
|
<a name="l00594"></a>00594 }
|
|
<a name="l00595"></a>00595
|
|
<a name="l00596"></a>00596 <span class="comment">// Configure Timer1 for the period we want.</span>
|
|
<a name="l00597"></a>00597 TCCR1A = 0;
|
|
<a name="l00598"></a>00598 TCCR1B = _BV(WGM13);
|
|
<a name="l00599"></a>00599 uint8_t saveSREG = SREG;
|
|
<a name="l00600"></a>00600 cli();
|
|
<a name="l00601"></a>00601 ICR1 = numCycles;
|
|
<a name="l00602"></a>00602 SREG = saveSREG; <span class="comment">// Implicit sei() if interrupts were on previously.</span>
|
|
<a name="l00603"></a>00603 TCCR1B = (TCCR1B & ~(_BV(CS12) | _BV(CS11) | _BV(CS10))) | prescaler;
|
|
<a name="l00604"></a>00604
|
|
<a name="l00605"></a>00605 <span class="comment">// Turn on the Timer1 overflow interrupt.</span>
|
|
<a name="l00606"></a>00606 TIMSK1 |= _BV(TOIE1);
|
|
<a name="l00607"></a>00607 }
|
|
<a name="l00608"></a>00608
|
|
<a name="l00614"></a><a class="code" href="classDMD.html#a39af27e216f654ecc7e60b0614cb6b33">00614</a> <span class="keywordtype">void</span> <a class="code" href="classDMD.html#a39af27e216f654ecc7e60b0614cb6b33" title="Disables Timer1 overflow interrupts.">DMD::disableTimer1</a>()
|
|
<a name="l00615"></a>00615 {
|
|
<a name="l00616"></a>00616 <span class="comment">// Turn off the Timer1 overflow interrupt.</span>
|
|
<a name="l00617"></a>00617 TIMSK1 &= ~_BV(TOIE1);
|
|
<a name="l00618"></a>00618 }
|
|
<a name="l00619"></a>00619
|
|
<a name="l00646"></a><a class="code" href="classDMD.html#a5469775db7fafebca2cdbc6a6372fb97">00646</a> <span class="keywordtype">void</span> <a class="code" href="classDMD.html#a5469775db7fafebca2cdbc6a6372fb97" title="Enables Timer2 overflow interrupts for updating this display.">DMD::enableTimer2</a>()
|
|
<a name="l00647"></a>00647 {
|
|
<a name="l00648"></a>00648 <span class="comment">// Configure Timer2 for the period we want. With the prescaler set</span>
|
|
<a name="l00649"></a>00649 <span class="comment">// to 128, then 256 increments of Timer2 gives roughly 4 ms between</span>
|
|
<a name="l00650"></a>00650 <span class="comment">// overflows on a system with a 16 MHz clock. We adjust the prescaler</span>
|
|
<a name="l00651"></a>00651 <span class="comment">// accordingly for other clock frequencies.</span>
|
|
<a name="l00652"></a>00652 TCCR2A = 0;
|
|
<a name="l00653"></a>00653 <span class="keywordflow">if</span> (F_CPU >= 32000000)
|
|
<a name="l00654"></a>00654 TCCR2B = _BV(CS22) | _BV(CS21); <span class="comment">// Prescaler = 256</span>
|
|
<a name="l00655"></a>00655 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (F_CPU >= 16000000)
|
|
<a name="l00656"></a>00656 TCCR2B = _BV(CS22) | _BV(CS20); <span class="comment">// Prescaler = 128</span>
|
|
<a name="l00657"></a>00657 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (F_CPU >= 8000000)
|
|
<a name="l00658"></a>00658 TCCR2B = _BV(CS22); <span class="comment">// Prescaler = 64</span>
|
|
<a name="l00659"></a>00659 <span class="keywordflow">else</span>
|
|
<a name="l00660"></a>00660 TCCR2B = _BV(CS21) | _BV(CS20); <span class="comment">// Prescaler = 32</span>
|
|
<a name="l00661"></a>00661
|
|
<a name="l00662"></a>00662 <span class="comment">// Reset Timer2 to kick off the process.</span>
|
|
<a name="l00663"></a>00663 TCNT2 = 0;
|
|
<a name="l00664"></a>00664
|
|
<a name="l00665"></a>00665 <span class="comment">// Turn on the Timer2 overflow interrupt (also turn off OCIE2A and OCIE2B).</span>
|
|
<a name="l00666"></a>00666 TIMSK2 = _BV(TOIE2);
|
|
<a name="l00667"></a>00667 }
|
|
<a name="l00668"></a>00668
|
|
<a name="l00674"></a><a class="code" href="classDMD.html#a52fe885bfb380b74df54c96221811cff">00674</a> <span class="keywordtype">void</span> <a class="code" href="classDMD.html#a52fe885bfb380b74df54c96221811cff" title="Disables Timer2 overflow interrupts.">DMD::disableTimer2</a>()
|
|
<a name="l00675"></a>00675 {
|
|
<a name="l00676"></a>00676 <span class="comment">// Turn off the Timer2 overflow interrupt.</span>
|
|
<a name="l00677"></a>00677 TIMSK2 &= ~_BV(TOIE2);
|
|
<a name="l00678"></a>00678 }
|
|
<a name="l00679"></a>00679
|
|
<a name="l00690"></a><a class="code" href="classDMD.html#a557412f734fc4596e1102bf71e110ea0">00690</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="l00691"></a>00691 {
|
|
<a name="l00692"></a>00692 <span class="keywordflow">if</span> (r || g || b)
|
|
<a name="l00693"></a>00693 <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="l00694"></a>00694 <span class="keywordflow">else</span>
|
|
<a name="l00695"></a>00695 <span class="keywordflow">return</span> <a class="code" href="classBitmap.html#a2c7faeeb89d3624b5bbca58871785adc" title="Color value corresponding to "black".">Black</a>;
|
|
<a name="l00696"></a>00696 }
|
|
</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 Wed Jun 13 2012 15:22:29 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>
|