diff options
Diffstat (limited to 'firmware/target/arm/sandisk/adc-c200_e200.c')
-rw-r--r-- | firmware/target/arm/sandisk/adc-c200_e200.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/firmware/target/arm/sandisk/adc-c200_e200.c b/firmware/target/arm/sandisk/adc-c200_e200.c new file mode 100644 index 0000000000..31321ece37 --- /dev/null +++ b/firmware/target/arm/sandisk/adc-c200_e200.c | |||
@@ -0,0 +1,56 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 by Barry Wardell | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "adc.h" | ||
20 | #include "kernel.h" | ||
21 | #include "i2c-pp.h" | ||
22 | #include "as3514.h" | ||
23 | |||
24 | static struct mutex adc_mutex NOCACHEBSS_ATTR; | ||
25 | |||
26 | /* Read 10-bit channel data */ | ||
27 | unsigned short adc_read(int channel) | ||
28 | { | ||
29 | unsigned short data = 0; | ||
30 | |||
31 | if ((unsigned)channel < NUM_ADC_CHANNELS) | ||
32 | { | ||
33 | spinlock_lock(&adc_mutex); | ||
34 | |||
35 | /* Select channel */ | ||
36 | if (pp_i2c_send( AS3514_I2C_ADDR, ADC_0, (channel << 4)) >= 0) | ||
37 | { | ||
38 | unsigned char buf[2]; | ||
39 | |||
40 | /* Read data */ | ||
41 | if (i2c_readbytes( AS3514_I2C_ADDR, ADC_0, 2, buf) >= 0) | ||
42 | { | ||
43 | data = (((buf[0] & 0x3) << 8) | buf[1]); | ||
44 | } | ||
45 | } | ||
46 | |||
47 | spinlock_unlock(&adc_mutex); | ||
48 | } | ||
49 | |||
50 | return data; | ||
51 | } | ||
52 | |||
53 | void adc_init(void) | ||
54 | { | ||
55 | spinlock_init(&adc_mutex); | ||
56 | } | ||