From fcc01eeffbfe04ea907b950f58760443fb54d60d Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 14 Jun 2010 00:20:48 +0200 Subject: add common led control --- src/common/led.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/common/led.h | 31 ++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 src/common/led.c create mode 100644 src/common/led.h 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: + * }}} */ +#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); + } + } +} + diff --git a/src/common/led.h b/src/common/led.h new file mode 100644 index 0000000..e9bb1b3 --- /dev/null +++ b/src/common/led.h @@ -0,0 +1,31 @@ +#ifndef led_h +#define led_h +/* led.h */ +/* 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: + * }}} */ + +/** Display a binary number on leds during a duration (1 = 5 ms). */ +void +led_display (uint16_t leds, uint16_t duration); + +#endif /* led_h */ -- cgit v1.2.3