summaryrefslogtreecommitdiff
path: root/pwm.c
diff options
context:
space:
mode:
Diffstat (limited to 'pwm.c')
-rw-r--r--pwm.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/pwm.c b/pwm.c
new file mode 100644
index 0000000..e981e2d
--- /dev/null
+++ b/pwm.c
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2012 (C) Christian Franke <nobody at nowhere dot ws>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <avr/interrupt.h>
+#include <avr/io.h>
+#include <stdint.h>
+#include <string.h>
+
+volatile uint16_t value_red = 3072;
+volatile uint16_t value_green = 2048;
+volatile uint16_t value_blue = 1024;
+
+void pwm_set_rgb(uint8_t r, uint8_t g, uint8_t b)
+{
+ value_red = r << 4;
+ value_green = g << 4;
+ value_blue = b << 4;
+}
+
+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);
+ }
+ }
+}
+
+void pwm_init(void)
+{
+ PORTA = 0x00;
+ DDRA = (1 << PA0) | (1 << PA1) | (1 << PA2);
+}