Generic mbed Extensions used by STM Expansion Board Firmware Packages.

Dependents:   X_NUCLEO_IKS01A1 X_NUCLEO_6180XA1 1-DoorCloser 1-DoorCloser ... more

Fork of X_NUCLEO_COMMON by ST Expansion SW Team

Generic mbed Extensions used by STM Expansion Board Firmware Packages

DbgMCU

Helper class DbgMCU providing a default constructor which enables debugging on STM32 MCUs while using sleep modes.

DevI2C

Helper class DevI2C providing functions for multi-register I2C communication common for a series of I2C devices.

DevSPI

Helper class DevSPI providing functions for SPI communication common for a series of SPI devices.

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 */