for my students set_m_axes_offset
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Revision 7:fa19aa1a666d, committed 2020-02-08
- Comitter:
- docent
- Date:
- Sat Feb 08 09:11:31 2020 +0000
- Parent:
- 6:308889c4d074
- Commit message:
- for my students set_m_axes_offset
Changed in this revision
--- a/ST_INTERFACES.lib Wed Oct 18 11:14:26 2017 +0200 +++ b/ST_INTERFACES.lib Sat Feb 08 09:11:31 2020 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/ST_INTERFACES/#8f70f7159316 +https://developer.mbed.org/teams/ST/code/ST_INTERFACES/#d3c9b33b992c
--- a/lis3mdl.h Wed Oct 18 11:14:26 2017 +0200
+++ b/lis3mdl.h Sat Feb 08 09:11:31 2020 +0000
@@ -414,6 +414,7 @@
uint16_t NumByteToRead);
extern void LIS3MDL_IO_ITConfig( void );
+
/**
* @}
*/
--- a/lis3mdl_class.cpp Wed Oct 18 11:14:26 2017 +0200
+++ b/lis3mdl_class.cpp Sat Feb 08 09:11:31 2020 +0000
@@ -44,7 +44,7 @@
X-CUBE-MEMS1/trunk/Drivers/BSP/Components/lis3mdl/lis3mdl.c: revision #400,
X-CUBE-MEMS1/trunk: revision #416
*/
-
+/* my
LIS3MDL::LIS3MDL(SPI *spi, PinName cs_pin, PinName int_pin, SPI_type_t spi_type) :
_dev_spi(spi), _cs_pin(cs_pin), _int_pin(int_pin), _spi_type(spi_type)
{
@@ -63,15 +63,15 @@
if (_spi_type == SPI3W) LIS3MDL_Set_SpiInterface ((void *)this, LIS3MDL_SPI_3_WIRE);
else if (_spi_type == SPI4W) LIS3MDL_Set_SpiInterface ((void *)this, LIS3MDL_SPI_4_WIRE);
}
-
+*/
LIS3MDL::LIS3MDL(DevI2C *i2c, uint8_t address, PinName int_pin) :
_dev_i2c(i2c), _address(address), _cs_pin(NC), _int_pin(int_pin)
{
assert (i2c);
- _dev_spi = NULL;
+ //_dev_spi = NULL;
}
-
+/* my
MAGNETO_StatusTypeDef LIS3MDL::LIS3MDL_Set_SpiInterface (void *handle, LIS3MDL_SPIMode_t spimode)
{
uint8_t tmp=0x03; //deft LIS3MDL_CTRL_REG3 value
@@ -80,7 +80,7 @@
if (LIS3MDL_IO_Write(&tmp, LIS3MDL_M_CTRL_REG3_M, 1) != MAGNETO_OK) return MAGNETO_ERROR;
return MAGNETO_OK;
}
-
+*/
/**
* @brief Set LIS3MDL Initialization
* @param LIS3MDL_Init the configuration setting for the LIS3MDL
@@ -203,7 +203,7 @@
return MAGNETO_ERROR;
}
- pData[1] = ((((int16_t)tempReg[1]) << 8) + (int16_t)tempReg[0]);
+ pData[1] = *((int16_t*)&tempReg[0]);//((((int16_t)tempReg[1]) << 8) + (int16_t)tempReg[0]);
if(LIS3MDL_IO_Read(&tempReg[0], (LIS3MDL_M_OUT_Z_L_M | LIS3MDL_I2C_MULTIPLEBYTE_CMD),
2) != MAGNETO_OK)
@@ -217,6 +217,50 @@
}
+
+//my----------------------------------------------------------------------------
+MAGNETO_StatusTypeDef LIS3MDL::LIS3MDL_M_SetAxeOffset(uint8_t axe,int16_t offset)
+{
+ int16_t tmp;
+ uint8_t tmp1;
+ uint8_t tempReg = 0x00;
+ float sensitivity = 0;
+ float foffset;
+
+ if(LIS3MDL_IO_Read(&tempReg, LIS3MDL_M_CTRL_REG2_M, 1) != MAGNETO_OK)
+ {
+ return MAGNETO_ERROR;
+ }
+ tempReg &= LIS3MDL_M_FS_MASK;
+ switch(tempReg)
+ {
+ case LIS3MDL_M_FS_4:
+ sensitivity = 0.14;
+ break;
+ case LIS3MDL_M_FS_8:
+ sensitivity = 0.29;
+ break;
+ case LIS3MDL_M_FS_12:
+ sensitivity = 0.43;
+ break;
+ case LIS3MDL_M_FS_16:
+ sensitivity = 0.58;
+ break;
+ }
+
+ foffset=(float)offset;
+ foffset=foffset/sensitivity;
+ tmp=floor(foffset);
+ tmp1=tmp;
+ if(LIS3MDL_IO_Write(&tmp1, 5+2*axe, 1)!= MAGNETO_OK)
+ return MAGNETO_ERROR;
+ tmp1=tmp>>8;
+ if(LIS3MDL_IO_Write(&tmp1, 6+2*axe, 1)!= MAGNETO_OK)
+ return MAGNETO_ERROR;
+ return MAGNETO_OK;
+}
+
+
/**
* @brief Read data from LIS3MDL Magnetic sensor and calculate Magnetic in mgauss
* @param pData the pointer where the magnetometer data are stored
--- a/lis3mdl_class.h Wed Oct 18 11:14:26 2017 +0200
+++ b/lis3mdl_class.h Sat Feb 08 09:11:31 2020 +0000
@@ -51,9 +51,9 @@
*/
class LIS3MDL : public MagneticSensor {
public:
- enum SPI_type_t {SPI3W, SPI4W};
+ //my enum SPI_type_t {SPI3W, SPI4W};
- LIS3MDL(SPI *spi, PinName cs_pin, PinName int_pin=NC, SPI_type_t spi_type=SPI4W);
+ //my LIS3MDL(SPI *spi, PinName cs_pin, PinName int_pin=NC, SPI_type_t spi_type=SPI4W);
/** Constructor
* @param[in] i2c device I2C to be used for communication
@@ -81,15 +81,18 @@
virtual int get_m_axes_raw(int16_t *pData) {
return LIS3MDL_M_GetAxesRaw(pData);
}
-
+
+ virtual int set_m_axes_offset(uint8_t axe,int16_t offset) { //my
+ return LIS3MDL_M_SetAxeOffset(axe,offset);
+ }
protected:
/*** Methods ***/
MAGNETO_StatusTypeDef LIS3MDL_Init(MAGNETO_InitTypeDef *LIS3MDL_Init);
MAGNETO_StatusTypeDef LIS3MDL_Read_M_ID(uint8_t *m_id);
MAGNETO_StatusTypeDef LIS3MDL_M_GetAxes(int32_t *pData);
MAGNETO_StatusTypeDef LIS3MDL_M_GetAxesRaw(int16_t *pData);
- MAGNETO_StatusTypeDef LIS3MDL_Set_SpiInterface (void *handle, LIS3MDL_SPIMode_t spimode);
-
+ //my MAGNETO_StatusTypeDef LIS3MDL_Set_SpiInterface (void *handle, LIS3MDL_SPIMode_t spimode);
+ MAGNETO_StatusTypeDef LIS3MDL_M_SetAxeOffset(uint8_t axe,int16_t offset);//my
/**
* @brief Configures LIS3MDL interrupt lines for NUCLEO boards
*/
@@ -118,8 +121,9 @@
MAGNETO_StatusTypeDef LIS3MDL_IO_Read(uint8_t* pBuffer,
uint8_t RegisterAddr, uint16_t NumByteToRead)
{
+/*my
if (_dev_spi) {
- /* Write Reg Address */
+ // Write Reg Address
_dev_spi->lock();
_cs_pin = 0;
if (_spi_type == SPI4W) {
@@ -128,14 +132,15 @@
*(pBuffer+i) = _dev_spi->write(0x00);
}
} else if (_spi_type == SPI3W){
- /* Write RD Reg Address with RD bit*/
+ // Write RD Reg Address with RD bit
uint8_t TxByte = RegisterAddr | 0x80;
_dev_spi->write((char *)&TxByte, 1, (char *)pBuffer, (int) NumByteToRead);
}
_cs_pin = 1;
_dev_spi->unlock();
return MAGNETO_OK;
- }
+ }
+*/
if (!_dev_i2c) return MAGNETO_ERROR;
int ret = _dev_i2c->i2c_read(pBuffer,
_address,
@@ -158,7 +163,7 @@
MAGNETO_StatusTypeDef LIS3MDL_IO_Write(uint8_t* pBuffer,
uint8_t RegisterAddr, uint16_t NumByteToWrite)
{
-
+/*
if (_dev_spi) {
_dev_spi->lock();
_cs_pin = 0;
@@ -168,7 +173,7 @@
_dev_spi->unlock();
return MAGNETO_OK;
}
-
+*/
if (!_dev_i2c) return MAGNETO_ERROR;
int ret = _dev_i2c->i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite);
if(ret != 0) {
@@ -180,11 +185,11 @@
/*** Instance Variables ***/
/* IO Device */
DevI2C *_dev_i2c;
- SPI *_dev_spi;
+ //my SPI *_dev_spi;
uint8_t _address;
DigitalOut _cs_pin;
InterruptIn _int_pin;
- SPI_type_t _spi_type;
+ //my SPI_type_t _spi_type;
};
#endif // __LIS3MDL_CLASS_H