Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3847

C/C++ • Re: Example of GPIO use with Linux only (no third party libraries)

$
0
0
I did scratch my head over the logic operations in function gpio_line_set_values. It seems to turn everything on or everything off. In fact, that's what it does on my system. You might not have noticed if you only had one LED.
Indeed - gpio_line_set_values() could pass the bits field direct to the kernel unaltered in the linevals->bits. The kernel ignores any bits where the mask bit is not set or any bits beyond the number of lines requested.

As written, that parameter should be called value, not bits - it applies that value to all lines set in the mask. To be fair, that is what the func docs say:

Code:

 * @param bits gpio value to write (0 - LO, 1 - HI) to set bit in linereq->bits for bits specified in mask.
which is fine, but the kernel does allow you to set lines both hi and low in the one ioctl call - the intent being to allow bit-bashing of busses, setting all the lines in the bus at once, or as close as the kernel device driver allows, and to whatever value is appropriate.

Statistics: Posted by warthog618 — Tue Sep 17, 2024 6:34 am



Viewing all articles
Browse latest Browse all 3847

Trending Articles