Rev 1808 | Rev 2214 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1808 | Rev 2213 | ||
|---|---|---|---|
| Line 31... | Line 31... | ||
| 31 | 31 | ||
| 32 | #define OUTPUT 0 |
32 | #define OUTPUT 0 |
| 33 | #define INPUT 1 |
33 | #define INPUT 1 |
| 34 | 34 | ||
| 35 | volatile GrLcdStateType GrLcdState; |
35 | volatile GrLcdStateType GrLcdState; |
| 36 | uint8_t dotmatrixFramebuf[ |
36 | uint8_t dotmatrixFramebuf[dotmatrixSIZEY/8][dotmatrixSIZEX]; |
| 37 | uint8_t dotmatrixRowCounter=0; |
37 | uint8_t dotmatrixRowCounter=0; |
| 38 | 38 | ||
| 39 | /* Write a byte on SPI */ |
39 | /* Write a byte on SPI */ |
| 40 | void dotmatrixSPIWrite(uint8_t data) { |
40 | void dotmatrixSPIWrite(uint8_t data) { |
| 41 | uint8_t dummy = 0; |
41 | uint8_t dummy = 0; |
| Line 57... | Line 57... | ||
| 57 | 57 | ||
| 58 | /* Sets data into framebuffer, data arrives in a byte as a column */ |
58 | /* Sets data into framebuffer, data arrives in a byte as a column */ |
| 59 | void dotmatrixSetData(uint8_t Data) |
59 | void dotmatrixSetData(uint8_t Data) |
| 60 | { |
60 | { |
| 61 | /* Which ledmodule */ |
61 | /* Which ledmodule */ |
| 62 | uint8_t module = GrLcdState.lcdXAddr |
62 | uint8_t module = GrLcdState.lcdXAddr; |
| 63 | /* Which column in ledmodule */ |
63 | /* Which column in ledmodule */ |
| - | 64 | uint8_t column = GrLcdState.lcdYAddr/dotmatrixSIZEY; |
|
| 64 |
|
65 | //uint8_t column = GrLcdState.lcdXAddr%8; |
| 65 | /* Which row */ |
66 | /* Which row */ |
| 66 | // uint8_t row = GrLcdState.lcdYAddr%8; |
67 | // uint8_t row = GrLcdState.lcdYAddr%8; |
| 67 | 68 | ||
| 68 | /* Check panel size */ |
69 | /* Check panel size */ |
| 69 | if ((column < dotmatrixSIZEY) |
70 | if ((column < dotmatrixSIZEY/8) && (module < dotmatrixSIZEX)) |
| 70 | { |
71 | { |
| 71 | dotmatrixFramebuf[column][module] = Data; |
72 | dotmatrixFramebuf[column][module] = Data; |
| 72 | } |
73 | } |
| 73 | } |
74 | } |
| 74 | 75 | ||
| 75 | uint8_t dotmatrixGetData(void){ |
76 | uint8_t dotmatrixGetData(void){ |
| 76 | /* Which ledmodule */ |
77 | /* Which ledmodule */ |
| 77 | uint8_t module = GrLcdState.lcdXAddr |
78 | uint8_t module = GrLcdState.lcdXAddr; |
| 78 | /* Which column in ledmodule */ |
79 | /* Which column in ledmodule */ |
| 79 | uint8_t column = GrLcdState. |
80 | uint8_t column = GrLcdState.lcdYAddr/dotmatrixSIZEY; |
| 80 | /* Which row */ |
81 | /* Which row */ |
| 81 | // uint8_t row = GrLcdState.lcdYAddr%8; |
82 | // uint8_t row = GrLcdState.lcdYAddr%8; |
| 82 | 83 | ||
| 83 | /* Check panel size */ |
84 | /* Check panel size */ |
| 84 | if ((column < dotmatrixSIZEY) |
85 | if ((column < dotmatrixSIZEY/8) && (module < dotmatrixSIZEX)) |
| 85 | { |
86 | { |
| 86 | return (dotmatrixFramebuf[column][module]); |
87 | return (dotmatrixFramebuf[column][module]); |
| 87 | } |
88 | } |
| 88 | else |
89 | else |
| 89 | { |
90 | { |
| Line 161... | Line 162... | ||
| 161 | /* Callback run periodically to manage rows. |
162 | /* Callback run periodically to manage rows. |
| 162 | For each time callback is run, the next row is enabled and the last disabled |
163 | For each time callback is run, the next row is enabled and the last disabled |
| 163 | */ |
164 | */ |
| 164 | void dotmatrixRefresh() |
165 | void dotmatrixRefresh() |
| 165 | { |
166 | { |
| - | 167 | uint8_t col = 0; |
|
| 166 | /* Increase row counter */ |
168 | /* Increase row counter */ |
| 167 | if (dotmatrixRowCounter++ == 8) {dotmatrixRowCounter = 0;} |
169 | if (dotmatrixRowCounter++ == 8) {dotmatrixRowCounter = 0;} |
| 168 | 170 | ||
| - | 171 | ||
| - | 172 | /* Write one column of frame buffer to shift registers */ |
|
| - | 173 | for (col = 0; col < (dotmatrixSIZEX/8*dotmatrixSIZEY/8); col++) { |
|
| - | 174 | dotmatrixSPIWrite(dotmatrixFramebuf[0][col*8+dotmatrixRowCounter]); |
|
| - | 175 | } |
|
| - | 176 | ||
| 169 | /* Disable all rows */ |
177 | /* Disable all rows */ |
| 170 | gpio_clr_pin(dotmatrixROW_IO1); |
178 | gpio_clr_pin(dotmatrixROW_IO1); |
| 171 | gpio_clr_pin(dotmatrixROW_IO2); |
179 | gpio_clr_pin(dotmatrixROW_IO2); |
| 172 | gpio_clr_pin(dotmatrixROW_IO3); |
180 | gpio_clr_pin(dotmatrixROW_IO3); |
| 173 | gpio_clr_pin(dotmatrixROW_IO4); |
181 | gpio_clr_pin(dotmatrixROW_IO4); |
| 174 | gpio_clr_pin(dotmatrixROW_IO5); |
182 | gpio_clr_pin(dotmatrixROW_IO5); |
| 175 | gpio_clr_pin(dotmatrixROW_IO6); |
183 | gpio_clr_pin(dotmatrixROW_IO6); |
| 176 | gpio_clr_pin(dotmatrixROW_IO7); |
184 | gpio_clr_pin(dotmatrixROW_IO7); |
| 177 | gpio_clr_pin(dotmatrixROW_IO8); |
185 | gpio_clr_pin(dotmatrixROW_IO8); |
| 178 | 186 | ||
| 179 | /* Write one column of frame buffer to shift registers */ |
- | |
| 180 | dotmatrixSPIWrite(dotmatrixFramebuf[dotmatrixRowCounter][0]); |
- | |
| 181 | dotmatrixSPIWrite(dotmatrixFramebuf[dotmatrixRowCounter][1]); |
- | |
| 182 | dotmatrixSPIWrite(dotmatrixFramebuf[dotmatrixRowCounter][2]); |
- | |
| 183 | dotmatrixSPIWrite(dotmatrixFramebuf[dotmatrixRowCounter][3]); |
- | |
| 184 | /* Add more here to support 8-module panels */ |
- | |
| 185 | 187 | ||
| 186 | /* Toggle shift register latch */ |
188 | /* Toggle shift register latch */ |
| 187 | gpio_clr_pin(dotmatrixLATCHCLOCK_IO); |
189 | gpio_clr_pin(dotmatrixLATCHCLOCK_IO); |
| 188 | gpio_set_pin(dotmatrixLATCHCLOCK_IO); |
190 | gpio_set_pin(dotmatrixLATCHCLOCK_IO); |
| 189 | 191 | ||
| Line 242... | Line 244... | ||
| 242 | /* Set up PWM controlling brightness */ |
244 | /* Set up PWM controlling brightness */ |
| 243 | // TCCR0A |= (1<<COM0B1)|(1<<WGM01)|(1<<WGM00); |
245 | // TCCR0A |= (1<<COM0B1)|(1<<WGM01)|(1<<WGM00); |
| 244 | // TCCR0B |= (1<<CS00); |
246 | // TCCR0B |= (1<<CS00); |
| 245 | // OCR0B = 0xff-act_DotMatrix_INITIAL_BRIGHTNESS; |
247 | // OCR0B = 0xff-act_DotMatrix_INITIAL_BRIGHTNESS; |
| 246 | // DDRD |= (1<<PD5); |
248 | // DDRD |= (1<<PD5); |
| 247 | 249 | ||
| 248 | /* Set up output latch clock */ |
250 | /* Set up output latch clock */ |
| 249 | gpio_clr_pin(dotmatrixLATCHCLOCK_IO); |
251 | gpio_clr_pin(dotmatrixLATCHCLOCK_IO); |
| 250 | gpio_set_out(dotmatrixLATCHCLOCK_IO); |
252 | gpio_set_out(dotmatrixLATCHCLOCK_IO); |
| 251 | 253 | ||
| 252 | /* Initialize USART in SPI-mode */ |
254 | /* Initialize USART in SPI-mode */ |
| 253 | UBRR0 = 0; |
255 | UBRR0 = 0; |
| 254 | USART_SPI_XCK_DDR |= (1<<USART_SPI_XCK); // xck (sck) output |
256 | USART_SPI_XCK_DDR |= (1<<USART_SPI_XCK); // xck (sck) output |
| 255 | UCSR0C = (1<<UMSEL01)|(1<<UMSEL00)|(0<<UCPHA0)|(0<<UCPOL0); |
257 | UCSR0C = (1<<UMSEL01)|(1<<UMSEL00)|(0<<UCPHA0)|(0<<UCPOL0); |
| 256 | UCSR0B = (1<<RXEN0)|(1<<TXEN0); |
258 | UCSR0B = (1<<RXEN0)|(1<<TXEN0); |
| 257 | UBRR0 = |
259 | UBRR0 = 3; |
| 258 | 260 | ||
| 259 | dotmatrixClear(); |
261 | dotmatrixClear(); |
| 260 | 262 | ||
| 261 | GrLcdState.color = GLCD_COLOR_BLACK; |
263 | GrLcdState.color = GLCD_COLOR_BLACK; |
| 262 | } |
264 | } |
| 263 | 265 | ||
| 264 | void dotmatrixClear(){ |
266 | void dotmatrixClear(){ |
| 265 | /* Clear buffer memory */ |
267 | /* Clear buffer memory */ |
| 266 | for (uint8_t i=0; i< |
268 | for (uint8_t i=0; i<dotmatrixSIZEY; i++) |
| 267 | { |
269 | { |
| 268 | for (uint8_t j=0; j< |
270 | for (uint8_t j=0; j<(dotmatrixSIZEX/8); j++) |
| 269 | { |
271 | { |
| 270 | dotmatrixFramebuf[i][j] = dotmatrixINITIAL_ROW; |
272 | dotmatrixFramebuf[i][j] = dotmatrixINITIAL_ROW; |
| 271 | } |
273 | } |
| 272 | } |
274 | } |
| 273 | } |
275 | } |
| 274 | 276 | ||
| 275 | void dotmatrixSetXY(uint8_t x, uint8_t y){ |
277 | void dotmatrixSetXY(uint8_t x, uint8_t y){ |
| 276 | GrLcdState.lcdXAddr = x; |
278 | GrLcdState.lcdXAddr = x; |
| 277 | GrLcdState.lcdYAddr = y; |
279 | GrLcdState.lcdYAddr = y; |
| 278 | GrLcdState.lcdYpage = y/8; |
- | |
| 279 | } |
280 | } |
| 280 | 281 | ||
| 281 | uint8_t dotmatrixGetX(void){ |
282 | uint8_t dotmatrixGetX(void){ |
| 282 | return GrLcdState.lcdXAddr; |
283 | return GrLcdState.lcdXAddr; |
| 283 | } |
284 | } |