blemasle / arduino-mcp23017

Complete support of MCP23017
MIT License
71 stars 40 forks source link

Adding inverted input capability #14

Closed Beerlesklopfer closed 4 years ago

Beerlesklopfer commented 4 years ago

I neded an inverted input for my application so I am share my changes with you.

blemasle commented 4 years ago

I don't have the time nor the circuitry to test that code at the moment. That's a shame cause I really think it's a nice addition to the library :)

Let me know If you ever have the chance to the test that code, especially the fact that any change to the register can be reverted without a chip reboot to keep things consistent with the rest the library. Why not merge that PR after all ? :)

Beerlesklopfer commented 4 years ago

Salut Bertrand,

 

J'ai créé une nouvelle demande d'extraction et j'ai fusionné le code vérifié. De plus, j'ai légèrement révisé la documentation pour que le wiki puisse la reprendre.

Peut-être que je enverrai le wiki plus tard á tois.

 

Une semaine bonne et saine pour tois.

 

Cordialement Jörg

 

Gesendet: Samstag, 29. Februar 2020 um 13:29 Uhr Von: "Bertrand Lemasle" notifications@github.com An: blemasle/arduino-mcp23017 arduino-mcp23017@noreply.github.com Cc: "Jörg Bernau" Joerg.Bernau@web.de, "State change" state_change@noreply.github.com Betreff: Re: [blemasle/arduino-mcp23017] Adding inverted input capability (#14)

I don't have the time nor the circuitry to test that code at the moment. That's a shame cause I really think it's a nice addition to the library :)

Let me know If you ever have the chance to the test that code, especially the fact that any change to the register can be reverted without a chip reboot to keep things consistent with the rest the library. Why not merge that PR after all ? :)

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or unsubscribe.

Beerlesklopfer commented 4 years ago
MCP23017 16-Bit I/O Expander with Serial Interface

## Public Member Functions

MCP23017 (uint8_t address, TwoWire \&bus=Wire)

void init()

void begin(uint8_t pullup_a=0x00, uint8_t pullup_b=0x00)

void portMode(MCP23017_PORT port, uint8_t modes, uint8_t pullups=0xff, uint8_t inverteds=0x00)

void pinMode(uint8_t pin, uint8_t mode, bool inverted=false)

void digitalWrite(uint8_t pin, uint8_t state)

uint8_t digitalRead(uint8_t pin)

void writePort(MCP23017_PORT port, uint8_t values)

void write(uint16_t values)

uint8_t readPort(MCP23017_PORT port)

uint16_t read()

void writeRegister(MCP23017_REGISTER reg, uint8_t value)

void writeRegister(MCP23017_REGISTER reg, uint8_t portA, uint8_t portB)

uint8_t readRegister(MCP23017_REGISTER reg)

void readRegister(MCP23017_REGISTER reg, uint8_t \&portA, uint8_t \&portB)

void interruptMode(MCP23017_INTMODE intMode)

void interrupt(MCP23017_PORT port, uint8_t mode)

void disableInterrupt(MCP23017_PORT port)

void interruptedBy(uint8_t \&portA, uint8_t \&portB)

void clearInterrupts()

void clearInterrupts(uint8_t \&portA, uint8_t \&portB)

Constructor & Destructor Documentation

MCP23017()

| | | | | | ------------------ | - | --------- | -------------- | | MCP23017::MCP23017 | ( | uint8\_t | *address*, | | | | TwoWire & | *bus* = `Wire` | | | ) | | |
Instantiates a new instance to interact with a MCP23017 at the specified address. - Parameters | | | | ------- | -------------------------------------- | | address | bus address of MCP23017 (0x20 \~ 0x27) | | bus | refence to i2c bus object |

Member Function Documentation

begin()

| | | | | | -------------------- | - | -------- | --------------------- | | void MCP23017::begin | ( | uint8\_t | *pullup\_a* = `0x00`, | | | | uint8\_t | *pullup\_b* = `0x00` | | | ) | | |
Initializes the chip with the default configuration. Enables Byte mode (IOCON.BANK = 0 and IOCON.SEQOP = 1). Enables pull-up resistors for all pins by default. This will only be effective for input pins. - Note See"3.2.1 Byte mode and Sequential mode".See - Parameters | | | | --------- | ------------------------------------------------------------- | | pullup\_a | bitmask for port A | | pullup\_b | bitmask for port B See "3.2.1 Byte mode and Sequential mode". |

clearInterrupts() [1/2]

Clears interrupts on both ports. - Note See"3.5.9 INTERRUPT CAPTURED REGISTER".See

clearInterrupts() [2/2]

| | | | | | ------------------------------ | - | ---------- | -------- | | void MCP23017::clearInterrupts | ( | uint8\_t & | *portA*, | | | | uint8\_t & | *portB* | | | ) | | |
Clear interrupts on both ports. Returns port values at the time the interrupt occured. - Note See"3.5.9 INTERRUPT CAPTURED REGISTER".See - Parameters | | | | ----- | --------------------------------------------------------- | | portA | reference to port A value; returns the value by reference | | portB | reference to port B value; returns the value by reference |

digitalRead()

Reads a single pin state. - Note See"3.5.10 Port register \<0x09See".See - Parameters | | | | ------ | ---------------------------------------------------------------- | | pin | Pin 0-7 for port A, 8-15 for port B. | | return | HIGH or 0x01, LOW or 0x00 depending the hardwarestate of the pin |

digitalWrite()

| | | | | | --------------------------- | - | -------- | ------- | | void MCP23017::digitalWrite | ( | uint8\_t | *pin*, | | | | uint8\_t | *state* | | | ) | | |
Writes a single pin state. - Note See"3.5.10 Port register \<0x09See".See - Parameters | | | | ----- | ------------------------------------ | | pin | Pin 0-7 for port A, 8-15 for port B. | | state | HIGH or 0x01 LOW or 0x00 |

disableInterrupt()

| | | | | | | ------------------------------- | - | -------------- | ------ | - | | void MCP23017::disableInterrupt | ( | MCP23017\_PORT | *port* | ) |
Disables interrupts for the specified port. - Note See"3.5.3 INTERRUPT-ON-CHANGE CONTROL REGISTER".See - Parameters | | | | ---- | -------------------- | | port | MCP23017 port A or B |

interrupt()

| | | | | | ------------------------ | - | -------------- | ------- | | void MCP23017::interrupt | ( | MCP23017\_PORT | *port*, | | | | uint8\_t | *mode* | | | ) | | |
Configures interrupt registers using an Arduino-like API-mode . - Note See"3.5.3 INTERRUPT-ON-CHANGE CONTROL REGISTER".See - Parameters | | | | ---- | --------------------------------------- | | port | MCP23017 port A or B | | mode | Can be one of CHANGE, FALLING or RISING |

interruptedBy()

| | | | | | ---------------------------- | - | ---------- | -------- | | void MCP23017::interruptedBy | ( | uint8\_t & | *portA*, | | | | uint8\_t & | *portB* | | | ) | | |
Reads which pin caused the interrupt. - Note See"3.5.9 GPINTEN: INTERRUPT CAPTURED REGISTER".See - Parameters | | | | ----- | --------------------------------------------------------- | | portA | reference to port A value; returns the value by reference | | portB | reference to port B value; returns the value by reference |

interruptMode()

| | | | | | | ---------------------------- | - | ----------------- | --------- | | | void MCP23017::interruptMode | ( | MCP23017\_INTMODE | *intMode* | ) |
Controls how the interrupt pins act with each other. If intMode is SEPARATED, interrupt conditions on a port will cause its respective INT pin to active. If intMode is OR, interrupt pins are OR'ed so an interrupt on one of the port will cause both pints to active. - Note See"3.5.6 I/O EXPANDER CONFIGURATION REGISTER \<0x05\>".See - Parameters | | | | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | intMode | When OR, the INTn pins are functionally OR’ed so that an interrupt on either port will cause both pins to activate. Otherwise use SEPARATED as parameter. |

pinMode()

| | | | | | ---------------------- | - | -------- | -------------------- | | void MCP23017::pinMode | ( | uint8\_t | *pin*, | | | | uint8\_t | *mode*, | | | | bool | *inverted* = `false` | | | ) | | |
Sets a single pins' direction. When the pin is an input pin a pullup and/or an inverted option can be specified. - Note See"3.5.1 I/O IODIR I/O DIRECTION REGISTER \<0x00\>", "3.5.2 I NPUT POLARITY REGISTER \<0x01\>", "3.5.7 PULL-UP RESISTOR CONFIGURATION REGISTER \<0x06\>"See - Parameters | | | | ---- | -------------------------------------------------------------------- | | pin | Controls a single pin direction. Pin 0-7 for port A, 8-15 fo port B. | | mode | INPUT or 0x00 INPUT\_PULLUP or 0x02 OUTPUT or 0x01 |

portMode()

| | | | | | ----------------------- | - | -------------- | -------------------- | | void MCP23017::portMode | ( | MCP23017\_PORT | *port*, | | | | uint8\_t | *modes*, | | | | uint8\_t | *pullups* = `0xff`, | | | | uint8\_t | *inverteds* = `0x00` | | | ) | | |
Controls the pins direction on a whole port at once. - Note See"3.5.1 I/O IODIR I/O DIRECTION REGISTER \<0x00\>", "3.5.2 I NPUT POLARITY REGISTER \<0x01\>", "3.5.7 PULL-UP RESISTOR CONFIGURATION REGISTER \<0x06\>"See - Parameters | | | | --------- | -------------------------------------------------- | | port | MCP23017 port A or B | | modes | direction of whole port INPUT or 0x0 OUTPUT or0x01 | | pullup | bitmask for internal 100k pullup resistors | | inverteds | bitmask for inverted mode |

read()

Reads pins state for both ports. - Note See"3.5.10 Port register \<0x09See".See - Parameters | | | | ------ | ---------------------------------------------------------------- | | return | HIGH or 0x01, LOW or 0x00 depending the hardwarestate of the pin |

readPort()

| | | | | | | --------------------------- | - | -------------- | ------ | - | | uint8\_t MCP23017::readPort | ( | MCP23017\_PORT | *port* | ) |
Reads pins state for a whole port. - Note See"3.5.10 Port register \<0x09\>".See - Parameters | | | | ------ | ---------------------------------------------------------------- | | port | MCP23017 port A or B | | return | HIGH or 0x01, LOW or 0x00 depending the hardwarestate of the pin |

readRegister() [1/2]

| | | | | | | ------------------------------- | - | ------------------ | ----- | - | | uint8\_t MCP23017::readRegister | ( | MCP23017\_REGISTER | *reg* | ) |
Reads a single registers value. - Parameters | | | | --- | -------------------------------------------------------- | | reg | register to read port A: 0x00 \~ 0A0 port B: 0x10 \~ 1A0 |

readRegister() [2/2]

| | | | | | --------------------------- | - | ------------------ | -------- | | void MCP23017::readRegister | ( | MCP23017\_REGISTER | *reg*, | | | | uint8\_t & | *portA*, | | | | uint8\_t & | *portB* | | | ) | | |
Reads the values from a register pair. - Parameters | | | | ----- | --------------------------------------------------------- | | reg | register to read port A: 0x00 \~ 0A0 | | portA | reference to port A value; returns the value by reference | | portB | reference to port B value; returns the value by reference | - Note For portA and portB variable to effectively match the desired port, you have to supply a portA register address to reg. Otherwise, values will be reversed due to the way the MCP23017 works in Byte mode.

write()

| | | | | | | -------------------- | - | --------- | -------- | - | | void MCP23017::write | ( | uint16\_t | *values* | ) |
Writes pins state to both ports. - Note See"3.5.10 Port register \<0x09\>".See - Parameters | | | | ------ | -------------------------------------------- | | values | bitmask to manipulate all OUTPUT of the chip |

writePort()

| | | | | | ------------------------ | - | -------------- | -------- | | void MCP23017::writePort | ( | MCP23017\_PORT | *port*, | | | | uint8\_t | *values* | | | ) | | |
Writes pins state to a whole port. - Note See"3.5.10 Port register \<0x09\>".See - Parameters | | | | ------ | ---------------------------------------------- | | port | MCP23017 port A or B | | values | bitmask to manipulate the given port as OUTPUT |

writeRegister()

| | | | | | ---------------------------- | - | ------------------ | -------- | | void MCP23017::writeRegister | ( | MCP23017\_REGISTER | *reg*, | | | | uint8\_t | *portA*, | | | | uint8\_t | *portB* | | | ) | | |
Writes values to a register pair. - Note For portA and portB variable to effectively match the desired port, you have to supply a portA register address to reg. Otherwise, values will be reversed due to the way the MCP23017 works in Byte mode.

blemasle commented 4 years ago

Bonjour Jörg :)

Thanks again for the input. I'm sorry for the reaction time, but I've just started a new job a few days ago and It has been going like crazy since then :) For instance, this is the first opportunity I had to check my mails since last sunday :/

Anyway, I'll review your changes as soon as I can and probably accept the PR once done. One question though, what did you use to generate the wiki content from the comments ?

Regards, Bertrand

On Sun, Mar 1, 2020 at 7:52 PM Jörg Bernau notifications@github.com wrote:

Salut Bertrand,

J'ai créé une nouvelle demande d'extraction et j'ai fusionné le code vérifié. De plus, j'ai légèrement révisé la documentation pour que le wiki puisse la reprendre.

Peut-être que je enverrai le wiki plus tard á tois.

Une semaine bonne et saine pour tois.

Cordialement Jörg

Gesendet: Samstag, 29. Februar 2020 um 13:29 Uhr Von: "Bertrand Lemasle" notifications@github.com An: blemasle/arduino-mcp23017 arduino-mcp23017@noreply.github.com Cc: "Jörg Bernau" Joerg.Bernau@web.de, "State change" < state_change@noreply.github.com> Betreff: Re: [blemasle/arduino-mcp23017] Adding inverted input capability (#14)

I don't have the time nor the circuitry to test that code at the moment. That's a shame cause I really think it's a nice addition to the library :)

Let me know If you ever have the chance to the test that code, especially the fact that any change to the register can be reverted without a chip reboot to keep things consistent with the rest the library. Why not merge that PR after all ? :)

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or unsubscribe.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/blemasle/arduino-mcp23017/pull/14?email_source=notifications&email_token=ABHRZYPM3JUFTY3IFPG6VZ3RFKVGTA5CNFSM4K2XNLAKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENNHMXY#issuecomment-593131103, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHRZYLWIBPA5CSKEMBNHALRFKVGTANCNFSM4K2XNLAA .

Beerlesklopfer commented 4 years ago

Hi Bertrand,

I used Doxygen first and pandoc afterwards. The rest was manual editing.

Regards Jörg