Master Thesis  V1.0
Research and Design of Sensor Node for NMSD Treatment
main.c File Reference

Code used in master thesis, MAIN FILE. More...

#include <adc.h>
#include "em_system.h"
#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_emu.h"
#include "em_gpio.h"
#include "em_usart.h"
#include "em_rtc.h"
#include "em_adc.h"
#include "rtcdriver.h"
#include "em_core.h"
#include "debug_dbprint.h"
#include "delay.h"
#include "ICM20948.h"
#include "interrupt.h"
#include "ble.h"
#include "uart.h"
#include "timer.h"
#include "datatypes.h"
#include "util.h"
#include "rtcdrv_config.h"
#include "pinout.h"
#include <stdint.h>
#include <stdbool.h>
#include "I2C.h"
#include "MadgwickAHRS.h"
#include "math.h"
#include "bsp.h"
#include "bsp_trace.h"
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define DIY   1
 

Functions

void CheckIMUidle (void)
 Function called by RTC timer every second. More...
 
void measure_send (void)
 Function called by interrupt from IMU @50 Hz. More...
 
int main (void)
 Main function. More...
 
void GPIO_EVEN_IRQHandler (void)
 GPIO Even IRQ for pushbuttons on even-numbered pins. More...
 
void GPIO_ODD_IRQHandler (void)
 GPIO Odd IRQ for pushbuttons on odd-numbered pins. More...
 

Variables

MeasurementData_t data
 
bool bleConnected = false
 
bool IMU_MEASURING = false
 
bool IDLE = false
 
bool _sleep = false
 
uint8_t idle_count = 0
 
uint8_t ble_sec_not_connected = 0
 
uint32_t interruptStatus [1]
 
RTCDRV_TimerID_t IMU_Idle_Timer
 
bool helft = false
 
uint8_t teller = 0
 
uint8_t teller_accuracy = 0
 
volatile float beta = 1.0f
 

Detailed Description

Code used in master thesis, MAIN FILE.

Development of sensor node to use for threating NMSA

Version
1.0
Author
Jona Cappelle

Versions

Please check https://github.com/jonacappelle/Master-Thesis to find the latest version!

  • v1.0: Master Thesis result

Todo:
Future improvements:
  • Measurement of accuracy of sensor node against reference system
  • Enable remote calibration by receiving special packet from BLE

License

Copyright (C) 2020 - Jona Cappelle

Definition in file main.c.

Macro Definition Documentation

◆ DIY

#define DIY   1

Variable to change between pinout of sensor node and pinout of development board

Definition at line 116 of file main.c.

Function Documentation

◆ CheckIMUidle()

void CheckIMUidle ( void  )

Function called by RTC timer every second.

Check batt Check gyro idle Check BLE connected Dynamically set Madgwick beta parameter

Definition at line 163 of file main.c.

164 {
165 
166  /* Read battery in percent */
168 
169  float mean_gyro = (uint8_t) ( data.ICM_20948_gyro[0] + data.ICM_20948_gyro[1] + data.ICM_20948_gyro[2] ) / 3;
170 
171  /* Add 1 sec to the count of idle seconds */
172  if( mean_gyro < 0.1 )
173  {
174  idle_count++;
175  }else{ /* If there is movement, reset idle seconds */
176  idle_count = 0;
177  }
178 
179 
180  if( (idle_count > 60) || (ble_sec_not_connected > 5*5)) // 5sec * 75Hz
181  {
182  idle_count = 0;
184  teller_accuracy = 0;
185  beta = 1.0f;
186  /* Dont't check idle state in sleep */
187  RTCDRV_StopTimer( IMU_Idle_Timer );
188  /* Stop generating interrupts */
189  ICM_20948_interruptEnable(false, false);
190  appState = SLEEP;
191  _sleep = true;
192  }
193  // Reset timer is BLE is connected
194  if(bleConnected)
195  {
197  }
198 
199 /* For visual representation where in the code */
200 #if DIY == 0
201  BSP_LedToggle(1);
202 #endif
203 
204  if(teller_accuracy < 10)
205  {
206  teller_accuracy++;
207  }
208 
209  if(teller_accuracy >= 10)
210  {
211  beta = 0.05f;
212  }
213 
214 }

References ADC_get_batt(), MeasurementData_t::batt, beta, ble_sec_not_connected, data, MeasurementData_t::ICM_20948_gyro, ICM_20948_interruptEnable(), idle_count, IMU_Idle_Timer, and teller_accuracy.

◆ GPIO_EVEN_IRQHandler()

void GPIO_EVEN_IRQHandler ( void  )

GPIO Even IRQ for pushbuttons on even-numbered pins.

Definition at line 618 of file main.c.

619 {
620  // Clear all even pin interrupt flags
621  GPIO_IntClear(0x5555);
622 #if DEBUG_DBPRINTs == 1 /* DEBUG_DBPRINT */
623  dbprint("Interrupt fired! 1");
624 #endif /* DEBUG_DBPRINT */
625 
626 // measure_send();
627 
628 // ICM_20948_interruptStatusRead(interruptStatus);
629 //
630 // /* AND with mask to check only bit 4 of byte 1 */
631 // if( (interruptStatus[0] & 8) == 8 ) /* If interrupt is bit WOM interrupt */
632 // {
633 // appState = SLEEP;
634 // }else{
635 
636  /* If sensor is not trying to sleep, read sensors
637  * Otherwise bug when trying to sleep but still last interrupts occurring, sensor won't go to sleep
638  */
639  if(appState != SLEEP)
640  {
641  appState = SENSORS_READ;
642  }
643 
644 
645 // }
646 }

References dbprint().

◆ GPIO_ODD_IRQHandler()

void GPIO_ODD_IRQHandler ( void  )

GPIO Odd IRQ for pushbuttons on odd-numbered pins.

Definition at line 651 of file main.c.

652 {
653  // Clear all odd pin interrupt flags
654  GPIO_IntClear(0xAAAA);
655 
656 #if DEBUG_DBPRINTs == 1 /* DEBUG_DBPRINT */
657  dbprint("Interrupt fired! 2");
658 #endif /* DEBUG_DBPRINT */
659 
660 // appState = SENSORS_READ;
661 }

References dbprint().

◆ main()

int main ( void  )

Main function.

State diagram BATT_READ and CALLIBRATE will never be reached Future update: calibrate when receiving special BLE packet

Definition at line 316 of file main.c.

317 {
318 
319  /* Start with initialization */
320  appState = INIT;
321 
322  /* Infinite loop */
323  while (1)
324  {
325  switch (appState)
326  {
327  /***************************/
328  case SYS_IDLE:
329  {
330  /* Wait in EM2 */
331 // EMU_EnterEM2(true);
332 
333  }
334  break;
335  /***************************/
336  case INIT:
337  {
338  /* Chip errata */
339  CHIP_Init();
340 
341 
342  /* ENABLE CODE CORRELATION -- uses SWO */
343  /* If first word of user data page is non-zero, enable eA Profiler trace */
344 // BSP_TraceProfilerSetup();
345 
346  /* FULL SPEED */
347  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
348 // CMU_OscillatorEnable(cmuOsc_HFRCO, false, false);
349 
350  CMU_ClockEnable(cmuClock_HFPER, true);
351  CMU_ClockEnable(cmuClock_GPIO, true);
352 
353  /* Set output pin to check frequency of execution */
354 
355  GPIO_PinModeSet(gpioPortE, 11, gpioModePushPull, 0);
356 
357 #if DIY == 1
358  GPIO_PinModeSet(LED_PORT, LED_PIN, gpioModePushPull, 1);
359  delay(1000);
360  GPIO_PinModeSet(LED_PORT, LED_PIN, gpioModeDisabled, 0);
361 
362  blink(3);
363 #endif
364 
365  /* Leds on development board */
366 #if DIY == 0
367  BSP_LedsInit();
368 #endif
369 
370  /* Setup printing to virtual COM port, w */
371 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
372  dbprint_INIT(USART1, 4, true, false);
373 #endif /* DEBUG_DBPRINT */
374 
375  /* Timer init */
376  RTCDRV_Init();
377  RTCDRV_AllocateTimer(&IMU_Idle_Timer);
378 
379 
380  /* Initialize ICM_20948 + SPI interface */
381  ICM_20948_Init();
382  //ICM_20948_Init_SPI();
383 
384  /* Initialize GPIO interrupts on port C 2 */
386 
387  /* Initialize ADC to read battery voltage */
388  initADC();
389 // ADC_get_batt(data.batt);
390 
391 
392 
393 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
394  dbprintln("INIT");
395 #endif /* DEBUG_DBPRINT */
396 
397  /* Bluetooth */
398 #if DEBUG_DBPRINT == 0 /* DEBUG_DBPRINT */
399  BLE_Init();
400 #endif /* DEBUG_DBPRINT */
401 
402  delay(200);
403  /* Set output power */
404 // BLE_set_output_power(BLE_OUTPUT_POWER_0DB);
405 // delay(100);
406 
407  // TODO Temporary
408  /* Check connection */
409 #if DEBUG_DBPRINT == 0 /* DEBUG_DBPRINT */
411  if (!bleConnected)
412  {
413  BLE_power(true);
414  delay(1000);
415  BLE_connect();
416  }
417 #endif /* DEBUG_DBPRINT */
418 
419  /* Set interrupt to trigger every 100ms when the data is ready */
420  IMU_MEASURING = true;
421  ICM_20948_interruptEnable(true, false);
422 
423  /* Fancy LED's */
424 #if DIY == 0
425  for(uint8_t i=0; i<8; i++)
426  {
427  BSP_LedSet(0);
428  BSP_LedSet(1);
429  delay(100);
430  BSP_LedClear(0);
431  BSP_LedClear(1);
432  delay(100);
433  }
434 #endif
435 
436  /* Timer for checking if IMU is idle */
437  RTCDRV_StartTimer( IMU_Idle_Timer, rtcdrvTimerTypePeriodic, 2000, (RTCDRV_Callback_t)CheckIMUidle, NULL);
438 
439 
440 
441  appState = SYS_IDLE;
442 
443 
444  }
445  break;
446  /***************************/
447  case SENSORS_READ:
448  {
449 
450 #if DEBUG_DBPRINTs == 1 /* DEBUG_DBPRINT */
451  dbprintln("SENSORS_READ");
452 #endif /* DEBUG_DBPRINT */
453 
454  measure_send();
455 
456 #if DEBUG_DBPRINTs == 1 /* DEBUG_DBPRINT */
457  dbprintInt((int) ( data.ICM_20948_gyro[0]*100) );
458  dbprint(",");
459  dbprintInt((int) (data.ICM_20948_gyro[1] *100) );
460  dbprint(",");
461  dbprintInt((int) (data.ICM_20948_gyro[2] *100) );
462  dbprint(",");
463  dbprintInt((int) ( data.ICM_20948_accel[0]*100) );
464  dbprint(",");
465  dbprintInt((int) (data.ICM_20948_accel[1] *100) );
466  dbprint(",");
467  dbprintlnInt((int) (data.ICM_20948_accel[2] *100) );
468 #endif /* DEBUG_DBPRINT */
469 
470 #if DEBUG_DBPRINTs == 1 /* DEBUG_DBPRINT */
471  //dbprint(" roll: ");
472  dbprintInt((int) (ICM_20948_euler_angles[0] *100) );
473  //dbprint(" pitch: ");
474  dbprint("\t");
475  dbprintInt((int) (ICM_20948_euler_angles[1] *100) );
476  //dbprint(" yaw: ");
477  dbprint("\t");
478  dbprintlnInt((int) (ICM_20948_euler_angles[2] *100) );
479 #endif /* DEBUG_DBPRINT */
480 
481 #if DEBUG_DBPRINTs == 1 /* DEBUG_DBPRINT */
482  dbprintInt((int) ICM_20948_magn[0] );
483  dbprint(",");
484  dbprintInt((int) ICM_20948_magn[1] );
485  dbprint(",");
486  dbprintlnInt((int) ICM_20948_magn[2] );
487 #endif /* DEBUG_DBPRINT */
488 
489 
490  /* If imu is idle, give it the chance to go to sleep */
491  if(!_sleep)
492  {
493  appState = SYS_IDLE;
494  }
495  }
496  break;
497  /***************************/
498  case BATT_READ:
499  {
500  ADC_Batt_Read();
502 
503 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
504  dbprintln("BATT_READ");
505 #endif /* DEBUG_DBPRINT */
506 
507  appState = SYS_IDLE;
508  }
509  break;
510  /***************************/
511  case SLEEP:
512  {
513  //RTCDRV_StartTimer( IMU_Idle_Timer, rtcdrvTimerTypeOneshot, 2000, test, NULL);
514 
515  RTCDRV_StopTimer( IMU_Idle_Timer );
516  RTCDRV_DeInit();
517 
518  BLE_disconnect();
519  delay(100);
520  BLE_power( false);
521  BLE_rxtx_enable( false );
522 
523  bleConnected = false;
524 
525  CMU_ClockEnable(cmuClock_ADC0, false);
526 // GPIO_PinModeSet(gpioPortD, 4, gpioModeDisabled, 0);
527 
528  GPIO_PinModeSet(gpioPortE, 11, gpioModeDisabled, 0);
529 
530 
531  /* Shut down magnetometer */
533  delay(100);
534 
535  uint8_t temp1[8];
536  ICM_20948_read_mag_register(0x31, 1, temp1);
537  /* Update data by reading through till ST2 register */
538  ICM_20948_read_mag_register(0x11, 8, temp1);
539 
540 
541  /* Wake on motion: 50 mg's (0.05 G) */
542  ICM_20948_wakeOnMotionITEnable(true, 20, 2.2);
543 // ICM_20948_sleepModeEnable(true);
544  delay(400);
545 
546  IIC_Enable(false);
547 
548 
549  /* Disable Systicks before going to sleep */
550  EMU_EnterEM2(true);
551 
552 
554  /* When waking up, initialize everything */
556 
557  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
558 
559  IIC_Enable(true);
560  BLE_power(true);
561  BLE_rxtx_enable( true );
562  CMU_ClockEnable(cmuClock_ADC0, true);
563 
564  _sleep = false;
565 
566  /* Setup IMU */
567  ICM_20948_lowPowerModeEnter(false, false, false);
568  ICM_20948_Init2();
569 
570 
571  /* Timer for checking if IMU is idle */
572  RTCDRV_Init();
573  RTCDRV_AllocateTimer(&IMU_Idle_Timer);
574  RTCDRV_StartTimer( IMU_Idle_Timer, rtcdrvTimerTypePeriodic, 2000, (RTCDRV_Callback_t)CheckIMUidle, NULL);
575 
576  /* Set interrupt to trigger every 100ms when the data is ready */
577  IMU_MEASURING = true;
578  ICM_20948_interruptEnable(true, false);
579 
580  GPIO_PinModeSet(gpioPortE, 11, gpioModePushPull, 0);
581 
582  appState = SYS_IDLE;
583 
584 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
585  dbprintln("SLEEP");
586 #endif /* DEBUG_DBPRINT */
587  }
588  break;
589  /***************************/
590  case CALLIBRATE:
591  {
592 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
593  dbprintln("CALLIBRATE");
594 #endif /* DEBUG_DBPRINT */
595 
598 
599  appState = SYS_IDLE;
600  }
601  break;
602  /***************************/
603  } //switch
604 
605  } //while
606 } //main

◆ measure_send()

void measure_send ( void  )

Function called by interrupt from IMU @50 Hz.

Measure Gyro + Accel + Magn Sensor fusion with Madgwick filter Convert quaternions to Euler angles Convert floats to uint8_t for transmission Send data via UART to BLE module (interrupt based) Toggle pin to check speed

Note
Max execution speed 75 Hz

Definition at line 234 of file main.c.

235 {
236 
237  /* Check connection */
238 #if DEBUG_DBPRINT == 0 /* DEBUG_DBPRINT */
240  if (!bleConnected)
241  {
243  BLE_power(true);
244  delay(200);
245  BLE_connect();
246  }
247 
248 #endif /* DEBUG_DBPRINT */
249 
250  /* Read all sensors */
254 
255  // TODO: embedded ICM_20948_magn_to_angle( ICM_20948_magn, ICM_20948_magn_angle );
256 
257 // uint32_t start = millis();
258 
259  /* Sensor fusion */
261  data.ICM_20948_gyro[1] * M_PI / 180.0f,
262  data.ICM_20948_gyro[2] * M_PI / 180.0f,
266 
267 
268 
269 // uint32_t duration = millis() - start;
270 
271  /* Convert float's to uint8_t arrays for transmission over BLE */
274 
275 // helft = !helft;
276 
277 
278 #if DEBUG_DBPRINT == 0 /* DEBUG_DBPRINT */
279 // if(helft == 1)
280 // {
281 
282 // if(teller < 3)
283 // {
285  /* Test frequency */
286  GPIO_PinOutSet(gpioPortE, 11);
287  GPIO_PinOutClear(gpioPortE, 11);
288 // }else{
289 // teller = 0;
290 // }
291 // teller++;
292 
293 
294 // }
295 #endif /* DEBUG_DBPRINT */
296 
297 #if DIY == 0
298  BSP_LedToggle(0);
299 #endif
300 
301 
302 }

References MeasurementData_t::batt, BLE_check_connect(), BLE_connect(), MeasurementData_t::BLE_data, MeasurementData_t::BLE_euler_angles, BLE_power(), ble_sec_not_connected, BLE_sendData(), bleConnected, data, delay(), float_to_uint8_t_x3(), MeasurementData_t::ICM_20948_accel, ICM_20948_accelDataRead(), MeasurementData_t::ICM_20948_euler_angles, MeasurementData_t::ICM_20948_gyro, ICM_20948_gyroDataRead(), ICM_20948_magDataRead(), MeasurementData_t::ICM_20948_magn, M_PI, MadgwickAHRSupdate(), and QuaternionsToEulerAngles().

Variable Documentation

◆ _sleep

bool _sleep = false

Variable to fix some problems with IMU generating interrupt and thus waking up the system when trying to go to sleep

Definition at line 128 of file main.c.

◆ beta

volatile float beta = 1.0f

Beta parameter of Madgwick filter

Definition at line 145 of file main.c.

Referenced by CheckIMUidle(), MadgwickAHRSupdate(), and MadgwickAHRSupdateIMU().

◆ ble_sec_not_connected

uint8_t ble_sec_not_connected = 0

200 ms that the BLE is not connected

Definition at line 131 of file main.c.

Referenced by CheckIMUidle(), and measure_send().

◆ bleConnected

bool bleConnected = false

Keep track of the state of the BLE module

Definition at line 125 of file main.c.

Referenced by BLE_check_connect(), and measure_send().

◆ data

◆ helft

bool helft = false

Not used at the moment

Definition at line 140 of file main.c.

◆ IDLE

bool IDLE = false

Variable to keep track if the system is IDLE of the IDLE state, not used at the moment

Definition at line 127 of file main.c.

◆ idle_count

uint8_t idle_count = 0

Seconds that the IMU is idle

Definition at line 130 of file main.c.

Referenced by CheckIMUidle().

◆ IMU_Idle_Timer

RTCDRV_TimerID_t IMU_Idle_Timer

Timer used for checking variables every second

Definition at line 136 of file main.c.

Referenced by CheckIMUidle().

◆ IMU_MEASURING

bool IMU_MEASURING = false

Keep track of the state of the IMU

Definition at line 126 of file main.c.

◆ interruptStatus

uint32_t interruptStatus[1]

Not used at the moment

Definition at line 133 of file main.c.

◆ teller

uint8_t teller = 0

Not used at the moment

Definition at line 142 of file main.c.

◆ teller_accuracy

uint8_t teller_accuracy = 0

Counter to keep track when to enter accuracy mode on Madgwick filter

Definition at line 143 of file main.c.

Referenced by CheckIMUidle().

MeasurementData_t::magOffset
float magOffset[3]
Definition: datatypes.h:47
teller_accuracy
uint8_t teller_accuracy
Definition: main.c:143
CheckIMUidle
void CheckIMUidle(void)
Function called by RTC timer every second.
Definition: main.c:163
MeasurementData_t::ICM_20948_gyro
float ICM_20948_gyro[3]
Definition: datatypes.h:35
dbprint_INIT
void dbprint_INIT(USART_TypeDef *pointer, uint8_t location, bool vcom, bool interrupts)
data
MeasurementData_t data
Definition: main.c:122
BLE_sendData
void BLE_sendData(uint8_t *data, uint8_t *batt, uint8_t length, uint8_t *ble_data)
Send all the data over BLE.
Definition: ble.c:261
ICM_20948_accelDataRead
uint32_t ICM_20948_accelDataRead(float *accel)
Read RAW accelerometer data.
Definition: ICM20948.c:1170
ICM_20948_lowPowerModeEnter
uint32_t ICM_20948_lowPowerModeEnter(bool enAccel, bool enGyro, bool enTemp)
Enter low power mode for selected sensors.
Definition: ICM20948.c:1037
MeasurementData_t::BLE_data
uint8_t BLE_data[sizeof(float) *3+5]
Definition: datatypes.h:42
IMU_Idle_Timer
RTCDRV_TimerID_t IMU_Idle_Timer
Definition: main.c:136
BLE_power
void BLE_power(bool enable)
Turn power on/off for BLE module.
Definition: ble.c:84
ble_sec_not_connected
uint8_t ble_sec_not_connected
Definition: main.c:131
ICM_20948_wakeOnMotionITEnable
uint32_t ICM_20948_wakeOnMotionITEnable(bool enable, uint8_t womThreshold, float sampleRate)
Set wake on motion interrupt.
Definition: ICM20948.c:1295
dbprint
void dbprint(char *message)
delay
void delay(uint32_t msDelay)
Wait for a certain amount of milliseconds in EM2/3.
Definition: delay.c:116
dbprintInt
void dbprintInt(int32_t value)
SENSORS_READ
Definition: datatypes.h:25
BLE_rxtx_enable
void BLE_rxtx_enable(bool enable)
Enable disable RX/TX pins from BLE module.
Definition: ble.c:128
IMU_MEASURING
bool IMU_MEASURING
Definition: main.c:126
idle_count
uint8_t idle_count
Definition: main.c:130
MeasurementData_t::ICM_20948_accel
float ICM_20948_accel[3]
Definition: datatypes.h:36
BLE_check_connect
void BLE_check_connect()
Check if LED pin on BLE is high to check if the module is connected to a receiver.
Definition: ble.c:179
blink
void blink(uint8_t times)
Function to blink LED on sensor node.
Definition: util.c:57
LED_PORT
#define LED_PORT
Definition: pinout.h:20
ICM_20948_Init
void ICM_20948_Init()
Init function for ICM20948.
Definition: ICM20948.c:85
initADC
void initADC(void)
Initialisation of the ADC.
Definition: adc.c:32
bleConnected
bool bleConnected
Definition: main.c:125
dbprintlnInt
void dbprintlnInt(int32_t value)
IIC_Enable
void IIC_Enable(bool enable)
Definition: I2C.c:71
SLEEP
Definition: datatypes.h:27
ICM_20948_gyroDataRead
uint32_t ICM_20948_gyroDataRead(float *gyro)
Read gyroscope data from IMU.
Definition: ICM20948.c:783
measure_send
void measure_send(void)
Function called by interrupt from IMU @50 Hz.
Definition: main.c:234
ADC_Batt_Read
void ADC_Batt_Read(void)
Do single ADC conversion (read)
Definition: adc.c:100
MeasurementData_t::batt
uint8_t batt[1]
Definition: datatypes.h:51
BLE_connect
void BLE_connect()
Connect sequence BLE.
Definition: ble.c:152
ICM_20948_Init2
void ICM_20948_Init2()
Second init function for ICM20948, use when waking from sleep.
Definition: ICM20948.c:169
ICM_20948_interruptEnable
uint32_t ICM_20948_interruptEnable(bool dataReadyEnable, bool womEnable)
Enable interrupt for data ready or wake on motion.
Definition: ICM20948.c:885
MeasurementData_t::ICM_20948_magn
float ICM_20948_magn[3]
Definition: datatypes.h:37
SYS_IDLE
Definition: datatypes.h:29
ICM_20948_read_mag_register
void ICM_20948_read_mag_register(uint8_t addr, uint8_t numBytes, uint8_t *data)
Read register in the AK09916 magnetometer device.
Definition: ICM20948.c:1594
ICM_20948_set_mag_mode
uint32_t ICM_20948_set_mag_mode(uint8_t magMode)
Set magnetometer mode (sample rate / on-off)
Definition: ICM20948.c:1670
ICM_20948_calibrate_mag
bool ICM_20948_calibrate_mag(float *offset, float *scale)
Magnetometer calibration function. Get magnetometer minimum and maximum values, while moving the devi...
Definition: ICM20948.c:2289
ADC_get_batt
void ADC_get_batt(uint8_t *percent)
Get battery in percentage.
Definition: adc.c:132
LED_PIN
#define LED_PIN
Definition: pinout.h:21
beta
volatile float beta
Definition: main.c:145
initGPIO_interrupt
void initGPIO_interrupt(void)
GPIO interrupt initialization.
Definition: interrupt.c:42
MeasurementData_t::ICM_20948_euler_angles
float ICM_20948_euler_angles[3]
Definition: datatypes.h:38
AK09916_BIT_MODE_POWER_DOWN
#define AK09916_BIT_MODE_POWER_DOWN
Definition: pinout.h:384
MeasurementData_t::gyroCal
float gyroCal[3]
Definition: datatypes.h:46
ICM_20948_magDataRead
void ICM_20948_magDataRead(float *magn)
Convert raw magnetometer values to calibrated and scaled ones.
Definition: ICM20948.c:1745
ICM_20948_accelGyroCalibrate
uint32_t ICM_20948_accelGyroCalibrate(float *accelBiasScaled, float *gyroBiasScaled)
Accelerometer and gyroscope calibration function. Reads the gyroscope and accelerometer values while ...
Definition: ICM20948.c:1820
MeasurementData_t::accelCal
float accelCal[3]
Definition: datatypes.h:45
QuaternionsToEulerAngles
void QuaternionsToEulerAngles(float *euler_angles)
Convert quaternions to euler angles.
Definition: MadgwickAHRS.c:351
INIT
Definition: datatypes.h:24
CALLIBRATE
Definition: datatypes.h:28
float_to_uint8_t_x3
void float_to_uint8_t_x3(float *in, uint8_t *out)
Float to uint8_t conversion x3.
Definition: ble.c:419
MeasurementData_t::BLE_euler_angles
uint8_t BLE_euler_angles[sizeof(float) *3]
Definition: datatypes.h:41
MeasurementData_t::magScale
float magScale[3]
Definition: datatypes.h:48
_sleep
bool _sleep
Definition: main.c:128
M_PI
#define M_PI
Definition: ICM20948.c:41
dbprintln
void dbprintln(char *message)
MadgwickAHRSupdate
void MadgwickAHRSupdate(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz)
Madgwick algorithm.
Definition: MadgwickAHRS.c:92
BATT_READ
Definition: datatypes.h:26
BLE_disconnect
void BLE_disconnect()
Disconnect BLE from receiver.
Definition: ble.c:195
BLE_Init
void BLE_Init()
BLE chip init.
Definition: ble.c:61