diff options
author | Johannes Kroll <jkroll@lavabit.com> | 2012-03-05 22:37:20 +0100 |
---|---|---|
committer | Johannes Kroll <jkroll@lavabit.com> | 2012-03-05 22:37:20 +0100 |
commit | f8bf5cf4bb61ef4b8c01c68dfc3fe826d9e91360 (patch) | |
tree | d73407be96e703141701a71156d179365928ce14 | |
parent | 9f0a3a5e2ad8b1b5707e1ceb99cccd42abdc5d0f (diff) |
pwm loop update
-rw-r--r-- | pwm.c | 22 |
1 files changed, 7 insertions, 15 deletions
@@ -35,21 +35,13 @@ void pwm_set_rgb(uint8_t r, uint8_t g, uint8_t b) void pwm_worker_loop(void) { for (;;) { - if (value_red) - PORTA |= (1 << PA0); - if (value_green) - PORTA |= (1 << PA1); - if (value_blue) - PORTA |= (1 << PA2); - - for (uint16_t i = 0; i < 4096; i++) { - if (value_red < i) - PORTA &= ~(1 << PA0); - if (value_green < i) - PORTA &= ~(1 << PA1); - if (value_blue < i) - PORTA &= ~(1 << PA2); - } + 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<<PA0)|(1<<PA1)|(1<<PA2))) | + (value_red > i? (1<<PA0): 0) | + (value_green > i? (1<<PA1): 0) | + (value_blue > i? (1<<PA2): 0); + } } } |