/* * Simple ShiftBrite interface code for remoodlamp firmware * Copyright 2012 (C) Johannes Kroll * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with This program. If not, see . * */ #include #include #include #include #include // shiftbrites connected to header labeled as 'aux', setup: // PC0 -> CI (clock) // PC1 -> LI (latch) // PC2 -> DI (data) #define SBCI PC0 #define SBLI PC1 #define SBDI PC2 #define MAXSHIFTBRITES 16 typedef struct rgb { uint16_t r, g, b; // 10-bit values } rgb_t; static volatile rgb_t sb_colors[MAXSHIFTBRITES]; // number of connected shiftbrites // todo: create a command to make this value configurable static volatile uint8_t sb_num_shiftbrites= 3; // toggle the latch so the shiftbrites accept new values static void sb_toggle_latch(void) { _delay_us(15); PORTC|= (1<=0; i--) { //_delay_us(clkdelay); PORTC&= ~(1<>i)&1) PORTC|= (1<=0; i--) sb_shiftout( (uint32_t)sb_colors[i].g | ((uint32_t)sb_colors[i].r<<10) | ((uint32_t)sb_colors[i].b<<20) ); sb_toggle_latch(); } // set the color of a shiftbrite. void sb_setcolor(uint8_t lamp_index, uint8_t r, uint8_t g, uint8_t b) { if(lamp_index>=MAXSHIFTBRITES) return; sb_colors[lamp_index].r= r<<2; sb_colors[lamp_index].g= g<<2; sb_colors[lamp_index].b= b<<2; sb_update_all_colors(); } #if 0 static void tmp_shiftbritetest(void) { sb_shiftout( (uint32_t)(100) | ((uint32_t)(120)<<10) | ((uint32_t)(100)<<20) | ((uint32_t)1<<30) ); sb_shiftout( (uint32_t)(100) | ((uint32_t)(120)<<10) | ((uint32_t)(100)<<20) | ((uint32_t)1<<30) ); sb_shiftout( (uint32_t)(100) | ((uint32_t)(120)<<10) | ((uint32_t)(100)<<20) | ((uint32_t)1<<30) ); _delay_us(15); PORTC|= (1<