|
ShiftRegGPIOXpander Library for ESP32 (Arduino) v1.1.3
A library that provides an easy mechanism to add GPIO digital output pins by using Shift Registers
|
A class that models a GPIO outputs pins expander through the use of 8-bits serial in paralell out (SIPO) shift registers. More...
#include <ShiftRegGPIOXpander_ESP32.h>
Public Member Functions | |
| ShiftRegGPIOXpander () | |
| Class default constructor. | |
| ShiftRegGPIOXpander (uint8_t ds, uint8_t sh_cp, uint8_t st_cp, uint8_t srQty=1, uint8_t *initCntnt=nullptr) | |
| Class constructor. | |
| ~ShiftRegGPIOXpander () | |
| Class destructor. | |
| bool | copyMainToAux (bool overWriteIfExists=true) |
| Copies the Buffer content to the Auxiliary Buffer | |
| void | discardAux () |
| Deletes the Auxiliary Buffer. | |
| uint8_t | digitalReadSr (const uint8_t &srPin) |
| Returns the state of the requested pin. | |
| void | digitalWriteSr (const uint8_t srPin, const uint8_t value) |
| Set a specific pin to either HIGH (0x01) or LOW (0x00). | |
| void | digitalWriteSrAllReset () |
| Sets all the pins to LOW (0x00). | |
| void | digitalWriteSrAllSet () |
| Sets all the pins to HIGH (0x01). | |
| void | digitalWriteSrMaskReset (uint8_t *newResetMask) |
| Modifies the Main buffer contents by resetting simultaneously certain pins. | |
| void | digitalWriteSrMaskSet (uint8_t *newSetMask) |
| Modifies the Main buffer contents by setting simultaneously certain pins. | |
| void | digitalWriteSrToAux (const uint8_t srPin, const uint8_t value) |
| Set a specific pin to either HIGH (0x01) or LOW (0x00) in the Auxiliary Buffer. | |
| uint8_t * | getMainBuffPtr () |
| Retrieves the pointer to the Main Buffer. | |
| uint8_t | getMaxPin () |
| Return the greatest valid pin number. | |
| uint8_t | getSrQty () |
| Return the quantity of shift registers composing the GPIOXtender object. | |
| bool | moveAuxToMain (bool flushASAP=true) |
| Moves the data in the Auxiliary to the Main. | |
| bool | stampOverMain (uint8_t *newCntntPtr) |
| Sets all of the output pins of the shift register to new provided values at once. | |
| bool | sendAllSRCntnt () |
| Flushes the contents of the Buffer to the GPIO Expander pins. | |
A class that models a GPIO outputs pins expander through the use of 8-bits serial in paralell out (SIPO) shift registers.
The GPIO pins expansion modeled adds digital output pins managed by the use of an API similar to the built in Arduino platform tools. As the hardware is built using daisy-chained 74HCx595 shift registers, the connection pins to the hardware are needed as parameters to build the object, as the number of shift registers daisy-chain connected is needed
| ShiftRegGPIOXpander::ShiftRegGPIOXpander | ( | uint8_t | ds, |
| uint8_t | sh_cp, | ||
| uint8_t | st_cp, | ||
| uint8_t | srQty = 1, | ||
| uint8_t * | initCntnt = nullptr ) |
Class constructor.
Instantiates a ShiftRegGPIOXpander object, the parameters provide the pins used to communicate with the shift registers and the number of shift registers composing the expander. 8-bits will be added with every shift register connected in a daisy-chain arrangement.
| ds | MCU GPIO pin connected to the DS pin -a.k.a. serial data input (DIO)- pin of the 74HCx595 to send data serially to the expander |
| sh_cp | MCU GPIO pin connected to the SH_CP pin -a.k.a. shift register clock input- of the 74HCx595 to manage the communication's clock line to the expander |
| st_cp | MCU GPIO pin connected to the ST_CP pin -a.k.a. storage register clock input- to set (latch) the output pins from the internal buffer of the expander |
| srQty | Optional parameter. Quantity of shift registers set in daisy-chain configuration composing the expander. |
| initCntnt | Optional parameter. Initial value to be loaded into the Main Buffer, and thus will be the inital state of the Shift Register output pins. The value is provided in the form of a uint8_t*, and the constructor expects the data to be set in the memory area from the pointed address to the pointed address + (srQty - 1) consecutive bytes. If the parameter is not provided, or set to nullptr the inital value to be loaded into the Main Buffer will be 0x00 to all the shift registers positions. |

| ShiftRegGPIOXpander::~ShiftRegGPIOXpander | ( | ) |
Class destructor.
Takes care of resources releasing
| bool ShiftRegGPIOXpander::copyMainToAux | ( | bool | overWriteIfExists = true | ) |
Copies the Buffer content to the Auxiliary Buffer
If there's no existent Auxiliary the method creates it and copies the content
If there's an Auxiliary, the method will proceed acording to the value passed in the parameter:
| overWriteIfExists | Indicates the authorization to overwrite the Auxiliary with the contents of the Main Buffer if the Auxiliary exists at the moment of the invocation. |
| true | The Auxiliary was non-existent, or existed and the parameter was true |
| false | The Auxiliary was existent and the parameter was false, not allowing the Auxiliary to be overwritten |

| uint8_t ShiftRegGPIOXpander::digitalReadSr | ( | const uint8_t & | srPin | ) |
Returns the state of the requested pin.
| srPin | Pin whose current value is required. |
| 0x00 | The pin state was LOW |
| 0x01 | The pin state was HIGH |
| 0xFF | ERROR, the pin number was beyond implemented limit |

| void ShiftRegGPIOXpander::digitalWriteSr | ( | const uint8_t | srPin, |
| const uint8_t | value ) |
Set a specific pin to either HIGH (0x01) or LOW (0x00).
| srPin | a positive value indicating which pin to set. The valid range is 0 <= srPin <= (srQty*8)-1 |
| value | Value to set for the indicated Pin |

| void ShiftRegGPIOXpander::digitalWriteSrMaskReset | ( | uint8_t * | newResetMask | ) |
Modifies the Main buffer contents by resetting simultaneously certain pins.
The pins to be reset are provided as a parameter pointer to a mask. Every bit position set (HIGH, 0x01) on the mask will be reset in the buffer, leaving the reset pins (LOW, 0x00) positions of the mask unmodified in the Main Buffer.
| newResetMask | Pointer to the array containing the mask to modify the Main. |

| void ShiftRegGPIOXpander::digitalWriteSrMaskSet | ( | uint8_t * | newSetMask | ) |
Modifies the Main buffer contents by setting simultaneously certain pins.
The pins to be set are provided as a parameter pointer to a mask. Every bit position set (HIGH, 0x01) on the mask will be set in the buffer, leaving the reset pins (LOW, 0x00) positions of the mask unmodified in the Main Buffer.
| newResetMask | Pointer to the array containing the mask to modify the Main. |

| void ShiftRegGPIOXpander::digitalWriteSrToAux | ( | const uint8_t | srPin, |
| const uint8_t | value ) |
Set a specific pin to either HIGH (0x01) or LOW (0x00) in the Auxiliary Buffer.
| srPin | a positive value indicating which pin to set. The valid range is 0 <= srPin <= (srQty*8)-1 |
| value | Value to set for the indicated Pin |

| void ShiftRegGPIOXpander::discardAux | ( | ) |
Deletes the Auxiliary Buffer.
Discards the contents of the Auxiliary Buffer, frees the memory allocated to it and nullyfies the corresponding memory pointer

| uint8_t * ShiftRegGPIOXpander::getMainBuffPtr | ( | ) |
Retrieves the pointer to the Main Buffer.
| uint8_t ShiftRegGPIOXpander::getMaxPin | ( | ) |
Return the greatest valid pin number.
The greatest valid pin number is directly related to the quantity of shift registers connected
| uint8_t ShiftRegGPIOXpander::getSrQty | ( | ) |
Return the quantity of shift registers composing the GPIOXtender object.
The value is passed as a parameter in the class constructor
| bool ShiftRegGPIOXpander::moveAuxToMain | ( | bool | flushASAP = true | ) |
Moves the data in the Auxiliary to the Main.
Moving the contents from the Auxiliary to the Main implies several steps:
| true | There was an Auxiliary an it's value could be moved |
| false | There was no Auxiliary present, no data have been moved |


| bool ShiftRegGPIOXpander::sendAllSRCntnt | ( | ) |
Flushes the contents of the Buffer to the GPIO Expander pins.
The method will ensure the object buffer is updated -if there are modifications pending in the Auxiliary Buffer- enable the hardware to receive the information and invoke the needed methods to send serially the information required to each physical shift register.
| flushASAP | indicates if the method should take care of sending the updated Main Buffer to the shift registers before exiting, or avoid doing so. The avoidance is related to the use of the method by another method or procedure that will take care of invoking a bool sendAllSRCntnt() by itself. |

| bool ShiftRegGPIOXpander::stampOverMain | ( | uint8_t * | newCntntPtr | ) |
Sets all of the output pins of the shift register to new provided values at once.
The method gives a tool to change all the shift registers pins in one operation instead of pin by pin. The method uses the provided pointer as a data source to overwrite the Main Buffer with the new contents.
| newCntntPtr | A uint8_t* pointing the memory area containing the new values to be set to the buffer |
| true | The Buffer was overwritten and the new contents flushed |
| false | The parameter passed was a nullptr/NULL and no overwritting was possible. |
