Newer
Older
matrix4x5 / keypad.h
/**
 *   @file keypad.h
 *
 *   @date 01.02.2015
 * @author Pascal Gollor
 *     web http://www.pgollor.de
 *
 * @copyright Dieses Werk ist unter einer Creative Commons Lizenz vom Typ
 * Namensnennung - Weitergabe unter gleichen Bedingungen 3.0 Deutschland zugänglich.
 * Um eine Kopie dieser Lizenz einzusehen, konsultieren Sie
 * http://creativecommons.org/licenses/by-sa/3.0/de/ oder wenden Sie sich
 * brieflich an Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
 *
 * -- englisch version --
 * @n This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Germany License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
 *
 */

#ifndef __KEYPAD_H__
#define __KEYPAD_H__


#include <avr/io.h>


/**
 * @brief define x-axis channels (columns)
 *
 * all channels have to be at the same port site by site
 */
#define KEYPAD_COLUMNS 4
#define KEYPAD_COLUMN_REGISTER DDRD
#define KEYPAD_COLUMN_IN PIND
#define KEYPAD_COLUMN_OUT PORTD
#define KEYPAD_COLUMN_FIRST_CHANNEL 2 // 2 means PD2, PD3, PD4, PD5 for 4 columns

/**
 * @brief define y-axis channels (rows)
 *
 * all channels have to be at the same port site by site
 */
#define KEYPAD_ROWS 5
#define KEYPAD_ROW_REGISTER DDRC
#define KEYPAD_ROW_IN PINC
#define KEYPAD_ROW_OUT PORTC
#define KEYPAD_ROW_FIRST_CHANNEL 0 // 0 means PC0, PC1, PC2, PC3, PC4 for 5 rows


/**
 * @brief uncomment this to enable debug output over uart
 */
//#define KEYPAD_DEBUG


// do not change afters this
#define KEYPAD_COLUMN_BITS ( ((1 << KEYPAD_COLUMNS) - 1) << KEYPAD_COLUMN_FIRST_CHANNEL )
#define KEYPAD_ROW_BITS ( ((1 << KEYPAD_ROWS) - 1) << KEYPAD_ROW_FIRST_CHANNEL )
//#define KEYPAD_COLUMN_BITS 0b11110000
//#define KEYPAD_ROW_BITS 0b11111000

#define KEYPAD_NO_VALID_KEY 0xff


void keypad_init(void);
uint8_t keypad_getKey(void);
uint8_t keypad_getKeyAndWait(void);


#endif // __KEYPAD_H__