61 static DrvContextTypeDef MAGNETO_SensorHandle[ MAGNETO_SENSORS_MAX_NUM ];
62 static MAGNETO_Data_t MAGNETO_Data[ MAGNETO_SENSORS_MAX_NUM ];
63 static LSM303AGR_M_Data_t LSM303AGR_M_0_Data;
73 static DrvStatusTypeDef BSP_LSM303AGR_MAGNETO_Init(
void **handle );
84 extern DrvStatusTypeDef Sensor_IO_Init(
void );
108 case MAGNETO_SENSORS_AUTO:
111 if( BSP_LSM303AGR_MAGNETO_Init(handle) == COMPONENT_ERROR )
113 return COMPONENT_ERROR;
119 if( BSP_LSM303AGR_MAGNETO_Init(handle) == COMPONENT_ERROR )
121 return COMPONENT_ERROR;
131 static DrvStatusTypeDef BSP_LSM303AGR_MAGNETO_Init(
void **handle )
133 MAGNETO_Drv_t *driver = NULL;
136 if(MAGNETO_SensorHandle[ LSM303AGR_M_0 ].isInitialized == 1)
139 return COMPONENT_ERROR;
144 return COMPONENT_ERROR;
148 MAGNETO_SensorHandle[ LSM303AGR_M_0 ].who_am_i = LSM303AGR_MAG_WHO_AM_I;
149 MAGNETO_SensorHandle[ LSM303AGR_M_0 ].ifType = 1;
150 MAGNETO_SensorHandle[ LSM303AGR_M_0 ].address = LSM303AGR_MAG_I2C_ADDRESS;
151 MAGNETO_SensorHandle[ LSM303AGR_M_0 ].spiDevice = LSM303AGR_M;
152 MAGNETO_SensorHandle[ LSM303AGR_M_0 ].instance = LSM303AGR_M_0;
153 MAGNETO_SensorHandle[ LSM303AGR_M_0 ].isInitialized = 0;
154 MAGNETO_SensorHandle[ LSM303AGR_M_0 ].isEnabled = 0;
155 MAGNETO_SensorHandle[ LSM303AGR_M_0 ].isCombo = 0;
156 MAGNETO_SensorHandle[ LSM303AGR_M_0 ].pData = (
void * )&MAGNETO_Data[ LSM303AGR_M_0 ];
157 MAGNETO_SensorHandle[ LSM303AGR_M_0 ].pVTable = (
void * )&LSM303AGR_M_Drv;
158 MAGNETO_SensorHandle[ LSM303AGR_M_0 ].pExtVTable = 0;
160 LSM303AGR_M_0_Data.comboData = &LSM303AGR_Combo_Data[0];
161 MAGNETO_Data[ LSM303AGR_M_0 ].pComponentData = (
void * )&LSM303AGR_M_0_Data;
162 MAGNETO_Data[ LSM303AGR_M_0 ].pExtData = 0;
164 *handle = (
void *)&MAGNETO_SensorHandle[ LSM303AGR_M_0 ];
166 Sensor_IO_SPI_CS_Init(*handle);
168 if(LSM303AGR_Combo_Data[0].isAccInitialized == 0)
173 return COMPONENT_ERROR;
177 driver = ( MAGNETO_Drv_t * )((DrvContextTypeDef *)(*handle))->pVTable;
179 if ( driver->Init == NULL )
181 memset((*handle), 0,
sizeof(DrvContextTypeDef));
183 return COMPONENT_ERROR;
186 if ( driver->Init( (DrvContextTypeDef *)(*handle) ) == COMPONENT_ERROR )
188 memset((*handle), 0,
sizeof(DrvContextTypeDef));
190 return COMPONENT_ERROR;
194 if ( LSM303AGR_MAG_W_I2C_DIS( *handle, LSM303AGR_MAG_I2C_DISABLED ) == MEMS_ERROR )
196 return COMPONENT_ERROR;
211 DrvContextTypeDef *ctx = (DrvContextTypeDef *)(*handle);
212 MAGNETO_Drv_t *driver = NULL;
216 return COMPONENT_ERROR;
219 driver = ( MAGNETO_Drv_t * )ctx->pVTable;
221 if ( driver->DeInit == NULL )
223 return COMPONENT_ERROR;
226 if ( driver->DeInit( ctx ) == COMPONENT_ERROR )
228 return COMPONENT_ERROR;
231 memset(ctx, 0,
sizeof(DrvContextTypeDef));
248 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
249 MAGNETO_Drv_t *driver = NULL;
253 return COMPONENT_ERROR;
256 driver = ( MAGNETO_Drv_t * )ctx->pVTable;
258 if ( driver->Sensor_Enable == NULL )
260 return COMPONENT_ERROR;
263 if ( driver->Sensor_Enable( ctx ) == COMPONENT_ERROR )
265 return COMPONENT_ERROR;
282 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
283 MAGNETO_Drv_t *driver = NULL;
287 return COMPONENT_ERROR;
290 driver = ( MAGNETO_Drv_t * )ctx->pVTable;
292 if ( driver->Sensor_Disable == NULL )
294 return COMPONENT_ERROR;
297 if ( driver->Sensor_Disable( ctx ) == COMPONENT_ERROR )
299 return COMPONENT_ERROR;
315 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
319 return COMPONENT_ERROR;
322 if ( status == NULL )
324 return COMPONENT_ERROR;
327 *status = ctx->isInitialized;
342 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
346 return COMPONENT_ERROR;
349 if ( status == NULL )
351 return COMPONENT_ERROR;
354 *status = ctx->isEnabled;
369 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
373 return COMPONENT_ERROR;
376 if ( status == NULL )
378 return COMPONENT_ERROR;
381 *status = ctx->isCombo;
396 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
400 return COMPONENT_ERROR;
403 if ( instance == NULL )
405 return COMPONENT_ERROR;
408 *instance = ctx->instance;
425 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
426 MAGNETO_Drv_t *driver = NULL;
430 return COMPONENT_ERROR;
433 driver = ( MAGNETO_Drv_t * )ctx->pVTable;
435 if ( who_am_i == NULL )
437 return COMPONENT_ERROR;
439 if ( driver->Get_WhoAmI == NULL )
441 return COMPONENT_ERROR;
443 if ( driver->Get_WhoAmI( ctx, who_am_i ) == COMPONENT_ERROR )
445 return COMPONENT_ERROR;
462 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
463 MAGNETO_Drv_t *driver = NULL;
467 return COMPONENT_ERROR;
470 driver = ( MAGNETO_Drv_t * )ctx->pVTable;
472 if ( driver->Check_WhoAmI == NULL )
474 return COMPONENT_ERROR;
476 if ( driver->Check_WhoAmI( ctx ) == COMPONENT_ERROR )
478 return COMPONENT_ERROR;
496 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
497 MAGNETO_Drv_t *driver = NULL;
501 return COMPONENT_ERROR;
504 driver = ( MAGNETO_Drv_t * )ctx->pVTable;
506 if ( magnetic_field == NULL )
508 return COMPONENT_ERROR;
510 if ( driver->Get_Axes == NULL )
512 return COMPONENT_ERROR;
514 if ( driver->Get_Axes( ctx, magnetic_field ) == COMPONENT_ERROR )
516 return COMPONENT_ERROR;
534 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
535 MAGNETO_Drv_t *driver = NULL;
539 return COMPONENT_ERROR;
542 driver = ( MAGNETO_Drv_t * )ctx->pVTable;
546 return COMPONENT_ERROR;
549 if ( driver->Get_AxesRaw == NULL )
551 return COMPONENT_ERROR;
554 if ( driver->Get_AxesRaw( ctx, value ) == COMPONENT_ERROR )
556 return COMPONENT_ERROR;
575 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
576 MAGNETO_Drv_t *driver = NULL;
580 return COMPONENT_ERROR;
583 driver = ( MAGNETO_Drv_t * )ctx->pVTable;
585 if ( sensitivity == NULL )
587 return COMPONENT_ERROR;
589 if ( driver->Get_Sensitivity == NULL )
591 return COMPONENT_ERROR;
593 if ( driver->Get_Sensitivity( ctx, sensitivity ) == COMPONENT_ERROR )
595 return COMPONENT_ERROR;
613 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
614 MAGNETO_Drv_t *driver = NULL;
618 return COMPONENT_ERROR;
621 driver = ( MAGNETO_Drv_t * )ctx->pVTable;
625 return COMPONENT_ERROR;
627 if ( driver->Get_ODR == NULL )
629 return COMPONENT_ERROR;
631 if ( driver->Get_ODR( ctx, odr ) == COMPONENT_ERROR )
633 return COMPONENT_ERROR;
651 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
652 MAGNETO_Drv_t *driver = NULL;
656 return COMPONENT_ERROR;
659 driver = ( MAGNETO_Drv_t * )ctx->pVTable;
661 if ( driver->Set_ODR == NULL )
663 return COMPONENT_ERROR;
665 if ( driver->Set_ODR( ctx, odr ) == COMPONENT_ERROR )
667 return COMPONENT_ERROR;
685 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
686 MAGNETO_Drv_t *driver = NULL;
690 return COMPONENT_ERROR;
693 driver = ( MAGNETO_Drv_t * )ctx->pVTable;
695 if ( driver->Set_ODR_Value == NULL )
697 return COMPONENT_ERROR;
699 if ( driver->Set_ODR_Value( ctx, odr ) == COMPONENT_ERROR )
701 return COMPONENT_ERROR;
719 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
720 MAGNETO_Drv_t *driver = NULL;
724 return COMPONENT_ERROR;
727 driver = ( MAGNETO_Drv_t * )ctx->pVTable;
729 if ( fullScale == NULL )
731 return COMPONENT_ERROR;
733 if ( driver->Get_FS == NULL )
735 return COMPONENT_ERROR;
737 if ( driver->Get_FS( ctx, fullScale ) == COMPONENT_ERROR )
739 return COMPONENT_ERROR;
757 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
758 MAGNETO_Drv_t *driver = NULL;
762 return COMPONENT_ERROR;
765 driver = ( MAGNETO_Drv_t * )ctx->pVTable;
767 if ( driver->Set_FS == NULL )
769 return COMPONENT_ERROR;
771 if ( driver->Set_FS( ctx, fullScale ) == COMPONENT_ERROR )
773 return COMPONENT_ERROR;
791 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
792 MAGNETO_Drv_t *driver = NULL;
796 return COMPONENT_ERROR;
799 driver = ( MAGNETO_Drv_t * )ctx->pVTable;
801 if ( driver->Set_FS_Value == NULL )
803 return COMPONENT_ERROR;
805 if ( driver->Set_FS_Value( ctx, fullScale ) == COMPONENT_ERROR )
807 return COMPONENT_ERROR;
825 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
826 MAGNETO_Drv_t *driver = NULL;
830 return COMPONENT_ERROR;
833 driver = ( MAGNETO_Drv_t * )ctx->pVTable;
837 return COMPONENT_ERROR;
840 if ( driver->Read_Reg == NULL )
842 return COMPONENT_ERROR;
845 if ( driver->Read_Reg( ctx, reg, data ) == COMPONENT_ERROR )
847 return COMPONENT_ERROR;
866 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
867 MAGNETO_Drv_t *driver = NULL;
871 return COMPONENT_ERROR;
874 driver = ( MAGNETO_Drv_t * )ctx->pVTable;
876 if ( driver->Write_Reg == NULL )
878 return COMPONENT_ERROR;
881 if ( driver->Write_Reg( ctx, reg, data ) == COMPONENT_ERROR )
883 return COMPONENT_ERROR;
901 DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
902 MAGNETO_Drv_t *driver = NULL;
906 return COMPONENT_ERROR;
909 driver = ( MAGNETO_Drv_t * )ctx->pVTable;
911 if ( driver->Get_DRDY_Status == NULL )
913 return COMPONENT_ERROR;
916 if ( driver->Get_DRDY_Status( ctx, status ) == COMPONENT_ERROR )
918 return COMPONENT_ERROR;
DrvStatusTypeDef BSP_MAGNETO_Check_WhoAmI(void *handle)
Check the WHO_AM_I ID of the magnetometer sensor.
DrvStatusTypeDef BSP_MAGNETO_Set_ODR(void *handle, SensorOdr_t odr)
Set the magnetometer sensor output data rate.
DrvStatusTypeDef BSP_MAGNETO_DeInit(void **handle)
Deinitialize a magnetometer sensor.
DrvStatusTypeDef BSP_MAGNETO_Set_ODR_Value(void *handle, float odr)
Set the magnetometer sensor output data rate.
DrvStatusTypeDef BSP_MAGNETO_Get_FS(void *handle, float *fullScale)
Get the magnetometer sensor full scale.
DrvStatusTypeDef BSP_MAGNETO_Get_AxesRaw(void *handle, SensorAxesRaw_t *value)
Get the magnetometer sensor raw axes.
uint8_t Sensor_IO_Write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite)
Writes a buffer to the sensor.
DrvStatusTypeDef BSP_MAGNETO_Set_FS_Value(void *handle, float fullScale)
Set the magnetometer sensor full scale.
DrvStatusTypeDef BSP_MAGNETO_Set_FS(void *handle, SensorFs_t fullScale)
Set the magnetometer sensor full scale.
DrvStatusTypeDef Sensor_IO_SPI_Init(void)
Configures sensor SPI interface.
DrvStatusTypeDef BSP_MAGNETO_Get_WhoAmI(void *handle, uint8_t *who_am_i)
Get the WHO_AM_I ID of the magnetometer sensor.
DrvStatusTypeDef BSP_MAGNETO_IsCombo(void *handle, uint8_t *status)
Check if the magnetometer sensor is combo.
DrvStatusTypeDef BSP_MAGNETO_Get_DRDY_Status(void *handle, uint8_t *status)
Get magnetometer data ready status.
DrvStatusTypeDef BSP_MAGNETO_Get_Instance(void *handle, uint8_t *instance)
Get the magnetometer sensor instance.
DrvStatusTypeDef BSP_MAGNETO_Sensor_Enable(void *handle)
Enable magnetometer sensor.
DrvStatusTypeDef BSP_MAGNETO_IsEnabled(void *handle, uint8_t *status)
Check if the magnetometer sensor is enabled.
DrvStatusTypeDef BSP_MAGNETO_Get_Axes(void *handle, SensorAxes_t *magnetic_field)
Get the magnetometer sensor axes.
DrvStatusTypeDef BSP_MAGNETO_IsInitialized(void *handle, uint8_t *status)
Check if the magnetometer sensor is initialized.
DrvStatusTypeDef BSP_MAGNETO_Init(MAGNETO_ID_t id, void **handle)
Initialize a magnetometer sensor.
DrvStatusTypeDef BSP_MAGNETO_Get_Sensitivity(void *handle, float *sensitivity)
Get the magnetometer sensor sensitivity.
DrvStatusTypeDef BSP_MAGNETO_Get_ODR(void *handle, float *odr)
Get the magnetometer sensor output data rate.
DrvStatusTypeDef BSP_MAGNETO_Read_Reg(void *handle, uint8_t reg, uint8_t *data)
Read the data from register.
DrvStatusTypeDef BSP_MAGNETO_Write_Reg(void *handle, uint8_t reg, uint8_t data)
Write the data to register.
DrvStatusTypeDef BSP_MAGNETO_Sensor_Disable(void *handle)
Disable magnetometer sensor.
This file contains definitions for SensorTile_magneto.c driver.