Compare commits

...

4 Commits

Author SHA1 Message Date
e2f55b4284 fix whitespace 2022-10-15 05:18:14 +02:00
e9dae2fdee fix indent 2022-10-15 05:17:15 +02:00
Max Brüggemann
f473da9c3f Nr of IOs now settable using defines 2021-08-23 19:37:37 +02:00
Max Brüggemann
3828826957 Fix missing header guards 2021-08-22 00:24:44 +02:00
3 changed files with 2205 additions and 2183 deletions

View File

@@ -1,10 +1,10 @@
#include <avr/io.h> #include <avr/io.h>
#include "io-helper.h" #include "io-helper.h"
volatile uint8_t outStates[]={0,0,0,0}; volatile uint8_t outStates[nrOfOutputs/8];
volatile uint8_t inStatesRaw[] = {0,0,0,0}; volatile uint8_t inStatesRaw[nrOfInputs/8];
volatile uint8_t inStates[] = {0,0,0,0}; volatile uint8_t inStates[nrOfInputs/8];
volatile uint8_t oldInstates[] = {0,0,0,0}; volatile uint8_t oldInstates[nrOfInputs/8];
/* @brief: copies a single bit from one char to another char (or arrays thereof) /* @brief: copies a single bit from one char to another char (or arrays thereof)
@@ -18,12 +18,12 @@ void ioHelperCpArb(volatile uint8_t *source, uint16_t sourceNr,volatile uint8_t
} else *(target+(targetNr/8))&=~(1<<(targetNr-((targetNr/8)*8))); } else *(target+(targetNr/8))&=~(1<<(targetNr-((targetNr/8)*8)));
} }
volatile uint8_t ioHelperDebounceTable[32]; volatile uint8_t ioHelperDebounceTable[nrOfInputs];
/* debounceing: */ /* debounceing: */
void ioHelperDebounce(void) { void ioHelperDebounce(void) {
static volatile uint8_t tablePos=0; static volatile uint8_t tablePos=0;
for(uint8_t i = 0; i<16; i++) { for(uint8_t i = 0; i<nrOfInputs; i++) {
ioHelperCpArb(inStatesRaw,i,ioHelperDebounceTable,i*8+tablePos); ioHelperCpArb(inStatesRaw,i,ioHelperDebounceTable,i*8+tablePos);
if(ioHelperDebounceTable[i]==0) ioHelperSetBit(inStates,i,0); if(ioHelperDebounceTable[i]==0) ioHelperSetBit(inStates,i,0);
else if(ioHelperDebounceTable[i]==0xFF) ioHelperSetBit(inStates,i,1); else if(ioHelperDebounceTable[i]==0xFF) ioHelperSetBit(inStates,i,1);
@@ -69,6 +69,17 @@ uint8_t getBit0(uint8_t bit) {
//} //}
void ioHelperIoConf(void) { 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 #ifdef DDRA
DDRA|=0 DDRA|=0
#ifdef BitPA0 #ifdef BitPA0

View File

@@ -1,5 +1,14 @@
extern volatile uint8_t outStates[4]; #ifndef _IO_HELPER_
extern volatile uint8_t inStates[4]; #define _IO_HELPER_
#include <avr/io.h>
#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 ioHelperSetOuts(void);
void ioHelperReadPins(void); void ioHelperReadPins(void);
void ioHelperIoConf(void); void ioHelperIoConf(void);
@@ -17,3 +26,5 @@ void ioHelperDebounce(void);
//Pin | Bit in inStates //Pin | Bit in inStates
#define BitPinC1 0 #define BitPinC1 0
#define BitPinC5 1 #define BitPinC5 1
#endif