diff --git a/io-helper.c b/io-helper.c index d9e8fe1..25eb2e1 100644 --- a/io-helper.c +++ b/io-helper.c @@ -4,7 +4,20 @@ volatile uint8_t outStates[]={0,0,0,0}; volatile uint8_t inStatesRaw[] = {0,0,0,0}; volatile uint8_t inStates[] = {0,0,0,0}; + volatile uint8_t oldInstates[] = {0,0,0,0}; +volatile uint8_t inStatesBothEdges[] = {0,0,0,0}; +volatile uint8_t inStatesRisingEdge[] = {0,0,0,0}; +volatile uint8_t inStatesFallingEdge[] = {0,0,0,0}; + +void ioHelperEdgeDetector(void){ + for (uint8_t i = 0; i < 4; i++){ + inStatesBothEdges[i] = oldInstates[i] ^ inStates[i]; + inStatesRisingEdge[i] = inStatesBothEdges[i] & inStates[i]; + inStatesFallingEdge[i] = inStatesBothEdges[i] & oldInstates[i]; + oldInstates[i] = inStates[i]; + } +} /* @brief: copies a single bit from one char to another char (or arrays thereof) diff --git a/io-helper.h b/io-helper.h index 779f8ae..8f9edc9 100644 --- a/io-helper.h +++ b/io-helper.h @@ -6,6 +6,10 @@ extern volatile uint8_t outStates[4]; extern volatile uint8_t inStates[4]; extern volatile uint8_t ioHelperDebounceTable[32]; +extern volatile uint8_t oldInstates[4]; +extern volatile uint8_t inStatesBothEdges[4]; +extern volatile uint8_t inStatesRisingEdge[4]; +extern volatile uint8_t inStatesFallingEdge[4]; void ioHelperSetOuts(void); void ioHelperReadPins(void); @@ -13,7 +17,7 @@ void ioHelperIoConf(void); void ioHelperSetBit(volatile uint8_t *list, uint8_t nr, uint8_t state); unsigned char ioHelperReadBit(volatile uint8_t *list, uint8_t nr); void ioHelperDebounce(void); - +void ioHelperEdgeDetector(void); //Outputs //Pin | Bit in outStates