aboutsummaryrefslogtreecommitdiff
path: root/kernel/rgb.c
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2011-03-11 01:28:00 +0000
committerDimitri Sokolyuk <demon@dim13.org>2011-03-11 01:28:00 +0000
commitb8335062ae7d19bd27e6131fadcd7d3a116c4992 (patch)
tree3bd226885fb6f2ca24ee300a44d7b51ffb8d2706 /kernel/rgb.c
DimOS RT
Diffstat (limited to 'kernel/rgb.c')
-rw-r--r--kernel/rgb.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/kernel/rgb.c b/kernel/rgb.c
new file mode 100644
index 0000000..c1aefde
--- /dev/null
+++ b/kernel/rgb.c
@@ -0,0 +1,79 @@
+/* $Id$ */
+/*
+ * Copyright (c) 2011 Dimitri Sokolyuk <demon@dim13.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <inttypes.h>
+#include <avr/io.h>
+#include "kernel.h"
+#include "tasks.h"
+
+void hsv(uint8_t *, uint8_t *, uint8_t *, uint16_t, uint8_t, uint8_t);
+
+/*
+struct pwmarg pwmargs[] = {
+ { &red, PB2, 0, 0 },
+ { &green, PB3, 0, 0 },
+ { &blue, PB4, 0, 0 },
+};
+ */
+
+void
+rgb(void *arg)
+{
+ struct rgbarg *a = (struct rgbarg *)arg;
+ uint32_t d = deadline();
+ uint32_t r = release();
+ uint16_t i = 0;
+ uint8_t v;
+
+ for (;;) {
+ i = (i + 1) % 360;
+ v = i % 120;
+ v = (v < 60) ? 255 - 2 * v : 15 + 2 * v;
+
+ hsv(a->r, a->g, a->b, i, 255, v);
+
+ r = d + MSEC(28);
+ d = r + MSEC(2);
+ update(r, d);
+ }
+}
+
+void
+pwm(void *arg)
+{
+#define SCALE 4
+ struct pwmarg *a = (struct pwmarg *)arg;
+ a->d = deadline();
+ a->r = release();
+
+ DDRB |= _BV(a->pin);
+ PORTB &= ~_BV(a->pin);
+
+ for (;;) {
+ if (*a->value > 0) {
+ PORTB |= _BV(a->pin);
+ a->r = a->d += USEC(*a->value << SCALE);
+ update(a->r, a->d);
+ }
+
+ if (*a->value < 255) {
+ PORTB &= ~_BV(a->pin);
+ a->r = a->d += USEC((255 - *a->value) << SCALE);
+ update(a->r, a->d);
+ }
+ }
+}