sumotoy / gpio_expander

A library for drive a lot of GPIO chips with Arduino/Teensy3.x or LC
67 stars 29 forks source link

Inconsistent behaviour in mcp23s08 (and others) #8

Open PBudmark opened 7 years ago

PBudmark commented 7 years ago

The function mcp23s08::gpioPinMode uses the Arduino.h defines INPUT and OUTPUT for explicit setting of 'all input' and 'all output', but this usage restricts the freedom to set any combination of input/output, as INPUT has the value 0 and OUTPUT has the value 1.

If I try to set the combination 0b00000001 (GP0 input and GP1-7 as output), it will be interpreted as OUTPUT and all GP0-7 will be outputs.

Two new defines/constants would solve this problem, ALL_INPUT with value 0xFF and ALL_OUTPUT with value 0x00.

The same problem shows in functions mcp23s08::gpioPort and mcp23s08::portPullup, but here the defines HIGH with value 1 and LOW with value 0 are the problem.

Two new defines/constants would solve this problem, ALL_HIGH with value 0xFF and ALL_LOW with value 0x00.

The same problem shows also in the solutions with 16 GPIO, in those cases the defines/constants need to be 0xFFFF or 0x0000