JeVois  1.17
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
IMU.H
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2020 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
18 #pragma once
19 
20 #include <cstddef> // for size_t
21 
22 namespace jevois
23 {
24  //! Abstract interface to an ICM20948 inertial measurement unit (IMU)
25  /*! This class abstracts the low-level communication interface (over SPI bus on JeVois-Pro hardware, or over I2C bus
26  shared with the camera sensor chip and through custom ioctl() calls on JeVois-A33. \ingroup imu */
27  class IMU
28  {
29  public:
30 
31  //! Constructor
32  IMU();
33 
34  //! Destructor
35  virtual ~IMU();
36 
37  //! Returns true if we use SPI for transfers. Used when ICM20948_REG_USER_CTRL is written to
38  virtual bool isSPI() const = 0;
39 
40  //! @name Access functions for IMU registers
41  //! @{
42 
43  //! Write a value to one of the IMU registers
44  /*! This very low-level access is for development of optimal IMU settings only and should not be used in normal
45  operation, it can crash your system. Bank selection is included in this function. */
46  virtual void writeRegister(unsigned short reg, unsigned char val) = 0;
47 
48  //! Read a value from one of the camera's IMU registers
49  /*! This very low-level access is for development of optimal IMU settings only and should not be used in normal
50  operation, it can crash your system. Bank selection is included in this function. */
51  virtual unsigned char readRegister(unsigned short reg) = 0;
52 
53  //! Write an array of values to the camera's IMU registers
54  /*! This very low-level access is for development of optimal IMU settings only and should not be used in normal
55  operation, it can crash your system. Memory for vals should have been allocated by the caller with at least
56  num bytes. num must be less than 32. Bank selection is included in this function. */
57  virtual void writeRegisterArray(unsigned short reg, unsigned char const * vals, size_t num) = 0;
58 
59  //! Read an array of values from the camera's IMU registers
60  /*! This very low-level access is for development of optimal IMU settings only and should not be used in normal
61  operation, it can crash your system. Memory for vals should have been allocated by the caller with at least
62  num bytes. num must be less than 32. Bank selection is included in this function. */
63  virtual void readRegisterArray(unsigned short reg, unsigned char * vals, size_t num) = 0;
64 
65  //! @}
66 
67  //! @name Access functions for DMP registers
68  //! @{
69 
70  //! Load the DMP firmware
71  /*! On JeVois-A33, the firmware is already loaded by the camera kernel module. So this is only useful on
72  JeVois-Pro to load the firmware over SPI. If verify is true, we will read it back and check. If errthrow is
73  also true, throws an exception if verification fails. */
74  void loadDMPfirmware(bool verify = false, bool errthrow = false);
75 
76  //! Write a value to a DMP register
77  /*! This very low-level access is for development of optimal DMP settings only and should not be used in normal
78  operation, it can crash your system. Note that the value will be converted to big endian, as required by the
79  DMP processor. */
80  void writeDMPregister(unsigned short reg, unsigned short val);
81 
82  //! Read a value from a DMP register
83  /*! This very low-level access is for development of optimal DMP settings only and should not be used in normal
84  operation, it can crash your system. Note that the value will be converted from big endian of DMP processor to
85  little endian of the JeVois processor.*/
86  unsigned short readDMPregister(unsigned short reg);
87 
88  //! Write an array of values to DMP registers
89  /*! This very low-level access is for development of optimal DMP settings only and should not be used in normal
90  operation, it can crash your system. Memory for vals should have been allocated by the caller with at least
91  num bytes. num must be less than 32. This function does not handle crossing of memory banks, so the caller
92  should segment the calls to match memory bank boundaries. Finally, this function does not perform any endian
93  conversion. Callers should be aware that the DMP is a 16-bit big endian system while the JeVois processor is
94  little endian. */
95  void writeDMPregisterArray(unsigned short reg, unsigned char const * vals, size_t num);
96 
97  //! Read an array of values from DMP registers
98  /*! This very low-level access is for development of optimal DMP settings only and should not be used in normal
99  operation, it can crash your system. Memory for vals should have been allocated by the caller with at least
100  num bytes. num must be less than 32. This function does not handle crossing of memory banks, so the caller
101  should segment the calls to match memory bank boundaries. Finally, this function does not perform any endian
102  conversion. Callers should be aware that the DMP is a 16-bit big endian system while the JeVois processor is
103  little endian. */
104  void readDMPregisterArray(unsigned short reg, unsigned char * vals, size_t num);
105 
106  //! @}
107  };
108 } // namespace jevois
jevois::IMU::loadDMPfirmware
void loadDMPfirmware(bool verify=false, bool errthrow=false)
Load the DMP firmware.
Definition: IMU.C:37
jevois::IMU::~IMU
virtual ~IMU()
Destructor.
Definition: IMU.C:33
jevois::IMU::IMU
IMU()
Constructor.
Definition: IMU.C:29
jevois::IMU::readDMPregister
unsigned short readDMPregister(unsigned short reg)
Read a value from a DMP register.
Definition: IMU.C:138
jevois::IMU::writeRegister
virtual void writeRegister(unsigned short reg, unsigned char val)=0
Write a value to one of the IMU registers.
jevois
Definition: Concepts.dox:1
jevois::IMU::isSPI
virtual bool isSPI() const =0
Returns true if we use SPI for transfers. Used when ICM20948_REG_USER_CTRL is written to.
jevois::IMU::readRegister
virtual unsigned char readRegister(unsigned short reg)=0
Read a value from one of the camera's IMU registers.
jevois::IMU::writeDMPregisterArray
void writeDMPregisterArray(unsigned short reg, unsigned char const *vals, size_t num)
Write an array of values to DMP registers.
Definition: IMU.C:125
jevois::IMU
Abstract interface to an ICM20948 inertial measurement unit (IMU)
Definition: IMU.H:27
jevois::IMU::readRegisterArray
virtual void readRegisterArray(unsigned short reg, unsigned char *vals, size_t num)=0
Read an array of values from the camera's IMU registers.
jevois::IMU::writeRegisterArray
virtual void writeRegisterArray(unsigned short reg, unsigned char const *vals, size_t num)=0
Write an array of values to the camera's IMU registers.
jevois::IMU::writeDMPregister
void writeDMPregister(unsigned short reg, unsigned short val)
Write a value to a DMP register.
Definition: IMU.C:114
jevois::IMU::readDMPregisterArray
void readDMPregisterArray(unsigned short reg, unsigned char *vals, size_t num)
Read an array of values from DMP registers.
Definition: IMU.C:149