2008-10-19 14:11:01 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 by ??
|
|
|
|
*
|
|
|
|
* 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "adc.h"
|
|
|
|
|
|
|
|
void button_init_device(void)
|
|
|
|
{
|
2008-10-25 15:57:18 +00:00
|
|
|
GPIOA_DIR &= ~((1<<3) | (1<<2) | (1<<1) | (1<<0)); /* A3-A0 is input */
|
|
|
|
GPIOA_DIR |= ((1<<6) | (1<<5) | (1<<4)); /* A4-A6 row outputs */
|
2008-10-19 14:11:01 +00:00
|
|
|
}
|
|
|
|
|
2008-11-14 21:57:43 +00:00
|
|
|
/* short delay is needed between raising a colum pin, and reading the row pin. values is arbitraty */
|
|
|
|
static inline void btn_delay(void) { int i = 5; while(i--) ; }
|
|
|
|
|
2008-10-19 14:11:01 +00:00
|
|
|
int button_read_device(void)
|
|
|
|
{
|
2008-10-25 15:57:18 +00:00
|
|
|
int result = BUTTON_NONE;
|
2008-12-03 18:41:02 +00:00
|
|
|
if(button_hold())
|
|
|
|
return result;
|
2008-11-14 21:57:43 +00:00
|
|
|
|
2008-10-25 15:57:18 +00:00
|
|
|
/* direct GPIO connections */
|
|
|
|
if (GPIOA_PIN(3))
|
2008-12-12 19:50:49 +00:00
|
|
|
result |= BUTTON_POWER;
|
2008-10-25 15:57:18 +00:00
|
|
|
|
|
|
|
/* This is a keypad using A4-A6 as columns and A0-A2 as rows */
|
|
|
|
GPIOA_PIN(4) = (1<<4);
|
2008-11-14 21:57:43 +00:00
|
|
|
btn_delay();
|
2008-12-03 18:41:02 +00:00
|
|
|
|
2008-10-25 15:57:18 +00:00
|
|
|
/* A4A0 is unused */
|
|
|
|
|
|
|
|
if (GPIOA_PIN(1))
|
2008-12-12 19:50:49 +00:00
|
|
|
result |= BUTTON_VOL_DOWN;
|
2008-10-25 15:57:18 +00:00
|
|
|
|
|
|
|
if (GPIOA_PIN(2))
|
2008-12-12 19:50:49 +00:00
|
|
|
result |= BUTTON_UP;
|
2008-10-25 15:57:18 +00:00
|
|
|
|
|
|
|
GPIOA_PIN(4) = 0x00;
|
|
|
|
|
|
|
|
GPIOA_PIN(5) = (1<<5);
|
2008-11-14 21:57:43 +00:00
|
|
|
btn_delay();
|
|
|
|
|
2008-10-25 15:57:18 +00:00
|
|
|
if (GPIOA_PIN(0))
|
|
|
|
result |= BUTTON_LEFT;
|
|
|
|
|
|
|
|
if (GPIOA_PIN(1))
|
|
|
|
result |= BUTTON_SELECT;
|
|
|
|
|
|
|
|
if (GPIOA_PIN(2))
|
|
|
|
result |= BUTTON_RIGHT;
|
|
|
|
|
|
|
|
GPIOA_PIN(5) = 0x00;
|
|
|
|
|
|
|
|
|
|
|
|
GPIOA_PIN(6) = (1<<6);
|
2008-11-14 21:57:43 +00:00
|
|
|
btn_delay();
|
|
|
|
|
2008-10-25 15:57:18 +00:00
|
|
|
if (GPIOA_PIN(0))
|
2008-12-12 19:50:49 +00:00
|
|
|
result |= BUTTON_DOWN;
|
2008-10-25 15:57:18 +00:00
|
|
|
|
|
|
|
if (GPIOA_PIN(1))
|
2008-12-12 19:50:49 +00:00
|
|
|
result |= BUTTON_VOL_UP;
|
2008-10-25 15:57:18 +00:00
|
|
|
|
2008-12-03 18:41:02 +00:00
|
|
|
/* hold button is read in button_hold() */
|
2008-11-14 21:57:43 +00:00
|
|
|
|
2008-10-25 15:57:18 +00:00
|
|
|
GPIOA_PIN(6) = 0x00;
|
2008-10-19 14:11:01 +00:00
|
|
|
|
2008-10-25 15:57:18 +00:00
|
|
|
return result;
|
2008-10-19 14:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool button_hold(void)
|
|
|
|
{
|
2008-10-25 15:57:18 +00:00
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
GPIOA_PIN(6) = (1<<6);
|
|
|
|
if (GPIOA_PIN(2))
|
|
|
|
ret = true;
|
|
|
|
GPIOA_PIN(6) = 0x00;
|
|
|
|
|
|
|
|
return ret;
|
2008-10-19 14:11:01 +00:00
|
|
|
}
|