Improved error handling during code generation
[cerebrum.git] / avr / led_matrix.c.tp
blobb98caee26e9d341bec6eda67b67d7b3fdf723dab
1 /*
2  Copyright (C) 2012 jaseg <s@jaseg.de>
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License
6  version 3 as published by the Free Software Foundation.
7  */
9 #include <avr/io.h>
10 #include <util/delay.h>
12 ${modulevar("raw_buffer", "uint8_t", "7B", 7)};
14 //FIXME this is *definitely* not elegant.
15 ${modulevar("buffer", "uint8_t", "28B", 28, callbacks=(0, 1))};
16 void ${setter("buffer")}(const comm_callback_descriptor* cb, void* argbuf_end){
17         uint8_t t = 0;
18         for(uint8_t i = 7; i>0; i--){
19         ${modulevar("raw_buffer")}[i-1] = 0;
20                 for(uint8_t j = 0; j<i; j++){
21                         ${modulevar("raw_buffer")}[i-1] |= ${modulevar("buffer")}[t]<<j;
22                         t++;
23                 }
24         }
25         uart_putc(0x00);
26         uart_putc(0x00);
29 void ${loop_function()} (){
30         static uint8_t i = 0;
31         static uint8_t row = 2; //selects the currently active "row" of the matrix. On the
32                                                         //protoboards I make, this more or less corresponds to physical traces.
33         uint8_t data = ${modulevar("raw_buffer")}[i];
34         DDR${member["port"]}  = 0; //FIXME This is supposed to prevent "ghosting". Is it really necessary?
35     PORT${member["port"]} = 0;
36 % if member.get("inverted", False):
37         PORT${member["port"]} = ~data | row;
38 % else:
39         PORT${member["port"]} = data;
40 % endif
41         DDR${member["port"]}  = data | row;
42         i++;
43         row <<= 1;
44         if(row == 0){
45                 row = 2;
46                 i = 0;
47         }
48     _delay_ms(1);