Smart Matrix
matrix.hpp
Go to the documentation of this file.
1 // ==========================================================================
2 //
3 // File : matrix.hpp
4 // Part of : led matrix library
5 // Copyright : mostafa@khattat.nl 2016
6 //
7 // led matrix implementation for an Arduino Due (ATSAM3X8E chip)
8 //
9 // Distributed under the Boost Software License, Version 1.0.
10 // (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
12 //
13 // ==========================================================================
15 
16 #ifndef MATRIX_H
17 #define MATRIX_H
18 
19 #include "hwlib.hpp"
20 #include "Screen.hpp"
21 #include "gamma.h"
22 #include "Image.hpp"
23 #include "String.hpp"
24 #include "Timer.hpp"
25 #include "AnimatedImage.hpp"
26 #include "Image.hpp"
27 #include "vector.hpp"
28 
29 
30 #define CBIT 8
31 #define ROW 16
32 #define COL 512
33 
34 namespace target = hwlib::target;
35 
37 //
40 class matrix : public Screen {
41 
42 public:
43 
45  //
49  matrix(int width, int height, bool double_buffer);
51  //
55  matrix(int width, int height, bool double_buffer, target::pin_out _lat,
56  target::pin_out _oe, target::pin_out _clk,
57  target::pin_out _selA, target::pin_out _selB,
58  target::pin_out _selC, target::pin_out _selD,
59  target::pin_out _b1, target::pin_out _g1,
60  target::pin_out _r1, target::pin_out _b2,
61  target::pin_out _g2, target::pin_out _r2);
63  //
66  //
69  void drawPixel(int x, int y, uint8_t rc, uint8_t gc, uint8_t bc) override;
71  //
74  //
77  void drawPixel(int x, int y, uint32_t color);
79  //
81  void fillScreen(uint8_t r, uint8_t g, uint8_t b) override;
83  //
85  void fillScreen(uint32_t color);
87  //
89  void clear() override;
91  //
94  void start() override;
96  //
99  void stop() override;
101  //
108  //
110  void swap_buffer(bool copy) override;
112  //
115  void update() override;
116  void update2();
117 
118  bool is_using_default_pins(){
119  return useDefault;
120  }
121 
122 private:
123 
124  void init();
125 
126  bool useDefault;
127 
129  uint8_t front_buffer[ROW*COL] = {};
131  uint8_t back_buffer[ROW*COL] = {};
133  uint8_t * current_buffer;
135  uint8_t * next_buffer;
136 
138  volatile int current_row, current_bit;
144  volatile bool double_buffer, swap_flag, swap_copy;
145 
147  volatile int t_delay;
148 
150  hwlib::target::pin_out _lat;
152  hwlib::target::pin_out _oe;
154  hwlib::target::pin_out _clk;
155 
157  hwlib::target::pin_out _selA;
159  hwlib::target::pin_out _selB;
161  hwlib::target::pin_out _selC;
163  hwlib::target::pin_out _selD;
164 
166  hwlib::target::pin_out _b1;
168  hwlib::target::pin_out _g1;
170  hwlib::target::pin_out _r1;
172  hwlib::target::pin_out _b2;
174  hwlib::target::pin_out _g2;
176  hwlib::target::pin_out _r2;
177 
178 //
179 };
180 
181 
182 #endif
void start() override
Start the auto update of the screen.
Definition: matrix.cpp:205
Led matrix implementation for the abstract class Screen.
Definition: matrix.hpp:40
The interface for led matrix and eventual other led screens.
Definition: Screen.hpp:28
void swap_buffer(bool copy) override
Swap the front buffer with the back buffer.
Definition: matrix.cpp:216
void drawPixel(int x, int y, uint8_t rc, uint8_t gc, uint8_t bc) override
Draw a given pixel with a color R G B.
Definition: matrix.cpp:133
void fillScreen(uint8_t r, uint8_t g, uint8_t b) override
Fill the entire screen with r g b colors.
Definition: matrix.cpp:189
void update() override
Update the screen.
Definition: matrix.cpp:301
void stop() override
Stop the auto update of the screen.
Definition: matrix.cpp:211
int width
width and height of the screen.
Definition: Screen.hpp:77
matrix(int width, int height, bool double_buffer)
Matrix constructor with default wiring.
Definition: matrix.cpp:8
void clear() override
Clear the entire screen.
Definition: matrix.cpp:128