SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
sensor/accelerometer/bma/SensorBMA4XX.hpp
Go to the documentation of this file.
1
31#pragma once
32
33#include "../../../SensorBuildOpt.h"
34#if !SENSORLIB_EXCLUDE_BMA4XX_COMMON
35
36#include "../../../platform/comm/ComplexStaticDeviceWithHal.hpp"
37#include "../../../sensor/AccelerometerBase.hpp"
38#include "../../../bosch/bma4xx/bma4.h"
39
43static constexpr uint8_t BMA4XX_I2C_ADDR_SDO_LOW = (0x18);
47static constexpr uint8_t BMA4XX_I2C_ADDR_SDO_HIGH = (0x19);
48
49
55enum class AccelBandwidth : uint8_t {
56 OSR4_AVG1 = 0,
57 OSR2_AVG2 = 1,
58 NORMAL_AVG4 = 2,
59 CIC_AVG8 = 3,
60 RES_AVG16 = 4,
61 RES_AVG32 = 5,
62 RES_AVG64 = 6,
63 RES_AVG128 = 7
64};
65
70enum class AccelPerfMode : uint8_t {
71 CIC_AVG_MODE = 0,
73};
74
80enum class TapType {
81 NO_TAP = 0,
82 SINGLE_TAP = 1,
83 DOUBLE_TAP = 2,
84 TRIPLE_TAP = 3,
85};
86
92enum class ActivityType {
93 STATIONARY = 0,
94 WALKING = 1,
95 RUNNING = 2,
96 UNKNOWN = 3,
97};
98
106{
107enum class Capability : uint32_t {
108 None = 0,
109 SupportDataReady = (1 << 0),
110 SupportAnyMotion = (1 << 1),
111 SupportNoMotion = (1 << 2),
112 SupportTap = (1 << 3),
113 SupportStepDetector = (1 << 4),
114 SupportStepCounter = (1 << 5),
115 SupportActivity = (1 << 6),
116 SupportTilt = (1 << 7),
117 SupportAxisRemap = (1 << 8),
118};
119
121{
122 return static_cast<Capability>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
123}
124
125constexpr bool operator&(Capability a, Capability b)
126{
127 return (static_cast<uint32_t>(a) & static_cast<uint32_t>(b)) != 0;
128}
129}
130
162{
163public:
164
168 using bma4_dev_t = struct bma4_dev ;
169
177 uint8_t x_axis : 1;
178 uint8_t y_axis : 1;
179 uint8_t z_axis : 1;
180
187 MotionAxesConfig(uint8_t x = 1, uint8_t y = 1, uint8_t z = 1)
188 : x_axis(x), y_axis(y), z_axis(z) {}
189 };
190
195 BMA422 = 0x12,
196 BMA423 = 0x13,
197 BMA456 = 0x16,
198 BMA456_AN_SEC = 0x1A
199 };
200
201protected:
207 {
208 }
209
214 ~SensorBMA4XX() = default;
215
216
217public:
224 bool readData(AccelerometerData &data) override
225 {
226 if (!dev) {
227 SENSORLIB_LOG_E("Device not initialized");
228 return false;
229 }
230 struct bma4_accel sens_data = { 0, 0, 0 };
231 if (bma4_read_accel_xyz(&sens_data, dev.get()) != 0) {
232 SENSORLIB_LOG_E("Failed to read acceleration data");
233 return false;
234 }
235 data.raw.x = sens_data.x - _x_offset;
236 data.raw.y = sens_data.y - _y_offset;
237 data.raw.z = sens_data.z - _z_offset;
238
240
241 data.mps2.x = (float)(sens_data.x) * _sensitivity;
242 data.mps2.y = (float)(sens_data.y) * _sensitivity;
243 data.mps2.z = (float)(sens_data.z) * _sensitivity;
244
248
249 return true;
250 }
251
257 bool isDataReady() override
258 {
259 uint16_t int_status = 0;
260 bma4_read_int_status(&int_status, dev.get());
261 return (int_status & BMA4_ACCEL_DATA_RDY_INT) != 0;
262 }
263
269 bool reset() override
270 {
271 if (!dev) {
272 SENSORLIB_LOG_E("Device not initialized");
273 return false;
274 }
275 return bma4_soft_reset(dev.get()) == 0;
276 }
277
283 bool selfTest() override
284 {
285 if (!dev) {
286 SENSORLIB_LOG_E("Device not initialized");
287 return false;
288 }
289 int8_t selftest_rslt = 0;
290 if (bma4_perform_accel_selftest(&selftest_rslt, dev.get()) != 0) {
291 SENSORLIB_LOG_I("Self test failed");
292 return false;
293 }
294 return selftest_rslt == 0;
295 }
296
297
305 {
306 uint8_t regValue = 0;
307 switch (range) {
308 case AccelFullScaleRange::FS_2G: // ±2g
309 regValue = BMA4_ACCEL_RANGE_2G;
310 break;
311 case AccelFullScaleRange::FS_4G: // ±4g
312 regValue = BMA4_ACCEL_RANGE_4G;
313 break;
314 case AccelFullScaleRange::FS_8G: // ±8g
315 regValue = BMA4_ACCEL_RANGE_8G;
316 break;
317 case AccelFullScaleRange::FS_16G: // ±16g
318 regValue = BMA4_ACCEL_RANGE_16G;
319 break;
320 default:
321 SENSORLIB_LOG_E("Error: Invalid range %d\n", static_cast<int>(range));
322 return false;
323 }
324 _accel_conf.range = regValue;
325 if (bma4_set_accel_config(&_accel_conf, dev.get()) == 0) {
326 float tmp_range = AccelerometerUtils::rangeToG(range);
327 _config.range = (int)tmp_range;
328 _sensitivity = tmp_range / _half_scale;
329 return true;
330 }
331 return false;
332 }
333
341 bool setOutputDataRate(float data_rate_hz) override
342 {
343 int rangeInt = static_cast<int>(data_rate_hz * 100 + 0.5);
344 SENSORLIB_LOG_D("Input: %.2f, Integer: %d\n", data_rate_hz, rangeInt);
345 uint8_t regValue = 0;
346 switch (rangeInt) {
347 case 78: // 0.78HZ
348 regValue = BMA4_OUTPUT_DATA_RATE_0_78HZ;
349 break;
350 case 156: // 1.56HZ
351 regValue = BMA4_OUTPUT_DATA_RATE_1_56HZ;
352 break;
353 case 312: // 3.12HZ
354 regValue = BMA4_OUTPUT_DATA_RATE_3_12HZ;
355 break;
356 case 625: // 6.25HZ
357 regValue = BMA4_OUTPUT_DATA_RATE_6_25HZ;
358 break;
359 case 1250: // 12.5HZ
360 regValue = BMA4_OUTPUT_DATA_RATE_12_5HZ;
361 break;
362 case 2500: // 25.0HZ
363 regValue = BMA4_OUTPUT_DATA_RATE_25HZ;
364 break;
365 case 5000: // 50.0HZ
366 regValue = BMA4_OUTPUT_DATA_RATE_50HZ;
367 break;
368 case 10000: // 100.0HZ
369 regValue = BMA4_OUTPUT_DATA_RATE_100HZ;
370 break;
371 case 20000: // 200.0HZ
372 regValue = BMA4_OUTPUT_DATA_RATE_200HZ;
373 break;
374 case 40000: // 400.0HZ
375 regValue = BMA4_OUTPUT_DATA_RATE_400HZ;
376 break;
377 case 80000: // 800.0HZ
378 regValue = BMA4_OUTPUT_DATA_RATE_800HZ;
379 break;
380 case 160000: // 1600.0HZ
381 regValue = BMA4_OUTPUT_DATA_RATE_1600HZ;
382 break;
383 default:
384 SENSORLIB_LOG_E("Error: Invalid range %.2f\n", data_rate_hz);
385 break;
386 }
387 _accel_conf.odr = regValue;
388 if (bma4_set_accel_config(&_accel_conf, dev.get()) == 0) {
389 _config.sample_rate = data_rate_hz;
390 return true;
391 }
392 return false;
393 }
394
402 {
403 uint8_t regValue = 0;
404 switch (bandwidth) {
406 regValue = BMA4_ACCEL_OSR4_AVG1;
407 break;
409 regValue = BMA4_ACCEL_OSR2_AVG2;
410 break;
412 regValue = BMA4_ACCEL_NORMAL_AVG4;
413 break;
415 regValue = BMA4_ACCEL_CIC_AVG8;
416 break;
418 regValue = BMA4_ACCEL_RES_AVG16;
419 break;
421 regValue = BMA4_ACCEL_RES_AVG32;
422 break;
424 regValue = BMA4_ACCEL_RES_AVG64;
425 break;
427 regValue = BMA4_ACCEL_RES_AVG128;
428 break;
429 default:
430 SENSORLIB_LOG_E("Error: Invalid bandwidth %d\n", static_cast<int>(bandwidth));
431 return false;
432 }
433 _accel_conf.bandwidth = regValue;
434 if (bma4_set_accel_config(&_accel_conf, dev.get()) == 0) {
435 return true;
436 }
437 return false;
438 }
439
449 {
450 uint8_t regValue = 0;
451 switch (mode) {
453 regValue = BMA4_CIC_AVG_MODE;
454 break;
456 regValue = BMA4_CONTINUOUS_MODE;
457 break;
458 default:
459 SENSORLIB_LOG_E("Error: Invalid performance mode %d\n", static_cast<int>(mode));
460 return false;
461 }
462 _accel_conf.perf_mode = regValue;
463 if (bma4_set_accel_config(&_accel_conf, dev.get()) == 0) {
464 return true;
465 }
466 return false;
467 }
468
475 bool setOperationMode(OperationMode mode) override
476 {
477 bool enable = false;
478 switch (mode) {
480 enable = false;
481 break;
483 enable = true;
484 break;
485 default:
486 SENSORLIB_LOG_E("Error: Invalid operation mode %d\n", static_cast<int>(mode));
487 break;
488 }
489 if (bma4_set_accel_enable(enable, dev.get()) == 0) {
490 _config.mode = mode;
491 return true;
492 }
493 return false;
494 }
495
506 bool configAccelerometer(OperationMode mode, AccelFullScaleRange range, float data_rate_hz,
507 AccelBandwidth bandwidth, AccelPerfMode perf_mode)
508
509 {
510 bool rslt;
511
512 rslt = setFullScaleRange(range);
513 if (!rslt) {
514 return false;
515 }
516
517 rslt = setOutputDataRate(data_rate_hz);
518 if (!rslt) {
519 return false;
520 }
521
522 rslt = setBandwidth(bandwidth);
523 if (!rslt) {
524 return false;
525 }
526
527 rslt = setPerformanceMode(perf_mode);
528 if (!rslt) {
529 return false;
530 }
531
532 rslt = setOperationMode(mode);
533 if (!rslt) {
534 return false;
535 }
536 return true;
537 }
538
544 float getTemperature() const
545 {
546 float temperature = NAN;
547 int32_t raw_temperature = 0;
548 if (bma4_get_temperature(&raw_temperature, BMA4_DEG, dev.get()) == 0) {
549 if (((raw_temperature - 23) / BMA4_SCALE_TEMP) != 0x80) {
550 temperature = static_cast<float>(raw_temperature) / BMA4_SCALE_TEMP;
551 }
552 }
553 return temperature;
554 }
555
567 {
568 uint16_t int_status = 0;
569 if (bma4_read_int_status(&int_status, dev.get()) != 0) {
570 return 0;
571 }
572 return int_status;
573 }
574
583 bool isInterruptActive(uint16_t interrupt_mask)
584 {
585 uint16_t int_status = getInterruptStatus();
586 return (int_status & interrupt_mask) != 0;
587 }
588
606 bool edge_trigger = false,
607 bool active_low = true,
608 bool output_en = true,
609 bool input_en = false)
610 {
611 struct bma4_int_pin_config config ;
612 config.edge_ctrl = edge_trigger ? BMA4_EDGE_TRIGGER : BMA4_LEVEL_TRIGGER;
613 config.lvl = active_low ? BMA4_ACTIVE_LOW : BMA4_ACTIVE_HIGH;
614 config.od = active_low ? BMA4_OPEN_DRAIN : BMA4_PUSH_PULL;
615 config.output_en = output_en ? BMA4_OUTPUT_ENABLE : BMA4_OUTPUT_DISABLE;
616 config.input_en = input_en ? BMA4_INPUT_ENABLE : BMA4_INPUT_DISABLE;
617 uint8_t int_line = pin_map == InterruptPinMap::PIN1 ? BMA4_INTR1_MAP : BMA4_INTR2_MAP;
618 return bma4_set_int_pin_config(&config, int_line, dev.get()) == 0;
619 }
620
634 bool enableInterrupt(InterruptPinMap pin_map, uint16_t interrupt_sources, bool enable)
635 {
636 uint8_t int_line = 0;
637 switch (pin_map) {
639 int_line = 0x00;
640 break;
642 int_line = 0x01;
643 break;
644 default:
645 SENSORLIB_LOG_E("Invalid interrupt pin specified");
646 return false;
647 }
648
649 int8_t result = bma4_map_interrupt(int_line, interrupt_sources, enable, dev.get());
650 if (result != 0) {
651 SENSORLIB_LOG_E("Failed to %s interrupt 0x%04X on pin %d: %d",
652 enable ? "enable" : "disable",
653 interrupt_sources,
654 (pin_map == InterruptPinMap::PIN1) ? 1 : 2,
655 result);
656 return false;
657 }
658
659 return true;
660 }
661
668 virtual bool setRemapAxes(SensorRemap remap)
669 {
670 if (_remap_reg_offset == 0) {
671 SENSORLIB_LOG_E("Remap feature not supported for this model");
672 return false;
673 }
674 struct bma4_remap remap_data;
675 switch (remap) {
677 remap_data.x = BMA4_NEG_Y;
678 remap_data.y = BMA4_X;
679 remap_data.z = BMA4_Z;
680 break;
682 remap_data.x = BMA4_X;
683 remap_data.y = BMA4_Y;
684 remap_data.z = BMA4_Z;
685 break;
687 remap_data.x = BMA4_Y;
688 remap_data.y = BMA4_NEG_Y;
689 remap_data.z = BMA4_Z;
690 break;
692 remap_data.x = BMA4_NEG_X;
693 remap_data.y = BMA4_NEG_Y;
694 remap_data.z = BMA4_Z;
695 break;
697 remap_data.x = BMA4_NEG_X;
698 remap_data.y = BMA4_Y;
699 remap_data.z = BMA4_NEG_Z;
700 break;
702 remap_data.x = BMA4_Y;
703 remap_data.y = BMA4_X;
704 remap_data.z = BMA4_NEG_Z;
705 break;
707 remap_data.x = BMA4_X;
708 remap_data.y = BMA4_NEG_Y;
709 remap_data.z = BMA4_NEG_Z;
710 break;
712 remap_data.x = BMA4_NEG_Y;
713 remap_data.y = BMA4_NEG_X;
714 remap_data.z = BMA4_NEG_Z;
715 break;
716 default:
717 SENSORLIB_LOG_E("Invalid remap option");
718 return false;
719 }
720 SENSORLIB_LOG_D("Remap register offset: 0x%X", _remap_reg_offset);
721 auto feature_config = std::unique_ptr<uint8_t[]>(new uint8_t[dev->feature_len]());
722 return bma4_set_remap_axes(&remap_data, feature_config.get(),
723 _remap_reg_offset, dev->feature_len, dev.get()) == 0;
724 }
725
731 const char *getModelName() const
732 {
733 if (!dev) {
734 SENSORLIB_LOG_E("Device not initialized");
735 return "Unknown";
736 }
737 switch (dev->chip_id) {
739 return "BMA422";
741 return "BMA423";
743 return "BMA456";
745 return "BMA456_AN_SEC";
746 default:
747 return "Unknown";
748 }
749 }
750
757 {
758 return dev.get();
759 }
760
770 uint32_t getTimeSampleMs() const
771 {
772 uint32_t sensor_time_ticks = 0;
773 bma4_get_sensor_time(&sensor_time_ticks, dev.get());
774 // Convert ticks to milliseconds (1 tick = 39.0625 μs = 0.0390625 ms)
775 float time_ms = sensor_time_ticks * 0.0390625f;
776 return static_cast<uint32_t>(time_ms);
777 }
778
785
789 virtual bool enableDataReady(bool enable = true, InterruptPinMap pin_map = InterruptPinMap::PIN1)
790 {
791 (void)enable;
792 (void)pin_map;
793 return false;
794 }
795
799 virtual bool enableAnyMotionDetection(const MotionAxesConfig &cfg, bool enable,
800 bool interrupt_enable = false,
802 {
803 (void)cfg;
804 (void)enable;
805 (void)interrupt_enable;
806 (void)pin_map;
807 return false;
808 }
809
813 virtual bool enableNoMotionDetection(const MotionAxesConfig &cfg, bool enable,
814 bool interrupt_enable = false,
816 {
817 (void)cfg;
818 (void)enable;
819 (void)interrupt_enable;
820 (void)pin_map;
821 return false;
822 }
823
827 virtual bool configAnyMotion(uint16_t threshold, uint16_t duration)
828 {
829 (void)threshold;
830 (void)duration;
831 return false;
832 }
833
837 virtual bool configNoMotion(uint16_t threshold, uint16_t duration)
838 {
839 (void)threshold;
840 (void)duration;
841 return false;
842 }
843
848 virtual bool configMotion(bool any_motion, uint16_t threshold, uint16_t duration)
849 {
850 (void)any_motion;
851 (void)threshold;
852 (void)duration;
853 return false;
854 }
855
859 virtual bool configAnyMotionInPhysicalUnits(float threshold_mg, float duration_ms)
860 {
861 (void)threshold_mg;
862 (void)duration_ms;
863 return false;
864 }
865
869 virtual bool configNoMotionInPhysicalUnits(float threshold_mg, float duration_ms)
870 {
871 (void)threshold_mg;
872 (void)duration_ms;
873 return false;
874 }
875
879 virtual bool enableTapDetector(bool enable, bool interrupt_enable = false,
881 {
882 (void)enable;
883 (void)interrupt_enable;
884 (void)pin_map;
885 return false;
886 }
887
891 virtual bool enableStepCounter(bool enable, uint16_t step_counter_wm = 1,
892 bool reset_counter = false)
893 {
894 (void)enable;
895 (void)step_counter_wm;
896 (void)reset_counter;
897 return false;
898 }
899
903 virtual bool enableStepDetector(bool enable, bool interrupt_enable = false,
905 {
906 (void)enable;
907 (void)interrupt_enable;
908 (void)pin_map;
909 return false;
910 }
911
915 virtual bool enableActivityRecognition(bool enable, bool interrupt_enable = false,
917 {
918 (void)enable;
919 (void)interrupt_enable;
920 (void)pin_map;
921 return false;
922 }
923
927 virtual bool enableTiltDetector(bool enable, bool interrupt_enable = false,
929 {
930 (void)enable;
931 (void)interrupt_enable;
932 (void)pin_map;
933 return false;
934 }
935
941 virtual void update() = 0;
942
943private:
950 virtual bool boschInitImpl() = 0;
951
959 bool initImpl(uint8_t param) override
960 {
961 dev = std::make_unique<struct bma4_dev>();
962 if (!dev) {
963 SENSORLIB_LOG_E(" Device handler malloc failed!");
964 return false;
965 }
966 switch (_iface) {
967 case COMM_I2C:
968 dev->intf = BMA4_I2C_INTF;
969 break;
970 case COMM_SPI:
971 dev->intf = BMA4_SPI_INTF;
972 break;
973 default:
974 return false;
975 }
978 dev->intf_ptr = staticComm.get();
980 dev->read_write_len = 32;
981 dev->perf_mode_status = BMA4_DISABLE;
982
983 if (bma4_soft_reset(dev.get()) != 0) {
984 SENSORLIB_LOG_E("BMA4xx soft reset failed");
985 return false;
986 }
987 hal->delay(20);
988
989
990 if (!boschInitImpl()) {
991 SENSORLIB_LOG_E("BMA4xx sensor initialization failed");
992 return false;
993 }
994
995 _info.uid = dev->chip_id;
996 _info.manufacturer = "Bosch-Sensortec";
1000 _info.version = 1; // Set a default version
1001
1002 // Set default axis remapping
1003 struct bma4_axes_remap axes_remap;
1004 axes_remap.x_axis = BMA4_MAP_X_AXIS;
1005 axes_remap.x_axis_sign = BMA4_MAP_POSITIVE;
1006 axes_remap.y_axis = BMA4_MAP_Y_AXIS;
1007 axes_remap.y_axis_sign = BMA4_MAP_POSITIVE;
1008 axes_remap.z_axis = BMA4_MAP_Z_AXIS;
1009 axes_remap.z_axis_sign = BMA4_MAP_POSITIVE;
1010 dev->remap = axes_remap;
1011
1012 // Set accelerometer configuration values
1013 _accel_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4;
1014 _accel_conf.odr = BMA4_OUTPUT_DATA_RATE_50HZ;
1015 _accel_conf.perf_mode = BMA4_CIC_AVG_MODE;
1016 _accel_conf.range = BMA4_ACCEL_RANGE_2G;
1017
1019 _config.range = 2.0f;
1020 _config.sample_rate = 50.0f;
1021 _config.latency = 0;
1023
1024 // Calculate half scale
1025 _half_scale = powf(2.0f, (float)dev->resolution) / 2.0f;
1026
1027 SENSORLIB_LOG_D("Half scale calculated: %.0f (for %d-bit sensor)",
1028 _half_scale, dev->resolution);
1029
1030 // Set default full scale range to 2g
1032 SENSORLIB_LOG_E("Failed to set default 2g range");
1033 return false;
1034 }
1035
1036 // Set default output data rate to 50Hz
1037 if (!setOutputDataRate(50.0f)) {
1038 SENSORLIB_LOG_E("Failed to set default ODR 50Hz");
1039 return false;
1040 }
1041
1042 return true;
1043 }
1044
1045protected:
1046 std::unique_ptr<struct bma4_dev> dev;
1047 struct bma4_accel_config _accel_conf;
1050};
1051
1052#endif
@ ACCELEROMETER
Accelerometer sensor.
OperationMode
Enumeration of sensor operation modes.
SensorRemap
Enumeration representing different remapping options for the sensor's orientation.
@ BOTTOM_LAYER_BOTTOM_RIGHT_CORNER
@ BOTTOM_LAYER_TOP_RIGHT_CORNER
@ TOP_LAYER_BOTTOM_LEFT_CORNER
@ BOTTOM_LAYER_TOP_LEFT_CORNER
@ BOTTOM_LAYER_BOTTOM_LEFT_CORNER
@ TOP_LAYER_BOTTOM_RIGHT_CORNER
@ TOP_LAYER_RIGHT_CORNER
@ TOP_LAYER_LEFT_CORNER
AccelFullScaleRange
Enumeration of accelerometer full-scale range settings.
@ FS_16G
±16g range
InterruptPinMap
Enumeration of interrupt pin mapping options.
@ PIN1
Interrupt pin 1.
@ PIN2
Interrupt pin 2.
#define SENSORLIB_LOG_I(...)
#define SENSORLIB_LOG_E(...)
#define SENSORLIB_LOG_D(...)
@ COMM_SPI
@ COMM_I2C
SensorTemperature temperature(bhy)
Abstract base class for accelerometer implementations.
std::unique_ptr< SensorCommStatic > staticComm
std::unique_ptr< SensorHal > hal
bool setBandwidth(AccelBandwidth bandwidth)
Set the bandwidth of the accelerometer.
bool setOperationMode(OperationMode mode) override
Set the operation mode of the accelerometer.
virtual bool enableNoMotionDetection(const MotionAxesConfig &cfg, bool enable, bool interrupt_enable=false, InterruptPinMap pin_map=InterruptPinMap::PIN1)
Enable or disable no-motion detection (default: not supported)
bma4_dev bma4_dev_t
typedef for BMA4 device structure
bool isDataReady() override
Check if new accelerometer data is available.
virtual bool enableStepCounter(bool enable, uint16_t step_counter_wm=1, bool reset_counter=false)
Enable or disable step counter (default: not supported)
virtual bool configMotion(bool any_motion, uint16_t threshold, uint16_t duration)
Configure motion detection (default: not supported)
virtual void update()=0
Update the sensor data, this method is implemented by a subclass.
bool enableInterrupt(InterruptPinMap pin_map, uint16_t interrupt_sources, bool enable)
Enable or disable specific interrupt sources on a pin.
virtual bool configAnyMotionInPhysicalUnits(float threshold_mg, float duration_ms)
Configure any-motion using physical units (default: not supported)
virtual bool configNoMotion(uint16_t threshold, uint16_t duration)
Configure no-motion threshold and duration (default: not supported)
virtual bool setRemapAxes(SensorRemap remap)
Set the remapping of axes for the BMA4XX sensor.
uint32_t getTimeSampleMs() const
Get the current sensor time in milliseconds.
~SensorBMA4XX()=default
Destructor for the SensorBMA4XX class.
uint16_t getInterruptStatus()
Get the current interrupt status flags.
bool setOutputDataRate(float data_rate_hz) override
Set the output data rate of the accelerometer.
virtual bool enableStepDetector(bool enable, bool interrupt_enable=false, InterruptPinMap pin_map=InterruptPinMap::PIN1)
Enable or disable step detector (default: not supported)
bool setPerformanceMode(AccelPerfMode mode)
Set the performance mode of the accelerometer.
bool setInterruptPinConfig(InterruptPinMap pin_map, bool edge_trigger=false, bool active_low=true, bool output_en=true, bool input_en=false)
Configure the electrical properties of an interrupt pin.
SensorBMA4XX()
Constructor for the SensorBMA4XX class.
bma4_dev_t * getDev()
Get the device structure for the BMA4XX sensor.
virtual bool enableAnyMotionDetection(const MotionAxesConfig &cfg, bool enable, bool interrupt_enable=false, InterruptPinMap pin_map=InterruptPinMap::PIN1)
Enable or disable any-motion detection (default: not supported)
virtual bool enableTapDetector(bool enable, bool interrupt_enable=false, InterruptPinMap pin_map=InterruptPinMap::PIN1)
Enable or disable tap detection (default: not supported)
virtual bool enableTiltDetector(bool enable, bool interrupt_enable=false, InterruptPinMap pin_map=InterruptPinMap::PIN1)
Enable or disable tilt detection (default: not supported)
virtual bool enableActivityRecognition(bool enable, bool interrupt_enable=false, InterruptPinMap pin_map=InterruptPinMap::PIN1)
Enable or disable activity recognition (default: not supported)
const char * getModelName() const
Get the model name of the BMA4XX sensor.
bool selfTest() override
Perform a self-test on the sensor.
float getTemperature() const
Get the temperature reading from the sensor.
bool reset() override
Reset the sensor.
bool isInterruptActive(uint16_t interrupt_mask)
Check if a specific interrupt is active.
virtual bool configAnyMotion(uint16_t threshold, uint16_t duration)
Configure any-motion threshold and duration (default: not supported)
virtual BMA4XXCapability::Capability getCapabilities() const =0
Get supported capabilities.
virtual bool enableDataReady(bool enable=true, InterruptPinMap pin_map=InterruptPinMap::PIN1)
Enable data ready interrupt (default: not supported)
bool readData(AccelerometerData &data) override
Get the accelerometer data.
bool configAccelerometer(OperationMode mode, AccelFullScaleRange range, float data_rate_hz, AccelBandwidth bandwidth, AccelPerfMode perf_mode)
Configure the accelerometer.
BMA4XXModel
Enumeration of BMA4XX models.
virtual bool configNoMotionInPhysicalUnits(float threshold_mg, float duration_ms)
Configure no-motion using physical units (default: not supported)
std::unique_ptr< struct bma4_dev > dev
bool setFullScaleRange(AccelFullScaleRange range) override
Set the full-scale range of the accelerometer.
SensorConfig _config
Current configuration.
SensorInfo _info
Sensor information.
static int8_t sensor_static_read_data(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
static int8_t sensor_static_write_data(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
static void sensor_static_delay_us(uint32_t us, void *private_data)
float rangeToG(AccelFullScaleRange range)
Convert full-scale range enumeration to g-force value.
float gToMps2(float g_value)
Convert acceleration from g-force to m/s²
constexpr bool operator&(Capability a, Capability b)
constexpr Capability operator|(Capability a, Capability b)
AccelBandwidth
BMA4 Accelerometer averaging filter configuration These values configure the internal averaging filte...
@ OSR2_AVG2
OSR2 mode with 2 samples averaged.
@ NORMAL_AVG4
Normal mode with 4 samples averaged.
@ RES_AVG32
Resolution mode with 32 samples averaged.
@ OSR4_AVG1
OSR4 mode with 1 sample averaging (lowest power, highest noise)
@ RES_AVG64
Resolution mode with 64 samples averaged.
@ CIC_AVG8
CIC filter with 8 samples averaged.
@ RES_AVG128
Resolution mode with 128 samples averaged (best noise reduction, highest power)
@ RES_AVG16
Resolution mode with 16 samples averaged.
ActivityType
Activity detection type.
TapType
Tap detection type.
AccelPerfMode
BMA4 Accelerometer performance mode configuration Configures the internal filter behavior for sample ...
@ CONTINUOUS_MODE
Continuous mode: no averaging, raw samples with lower latency.
@ CIC_AVG_MODE
Averaging filter mode: samples are averaged based on configured bandwidth and ODR.
Structure representing accelerometer data.
SensorVector mps2
Acceleration in meters per second squared (m/s²)
float temperature
Temperature in degrees Celsius (if available)
RawVector raw
Raw sensor values in LSB (least significant bits)
int16_t x
X-axis raw value.
int16_t y
Y-axis raw value.
int16_t z
Z-axis raw value.
uint8_t z_axis
Enable motion detection on Z-axis (1=enabled, 0=disabled)
uint8_t y_axis
Enable motion detection on Y-axis (1=enabled, 0=disabled)
MotionAxesConfig(uint8_t x=1, uint8_t y=1, uint8_t z=1)
Constructor for MotionAxesConfig.
uint8_t x_axis
Enable motion detection on X-axis (1=enabled, 0=disabled)
uint32_t latency
Reporting latency in milliseconds.
float sample_rate
Sample rate in Hz.
float range
Measurement range.
SensorType type
Type of the sensor.
OperationMode mode
Operation mode.
uint8_t version
Hardware/firmware version.
uint8_t i2c_address
Default I2C address.
uint32_t uid
Unique identifier.
SensorType type
Sensor type.
const char * manufacturer
Manufacturer name.
const char * model
Model name/identifier.
float x
X-axis component.
float y
Y-axis component.
float z
Z-axis component.
int16_t x[5]
int16_t y[5]