/* Send data with special length in master mode through the USIx peripheral.  */
u8 USI_I2C_MasterWrite(USI_TypeDef *USIx, u8 *pBuf, u8 len)
/* Send data with special length in master mode through the USIx peripheral.  */
u8 USI_I2C_MasterWrite(USI_TypeDef *USIx, u8 *pBuf, u8 len)
{
	u8 cnt = 0;
	assert_param(IS_USI_I2C_ALL_PERIPH(USIx));
	for(cnt = 0; cnt < len; cnt++)
	{
		while((USI_I2C_CheckTXFIFOState(USIx, USI_TXFIFO_ALMOST_EMPTY_COPY)) == 0);
		if(cnt >= len - 1)
		{
			USIx->TX_FIFO_WRITE = (*pBuf++) | (1 << 9);
		}
		else
		{
			USIx->TX_FIFO_WRITE = (*pBuf++);
		}
		while((USI_I2C_CheckTXFIFOState(USIx, USI_TXFIFO_EMPTY)) == 0) {
			if(USI_I2C_GetRawINT(USIx) & USI_I2C_TX_ABRT_RSTS) {
				USI_I2C_ClearAllINT(USIx);
				return cnt;
			}
		}
	}
	return cnt;
}