summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2011-06-14 00:32:46 +0200
committerNicolas Schodet2011-09-26 19:41:29 +0200
commitcbcfce6e5b75b66deacb559858cb9acc7a4e2d52 (patch)
tree159484aa63a5b48e4081c59dd76556c78e92e728
parentba617778ee01eaf7d0ed64709a472f082839c923 (diff)
src/binwatch: add first basic program
-rw-r--r--src/binwatch/Makefile6
-rw-r--r--src/binwatch/avrconfig.h26
-rw-r--r--src/binwatch/binwatch.c81
3 files changed, 112 insertions, 1 deletions
diff --git a/src/binwatch/Makefile b/src/binwatch/Makefile
index 43bf9db..e123a2c 100644
--- a/src/binwatch/Makefile
+++ b/src/binwatch/Makefile
@@ -1,7 +1,9 @@
BASE = $b/digital/avr
-AVR_PROGS = counter
+AVR_PROGS = counter binwatch
counter_SOURCES = counter.c led.c button.c
+binwatch_SOURCES = binwatch.c led.c rtc.c button.c
MODULES = utils
+binwatch_MODULES = utils twi
CONFIGFILE = avrconfig.h
# atmega8, atmega8535, atmega128...
AVR_MCU = attiny85
@@ -13,3 +15,5 @@ INCLUDES = -I.. -I.
vpath %.c ../common
include $(BASE)/make/Makefile.gen
+
+all: bin
diff --git a/src/binwatch/avrconfig.h b/src/binwatch/avrconfig.h
index eae41be..a6e4fdb 100644
--- a/src/binwatch/avrconfig.h
+++ b/src/binwatch/avrconfig.h
@@ -29,5 +29,31 @@
* 8000000, 11059200, 14745600, 16000000, 18432000, 20000000. */
#define AC_FREQ 1000000
+/* twi - TWI module. */
+/** Driver to implement TWI: HARD, SOFT, or USI. */
+#define AC_TWI_DRIVER SOFT
+/** Do not use interrupts. */
+#define AC_TWI_NO_INTERRUPT 0
+/** TWI frequency, should really be 100 kHz. */
+#define AC_TWI_FREQ 100000
+/** Enable slave part. */
+#define AC_TWI_SLAVE_ENABLE 0
+/** Enable master part. */
+#define AC_TWI_MASTER_ENABLE 1
+/** Use polled slave mode: received data is stored in a buffer which can be
+ * polled using twi_slave_poll. */
+#define AC_TWI_SLAVE_POLLED 0
+/** Slave reception callback to be defined by the user when not in polled
+ * mode. */
+#undef AC_TWI_SLAVE_RECV
+/** Master transfer completion callback, optionally defined by the user, called
+ * at end of master transfer. */
+#undef AC_TWI_MASTER_DONE
+/** Use internal pull up. */
+#define AC_TWI_PULL_UP 1
+/** SDA line IO for SOFT driver. */
+#define AC_TWI_SOFT_SDA_IO B, 0
+/** SCL line IO for SOFT driver. */
+#define AC_TWI_SOFT_SCL_IO B, 2
#endif /* avrconfig_h */
diff --git a/src/binwatch/binwatch.c b/src/binwatch/binwatch.c
new file mode 100644
index 0000000..de48181
--- /dev/null
+++ b/src/binwatch/binwatch.c
@@ -0,0 +1,81 @@
+/* binwatch.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 "io.h"
+#include "common/led.h"
+#include "common/rtc.h"
+#include "common/button.h"
+
+/** Get time in leds format. */
+static uint16_t
+binwatch_get_time (void)
+{
+ uint8_t hour, minute, second;
+ rtc_get_time (&hour, &minute, &second);
+ hour = hour % 12;
+ if (hour == 0)
+ hour = 12;
+ return hour << 6 | minute;
+}
+
+int
+main (void)
+{
+ /* Initialise hardware. */
+ led_init ();
+ button_init ();
+ /* Initialise RTC. */
+ uint8_t init;
+ init = rtc_init ();
+ if (!init)
+ {
+ /* Initialisation failed, blink! */
+ while (1)
+ {
+ led_display (0x3f, LED_100MS);
+ led_display (0, 9 * LED_100MS);
+ }
+ }
+ else
+ {
+ /* Initialisation ok, display current time. */
+ uint16_t time;
+ time = binwatch_get_time ();
+ led_display (time, 3 * LED_1S);
+ /* If low voltage detected, wait user press to let clock go. */
+ if (init == RTC_LOW_VOLTAGE)
+ {
+ button_wait ();
+ rtc_go ();
+ led_display (time, 3 * LED_1S);
+ }
+ /* Wait user press to display time. */
+ while (1)
+ {
+ button_wait ();
+ time = binwatch_get_time ();
+ led_display (time, 3 * LED_1S);
+ }
+ }
+}
+