16FXlib
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
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;
30
BUTTONS_DDR
= ~(
BUTTON_MASK
);
31
BUTTONS_PIER
=
BUTTON_MASK
;
32
}
33
34
int8_t
buttons_get
(
uint8_t
pin) {
35
if
(
_BV
(pin) &
BUTTON_MASK
)
36
return
((~
BUTTONS_PORT
) &
_BV
(pin)) >> pin;
37
return
-1;
38
}
39
40
int8_t
buttons_event
(
uint8_t
pin) {
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
}
buttons.h
BUTTONS_PORT
#define BUTTONS_PORT
Port used by the buttons.
Definition:
buttons.cfg.h:35
_BV
#define _BV(bit)
Definition:
util.h:39
buttons_get
int8_t buttons_get(uint8_t pin)
Definition:
buttons.c:34
uint8_t
unsigned char uint8_t
Definition:
inttypes.h:35
int8_t
char int8_t
Definition:
inttypes.h:45
BUTTONS_PIER
#define BUTTONS_PIER
Input enable register for the port.
Definition:
buttons.cfg.h:39
BUTTONS_DDR
#define BUTTONS_DDR
Direction register for the port.
Definition:
buttons.cfg.h:37
BUTTON_MASK
#define BUTTON_MASK
Button mask.
Definition:
buttons.cfg.h:46
buttons.cfg.h
buttons_init
void buttons_init(void)
Definition:
buttons.c:28
buttons_event
int8_t buttons_event(uint8_t pin)
Definition:
buttons.c:40
tud-cpp-16FXlib
buttons.c
Generated on Fri Aug 7 2015 16:08:32 for 16FXlib by
1.8.9.1