summaryrefslogtreecommitdiff
path: root/src/common/led.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/led.c')
-rw-r--r--src/common/led.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/common/led.c b/src/common/led.c
new file mode 100644
index 0000000..16036f3
--- /dev/null
+++ b/src/common/led.c
@@ -0,0 +1,78 @@
+/* led.c */
+/* binwatch - Tiny binary wristwatch. {{{
+ *
+ * Copyright (C) 2010 Nicolas Schodet
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Contact :
+ * Web: http://ni.fr.eu.org/
+ * Email: <nico at ni.fr.eu.org>
+ * }}} */
+#include "common.h"
+#include "modules/utils/utils.h"
+#include "io.h"
+
+#include "led.h"
+
+/** Time a led is lit. */
+#define LED_UP_MS 0.05
+#define LED_DOWN_MS (0.5 - LED_UP_MS)
+
+struct led_t
+{
+ uint8_t ddr;
+ uint8_t port;
+};
+
+struct led_t led_tab[] =
+{
+ /* 432 1 432 1 */
+ { 0b001010, 0b000010 }, /* M0 */
+ { 0b001010, 0b001000 }, /* M1 */
+ { 0b010010, 0b000010 }, /* M2 */
+ { 0b010010, 0b010000 }, /* M3 */
+ { 0b100010, 0b000010 }, /* M4 */
+ { 0b100010, 0b100000 }, /* M5 */
+ { 0b011000, 0b001000 }, /* H0 */
+ { 0b011000, 0b010000 }, /* H1 */
+ { 0b101000, 0b001000 }, /* H2 */
+ { 0b101000, 0b100000 }, /* H3 */
+};
+
+void
+led_display (uint16_t leds, uint16_t duration)
+{
+ uint8_t l;
+ uint16_t i;
+ for (i = 0; i < duration; i++)
+ {
+ for (l = 0; l < UTILS_COUNT (led_tab); l++)
+ {
+ /* Turn on if selected. */
+ if (leds & (1u << l))
+ {
+ PORTB = led_tab[l].port;
+ DDRB = led_tab[l].ddr;
+ }
+ utils_delay_ms (LED_UP_MS);
+ /* Turn off, leds are too bright. */
+ DDRB = 0;
+ PORTB = 0;
+ utils_delay_ms (LED_DOWN_MS);
+ }
+ }
+}
+