Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Revision 7:c9c9ed520566, committed 2021-09-27
- Comitter:
- docent
- Date:
- Mon Sep 27 05:10:52 2021 +0000
- Parent:
- 6:308889c4d074
- Commit message:
- AGV_RKP
Changed in this revision
--- a/ST_INTERFACES.lib Wed Oct 18 11:14:26 2017 +0200 +++ b/ST_INTERFACES.lib Mon Sep 27 05:10:52 2021 +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 Mon Sep 27 05:10:52 2021 +0000
@@ -128,7 +128,8 @@
*/
#define LIS3MDL_M_CTRL_REG3_M 0x22
-
+#define LIS3MDL_M_CTRL_REG5_M 0x24 //my
+#define LIS3MDL_M_STATUS_REG_M 0x27 //my
/**
* @brief Magnetic sensor data (LSB)
* \code
@@ -137,7 +138,6 @@
*/
#define LIS3MDL_M_OUT_X_L_M 0x28
-
/**
* @brief Magnetic sensor data (MSB)
* \code
@@ -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 Mon Sep 27 05:10:52 2021 +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
@@ -90,8 +90,8 @@
{
uint8_t tmp1 = 0x00;
MAGNETO_InitTypeDef *initStructure = LIS3MDL_Init;
- MAGNETO_InitTypeDef tempInit;
-
+ MAGNETO_InitTypeDef tempInit;
+
if (initStructure == NULL) {// default params
tempInit.M_FullScale = LIS3MDL_M_FS_4;
tempInit.M_OperatingMode = LIS3MDL_M_MD_CONTINUOUS;
@@ -155,6 +155,8 @@
return MAGNETO_ERROR;
}
+ //set_BDU();//my
+
/* Configure interrupt lines */
LIS3MDL_IO_ITConfig();
@@ -203,7 +205,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)
@@ -216,6 +218,24 @@
return MAGNETO_OK;
}
+//my----------------------------------------------------------------------------
+MAGNETO_StatusTypeDef LIS3MDL::LIS3MDL_M_SetAxeOffset(uint8_t axe,int16_t offset)
+{
+ uint8_t tmp[2];
+ tmp[0]=offset;
+ tmp[1]=offset>>8;
+ if(LIS3MDL_IO_Write(tmp, 5+2*axe, 2)!= MAGNETO_OK)
+ return MAGNETO_ERROR;
+ else
+ return MAGNETO_OK;
+/*
+ tmp=offset>>8;
+ if(LIS3MDL_IO_Write(&tmp, 6+2*axe, 1)!= MAGNETO_OK)
+ return MAGNETO_ERROR;
+ return MAGNETO_OK;
+*/
+}
+
/**
* @brief Read data from LIS3MDL Magnetic sensor and calculate Magnetic in mgauss
@@ -232,7 +252,7 @@
{
return MAGNETO_ERROR;
}
-
+
if(LIS3MDL_IO_Read(&tempReg, LIS3MDL_M_CTRL_REG2_M, 1) != MAGNETO_OK)
{
return MAGNETO_ERROR;
@@ -259,7 +279,7 @@
pData[0] = (int32_t)(pDataRaw[0] * sensitivity);
pData[1] = (int32_t)(pDataRaw[1] * sensitivity);
pData[2] = (int32_t)(pDataRaw[2] * sensitivity);
-
+
return MAGNETO_OK;
}
--- a/lis3mdl_class.h Wed Oct 18 11:14:26 2017 +0200
+++ b/lis3mdl_class.h Mon Sep 27 05:10:52 2021 +0000
@@ -51,8 +51,10 @@
*/
class LIS3MDL : public MagneticSensor {
public:
- enum SPI_type_t {SPI3W, SPI4W};
+ //my
+ enum SPI_type_t {SPI3W, SPI4W};
+ //my
LIS3MDL(SPI *spi, PinName cs_pin, PinName int_pin=NC, SPI_type_t spi_type=SPI4W);
/** Constructor
@@ -81,15 +83,26 @@
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);
+ }
+ virtual int set_BDU() { //my
+ uint8_t tmp;
+ if(LIS3MDL_IO_Read(&tmp, LIS3MDL_M_CTRL_REG5_M, 1) != MAGNETO_OK)
+ return MAGNETO_ERROR;
+ tmp=0x40;
+ return LIS3MDL_IO_Write(&tmp, LIS3MDL_M_CTRL_REG5_M, 1);
+ }
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);
+ //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 +131,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 +142,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 +173,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 +183,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,10 +195,12 @@
/*** Instance Variables ***/
/* IO Device */
DevI2C *_dev_i2c;
+ //my
SPI *_dev_spi;
uint8_t _address;
DigitalOut _cs_pin;
InterruptIn _int_pin;
+ //my
SPI_type_t _spi_type;
};