16FXlib
buttons.c
Go to the documentation of this file.
1 
2 //*****************************************************************************
3 // Author : Christian Illy
4 // Created : 20.04.2009
5 // Revised : 04.06.2009
6 // Version : 0.1
7 // Target MCU : Fujitsu MB96300 series
8 //
9 // This program is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 //
22 //*****************************************************************************
23 
24 #include "mb96348hs.h"
25 #include "buttons.h"
26 #include "buttons.cfg.h"
27 
28 void buttons_init(void) {
29  BUTTONS_PORT = 0x00;
32 }
33 
35  if (_BV(pin) & BUTTON_MASK)
36  return ((~BUTTONS_PORT) & _BV(pin)) >> pin;
37  return -1;
38 }
39 
41  static uint8_t buttonState = 0xff;
42  if (_BV(pin) & BUTTON_MASK) {
43  uint8_t s = buttons_get(pin);
44  if (s != ((buttonState >> pin) & 1)) {
45  buttonState &= ~(1 << pin);
46  buttonState |= s << pin;
47  if (s == 1)
48  return 1;
49  }
50  return 0;
51  }
52  return -1;
53 }
#define BUTTONS_PORT
Port used by the buttons.
Definition: buttons.cfg.h:35
#define _BV(bit)
Definition: util.h:39
int8_t buttons_get(uint8_t pin)
Definition: buttons.c:34
unsigned char uint8_t
Definition: inttypes.h:35
char int8_t
Definition: inttypes.h:45
#define BUTTONS_PIER
Input enable register for the port.
Definition: buttons.cfg.h:39
#define BUTTONS_DDR
Direction register for the port.
Definition: buttons.cfg.h:37
#define BUTTON_MASK
Button mask.
Definition: buttons.cfg.h:46
void buttons_init(void)
Definition: buttons.c:28
int8_t buttons_event(uint8_t pin)
Definition: buttons.c:40