summaryrefslogtreecommitdiffstats
path: root/libsensors_iio/software/core/mllite/linux
diff options
context:
space:
mode:
Diffstat (limited to 'libsensors_iio/software/core/mllite/linux')
-rw-r--r--libsensors_iio/software/core/mllite/linux/inv_sysfs_utils.c318
-rw-r--r--libsensors_iio/software/core/mllite/linux/inv_sysfs_utils.h84
-rw-r--r--libsensors_iio/software/core/mllite/linux/ml_load_dmp.c62
-rw-r--r--libsensors_iio/software/core/mllite/linux/ml_stored_data.c53
-rw-r--r--libsensors_iio/software/core/mllite/linux/ml_stored_data.h2
-rw-r--r--libsensors_iio/software/core/mllite/linux/ml_sysfs_helper.c13
-rw-r--r--libsensors_iio/software/core/mllite/linux/ml_sysfs_helper.h4
-rw-r--r--libsensors_iio/software/core/mllite/linux/mlos_linux.c4
8 files changed, 70 insertions, 470 deletions
diff --git a/libsensors_iio/software/core/mllite/linux/inv_sysfs_utils.c b/libsensors_iio/software/core/mllite/linux/inv_sysfs_utils.c
deleted file mode 100644
index 649b917..0000000
--- a/libsensors_iio/software/core/mllite/linux/inv_sysfs_utils.c
+++ /dev/null
@@ -1,318 +0,0 @@
-/**
- * @brief Provides helpful file IO wrappers for use with sysfs.
- * @details Based on Jonathan Cameron's @e iio_utils.h.
- */
-
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <dirent.h>
-#include <errno.h>
-#include <unistd.h>
-#include "inv_sysfs_utils.h"
-
-/* General TODO list:
- * Select more reasonable string lengths or use fseek and malloc.
- */
-
-/**
- * inv_sysfs_write() - Write an integer to a file.
- * @filename: Path to file.
- * @data: Value to write to file.
- * Returns number of bytes written or a negative error code.
- */
-int inv_sysfs_write(char *filename, long data)
-{
- FILE *fp;
- int count;
-
- if (!filename)
- return -1;
- fp = fopen(filename, "w");
- if (!fp)
- return -errno;
- count = fprintf(fp, "%ld", data);
- fclose(fp);
- return count;
-}
-
-/**
- * inv_sysfs_read() - Read a string from a file.
- * @filename: Path to file.
- * @num_bytes: Number of bytes to read.
- * @data: Data from file.
- * Returns number of bytes written or a negative error code.
- */
-int inv_sysfs_read(char *filename, long num_bytes, char *data)
-{
- FILE *fp;
- int count;
-
- if (!filename)
- return -1;
- fp = fopen(filename, "r");
- if (!fp)
- return -errno;
- count = fread(data, 1, num_bytes, fp);
- fclose(fp);
- return count;
-}
-
-/**
- * inv_read_buffer() - Read data from ring buffer.
- * @fd: File descriptor for buffer file.
- * @data: Data in hardware units.
- * @timestamp: Time when data was read from device. Use NULL if unsupported.
- * Returns number of bytes written or a negative error code.
- */
-int inv_read_buffer(int fd, long *data, long long *timestamp)
-{
- char str[35];
- int count;
-
- count = read(fd, str, sizeof(str));
- if (!count)
- return count;
- if (!timestamp)
- count = sscanf(str, "%ld%ld%ld", &data[0], &data[1], &data[2]);
- else
- count = sscanf(str, "%ld%ld%ld%lld", &data[0], &data[1],
- &data[2], timestamp);
-
- if (count < (timestamp?4:3))
- return -EAGAIN;
- return count;
-}
-
-/**
- * inv_read_raw() - Read raw data.
- * @names: Names of sysfs files.
- * @data: Data in hardware units.
- * @timestamp: Time when data was read from device. Use NULL if unsupported.
- * Returns number of bytes written or a negative error code.
- */
-int inv_read_raw(const struct inv_sysfs_names_s *names, long *data,
- long long *timestamp)
-{
- char str[40];
- int count;
-
- count = inv_sysfs_read((char*)names->raw_data, sizeof(str), str);
- if (count < 0)
- return count;
- if (!timestamp)
- count = sscanf(str, "%ld%ld%ld", &data[0], &data[1], &data[2]);
- else
- count = sscanf(str, "%ld%ld%ld%lld", &data[0], &data[1],
- &data[2], timestamp);
- if (count < (timestamp?4:3))
- return -EAGAIN;
- return count;
-}
-
-/**
- * inv_read_temperature_raw() - Read temperature.
- * @names: Names of sysfs files.
- * @data: Data in hardware units.
- * @timestamp: Time when data was read from device.
- * Returns number of bytes written or a negative error code.
- */
-int inv_read_temperature_raw(const struct inv_sysfs_names_s *names, short *data,
- long long *timestamp)
-{
- char str[25];
- int count;
-
- count = inv_sysfs_read((char*)names->temperature, sizeof(str), str);
- if (count < 0)
- return count;
- count = sscanf(str, "%hd%lld", &data[0], timestamp);
- if (count < 2)
- return -EAGAIN;
- return count;
-}
-
-/**
- * inv_read_fifo_rate() - Read fifo rate.
- * @names: Names of sysfs files.
- * @data: Fifo rate.
- * Returns number of bytes written or a negative error code.
- */
-int inv_read_fifo_rate(const struct inv_sysfs_names_s *names, short *data)
-{
- char str[8];
- int count;
-
- count = inv_sysfs_read((char*)names->fifo_rate, sizeof(str), str);
- if (count < 0)
- return count;
- count = sscanf(str, "%hd", data);
- if (count < 1)
- return -EAGAIN;
- return count;
-}
-
-/**
- * inv_read_power_state() - Read power state.
- * @names: Names of sysfs files.
- * @data: 1 if device is on.
- * Returns number of bytes written or a negative error code.
- */
-int inv_read_power_state(const struct inv_sysfs_names_s *names, char *data)
-{
- char str[2];
- int count;
-
- count = inv_sysfs_read((char*)names->power_state, sizeof(str), str);
- if (count < 0)
- return count;
- count = sscanf(str, "%hd", (short*)data);
- if (count < 1)
- return -EAGAIN;
- return count;
-}
-
-/**
- * inv_read_scale() - Read scale.
- * @names: Names of sysfs files.
- * @data: 1 if device is on.
- * Returns number of bytes written or a negative error code.
- */
-int inv_read_scale(const struct inv_sysfs_names_s *names, float *data)
-{
- char str[5];
- int count;
-
- count = inv_sysfs_read((char*)names->scale, sizeof(str), str);
- if (count < 0)
- return count;
- count = sscanf(str, "%f", data);
- if (count < 1)
- return -EAGAIN;
- return count;
-}
-
-/**
- * inv_read_temp_scale() - Read temperature scale.
- * @names: Names of sysfs files.
- * @data: 1 if device is on.
- * Returns number of bytes written or a negative error code.
- */
-int inv_read_temp_scale(const struct inv_sysfs_names_s *names, short *data)
-{
- char str[4];
- int count;
-
- count = inv_sysfs_read((char*)names->temp_scale, sizeof(str), str);
- if (count < 0)
- return count;
- count = sscanf(str, "%hd", data);
- if (count < 1)
- return -EAGAIN;
- return count;
-}
-
-/**
- * inv_read_temp_offset() - Read temperature offset.
- * @names: Names of sysfs files.
- * @data: 1 if device is on.
- * Returns number of bytes written or a negative error code.
- */
-int inv_read_temp_offset(const struct inv_sysfs_names_s *names, short *data)
-{
- char str[4];
- int count;
-
- count = inv_sysfs_read((char*)names->temp_offset, sizeof(str), str);
- if (count < 0)
- return count;
- count = sscanf(str, "%hd", data);
- if (count < 1)
- return -EAGAIN;
- return count;
-}
-
-/**
- * inv_read_q16() - Get data as q16 fixed point.
- * @names: Names of sysfs files.
- * @data: 1 if device is on.
- * @timestamp: Time when data was read from device.
- * Returns number of bytes written or a negative error code.
- */
-int inv_read_q16(const struct inv_sysfs_names_s *names, long *data,
- long long *timestamp)
-{
- int count;
- short raw[3];
- float scale;
- count = inv_read_raw(names, (long*)raw, timestamp);
- count += inv_read_scale(names, &scale);
- data[0] = (long)(raw[0] * (65536.f / scale));
- data[1] = (long)(raw[1] * (65536.f / scale));
- data[2] = (long)(raw[2] * (65536.f / scale));
- return count;
-}
-
-/**
- * inv_read_q16() - Get temperature data as q16 fixed point.
- * @names: Names of sysfs files.
- * @data: 1 if device is on.
- * @timestamp: Time when data was read from device.
- * Returns number of bytes read or a negative error code.
- */
-int inv_read_temp_q16(const struct inv_sysfs_names_s *names, long *data,
- long long *timestamp)
-{
- int count = 0;
- short raw;
- static short scale, offset;
- static unsigned char first_read = 1;
-
- if (first_read) {
- count += inv_read_temp_scale(names, &scale);
- count += inv_read_temp_offset(names, &offset);
- first_read = 0;
- }
- count += inv_read_temperature_raw(names, &raw, timestamp);
- data[0] = (long)((35 + ((float)(raw - offset) / scale)) * 65536.f);
-
- return count;
-}
-
-/**
- * inv_write_fifo_rate() - Write fifo rate.
- * @names: Names of sysfs files.
- * @data: Fifo rate.
- * Returns number of bytes written or a negative error code.
- */
-int inv_write_fifo_rate(const struct inv_sysfs_names_s *names, short data)
-{
- return inv_sysfs_write((char*)names->fifo_rate, (long)data);
-}
-
-/**
- * inv_write_buffer_enable() - Enable/disable buffer in /dev.
- * @names: Names of sysfs files.
- * @data: Fifo rate.
- * Returns number of bytes written or a negative error code.
- */
-int inv_write_buffer_enable(const struct inv_sysfs_names_s *names, char data)
-{
- return inv_sysfs_write((char*)names->enable, (long)data);
-}
-
-/**
- * inv_write_power_state() - Turn device on/off.
- * @names: Names of sysfs files.
- * @data: 1 to turn on.
- * Returns number of bytes written or a negative error code.
- */
-int inv_write_power_state(const struct inv_sysfs_names_s *names, char data)
-{
- return inv_sysfs_write((char*)names->power_state, (long)data);
-}
-
-
-
diff --git a/libsensors_iio/software/core/mllite/linux/inv_sysfs_utils.h b/libsensors_iio/software/core/mllite/linux/inv_sysfs_utils.h
deleted file mode 100644
index 45a35f9..0000000
--- a/libsensors_iio/software/core/mllite/linux/inv_sysfs_utils.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * @brief Provides helpful file IO wrappers for use with sysfs.
- * @details Based on Jonathan Cameron's @e iio_utils.h.
- */
-
-#ifndef _INV_SYSFS_UTILS_H_
-#define _INV_SYSFS_UTILS_H_
-
-/**
- * struct inv_sysfs_names_s - Files needed by user applications.
- * @buffer: Ring buffer attached to FIFO.
- * @enable: Turns on HW-to-ring buffer flow.
- * @raw_data: Raw data from registers.
- * @temperature: Temperature data from register.
- * @fifo_rate: FIFO rate/ODR.
- * @power_state: Power state (this is a five-star comment).
- * @fsr: Full-scale range.
- * @lpf: Digital low pass filter.
- * @scale: LSBs / dps (or LSBs / Gs).
- * @temp_scale: LSBs / degrees C.
- * @temp_offset: Offset in LSBs.
- */
-struct inv_sysfs_names_s {
-
- //Sysfs for ITG3500 & MPU6050
- const char *buffer;
- const char *enable;
- const char *raw_data; //Raw Gyro data
- const char *temperature;
- const char *fifo_rate;
- const char *power_state;
- const char *fsr;
- const char *lpf;
- const char *scale; //Gyro scale
- const char *temp_scale;
- const char *temp_offset;
- const char *self_test;
- //Starting Sysfs available for MPU6050 only
- const char *accel_en;
- const char *accel_fifo_en;
- const char *accel_fs;
- const char *clock_source;
- const char *early_suspend_en;
- const char *firmware_loaded;
- const char *gyro_en;
- const char *gyro_fifo_en;
- const char *key;
- const char *raw_accel;
- const char *reg_dump;
- const char *tap_on;
- const char *dmp_firmware;
-};
-
-/* File IO. Typically won't be called directly by user application, but they'll
- * be here for your enjoyment.
- */
-int inv_sysfs_write(char *filename, long data);
-int inv_sysfs_read(char *filename, long num_bytes, char *data);
-
-/* Helper APIs to extract specific data. */
-int inv_read_buffer(int fd, long *data, long long *timestamp);
-int inv_read_raw(const struct inv_sysfs_names_s *names, long *data,
- long long *timestamp);
-int inv_read_temperature_raw(const struct inv_sysfs_names_s *names, short *data,
- long long *timestamp);
-int inv_read_fifo_rate(const struct inv_sysfs_names_s *names, short *data);
-int inv_read_power_state(const struct inv_sysfs_names_s *names, char *data);
-int inv_read_scale(const struct inv_sysfs_names_s *names, float *data);
-int inv_read_temp_scale(const struct inv_sysfs_names_s *names, short *data);
-int inv_read_temp_offset(const struct inv_sysfs_names_s *names, short *data);
-int inv_write_fifo_rate(const struct inv_sysfs_names_s *names, short data);
-int inv_write_buffer_enable(const struct inv_sysfs_names_s *names, char data);
-int inv_write_power_state(const struct inv_sysfs_names_s *names, char data);
-
-/* Scaled data. */
-int inv_read_q16(const struct inv_sysfs_names_s *names, long *data,
- long long *timestamp);
-int inv_read_temp_q16(const struct inv_sysfs_names_s *names, long *data,
- long long *timestamp);
-
-
-#endif /* #ifndef _INV_SYSFS_UTILS_H_ */
-
-
diff --git a/libsensors_iio/software/core/mllite/linux/ml_load_dmp.c b/libsensors_iio/software/core/mllite/linux/ml_load_dmp.c
index f0f078c..91c766b 100644
--- a/libsensors_iio/software/core/mllite/linux/ml_load_dmp.c
+++ b/libsensors_iio/software/core/mllite/linux/ml_load_dmp.c
@@ -30,10 +30,10 @@
#define LOADDMP_LOG MPL_LOGI
#define NUM_LOCAL_KEYS (sizeof(dmpTConfig)/sizeof(dmpTConfig[0]))
-#define DMP_CODE_SIZE 3060
+#define DMP_CODE_SIZE 3065
static const unsigned char dmpMemory[DMP_CODE_SIZE] = {
- /* bank # 0 */
+ /* bank # 0 */
0x00,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, 0xa9, 0x80, 0xda, 0x3c, 0xd8, 0xa8, 0x2e, 0xa8, 0x39, 0x90, 0xd9, 0x0c, 0xd8, 0xa8, 0x95,
+ 0x31, 0x98, 0xd9, 0x0c, 0xd8, 0xa8, 0x09, 0xd9, 0xff, 0xd8, 0x01, 0xda, 0xff, 0xd8, 0x95, 0x39,
+ 0xa9, 0xda, 0x26, 0xff, 0xd8, 0x90, 0xa8, 0x0d, 0x89, 0x99, 0xa8, 0x10, 0x80, 0x98, 0x21, 0xda,
+ 0x2e, 0xd8, 0x89, 0x99, 0xa8, 0x31, 0x80, 0xda, 0x2e, 0xd8, 0xa8, 0x86, 0x96, 0x31, 0x80, 0xda,
+ 0x2e, 0xd8, 0xa8, 0x87, 0x31, 0x80, 0xda, 0x2e, 0xd8, 0xa8, 0x82, 0x92, 0xf3, 0x41, 0x80, 0xf1,
+ 0xd9, 0x2e, 0xd8, 0xa8, 0x82, 0xf3, 0x19, 0x80, 0xf1, 0xd9, 0x2e, 0xd8, 0x82, 0xac, 0xf3, 0xc0,
+ 0xa2, 0x80, 0x22, 0xf1, 0xa6, 0x2e, 0xa7, 0x2e, 0xa9, 0x22, 0x98, 0xa8, 0x29, 0xda, 0xac, 0xde,
+ 0xff, 0xd8, 0xa2, 0xf2, 0x2a, 0xf1, 0xa9, 0x2e, 0x82, 0x92, 0xa8, 0xf2, 0x31, 0x80, 0xa6, 0x96,
+ 0xf1, 0xd9, 0x00, 0xac, 0x8c, 0x9c, 0x0c, 0x30, 0xac, 0xde, 0xd0, 0xde, 0xff, 0xd8, 0x8c, 0x9c,
+ 0xac, 0xd0, 0x10, 0xac, 0xde, 0x80, 0x92, 0xa2, 0xf2, 0x4c, 0x82, 0xa8, 0xf1, 0xca, 0xf2, 0x35,
+ 0xf1, 0x96, 0x88, 0xa6, 0xd9, 0x00, 0xd8, 0xf1, 0xff
};
#define DMP_VERSION (dmpMemory)
@@ -250,11 +250,10 @@ inv_error_t inv_write_dmp_data(FILE *fd, const unsigned char *dmp, size_t len)
if (len <= 0) {
MPL_LOGE("Nothing to write");
return INV_ERROR_FILE_WRITE;
- }
- else {
+ } else {
MPL_LOGI("dmp firmware size to write = %d", len);
}
- if ( fd == NULL ) {
+ if (fd == NULL) {
return INV_ERROR_FILE_OPEN;
}
bytesWritten = fwrite(dmp, 1, len, fd);
@@ -262,8 +261,7 @@ inv_error_t inv_write_dmp_data(FILE *fd, const unsigned char *dmp, size_t len)
MPL_LOGE("bytes written (%d) don't match requested length (%d)\n",
bytesWritten, len);
result = INV_ERROR_FILE_WRITE;
- }
- else {
+ } else {
MPL_LOGI("Bytes written = %d", bytesWritten);
}
return result;
diff --git a/libsensors_iio/software/core/mllite/linux/ml_stored_data.c b/libsensors_iio/software/core/mllite/linux/ml_stored_data.c
index c5cf2e6..24b3217 100644
--- a/libsensors_iio/software/core/mllite/linux/ml_stored_data.c
+++ b/libsensors_iio/software/core/mllite/linux/ml_stored_data.c
@@ -38,26 +38,40 @@
#define STORECAL_LOG MPL_LOGI
#define LOADCAL_LOG MPL_LOGI
-inv_error_t inv_read_cal(unsigned char *cal, size_t len)
+inv_error_t inv_read_cal(unsigned char **calData, size_t *bytesRead)
{
FILE *fp;
- int bytesRead;
inv_error_t result = INV_SUCCESS;
+ size_t fsize;
fp = fopen(MLCAL_FILE,"rb");
if (fp == NULL) {
MPL_LOGE("Cannot open file \"%s\" for read\n", MLCAL_FILE);
return INV_ERROR_FILE_OPEN;
}
- bytesRead = fread(cal, 1, len, fp);
- if (bytesRead != len) {
- MPL_LOGE("bytes read (%d) don't match requested length (%d)\n",
- bytesRead, len);
+
+ // obtain file size
+ fseek (fp, 0 , SEEK_END);
+ fsize = ftell (fp);
+ rewind (fp);
+
+ *calData = (unsigned char *)inv_malloc(fsize);
+ if (*calData==NULL) {
+ MPL_LOGE("Could not allocate buffer of %d bytes - "
+ "aborting\n", fsize);
+ fclose(fp);
+ return INV_ERROR_MEMORY_EXAUSTED;
+ }
+
+ *bytesRead = fread(*calData, 1, fsize, fp);
+ if (*bytesRead != fsize) {
+ MPL_LOGE("bytes read (%d) don't match file size (%d)\n",
+ *bytesRead, fsize);
result = INV_ERROR_FILE_READ;
goto read_cal_end;
}
else {
- MPL_LOGI("Bytes read = %d", bytesRead);
+ MPL_LOGI("Bytes read = %d", *bytesRead);
}
read_cal_end:
@@ -261,31 +275,18 @@ inv_error_t inv_store_cal(unsigned char *calData, size_t length)
*/
inv_error_t inv_load_calibration(void)
{
- unsigned char *calData;
+ unsigned char *calData= NULL;
inv_error_t result = 0;
- size_t length;
-
- inv_get_mpl_state_size(&length);
- if (length <= 0) {
- MPL_LOGE("Could not get file calibration length - "
- "error %d - aborting\n", result);
- return result;
- }
+ size_t bytesRead = 0;
- calData = (unsigned char *)inv_malloc(length);
- if (!calData) {
- MPL_LOGE("Could not allocate buffer of %d bytes - "
- "aborting\n", length);
- return INV_ERROR_MEMORY_EXAUSTED;
- }
-
- result = inv_read_cal(calData, length);
+ result = inv_read_cal(&calData, &bytesRead);
if(result != INV_SUCCESS) {
MPL_LOGE("Could not load cal file - "
"aborting\n");
+ goto free_mem_n_exit;
}
- result = inv_load_mpl_states(calData, length);
+ result = inv_load_mpl_states(calData, bytesRead);
if (result != INV_SUCCESS) {
MPL_LOGE("Could not load the calibration data - "
"error %d - aborting\n", result);
@@ -294,7 +295,7 @@ inv_error_t inv_load_calibration(void)
free_mem_n_exit:
inv_free(calData);
- return INV_SUCCESS;
+ return result;
}
/**
diff --git a/libsensors_iio/software/core/mllite/linux/ml_stored_data.h b/libsensors_iio/software/core/mllite/linux/ml_stored_data.h
index 336f081..115b34c 100644
--- a/libsensors_iio/software/core/mllite/linux/ml_stored_data.h
+++ b/libsensors_iio/software/core/mllite/linux/ml_stored_data.h
@@ -36,7 +36,7 @@ inv_error_t inv_store_calibration(void);
/*
Internal APIs
*/
-inv_error_t inv_read_cal(unsigned char *cal, size_t len);
+inv_error_t inv_read_cal(unsigned char **, size_t *);
inv_error_t inv_write_cal(unsigned char *cal, size_t len);
inv_error_t inv_load_cal_V0(unsigned char *calData, size_t len);
inv_error_t inv_load_cal_V1(unsigned char *calData, size_t len);
diff --git a/libsensors_iio/software/core/mllite/linux/ml_sysfs_helper.c b/libsensors_iio/software/core/mllite/linux/ml_sysfs_helper.c
index 5636a02..a12a4ed 100644
--- a/libsensors_iio/software/core/mllite/linux/ml_sysfs_helper.c
+++ b/libsensors_iio/software/core/mllite/linux/ml_sysfs_helper.c
@@ -5,7 +5,6 @@
#include <ctype.h>
#define MPU_SYSFS_ABS_PATH "/sys/class/invensense/mpu"
-#define CHIP_NUM 4
enum PROC_SYSFS_CMD {
CMD_GET_SYSFS_PATH,
CMD_GET_DMP_PATH,
@@ -15,7 +14,7 @@ enum PROC_SYSFS_CMD {
CMD_GET_DEVICE_NODE
};
static char sysfs_path[100];
-static char *chip_name[CHIP_NUM] = {"ITG3500", "MPU6050", "MPU9150", "MPU3050"};
+static char *chip_name[] = {"ITG3500", "MPU6050", "MPU9150", "MPU3050", "MPU6500"};
static int chip_ind;
static int initialized =0;
static int status = 0;
@@ -27,6 +26,8 @@ static int iio_dev_num = 0;
#define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements"
#define FORMAT_TYPE_FILE "%s_type"
+#define CHIP_NUM sizeof(chip_name)/sizeof(char*)
+
static const char *iio_dir = "/sys/bus/iio/devices/";
/**
@@ -392,9 +393,9 @@ inv_error_t inv_get_input_number(const char *name, int *num)
* name. It should be zeroed before calling this function.
* Or it could have unpredicable result.
*/
-inv_error_t inv_get_iio_trigger_path(const char *name)
+inv_error_t inv_get_iio_trigger_path(char *name)
{
- if (process_sysfs_request(CMD_GET_TRIGGER_PATH, name) < 0)
+ if (process_sysfs_request(CMD_GET_TRIGGER_PATH, (char *)name) < 0)
return INV_ERROR_NOT_OPENED;
else
return INV_SUCCESS;
@@ -407,9 +408,9 @@ inv_error_t inv_get_iio_trigger_path(const char *name)
* node. It should be zeroed before calling this function.
* Or it could have unpredicable result.
*/
-inv_error_t inv_get_iio_device_node(const char *name)
+inv_error_t inv_get_iio_device_node(char *name)
{
- if (process_sysfs_request(CMD_GET_DEVICE_NODE, name) < 0)
+ if (process_sysfs_request(CMD_GET_DEVICE_NODE, (char *)name) < 0)
return INV_ERROR_NOT_OPENED;
else
return INV_SUCCESS;
diff --git a/libsensors_iio/software/core/mllite/linux/ml_sysfs_helper.h b/libsensors_iio/software/core/mllite/linux/ml_sysfs_helper.h
index eb285c5..9470874 100644
--- a/libsensors_iio/software/core/mllite/linux/ml_sysfs_helper.h
+++ b/libsensors_iio/software/core/mllite/linux/ml_sysfs_helper.h
@@ -27,8 +27,8 @@ inv_error_t inv_get_chip_name(char *name);
inv_error_t inv_get_sysfs_key(unsigned char *key);
inv_error_t inv_get_handler_number(const char *name, int *num);
inv_error_t inv_get_input_number(const char *name, int *num);
-inv_error_t inv_get_iio_trigger_path(const char *name);
-inv_error_t inv_get_iio_device_node(const char *name);
+inv_error_t inv_get_iio_trigger_path(char *name);
+inv_error_t inv_get_iio_device_node(char *name);
#ifdef __cplusplus
}
diff --git a/libsensors_iio/software/core/mllite/linux/mlos_linux.c b/libsensors_iio/software/core/mllite/linux/mlos_linux.c
index 75f062e..6c9a6ca 100644
--- a/libsensors_iio/software/core/mllite/linux/mlos_linux.c
+++ b/libsensors_iio/software/core/mllite/linux/mlos_linux.c
@@ -58,7 +58,9 @@ void *inv_malloc(unsigned int numBytes)
inv_error_t inv_free(void *ptr)
{
// Deallocate space.
- free(ptr);
+ if (ptr) {
+ free(ptr);
+ }
return INV_SUCCESS;
}