#ifndef __SENSOR_ERROR_H__
#define __SENSOR_ERROR_H__

/** @brief Common error code definition
 */
typedef enum sensor_error
{
    SENSOR_SUCCESS            = 0,   /* no error */
    SENSOR_ERROR              = -1,  /* unspecified error */
    SENSOR_ERROR_NIMPL        = -2,  /* function not implemented for given arguments */
    SENSOR_ERROR_ARGS         = -3,  /* given arguments is not in range or error type */
    SENSOR_ERROR_IO           = -4,  /* I2C OR SPI etc serial interface error */
    SENSOR_ERROR_CHECK_ID     = -5,  /* Check ID or who am i error */
    SENSOR_ERROR_TIMEOUT      = -6,
    SENSOR_ERROR_NOACK        = -7,
    SENSOR_INIT_FAILURE       = -8,
    SENSOR_VAR_NOT_INIT       = -9,  /* variable not initialize */
    SENSOR_ERROR_FIFO_FULL    = -10,  /* FIFO is full */
    SENSOR_FIFO_COUNT_INVALID = -11,
}SENSOR_ERROR_t;


#define DEV_ASSERT(dev)    do{                    \
    if(dev == NULL)                               \
    {                                             \
        SENSOR_ERR("device is NULL\r\n");\
        return SENSOR_ERROR_NIMPL;                \
    }                                             \
    if(dev->driver == NULL)                       \
    {                                             \
        SENSOR_ERR("Driver api is NULL\r\n");     \
        return SENSOR_ERROR_NIMPL;                \
    }                                             \
}while(0)


#define SENSOR_RESULT_CHECK(code)    do{          \
    const int error = (code);                     \
    if (error != SENSOR_SUCCESS)                  \
    {                                             \
        goto err;                                 \
    }                                             \
}while(0)


const char *sensor_error_str(int error);

#endif  // @page end

