Skip to content

Commit

Permalink
clean-up static definition
Browse files Browse the repository at this point in the history
  • Loading branch information
aldwinhermanudin committed Dec 30, 2023
1 parent a7a317a commit ba30a89
Showing 1 changed file with 62 additions and 69 deletions.
131 changes: 62 additions & 69 deletions src/mbedos/test-bme688/source/bme688/BME688.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,69 @@ namespace sensors {
namespace bme688 {

// *********************************************************************
// SENSOR STATIC CALLBACK FORWARD DECLARATION
// SENSOR STATIC CALLBACK DEFINITION
// *********************************************************************
static int8_t SensorInternalReadRegisterCb(uint8_t reg_addr, uint8_t *regdata, uint32_t length, void *intf_ptr);
static int8_t SensorInternalWriteRegisterCb(uint8_t reg_addr,const uint8_t *reg_data, uint32_t length,void *intf_ptr);
static void SensorInternalDelayUsCb(uint32_t time_us, void *intf_ptr);
static int8_t SensorInternalReadRegisterCb( uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr )
{
BME688* bme688 = (BME688*) intf_ptr;
if( bme688->i2c_local == nullptr )
{
// return error
return 0xFF;
}

// local variable definition
int8_t rslt = 0; // Return 0 for Success, non-zero for failure
uint32_t aux = 0;
aux = bme688->i2c_local->write ( bme688->bme688_addr_8bit, (char*)&reg_addr, 1, true );
if ( aux != 0 ) {
return 0xFF; // return error
}

aux = bme688->i2c_local->read ( bme688->bme688_addr_8bit, (char*)&reg_data[0], length );
if ( aux != 0 ) {
return 0xFF; // return error
}

return rslt;
}

static int8_t SensorInternalWriteRegisterCb(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
// check callback obeject pointer
BME688* bme688 = (BME688*) intf_ptr;
if( bme688->i2c_local == nullptr )
{
return 0xFF; // return error
}

// local variable definition
int8_t rslt = 0; // Return 0 for Success, non-zero for failure
uint32_t aux = 0;
char cmd[16] = {0};
uint32_t i = 0;

// Prepare the data to be sent
cmd[0] = reg_addr;
for ( i = 1; i <= length; i++ ) {
cmd[i] = reg_data[i - 1];
}

// Write data
aux = bme688->i2c_local->write( bme688->bme688_addr_8bit, &cmd[0], length + 1, false );
if ( aux != 0 ) {
return 0xFF; // return error
}

return rslt;
}

static void SensorInternalDelayUsCb(uint32_t time_us, void *intf_ptr)
{
/* use wait_us to wait without sleep
if system goes to sleep, I2C comm need to be re-init */
wait_us ( time_us );
}


// *********************************************************************
Expand Down Expand Up @@ -584,71 +642,6 @@ ReturnCode BME688::ReadRegister( const uint8_t reg_addr, uint8_t* const reg_data
return ReturnCode::kOk;
}

// *********************************************************************
// SENSOR STATIC CALLBACK DEFINITION
// *********************************************************************
int8_t SensorInternalReadRegisterCb( uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr )
{
BME688* bme688 = (BME688*) intf_ptr;
if( bme688->i2c_local == nullptr )
{
// return error
return 0xFF;
}

// local variable definition
int8_t rslt = 0; // Return 0 for Success, non-zero for failure
uint32_t aux = 0;
aux = bme688->i2c_local->write ( bme688->bme688_addr_8bit, (char*)&reg_addr, 1, true );
if ( aux != 0 ) {
return 0xFF; // return error
}

aux = bme688->i2c_local->read ( bme688->bme688_addr_8bit, (char*)&reg_data[0], length );
if ( aux != 0 ) {
return 0xFF; // return error
}

return rslt;
}

static int8_t SensorInternalWriteRegisterCb(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
// check callback obeject pointer
BME688* bme688 = (BME688*) intf_ptr;
if( bme688->i2c_local == nullptr )
{
return 0xFF; // return error
}

// local variable definition
int8_t rslt = 0; // Return 0 for Success, non-zero for failure
uint32_t aux = 0;
char cmd[16] = {0};
uint32_t i = 0;

// Prepare the data to be sent
cmd[0] = reg_addr;
for ( i = 1; i <= length; i++ ) {
cmd[i] = reg_data[i - 1];
}

// Write data
aux = bme688->i2c_local->write( bme688->bme688_addr_8bit, &cmd[0], length + 1, false );
if ( aux != 0 ) {
return 0xFF; // return error
}

return rslt;
}

static void SensorInternalDelayUsCb(uint32_t time_us, void *intf_ptr)
{
/* use wait_us to wait without sleep
if system goes to sleep, I2C comm need to be re-init */
wait_us ( time_us );
}

} // namespace bme688
} // namespace sensors
} // namespace teapotlabs
Expand Down

0 comments on commit ba30a89

Please sign in to comment.