Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sensirion_i2c_hal_init: add parameter to specify the device path #8

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion sen5x_i2c_example_usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 2 additions & 8 deletions sensirion_i2c_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@
#include <sys/ioctl.h>
#include <unistd.h>

/**
* 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
Expand All @@ -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 */
}
Expand Down
2 changes: 1 addition & 1 deletion sensirion_i2c_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down