merge edge detection and blink by nowka

newsource
Eggert Jung 3 years ago
parent e355efd233
commit a39486c0fc

@ -5,8 +5,69 @@
volatile uint8_t outStates[nrOfOutputs/8];
volatile uint8_t inStatesRaw[nrOfInputs/8];
volatile uint8_t inStates[nrOfInputs/8];
volatile uint8_t oldInstates[nrOfInputs/8];
volatile uint8_t outStatesBlinking[nrOfOutputs/8];
volatile uint8_t oldInstates[nrOfInputs/8];
volatile uint8_t inStatesBothEdges[nrOfInputs/8];
volatile uint8_t inStatesRisingEdge[nrOfInputs/8];
volatile uint8_t inStatesFallingEdge[nrOfInputs/8];
uint8_t read_Input(uint8_t nr, uint8_t type) {
uint8_t state = 0;
switch (type) {
case LEVEL:
state = ioHelperReadBit(inStates, nr);
break;
case EDGE:
state = ioHelperReadBit(inStatesBothEdges, nr);
ioHelperSetBit(inStatesBothEdges, nr, 0);
break;
case RISING:
state = ioHelperReadBit(inStatesRisingEdge, nr);
ioHelperSetBit(inStatesRisingEdge, nr, 0);
break;
case FALLING:
state = ioHelperReadBit(inStatesFallingEdge, nr);
ioHelperSetBit(inStatesFallingEdge, nr, 0);
break;
}
return state;
}
void set_Output(uint8_t nr, uint8_t state) {
switch (state) {
case BLINK:
ioHelperSetBit(outStatesBlinking, nr, ON);
break;
case TOGGLE:
ioHelperSetBit(outStatesBlinking, nr, OFF);
if (ioHelperReadBit(outStates, nr)) {
ioHelperSetBit(outStates, nr, OFF);
} else {
ioHelperSetBit(outStates, nr, ON);
}
break;
case ON:
ioHelperSetBit(outStates, nr, ON);
ioHelperSetBit(outStatesBlinking, nr, OFF);
break;
case OFF:
ioHelperSetBit(outStates, nr, OFF);
ioHelperSetBit(outStatesBlinking, nr, OFF);
break;
}
}
void ioHelperEdgeDetector(void){
for (uint8_t i = 0; i < nrOfInputs/8; 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)
*

@ -3,19 +3,33 @@
#include <avr/io.h>
#define LEVEL 0
#define EDGE 1
#define RISING 2
#define FALLING 3
#define OFF 0
#define ON 1
#define BLINK 2
#define TOGGLE 3
#define nrOfOutputs 32 //must be multiple of 8
#define nrOfInputs 32 //must be multiple of 8
extern volatile uint8_t outStates[nrOfOutputs/8];
extern volatile uint8_t inStates[nrOfInputs/8];
extern volatile uint8_t ioHelperDebounceTable[nrOfInputs];
void ioHelperSetOuts(void);
void ioHelperReadPins(void);
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);
uint8_t read_Input(uint8_t nr, uint8_t type);
void set_Output(uint8_t nr, uint8_t state);
//Outputs
//Pin | Bit in outStates

@ -1,6 +1,7 @@
import string
ddr="""#ifdef DDRA
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
DDRA|=0
#ifdef BitPA0
|(1<<0)
@ -27,13 +28,14 @@ DDRA|=0
|(1<<7)
#endif
|0;
}
#endif
"""
port="""
#ifdef PORTA
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
PORTA|=0
#ifdef BitPA0
|(getBit1(BitPA0)<<0)
@ -60,7 +62,9 @@ PORTA|=0
|(getBit1(BitPA7)<<7)
#endif
|0;
}
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
PORTA&=~(0
#ifdef BitPA0
|(getBit0(BitPA0)<<0)
@ -87,6 +91,7 @@ PORTA&=~(0
|(getBit0(BitPA7)<<7)
#endif
|0);
}
#endif
"""

Loading…
Cancel
Save