From 7aac1f4ece4f263aae600608a2e4bcb1828011d4 Mon Sep 17 00:00:00 2001 From: Matthias Klein Date: Wed, 26 Jun 2024 15:22:52 +0200 Subject: [PATCH] sensirion_i2c_hal_init: add parameter to specify the device path --- sen5x_i2c_example_usage.c | 8 +++++++- sensirion_i2c_hal.c | 10 ++-------- sensirion_i2c_hal.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sen5x_i2c_example_usage.c b/sen5x_i2c_example_usage.c index ec72e06..095d235 100644 --- a/sen5x_i2c_example_usage.c +++ b/sen5x_i2c_example_usage.c @@ -47,10 +47,16 @@ * #define printf(...) */ +/** + * Linux specific configuration. Adjust the following define to the device path + * of your sensor. + */ +#define I2C_DEVICE_PATH "/dev/i2c-1" + int main(void) { int16_t error = 0; - sensirion_i2c_hal_init(); + sensirion_i2c_hal_init(I2C_DEVICE_PATH); error = sen5x_device_reset(); if (error) { diff --git a/sensirion_i2c_hal.c b/sensirion_i2c_hal.c index d55ecc8..44c9e40 100644 --- a/sensirion_i2c_hal.c +++ b/sensirion_i2c_hal.c @@ -41,12 +41,6 @@ #include #include -/** - * Linux specific configuration. Adjust the following define to the device path - * of your sensor. - */ -#define I2C_DEVICE_PATH "/dev/i2c-1" - /** * The following define was taken from i2c-dev.h. Alternatively the header file * can be included. The define was added in Linux v3.10 and never changed since @@ -64,9 +58,9 @@ static uint8_t i2c_address = 0; * Initialize all hard- and software components that are needed for the I2C * communication. */ -void sensirion_i2c_hal_init(void) { +void sensirion_i2c_hal_init(const char* device_path) { /* open i2c adapter */ - i2c_device = open(I2C_DEVICE_PATH, O_RDWR); + i2c_device = open(device_path, O_RDWR); if (i2c_device == -1) return; /* no error handling */ } diff --git a/sensirion_i2c_hal.h b/sensirion_i2c_hal.h index f97444a..d6b9c7c 100644 --- a/sensirion_i2c_hal.h +++ b/sensirion_i2c_hal.h @@ -54,7 +54,7 @@ int16_t sensirion_i2c_hal_select_bus(uint8_t bus_idx); * Initialize all hard- and software components that are needed for the I2C * communication. */ -void sensirion_i2c_hal_init(void); +void sensirion_i2c_hal_init(const char* device_path); /** * Release all resources initialized by sensirion_i2c_hal_init().