2006-10-16 17:21:36 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Barry Wardell
|
|
|
|
*
|
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.
|
2006-10-16 17:21:36 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "adc.h"
|
2007-07-12 04:19:21 +00:00
|
|
|
#include "kernel.h"
|
2008-10-31 00:16:42 +00:00
|
|
|
#include "ascodec.h"
|
2007-03-13 01:50:13 +00:00
|
|
|
#include "as3514.h"
|
2006-10-16 17:21:36 +00:00
|
|
|
|
|
|
|
/* Read 10-bit channel data */
|
|
|
|
unsigned short adc_read(int channel)
|
|
|
|
{
|
2007-02-20 15:55:38 +00:00
|
|
|
unsigned short data = 0;
|
2006-10-16 17:21:36 +00:00
|
|
|
|
2007-07-12 04:19:21 +00:00
|
|
|
if ((unsigned)channel < NUM_ADC_CHANNELS)
|
|
|
|
{
|
2008-10-31 00:16:42 +00:00
|
|
|
ascodec_lock();
|
2007-07-12 04:19:21 +00:00
|
|
|
|
|
|
|
/* Select channel */
|
2008-10-31 00:16:42 +00:00
|
|
|
if (ascodec_write(AS3514_ADC_0, (channel << 4)) >= 0)
|
2007-07-12 04:19:21 +00:00
|
|
|
{
|
|
|
|
unsigned char buf[2];
|
|
|
|
|
2010-03-23 05:02:37 +00:00
|
|
|
/*
|
|
|
|
* The AS3514 ADC will trigger an interrupt when the conversion
|
|
|
|
* is finished, if the corresponding enable bit in IRQ_ENRD2
|
|
|
|
* is set.
|
|
|
|
* Previously the code did not wait and this apparently did
|
|
|
|
* not pose any problems, but this should be more correct.
|
|
|
|
* Without the wait the data read back may be completely or
|
|
|
|
* partially (first one of the two bytes) stale.
|
|
|
|
*/
|
|
|
|
ascodec_wait_adc_finished();
|
|
|
|
|
|
|
|
|
2007-07-12 04:19:21 +00:00
|
|
|
/* Read data */
|
2008-10-31 00:16:42 +00:00
|
|
|
if (ascodec_readbytes(AS3514_ADC_0, 2, buf) >= 0)
|
2007-07-12 04:19:21 +00:00
|
|
|
{
|
|
|
|
data = (((buf[0] & 0x3) << 8) | buf[1]);
|
|
|
|
}
|
|
|
|
}
|
2007-03-13 01:50:13 +00:00
|
|
|
|
2008-10-31 00:16:42 +00:00
|
|
|
ascodec_unlock();
|
2007-07-12 04:19:21 +00:00
|
|
|
}
|
2007-03-13 01:50:13 +00:00
|
|
|
|
2007-02-20 15:55:38 +00:00
|
|
|
return data;
|
2006-10-16 17:21:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void adc_init(void)
|
|
|
|
{
|
|
|
|
}
|