2018-12-18 08:06 AM
Hi,
Here is the code from CubeMX generated BSP module for hts221 sensor.
/**
* @brief Read generic device register
*
* @param hts221_ctx_t* ctx: read / write interface definitions
* @param uint8_t reg: register to read
* @param uint8_t* data: pointer to buffer that store the data read
* @param uint16_t len: number of consecutive register to read
*
*/
int32_t hts221_read_reg(hts221_ctx_t *ctx, uint8_t reg, uint8_t *data,
uint16_t len)
{
int32_t ret;
ret = ctx->read_reg(ctx->handle, reg, data, len);
return ret;
}
I need help to understand constructs like in this code. int32_t hts221_read_reg(hts221_ctx_t *ctx, uint8_t reg, uint8_t *data, uint16_t len) is function which is doing something with a pointers, but I'm not sure what.
And Why? What are benefits of such a constructs. Is it mandatory to use it because of some coding standard (ie. MISRA-C ) or is it something else?
Thanks.
2018-12-18 08:14 AM
It is calling a function pointer providing the underlying support functions.
I think this allows for a) abstraction, b) different busing, c) multiple sensors