iio_core: Patches for IIO core kernel standard

Applying patches from Kuan Loon Lay.

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck 2016-06-30 14:54:46 -07:00
parent 634208e3dc
commit e1df8b5bf6
9 changed files with 52 additions and 37 deletions

11
examples/c++/kxcjk1013.cxx Executable file → Normal file
View File

@ -1,6 +1,6 @@
/* /*
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.com> * Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
* Copyright (c) 2015 Intel Corporation. * Copyright (c) 2016 Intel Corporation.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
@ -22,8 +22,9 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <iomanip>
#include <unistd.h>
#include <signal.h> #include <signal.h>
#include "kxcjk1013.hpp" #include "kxcjk1013.hpp"
@ -44,7 +45,8 @@ data_callback(char* data)
{ {
float x, y, z; float x, y, z;
accelerometer->extract3Axis(data, &x, &y, &z); accelerometer->extract3Axis(data, &x, &y, &z);
printf("% .1f % .1f % .1f\n", x, y, z); cout << fixed << setprecision(1);
cout << x << '\t' << y << '\t' << z << "[m/s^2]" << endl;
} }
int int
@ -54,7 +56,10 @@ main()
//! [Interesting] //! [Interesting]
// Instantiate a KXCJK1013 Accelerometer Sensor on iio device 0 // Instantiate a KXCJK1013 Accelerometer Sensor on iio device 0
accelerometer = new upm::KXCJK1013(0); accelerometer = new upm::KXCJK1013(0);
// Available scales are 0.009582(2g), 0.019163(4g), and 0.038326(8g)
accelerometer->setScale(0.019163); accelerometer->setScale(0.019163);
// Available sampling frequency are 0.781000, 1.563000, 3.125000, 6.250000, 12.500000, 25, 50,
// 100, 200, 400, 800, and 1600
accelerometer->setSamplingFrequency(25.0); accelerometer->setSamplingFrequency(25.0);
accelerometer->enable3AxisChannel(); accelerometer->enable3AxisChannel();
accelerometer->installISR(data_callback, NULL); accelerometer->installISR(data_callback, NULL);

View File

@ -1,6 +1,6 @@
/* /*
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.com> * Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
* Copyright (c) 2015 Intel Corporation. * Copyright (c) 2016 Intel Corporation.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
@ -22,8 +22,9 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <unistd.h>
#include <iostream> #include <iostream>
#include <iomanip>
#include <unistd.h>
#include <signal.h> #include <signal.h>
#include "l3gd20.hpp" #include "l3gd20.hpp"
@ -43,8 +44,10 @@ void
data_callback(char* data) data_callback(char* data)
{ {
float x, y, z; float x, y, z;
if (gyroscope->extract3Axis(data, &x, &y, &z)) if (gyroscope->extract3Axis(data, &x, &y, &z)) {
printf("% .2f % .2f % .2f\n", x, y, z); cout << fixed << setprecision(1);
cout << x << '\t' << y << '\t' << z << "[rad/sec]" << endl;
}
} }
int int
@ -54,7 +57,9 @@ main()
//! [Interesting] //! [Interesting]
// Instantiate a L3GD20 Gyroscope Sensor on iio device 3 // Instantiate a L3GD20 Gyroscope Sensor on iio device 3
gyroscope = new upm::L3GD20(3); gyroscope = new upm::L3GD20(3);
// Available scales are 0.000153(250dps), 0.000305(500dps), and 0.001222(2000dps)
gyroscope->setScale(0.001222); gyroscope->setScale(0.001222);
// Available sampling frequency are 95, 190, 380, and 760
gyroscope->setSamplingFrequency(95.0); gyroscope->setSamplingFrequency(95.0);
gyroscope->enable3AxisChannel(); gyroscope->enable3AxisChannel();
gyroscope->installISR(data_callback, NULL); gyroscope->installISR(data_callback, NULL);

0
src/kxcjk1013/CMakeLists.txt Executable file → Normal file
View File

0
src/kxcjk1013/jsupm_kxcjk1013.i Executable file → Normal file
View File

View File

@ -1,6 +1,6 @@
/* /*
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.com> * Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
* Copyright (c) 2015 Intel Corporation. * Copyright (c) 2016 Intel Corporation.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
@ -30,8 +30,6 @@
#define NUMBER_OF_BITS_IN_BYTE 8 #define NUMBER_OF_BITS_IN_BYTE 8
#define NUMBER_OF_BITS_IN_BYTE 8
using namespace upm; using namespace upm;
KXCJK1013::KXCJK1013(int device) KXCJK1013::KXCJK1013(int device)
@ -51,7 +49,7 @@ KXCJK1013::KXCJK1013(int device)
if (mraa_iio_create_trigger(m_iio, trigger) != MRAA_SUCCESS) if (mraa_iio_create_trigger(m_iio, trigger) != MRAA_SUCCESS)
fprintf(stderr, "Create trigger %s failed\n", trigger); fprintf(stderr, "Create trigger %s failed\n", trigger);
if (mraa_iio_get_mounting_matrix(m_iio, m_mount_matrix) == MRAA_SUCCESS) if (mraa_iio_get_mount_matrix(m_iio, "in_mount_matrix", m_mount_matrix) == MRAA_SUCCESS)
m_mount_matrix_exist = true; m_mount_matrix_exist = true;
else else
m_mount_matrix_exist = false; m_mount_matrix_exist = false;
@ -62,7 +60,7 @@ KXCJK1013::KXCJK1013(int device)
KXCJK1013::~KXCJK1013() KXCJK1013::~KXCJK1013()
{ {
if(m_iio) if (m_iio)
mraa_iio_close(m_iio); mraa_iio_close(m_iio);
} }
@ -146,6 +144,7 @@ KXCJK1013::disableBuffer()
bool bool
KXCJK1013::setScale(float scale) KXCJK1013::setScale(float scale)
{ {
m_scale = scale;
mraa_iio_write_float(m_iio, "in_accel_scale", scale); mraa_iio_write_float(m_iio, "in_accel_scale", scale);
return true; return true;
@ -187,6 +186,7 @@ KXCJK1013::extract3Axis(char* data, float* x, float* y, float* z)
iio_y = getChannelValue((unsigned char*) (data + channels[1].location), &channels[1]); iio_y = getChannelValue((unsigned char*) (data + channels[1].location), &channels[1]);
iio_z = getChannelValue((unsigned char*) (data + channels[2].location), &channels[2]); iio_z = getChannelValue((unsigned char*) (data + channels[2].location), &channels[2]);
// Raw data is acceleration in direction. Units after application of scale are m/s^2
*x = (iio_x * m_scale); *x = (iio_x * m_scale);
*y = (iio_y * m_scale); *y = (iio_y * m_scale);
*z = (iio_z * m_scale); *z = (iio_z * m_scale);

17
src/kxcjk1013/kxcjk1013.hpp Executable file → Normal file
View File

@ -1,6 +1,6 @@
/* /*
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.com> * Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
* Copyright (c) 2015 Intel Corporation. * Copyright (c) 2016 Intel Corporation.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
@ -85,7 +85,7 @@ class KXCJK1013
/** /**
* Enable trigger buffer * Enable trigger buffer
* @param trigger buffer length in string * @param trigger buffer length in integer
*/ */
bool enableBuffer(int length); bool enableBuffer(int length);
@ -96,13 +96,18 @@ class KXCJK1013
/** /**
* Set scale * Set scale
* @param scale in string * @param scale in float
* Available scales are 0.009582(2g), 0.019163(4g), and 0.038326(8g)
* Default scale is 0.019163
*/ */
bool setScale(const float scale); bool setScale(const float scale);
/** /**
* Set sampling frequency * Set sampling frequency
* @param sampling frequency in string * @param sampling frequency in float
* Available sampling frequency are 0.781000, 1.563000, 3.125000, 6.250000, 12.500000, 25, 50,
* 100, 200, 400, 800, and 1600
* Default sampling frequency is 25
*/ */
bool setSamplingFrequency(const float sampling_frequency); bool setSamplingFrequency(const float sampling_frequency);
@ -124,7 +129,7 @@ class KXCJK1013
mraa_iio_context m_iio; mraa_iio_context m_iio;
int m_iio_device_num; int m_iio_device_num;
bool m_mount_matrix_exist; // is mount matrix exist bool m_mount_matrix_exist; // is mount matrix exist
float m_mount_matrix[9]; // mount matrix float m_mount_matrix[9]; // mount matrix
float m_scale; // accelerometer data scale float m_scale; // accelerometer data scale
}; };
} }

0
src/kxcjk1013/pyupm_kxcjk1013.i Executable file → Normal file
View File

18
src/l3gd20/l3gd20.cxx Normal file → Executable file
View File

@ -1,6 +1,6 @@
/* /*
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.com> * Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
* Copyright (c) 2015 Intel Corporation. * Copyright (c) 2016 Intel Corporation.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
@ -56,7 +56,7 @@ L3GD20::L3GD20(int device)
if (mraa_iio_create_trigger(m_iio, trigger) != MRAA_SUCCESS) if (mraa_iio_create_trigger(m_iio, trigger) != MRAA_SUCCESS)
fprintf(stderr, "Create trigger %s failed\n", trigger); fprintf(stderr, "Create trigger %s failed\n", trigger);
if (mraa_iio_get_mounting_matrix(m_iio, m_mount_matrix) == MRAA_SUCCESS) if (mraa_iio_get_mount_matrix(m_iio, "in_mount_matrix", m_mount_matrix) == MRAA_SUCCESS)
m_mount_matrix_exist = true; m_mount_matrix_exist = true;
else else
m_mount_matrix_exist = false; m_mount_matrix_exist = false;
@ -88,18 +88,10 @@ L3GD20::~L3GD20()
free(m_filter.buff); free(m_filter.buff);
m_filter.buff = NULL; m_filter.buff = NULL;
} }
if(m_iio) if (m_iio)
mraa_iio_close(m_iio); mraa_iio_close(m_iio);
} }
#ifdef JAVACALLBACK
void
L3GD20::installISR(IsrCallback* cb)
{
installISR(generic_callback_isr, cb);
}
#endif
void void
L3GD20::installISR(void (*isr)(char*), void* arg) L3GD20::installISR(void (*isr)(char*), void* arg)
{ {
@ -177,6 +169,8 @@ L3GD20::disableBuffer()
bool bool
L3GD20::setScale(float scale) L3GD20::setScale(float scale)
{ {
m_scale = scale;
mraa_iio_write_float(m_iio, "in_anglvel_x_scale", scale); mraa_iio_write_float(m_iio, "in_anglvel_x_scale", scale);
mraa_iio_write_float(m_iio, "in_anglvel_y_scale", scale); mraa_iio_write_float(m_iio, "in_anglvel_y_scale", scale);
mraa_iio_write_float(m_iio, "in_anglvel_z_scale", scale); mraa_iio_write_float(m_iio, "in_anglvel_z_scale", scale);
@ -224,6 +218,8 @@ L3GD20::extract3Axis(char* data, float* x, float* y, float* z)
iio_y = getChannelValue((unsigned char*) (data + channels[1].location), &channels[1]); iio_y = getChannelValue((unsigned char*) (data + channels[1].location), &channels[1]);
iio_z = getChannelValue((unsigned char*) (data + channels[2].location), &channels[2]); iio_z = getChannelValue((unsigned char*) (data + channels[2].location), &channels[2]);
// Raw data is x, y, z axis angular velocity. Units after application of scale are radians per
// second
*x = (iio_x * m_scale); *x = (iio_x * m_scale);
*y = (iio_y * m_scale); *y = (iio_y * m_scale);
*z = (iio_z * m_scale); *z = (iio_z * m_scale);

20
src/l3gd20/l3gd20.hpp Executable file → Normal file
View File

@ -1,6 +1,6 @@
/* /*
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.com> * Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
* Copyright (c) 2015 Intel Corporation. * Copyright (c) 2016 Intel Corporation.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
@ -100,7 +100,7 @@ class L3GD20
/** /**
* Enable trigger buffer * Enable trigger buffer
* @param trigger buffer length in string * @param trigger buffer length in integer
*/ */
bool enableBuffer(int length); bool enableBuffer(int length);
@ -111,13 +111,17 @@ class L3GD20
/** /**
* Set scale * Set scale
* @param scale in string * @param scale in float
* Available scales are 0.000153(250dps), 0.000305(500dps), and 0.001222(2000dps)
* Default scale is 0.000153
*/ */
bool setScale(const float scale); bool setScale(const float scale);
/** /**
* Set sampling frequency * Set sampling frequency
* @param sampling frequency in string * @param sampling frequency in float
* Available sampling frequency are 95, 190, 380, and 760
* Default sampling frequency is 95
*/ */
bool setSamplingFrequency(const float sampling_frequency); bool setSamplingFrequency(const float sampling_frequency);
@ -202,9 +206,9 @@ class L3GD20
bool m_mount_matrix_exist; // is mount matrix exist bool m_mount_matrix_exist; // is mount matrix exist
float m_mount_matrix[9]; // mount matrix float m_mount_matrix[9]; // mount matrix
float m_scale; // gyroscope data scale float m_scale; // gyroscope data scale
int m_event_count; // sample data arrive int m_event_count; // sample data arrive
bool m_calibrated; // calibrate state bool m_calibrated; // calibrate state
gyro_cal_t m_cal_data; // calibrate data gyro_cal_t m_cal_data; // calibrate data
filter_median_t m_filter; // filter data filter_median_t m_filter; // filter data
}; };
} }