mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-10 18:24:11 +01:00
OP-1658 - HMC5x83 sensor device model implementation
This commit is contained in:
parent
6341fa7eca
commit
84f577029e
@ -50,6 +50,22 @@ typedef struct {
|
|||||||
|
|
||||||
static int32_t PIOS_HMC5x83_Config(pios_hmc5x83_dev_data_t *dev);
|
static int32_t PIOS_HMC5x83_Config(pios_hmc5x83_dev_data_t *dev);
|
||||||
|
|
||||||
|
// sensor driver interface
|
||||||
|
bool PIOS_HMC5x83_driver_Test(uintptr_t context);
|
||||||
|
void PIOS_HMC5x83_driver_Reset(uintptr_t context);
|
||||||
|
void PIOS_HMC5x83_driver_get_scale(float *scales, uint8_t size, uintptr_t context);
|
||||||
|
void PIOS_HMC5x83_driver_fetch(void *, uint8_t size, uintptr_t context);
|
||||||
|
bool PIOS_HMC5x83_driver_poll(uintptr_t context);
|
||||||
|
|
||||||
|
PIOS_SENSORS_Driver PIOS_HMC5x83_Driver = {
|
||||||
|
.test = PIOS_HMC5x83_driver_Test,
|
||||||
|
.poll = PIOS_HMC5x83_driver_poll,
|
||||||
|
.fetch = PIOS_HMC5x83_driver_fetch,
|
||||||
|
.reset = PIOS_HMC5x83_driver_Reset,
|
||||||
|
.get_queue = NULL,
|
||||||
|
.get_scale = PIOS_HMC5x83_driver_get_scale,
|
||||||
|
.is_polled = true,
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* Allocate the device setting structure
|
* Allocate the device setting structure
|
||||||
* @return pios_hmc5x83_dev_data_t pointer to newly created structure
|
* @return pios_hmc5x83_dev_data_t pointer to newly created structure
|
||||||
@ -99,6 +115,11 @@ pios_hmc5x83_dev_t PIOS_HMC5x83_Init(const struct pios_hmc5x83_cfg *cfg, uint32_
|
|||||||
return (pios_hmc5x83_dev_t)dev;
|
return (pios_hmc5x83_dev_t)dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PIOS_HMC5x83_Register(pios_hmc5x83_dev_t handler)
|
||||||
|
{
|
||||||
|
PIOS_SENSORS_Register(&PIOS_HMC5x83_Driver, PIOS_SENSORS_TYPE_3AXIS_MAG, handler);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize the HMC5x83 magnetometer sensor
|
* @brief Initialize the HMC5x83 magnetometer sensor
|
||||||
* \return none
|
* \return none
|
||||||
@ -549,6 +570,37 @@ int32_t PIOS_HMC5x83_I2C_Write(pios_hmc5x83_dev_t handler, uint8_t address, uint
|
|||||||
}
|
}
|
||||||
#endif /* PIOS_INCLUDE_I2C */
|
#endif /* PIOS_INCLUDE_I2C */
|
||||||
|
|
||||||
|
/* PIOS sensor driver implementation */
|
||||||
|
bool PIOS_HMC5x83_driver_Test(uintptr_t context)
|
||||||
|
{
|
||||||
|
return !PIOS_HMC5x83_Test((pios_hmc5x83_dev_t)context);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PIOS_HMC5x83_driver_Reset(__attribute__((unused)) uintptr_t context) {}
|
||||||
|
|
||||||
|
void PIOS_HMC5x83_driver_get_scale(float *scales, uint8_t size, __attribute__((unused)) uintptr_t context)
|
||||||
|
{
|
||||||
|
PIOS_Assert(size > 0);
|
||||||
|
scales[0] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PIOS_HMC5x83_driver_fetch(void *data, uint8_t size, uintptr_t context)
|
||||||
|
{
|
||||||
|
PIOS_Assert(size > 0);
|
||||||
|
int16_t mag[3];
|
||||||
|
PIOS_HMC5x83_ReadMag((pios_hmc5x83_dev_t)context, mag);
|
||||||
|
PIOS_SENSORS_3Axis_SensorsWithTemp *tmp = data;
|
||||||
|
tmp->count = 1;
|
||||||
|
tmp->sample[0].x = mag[0];
|
||||||
|
tmp->sample[0].y = mag[1];
|
||||||
|
tmp->sample[0].z = mag[2];
|
||||||
|
tmp->temperature = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PIOS_HMC5x83_driver_poll(uintptr_t context)
|
||||||
|
{
|
||||||
|
return PIOS_HMC5x83_NewDataAvailable((pios_hmc5x83_dev_t)context);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* PIOS_INCLUDE_HMC5x83 */
|
#endif /* PIOS_INCLUDE_HMC5x83 */
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#ifndef PIOS_HMC5x83_H
|
#ifndef PIOS_HMC5x83_H
|
||||||
#define PIOS_HMC5x83_H
|
#define PIOS_HMC5x83_H
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <pios_sensors.h>
|
||||||
/* HMC5x83 Addresses */
|
/* HMC5x83 Addresses */
|
||||||
#define PIOS_HMC5x83_I2C_ADDR 0x1E
|
#define PIOS_HMC5x83_I2C_ADDR 0x1E
|
||||||
#define PIOS_HMC5x83_I2C_READ_ADDR 0x3D
|
#define PIOS_HMC5x83_I2C_READ_ADDR 0x3D
|
||||||
@ -123,12 +124,16 @@ struct pios_hmc5x83_cfg {
|
|||||||
|
|
||||||
/* Public Functions */
|
/* Public Functions */
|
||||||
extern pios_hmc5x83_dev_t PIOS_HMC5x83_Init(const struct pios_hmc5x83_cfg *cfg, uint32_t port_id, uint8_t device_num);
|
extern pios_hmc5x83_dev_t PIOS_HMC5x83_Init(const struct pios_hmc5x83_cfg *cfg, uint32_t port_id, uint8_t device_num);
|
||||||
|
extern void PIOS_HMC5x83_Register(pios_hmc5x83_dev_t handler);
|
||||||
|
|
||||||
extern bool PIOS_HMC5x83_NewDataAvailable(pios_hmc5x83_dev_t handler);
|
extern bool PIOS_HMC5x83_NewDataAvailable(pios_hmc5x83_dev_t handler);
|
||||||
extern int32_t PIOS_HMC5x83_ReadMag(pios_hmc5x83_dev_t handler, int16_t out[3]);
|
extern int32_t PIOS_HMC5x83_ReadMag(pios_hmc5x83_dev_t handler, int16_t out[3]);
|
||||||
extern uint8_t PIOS_HMC5x83_ReadID(pios_hmc5x83_dev_t handler, uint8_t out[4]);
|
extern uint8_t PIOS_HMC5x83_ReadID(pios_hmc5x83_dev_t handler, uint8_t out[4]);
|
||||||
extern int32_t PIOS_HMC5x83_Test(pios_hmc5x83_dev_t handler);
|
extern int32_t PIOS_HMC5x83_Test(pios_hmc5x83_dev_t handler);
|
||||||
extern bool PIOS_HMC5x83_IRQHandler(pios_hmc5x83_dev_t handler);
|
extern bool PIOS_HMC5x83_IRQHandler(pios_hmc5x83_dev_t handler);
|
||||||
|
|
||||||
|
extern PIOS_SENSORS_Driver PIOS_MPU6000_Driver;
|
||||||
|
|
||||||
#endif /* PIOS_HMC5x83_H */
|
#endif /* PIOS_HMC5x83_H */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user