summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/target/arm/adc-as3514.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/firmware/target/arm/adc-as3514.c b/firmware/target/arm/adc-as3514.c
index 77d65455fb..8c661eb133 100644
--- a/firmware/target/arm/adc-as3514.c
+++ b/firmware/target/arm/adc-as3514.c
@@ -28,36 +28,36 @@ unsigned short adc_read(int channel)
28{ 28{
29 unsigned short data = 0; 29 unsigned short data = 0;
30 30
31 if ((unsigned)channel < NUM_ADC_CHANNELS) 31 if ((unsigned)channel >= NUM_ADC_CHANNELS)
32 { 32 return 0;
33 ascodec_lock();
34 33
35 /* Select channel */ 34 ascodec_lock();
36 if (ascodec_write(AS3514_ADC_0, (channel << 4)) >= 0)
37 {
38 unsigned char buf[2];
39 35
40 /* 36 /* Select channel */
41 * The AS3514 ADC will trigger an interrupt when the conversion 37 if (ascodec_write(AS3514_ADC_0, (channel << 4)) >= 0)
42 * is finished, if the corresponding enable bit in IRQ_ENRD2 38 {
43 * is set. 39 unsigned char buf[2];
44 * Previously the code did not wait and this apparently did
45 * not pose any problems, but this should be more correct.
46 * Without the wait the data read back may be completely or
47 * partially (first one of the two bytes) stale.
48 */
49 ascodec_wait_adc_finished();
50 40
41 /*
42 * The AS3514 ADC will trigger an interrupt when the conversion
43 * is finished, if the corresponding enable bit in IRQ_ENRD2
44 * is set.
45 * Previously the code did not wait and this apparently did
46 * not pose any problems, but this should be more correct.
47 * Without the wait the data read back may be completely or
48 * partially (first one of the two bytes) stale.
49 */
50 ascodec_wait_adc_finished();
51 51
52 /* Read data */
53 if (ascodec_readbytes(AS3514_ADC_0, 2, buf) >= 0)
54 {
55 data = (((buf[0] & 0x3) << 8) | buf[1]);
56 }
57 }
58 52
59 ascodec_unlock(); 53 /* Read data */
54 if (ascodec_readbytes(AS3514_ADC_0, 2, buf) >= 0)
55 {
56 data = (((buf[0] & 0x3) << 8) | buf[1]);
57 }
60 } 58 }
59
60 ascodec_unlock();
61 61
62 return data; 62 return data;
63} 63}