Commit 575de9d4 authored by Armando Visconti's avatar Armando Visconti Committed by Kumar Gala
Browse files

sensor/stmemsc: Align stmemsc i/f to v2.00



Align stmemsc HAL i/f to v2.00

Signed-off-by: default avatarArmando Visconti <armando.visconti@st.com>
parent b52fdbf4
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
set(stmems_pids
  a3g4250d
  ais2dw12
  ais2ih
  ais328dq
  ais3624dq
  asm330lhh
@@ -40,9 +41,11 @@ set(stmems_pids
  lis3dhh
  lis3dsh
  lis3mdl
  lps22ch
  lps22hb
  lps22hh
  lps25hb
  lps27hhtw
  lps27hhw
  lps33hw
  lps33k
@@ -50,11 +53,12 @@ set(stmems_pids
  lsm303agr
  lsm303ah
  lsm6ds3
  lsm6ds3tr_c
  lsm6ds3tr-c
  lsm6dsl
  lsm6dsm
  lsm6dso
  lsm6dso32
  lsm6dso32x
  lsm6dsox
  lsm6dsr
  lsm6dsrx
+3 −3
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ Origin:
   https://www.st.com/en/embedded-software/c-driver-mems.html

Status:
   version v1.03
   version v2.00

Purpose:
   ST Microelectronics standard C platform-independent drivers for MEMS
@@ -31,7 +31,7 @@ Description:
   I2C or SPI platform driver like the following:

   /** Please note that is MANDATORY: return 0 -> no Error.**/
   int platform_wr(void *handle, u8_t reg, u8_t *bufp, u16_t len);
   int platform_wr(void *handle, u8_t reg, const u8_t *bufp, u16_t len);
   int platform_rd(void *handle, u8_t reg, u8_t *bufp, u16_t len);

   stmdev_ctx_t stmdev_ctx = {
@@ -46,7 +46,7 @@ URL:
   https://www.st.com/en/embedded-software/c-driver-mems.html

commit:
   version v1.03
   version v2.00

Maintained-by:
   ST Microelectronics
+156 −126
Original line number Diff line number Diff line
@@ -94,7 +94,8 @@ static st_fifo_compression_type get_compression_type(uint8_t tag);
static uint8_t is_tag_valid(uint8_t tag);
static void get_diff_2x(int16_t diff[6], uint8_t input[6]);
static void get_diff_3x(int16_t diff[9], uint8_t input[6]);
static void byte_cpy(uint8_t *destination, uint8_t *source, uint32_t len);
static void byte_cpy(uint8_t *destination, uint8_t *source,
                     uint32_t len);

/* Private variables ---------------------------------------------------------*/
static uint8_t tag_counter_old     = 0x00U;
@@ -114,7 +115,7 @@ static int16_t last_data_gy[3] = {0};

/**
  * @defgroup  FIFO_pubblic_functions
  * @brief     This section provide a set of usefull APIs for managing data
  * @brief     This section provide a set of useful APIs for managing data
  *            compression in smart FIFO.
  * @{
  *
@@ -143,11 +144,12 @@ st_fifo_status st_fifo_init(float_t bdr_xl_in,
  uint32_t i;
  st_fifo_status ret = ST_FIFO_ERR;

  if ((bdr_xl_in < 0.0f) || (bdr_gy_in < 0.0f) || (bdr_vsens_in < 0.0f)) {
  if ((bdr_xl_in < 0.0f) || (bdr_gy_in < 0.0f) ||
      (bdr_vsens_in < 0.0f)) {
    ret = ST_FIFO_ERR;
  }
  else {

  else {
    tag_counter_old = 0x00U;
    bdr_xl = bdr_xl_in;
    bdr_gy = bdr_gy_in;
@@ -165,7 +167,6 @@ st_fifo_status st_fifo_init(float_t bdr_xl_in,
    for (i = 0; i < 3U; i++) {
      last_data_xl[i] = 0;
      last_data_gy[i] = 0;

      ret = ST_FIFO_OK;
    }
  }
@@ -199,25 +200,23 @@ st_fifo_status st_fifo_decompress(st_fifo_out_slot *fifo_out_slot,
  uint8_t bdr_vsens_cfg;
  uint32_t last_timestamp;
  int16_t diff[9];

  float_t bdr_acc_vect[]  = {    0,   13,  26,   52,  104,
                                 208,  416, 833, 1666, 3333,
                                 6666,    1.625,   0,    0,    0,
                                 0 };

                                 0
                            };
  float_t bdr_gyr_vect[] = {   0,   13,   26,   52, 104, 208, 416,
                               833, 1666, 3333, 6666,   0,   0,   0,
                               0,    0};

                               0,    0
                           };
  float_t bdr_vsens_vect[] = { 0, 13, 26, 52, 104, 208, 416,
                               0,  0,  0,  0,   1.625,   0,   0,
                               0,  0};
                               0,  0
                             };

  for (uint16_t i = 0; i < stream_size; i++) {

    tag = (fifo_raw_slot[i].fifo_data_out[0] & TAG_SENSOR_MASK);
    tag = tag >> TAG_SENSOR_SHIFT;

    tag_counter = (fifo_raw_slot[i].fifo_data_out[0] & TAG_COUNTER_MASK);
    tag_counter = tag_counter >> TAG_COUNTER_SHIFT;

@@ -227,10 +226,10 @@ st_fifo_status st_fifo_decompress(st_fifo_out_slot *fifo_out_slot,
    }

    if ((tag_counter != (tag_counter_old)) && (bdr_max != 0.0f)) {

      if (tag_counter < tag_counter_old) {
        diff_tag_counter = tag_counter + 4U - tag_counter_old;
      }

      else {
        diff_tag_counter = tag_counter - tag_counter_old;
      }
@@ -239,34 +238,29 @@ st_fifo_status st_fifo_decompress(st_fifo_out_slot *fifo_out_slot,
    }

    if (tag == TAG_ODRCHG) {

      bdr_acc_cfg = (fifo_raw_slot[i].fifo_data_out[6] & BDR_XL_MASK);
      bdr_acc_cfg = bdr_acc_cfg >> BDR_XL_SHIFT;

      bdr_gyr_cfg = (fifo_raw_slot[i].fifo_data_out[6] & BDR_GY_MASK);
      bdr_gyr_cfg = bdr_gyr_cfg >> BDR_GY_SHIFT;

      bdr_vsens_cfg = (fifo_raw_slot[i].fifo_data_out[3] & BDR_VSENS_MASK);
      bdr_vsens_cfg = bdr_vsens_cfg >> BDR_VSENS_SHIFT;

      bdr_xl_old = bdr_xl;
      bdr_gy_old = bdr_gy;

      bdr_xl = bdr_acc_vect[bdr_acc_cfg];
      bdr_gy = bdr_gyr_vect[bdr_gyr_cfg];
      bdr_vsens = bdr_vsens_vect[bdr_vsens_cfg];
      bdr_max = ((bdr_xl > bdr_gy) ? bdr_xl : bdr_gy);
      bdr_max = ((bdr_max > bdr_vsens) ? bdr_max : bdr_vsens);

      bdr_chg_xl_flag = 1;
      bdr_chg_gy_flag = 1;
    }

      } else if (tag == TAG_TS) {

        byte_cpy( (uint8_t*)&timestamp, &fifo_raw_slot[i].fifo_data_out[1], 4);

      } else {
    else if (tag == TAG_TS) {
      byte_cpy( (uint8_t *)&timestamp, &fifo_raw_slot[i].fifo_data_out[1],
                4);
    }

    else {
      st_fifo_compression_type compression_type = get_compression_type(tag);
      st_fifo_sensor_type sensor_type = get_sensor_type(tag);

@@ -276,6 +270,7 @@ st_fifo_status st_fifo_decompress(st_fifo_out_slot *fifo_out_slot,
            byte_cpy((uint8_t *)&fifo_out_slot[j].timestamp,
                     &fifo_raw_slot[i].fifo_data_out[3], 4);
          }

          else {
            fifo_out_slot[j].timestamp = timestamp;
          }
@@ -298,18 +293,18 @@ st_fifo_status st_fifo_decompress(st_fifo_out_slot *fifo_out_slot,

          j++;
          break;

        case ST_FIFO_COMPRESSION_NC_T_1:
          fifo_out_slot[j].sensor_tag = get_sensor_type(tag);
          byte_cpy(fifo_out_slot[j].raw_data,
                   &fifo_raw_slot[i].fifo_data_out[1], 6);

          if (sensor_type == ST_FIFO_ACCELEROMETER) {


            if (bdr_chg_xl_flag != 0U) {
              last_timestamp = (last_timestamp_xl +
                                (TIMESTAMP_FREQ / (uint32_t)bdr_xl_old));
            }

            else {
              last_timestamp = ((uint32_t)timestamp -
                                ((uint32_t)TIMESTAMP_FREQ / (uint32_t)bdr_xl));
@@ -322,12 +317,11 @@ st_fifo_status st_fifo_decompress(st_fifo_out_slot *fifo_out_slot,
          }

          if (sensor_type == ST_FIFO_GYROSCOPE) {


            if (bdr_chg_gy_flag != 0U) {
              last_timestamp = (last_timestamp_gy +
                                (TIMESTAMP_FREQ / (uint32_t)bdr_gy_old));
            }

            else {
              last_timestamp = (timestamp -
                                (TIMESTAMP_FREQ / (uint32_t)bdr_gy));
@@ -340,6 +334,7 @@ st_fifo_status st_fifo_decompress(st_fifo_out_slot *fifo_out_slot,

          j++;
          break;

        case ST_FIFO_COMPRESSION_NC_T_2:
          fifo_out_slot[j].sensor_tag = get_sensor_type(tag);
          byte_cpy(fifo_out_slot[j].raw_data,
@@ -350,6 +345,7 @@ st_fifo_status st_fifo_decompress(st_fifo_out_slot *fifo_out_slot,
              last_timestamp = (last_timestamp_xl +
                                (TIMESTAMP_FREQ / (uint32_t)bdr_xl_old));
            }

            else {
              last_timestamp = (timestamp -
                                ((2U * TIMESTAMP_FREQ) / (uint32_t) bdr_xl));
@@ -359,12 +355,13 @@ st_fifo_status st_fifo_decompress(st_fifo_out_slot *fifo_out_slot,
            byte_cpy((uint8_t *)last_data_xl, fifo_out_slot[j].raw_data, 6);
            last_timestamp_xl = last_timestamp;
          }
          if (sensor_type == ST_FIFO_GYROSCOPE) {

          if (sensor_type == ST_FIFO_GYROSCOPE) {
            if (bdr_chg_gy_flag != 0U) {
              last_timestamp = (last_timestamp_gy +
                                (TIMESTAMP_FREQ / (uint32_t)bdr_gy_old));
            }

            else {
              last_timestamp = (timestamp -
                                (2U * TIMESTAMP_FREQ / (uint32_t)bdr_gy));
@@ -378,9 +375,9 @@ st_fifo_status st_fifo_decompress(st_fifo_out_slot *fifo_out_slot,

          j++;
          break;

        case ST_FIFO_COMPRESSION_2X:
          get_diff_2x(diff, &fifo_raw_slot[i].fifo_data_out[1]);

          fifo_out_slot[j].sensor_tag = sensor_type;

          if (sensor_type == ST_FIFO_ACCELEROMETER) {
@@ -390,7 +387,6 @@ st_fifo_status st_fifo_decompress(st_fifo_out_slot *fifo_out_slot,
            byte_cpy(fifo_out_slot[j].raw_data, (uint8_t *)data, 6);
            fifo_out_slot[j].timestamp =
              (timestamp - (2U * TIMESTAMP_FREQ / (uint32_t)bdr_xl));

            byte_cpy((uint8_t *)last_data_xl, fifo_out_slot[j].raw_data, 6);
          }

@@ -401,12 +397,10 @@ st_fifo_status st_fifo_decompress(st_fifo_out_slot *fifo_out_slot,
            byte_cpy(fifo_out_slot[j].raw_data, (uint8_t *)data, 6);
            fifo_out_slot[j].timestamp =
              (timestamp - (2U * TIMESTAMP_FREQ / (uint32_t)bdr_gy));

            byte_cpy((uint8_t *)last_data_gy, fifo_out_slot[j].raw_data, 6);
          }

          j++;

          fifo_out_slot[j].sensor_tag = sensor_type;

          if (sensor_type == ST_FIFO_ACCELEROMETER) {
@@ -433,10 +427,9 @@ st_fifo_status st_fifo_decompress(st_fifo_out_slot *fifo_out_slot,

          j++;
          break;
        default: //(compression_type == ST_FIFO_COMPRESSION_3X)

        default: //(compression_type == ST_FIFO_COMPRESSION_3X)
          get_diff_3x(diff, &fifo_raw_slot[i].fifo_data_out[1]);

          fifo_out_slot[j].sensor_tag = sensor_type;

          if (sensor_type == ST_FIFO_ACCELEROMETER) {
@@ -461,7 +454,6 @@ st_fifo_status st_fifo_decompress(st_fifo_out_slot *fifo_out_slot,
          }

          j++;

          fifo_out_slot[j].sensor_tag = sensor_type;

          if (sensor_type == ST_FIFO_ACCELEROMETER) {
@@ -485,7 +477,6 @@ st_fifo_status st_fifo_decompress(st_fifo_out_slot *fifo_out_slot,
          }

          j++;

          fifo_out_slot[j].timestamp = timestamp;
          fifo_out_slot[j].sensor_tag = sensor_type;

@@ -527,21 +518,20 @@ st_fifo_status st_fifo_decompress(st_fifo_out_slot *fifo_out_slot,
  * @param  out_slot_size     decoded srteam size.
  *
  */
void st_fifo_sort(st_fifo_out_slot *fifo_out_slot, uint16_t out_slot_size)
void st_fifo_sort(st_fifo_out_slot *fifo_out_slot,
                  uint16_t out_slot_size)
{

  int32_t j, i;
  st_fifo_out_slot temp;

  for (i = 1; i < (int32_t)out_slot_size; i++) {

    byte_cpy((uint8_t *)&temp, (uint8_t *)&fifo_out_slot[i],
             sizeof(st_fifo_out_slot));

    j = i - 1;

    while ((j >= 0) && (fifo_out_slot[j].timestamp > temp.timestamp)) {
      byte_cpy((uint8_t*)&fifo_out_slot[j + 1], (uint8_t*)&fifo_out_slot[j],
      byte_cpy((uint8_t *)&fifo_out_slot[j + 1],
               (uint8_t *)&fifo_out_slot[j],
               sizeof(st_fifo_out_slot));
      j--;
    }
@@ -549,7 +539,6 @@ void st_fifo_sort(st_fifo_out_slot *fifo_out_slot, uint16_t out_slot_size)
    byte_cpy((uint8_t *)&fifo_out_slot[j + 1], (uint8_t *)&temp,
             sizeof(st_fifo_out_slot));
  }

}

/**
@@ -565,18 +554,17 @@ void st_fifo_sort(st_fifo_out_slot *fifo_out_slot, uint16_t out_slot_size)
  *                           decoded FIFO stream.
  *
  */
uint16_t  st_fifo_get_sensor_occurrence(st_fifo_out_slot *fifo_out_slot,
uint16_t  st_fifo_get_sensor_occurrence(st_fifo_out_slot
                                        *fifo_out_slot,
                                        uint16_t out_slot_size,
                                        st_fifo_sensor_type sensor_type)
{
  uint16_t occurrence = 0;

  for (uint16_t i = 0; i < out_slot_size; i++) {

    if (fifo_out_slot[i].sensor_tag == sensor_type) {
      occurrence++;
    }

  }

  return occurrence;
@@ -601,15 +589,12 @@ void st_fifo_extract_sensor(st_fifo_out_slot *sensor_out_slot,
  uint16_t temp_i = 0;

  for (uint16_t i = 0; i < out_slot_size; i++) {

    if (fifo_out_slot[i].sensor_tag == sensor_type) {

      byte_cpy((uint8_t*)&sensor_out_slot[temp_i], (uint8_t*)&fifo_out_slot[i],
      byte_cpy((uint8_t *)&sensor_out_slot[temp_i],
               (uint8_t *)&fifo_out_slot[i],
               sizeof(st_fifo_out_slot));

      temp_i++;
    }

  }
}

@@ -641,6 +626,7 @@ static uint8_t is_tag_valid(uint8_t tag)
  if (tag > TAG_VALID_LIMIT) {
    ret = 0;
  }

  else {
    ret = 1;
  }
@@ -659,81 +645,105 @@ static uint8_t is_tag_valid(uint8_t tag)
static st_fifo_sensor_type get_sensor_type(uint8_t tag)
{
  st_fifo_sensor_type ret;

  switch (tag) {
    case TAG_GY:
      ret = ST_FIFO_GYROSCOPE;
      break;

    case TAG_XL:
      ret =  ST_FIFO_ACCELEROMETER;
      break;

    case TAG_TEMP:
      ret =  ST_FIFO_TEMPERATURE;
      break;

    case TAG_EXT_SENS_0:
      ret =  ST_FIFO_EXT_SENSOR0;
      break;

    case TAG_EXT_SENS_1:
      ret =  ST_FIFO_EXT_SENSOR1;
      break;

    case TAG_EXT_SENS_2:
      ret =  ST_FIFO_EXT_SENSOR2;
      break;

    case TAG_EXT_SENS_3:
      ret =  ST_FIFO_EXT_SENSOR3;
      break;

    case TAG_STEP_COUNTER:
      ret =  ST_FIFO_STEP_COUNTER;
      break;

    case TAG_XL_UNCOMPRESSED_T_2:
      ret =  ST_FIFO_ACCELEROMETER;
      break;

    case TAG_XL_UNCOMPRESSED_T_1:
      ret =  ST_FIFO_ACCELEROMETER;
      break;

    case TAG_XL_COMPRESSED_2X:
      ret =  ST_FIFO_ACCELEROMETER;
      break;

    case TAG_XL_COMPRESSED_3X:
      ret =  ST_FIFO_ACCELEROMETER;
      break;

    case TAG_GY_UNCOMPRESSED_T_2:
      ret =  ST_FIFO_GYROSCOPE;
      break;

    case TAG_GY_UNCOMPRESSED_T_1:
      ret =  ST_FIFO_GYROSCOPE;
      break;

    case TAG_GY_COMPRESSED_2X:
      ret =  ST_FIFO_GYROSCOPE;
      break;

    case TAG_GY_COMPRESSED_3X:
      ret =  ST_FIFO_GYROSCOPE;
      break;

    case TAG_GAME_RV:
      ret =  ST_FIFO_6X_GAME_RV;
      break;

    case TAG_GEOM_RV:
      ret =  ST_FIFO_6X_GEOM_RV;
      break;

    case TAG_NORM_RV:
      ret =  ST_FIFO_9X_RV;
      break;

    case TAG_GYRO_BIAS:
      ret =  ST_FIFO_GYRO_BIAS;
      break;

    case TAG_GRAVITIY:
      ret =  ST_FIFO_GRAVITY;
      break;

    case TAG_MAG_CAL:
      ret =  ST_FIFO_MAGNETOMETER_CALIB;
      break;

    case TAG_EXT_SENS_NACK:
      ret =  ST_FIFO_EXT_SENSOR_NACK;
      break;

    default:
      ret =  ST_FIFO_NONE;
      break;

  }

  return ret;
}

@@ -748,59 +758,77 @@ static st_fifo_sensor_type get_sensor_type(uint8_t tag)
static st_fifo_compression_type get_compression_type(uint8_t tag)
{
  st_fifo_compression_type ret;

  switch (tag) {
    case TAG_GY:
      ret =  ST_FIFO_COMPRESSION_NC;
      break;

    case TAG_XL:
      ret =  ST_FIFO_COMPRESSION_NC;
      break;

    case TAG_TEMP:
      ret =  ST_FIFO_COMPRESSION_NC;
      break;

    case TAG_EXT_SENS_0:
      ret =  ST_FIFO_COMPRESSION_NC;
      break;

    case TAG_EXT_SENS_1:
      ret =  ST_FIFO_COMPRESSION_NC;
      break;

    case TAG_EXT_SENS_2:
      ret =  ST_FIFO_COMPRESSION_NC;
      break;

    case TAG_EXT_SENS_3:
      ret =  ST_FIFO_COMPRESSION_NC;
      break;

    case TAG_STEP_COUNTER:
      ret =  ST_FIFO_COMPRESSION_NC;
      break;

    case TAG_XL_UNCOMPRESSED_T_2:
      ret =  ST_FIFO_COMPRESSION_NC_T_2;
      break;

    case TAG_XL_UNCOMPRESSED_T_1:
      ret =  ST_FIFO_COMPRESSION_NC_T_1;
      break;

    case TAG_XL_COMPRESSED_2X:
      ret =  ST_FIFO_COMPRESSION_2X;
      break;

    case TAG_XL_COMPRESSED_3X:
      ret =  ST_FIFO_COMPRESSION_3X;
      break;

    case TAG_GY_UNCOMPRESSED_T_2:
      ret =  ST_FIFO_COMPRESSION_NC_T_2;
      break;

    case TAG_GY_UNCOMPRESSED_T_1:
      ret =  ST_FIFO_COMPRESSION_NC_T_1;
      break;

    case TAG_GY_COMPRESSED_2X:
      ret =  ST_FIFO_COMPRESSION_2X;
      break;

    case TAG_GY_COMPRESSED_3X:
      ret =  ST_FIFO_COMPRESSION_3X;
      break;

    default:
      ret =  ST_FIFO_COMPRESSION_NC;
      break;
  }

  return ret;
}

@@ -840,10 +868,12 @@ static uint8_t has_even_parity(uint8_t x)
static void get_diff_2x(int16_t diff[6], uint8_t input[6])
{
  uint8_t i;

  for (i = 0; i < 6U; i++) {
    if (input[i] < 128U ) {
      diff[i] = (int16_t)input[i];
    }

    else {
      diff[i] = ((int16_t)input[i] - 256);
    }
@@ -863,16 +893,16 @@ static void get_diff_3x(int16_t diff[9], uint8_t input[6])
  uint16_t dummy;

  for (uint8_t i = 0; i < 3U; i++) {

    byte_cpy((uint8_t *)&decode_temp, &input[2U * i], 2);

    for (uint8_t j = 0; j < 3U; j++) {

      dummy = decode_temp & ( (uint16_t)0x1FU << (5U * j) );
      dummy = dummy >> (5U * j);

      if (dummy >= 16U) {
        dummy -= 32U;
      }

      diff[j + (3U * i)] = (int16_t)dummy;
    }
  }
@@ -885,14 +915,14 @@ static void get_diff_3x(int16_t diff[9], uint8_t input[6])
  * @param  source           Source buffer.(ptr)
  *
  */
static void byte_cpy(uint8_t *destination, uint8_t *source, uint32_t len)
static void byte_cpy(uint8_t *destination, uint8_t *source,
                     uint32_t len)
{
  uint32_t i;

  for ( i = 0; i < len; i++ ) {
    destination[i] =  source[i];
  }

}

/**
+6 −3
Original line number Diff line number Diff line
@@ -104,16 +104,19 @@ typedef union {
  *
  */

st_fifo_status st_fifo_init(float_t bdr_xl, float_t bdr_gy, float_t bdr_vsens);
st_fifo_status st_fifo_init(float_t bdr_xl, float_t bdr_gy,
                            float_t bdr_vsens);

st_fifo_status st_fifo_decompress(st_fifo_out_slot *fifo_out_slot,
                                  st_fifo_raw_slot *fifo_raw_slot,
                                  uint16_t *out_slot_size,
                                  uint16_t stream_size);

void st_fifo_sort(st_fifo_out_slot *fifo_out_slot, uint16_t out_slot_size);
void st_fifo_sort(st_fifo_out_slot *fifo_out_slot,
                  uint16_t out_slot_size);

uint16_t st_fifo_get_sensor_occurrence(st_fifo_out_slot *fifo_out_slot,
uint16_t st_fifo_get_sensor_occurrence(st_fifo_out_slot
                                       *fifo_out_slot,
                                       uint16_t out_slot_size,
                                       st_fifo_sensor_type sensor_type);

+414 −199

File changed.

Preview size limit exceeded, changes collapsed.

Loading