summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-12-25 18:23:17 +0000
committerThomas Martitz <kugel@rockbox.org>2011-12-25 18:23:17 +0000
commit16784598ac550dab147ea8ee15634a2f15739fff (patch)
tree07b9e6a517e77ce2be5e12ea81c93e096297604f
parent1dcc834e5954cfd662e501565d265c3d0c8d9cae (diff)
downloadrockbox-16784598ac550dab147ea8ee15634a2f15739fff.tar.gz
rockbox-16784598ac550dab147ea8ee15634a2f15739fff.zip
ypr0: Fix ascodec_readbytes().
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31429 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/target/hosted/ypr0/ascodec-ypr0.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/firmware/target/hosted/ypr0/ascodec-ypr0.c b/firmware/target/hosted/ypr0/ascodec-ypr0.c
index b3bc48290f..ec5568554b 100644
--- a/firmware/target/hosted/ypr0/ascodec-ypr0.c
+++ b/firmware/target/hosted/ypr0/ascodec-ypr0.c
@@ -104,13 +104,14 @@ int ascodec_readbytes(unsigned int index, unsigned int len, unsigned char *data)
104{ 104{
105 int i, val, ret = 0; 105 int i, val, ret = 0;
106 106
107 for (i = index; i < (int)len; i++) { 107 for (i = 0; i < (int)len; i++)
108 val = ascodec_read(i); 108 {
109 val = ascodec_read(i + index);
109 if (val >= 0) data[i] = val; 110 if (val >= 0) data[i] = val;
110 else ret = -1; 111 else ret = -1;
111 } 112 }
112 113
113 return ret ?: i; /* i means success */ 114 return (ret ?: (int)len);
114} 115}
115 116
116/* 117/*
@@ -144,7 +145,8 @@ unsigned short adc_read(int channel)
144 unsigned char buf[2]; 145 unsigned char buf[2];
145 146
146 /* Read data */ 147 /* Read data */
147 ascodec_readbytes(AS3514_ADC_0, sizeof(buf), buf); 148 if (ascodec_readbytes(AS3514_ADC_0, 2, buf) < 0)
149 return 0;
148 150
149 /* decode to 10-bit and return */ 151 /* decode to 10-bit and return */
150 return (((buf[0] & 0x3) << 8) | buf[1]); 152 return (((buf[0] & 0x3) << 8) | buf[1]);