2010-02-05 12:40:25 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 François Dinel
|
|
|
|
* Copyright © 2008-2009 Rafaël Carré
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-01-08 00:07:19 +00:00
|
|
|
#include "button.h"
|
2010-02-05 12:40:25 +00:00
|
|
|
#include "as3525v2.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
|
|
|
|
void button_init_device(void)
|
|
|
|
{
|
2010-02-22 10:02:05 +00:00
|
|
|
/* Set pins to input for reading buttons */
|
|
|
|
GPIOC_DIR = 0; /* All C pins input */
|
|
|
|
GPIOA_DIR &= ~(1<<1|1<<6|1<<7); /* Pins A1,A6,A7 input */
|
|
|
|
/* OF does not set D6 to input */
|
2017-12-09 21:36:58 +00:00
|
|
|
GPIOB_DIR |= (1<<6); /* Pin B6 output */
|
2010-02-22 10:02:05 +00:00
|
|
|
GPIOB_DIR |= (1<<0); /* Pin B0 set output */
|
2010-02-05 12:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int button_read_device(void)
|
|
|
|
{
|
2010-02-22 10:02:05 +00:00
|
|
|
int buttons = 0;
|
2010-02-15 19:29:47 +00:00
|
|
|
|
|
|
|
/* Buttons do not appear to need reset */
|
2017-12-09 21:36:58 +00:00
|
|
|
/* D6 does not appear to need special handling */
|
|
|
|
#if 0
|
2010-02-15 19:29:47 +00:00
|
|
|
GPIOB_PIN(0) = 1; /* set B0 */
|
|
|
|
|
|
|
|
int delay = 500;
|
|
|
|
do {
|
|
|
|
asm volatile("nop\n");
|
|
|
|
} while (delay--);
|
2017-12-09 21:36:58 +00:00
|
|
|
#endif
|
2010-02-15 19:29:47 +00:00
|
|
|
if GPIOD_PIN(6) /* read D6 */
|
|
|
|
buttons |= BUTTON_POWER;
|
2017-12-09 21:36:58 +00:00
|
|
|
#if 0
|
2010-02-15 19:29:47 +00:00
|
|
|
GPIOB_PIN(0) = 0; /* unset B0 */
|
|
|
|
|
|
|
|
delay = 240;
|
|
|
|
do {
|
|
|
|
asm volatile("nop\n");
|
|
|
|
} while (delay--);
|
2017-12-09 21:36:58 +00:00
|
|
|
#endif
|
2010-02-15 19:29:47 +00:00
|
|
|
|
|
|
|
if GPIOA_PIN(1)
|
|
|
|
buttons |= BUTTON_HOME;
|
|
|
|
if GPIOA_PIN(6)
|
|
|
|
buttons |= BUTTON_VOL_DOWN;
|
|
|
|
if GPIOA_PIN(7)
|
|
|
|
buttons |= BUTTON_VOL_UP;
|
2017-12-09 21:36:58 +00:00
|
|
|
|
|
|
|
if GPIOC_PIN(1)
|
|
|
|
buttons |= BUTTON_DOWN;
|
2010-02-15 19:29:47 +00:00
|
|
|
if GPIOC_PIN(2)
|
|
|
|
buttons |= BUTTON_UP;
|
|
|
|
if GPIOC_PIN(3)
|
|
|
|
buttons |= BUTTON_LEFT;
|
|
|
|
if GPIOC_PIN(4)
|
|
|
|
buttons |= BUTTON_SELECT;
|
|
|
|
if GPIOC_PIN(5)
|
|
|
|
buttons |= BUTTON_RIGHT;
|
|
|
|
|
|
|
|
return buttons;
|
2010-02-05 12:40:25 +00:00
|
|
|
}
|