2008-12-24 04:10:18 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id: button-e200v2.c 19035 2008-11-07 05:31:05Z jdgordon $
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Barry Wardell
|
|
|
|
*
|
|
|
|
* 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 "system.h"
|
2009-06-17 19:55:27 +00:00
|
|
|
#include "button-target.h"
|
2008-12-24 04:10:18 +00:00
|
|
|
#include "button.h"
|
|
|
|
#include "backlight.h"
|
|
|
|
#include "powermgmt.h"
|
|
|
|
|
|
|
|
|
2009-06-17 19:55:27 +00:00
|
|
|
unsigned short _dbop_din = 0;
|
|
|
|
|
|
|
|
/* in the lcd driver */
|
|
|
|
extern bool lcd_button_support(void);
|
|
|
|
|
2008-12-24 04:10:18 +00:00
|
|
|
static bool hold_button = false;
|
2009-06-17 19:55:27 +00:00
|
|
|
#ifndef BOOTLOADER
|
2008-12-24 04:10:18 +00:00
|
|
|
static bool hold_button_old = false;
|
2009-06-17 19:55:27 +00:00
|
|
|
#endif
|
2008-12-24 04:10:18 +00:00
|
|
|
|
|
|
|
void button_init_device(void)
|
|
|
|
{
|
2009-06-17 19:55:27 +00:00
|
|
|
GPIOA_DIR &= ~(1<<3);
|
2008-12-24 04:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool button_hold(void)
|
|
|
|
{
|
2009-06-17 19:55:27 +00:00
|
|
|
return hold_button;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void button_read_dbop(void)
|
|
|
|
{
|
|
|
|
/* Set up dbop for input */
|
|
|
|
DBOP_CTRL |= (1<<19); /* Tri-state DBOP on read cycle */
|
|
|
|
DBOP_CTRL &= ~(1<<16); /* disable output (1:write enabled) */
|
|
|
|
DBOP_TIMPOL_01 = 0xe167e167; /* Set Timing & Polarity regs 0 & 1 */
|
|
|
|
DBOP_TIMPOL_23 = 0xe167006e; /* Set Timing & Polarity regs 2 & 3 */
|
|
|
|
|
|
|
|
int i = 50;
|
|
|
|
while(i--) asm volatile ("nop\n");
|
|
|
|
|
|
|
|
DBOP_CTRL |= (1<<15); /* start read */
|
|
|
|
while (!(DBOP_STAT & (1<<16))); /* wait for valid data */
|
|
|
|
|
|
|
|
_dbop_din = DBOP_DIN; /* Read dbop data*/
|
|
|
|
|
|
|
|
/* Reset dbop for output */
|
|
|
|
DBOP_TIMPOL_01 = 0x6e167; /* Set Timing & Polarity regs 0 & 1 */
|
|
|
|
DBOP_TIMPOL_23 = 0xa167e06f; /* Set Timing & Polarity regs 2 & 3 */
|
|
|
|
DBOP_CTRL |= (1<<16); /* Enable output (0:write disable) */
|
|
|
|
DBOP_CTRL &= ~(1<<19); /* Tri-state when no active write */
|
2008-12-24 04:10:18 +00:00
|
|
|
}
|
|
|
|
|
2009-06-17 19:55:27 +00:00
|
|
|
/*
|
|
|
|
* Get button pressed from hardware
|
|
|
|
*/
|
|
|
|
int button_read_device(void)
|
2008-12-24 04:10:18 +00:00
|
|
|
{
|
2009-06-17 19:55:27 +00:00
|
|
|
int delay;
|
2008-12-24 04:10:18 +00:00
|
|
|
int dir_save_c = 0;
|
|
|
|
int afsel_save_c = 0;
|
2009-06-17 19:55:27 +00:00
|
|
|
int btn = BUTTON_NONE;
|
2008-12-24 04:10:18 +00:00
|
|
|
|
|
|
|
/* Save the current direction and afsel */
|
|
|
|
dir_save_c = GPIOC_DIR;
|
|
|
|
afsel_save_c = GPIOC_AFSEL;
|
|
|
|
|
|
|
|
GPIOC_AFSEL &= ~(1<<6|1<<5|1<<4|1<<3);
|
|
|
|
GPIOC_DIR |= (1<<6|1<<5|1<<4|1<<3);
|
|
|
|
|
|
|
|
/* These should not be needed with button event interupts */
|
|
|
|
/* they are necessary now to clear out lcd data */
|
|
|
|
|
|
|
|
GPIOC_PIN(6) = (1<<6);
|
|
|
|
GPIOC_PIN(5) = (1<<5);
|
|
|
|
GPIOC_PIN(4) = (1<<4);
|
|
|
|
GPIOC_PIN(3) = (1<<3);
|
|
|
|
GPIOC_DIR &= ~(1<<6|1<<5|1<<4|1<<3);
|
|
|
|
|
2009-06-17 19:55:27 +00:00
|
|
|
delay = 100;
|
|
|
|
while(delay--)
|
|
|
|
asm volatile("nop\n");
|
2008-12-24 04:10:18 +00:00
|
|
|
|
|
|
|
/* direct GPIO connections */
|
|
|
|
if (GPIOA_PIN(3))
|
2009-06-17 19:55:27 +00:00
|
|
|
btn |= BUTTON_POWER;
|
2008-12-24 04:10:18 +00:00
|
|
|
if (!GPIOC_PIN(6))
|
2009-06-17 19:55:27 +00:00
|
|
|
btn |= BUTTON_RIGHT;
|
2008-12-24 04:10:18 +00:00
|
|
|
if (!GPIOC_PIN(5))
|
2009-06-17 19:55:27 +00:00
|
|
|
btn |= BUTTON_UP;
|
2008-12-24 04:10:18 +00:00
|
|
|
if (!GPIOC_PIN(4))
|
2009-06-17 19:55:27 +00:00
|
|
|
btn |= BUTTON_SELECT;
|
2008-12-24 04:10:18 +00:00
|
|
|
if (!GPIOC_PIN(3))
|
2009-06-17 19:55:27 +00:00
|
|
|
btn |= BUTTON_DOWN;
|
2008-12-24 04:10:18 +00:00
|
|
|
|
|
|
|
/* return to settings needed for lcd */
|
|
|
|
GPIOC_DIR = dir_save_c;
|
|
|
|
GPIOC_AFSEL = afsel_save_c;
|
|
|
|
|
2009-06-17 19:55:27 +00:00
|
|
|
if(lcd_button_support())
|
|
|
|
button_read_dbop();
|
|
|
|
|
|
|
|
if(_dbop_din & (1<<6))
|
|
|
|
btn |= BUTTON_LEFT;
|
|
|
|
|
2008-12-24 04:10:18 +00:00
|
|
|
#ifndef BOOTLOADER
|
|
|
|
/* light handling */
|
|
|
|
if (hold_button != hold_button_old)
|
|
|
|
{
|
|
|
|
hold_button_old = hold_button;
|
|
|
|
backlight_hold_changed(hold_button);
|
|
|
|
}
|
|
|
|
#endif /* BOOTLOADER */
|
|
|
|
|
2009-06-17 19:55:27 +00:00
|
|
|
return btn;
|
2008-12-24 04:10:18 +00:00
|
|
|
}
|