From 701f8c1be3ae9f2f1448217aa93a664e769ce015 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Wed, 17 May 2023 22:44:43 +0200 Subject: [PATCH 1/3] build system: fix `make compile-commands BUILD_IN_DOCKER=1` Just run `make compile-commands` outside of docker, as the compile commands generated in the docker container won't be helpful for tools outside of the container anyway. Fixes https://github.com/RIOT-OS/RIOT/issues/17507 --- Makefile.include | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile.include b/Makefile.include index 029aff0480..7534453b53 100644 --- a/Makefile.include +++ b/Makefile.include @@ -728,6 +728,15 @@ else _LINK = $(if $(CPPMIX),$(LINKXX),$(LINK)) $$(find $(BASELIBS:%.module=$(BINDIR)/%/) -name "*.o" 2> /dev/null | sort) $(ARCHIVES_GROUP) $(LINKFLAGS) $(LINKFLAGPREFIX)-Map=$(BINDIR)/$(APPLICATION).map endif # BUILDOSXNATIVE +COMPILE_COMMANDS_PATH ?= $(RIOTBASE)/compile_commands.json +COMPILE_COMMANDS_FLAGS ?= --clangd +.PHONY: compile-commands +compile-commands: $(BUILDDEPS) + $(Q)DIRS="$(DIRS)" APPLICATION_BLOBS="$(BLOBS)" \ + "$(MAKE)" -C $(APPDIR) -f $(RIOTMAKE)/application.inc.mk compile-commands + $(Q)$(RIOTTOOLS)/compile_commands/compile_commands.py $(COMPILE_COMMANDS_FLAGS) $(BINDIR) \ + > $(COMPILE_COMMANDS_PATH) + ifeq ($(BUILD_IN_DOCKER),1) link: ..in-docker-container else @@ -751,15 +760,6 @@ $(APPLICATION_MODULE).module: pkg-build $(BUILDDEPS) "$(MAKE)" -C $(APPDIR) -f $(RIOTMAKE)/application.inc.mk $(APPLICATION_MODULE).module: FORCE -COMPILE_COMMANDS_PATH ?= $(RIOTBASE)/compile_commands.json -COMPILE_COMMANDS_FLAGS ?= --clangd -.PHONY: compile-commands -compile-commands: $(BUILDDEPS) - $(Q)DIRS="$(DIRS)" APPLICATION_BLOBS="$(BLOBS)" \ - "$(MAKE)" -C $(APPDIR) -f $(RIOTMAKE)/application.inc.mk compile-commands - $(Q)$(RIOTTOOLS)/compile_commands/compile_commands.py $(COMPILE_COMMANDS_FLAGS) $(BINDIR) \ - > $(COMPILE_COMMANDS_PATH) - # Other modules are built by application.inc.mk and packages building _SUBMAKE_LIBS = $(filter-out $(APPLICATION_MODULE).module $(APPDEPS), $(BASELIBS) $(ARCHIVES)) $(_SUBMAKE_LIBS): $(APPLICATION_MODULE).module pkg-build From 533af18119d42d6255b6a3a6c562bfc354fff31a Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Tue, 23 May 2023 21:40:40 +0200 Subject: [PATCH 2/3] drivers/mpu9x50: clean up code Avoid using floating point arithmetic and some minor cleanups. --- drivers/mpu9x50/mpu9x50.c | 141 +++++++++++++++++--------------------- 1 file changed, 61 insertions(+), 80 deletions(-) diff --git a/drivers/mpu9x50/mpu9x50.c b/drivers/mpu9x50/mpu9x50.c index fcb9be2f83..6f6d1dbf86 100644 --- a/drivers/mpu9x50/mpu9x50.c +++ b/drivers/mpu9x50/mpu9x50.c @@ -236,28 +236,19 @@ int mpu9x50_set_compass_power(mpu9x50_t *dev, mpu9x50_pwr_t pwr_conf) return 0; } +static inline uint32_t gyro_fsr_enum_to_value(mpu9x50_gyro_ranges_t fsr) +{ + return 250U << fsr; +} + int mpu9x50_read_gyro(const mpu9x50_t *dev, mpu9x50_results_t *output) { uint8_t data[6]; int16_t temp; - float fsr; - switch (dev->conf.gyro_fsr) { - case MPU9X50_GYRO_FSR_250DPS: - fsr = 250.0; - break; - case MPU9X50_GYRO_FSR_500DPS: - fsr = 500.0; - break; - case MPU9X50_GYRO_FSR_1000DPS: - fsr = 1000.0; - break; - case MPU9X50_GYRO_FSR_2000DPS: - fsr = 2000.0; - break; - default: - return -2; - } + assert((unsigned)dev->conf.gyro_fsr <= (unsigned)MPU9X50_GYRO_FSR_2000DPS); + + uint32_t fsr = gyro_fsr_enum_to_value(dev->conf.gyro_fsr); /* Acquire exclusive access */ i2c_acquire(DEV_I2C); @@ -267,38 +258,29 @@ int mpu9x50_read_gyro(const mpu9x50_t *dev, mpu9x50_results_t *output) i2c_release(DEV_I2C); /* Normalize data according to configured full scale range */ - temp = (data[0] << 8) | data[1]; + temp = byteorder_lebuftohs(&data[0]); output->x_axis = (temp * fsr) / MAX_VALUE; - temp = (data[2] << 8) | data[3]; + temp = byteorder_lebuftohs(&data[2]); output->y_axis = (temp * fsr) / MAX_VALUE; - temp = (data[4] << 8) | data[5]; + temp = byteorder_lebuftohs(&data[4]); output->z_axis = (temp * fsr) / MAX_VALUE; return 0; } +static inline uint32_t accel_fsr_enum_to_value(mpu9x50_accel_ranges_t fsr) +{ + return 2000U << fsr; +} + int mpu9x50_read_accel(const mpu9x50_t *dev, mpu9x50_results_t *output) { uint8_t data[6]; int16_t temp; - float fsr; - switch (dev->conf.accel_fsr) { - case MPU9X50_ACCEL_FSR_2G: - fsr = 2000.0; - break; - case MPU9X50_ACCEL_FSR_4G: - fsr = 4000.0; - break; - case MPU9X50_ACCEL_FSR_8G: - fsr = 8000.0; - break; - case MPU9X50_ACCEL_FSR_16G: - fsr = 16000.0; - break; - default: - return -2; - } + assert((unsigned)dev->conf.accel_fsr <= (unsigned)MPU9X50_ACCEL_FSR_16G); + + uint32_t fsr = accel_fsr_enum_to_value(dev->conf.accel_fsr); /* Acquire exclusive access */ i2c_acquire(DEV_I2C); @@ -308,16 +290,25 @@ int mpu9x50_read_accel(const mpu9x50_t *dev, mpu9x50_results_t *output) i2c_release(DEV_I2C); /* Normalize data according to configured full scale range */ - temp = (data[0] << 8) | data[1]; + temp = byteorder_lebuftohs(&data[0]); output->x_axis = (temp * fsr) / MAX_VALUE; - temp = (data[2] << 8) | data[3]; + temp = byteorder_lebuftohs(&data[2]); output->y_axis = (temp * fsr) / MAX_VALUE; - temp = (data[4] << 8) | data[5]; + temp = byteorder_lebuftohs(&data[4]); output->z_axis = (temp * fsr) / MAX_VALUE; return 0; } +static int16_t convert_magnometer(int16_t raw, uint8_t adjust) +{ + int32_t tmp = raw; + /* Compute sensitivity adjustment */ + tmp += tmp * ((int32_t)adjust - 128) / 256; + /* return normalized data */ + return (tmp * 3) / 10; +} + int mpu9x50_read_compass(const mpu9x50_t *dev, mpu9x50_results_t *output) { uint8_t data[6]; @@ -329,22 +320,12 @@ int mpu9x50_read_compass(const mpu9x50_t *dev, mpu9x50_results_t *output) /* Release the bus */ i2c_release(DEV_I2C); - output->x_axis = (data[1] << 8) | data[0]; - output->y_axis = (data[3] << 8) | data[2]; - output->z_axis = (data[5] << 8) | data[4]; - - /* Compute sensitivity adjustment */ - output->x_axis = (int16_t) (((float)output->x_axis) * - ((((dev->conf.compass_x_adj - 128) * 0.5) / 128.0) + 1)); - output->y_axis = (int16_t) (((float)output->y_axis) * - ((((dev->conf.compass_y_adj - 128) * 0.5) / 128.0) + 1)); - output->z_axis = (int16_t) (((float)output->z_axis) * - ((((dev->conf.compass_z_adj - 128) * 0.5) / 128.0) + 1)); - - /* Normalize data according to full-scale range */ - output->x_axis = output->x_axis * 0.3; - output->y_axis = output->y_axis * 0.3; - output->z_axis = output->z_axis * 0.3; + output->x_axis = convert_magnometer(byteorder_lebuftohs(&data[0]), + dev->conf.compass_x_adj); + output->y_axis = convert_magnometer(byteorder_lebuftohs(&data[2]), + dev->conf.compass_y_adj); + output->z_axis = convert_magnometer(byteorder_lebuftohs(&data[4]), + dev->conf.compass_z_adj); return 0; } @@ -374,18 +355,18 @@ int mpu9x50_set_gyro_fsr(mpu9x50_t *dev, mpu9x50_gyro_ranges_t fsr) } switch (fsr) { - case MPU9X50_GYRO_FSR_250DPS: - case MPU9X50_GYRO_FSR_500DPS: - case MPU9X50_GYRO_FSR_1000DPS: - case MPU9X50_GYRO_FSR_2000DPS: - i2c_acquire(DEV_I2C); - i2c_write_reg(DEV_I2C, DEV_ADDR, - MPU9X50_GYRO_CFG_REG, (fsr << 3), 0); - i2c_release(DEV_I2C); - dev->conf.gyro_fsr = fsr; - break; - default: - return -2; + case MPU9X50_GYRO_FSR_250DPS: + case MPU9X50_GYRO_FSR_500DPS: + case MPU9X50_GYRO_FSR_1000DPS: + case MPU9X50_GYRO_FSR_2000DPS: + i2c_acquire(DEV_I2C); + i2c_write_reg(DEV_I2C, DEV_ADDR, + MPU9X50_GYRO_CFG_REG, (fsr << 3), 0); + i2c_release(DEV_I2C); + dev->conf.gyro_fsr = fsr; + break; + default: + return -2; } return 0; @@ -398,18 +379,18 @@ int mpu9x50_set_accel_fsr(mpu9x50_t *dev, mpu9x50_accel_ranges_t fsr) } switch (fsr) { - case MPU9X50_ACCEL_FSR_2G: - case MPU9X50_ACCEL_FSR_4G: - case MPU9X50_ACCEL_FSR_8G: - case MPU9X50_ACCEL_FSR_16G: - i2c_acquire(DEV_I2C); - i2c_write_reg(DEV_I2C, DEV_ADDR, - MPU9X50_ACCEL_CFG_REG, (fsr << 3), 0); - i2c_release(DEV_I2C); - dev->conf.accel_fsr = fsr; - break; - default: - return -2; + case MPU9X50_ACCEL_FSR_2G: + case MPU9X50_ACCEL_FSR_4G: + case MPU9X50_ACCEL_FSR_8G: + case MPU9X50_ACCEL_FSR_16G: + i2c_acquire(DEV_I2C); + i2c_write_reg(DEV_I2C, DEV_ADDR, + MPU9X50_ACCEL_CFG_REG, (fsr << 3), 0); + i2c_release(DEV_I2C); + dev->conf.accel_fsr = fsr; + break; + default: + return -2; } return 0; From d475c9769234aaf782c7012f75427a13e07995d6 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 4 May 2023 23:24:56 +0200 Subject: [PATCH 3/3] pkg/littlefs2: bump version to 2.6 This release bumps the on-disk minor version of littlefs from lfs2.0 -> lfs2.1. This change is backwards-compatible, but after the first write with the new version, the image on disk will no longer be mountable by older versions of littlefs. --- pkg/littlefs2/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/littlefs2/Makefile b/pkg/littlefs2/Makefile index 3f8d656b8a..1082097cd4 100644 --- a/pkg/littlefs2/Makefile +++ b/pkg/littlefs2/Makefile @@ -1,7 +1,7 @@ PKG_NAME=littlefs2 PKG_URL=https://github.com/ARMmbed/littlefs.git -# v2.5.1 -PKG_VERSION=6a53d76e90af33f0656333c1db09bd337fa75d23 +# v2.6 +PKG_VERSION=66f07563c333a6cfe25e51633ded6851568a0d49 PKG_LICENSE=Apache-2.0 include $(RIOTBASE)/pkg/pkg.mk