Da Vinci Firmware 1
Firmware for the DaVinci-M rocket avionics board.
Loading...
Searching...
No Matches
lis2mdl_reg.c
Go to the documentation of this file.
1
20#include "lis2mdl_reg.h"
21#include "main.h"
22
23#ifndef LIS2MDL_CS_GPIO_Port
24#define LIS2MDL_CS_GPIO_Port MAG_CS_GPIO_Port // Example GPIO Port
25#endif
26#ifndef LIS2MDL_CS_Pin
27#define LIS2MDL_CS_Pin MAG_CS_Pin // Example GPIO Pin
28#endif
29
30// Placeholder for HAL_Delay function (usually available)
31#ifndef platform_delay
32#define platform_delay(ms) HAL_Delay(ms)
33#endif
34
35// SPI timeout duration in milliseconds
36#define LIS2MDL_SPI_TIMEOUT 100
37
66int32_t __weak lis2mdl_read_reg(const stmdev_ctx_t *ctx, uint8_t reg,
67 uint8_t *data,
68 uint16_t len)
69{
70 int32_t ret;
71
72 if (ctx == NULL)
73 {
74 return -1;
75 }
76
77 ret = ctx->read_reg(ctx->handle, reg, data, len);
78
79 return ret;
80}
81
92int32_t __weak lis2mdl_write_reg(const stmdev_ctx_t *ctx, uint8_t reg,
93 uint8_t *data,
94 uint16_t len)
95{
96 int32_t ret;
97
98 if (ctx == NULL)
99 {
100 return -1;
101 }
102
103 ret = ctx->write_reg(ctx->handle, reg, data, len);
104
105 return ret;
106}
107
119float_t lis2mdl_from_lsb_to_mgauss(int16_t lsb)
120{
121 return ((float_t)lsb * 1.5f);
122}
123
124float_t lis2mdl_from_lsb_to_celsius(int16_t lsb)
125{
126 return (((float_t)lsb / 8.0f) + 25.0f);
127}
128
138{
139 return ((float_t)lsb * 150.0f);
140}
141
167int32_t lis2mdl_mag_user_offset_set(const stmdev_ctx_t *ctx, int16_t *val)
168{
169 uint8_t buff[6];
170 int32_t ret;
171
172 buff[1] = (uint8_t)((uint16_t)val[0] / 256U);
173 buff[0] = (uint8_t)((uint16_t)val[0] - (buff[1] * 256U));
174 buff[3] = (uint8_t)((uint16_t)val[1] / 256U);
175 buff[2] = (uint8_t)((uint16_t)val[1] - (buff[3] * 256U));
176 buff[5] = (uint8_t)((uint16_t)val[2] / 256U);
177 buff[4] = (uint8_t)((uint16_t)val[2] - (buff[5] * 256U));
178 ret = lis2mdl_write_reg(ctx, LIS2MDL_OFFSET_X_REG_L, buff, 6);
179
180 return ret;
181}
182
195int32_t lis2mdl_mag_user_offset_get(const stmdev_ctx_t *ctx, int16_t *val)
196{
197 uint8_t buff[6];
198 int32_t ret;
199
200 ret = lis2mdl_read_reg(ctx, LIS2MDL_OFFSET_X_REG_L, buff, 6);
201 val[0] = (int16_t)buff[1];
202 val[0] = (val[0] * 256) + (int16_t)buff[0];
203 val[1] = (int16_t)buff[3];
204 val[1] = (val[1] * 256) + (int16_t)buff[2];
205 val[2] = (int16_t)buff[5];
206 val[2] = (val[2] * 256) + (int16_t)buff[4];
207
208 return ret;
209}
210
220 lis2mdl_md_t val)
221{
223 int32_t ret;
224
225 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
226
227 if (ret == 0)
228 {
229 reg.md = (uint8_t)val;
230 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
231 }
232
233 return ret;
234}
235
245 lis2mdl_md_t *val)
246{
248 int32_t ret;
249
250 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
251
252 switch (reg.md)
253 {
255 *val = LIS2MDL_POWER_DOWN;
256 break;
257
260 break;
261
264 break;
265
266 default:
267 *val = LIS2MDL_POWER_DOWN;
268 break;
269 }
270
271 return ret;
272}
273
283{
285 int32_t ret;
286
287 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
288
289 if (ret == 0)
290 {
291 reg.odr = (uint8_t)val;
292 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
293 }
294
295 return ret;
296}
297
307{
309 int32_t ret;
310
311 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
312
313 switch (reg.odr)
314 {
315 case LIS2MDL_ODR_10Hz:
316 *val = LIS2MDL_ODR_10Hz;
317 break;
318
319 case LIS2MDL_ODR_20Hz:
320 *val = LIS2MDL_ODR_20Hz;
321 break;
322
323 case LIS2MDL_ODR_50Hz:
324 *val = LIS2MDL_ODR_50Hz;
325 break;
326
328 *val = LIS2MDL_ODR_100Hz;
329 break;
330
331 default:
332 *val = LIS2MDL_ODR_10Hz;
333 break;
334 }
335
336 return ret;
337}
338
348{
350 int32_t ret;
351
352 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
353
354 if (ret == 0)
355 {
356 reg.lp = (uint8_t)val;
357 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
358 }
359
360 return ret;
361}
362
372{
374 int32_t ret;
375
376 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
377
378 switch (reg.lp)
379 {
382 break;
383
385 *val = LIS2MDL_LOW_POWER;
386 break;
387
388 default:
390 break;
391 }
392
393 return ret;
394}
395
404int32_t lis2mdl_offset_temp_comp_set(const stmdev_ctx_t *ctx, uint8_t val)
405{
407 int32_t ret;
408
409 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
410
411 if (ret == 0)
412 {
413 reg.comp_temp_en = val;
414 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
415 }
416
417 return ret;
418}
419
428int32_t lis2mdl_offset_temp_comp_get(const stmdev_ctx_t *ctx, uint8_t *val)
429{
431 int32_t ret;
432
433 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
434 *val = reg.comp_temp_en;
435
436 return ret;
437}
438
448 lis2mdl_lpf_t val)
449{
451 int32_t ret;
452
453 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
454
455 if (ret == 0)
456 {
457 reg.lpf = (uint8_t)val;
458 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
459 }
460
461 return ret;
462}
463
473 lis2mdl_lpf_t *val)
474{
476 int32_t ret;
477
478 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
479
480 switch (reg.lpf)
481 {
483 *val = LIS2MDL_ODR_DIV_2;
484 break;
485
487 *val = LIS2MDL_ODR_DIV_4;
488 break;
489
490 default:
491 *val = LIS2MDL_ODR_DIV_2;
492 break;
493 }
494
495 return ret;
496}
497
508{
510 int32_t ret;
511
512 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
513
514 if (ret == 0)
515 {
516 reg.set_rst = (uint8_t)val;
517 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
518 }
519
520 return ret;
521}
522
533{
535 int32_t ret;
536
537 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
538
539 switch (reg.set_rst)
540 {
543 break;
544
547 break;
548
551 break;
552
553 default:
555 break;
556 }
557
558 return ret;
559}
560
574 uint8_t val)
575{
577 int32_t ret;
578
579 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
580
581 if (ret == 0)
582 {
583 reg.off_canc_one_shot = val;
584 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
585 }
586
587 return ret;
588}
589
603 uint8_t *val)
604{
606 int32_t ret;
607
608 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
609 *val = reg.off_canc_one_shot;
610
611 return ret;
612}
613
622int32_t lis2mdl_block_data_update_set(const stmdev_ctx_t *ctx, uint8_t val)
623{
625 int32_t ret;
626
627 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
628
629 if (ret == 0)
630 {
631 reg.bdu = val;
632 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
633 }
634
635 return ret;
636}
637
646int32_t lis2mdl_block_data_update_get(const stmdev_ctx_t *ctx, uint8_t *val)
647{
649 int32_t ret;
650
651 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
652 *val = reg.bdu;
653
654 return ret;
655}
656
665int32_t lis2mdl_mag_data_ready_get(const stmdev_ctx_t *ctx, uint8_t *val)
666{
668 int32_t ret;
669
670 ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t *)&reg, 1);
671 *val = reg.zyxda;
672
673 return ret;
674}
675
684int32_t lis2mdl_mag_data_ovr_get(const stmdev_ctx_t *ctx, uint8_t *val)
685{
687 int32_t ret;
688
689 ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t *)&reg, 1);
690 *val = reg.zyxor;
691
692 return ret;
693}
694
703int32_t lis2mdl_magnetic_raw_get(const stmdev_ctx_t *ctx, int16_t *val)
704{
705 uint8_t buff[6];
706 int32_t ret;
707
708 ret = lis2mdl_read_reg(ctx, LIS2MDL_OUTX_L_REG, buff, 6);
709 val[0] = (int16_t)buff[1];
710 val[0] = (val[0] * 256) + (int16_t)buff[0];
711 val[1] = (int16_t)buff[3];
712 val[1] = (val[1] * 256) + (int16_t)buff[2];
713 val[2] = (int16_t)buff[5];
714 val[2] = (val[2] * 256) + (int16_t)buff[4];
715
716 return ret;
717}
718
727int32_t lis2mdl_temperature_raw_get(const stmdev_ctx_t *ctx, int16_t *val)
728{
729 uint8_t buff[2];
730 int32_t ret;
731
732 ret = lis2mdl_read_reg(ctx, LIS2MDL_TEMP_OUT_L_REG, buff, 2);
733 *val = (int16_t)buff[1];
734 *val = (*val * 256) + (int16_t)buff[0];
735
736 return ret;
737}
738
759int32_t lis2mdl_device_id_get(const stmdev_ctx_t *ctx, uint8_t *buff)
760{
761 int32_t ret;
762
763 ret = lis2mdl_read_reg(ctx, LIS2MDL_WHO_AM_I, buff, 1);
764
765 return ret;
766}
767
776int32_t lis2mdl_reset_set(const stmdev_ctx_t *ctx, uint8_t val)
777{
779 int32_t ret;
780
781 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
782
783 if (ret == 0)
784 {
785 reg.soft_rst = val;
786 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
787 }
788
789 return ret;
790}
791
800int32_t lis2mdl_reset_get(const stmdev_ctx_t *ctx, uint8_t *val)
801{
803 int32_t ret;
804
805 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
806 *val = reg.soft_rst;
807
808 return ret;
809}
810
819int32_t lis2mdl_boot_set(const stmdev_ctx_t *ctx, uint8_t val)
820{
822 int32_t ret;
823
824 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
825
826 if (ret == 0)
827 {
828 reg.reboot = val;
829 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
830 }
831
832 return ret;
833}
834
843int32_t lis2mdl_boot_get(const stmdev_ctx_t *ctx, uint8_t *val)
844{
846 int32_t ret;
847
848 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
849 *val = reg.reboot;
850
851 return ret;
852}
853
862int32_t lis2mdl_self_test_set(const stmdev_ctx_t *ctx, uint8_t val)
863{
865 int32_t ret;
866
867 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
868
869 if (ret == 0)
870 {
871 reg.self_test = val;
872 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
873 }
874
875 return ret;
876}
877
886int32_t lis2mdl_self_test_get(const stmdev_ctx_t *ctx, uint8_t *val)
887{
889 int32_t ret;
890
891 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
892 *val = reg.self_test;
893
894 return ret;
895}
896
906{
908 int32_t ret;
909
910 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
911
912 if (ret == 0)
913 {
914 reg.ble = (uint8_t)val;
915 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
916 }
917
918 return ret;
919}
920
930{
932 int32_t ret;
933
934 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
935
936 switch (reg.ble)
937 {
940 break;
941
944 break;
945
946 default:
948 break;
949 }
950
951 return ret;
952}
953
964{
965 int32_t ret;
966
967 ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t *) val, 1);
968
969 return ret;
970}
971
995{
997 int32_t ret;
998
999 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
1000
1001 if (ret == 0)
1002 {
1003 reg.int_on_dataoff = (uint8_t)val;
1004 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
1005 }
1006
1007 return ret;
1008}
1009
1021{
1023 int32_t ret;
1024
1025 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
1026
1027 switch (reg.int_on_dataoff)
1028 {
1030 *val = LIS2MDL_CHECK_BEFORE;
1031 break;
1032
1034 *val = LIS2MDL_CHECK_AFTER;
1035 break;
1036
1037 default:
1038 *val = LIS2MDL_CHECK_BEFORE;
1039 break;
1040 }
1041
1042 return ret;
1043}
1044
1053int32_t lis2mdl_drdy_on_pin_set(const stmdev_ctx_t *ctx, uint8_t val)
1054{
1056 int32_t ret;
1057
1058 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1059
1060 if (ret == 0)
1061 {
1062 reg.drdy_on_pin = val;
1063 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1064 }
1065
1066 return ret;
1067}
1068
1077int32_t lis2mdl_drdy_on_pin_get(const stmdev_ctx_t *ctx, uint8_t *val)
1078{
1080 int32_t ret;
1081
1082 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1083 *val = reg.drdy_on_pin;
1084
1085 return ret;
1086}
1087
1096int32_t lis2mdl_int_on_pin_set(const stmdev_ctx_t *ctx, uint8_t val)
1097{
1099 int32_t ret;
1100
1101 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1102
1103 if (ret == 0)
1104 {
1105 reg.int_on_pin = val;
1106 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1107 }
1108
1109 return ret;
1110}
1111
1120int32_t lis2mdl_int_on_pin_get(const stmdev_ctx_t *ctx, uint8_t *val)
1121{
1123 int32_t ret;
1124
1125 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1126 *val = reg.int_on_pin;
1127
1128 return ret;
1129}
1130
1141{
1142 int32_t ret;
1143
1144 ret = lis2mdl_write_reg(ctx, LIS2MDL_INT_CRTL_REG, (uint8_t *) val, 1);
1145
1146 return ret;
1147}
1148
1159{
1160 int32_t ret;
1161
1162 ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_CRTL_REG, (uint8_t *) val, 1);
1163
1164 return ret;
1165}
1166
1177{
1178 int32_t ret;
1179
1180 ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_SOURCE_REG, (uint8_t *) val, 1);
1181
1182 return ret;
1183}
1184
1195int32_t lis2mdl_int_gen_threshold_set(const stmdev_ctx_t *ctx, uint16_t val)
1196{
1197 uint8_t buff[2];
1198 int32_t ret;
1199
1200 buff[1] = (uint8_t)(val / 256U);
1201 buff[0] = (uint8_t)(val - (buff[1] * 256U));
1202 ret = lis2mdl_write_reg(ctx, LIS2MDL_INT_THS_L_REG, buff, 2);
1203
1204 return ret;
1205}
1206
1217int32_t lis2mdl_int_gen_threshold_get(const stmdev_ctx_t *ctx, uint16_t *val)
1218{
1219 uint8_t buff[2];
1220 int32_t ret;
1221
1222 ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_THS_L_REG, buff, 2);
1223 *val = buff[1];
1224 *val = (*val * 256U) + buff[0];
1225
1226 return ret;
1227}
1228
1251{
1253 int32_t ret;
1254
1255 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1256
1257 if (ret == 0)
1258 {
1259 reg._4wspi = (uint8_t)val;
1260 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1261 }
1262
1263 return ret;
1264}
1265
1275{
1277 int32_t ret;
1278
1279 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1280
1281 switch (reg._4wspi)
1282 {
1283 case LIS2MDL_SPI_4_WIRE:
1284 *val = LIS2MDL_SPI_4_WIRE;
1285 break;
1286
1287 case LIS2MDL_SPI_3_WIRE:
1288 *val = LIS2MDL_SPI_3_WIRE;
1289 break;
1290
1291 default:
1292 *val = LIS2MDL_SPI_3_WIRE;
1293 break;
1294 }
1295
1296 return ret;
1297}
1298
1309{
1311 int32_t ret;
1312
1313 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1314
1315 if (ret == 0)
1316 {
1317 reg.i2c_dis = (uint8_t)val;
1318 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1319 }
1320
1321 return ret;
1322}
1323
1333 lis2mdl_i2c_dis_t *val)
1334{
1336 int32_t ret;
1337
1338 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1339
1340 switch (reg.i2c_dis)
1341 {
1342 case LIS2MDL_I2C_ENABLE:
1343 *val = LIS2MDL_I2C_ENABLE;
1344 break;
1345
1347 *val = LIS2MDL_I2C_DISABLE;
1348 break;
1349
1350 default:
1351 *val = LIS2MDL_I2C_ENABLE;
1352 break;
1353 }
1354
1355 return ret;
1356}
1357
1372static int32_t platform_spi_write(void *handle, uint8_t reg, const uint8_t *bufp, uint16_t len)
1373{
1374 SPI_HandleTypeDef *spi_handle = (SPI_HandleTypeDef *)handle;
1375 uint8_t cmd_byte;
1376
1377 if (spi_handle == NULL || bufp == NULL) {
1378 return -1; // Invalid arguments
1379 }
1380
1381 // LIS2MDL SPI write command: MSB=0 for write, followed by 7-bit register address
1382 cmd_byte = reg & 0x7F; // Ensure MSB is 0 for write
1383
1384 BMP390_CS_HIGH;
1385 IMU_CS_HIGH;
1386 // Pull CS pin low to select the device
1387 HAL_GPIO_WritePin(LIS2MDL_CS_GPIO_Port, LIS2MDL_CS_Pin, GPIO_PIN_RESET);
1388
1389
1390 // Transmit the command byte (register address with write flag)
1391 if (HAL_SPI_Transmit(spi_handle, &cmd_byte, 1, LIS2MDL_SPI_TIMEOUT) != HAL_OK)
1392 {
1393 HAL_GPIO_WritePin(LIS2MDL_CS_GPIO_Port, LIS2MDL_CS_Pin, GPIO_PIN_SET); // Release CS
1394 return -1; // SPI transmission error
1395 }
1396
1397 // Transmit the data
1398 if (HAL_SPI_Transmit(spi_handle, (uint8_t*)bufp, len, LIS2MDL_SPI_TIMEOUT) != HAL_OK)
1399 {
1400 HAL_GPIO_WritePin(LIS2MDL_CS_GPIO_Port, LIS2MDL_CS_Pin, GPIO_PIN_SET); // Release CS
1401 return -1; // SPI transmission error
1402 }
1403
1404 // Pull CS pin high to deselect the device
1405 HAL_GPIO_WritePin(LIS2MDL_CS_GPIO_Port, LIS2MDL_CS_Pin, GPIO_PIN_SET);
1406
1407 return 0; // Success
1408}
1409
1418static int32_t platform_spi_read(void *handle, uint8_t reg, uint8_t *bufp, uint16_t len)
1419{
1420 SPI_HandleTypeDef *spi_handle = (SPI_HandleTypeDef *)handle;
1421 uint8_t cmd_byte;
1422
1423 if (spi_handle == NULL || bufp == NULL) {
1424 return -1; // Invalid arguments
1425 }
1426
1427 // LIS2MDL SPI read command: MSB=1 for read, followed by 7-bit register address
1428 cmd_byte = (reg & 0x7F) | 0x80; // Set MSB to 1 for read
1429
1430
1431 if(HAL_GPIO_ReadPin(IMU_CS_GPIO_Port,IMU_CS_Pin)!=GPIO_PIN_SET){IMU_CS_HIGH;}
1432 if(HAL_GPIO_ReadPin(BARO_CS_GPIO_Port,BARO_CS_Pin)!=GPIO_PIN_SET){BMP390_CS_HIGH;}
1433 // Pull CS pin low to select the device
1434 HAL_GPIO_WritePin(LIS2MDL_CS_GPIO_Port, LIS2MDL_CS_Pin, GPIO_PIN_RESET);
1435
1436 // Transmit the command byte (register address with read flag)
1437 if (HAL_SPI_Transmit(spi_handle, &cmd_byte, 1, LIS2MDL_SPI_TIMEOUT) != HAL_OK)
1438 {
1439 HAL_GPIO_WritePin(LIS2MDL_CS_GPIO_Port, LIS2MDL_CS_Pin, GPIO_PIN_SET); // Release CS
1440 return -1; // SPI transmission error
1441 }
1442
1443 // Receive the data
1444 if (HAL_SPI_Receive(spi_handle, bufp, len, LIS2MDL_SPI_TIMEOUT) != HAL_OK)
1445 {
1446 HAL_GPIO_WritePin(LIS2MDL_CS_GPIO_Port, LIS2MDL_CS_Pin, GPIO_PIN_SET); // Release CS
1447 return -1; // SPI reception error
1448 }
1449
1450 // Pull CS pin high to deselect the device
1451 HAL_GPIO_WritePin(LIS2MDL_CS_GPIO_Port, LIS2MDL_CS_Pin, GPIO_PIN_SET);
1452
1453 return 0; // Success
1454}
1455
1462{
1463 uint8_t who_am_i = 0;
1464 uint8_t val = 0; // Temporary variable for get functions
1465 lis2mdl_cfg_reg_a_t cfg_a;
1466 lis2mdl_cfg_reg_c_t cfg_c;
1467
1468
1469 if (ctx == NULL) return -1;
1470
1471
1474 ctx->handle = &hspi2; // Your SPI_HandleTypeDef
1475
1476 // Check WHO_AM_I register
1477 if (lis2mdl_device_id_get(ctx, &who_am_i) != 0) return -1; // Error reading WHO_AM_I
1478 if (who_am_i != LIS2MDL_ID){
1479 return -1;
1480 } // WHO_AM_I mismatch (LIS2MDL_ID should be 0x40 as per datasheet)
1481
1482 // Perform a software reset
1483 if (lis2mdl_reset_set(ctx, 1) != 0) return -1;
1484 platform_delay(5); // Wait for reset to complete (datasheet doesn't specify, 5ms is a guess)
1485 do {
1486 if (lis2mdl_reset_get(ctx, &val) != 0) return -1;
1487 } while (val); // Poll SOFT_RST bit until it is cleared
1488
1489
1490 // Reboot memory content to reload calibration parameters
1491 if (lis2mdl_boot_set(ctx, 1) != 0) return -1;
1492 platform_delay(5); // Wait for boot to complete
1493 do {
1494 if (lis2mdl_boot_get(ctx, &val) != 0) return -1;
1495 } while (val); // Poll REBOOT bit until it is cleared
1496
1497 // Configure for 4-wire SPI mode
1498 // Note: The LIS2MDL CS pin (pin 3) must be tied LOW to enable SPI mode.
1499 // This function configures the 4WSPI bit in CFG_REG_C for the SDO line.
1500 if (lis2mdl_spi_mode_set(ctx, LIS2MDL_SPI_4_WIRE) != 0) return -1;
1501
1502
1503 // Configure CFG_REG_A for:
1504 // - Temperature compensation enabled
1505 // - Continuous mode
1506 // - ODR 10 Hz
1507 // - High-resolution mode
1508 // This matches the datasheet startup example (CFG_REG_A = 0x80)
1509
1510 // Method 1: Using individual set functions (less efficient due to multiple R-M-W)
1511 // if (lis2mdl_offset_temp_comp_set(ctx, 1) != 0) return -1;
1512 // if (lis2mdl_operating_mode_set(ctx, LIS2MDL_CONTINUOUS_MODE) != 0) return -1;
1513 // if (lis2mdl_data_rate_set(ctx, LIS2MDL_ODR_10HZ) != 0) return -1; // Assuming LIS2MDL_ODR_10HZ is defined
1514 // if (lis2mdl_power_mode_set(ctx, LIS2MDL_HIGH_RESOLUTION) != 0) return -1;
1515
1516 // Method 2: Direct write to CFG_REG_A (more efficient)
1517 cfg_a.comp_temp_en = 1;
1518 cfg_a.reboot = 0;
1519 cfg_a.soft_rst = 0;
1520 cfg_a.lp = (uint8_t)LIS2MDL_HIGH_RESOLUTION; // Assuming LIS2MDL_HIGH_RESOLUTION = 0
1521 cfg_a.odr = (uint8_t)LIS2MDL_ODR_10Hz; // Assuming LIS2MDL_ODR_10Hz = 0
1522 cfg_a.md = (uint8_t)LIS2MDL_CONTINUOUS_MODE; // Assuming LIS2MDL_CONTINUOUS_MODE = 0
1523 if (lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&cfg_a, 1) != 0) return -1;
1524
1525
1526 // Configure CFG_REG_C for:
1527 // - Block Data Update (BDU) enabled
1528 // - Data Ready signal on INT/DRDY pin enabled (optional, as per datasheet startup example)
1529 // - 4-wire SPI is already set by lis2mdl_spi_mode_set above.
1530
1531 // Method 1: Using individual set functions
1532 // if (lis2mdl_block_data_update_set(ctx, 1) != 0) return -1;
1533 // if (lis2mdl_drdy_on_pin_set(ctx, 1) != 0) return -1; // Optional: enable DRDY on pin
1534
1535 // Method 2: Direct write to CFG_REG_C (more efficient, considers 4WSPI already set)
1536 if (lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&cfg_c, 1) != 0) return -1;
1537 cfg_c.bdu = 1;
1538 cfg_c.drdy_on_pin = 1; // Enable DRDY on pin as per datasheet example
1539 // cfg_c._4wspi is already set by lis2mdl_spi_mode_set, no need to change it here
1540 // unless lis2mdl_spi_mode_set is not called before this.
1541 // For safety, ensure it's set if not using the dedicated function earlier:
1542 // cfg_c._4wspi = 1; // If LIS2MDL_SPI_4_WIRE is desired
1543 cfg_c.i2c_dis = 1; // Disable I2C if exclusively using SPI
1544 cfg_c.int_on_pin = 0; // Disable interrupt on pin unless specifically needed
1545 cfg_c.self_test = 0; // Disable self-test
1546 cfg_c.ble = (uint8_t)LIS2MDL_LSB_AT_LOW_ADD; // Default data format
1547
1548 if (lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&cfg_c, 1) != 0) return -1;
1549
1550
1551 // Sensor is now initialized with basic settings.
1552 // Further configuration (e.g., interrupts, thresholds) can be done as needed.
1553 return 0; // Success
1554}
1555
1557{
1558 uint8_t who_am_i = 0;
1559 uint8_t val = 0; // Temporary variable for get functions
1560 lis2mdl_cfg_reg_a_t cfg_a;
1561 lis2mdl_cfg_reg_c_t cfg_c;
1562
1563
1564 if (ctx == NULL) return -1;
1565
1566
1569 ctx->handle = &hspi3; // Your SPI_HandleTypeDef
1570
1571 // Check WHO_AM_I register
1572 if (lis2mdl_device_id_get(ctx, &who_am_i) != 0) return -1; // Error reading WHO_AM_I
1573 if (who_am_i != LIS2MDL_ID) return -1; // WHO_AM_I mismatch (LIS2MDL_ID should be 0x40 as per datasheet)
1574
1575 // Perform a software reset
1576 if (lis2mdl_reset_set(ctx, 1) != 0) return -1;
1577 platform_delay(5); // Wait for reset to complete (datasheet doesn't specify, 5ms is a guess)
1578 do {
1579 if (lis2mdl_reset_get(ctx, &val) != 0) return -1;
1580 } while (val); // Poll SOFT_RST bit until it is cleared
1581
1582
1583 // Reboot memory content to reload calibration parameters
1584 if (lis2mdl_boot_set(ctx, 1) != 0) return -1;
1585 platform_delay(5); // Wait for boot to complete
1586 do {
1587 if (lis2mdl_boot_get(ctx, &val) != 0) return -1;
1588 } while (val); // Poll REBOOT bit until it is cleared
1589
1590 // Configure for 4-wire SPI mode
1591 // Note: The LIS2MDL CS pin (pin 3) must be tied LOW to enable SPI mode.
1592 // This function configures the 4WSPI bit in CFG_REG_C for the SDO line.
1593 if (lis2mdl_spi_mode_set(ctx, LIS2MDL_SPI_4_WIRE) != 0) return -1;
1594
1595
1596 // Configure CFG_REG_A for:
1597 // - Temperature compensation enabled
1598 // - Continuous mode
1599 // - ODR 10 Hz
1600 // - High-resolution mode
1601 // This matches the datasheet startup example (CFG_REG_A = 0x80)
1602
1603 // Method 1: Using individual set functions (less efficient due to multiple R-M-W)
1604 // if (lis2mdl_offset_temp_comp_set(ctx, 1) != 0) return -1;
1605 // if (lis2mdl_operating_mode_set(ctx, LIS2MDL_CONTINUOUS_MODE) != 0) return -1;
1606 // if (lis2mdl_data_rate_set(ctx, LIS2MDL_ODR_10HZ) != 0) return -1; // Assuming LIS2MDL_ODR_10HZ is defined
1607 // if (lis2mdl_power_mode_set(ctx, LIS2MDL_HIGH_RESOLUTION) != 0) return -1;
1608
1609 // Method 2: Direct write to CFG_REG_A (more efficient)
1610 cfg_a.comp_temp_en = 1;
1611 cfg_a.reboot = 0;
1612 cfg_a.soft_rst = 0;
1613 cfg_a.lp = (uint8_t)LIS2MDL_HIGH_RESOLUTION; // Assuming LIS2MDL_HIGH_RESOLUTION = 0
1614 cfg_a.odr = (uint8_t)LIS2MDL_ODR_10Hz; // Assuming LIS2MDL_ODR_10Hz = 0
1615 cfg_a.md = (uint8_t)LIS2MDL_CONTINUOUS_MODE; // Assuming LIS2MDL_CONTINUOUS_MODE = 0
1616 if (lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&cfg_a, 1) != 0) return -1;
1617
1618
1619 // Configure CFG_REG_C for:
1620 // - Block Data Update (BDU) enabled
1621 // - Data Ready signal on INT/DRDY pin enabled (optional, as per datasheet startup example)
1622 // - 4-wire SPI is already set by lis2mdl_spi_mode_set above.
1623
1624 // Method 1: Using individual set functions
1625 // if (lis2mdl_block_data_update_set(ctx, 1) != 0) return -1;
1626 // if (lis2mdl_drdy_on_pin_set(ctx, 1) != 0) return -1; // Optional: enable DRDY on pin
1627
1628 // Method 2: Direct write to CFG_REG_C (more efficient, considers 4WSPI already set)
1629 if (lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&cfg_c, 1) != 0) return -1;
1630 cfg_c.bdu = 1;
1631 cfg_c.drdy_on_pin = 1; // Enable DRDY on pin as per datasheet example
1632 // cfg_c._4wspi is already set by lis2mdl_spi_mode_set, no need to change it here
1633 // unless lis2mdl_spi_mode_set is not called before this.
1634 // For safety, ensure it's set if not using the dedicated function earlier:
1635 // cfg_c._4wspi = 1; // If LIS2MDL_SPI_4_WIRE is desired
1636 cfg_c.i2c_dis = 1; // Disable I2C if exclusively using SPI
1637 cfg_c.int_on_pin = 0; // Disable interrupt on pin unless specifically needed
1638 cfg_c.self_test = 0; // Disable self-test
1639 cfg_c.ble = (uint8_t)LIS2MDL_LSB_AT_LOW_ADD; // Default data format
1640
1641 if (lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&cfg_c, 1) != 0) return -1;
1642
1643
1644 // Sensor is now initialized with basic settings.
1645 // Further configuration (e.g., interrupts, thresholds) can be done as needed.
1646 return 0; // Success
1647}
1657/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#define NULL
Definition bmp3_defs.h:88
SPI_HandleTypeDef hspi2
HAL SPI handle for Sensor Bus 1 (e.g., IMU, Baro).
Definition main.c:62
SPI_HandleTypeDef hspi3
HAL SPI handle for Sensor Bus 2 (e.g., secondary sensors).
Definition main.c:63
int32_t __weak lis2mdl_write_reg(const stmdev_ctx_t *ctx, uint8_t reg, uint8_t *data, uint16_t len)
Write generic device register.
Definition lis2mdl_reg.c:92
int32_t __weak lis2mdl_read_reg(const stmdev_ctx_t *ctx, uint8_t reg, uint8_t *data, uint16_t len)
Read generic device register.
Definition lis2mdl_reg.c:66
int32_t lis2mdl_init_2(stmdev_ctx_t *ctx)
static int32_t platform_spi_write(void *handle, uint8_t reg, const uint8_t *bufp, uint16_t len)
Write data to LIS2MDL sensor via SPI.
static int32_t platform_spi_read(void *handle, uint8_t reg, uint8_t *bufp, uint16_t len)
Read data from LIS2MDL sensor via SPI.
int32_t lis2mdl_init(stmdev_ctx_t *ctx)
Initialize the LIS2MDL sensor.
float_t lis2mdl_from_lsb_to_nanotesla(int16_t lsb)
Converts raw magnetic data to nanotesla (nT). Sensitivity: 1 LSB = 1.5 mG = 150 nT.
float_t lis2mdl_from_lsb_to_celsius(int16_t lsb)
float_t lis2mdl_from_lsb_to_mgauss(int16_t lsb)
int32_t lis2mdl_self_test_set(const stmdev_ctx_t *ctx, uint8_t val)
Selftest.[set].
int32_t lis2mdl_data_format_set(const stmdev_ctx_t *ctx, lis2mdl_ble_t val)
Big/Little Endian data selection.[set].
int32_t lis2mdl_status_get(const stmdev_ctx_t *ctx, lis2mdl_status_reg_t *val)
Info about device status.[get].
int32_t lis2mdl_self_test_get(const stmdev_ctx_t *ctx, uint8_t *val)
Selftest.[get].
int32_t lis2mdl_data_format_get(const stmdev_ctx_t *ctx, lis2mdl_ble_t *val)
Big/Little Endian data selection.[get].
int32_t lis2mdl_boot_get(const stmdev_ctx_t *ctx, uint8_t *val)
Reboot memory content. Reload the calibration parameters.[get].
int32_t lis2mdl_reset_get(const stmdev_ctx_t *ctx, uint8_t *val)
Software reset. Restore the default values in user registers.[get].
int32_t lis2mdl_reset_set(const stmdev_ctx_t *ctx, uint8_t val)
Software reset. Restore the default values in user registers.[set].
int32_t lis2mdl_device_id_get(const stmdev_ctx_t *ctx, uint8_t *buff)
DeviceWhoamI.[get].
int32_t lis2mdl_boot_set(const stmdev_ctx_t *ctx, uint8_t val)
Reboot memory content. Reload the calibration parameters.[set].
int32_t lis2mdl_offset_temp_comp_get(const stmdev_ctx_t *ctx, uint8_t *val)
Enables the magnetometer temperature compensation.[get].
int32_t lis2mdl_mag_user_offset_get(const stmdev_ctx_t *ctx, int16_t *val)
These registers comprise a 3 group of 16-bit number and represent hard-iron offset in order to compen...
int32_t lis2mdl_set_rst_mode_set(const stmdev_ctx_t *ctx, lis2mdl_set_rst_t val)
Reset mode.[set].
int32_t lis2mdl_low_pass_bandwidth_set(const stmdev_ctx_t *ctx, lis2mdl_lpf_t val)
Low-pass bandwidth selection.[set].
int32_t lis2mdl_set_rst_sensor_single_get(const stmdev_ctx_t *ctx, uint8_t *val)
Enables offset cancellation in single measurement mode. The OFF_CANC bit must be set to 1 when enabli...
int32_t lis2mdl_block_data_update_get(const stmdev_ctx_t *ctx, uint8_t *val)
Blockdataupdate.[get].
int32_t lis2mdl_operating_mode_set(const stmdev_ctx_t *ctx, lis2mdl_md_t val)
Operating mode selection.[set].
int32_t lis2mdl_offset_temp_comp_set(const stmdev_ctx_t *ctx, uint8_t val)
Enables the magnetometer temperature compensation.[set].
int32_t lis2mdl_data_rate_set(const stmdev_ctx_t *ctx, lis2mdl_odr_t val)
Output data rate selection.[set].
int32_t lis2mdl_low_pass_bandwidth_get(const stmdev_ctx_t *ctx, lis2mdl_lpf_t *val)
Low-pass bandwidth selection.[get].
int32_t lis2mdl_set_rst_mode_get(const stmdev_ctx_t *ctx, lis2mdl_set_rst_t *val)
Reset mode.[get].
int32_t lis2mdl_block_data_update_set(const stmdev_ctx_t *ctx, uint8_t val)
Blockdataupdate.[set].
int32_t lis2mdl_mag_data_ready_get(const stmdev_ctx_t *ctx, uint8_t *val)
Magnetic set of data available.[get].
int32_t lis2mdl_power_mode_set(const stmdev_ctx_t *ctx, lis2mdl_lp_t val)
Enables high-resolution/low-power mode.[set].
int32_t lis2mdl_magnetic_raw_get(const stmdev_ctx_t *ctx, int16_t *val)
Magnetic output value.[get].
int32_t lis2mdl_power_mode_get(const stmdev_ctx_t *ctx, lis2mdl_lp_t *val)
Enables high-resolution/low-power mode.[get].
int32_t lis2mdl_mag_data_ovr_get(const stmdev_ctx_t *ctx, uint8_t *val)
Magnetic set of data overrun.[get].
int32_t lis2mdl_set_rst_sensor_single_set(const stmdev_ctx_t *ctx, uint8_t val)
Enables offset cancellation in single measurement mode. The OFF_CANC bit must be set to 1 when enabli...
int32_t lis2mdl_operating_mode_get(const stmdev_ctx_t *ctx, lis2mdl_md_t *val)
Operating mode selection.[get].
int32_t lis2mdl_mag_user_offset_set(const stmdev_ctx_t *ctx, int16_t *val)
These registers comprise a 3 group of 16-bit number and represent hard-iron offset in order to compen...
int32_t lis2mdl_temperature_raw_get(const stmdev_ctx_t *ctx, int16_t *val)
Temperature output value.[get].
int32_t lis2mdl_data_rate_get(const stmdev_ctx_t *ctx, lis2mdl_odr_t *val)
Output data rate selection.[get].
int32_t lis2mdl_int_gen_threshold_set(const stmdev_ctx_t *ctx, uint16_t val)
User-defined threshold value for xl interrupt event on generator. Data format is the same of output d...
int32_t lis2mdl_int_on_pin_set(const stmdev_ctx_t *ctx, uint8_t val)
Interrupt signal on INT_DRDY pin.[set].
int32_t lis2mdl_int_gen_threshold_get(const stmdev_ctx_t *ctx, uint16_t *val)
User-defined threshold value for xl interrupt event on generator. Data format is the same of output d...
int32_t lis2mdl_drdy_on_pin_get(const stmdev_ctx_t *ctx, uint8_t *val)
Data-ready signal on INT_DRDY pin.[get].
int32_t lis2mdl_int_gen_conf_set(const stmdev_ctx_t *ctx, lis2mdl_int_crtl_reg_t *val)
Interrupt generator configuration register.[set].
int32_t lis2mdl_int_on_pin_get(const stmdev_ctx_t *ctx, uint8_t *val)
Interrupt signal on INT_DRDY pin.[get].
int32_t lis2mdl_int_gen_conf_get(const stmdev_ctx_t *ctx, lis2mdl_int_crtl_reg_t *val)
Interrupt generator configuration register.[get].
int32_t lis2mdl_offset_int_conf_set(const stmdev_ctx_t *ctx, lis2mdl_int_on_dataoff_t val)
The interrupt block recognition checks data after/before the hard-iron correction to discover the int...
int32_t lis2mdl_drdy_on_pin_set(const stmdev_ctx_t *ctx, uint8_t val)
Data-ready signal on INT_DRDY pin.[set].
int32_t lis2mdl_offset_int_conf_get(const stmdev_ctx_t *ctx, lis2mdl_int_on_dataoff_t *val)
The interrupt block recognition checks data after/before the hard-iron correction to discover the int...
int32_t lis2mdl_int_gen_source_get(const stmdev_ctx_t *ctx, lis2mdl_int_source_reg_t *val)
Interrupt generator source register.[get].
int32_t lis2mdl_i2c_interface_set(const stmdev_ctx_t *ctx, lis2mdl_i2c_dis_t val)
Enable/Disable I2C interface.[set].
int32_t lis2mdl_i2c_interface_get(const stmdev_ctx_t *ctx, lis2mdl_i2c_dis_t *val)
Enable/Disable I2C interface.[get].
int32_t lis2mdl_spi_mode_set(const stmdev_ctx_t *ctx, lis2mdl_sim_t val)
SPI Serial Interface Mode selection.[set].
int32_t lis2mdl_spi_mode_get(const stmdev_ctx_t *ctx, lis2mdl_sim_t *val)
SPI Serial Interface Mode selection.[get].
#define LIS2MDL_STATUS_REG
lis2mdl_set_rst_t
#define LIS2MDL_INT_SOURCE_REG
#define __weak
lis2mdl_i2c_dis_t
lis2mdl_lpf_t
lis2mdl_odr_t
#define LIS2MDL_WHO_AM_I
lis2mdl_sim_t
#define LIS2MDL_INT_CRTL_REG
#define LIS2MDL_TEMP_OUT_L_REG
#define LIS2MDL_CFG_REG_C
lis2mdl_ble_t
lis2mdl_lp_t
#define LIS2MDL_CFG_REG_A
#define LIS2MDL_OUTX_L_REG
#define LIS2MDL_CFG_REG_B
#define LIS2MDL_OFFSET_X_REG_L
lis2mdl_int_on_dataoff_t
lis2mdl_md_t
#define LIS2MDL_INT_THS_L_REG
@ LIS2MDL_SET_SENS_ODR_DIV_63
@ LIS2MDL_SET_SENS_ONLY_AT_POWER_ON
@ LIS2MDL_SENS_OFF_CANC_EVERY_ODR
@ LIS2MDL_I2C_ENABLE
@ LIS2MDL_I2C_DISABLE
@ LIS2MDL_ODR_DIV_4
@ LIS2MDL_ODR_DIV_2
@ LIS2MDL_ODR_100Hz
@ LIS2MDL_ODR_50Hz
@ LIS2MDL_ODR_10Hz
@ LIS2MDL_ODR_20Hz
@ LIS2MDL_SPI_3_WIRE
@ LIS2MDL_SPI_4_WIRE
@ LIS2MDL_LSB_AT_LOW_ADD
@ LIS2MDL_MSB_AT_LOW_ADD
@ LIS2MDL_LOW_POWER
@ LIS2MDL_HIGH_RESOLUTION
@ LIS2MDL_CHECK_AFTER
@ LIS2MDL_CHECK_BEFORE
@ LIS2MDL_POWER_DOWN
@ LIS2MDL_CONTINUOUS_MODE
@ LIS2MDL_SINGLE_TRIGGER
#define LIS2MDL_ID
#define platform_delay(ms)
Definition lis2mdl_reg.c:32
#define LIS2MDL_CS_GPIO_Port
Definition lis2mdl_reg.c:24
#define LIS2MDL_CS_Pin
Definition lis2mdl_reg.c:27
#define LIS2MDL_SPI_TIMEOUT
Definition lis2mdl_reg.c:36
This file contains all the functions prototypes for the lis2mdl_reg.c driver.
: Header for main.c file. This file contains the common defines of the application.
stmdev_read_ptr read_reg
stmdev_write_ptr write_reg
@ HAL_OK