Skip to main content
Mario Simunic
Associate III
December 18, 2018
Question

X-NUCLEO-MEMS1 function call constructs

  • December 18, 2018
  • 1 reply
  • 686 views

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.

    This topic has been closed for replies.

    1 reply

    Tesla DeLorean
    Guru
    December 18, 2018

    It is calling a function pointer providing the underlying support functions.

    I think this allows for a) abstraction, b) different busing, c) multiple sensors

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..