christian-nils
Posts: 11
Joined: Wed Jun 22, 2016 9:27 am

Setting up hid over i2c: binding and interrupt [solved]

Mon Jun 27, 2016 6:07 pm

Hello,

I am trying to interface a IMU (from Microchip MM7150) which supports the HID over I2C standard defined by Microsoft.
I have activated the module (i2c-hid) in the kernel as well as activating the different drivers needed (hid-sensor-hub, and each single sensor drivers).

Following the documentation for i2c-hid, I binded the connection to the device tree (https://www.kernel.org/doc/Documentatio ... er-i2c.txt).

Here is my dts file

Code: Select all

// Definitions for HID over I2C
/dts-v1/;
/plugin/;

/{
	compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm, bcm2709";

	fragment@0 {
		target = <&i2c_arm>;
		__overlay__ {
			status = "okay";
		};
	};
	
	fragment@1 {
		target = <&gpio>;
		__overlay__ {
			i2c_hid_pins: i2c_hid_pins {
				brcm,pins = <23>;
				brcm,function = <0>;
			};
		};
	};
	
	fragment@2 {
		target = <&i2c_arm>;
		__overlay__{
			#address-cells = <1>;
			#size-cells = <0>;

			i2c_hid: i2c-hid-dev@2c {
				compatible = "hid-over-i2c";
				reg = <0x40>;
				hid-descr-addr = <0x0001>;
				gpio-controller;
				#gpio-cells = <2>;
				#interrupt-cells = <2>;
				interrupt-parent = <&gpio>;
				interrupts = <23 8>;
				interrupt-controller;
				
				status = "okay";
			};
			
		};
	};
	
	__overrides__ {
		gpiopin = <&i2c_hid_pins>, "brcm,pins:0",
					<&i2c_hid>, "interrupts:0";
		addr = <&i2c_hid>, "reg:0";
		};
		
};
The i2c communication seems to work, but the interrupt line seems to do not work properly. That is why I am posting this message, to know if any of you has suggestions to fix that part.

My interrupt line is connected to the GPIO 23. The interrupt line is active when the level is low. Do you think the binding is correctly made?

Thanks for the help!

Christian-Nils
Last edited by christian-nils on Thu Jul 28, 2016 6:03 am, edited 1 time in total.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3164
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Setting up hid over i2c: binding and interrupt

Mon Jun 27, 2016 8:26 pm

What you have there looks like a good start, but there are problems:

1)

Code: Select all

"brcm, bcm2709"
There should be no space here (but nothing is checking compatible strings on the overlays).

2)

Code: Select all

         i2c_hid: i2c-hid-dev@2c {
            ...
            reg = <0x40>;
The value after the "@" and the reg value are supposed to agree (although they won't if you use the "addr" parameter - that's not actually a problem, but it is bad form). Since 0x2c is the default, I assume that the reg value is correct, meaning the i2c-hid-dev declaration should say "@40", but I couldn't find any reference as to how to set the I2C address on the MM7150.

3) The following properties are not mentioned in the bindings and almost certainly shouldn't be used:

Code: Select all

            gpio-controller;
            #gpio-cells = <2>;
            #interrupt-cells = <2>;
            interrupt-controller;
(I doubt the device acts as an interrupt or GPIO controller).

4) You've declared the interrupt to be active-low level triggered - you could try high-to-low edge triggered (2) instead.

Your DT parameters look to be defined correctly.

christian-nils
Posts: 11
Joined: Wed Jun 22, 2016 9:27 am

Re: Setting up hid over i2c: binding and interrupt

Tue Jun 28, 2016 6:43 am

Hej!

Thanks for your help! I modified the file as you suggested me.
I think the falling edge is not the right interrupt flag, according to MM7150 datasheet. Even though, I tried and I have the same error.

Anyway, I think my interrupt binding works after having checked the line with the oscilloscope. What is happening is that after the RESET command sent by the i2c-hid module, the interrupt line should be asserted within 5 s. I checked and it is not the case! It happens way later...

So I wonder if it is not a problem of hardware simply... would it be possible that the device does not assert the interrupt line within the 5 seconds because of a hardware defect?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3164
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Setting up hid over i2c: binding and interrupt

Tue Jun 28, 2016 9:05 am

I think at this point your question is no longer about Device Tree - I suggest you try in the Interfacing forum.

christian-nils
Posts: 11
Joined: Wed Jun 22, 2016 9:27 am

Re: Setting up hid over i2c: binding and interrupt

Tue Jun 28, 2016 12:41 pm

Thank you PhilE. I have checked further (I got help from the creator of i2c-hid module) and it seems that the interrupt is not set correctly. So I think we can continue to try to fix the problem in this thread.

I have a RPi 3. I have connected the interrupt line from the MM7150 to the physical pin 13 (BCM pin 27). I have the following in the i2c-hid-dev node:

Code: Select all

interrupts = <27 0x8>;
The order is correct? (I ask because sometimes it is the inverse https://www.kernel.org/doc/Documentatio ... 5-gpio.txt)
The pin number corresponds to the BCM's, right?

Here is the dts updated

Code: Select all

// Definitions for HID over I2C
/dts-v1/;
/plugin/;

/{
	compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

	fragment@0 {
		target = <&i2c_arm>;
		__overlay__ {
			status = "okay";
		};
	};
	
	fragment@1 {
		target = <&gpio>;
		__overlay__ {
			i2c_hid_pins: i2c_hid_pins {
				brcm,pins = <27>;
				brcm,function = <0>;
			};
		};
	};
	
	fragment@2 {
		target = <&i2c_arm>;
		__overlay__{
			#address-cells = <1>;
			#size-cells = <0>;

			i2c_hid: i2c-hid-dev@40 {
				compatible = "hid-over-i2c";
				reg = <0x40>;
				hid-descr-addr = <0x0001>;
				interrupt-parent = <&gpio>;
				interrupts = <27 0x8>;
			};
			
		};
	};
	
	__overrides__ {
		gpiopin = <&i2c_hid_pins>, "brcm,pins:0",
					<&i2c_hid>, "interrupts:0";
		addr = <&i2c_hid>, "reg:0";
		};
		
};

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3164
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Setting up hid over i2c: binding and interrupt

Tue Jun 28, 2016 3:42 pm

I don't have one of these devices so I can't help much. I've noticed that the pins node isn't referenced by anything, so the pins won't be claimed on behalf of the driver. This shouldn't prevent the driver from claiming the GPIO itself, but it will prevent any pulls being set... Which brings me onto the fact that GPIO27 is a pin which pulls down by default, which is not what you want with an active-low interrupt. You can fix this in the pins section, which combined with a fix for the the other issue will result in an overlay like this:

Code: Select all

// Definitions for HID over I2C
/dts-v1/;
/plugin/;

/{
   compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

   fragment@0 {
      target = <&i2c_arm>;
      __overlay__ {
         status = "okay";
      };
   };

   fragment@1 {
      target = <&gpio>;
      __overlay__ {
         i2c_hid_pins: i2c_hid_pins {
            brcm,pins = <27>;
            brcm,function = <0>;
            brcm,pull = <2>; // up
         };
      };
   };

   fragment@2 {
      target = <&i2c_arm>;
      __overlay__{
         #address-cells = <1>;
         #size-cells = <0>;

         i2c_hid: i2c-hid-dev@40 {
            pinctrl-names = "default";
            pinctrl-0 = <&i2c_hid_pins>;

            compatible = "hid-over-i2c";
            reg = <0x40>;
            hid-descr-addr = <0x0001>;
            interrupt-parent = <&gpio>;
            interrupts = <27 0x8>;
         };

      };
   };

   __overrides__ {
      gpiopin = <&i2c_hid_pins>, "brcm,pins:0",
               <&i2c_hid>, "interrupts:0";
      addr = <&i2c_hid>, "reg:0";
      };

};
Give that a go and let me know how you get on.

Myzhar
Posts: 3
Joined: Fri Jul 22, 2016 7:11 am

Re: Setting up hid over i2c: binding and interrupt

Fri Jul 22, 2016 7:14 am

Hi Christian

I'm trying to use the same device on an Nvidia Jetson board (TK1 and TX1).

Have you finally succeded in using it with the Raspberry?
Can you post an update?

Thank you in advance
Walter

christian-nils
Posts: 11
Joined: Wed Jun 22, 2016 9:27 am

Re: Setting up hid over i2c: binding and interrupt

Tue Jul 26, 2016 7:47 pm

Hi Walter,

Actually, I was waiting for a happy ending before replying to this thread. I think I reached it today! ;)

The binding was properly made. There was no problem.
The problem was coming from the i2c baudrate. And actually it is extremely weird.

I had to set the i2c baudrate to 2 000 000 instead of 400 000 in order to get a proper connection. I do not know who is the faulty device, but I know that when I captured the i2c communication with an oscillo and with 400 000 bps the clock ticks were quite long... Anyway, from that point I was able to enumerate all the sensors.

Then, there was a long time of debugging to understand why I was not able to get values from the sensors. Now I fixed that, some of the old definitions of hid usage are used by Microchip while Linux uses the new ones. Basically the enum definitions are shifted by 1 in https://github.com/raspberrypi/linux/bl ... nsor-ids.h

Anyway, if you have any questions on the binding I guess we can take them here. Otherwise contact me via PM.

/CN

AndreyV
Posts: 1
Joined: Sun Aug 07, 2016 9:31 am

Re: Setting up hid over i2c: binding and interrupt

Sun Aug 07, 2016 9:46 am

christian-nils wrote:Hi Walter,
Then, there was a long time of debugging to understand why I was not able to get values from the sensors.
/CN
Hi Christian,

Could you give us a little more information about getting data from the sensors. I can interface with the module through I2C line and get data from Quaternion registers, but it is definitely wrong. I think the problem is interrupt handling while reading data or setting right values for sensors sensitivity and data rates. Perhaps it's also Exponent register value problem.

Thank you
Andrey.

Update:
I successfully got data for quaternion rotation. The problem was with wrong register addresses (VREG_ORXD and other registers). I made them "+ 2" (for example VREG_ORXD (0x29 + 2)) and now it works.

middyeasy
Posts: 1
Joined: Tue Mar 14, 2017 7:56 pm

Re: Setting up hid over i2c: binding and interrupt [solved]

Tue Mar 14, 2017 8:00 pm

Hello,
First thanks for posting the info on the mm7150! ive got 2 of these I've been dying to try out and I want to ultimate make this a ROS node that will be available to the other robotic users.. I've read thru this thread and while I have a fair understand of i2c.. the whole hid-i2c is new to me! Any chance you documented the steps you went thru or have an raspberry pi3 image you could share. It would be terrific to at least have an over view of the steps necessary to make it functional, any chance you could spare some wisdom!

Thanks in Advance,
Ken

Return to “Device Tree”