Update latest
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Diff: lis3mdl_class.cpp
- Revision:
- 4:00493226e59f
- Parent:
- 1:d85092ab306e
- Child:
- 6:308889c4d074
--- a/lis3mdl_class.cpp Mon Oct 02 09:28:58 2017 +0200 +++ b/lis3mdl_class.cpp Fri Oct 06 11:48:36 2017 +0000 @@ -45,6 +45,42 @@ X-CUBE-MEMS1/trunk: revision #416 */ +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) +{ + assert (spi); + if (cs_pin == NC) + { + printf ("ERROR LIS3MDL CS MUST NOT BE NC\n\r"); + _dev_spi = NULL; + _dev_i2c=NULL; + return; + } + + _cs_pin = 0; + _dev_i2c=NULL; + + 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; +} + + +MAGNETO_StatusTypeDef LIS3MDL::LIS3MDL_Set_SpiInterface (void *handle, LIS3MDL_SPIMode_t spimode) +{ + uint8_t tmp=0x03; //deft LIS3MDL_CTRL_REG3 value + + tmp |= (uint8_t)spimode; + 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