//***************************************************************************** // //! Reads data from CM3218 registers. //! //! \param psInst is a pointer to the CM3218 instance data. //! \param ui8Reg is the first register to read. //! \param pui16Data is a pointer to the location to store the data that is //! read. //! \param ui16Count the number of register values bytes to read. //! \param pfnCallback is the function to be called when data read is complete //! (can be \b NULL if a callback is not required). //! \param pvCallbackData is a pointer that is passed to the callback function. //! //! This function reads a sequence of data values from consecutive registers in //! the CM3218. //! //! \note The CM3218 does not auto-increment the register pointer, so reads of //! more than one value returns the same data. //! //! \return Returns 1 if the write was successfully started and 0 if it was //! not. // //***************************************************************************** uint_fast8_t CM3218Read(tCM3218 *psInst, uint_fast8_t ui8Reg, uint16_t *pui16Data, uint_fast16_t ui16Count, tSensorCallback *pfnCallback, void *pvCallbackData) { // // Return a failure if the CM3218 driver is not idle (in other words, there // is already an outstanding request to the CM3218). // if(psInst->ui8State != CM3218_STATE_IDLE) { return(0); } // // Save the callback information. // psInst->pfnCallback = pfnCallback; psInst->pvCallbackData = pvCallbackData; // // Move the state machine to the wait for read state. // psInst->ui8State = CM3218_STATE_READ; // // Read the requested registers from the CM3218. // if(I2CMRead16BE(&(psInst->uCommand.sReadState), psInst->psI2CInst, psInst->ui8Addr, ui8Reg, pui16Data, ui16Count, CM3218Callback, psInst) == 0) { // // The I2C write failed, so move to the idle state and return a // failure. // psInst->ui8State = CM3218_STATE_IDLE; return(0); } // // Success. // return(1); }
//***************************************************************************** // //! Reads data from TMP100 registers. //! //! \param psInst is a pointer to the TMP100 instance data. //! \param ui8Reg is the first register to read. //! \param pui16Data is a pointer to the location to store the data that is //! read. //! \param ui16Count the number of register values to read. //! \param pfnCallback is the function to be called when data read is complete //! (can be \b NULL if a callback is not required). //! \param pvCallbackData is a pointer that is passed to the callback function. //! //! This function reads a sequence of data values from consecutive registers in //! the TMP100. //! //! \note The TMP100 does not auto-increment the register pointer, so reads of //! more than one value returns garbage for the subsequent values. //! //! \return Returns 1 if the write was successfully started and 0 if it was //! not. // //***************************************************************************** uint_fast8_t TMP100Read(tTMP100 *psInst, uint_fast8_t ui8Reg, 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 read state. // psInst->ui8State = TMP100_STATE_READ; // // Read the requested registers from the TMP100. // if(ui8Reg == TMP100_O_CONFIG) { // // The configuration register is only one byte, so only a single byte // read is necessary and no endian swapping is required. // psInst->uCommand.pui8Buffer[0] = ui8Reg; if(I2CMRead(psInst->psI2CInst, psInst->ui8Addr, psInst->uCommand.pui8Buffer, 1, (uint8_t *)pui16Data, 1, 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(I2CMRead16BE(&(psInst->uCommand.sReadState), 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); }