fury
Posts: 15
Joined: Thu Sep 20, 2012 4:37 pm

Long dtoverlay line truncated? Can't seem to get all the properties recognized at once

Tue Feb 26, 2019 9:12 pm

I've attempted three different ways of setting up this rotary encoder (I will eventually have 2 hooked up, but for now, just trying to get this one)

Code: Select all

dtoverlay=rotary-encoder,pin_a=5,pin_b=6,steps-per-period=4,relative_axis,linux_axis=8
dtoverlay=rotary-encoder,pin_a=5,pin_b=6,steps-per-period=4,linux_axis=8,relative_axis
dtoverlay=rotary-encoder,pin_a=5,pin_b=6,linux_axis=8,relative_axis,steps-per-period=4
The first one results in the wrong axis (0 instead of 8)

Code: Select all

raspberrypi3:/boot# evtest /dev/input/by-path/platform-5.rotary-event
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x0 product 0x0 version 0x0
Input device name: "5.rotary"
Supported events:
  Event type 0 (EV_SYN)
  Event type 2 (EV_REL)
    Event code 0 (REL_X)
Properties:
Testing ... (interrupt to exit)
The second one results in an absolute axis (relative_axis parameter isn't recognized)

Code: Select all

raspberrypi3:~# evtest /dev/input/by-path/platform-5.rotary-event
evtest: No such file or directory
raspberrypi3:~# evtest /dev/input/by-path/platform-5.rotary-event-joystick 
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x0 product 0x0 version 0x0
Input device name: "5.rotary"
Supported events:
  Event type 0 (EV_SYN)
  Event type 3 (EV_ABS)
    Event code 8 (ABS_WHEEL)
      Value      0
      Min        0
      Max       24
      Flat       1
Properties:
Testing ... (interrupt to exit)
And the third one is the correct axis, and it's relative, but has the wrong steps-per-period (appears to be defaulting to 1, and by default it takes 4 rotary detents to equal 1 wheel event). When steps-per-period is the last item on the line, I can give it a bogus number like 8 and it will not give me the error I'm expecting from rotary_encoder.c#L280. So it looks like the line is getting truncated somewhere around 80 characters.

If I had to, I could connect to the encoder over I2C to reconfigure it for full period mode on startup, but changing steps-per-period in the dtoverlay seems much easier and more straightforward.

Can I configure these long dtoverlay settings on multiple lines? If so, how do I tell it the settings for each encoder? (when I hook up the second one, it will have a different set of pin_a & pin_b, different axis, etc., although I'm not sure yet if the second encoder will need a different steps-per-period)

Or, can I change something to have it recognize longer dtoverlay lines? (I'm building with Yocto and have already had to tweak the kernel a bit, so I could add another patch to tweak this if it's possible)

User avatar
Paeryn
Posts: 2517
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Long dtoverlay line truncated? Can't seem to get all the properties recognized at once

Tue Feb 26, 2019 9:39 pm

According to the docs there is an 80 character limit, it's about half to two thirds down the page. Just noticed, straight after that it says that parameters can be passed on subsequent lines.
https://www.raspberrypi.org/documentation/configuration/device-tree.md wrote: 3.2: DT parameters
As described above, DT parameters are a convenient way to make small changes to a device's configuration. The current base DTBs support parameters for enabling and controlling the onboard audio, I2C, I2S and SPI interfaces without using dedicated overlays. In use, parameters look like this:

dtparam=audio=on,i2c_arm=on,i2c_arm_baudrate=400000,spi=on
Note tht multiple assignments can be placed on the same line, but ensure you don't exceed the 80-character limit.

A future default config.txt may contain a section like this:

Code: Select all

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on
If you have an overlay that defines some parameters, they can be specified either on subsequent lines like this:

Code: Select all

dtoverlay=lirc-rpi
dtparam=gpio_out_pin=16
dtparam=gpio_in_pin=17
dtparam=gpio_in_pull=down
or appended to the overlay line like this:

Code: Select all

dtoverlay=lirc-rpi:gpio_out_pin=16,gpio_in_pin=17,gpio_in_pull=down
Note here the use of a colon (:) to separate the overlay name from its parameters, which is a supported syntax variant.
She who travels light — forgot something.

fury
Posts: 15
Joined: Thu Sep 20, 2012 4:37 pm

Re: Long dtoverlay line truncated? Can't seem to get all the properties recognized at once

Wed Feb 27, 2019 3:08 pm

Thank you! Ugh, I feel so bad for missing that - I swear I looked up all sorts of documentation and ctrl+F'd looking around for limits and characters, but seem to have missed that one.

Code: Select all

dtoverlay=rotary-encoder
dtparam=pin_a=6
dtparam=pin_b=5
dtparam=steps-per-period=4
dtparam=relative_axis
dtparam=linux_axis=8
That did the trick. For some reason, I had to swap the GPIO numbers for a and b when splitting it into different lines--I'm not sure why that is, unless it has to do with a different behavior of the driver in quarter period mode.

Though I don't have the second encoder ready yet to try, I presume for the next one I can just do another copy of that with different pin/axis assignments, and it will be able to tell the difference between the two? (i.e. the next dtoverlay=rotary-encoder line will start a new context of the rotary-encoder overlay)

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

Re: Long dtoverlay line truncated? Can't seem to get all the properties recognized at once

Thu Feb 28, 2019 9:03 am

Although I've not tried it with real hardware, at the Device Tree level multiple instances of the rotary-encoder should be fine - the pin_a parameter is used to uniquify the nodes to avoid clashes. The multiple-instance support was contributed last year (https://github.com/raspberrypi/linux/pull/2388) - presumably the user had an application that required it.

Return to “Device Tree”