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 --- moodlamp.c | 5 ++- pwm.c | 19 ++++----- pwm.h | 2 +- shiftbrite.c | 133 ++++++++++++++++++++++++++++++++--------------------------- shiftbrite.h | 7 ++++ 5 files changed, 93 insertions(+), 73 deletions(-) diff --git a/moodlamp.c b/moodlamp.c index 6392a4e..47e7bdd 100644 --- a/moodlamp.c +++ b/moodlamp.c @@ -30,5 +30,8 @@ int main(void) sb_init(); sei(); - pwm_worker_loop(); + for (;;) { + pwm_tick(); + sb_tick(); + } } diff --git a/pwm.c b/pwm.c index cf7b854..3436e9f 100644 --- a/pwm.c +++ b/pwm.c @@ -20,6 +20,7 @@ #include #include #include +#include "shiftbrite.h" volatile uint16_t value_red = 3072; volatile uint16_t value_green = 2048; @@ -32,17 +33,15 @@ void pwm_set_rgb(uint8_t r, uint8_t g, uint8_t b) value_blue = b << 4; } -void pwm_worker_loop(void) +void pwm_tick(void) { - for (;;) { - for (uint16_t i = 0; i < 4096; i++) { - // this should take about the same time for each iteration, regardless of pulse width - PORTA= (PORTA & ~((1< i? (1< i? (1< i? (1< i? (1< i? (1< i? (1< #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<