//***************************************************************************** // //! Writes data to BQ27510G3 registers. //! //! \param psInst is a pointer to the BQ27510G3 instance data. //! \param ui8Reg is the first register to write. //! \param pui16Data is a pointer to the 16-bit register data to write. //! \param ui16Count is the number of 16-bit registers to write. //! \param pfnCallback is the function to be called when the data has been //! written (can be \b NULL if a callback is not required). //! \param pvCallbackData is a pointer that is passed to the callback function. //! //! This function writes a sequence of data values to consecutive registers in //! the BQ27510G3. The first value in the \e pui16Data buffer contains the //! data to be written into the \e ui8Reg register, the second value contains //! the data to be written into the next register, and so on. //! //! \note The BQ27510G3 does not auto-increment the register pointer, so writes //! of more than one register are rejected by the BQ27510G3. //! //! \return Returns 1 if the write was successfully started and 0 if it was //! not. // //***************************************************************************** uint_fast8_t BQ27510G3Write(tBQ27510G3 *psInst, uint_fast8_t ui8Reg, const uint16_t *pui16Data, uint_fast16_t ui16Count, tSensorCallback *pfnCallback, void *pvCallbackData) { // // Return a failure if the BQ27510G3 driver is not idle (in other words, // there is already an outstanding request to the BQ27510G3). // if(psInst->ui8State != BQ27510G3_STATE_IDLE) { return(0); } // // Save the callback information. // psInst->pfnCallback = pfnCallback; psInst->pvCallbackData = pvCallbackData; // // Move the state machine to the wait for write state. // psInst->ui8State = BQ27510G3_STATE_WRITE; // // Write the requested registers to the BQ27510G3. // if(I2CMWrite16BE(&(psInst->uCommand.sWriteState), psInst->psI2CInst, psInst->ui8Addr, ui8Reg, pui16Data, ui16Count, BQ27510G3Callback, psInst) == 0) { // // The I2C write failed, so move to the idle state and return a // failure. // psInst->ui8State = BQ27510G3_STATE_IDLE; return(0); } // // Success. // return(1); }
//***************************************************************************** // //! Writes data to TMP100 registers. //! //! \param psInst is a pointer to the TMP100 instance data. //! \param ui8Reg is the first register to write. //! \param pui16Data is a pointer to the 16-bit register data to write. //! \param ui16Count is the number of 16-bit registers to write. //! \param pfnCallback is the function to be called when the data has been //! written (can be \b NULL if a callback is not required). //! \param pvCallbackData is a pointer that is passed to the callback function. //! //! This function writes a sequence of data values to consecutive registers in //! the TMP100. The first value in the \e pui16Data buffer contains the data //! to be written into the \e ui8Reg register, the second value contains the //! data to be written into the next register, and so on. //! //! \note The TMP100 does not auto-increment the register pointer, so writes of //! more than one register are rejected by the TMP100. //! //! \return Returns 1 if the write was successfully started and 0 if it was //! not. // //***************************************************************************** uint_fast8_t TMP100Write(tTMP100 *psInst, uint_fast8_t ui8Reg, const uint16_t *pui16Data, uint_fast16_t ui16Count, tSensorCallback *pfnCallback, void *pvCallbackData) { // // Return a failure if the TMP100 driver is not idle (in other words, there // is already an outstanding request to the TMP100). // if(psInst->ui8State != TMP100_STATE_IDLE) { return(0); } // // Save the callback information. // psInst->pfnCallback = pfnCallback; psInst->pvCallbackData = pvCallbackData; // // Move the state machine to the wait for write state. // psInst->ui8State = TMP100_STATE_WRITE; // // Write the requested registers to the TMP100. // if(ui8Reg == TMP100_O_CONFIG) { // // The configuration register is only one byte, so only a single byte // write is necessary and no endian swapping is required. // psInst->uCommand.pui8Buffer[0] = ui8Reg; psInst->uCommand.pui8Buffer[1] = *pui16Data & 0xff; if(I2CMWrite(psInst->psI2CInst, psInst->ui8Addr, psInst->uCommand.pui8Buffer, 2, TMP100Callback, psInst) == 0) { // // The I2C write failed, so move to the idle state and return a // failure. // psInst->ui8State = TMP100_STATE_IDLE; return(0); } } else { // // This is one of the temperature registers, which are 16-bit // big-endian registers. // if(I2CMWrite16BE(&(psInst->uCommand.sWriteState), psInst->psI2CInst, psInst->ui8Addr, ui8Reg, pui16Data, ui16Count, TMP100Callback, psInst) == 0) { // // The I2C write failed, so move to the idle state and return a // failure. // psInst->ui8State = TMP100_STATE_IDLE; return(0); } } // // Success. // return(1); }