From 753680192ced57c1183588aa4b6383f06ccba4ec Mon Sep 17 00:00:00 2001 From: Johannes Kroll Date: Tue, 6 Mar 2012 23:07:28 +0100 Subject: wip mult stuff --- shiftbrite.c | 133 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 72 insertions(+), 61 deletions(-) (limited to 'shiftbrite.c') diff --git a/shiftbrite.c b/shiftbrite.c index 5cc5b82..a5f319b 100644 --- a/shiftbrite.c +++ b/shiftbrite.c @@ -22,96 +22,101 @@ #include #include #include +#include +#include +#include "serial.h" -// shiftbrites connected to header labeled as 'aux', setup: -// PC0 -> CI (clock) -// PC1 -> LI (latch) -// PC2 -> DI (data) +/* 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 SBCI (1<=0; i--) { - //_delay_us(clkdelay); - PORTC&= ~(1<=0; i--) { + _delay_us(clkdelay); + PORTC&= ~SBCI; /* clock lo */ if((val>>i)&1) - PORTC|= (1<=0; i--) + for(int i = sb_num_shiftbrites-1; i>=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(); } +#endif - -// set the color of a shiftbrite. +/* 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; + if(lamp_index >= MAXSHIFTBRITES) return; + if(lamp_index+1 > sb_num_shiftbrites) sb_num_shiftbrites= lamp_index+1; + + sb_colors[lamp_index].r= r*r>>6; + sb_colors[lamp_index].g= g*g>>6; + sb_colors[lamp_index].b= b*b>>6; + + + char ch[256]; + sprintf(ch, "%" PRIx16 " %" PRIx16 " %" PRIx16 "\n", sb_colors[lamp_index].r, sb_colors[lamp_index].g, sb_colors[lamp_index].b); + serial_send(ch, strlen(ch), 1); + + /* works */ +/* + sb_colors[lamp_index].r= ((uint16_t)r*r>>6); + sb_colors[lamp_index].g= ((uint16_t)g*g>>6); + sb_colors[lamp_index].b= ((uint16_t)b*b>>6); +*/ +/* + updates are now done in sb_tick() 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<