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)
|
|
|
|
{
|
2017-01-21 13:04:43 +00:00
|
|
|
unsigned short data = 0;
|
|
|
|
|
|
|
|
if ((unsigned)channel >= NUM_ADC_CHANNELS)
|
|
|
|
return 0;
|
2007-07-12 04:19:21 +00:00
|
|
|
|
2010-05-15 19:44:54 +00:00
|
|
|
ascodec_lock();
|
2007-07-12 04:19:21 +00:00
|
|
|
|
2010-05-15 19:44:54 +00:00
|
|
|
/* Select channel */
|
2016-02-20 03:36:26 +00:00
|
|
|
ascodec_write(AS3514_ADC_0, (channel << 4));
|
2017-01-21 13:04:43 +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();
|
|
|
|
|
2010-03-23 05:02:37 +00:00
|
|
|
|
2017-01-21 13:04:43 +00:00
|
|
|
/* Read data */
|
|
|
|
unsigned char buf[2] = { 0, 0 };
|
2016-02-20 03:36:26 +00:00
|
|
|
ascodec_readbytes(AS3514_ADC_0, 2, buf);
|
2017-01-21 13:04:43 +00:00
|
|
|
data = (((buf[0] & 0x3) << 8) | buf[1]);
|
2010-05-15 19:44:54 +00:00
|
|
|
|
|
|
|
ascodec_unlock();
|
2016-02-20 03:36:26 +00:00
|
|
|
|
2017-01-21 13:04:43 +00:00
|
|
|
return data;
|
2006-10-16 17:21:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void adc_init(void)
|
|
|
|
{
|
|
|
|
}
|