2009-12-31 19:15:20 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2010-03-15 23:01:45 +00:00
|
|
|
* Copyright (C) 2009 Bertrik Sikken
|
2009-12-31 19:15:20 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2010-03-15 23:01:45 +00:00
|
|
|
#include "system.h"
|
2009-12-31 19:15:20 +00:00
|
|
|
#include "button-target.h"
|
|
|
|
#include "as3525v2.h"
|
2010-03-15 23:01:45 +00:00
|
|
|
#ifndef BOOTLOADER
|
|
|
|
#include "backlight.h"
|
|
|
|
#endif
|
2009-12-31 19:15:20 +00:00
|
|
|
|
|
|
|
void button_init_device(void)
|
|
|
|
{
|
|
|
|
GPIOA_DIR &= ~((1<<7) | (1<<3));
|
|
|
|
GPIOD_DIR &= ~((1<<2) | (1<<1) | (1<<0));
|
|
|
|
GPIOD_PIN(3) = 1<<3;
|
|
|
|
GPIOD_PIN(4) = 1<<4;
|
|
|
|
GPIOD_PIN(5) = 1<<5;
|
|
|
|
GPIOD_DIR |= ((1<<5) | (1<<4) | (1<<3));
|
2010-03-15 23:01:45 +00:00
|
|
|
|
|
|
|
/* get initial readings */
|
|
|
|
button_read_device();
|
|
|
|
button_read_device();
|
|
|
|
button_read_device();
|
2009-12-31 19:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int button_read_device(void)
|
|
|
|
{
|
2010-03-15 23:01:45 +00:00
|
|
|
static int row = 0;
|
|
|
|
static int buttons = 0;
|
2009-12-31 19:15:20 +00:00
|
|
|
static unsigned power_counter = 0;
|
|
|
|
|
|
|
|
if(button_hold())
|
|
|
|
{
|
|
|
|
power_counter = HZ;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* direct GPIO connections */
|
|
|
|
/* read power, but not if hold button was just released, since
|
|
|
|
* you basically always hit power due to the slider mechanism after
|
|
|
|
* releasing hold (wait 1 sec) */
|
|
|
|
if (power_counter)
|
|
|
|
power_counter--;
|
|
|
|
|
|
|
|
if (GPIOA_PIN(7) && !power_counter)
|
2010-03-15 23:01:45 +00:00
|
|
|
buttons |= BUTTON_POWER;
|
|
|
|
else
|
|
|
|
buttons &= ~BUTTON_POWER;
|
2009-12-31 19:15:20 +00:00
|
|
|
|
|
|
|
/* This is a keypad using D3-D5 as columns and D0-D2 as rows */
|
2010-03-15 23:01:45 +00:00
|
|
|
switch (row) {
|
2009-12-31 19:15:20 +00:00
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
case 0:
|
|
|
|
buttons &= ~(BUTTON_VOL_UP | BUTTON_UP);
|
2009-12-31 19:15:20 +00:00
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
(void)GPIOD_PIN(0); /* D3D0 is unused */
|
2009-12-31 19:15:20 +00:00
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
if (!GPIOD_PIN(1))
|
|
|
|
buttons |= BUTTON_VOL_UP;
|
2009-12-31 19:15:20 +00:00
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
if (!GPIOD_PIN(2))
|
|
|
|
buttons |= BUTTON_UP;
|
2009-12-31 19:15:20 +00:00
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
GPIOD_PIN(3) = 1<<3;
|
|
|
|
GPIOD_PIN(4) = 0x00;
|
|
|
|
row++;
|
|
|
|
break;
|
2009-12-31 19:15:20 +00:00
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
case 1:
|
|
|
|
buttons &= ~(BUTTON_LEFT | BUTTON_SELECT | BUTTON_RIGHT);
|
2009-12-31 19:15:20 +00:00
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
if (!GPIOD_PIN(0))
|
|
|
|
buttons |= BUTTON_LEFT;
|
2009-12-31 19:15:20 +00:00
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
if (!GPIOD_PIN(1))
|
|
|
|
buttons |= BUTTON_SELECT;
|
2009-12-31 19:15:20 +00:00
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
if (!GPIOD_PIN(2))
|
|
|
|
buttons |= BUTTON_RIGHT;
|
2009-12-31 19:15:20 +00:00
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
GPIOD_PIN(4) = 1<<4;
|
|
|
|
GPIOD_PIN(5) = 0x00;
|
|
|
|
row++;
|
|
|
|
break;
|
2009-12-31 19:15:20 +00:00
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
case 2:
|
|
|
|
buttons &= ~(BUTTON_DOWN | BUTTON_VOL_DOWN | BUTTON_HOME);
|
2009-12-31 19:15:20 +00:00
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
if (!GPIOD_PIN(0))
|
|
|
|
buttons |= BUTTON_DOWN;
|
2009-12-31 19:15:20 +00:00
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
if (!GPIOD_PIN(1))
|
|
|
|
buttons |= BUTTON_VOL_DOWN;
|
2009-12-31 19:15:20 +00:00
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
if (!GPIOD_PIN(2))
|
|
|
|
buttons |= BUTTON_HOME;
|
2009-12-31 19:15:20 +00:00
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
GPIOD_PIN(5) = 1<<5;
|
|
|
|
GPIOD_PIN(3) = 0x00;
|
2009-12-31 19:15:20 +00:00
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
default:
|
|
|
|
row = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buttons;
|
2009-12-31 19:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool button_hold(void)
|
|
|
|
{
|
2010-03-15 23:01:45 +00:00
|
|
|
#ifndef BOOTLOADER
|
|
|
|
static bool hold_button_old = false;
|
|
|
|
#endif
|
2010-04-03 22:33:47 +00:00
|
|
|
|
|
|
|
GPIOA_DIR |= 1<<7;
|
|
|
|
GPIOA_PIN(7) = 1<<7;
|
|
|
|
|
|
|
|
int delay = 50;
|
|
|
|
while(delay--)
|
|
|
|
asm("nop");
|
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
bool hold_button = (GPIOA_PIN(3) != 0);
|
|
|
|
|
2010-04-03 22:33:47 +00:00
|
|
|
GPIOA_PIN(7) = 0;
|
|
|
|
GPIOA_DIR &= ~(1<<7);
|
|
|
|
|
2010-03-15 23:01:45 +00:00
|
|
|
#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;
|
2009-12-31 19:15:20 +00:00
|
|
|
}
|