MSP device support complete. NOT TESTED YET! Preliminary python host lib
[cerebrum.git] / avr / led.c
blob3ab063e8a28a94a1dcff05c481316d812d8cd973
2 #include "led.h"
3 #include <util/delay.h>
5 //The DDRs of the led matrix outputs are set in the mux loop.
6 void led_setup(void){}
8 #ifdef HAS_LED_SUPPORT
10 void swapBuffers(void){
11 uint8_t* tmp = frameBuffer;
12 frameBuffer = secondFrameBuffer;
13 secondFrameBuffer = tmp;
16 void setLED(int num, int val){
17 if(num<32){
18 frameBuffer[num>>3] &= ~(1<<(num&7));
19 if(val)
20 frameBuffer[num>>3] |= 1<<(num&7);
24 void led_loop(){
25 uint8_t row = 2; //selects the currently active "row" of the matrix. On the protoboards I make, this actually corresponds to physical traces.
26 for(int i=0; i<7; i++){
27 uint8_t DDRQ = frameBuffer[i];
28 uint8_t Q = ~DDRQ;
29 Q |= row;
30 DDRQ |= row;
31 row <<= 1;
32 led_output_stuff1(Q, DDRQ);
33 _delay_ms(1);
37 //this scary construct is in place to make the compiler happy. if you know a better way, feel free to improve.
38 uint8_t _frameBuffer[] = {0,0,0,0,0,0,0};
39 uint8_t _secondFrameBuffer[] = {0,0,0,0,0,0,0};
40 uint8_t* frameBuffer = _frameBuffer;
41 uint8_t* secondFrameBuffer = _secondFrameBuffer;
43 #else//HAS_LED_SUPPORT
45 void led_loop(){}
47 #endif//HAS_LED_SUPPORT