Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 136 lines (100 sloc) 4.284 kb
2f1a4c0 @solexious Initial commit
authored
1 /*
2 MatrixDisplay Library 2.0
3 Author: Miles Burton, www.milesburton.com/
4 Need a 16x24 display? Check out www.mnethardware.co.uk
5 Copyright (c) 2010 Miles Burton All Rights Reserved
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef MATRIX_DISPLAY_GUARD
23 #define MATRIX_DISPLAY_GUARD
24
25 #include <inttypes.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include <math.h>
29 #include <wiring.h>
30 #include "HardwareSerial.h"
31
32 #include "ht1632_cmd.h"
33 // No operation ASM instruction. Forces a delay
34 #define _nop() do { __asm__ __volatile__ ("nop"); } while (0)
35
36 class MatrixDisplay
37 {
38 private:
39 uint8_t *pShadowBuffers; // Will store the pixel data for each display
40 uint8_t *pDisplayBuffers; // Will store the pixel data for each display
41 uint8_t *pDisplayPins; // Will contain the pins for each CS
42
43 // Associated pins
44 uint8_t dataPin;
45 uint8_t clkPin;
46
47 uint8_t displayCount;
48 uint8_t backBufferSize;
49
50 // Converts a cartesian coordinate to a display index
51 uint8_t displayXYToIndex(uint8_t x, uint8_t y);
52
53 // Converts caretesian coordinate to the custom display buffer index
54 uint8_t xyToIndex(uint8_t x, uint8_t y);
55
56 // Enables/disables a specific display in the series
57 void selectDisplay(uint8_t displayNum);
58 void releaseDisplay(uint8_t displayNum);
59
60 // Todo combine methods using bitwise shift
61 // Writes data to the write MSB first
62 void writeDataBE(int8_t bitCount, uint8_t data, bool useNop = false);
63
64 // Writes data to the wire LSB first
65 void writeDataLE(int8_t bitCount, uint8_t data);
66
67 // Write command to write
68 void writeCommand(uint8_t displayNum, uint8_t command);
69
70 // High speed write to write (AtMega328 only)
71 void bitBlast(uint8_t pin, uint8_t data);
72
73 // Debug, write a byte to serial
74 void dumpByte(uint8_t byte);
75
76 // Debug
77 void preCommand(); // Sends 100 down the line
78
79 //TODO:
80 // Write Column
81 // Write Block etc
82 // Take advantage of progresswrite
83 public:
84 // Constructor
85 // Number of displays (1-4)
86 // Shared clock pin
87 // Shared data pin
88 MatrixDisplay(uint8_t numDisplays, uint8_t clkPin, uint8_t dataPin, bool buildShadow = false);
89
90 // Destructor
91 ~MatrixDisplay();
92
93 // Fetch a pixel from a specific one display coordinate
94 uint8_t getPixel(uint8_t displayNum, uint8_t x, uint8_t y, bool useShadow = false);
95
96 // Set pixel from a specific one display coordinate
97 void setPixel(uint8_t displayNum, uint8_t x, uint8_t y, uint8_t value, bool paint = false, bool useShadow = false);
98
99 // Initalise a display
100 void initDisplay(uint8_t displayNum, uint8_t pin, bool isMaster);
101
102 // Sync display using progressive write (Can be buggy, very fast)
103 void syncDisplays();
104
105 // Clear a single display.
106 // paint ? Send data to display : Only clear data
107 void clear(uint8_t displayNum, bool paint = false, bool useShadow = false);
108
109 // Clear all displays
110 void clear(bool paint = false, bool useShadow = false);
111
112 // Write a single nybble to the display (the display writes 4 bits at a time min)
113 void writeNibbles(uint8_t displayNum, uint8_t addr, uint8_t* data, uint8_t nybbleCount);
114
115 // Helper functions
116 uint8_t getDisplayCount();
117
118 // Defaults
119 uint8_t getDisplayHeight();
120 uint8_t getDisplayWidth();
121
122 // Shadow
123 void copyBuffer();
124
125 // Shift the buffer Left|Right
126 void shiftLeft();
127 void shiftRight();
128
129 // Set PWN brightness
130 void setBrightness(uint8_t dispNum, uint8_t pwmValue);
131
132
133 };
134
135 #endif
Something went wrong with that request. Please try again.