Skip to content

Commit 24347d2

Browse files
author
albezanc
committed
lps27hhw: added endianness support #7
1 parent acb27f9 commit 24347d2

2 files changed

Lines changed: 203 additions & 27 deletions

File tree

lps27hhw_STdC/driver/lps27hhw_reg.c

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
******************************************************************************
77
* @attention
88
*
9-
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
9+
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
1010
* All rights reserved.</center></h2>
1111
*
1212
* This software component is licensed by ST under BSD 3-Clause license,
@@ -418,10 +418,15 @@ int32_t lps27hhw_data_rate_get(stmdev_ctx_t *ctx, lps27hhw_odr_t *val)
418418
* @retval interface status (MANDATORY: return 0 -> no Error)
419419
*
420420
*/
421-
int32_t lps27hhw_pressure_ref_set(stmdev_ctx_t *ctx, uint8_t *buff)
421+
int32_t lps27hhw_pressure_ref_set(stmdev_ctx_t *ctx, int16_t val)
422422
{
423+
uint8_t buff[2];
423424
int32_t ret;
425+
426+
buff[1] = (uint8_t) ((uint16_t)val / 256U);
427+
buff[0] = (uint8_t) ((uint16_t)val - (buff[1] * 256U));
424428
ret = lps27hhw_write_reg(ctx, LPS27HHW_REF_P_L, buff, 2);
429+
425430
return ret;
426431
}
427432

@@ -436,10 +441,15 @@ int32_t lps27hhw_pressure_ref_set(stmdev_ctx_t *ctx, uint8_t *buff)
436441
* @retval interface status (MANDATORY: return 0 -> no Error)
437442
*
438443
*/
439-
int32_t lps27hhw_pressure_ref_get(stmdev_ctx_t *ctx, uint8_t *buff)
444+
int32_t lps27hhw_pressure_ref_get(stmdev_ctx_t *ctx, int16_t *val)
440445
{
446+
uint8_t buff[2];
441447
int32_t ret;
448+
442449
ret = lps27hhw_read_reg(ctx, LPS27HHW_REF_P_L, buff, 2);
450+
*val = (int16_t)buff[1];
451+
*val = (*val * 256) + (int16_t)buff[0];
452+
443453
return ret;
444454
}
445455

@@ -453,10 +463,15 @@ int32_t lps27hhw_pressure_ref_get(stmdev_ctx_t *ctx, uint8_t *buff)
453463
* @retval interface status (MANDATORY: return 0 -> no Error)
454464
*
455465
*/
456-
int32_t lps27hhw_pressure_offset_set(stmdev_ctx_t *ctx, uint8_t *buff)
466+
int32_t lps27hhw_pressure_offset_set(stmdev_ctx_t *ctx, int16_t val)
457467
{
468+
uint8_t buff[2];
458469
int32_t ret;
470+
471+
buff[1] = (uint8_t) ((uint16_t)val / 256U);
472+
buff[0] = (uint8_t) ((uint16_t)val - (buff[1] * 256U));
459473
ret = lps27hhw_write_reg(ctx, LPS27HHW_RPDS_L, buff, 2);
474+
460475
return ret;
461476
}
462477

@@ -471,10 +486,15 @@ int32_t lps27hhw_pressure_offset_set(stmdev_ctx_t *ctx, uint8_t *buff)
471486
* @retval interface status (MANDATORY: return 0 -> no Error)
472487
*
473488
*/
474-
int32_t lps27hhw_pressure_offset_get(stmdev_ctx_t *ctx, uint8_t *buff)
489+
int32_t lps27hhw_pressure_offset_get(stmdev_ctx_t *ctx, int16_t *val)
475490
{
491+
uint8_t buff[2];
476492
int32_t ret;
493+
477494
ret = lps27hhw_read_reg(ctx, LPS27HHW_RPDS_L, buff, 2);
495+
*val = (int16_t)buff[1];
496+
*val = (*val * 256) + (int16_t)buff[0];
497+
478498
return ret;
479499
}
480500

@@ -576,10 +596,17 @@ int32_t lps27hhw_temp_flag_data_ready_get(stmdev_ctx_t *ctx, uint8_t *val)
576596
* @retval interface status (MANDATORY: return 0 -> no Error)
577597
*
578598
*/
579-
int32_t lps27hhw_pressure_raw_get(stmdev_ctx_t *ctx, uint8_t *buff)
599+
int32_t lps27hhw_pressure_raw_get(stmdev_ctx_t *ctx, uint32_t *buff)
580600
{
601+
uint8_t reg[3];
581602
int32_t ret;
582-
ret = lps27hhw_read_reg(ctx, LPS27HHW_PRESS_OUT_XL, buff, 3);
603+
604+
ret = lps27hhw_read_reg(ctx, LPS27HHW_PRESS_OUT_XL, reg, 3);
605+
*buff = reg[2];
606+
*buff = (*buff * 256) + reg[1];
607+
*buff = (*buff * 256) + reg[0];
608+
*buff *= 256;
609+
583610
return ret;
584611
}
585612

@@ -591,10 +618,15 @@ int32_t lps27hhw_pressure_raw_get(stmdev_ctx_t *ctx, uint8_t *buff)
591618
* @retval interface status (MANDATORY: return 0 -> no Error)
592619
*
593620
*/
594-
int32_t lps27hhw_temperature_raw_get(stmdev_ctx_t *ctx, uint8_t *buff)
621+
int32_t lps27hhw_temperature_raw_get(stmdev_ctx_t *ctx, int16_t *buff)
595622
{
623+
uint8_t reg[2];
596624
int32_t ret;
597-
ret = lps27hhw_read_reg(ctx, LPS27HHW_TEMP_OUT_L, buff, 2);
625+
626+
ret = lps27hhw_read_reg(ctx, LPS27HHW_TEMP_OUT_L, reg, 2);
627+
*buff = reg[1];
628+
*buff = (*buff * 256) + reg[0];
629+
598630
return ret;
599631
}
600632

@@ -606,10 +638,17 @@ int32_t lps27hhw_temperature_raw_get(stmdev_ctx_t *ctx, uint8_t *buff)
606638
* @retval interface status (MANDATORY: return 0 -> no Error)
607639
*
608640
*/
609-
int32_t lps27hhw_fifo_pressure_raw_get(stmdev_ctx_t *ctx, uint8_t *buff)
641+
int32_t lps27hhw_fifo_pressure_raw_get(stmdev_ctx_t *ctx, uint32_t *buff)
610642
{
643+
uint8_t reg[3];
611644
int32_t ret;
612-
ret = lps27hhw_read_reg(ctx, LPS27HHW_FIFO_DATA_OUT_PRESS_XL, buff, 3);
645+
646+
ret = lps27hhw_read_reg(ctx, LPS27HHW_FIFO_DATA_OUT_PRESS_XL, reg, 3);
647+
*buff = reg[2];
648+
*buff = (*buff * 256) + reg[1];
649+
*buff = (*buff * 256) + reg[0];
650+
*buff *= 256;
651+
613652
return ret;
614653
}
615654

@@ -621,10 +660,15 @@ int32_t lps27hhw_fifo_pressure_raw_get(stmdev_ctx_t *ctx, uint8_t *buff)
621660
* @retval interface status (MANDATORY: return 0 -> no Error)
622661
*
623662
*/
624-
int32_t lps27hhw_fifo_temperature_raw_get(stmdev_ctx_t *ctx, uint8_t *buff)
663+
int32_t lps27hhw_fifo_temperature_raw_get(stmdev_ctx_t *ctx, int16_t *buff)
625664
{
665+
uint8_t reg[2];
626666
int32_t ret;
627-
ret = lps27hhw_read_reg(ctx, LPS27HHW_FIFO_DATA_OUT_TEMP_L, buff, 2);
667+
668+
ret = lps27hhw_read_reg(ctx, LPS27HHW_FIFO_DATA_OUT_TEMP_L, reg, 2);
669+
*buff = reg[1];
670+
*buff = (*buff * 256) + reg[0];
671+
628672
return ret;
629673
}
630674

0 commit comments

Comments
 (0)