Tool/software:
Hello,
I am porting bmm350 sensor code to Tiva-C platform.
https://github.com/boschsensortec/BMM350_SensorAPI
The authors took advantage of function pointers and cleverly designed structs to create a driver in c++ that can work in many platforms.
However, using tm4c123gh6pm and ccs there are some problems with the pointers. Here is an example:
static int8_t bmm350I2cReadData(uint8_t Reg, uint8_t *Data, uint32_t len, void *intfPtr) { uint8_t deviceAddr = *(uint8_t*)intfPtr; I2C3Receive(deviceAddr, Reg, Data, len); return 0; }
The deviceAddr obtained by dereferencing void *intfPtr - is always wrong, although '*(uint8_t*)intfPtr' seems to be the correct syntax.
On the other side these parameters such as address is loaded as:
uint8_t devAddr; switch(interface) { case eBmm350InterfaceI2C: devAddr = BMM350_I2C_ADSEL_SET_LOW; // 0x14 bmm350Sensor.intfPtr = &devAddr; break; case eBmm350InterfaceI3C: break; }
The bmm350 device structure is as follows:
// brief bmm350 device structure struct bmm350_dev { // The interface pointer is used to enable the user // to link their interface descriptors for reference during the // implementation of the read and write interfaces to the hardware. void* intfPtr; // interface pointer uint8_t chipId; // chip Id of BMM350 pBmm350ReadFptr_t read; // Bus read function pointer pBmm350WriteFptr_t write; // Bus write function pointer pBmm350DelayUsFptr_t delayUs; // delay(in us) function pointer BMM350_INTF_RET_TYPE intf_rslt; // to store interface pointer error uint8_t axisEn; // variable to store status of axes enabled struct bmm350_mag_compensate mag_comp; // structure for mag compensate uint16_t otp_data[BMM350_OTP_DATA_LENGTH]; // array to store OTP data uint8_t var_id; // variant ID bmm350_mraw_override_t mraw_override; // magnetic reset and wait override uint8_t powerMode; // power mode };
Basically, the function pointers part work, but not the passing of values from pointers.
Any ideas / help greatly appreciated.
Best Regards,
C.