2008-10-12 16:46:01 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2009-06-11 22:17:47 +00:00
|
|
|
* Copyright (C) 2009 Bertrik Sikken
|
2008-10-12 16:46:01 +00:00
|
|
|
* Copyright (C) 2008 François Dinel
|
|
|
|
* Copyright (C) 2008 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "button-target.h"
|
|
|
|
#include "as3525.h"
|
2009-08-15 15:02:51 +00:00
|
|
|
#ifndef BOOTLOADER
|
|
|
|
#include "backlight.h"
|
|
|
|
#endif
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2009-06-11 22:17:47 +00:00
|
|
|
/* The Sansa Clip uses a button matrix that is scanned by selecting one of
|
|
|
|
three rows and reading back the button states from the columns.
|
|
|
|
|
|
|
|
In this driver, the row is changed at each call (i.e. once per tick).
|
|
|
|
In one tick, column data from one row is read back and then the next row
|
|
|
|
is selected for the following tick. This mechanism ensures that there is
|
|
|
|
plenty time between selecting a row and reading the columns, avoiding the
|
|
|
|
need for explicit delays.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2008-10-12 16:46:01 +00:00
|
|
|
void button_init_device(void)
|
|
|
|
{
|
|
|
|
GPIOA_DIR &= ~((1<<7) | (1<<3));
|
|
|
|
GPIOB_DIR &= ~((1<<2) | (1<<1) | (1<<0));
|
2009-06-11 22:17:47 +00:00
|
|
|
GPIOC_PIN(4) = 0;
|
|
|
|
GPIOC_PIN(5) = 0;
|
|
|
|
GPIOC_PIN(6) = 0;
|
2008-10-12 16:46:01 +00:00
|
|
|
GPIOC_DIR |= ((1<<6) | (1<<5) | (1<<4));
|
2009-06-11 22:17:47 +00:00
|
|
|
|
|
|
|
/* get initial readings */
|
|
|
|
button_read_device();
|
|
|
|
button_read_device();
|
|
|
|
button_read_device();
|
2008-10-12 16:46:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int button_read_device(void)
|
|
|
|
{
|
2009-06-11 22:17:47 +00:00
|
|
|
static int row = 0;
|
|
|
|
static int buttons = 0;
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2008-12-03 11:30:18 +00:00
|
|
|
if(button_hold())
|
2009-06-11 22:17:47 +00:00
|
|
|
return 0;
|
2008-12-03 11:30:18 +00:00
|
|
|
|
2008-10-12 16:46:01 +00:00
|
|
|
/* direct GPIO connections */
|
|
|
|
if (GPIOA_PIN(7))
|
2009-06-11 22:17:47 +00:00
|
|
|
buttons |= BUTTON_POWER;
|
|
|
|
else
|
|
|
|
buttons &= ~BUTTON_POWER;
|
2008-10-12 16:46:01 +00:00
|
|
|
|
|
|
|
/* This is a keypad using C4-C6 as columns and B0-B2 as rows */
|
2009-06-11 22:17:47 +00:00
|
|
|
switch (row) {
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
buttons &= ~(BUTTON_VOL_UP | BUTTON_UP);
|
|
|
|
|
|
|
|
(void)GPIOB_PIN(0); /* C4B0 is unused */
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2009-06-11 22:17:47 +00:00
|
|
|
if (GPIOB_PIN(1))
|
|
|
|
buttons |= BUTTON_VOL_UP;
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2009-06-11 22:17:47 +00:00
|
|
|
if (GPIOB_PIN(2))
|
|
|
|
buttons |= BUTTON_UP;
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2009-06-11 22:17:47 +00:00
|
|
|
GPIOC_PIN(4) = 0;
|
|
|
|
GPIOC_PIN(5) = (1<<5);
|
|
|
|
row++;
|
|
|
|
break;
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2009-06-11 22:17:47 +00:00
|
|
|
case 1:
|
|
|
|
buttons &= ~(BUTTON_LEFT | BUTTON_SELECT | BUTTON_RIGHT);
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2009-06-11 22:17:47 +00:00
|
|
|
if (GPIOB_PIN(0))
|
|
|
|
buttons |= BUTTON_LEFT;
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2009-06-11 22:17:47 +00:00
|
|
|
if (GPIOB_PIN(1))
|
|
|
|
buttons |= BUTTON_SELECT;
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2009-06-11 22:17:47 +00:00
|
|
|
if (GPIOB_PIN(2))
|
|
|
|
buttons |= BUTTON_RIGHT;
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2009-06-11 22:17:47 +00:00
|
|
|
GPIOC_PIN(5) = 0;
|
|
|
|
GPIOC_PIN(6) = (1<<6);
|
|
|
|
row++;
|
|
|
|
break;
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2009-06-11 22:17:47 +00:00
|
|
|
case 2:
|
|
|
|
buttons &= ~(BUTTON_DOWN | BUTTON_VOL_DOWN | BUTTON_HOME);
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2009-06-11 22:17:47 +00:00
|
|
|
if (GPIOB_PIN(0))
|
|
|
|
buttons |= BUTTON_DOWN;
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2009-06-11 22:17:47 +00:00
|
|
|
if (GPIOB_PIN(1))
|
|
|
|
buttons |= BUTTON_VOL_DOWN;
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2009-06-11 22:17:47 +00:00
|
|
|
if (GPIOB_PIN(2))
|
|
|
|
buttons |= BUTTON_HOME;
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2009-06-11 22:17:47 +00:00
|
|
|
GPIOC_PIN(6) = 0;
|
|
|
|
GPIOC_PIN(4) = (1<<4);
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2009-06-11 22:17:47 +00:00
|
|
|
default:
|
|
|
|
row = 0;
|
|
|
|
break;
|
|
|
|
}
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2009-06-11 22:17:47 +00:00
|
|
|
return buttons;
|
2008-10-12 16:46:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool button_hold(void)
|
|
|
|
{
|
2009-08-15 15:02:51 +00:00
|
|
|
#ifndef BOOTLOADER
|
|
|
|
static bool hold_button_old = false;
|
|
|
|
#endif
|
|
|
|
bool hold_button = (GPIOA_PIN(3) != 0);
|
|
|
|
|
|
|
|
#ifndef BOOTLOADER
|
|
|
|
/* light handling */
|
|
|
|
if (hold_button != hold_button_old)
|
|
|
|
{
|
|
|
|
hold_button_old = hold_button;
|
|
|
|
backlight_hold_changed(hold_button);
|
|
|
|
}
|
|
|
|
#endif /* BOOTLOADER */
|
|
|
|
|
|
|
|
return hold_button;
|
2008-10-12 16:46:01 +00:00
|
|
|
}
|