2007-09-20 04:46:41 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2007-09-22 06:04:14 +00:00
|
|
|
* $Id$
|
2007-09-20 04:46:41 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Karl Kurbjun
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* 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.
|
2007-09-20 04:46:41 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "cpu.h"
|
2008-09-10 20:14:22 +00:00
|
|
|
#include "adc.h"
|
2007-09-20 04:46:41 +00:00
|
|
|
#include "adc-target.h"
|
|
|
|
#include "kernel.h"
|
2009-04-28 05:07:25 +00:00
|
|
|
#include "tsc2100.h"
|
|
|
|
#include "button-target.h"
|
2007-09-20 04:46:41 +00:00
|
|
|
|
|
|
|
void adc_init(void)
|
|
|
|
{
|
2009-04-28 05:07:25 +00:00
|
|
|
/* Initialize the touchscreen and the battery readout */
|
|
|
|
tsc2100_adc_init();
|
|
|
|
|
|
|
|
/* Enable the tsc2100 interrupt */
|
|
|
|
IO_INTC_EINT2 |= (1<<3); /* IRQ_GIO14 */
|
2007-09-20 04:46:41 +00:00
|
|
|
}
|
|
|
|
|
2009-04-28 05:07:25 +00:00
|
|
|
/* Touchscreen data available interupt */
|
|
|
|
void GIO14(void)
|
2007-09-20 04:46:41 +00:00
|
|
|
{
|
2009-06-24 04:17:15 +00:00
|
|
|
/* Interrupts work properly when cleared first */
|
|
|
|
IO_INTC_IRQ2 = (1<<3); /* IRQ_GIO14 == 35 */
|
|
|
|
|
2009-04-28 05:07:25 +00:00
|
|
|
short tsadc = tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS);
|
|
|
|
short adscm = (tsadc&TSADC_ADSCM_MASK)>>TSADC_ADSCM_SHIFT;
|
|
|
|
|
|
|
|
/* Always read all registers in one go to clear any missed flags */
|
|
|
|
tsc2100_read_data();
|
|
|
|
|
|
|
|
switch (adscm)
|
|
|
|
{
|
2009-05-02 23:25:55 +00:00
|
|
|
case 0x01:
|
|
|
|
case 0x02:
|
|
|
|
case 0x03:
|
|
|
|
case 0x04:
|
|
|
|
case 0x05:
|
|
|
|
/* do a battery read - this will shutdown the adc till the next tick
|
|
|
|
*/
|
|
|
|
// tsc2100_set_mode(true, 0x0B);
|
2009-04-28 05:07:25 +00:00
|
|
|
break;
|
2009-05-02 23:25:55 +00:00
|
|
|
case 0x06:
|
|
|
|
case 0x07:
|
|
|
|
case 0x08:
|
|
|
|
case 0x09:
|
2009-04-28 05:07:25 +00:00
|
|
|
case 0x0B:
|
2009-05-02 23:25:55 +00:00
|
|
|
tsc2100_set_mode(true, 0x01);
|
2009-04-28 05:07:25 +00:00
|
|
|
break;
|
2009-06-24 04:17:15 +00:00
|
|
|
}
|
2007-09-20 04:46:41 +00:00
|
|
|
}
|
2009-05-02 23:25:55 +00:00
|
|
|
|