Merge pull request #2455 from openmv/drivers_lsm6dsm

drivers/lsm6dsm: Add LSM6DSM driver.
This commit is contained in:
Ibrahim Abdelkader 2024-10-16 09:45:50 +03:00 committed by GitHub
commit c8b4bd422c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 13134 additions and 957 deletions

View File

@ -57,6 +57,7 @@ MICROPY_DIR=micropython
GENX320_DIR=drivers/genx320
LEPTON_DIR=drivers/lepton
LSM6DS3_DIR=drivers/lsm6ds3
LSM6DSM_DIR=drivers/lsm6dsm
LSM6DSOX_DIR=drivers/lsm6dsox
WINC1500_DIR=drivers/winc1500
MLX90621_DIR=drivers/mlx90621

View File

@ -0,0 +1,29 @@
BSD 3-Clause License
Copyright (c) 2019, STMicroelectronics
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,42 @@
# SPDX-License-Identifier: MIT
#
# Copyright (C) 2013-2024 OpenMV, LLC.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ST Makefile
override CFLAGS += -Os
SRCS = $(wildcard src/*.c)
OBJS = $(addprefix $(BUILD)/, $(SRCS:.c=.o))
OBJ_DIRS = $(sort $(dir $(OBJS)))
all: | $(OBJ_DIRS) $(OBJS)
$(OBJ_DIRS):
$(MKDIR) -p $@
$(BUILD)/%.o : %.c
$(ECHO) "CC $<"
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD)/%.o : %.s
$(ECHO) "AS $<"
$(AS) $(AFLAGS) $< -o $@
-include $(OBJS:%.o=%.d)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -78,6 +78,7 @@ export CMSIS_DIR
export MICROPY_DIR
export LEPTON_DIR
export LSM6DS3_DIR
export LSM6DSM_DIR
export LSM6DSOX_DIR
export WINC1500_DIR
export MLX90621_DIR

View File

@ -58,6 +58,27 @@ typedef union {
#define lsm_from_fs2000_to_mdps lsm6ds3tr_c_from_fs2000dps_to_mdps
#define lsm_from_lsb_to_celsius lsm6ds3tr_c_from_lsb_to_celsius
#elif defined(OMV_IMU_CHIP_LSM6DSM)
#include "lsm6dsm_reg.h"
typedef union {
int16_t i16bit[3];
int16_t u8bit[3];
} axis3bit16_t;
typedef union {
int16_t i16bit;
int16_t u8bit[1];
} axis1bit16_t;
#define LSM_FUNC(f) lsm6dsm_##f
#define LSM_CONST(c) LSM6DSM_##c
#define lsm_from_fs8_to_mg lsm6dsm_from_fs8g_to_mg
#define lsm_from_fs8_to_mg lsm6dsm_from_fs8g_to_mg
#define lsm_from_fs2000_to_mdps lsm6dsm_from_fs2000dps_to_mdps
#define lsm_from_lsb_to_celsius lsm6dsm_from_lsb_to_celsius
#elif defined(OMV_IMU_CHIP_LSM6DSOX)
#include "lsm6dsox_reg.h"
@ -109,7 +130,7 @@ static void platform_deinit(void *imubus) {
imu_initialized = false;
}
static int32_t platform_write(void *imubus, uint8_t Reg, uint8_t *Bufp, uint16_t len) {
static int32_t platform_write(void *imubus, uint8_t Reg, const uint8_t *Bufp, uint16_t len) {
omv_spi_t *spi_bus = imubus;
omv_spi_transfer_t spi_xfer = {
@ -120,14 +141,13 @@ static int32_t platform_write(void *imubus, uint8_t Reg, uint8_t *Bufp, uint16_t
};
omv_gpio_write(spi_bus->cs, 0);
spi_xfer.size = 1;
spi_xfer.txbuf = &Reg;
spi_xfer.rxbuf = NULL;
omv_spi_transfer_start(spi_bus, &spi_xfer);
spi_xfer.size = len;
spi_xfer.txbuf = Bufp;
spi_xfer.txbuf = (uint8_t *) Bufp;
spi_xfer.rxbuf = NULL;
omv_spi_transfer_start(spi_bus, &spi_xfer);
@ -172,11 +192,11 @@ static void platform_deinit(void *imubus) {
imu_initialized = false;
}
static int32_t platform_write(void *imubus, uint8_t reg, uint8_t *bufp, uint16_t len) {
static int32_t platform_write(void *imubus, uint8_t reg, const uint8_t *bufp, uint16_t len) {
if (omv_i2c_write_bytes(&imu_bus, LSM6DS3TR_C_I2C_ADD_L, (uint8_t *) &reg, 1, OMV_I2C_XFER_SUSPEND) != 0) {
return -1;
}
if (omv_i2c_write_bytes(&imu_bus, LSM6DS3TR_C_I2C_ADD_L, bufp, len, OMV_I2C_XFER_NO_FLAGS) != 0) {
if (omv_i2c_write_bytes(&imu_bus, LSM6DS3TR_C_I2C_ADD_L, (uint8_t *) bufp, len, OMV_I2C_XFER_NO_FLAGS) != 0) {
return -1;
}
return 0;
@ -293,6 +313,7 @@ static float py_imu_get_pitch() {
#endif
return IM_RAD2DEG(fast_atan2f(zr, -yr));
}
void py_imu_init();
static mp_obj_t py_imu_acceleration_mg() {
error_on_not_ready();
@ -395,6 +416,7 @@ void py_imu_init() {
// Try to read device id...
for (int i = 0; (i < 10) && (whoamI != LSM_CONST(ID)); i++) {
LSM_FUNC(device_id_get) (&dev_ctx, &whoamI);
mp_event_wait_ms(1);
}
if (whoamI != LSM_CONST(ID)) {