diff options
author | Bertrik Sikken <bertrik@sikken.nl> | 2009-07-09 20:17:47 +0000 |
---|---|---|
committer | Bertrik Sikken <bertrik@sikken.nl> | 2009-07-09 20:17:47 +0000 |
commit | 9ecde3d75c2986b566a46d55b5271f7298b4658d (patch) | |
tree | c50753d5255c48dbfde156a96d87a6a45cf959b4 /firmware/target/arm/s5l8700/adc-s5l8700.c | |
parent | 402b8ebeae49b498d725f85262a02e718c8c2f11 (diff) | |
download | rockbox-9ecde3d75c2986b566a46d55b5271f7298b4658d.tar.gz rockbox-9ecde3d75c2986b566a46d55b5271f7298b4658d.zip |
S5L8700: Implement ADC driver
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21734 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/s5l8700/adc-s5l8700.c')
-rw-r--r-- | firmware/target/arm/s5l8700/adc-s5l8700.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/firmware/target/arm/s5l8700/adc-s5l8700.c b/firmware/target/arm/s5l8700/adc-s5l8700.c new file mode 100644 index 0000000000..4407334099 --- /dev/null +++ b/firmware/target/arm/s5l8700/adc-s5l8700.c | |||
@@ -0,0 +1,94 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2009 by Bertrik Sikken | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | |||
24 | #include "inttypes.h" | ||
25 | #include "s5l8700.h" | ||
26 | #include "adc.h" | ||
27 | #include "adc-target.h" | ||
28 | #include "kernel.h" | ||
29 | |||
30 | /* Driver for the built-in ADC of the s5l8700 | ||
31 | |||
32 | The ADC is put into standby mode after each conversion. | ||
33 | */ | ||
34 | |||
35 | #define ADC_PRESCALER 100 /* 1MHz ADC clock, assuming 100 MHz PCLK */ | ||
36 | #define ADC_DEFAULT (1<<14) | /* prescale enable */ \ | ||
37 | ((ADC_PRESCALER-1)<<6) | /* prescaler */ \ | ||
38 | (0<<3) | /* sel_mux */ \ | ||
39 | (0<<2) | /* stdbm */ \ | ||
40 | (0<<1) | /* read_start */ \ | ||
41 | (0<<0) /* enable start */ \ | ||
42 | |||
43 | |||
44 | static struct mutex adc_mtx; | ||
45 | static struct wakeup adc_wakeup; | ||
46 | |||
47 | void INT_ADC(void) | ||
48 | { | ||
49 | wakeup_signal(&adc_wakeup); | ||
50 | } | ||
51 | |||
52 | unsigned short adc_read(int channel) | ||
53 | { | ||
54 | unsigned short data; | ||
55 | |||
56 | mutex_lock(&adc_mtx); | ||
57 | |||
58 | /* set channel and start conversion */ | ||
59 | ADCCON = ADC_DEFAULT | | ||
60 | (channel << 3) | | ||
61 | (1 << 0); /* enable start */ | ||
62 | |||
63 | /* wait for conversion */ | ||
64 | wakeup_wait(&adc_wakeup, TIMEOUT_BLOCK); | ||
65 | |||
66 | /* get the converted data */ | ||
67 | data = ADCDAT0; | ||
68 | |||
69 | /* put ADC back into standby */ | ||
70 | ADCCON |= (1 << 2); | ||
71 | |||
72 | mutex_unlock(&adc_mtx); | ||
73 | |||
74 | return data; | ||
75 | } | ||
76 | |||
77 | void adc_init(void) | ||
78 | { | ||
79 | mutex_init(&adc_mtx); | ||
80 | wakeup_init(&adc_wakeup); | ||
81 | |||
82 | /* enable clock to ADC */ | ||
83 | PWRCON &= ~(1 << 10); | ||
84 | |||
85 | /* configure ADC and put in standby */ | ||
86 | ADCCON = ADC_DEFAULT | (1 << 2); | ||
87 | |||
88 | /* configure conversion delay (use default) */ | ||
89 | ADCDLY = 0xFF; | ||
90 | |||
91 | /* enable interrupt */ | ||
92 | INTMSK |= (1 << 31); | ||
93 | } | ||
94 | |||