Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of X_NUCLEO_COMMON by
Diff: DevI2C/DevI2C.h
- Revision:
- 3:bc5fc631e9c5
- Parent:
- 2:c1cac955d4bd
- Child:
- 4:33ee0cf483de
--- a/DevI2C/DevI2C.h Tue Apr 14 15:32:06 2015 +0200
+++ b/DevI2C/DevI2C.h Wed Apr 29 16:14:03 2015 +0200
@@ -64,7 +64,9 @@
* @param RegisterAddr specifies the internal address register
* where to start writing to (must be correctly masked).
* @param NumByteToWrite number of bytes to be written.
- * @retval 0 if ok, -1 if an I2C error has occured
+ * @retval 0 if ok,
+ * -1 if an I2C error has occured, or
+ * -2 on temporary buffer overflow (i.e. NumByteToWrite was too high)
* @note On some devices if NumByteToWrite is greater
* than one, the RegisterAddr must be masked correctly!
*/
@@ -72,8 +74,10 @@
uint16_t NumByteToWrite)
{
int ret;
- uint8_t tmp[32];
+ uint8_t tmp[TEMP_BUF_SIZE];
+ if(NumByteToWrite >= TEMP_BUF_SIZE) return -2;
+
/* First, send device address. Then, send data and STOP condition */
tmp[0] = RegisterAddr;
memcpy(tmp+1, pBuffer, NumByteToWrite);
@@ -110,6 +114,9 @@
if(ret) return -1;
return 0;
}
+
+ private:
+ static const unsigned int TEMP_BUF_SIZE = 32;
};
#endif /* __DEV_I2C_H */
