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)
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)
{
int i, val, ret = 0;
- for (i = index; i < (int)len; i++) {
- val = ascodec_read(i);
+ for (i = 0; i < (int)len; i++)
+ {
+ val = ascodec_read(i + index);
if (val >= 0) data[i] = val;
else ret = -1;
}
- return ret ?: i; /* i means success */
+ return (ret ?: (int)len);
}
/*
@@ -144,7 +145,8 @@ unsigned short adc_read(int channel)
unsigned char buf[2];
/* Read data */
- ascodec_readbytes(AS3514_ADC_0, sizeof(buf), buf);
+ if (ascodec_readbytes(AS3514_ADC_0, 2, buf) < 0)
+ return 0;
/* decode to 10-bit and return */
return (((buf[0] & 0x3) << 8) | buf[1]);