Skip to content

Commit ffff6a8

Browse files
committed
Read always both FIFO_STATUS1 and FIFO_STATUS2 regs
Signed-off-by: Armando Visconti <armando.visconti@st.com>
1 parent 164df10 commit ffff6a8

1 file changed

Lines changed: 60 additions & 39 deletions

File tree

lsm6dso_reg.c

Lines changed: 60 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6714,105 +6714,126 @@ int32_t lsm6dso_batch_counter_threshold_get(const stmdev_ctx_t *ctx,
67146714
}
67156715

67166716
/**
6717-
* @brief Number of unread sensor data(TAG + 6 bytes) stored in FIFO.[get]
6717+
* @brief Number of unread sensor data (TAG + 6 bytes) stored in FIFO.[get]
67186718
*
6719-
* @param ctx read / write interface definitions
6720-
* @param val Get the values of diff_fifo in reg FIFO_STATUS1
6721-
* @retval interface status (MANDATORY: return 0 -> no Error)
6719+
* @param ctx Read / write interface definitions.(ptr)
6720+
* @param val Read the value of diff_fifo in reg FIFO_STATUS1 and FIFO_STATUS2
6721+
* @retval Interface status (MANDATORY: return 0 -> no Error).
67226722
*
67236723
*/
6724-
int32_t lsm6dso_fifo_data_level_get(const stmdev_ctx_t *ctx, uint16_t *val)
6724+
int32_t lsm6dso_fifo_data_level_get(const stmdev_ctx_t *ctx,
6725+
uint16_t *val)
67256726
{
6726-
lsm6dso_fifo_status1_t fifo_status1;
6727-
lsm6dso_fifo_status2_t fifo_status2;
6727+
uint8_t reg[2];
6728+
lsm6dso_fifo_status1_t *fifo_status1 = (lsm6dso_fifo_status1_t *)&reg[0];
6729+
lsm6dso_fifo_status2_t *fifo_status2 = (lsm6dso_fifo_status2_t *)&reg[1];
67286730
int32_t ret;
67296731

6730-
ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_STATUS1,
6731-
(uint8_t *)&fifo_status1, 1);
6732-
6732+
/* read both FIFO_STATUS1 + FIFO_STATUS2 regs */
6733+
ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_STATUS1, (uint8_t *)reg, 2);
67336734
if (ret == 0)
67346735
{
6735-
ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_STATUS2,
6736-
(uint8_t *)&fifo_status2, 1);
6737-
*val = ((uint16_t)fifo_status2.diff_fifo << 8) +
6738-
(uint16_t)fifo_status1.diff_fifo;
6736+
*val = fifo_status2->diff_fifo;
6737+
*val = (*val * 256U) + fifo_status1->diff_fifo;
67396738
}
67406739

67416740
return ret;
67426741
}
67436742

67446743
/**
6745-
* @brief FIFO status.[get]
6744+
* @brief Smart FIFO status.[get]
67466745
*
6747-
* @param ctx read / write interface definitions
6748-
* @param val registers FIFO_STATUS2
6749-
* @retval interface status (MANDATORY: return 0 -> no Error)
6746+
* @param ctx Read / write interface definitions.(ptr)
6747+
* @param val Read registers FIFO_STATUS2
6748+
* @retval Interface status (MANDATORY: return 0 -> no Error).
67506749
*
67516750
*/
67526751
int32_t lsm6dso_fifo_status_get(const stmdev_ctx_t *ctx,
6753-
lsm6dso_fifo_status2_t *val)
6752+
lsm6dso_fifo_status2_t *val)
67546753
{
6754+
uint8_t reg[2];
6755+
lsm6dso_fifo_status2_t *fifo_status2 = (lsm6dso_fifo_status2_t *)&reg[1];
67556756
int32_t ret;
67566757

6757-
ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_STATUS2, (uint8_t *) val, 1);
6758+
/* read both FIFO_STATUS1 + FIFO_STATUS2 regs */
6759+
ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_STATUS1, (uint8_t *)reg, 2);
6760+
if (ret == 0)
6761+
{
6762+
*val = *fifo_status2;
6763+
}
67586764

67596765
return ret;
67606766
}
67616767

67626768
/**
67636769
* @brief Smart FIFO full status.[get]
67646770
*
6765-
* @param ctx read / write interface definitions
6766-
* @param val Get the values of fifo_full_ia in reg FIFO_STATUS2
6767-
* @retval interface status (MANDATORY: return 0 -> no Error)
6771+
* @param ctx Read / write interface definitions.(ptr)
6772+
* @param val Read the values of fifo_full_ia in reg FIFO_STATUS2
6773+
* @retval Interface status (MANDATORY: return 0 -> no Error).
67686774
*
67696775
*/
67706776
int32_t lsm6dso_fifo_full_flag_get(const stmdev_ctx_t *ctx, uint8_t *val)
67716777
{
6772-
lsm6dso_fifo_status2_t reg;
6778+
uint8_t reg[2];
6779+
lsm6dso_fifo_status2_t *fifo_status2 = (lsm6dso_fifo_status2_t *)&reg[1];
67736780
int32_t ret;
67746781

6775-
ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_STATUS2, (uint8_t *)&reg, 1);
6776-
*val = reg.fifo_full_ia;
6782+
/* read both FIFO_STATUS1 + FIFO_STATUS2 regs */
6783+
ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_STATUS1, (uint8_t *)reg, 2);
6784+
if (ret == 0)
6785+
{
6786+
*val = fifo_status2->fifo_full_ia;
6787+
}
67776788

67786789
return ret;
67796790
}
67806791

67816792
/**
67826793
* @brief FIFO overrun status.[get]
67836794
*
6784-
* @param ctx read / write interface definitions
6785-
* @param val Get the values of fifo_over_run_latched in
6786-
* reg FIFO_STATUS2
6787-
* @retval interface status (MANDATORY: return 0 -> no Error)
6795+
* @param ctx Read / write interface definitions.(ptr)
6796+
* @param val Read the values of fifo_over_run_latched in
6797+
* reg FIFO_STATUS2
6798+
* @retval Interface status (MANDATORY: return 0 -> no Error).
67886799
*
67896800
*/
67906801
int32_t lsm6dso_fifo_ovr_flag_get(const stmdev_ctx_t *ctx, uint8_t *val)
67916802
{
6792-
lsm6dso_fifo_status2_t reg;
6803+
uint8_t reg[2];
6804+
lsm6dso_fifo_status2_t *fifo_status2 = (lsm6dso_fifo_status2_t *)&reg[1];
67936805
int32_t ret;
67946806

6795-
ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_STATUS2, (uint8_t *)&reg, 1);
6796-
*val = reg.fifo_ovr_ia;
6807+
/* read both FIFO_STATUS1 + FIFO_STATUS2 regs */
6808+
ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_STATUS1, (uint8_t *)reg, 2);
6809+
if (ret == 0)
6810+
{
6811+
*val = fifo_status2->fifo_ovr_ia;
6812+
}
67976813

67986814
return ret;
67996815
}
68006816

68016817
/**
68026818
* @brief FIFO watermark status.[get]
68036819
*
6804-
* @param ctx read / write interface definitions
6805-
* @param val Get the values of fifo_wtm_ia in reg FIFO_STATUS2
6806-
* @retval interface status (MANDATORY: return 0 -> no Error)
6820+
* @param ctx Read / write interface definitions.(ptr)
6821+
* @param val Read the values of fifo_wtm_ia in reg FIFO_STATUS2
6822+
* @retval Interface status (MANDATORY: return 0 -> no Error).
68076823
*
68086824
*/
68096825
int32_t lsm6dso_fifo_wtm_flag_get(const stmdev_ctx_t *ctx, uint8_t *val)
68106826
{
6811-
lsm6dso_fifo_status2_t reg;
6827+
uint8_t reg[2];
6828+
lsm6dso_fifo_status2_t *fifo_status2 = (lsm6dso_fifo_status2_t *)&reg[1];
68126829
int32_t ret;
68136830

6814-
ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_STATUS2, (uint8_t *)&reg, 1);
6815-
*val = reg.fifo_wtm_ia;
6831+
/* read both FIFO_STATUS1 + FIFO_STATUS2 regs */
6832+
ret = lsm6dso_read_reg(ctx, LSM6DSO_FIFO_STATUS1, (uint8_t *)reg, 2);
6833+
if (ret == 0)
6834+
{
6835+
*val = fifo_status2->fifo_wtm_ia;
6836+
}
68166837

68176838
return ret;
68186839
}

0 commit comments

Comments
 (0)