Compare commits
2 Commits
e2f55b4284
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c530411395 | ||
|
|
545e7f380d |
36
io-helper.c
36
io-helper.c
@@ -1,10 +1,23 @@
|
||||
#include <avr/io.h>
|
||||
#include "io-helper.h"
|
||||
|
||||
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 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)
|
||||
@@ -18,12 +31,12 @@ void ioHelperCpArb(volatile uint8_t *source, uint16_t sourceNr,volatile uint8_t
|
||||
} else *(target+(targetNr/8))&=~(1<<(targetNr-((targetNr/8)*8)));
|
||||
}
|
||||
|
||||
volatile uint8_t ioHelperDebounceTable[nrOfInputs];
|
||||
volatile uint8_t ioHelperDebounceTable[32];
|
||||
|
||||
/* debounceing: */
|
||||
void ioHelperDebounce(void) {
|
||||
static volatile uint8_t tablePos=0;
|
||||
for(uint8_t i = 0; i<nrOfInputs; i++) {
|
||||
for(uint8_t i = 0; i<16; i++) {
|
||||
ioHelperCpArb(inStatesRaw,i,ioHelperDebounceTable,i*8+tablePos);
|
||||
if(ioHelperDebounceTable[i]==0) ioHelperSetBit(inStates,i,0);
|
||||
else if(ioHelperDebounceTable[i]==0xFF) ioHelperSetBit(inStates,i,1);
|
||||
@@ -69,17 +82,6 @@ uint8_t getBit0(uint8_t bit) {
|
||||
//}
|
||||
|
||||
void ioHelperIoConf(void) {
|
||||
for(uint8_t x=0; x<nrOfInputs; x++) {
|
||||
ioHelperDebounceTable[x]=0;
|
||||
}
|
||||
for(uint8_t x=0; x<nrOfInputs/8; x++) {
|
||||
inStates[x]=0;
|
||||
inStatesRaw[x]=0;
|
||||
}
|
||||
for(uint8_t x=0; x<nrOfOutputs/8; x++) {
|
||||
outStates[x]=0;
|
||||
}
|
||||
|
||||
#ifdef DDRA
|
||||
DDRA|=0
|
||||
#ifdef BitPA0
|
||||
|
||||
16
io-helper.h
16
io-helper.h
@@ -1,21 +1,23 @@
|
||||
#ifndef _IO_HELPER_
|
||||
#define _IO_HELPER_
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define nrOfOutputs 32 //must be multiple of 8
|
||||
#define nrOfInputs 32 //must be multiple of 8
|
||||
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];
|
||||
|
||||
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);
|
||||
|
||||
//Outputs
|
||||
//Pin | Bit in outStates
|
||||
|
||||
Reference in New Issue
Block a user