Production Test Program (PTP) for the LPC4088 Experiment Base Board
Dependencies: EALib I2S LM75B SDFileSystem mbed
Revision 7:48375cb50f3a, committed 2014-09-25
- Comitter:
- embeddedartists
- Date:
- Thu Sep 25 07:17:44 2014 +0000
- Parent:
- 6:4d97917c7dea
- Child:
- 8:b7d6f967617e
- Commit message:
- Fixed audio test volume issues and issues with the touch controller.
Changed in this revision
--- a/AR1021I2C.cpp Tue Sep 09 14:20:12 2014 +0000 +++ b/AR1021I2C.cpp Thu Sep 25 07:17:44 2014 +0000 @@ -78,6 +78,8 @@ #define AR1021_TIMEOUT 1000 //how many ms to wait for responce #define AR1021_RETRY 5 //how many times to retry sending command +#define AR1021_MIN(__a, __b) (((__a)<(__b))?(__a):(__b)) + AR1021I2C::AR1021I2C(PinName sda, PinName scl, PinName siq) : _i2c(sda, scl), _siq(siq), _siqIrq(siq) @@ -338,7 +340,7 @@ bool setCsOff) { int ret = 0; - char buff[10]; + int readLen = (respLen == NULL) ? 0 : *respLen; for (int attempt = 1; attempt <= AR1021_RETRY; attempt++) { if (attempt > 1) { wait_ms(50); @@ -375,55 +377,52 @@ // --------------- // 0x55 len status cmd data // 0x55 = header - // len = number of bytes following the len byte + // len = number of bytes following the len byte (i.e. including the status&cmd) // status = status // cmd = command ID // data = data to receive _i2c.start(); _i2c.write(AR1021_ADDR + 1); //send read address - char header = _i2c.read(1); //header should always be 0x55 - char length = _i2c.read(1); //data length - - //we need to send a NACK on the last read. - int i; - for (i = 0; i < (length-1); i++) { - buff[i] = _i2c.read(1); - } - buff[i] = _i2c.read(0); //last returned data byte - _i2c.stop(); - - + char header = _i2c.read(1); //header should always be 0x55 if (header != 0x55) { ret = AR1021_ERR_NO_HDR; continue; } + char length = _i2c.read(1); //data length if (length < 2) { - ret = AR1021_ERR_INV_LEN; + ret = AR1021_ERR_INV_LEN; //must have at least status and command bytes continue; } - if (buff[0] != AR1021_RESP_STAT_OK) { - ret = -buff[0]; - continue; - } - if (buff[1] != cmd) { - ret = AR1021_ERR_INV_RESP; + length -= 2; + if (length > readLen) { + ret = AR1021_ERR_INV_LEN; //supplied buffer is not enough continue; } + + char status = _i2c.read(1); //command status + char usedCmd; + if (readLen <= 0) { + usedCmd = _i2c.read(0); //no data => read command byte + NACK + } else { + usedCmd = _i2c.read(1); //which command + + //we need to send a NACK on the last read. + int i; + for (i = 0; i < (length-1); i++) { + respBuf[i] = _i2c.read(1); + } + respBuf[i] = _i2c.read(0); //last returned data byte + NACK + } + _i2c.stop(); - // copy data into response - if (respLen != NULL && respBuf != NULL) { - if ((length - 2) > *respLen) { - // respBuf too small, only copy what fits - for (i = 0; i < *respLen; i++) { - respBuf[i] = buff[i+2]; - } - } else { - // respBuf large enough, copy all - for (i = 0; i < (length-2); i++) { - respBuf[i] = buff[i+2]; - } - *respLen = (length-2); - } + + if (status != AR1021_RESP_STAT_OK) { + ret = -status; + continue; + } + if (usedCmd != cmd) { + ret = AR1021_ERR_INV_RESP; + continue; } // success @@ -559,4 +558,3 @@ } return (res == 0); } -
--- a/TestAudio.cpp Tue Sep 09 14:20:12 2014 +0000 +++ b/TestAudio.cpp Thu Sep 25 07:17:44 2014 +0000 @@ -157,7 +157,7 @@ _i2sTx.masterslave(I2S_SLAVE); _i2sTx.start(); - + int lastVol = -1000; // value not important do { //check if joystick-down pressed = play wave-file @@ -184,7 +184,15 @@ _codec.input_mute(false); } - _codec.headphone_volume(_aIn); + //attempt to filter out the small variations in analog values and + //only update volume when a "large enough" change is detected. + float v = _aIn; + int val = ((int)(v*1000))>>2; + if (val != lastVol) { + _codec.headphone_volume(v); + lastVol = val; + } + //_codec.headphone_volume(_aIn); wait(0.25); } while (up.read() != 0);
--- a/TestDisplay.cpp Tue Sep 09 14:20:12 2014 +0000 +++ b/TestDisplay.cpp Thu Sep 25 07:17:44 2014 +0000 @@ -162,11 +162,18 @@ delays++; } - int vh,vl,r,ty; - if (_touch.info(&vh,&vl,&r,&ty)) { - printf("Touch info: v%d.%d, %d-bit resolution, type 0x%x\n", vh, vl, r, ty); - } else { - printf("Failed to read touch information\n"); + int vh,vl,r,ty,att; + for (att = 1; att <= 5;att++) { + if (_touch.info(&vh,&vl,&r,&ty)) { + printf("Touch info: v%d.%d, %d-bit resolution, type 0x%x\n", vh, vl, r, ty); + break; + } else { + printf("Attempt %d to get touch controller info failed...\n", att); + wait(1); + } + } + if (att > 5) { + printf("Failed to read touch controller info even after %d attempts\n", att); break; }