From 932c73a6405792aa134d122f946dbaa1bff696ff Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sun, 18 Jul 2010 23:52:32 +0200 Subject: src/common: add button --- src/common/button.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/common/button.h | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/common/button.c create mode 100644 src/common/button.h diff --git a/src/common/button.c b/src/common/button.c new file mode 100644 index 0000000..716941d --- /dev/null +++ b/src/common/button.c @@ -0,0 +1,45 @@ +/* button.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 "io.h" +#include "button.h" + +/** Button port. */ +#define BUTTON_IO B, 1 + +void +button_init (void) +{ + /* Button is shared with leds, no PORT init. */ +} + +void +button_wait (void) +{ + /* Wait until button is pressed. */ + while (IO_GET (BUTTON_IO)) + ; + /* Wait until button is released. */ + while (!IO_GET (BUTTON_IO)) + ; +} diff --git a/src/common/button.h b/src/common/button.h new file mode 100644 index 0000000..e76211a --- /dev/null +++ b/src/common/button.h @@ -0,0 +1,35 @@ +#ifndef button_h +#define button_h +/* button.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: + * }}} */ + +/** Initialise button. */ +void +button_init (void); + +/** Wait until the button is pressed and released. */ +void +button_wait (void); + +#endif /* button_h */ -- cgit v1.2.3