Contiki 2.5
key.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 Swedish Institute of Computer Science
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in
12  * the documentation and/or other materials provided with the
13  * distribution.
14  * * Neither the name of the copyright holders nor the names of
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 /**
31  * \file
32  *
33  * \brief
34  * This file provides joystick operations. Combined with ADC functions.
35  *
36  * \author
37  * Mike Vidales mavida404@gmail.com
38  *
39  */
40 
41 #ifndef __KEY_H__
42 #define __KEY_H__
43 
44 #include <stdint.h>
45 #include <avr/io.h>
46 #include <avr/pgmspace.h>
47 
48 
49 
50 /** \name Port definition for reading the joystick input. */
51 /** \{ */
52 #define KEY_PORT PINF
53 #define KEY_PUR PORTF
54 #define KEY_DDR DDRF
55 #define KEY_PIN PINF1
56 /** \} */
57 
58 /** \name Port defininition for the joystick Enter button. */
59 /** \{ */
60 #define ENTER_PORT PINE
61 #define ENTER_PUR PORTE
62 #define ENTER_DDR DDRE
63 #define ENTER_PIN PINE2
64 /** \} */
65 
66 /** \name Valid Key States. */
67 /** \{ */
68 #define KEY_STATE_UP 0x01
69 #define KEY_STATE_DOWN 0x02
70 #define KEY_STATE_LEFT 0x04
71 #define KEY_STATE_RIGHT 0x08
72 #define KEY_STATE_ENTER 0x10
73 #define KEY_STATE_NO_KEY 0x00
74 #define KEY_STATE_DONE 0x20
75 /** \} */
76 
77 typedef enum {
78  KEY_UP = 0x01,
79  KEY_DOWN = 0x02,
80  KEY_LEFT = 0x04,
81  KEY_RIGHT = 0x08,
82  KEY_ENTER = 0x10,
83  KEY_NO_KEY = 0x00
84 }key_state_t;
85 
86 extern key_state_t button;
87 
88 /* Initialize the joystick */
89 void key_init(void);
90 void key_deinit(void);
91 key_state_t key_task(void);
92 key_state_t key_state_get(void);
93 uint8_t is_button(void);
94 uint8_t get_button(void);
95 
96 #endif /* __KEY_H__ */