add io helper lib
							parent
							
								
									e2a9d85b76
								
							
						
					
					
						commit
						979856fd12
					
				
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								| @ -0,0 +1,96 @@ | |||||||
|  | #ifndef _IO_HELPER_ | ||||||
|  | #define _IO_HELPER_ | ||||||
|  | 
 | ||||||
|  | #include <stdint.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 NUMBER_OF_INPUT_BYTES 2 | ||||||
|  | 
 | ||||||
|  | extern volatile uint8_t outStates[NUMBER_OF_INPUT_BYTES];  | ||||||
|  | extern volatile uint8_t outStatesBlinking[NUMBER_OF_INPUT_BYTES]; | ||||||
|  | extern volatile uint8_t inStates[NUMBER_OF_INPUT_BYTES]; | ||||||
|  | extern volatile uint8_t inStatesRaw[NUMBER_OF_INPUT_BYTES]; | ||||||
|  | extern volatile uint8_t ioHelperDebounceTable[NUMBER_OF_INPUT_BYTES*8]; | ||||||
|  | extern volatile uint8_t oldInstates[NUMBER_OF_INPUT_BYTES]; | ||||||
|  | extern volatile uint8_t inStatesBothEdges[NUMBER_OF_INPUT_BYTES]; | ||||||
|  | extern volatile uint8_t inStatesRisingEdge[NUMBER_OF_INPUT_BYTES]; | ||||||
|  | extern volatile uint8_t inStatesFallingEdge[NUMBER_OF_INPUT_BYTES]; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | uint8_t read_Input(uint8_t nr, uint8_t type); | ||||||
|  | void set_Output(uint8_t nr, uint8_t state); | ||||||
|  | 
 | ||||||
|  | void ioHelperInitBuffer(void); | ||||||
|  | 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
 | ||||||
|  | //Verknüpfen von Pin | Bit mit Bitposition (0...n) outStates[0...n/8].
 | ||||||
|  | #define BitPE4 0  //D0
 | ||||||
|  | #define BitPE5 1  //D1
 | ||||||
|  | #define BitPG5 2  //D2
 | ||||||
|  | #define BitPE3 3  //D3
 | ||||||
|  | #define BitPH3 4  //D4
 | ||||||
|  | #define BitPH4 5  //D5
 | ||||||
|  | #define BitPH5 6  //D6
 | ||||||
|  | #define BitPH6 7  //D7
 | ||||||
|  | 
 | ||||||
|  | #define BitPB4 8  //D8
 | ||||||
|  | #define BitPB5 9  //D9
 | ||||||
|  | #define BitPB6 10 //D10
 | ||||||
|  | #define BitPB7 11 //D11
 | ||||||
|  | 
 | ||||||
|  | #define LED_ROT_NOTAUS_SCHRANK  BitPG5 | ||||||
|  | #define LED_GRN_NOTAUS_SCHRANK  BitPE3 | ||||||
|  | #define LED_ROT_NOTAUS_ANLAGE   BitPH3 | ||||||
|  | #define LED_GRN_NOTAUS_ANLAGE   BitPH4 | ||||||
|  | #define LED_PLC_OK              BitPB5 | ||||||
|  | #define LED_BUS_OK              BitPB6 | ||||||
|  | #define LED_ZUMBACH             BitPH5 | ||||||
|  | #define LED_LUEFTER             BitPH6 | ||||||
|  | #define SCHUETZ_ZUMBACH         BitPE5 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | //Inputs
 | ||||||
|  | //Verknüpfen von Pin | Bit mit Bitposition (0...n) inStates[0...n/8].
 | ||||||
|  | #define BitPinF0 0  //A0
 | ||||||
|  | #define BitPinF1 1  //A1
 | ||||||
|  | #define BitPinF2 2  //A2
 | ||||||
|  | #define BitPinF3 3  //A3
 | ||||||
|  | #define BitPinF4 4  //A4
 | ||||||
|  | #define BitPinF5 5  //A5
 | ||||||
|  | #define BitPinF6 6  //A6
 | ||||||
|  | #define BitPinF7 7  //A7
 | ||||||
|  | 
 | ||||||
|  | #define BitPinK0 8  //A8
 | ||||||
|  | #define BitPinK1 9  //A9
 | ||||||
|  | #define BitPinD3 10 //INO
 | ||||||
|  | #define BitPinD2 11 //IN1
 | ||||||
|  | 
 | ||||||
|  | #define BTN_ZUMBACH_EIN         BitPinF2 | ||||||
|  | #define BTN_ZUMBACH_AUS         BitPinF3 | ||||||
|  | #define BTN_LUEFTER_EIN         BitPinF4 | ||||||
|  | #define BTN_LUEFTER_AUS         BitPinF5 | ||||||
|  | #define BTN_LUEFTER_PLUS        BitPinF6 | ||||||
|  | #define BTN_LUEFTER_MINUS       BitPinF7 | ||||||
|  | #define BTN_ANLAGE_EIN          BitPinD3 | ||||||
|  | #define IN_ANLAGE_EIN           BitPinD2 | ||||||
|  | #define IN_NOTAUS_ANLAGE        BitPinF0 | ||||||
|  | #define IN_NOTAUS_SCHRANK       BitPinF1 | ||||||
|  | 
 | ||||||
|  | #endif | ||||||
| @ -0,0 +1,155 @@ | |||||||
|  | import string | ||||||
|  | 
 | ||||||
|  | ddr="""#ifdef DDRA | ||||||
|  | DDRA|=0  | ||||||
|  | #ifdef BitPA0 | ||||||
|  | |(1<<0)       | ||||||
|  | #endif        | ||||||
|  | #ifdef BitPA1 | ||||||
|  | |(1<<1)       | ||||||
|  | #endif        | ||||||
|  | #ifdef BitPA2 | ||||||
|  | |(1<<2)       | ||||||
|  | #endif        | ||||||
|  | #ifdef BitPA3 | ||||||
|  | |(1<<3)       | ||||||
|  | #endif        | ||||||
|  | #ifdef BitPA4 | ||||||
|  | |(1<<4)       | ||||||
|  | #endif        | ||||||
|  | #ifdef BitPA5 | ||||||
|  | |(1<<5)       | ||||||
|  | #endif        | ||||||
|  | #ifdef BitPA6 | ||||||
|  | |(1<<6)       | ||||||
|  | #endif        | ||||||
|  | #ifdef BitPA7 | ||||||
|  | |(1<<7)       | ||||||
|  | #endif        | ||||||
|  | |0;           | ||||||
|  |              | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  | """ | ||||||
|  | 
 | ||||||
|  | port=""" | ||||||
|  | #ifdef PORTA | ||||||
|  | PORTA|=0 | ||||||
|  | #ifdef BitPA0 | ||||||
|  | |(getBit1(BitPA0)<<0) | ||||||
|  | #endif | ||||||
|  | #ifdef BitPA1 | ||||||
|  | |(getBit1(BitPA1)<<1) | ||||||
|  | #endif | ||||||
|  | #ifdef BitPA2 | ||||||
|  | |(getBit1(BitPA2)<<2) | ||||||
|  | #endif | ||||||
|  | #ifdef BitPA3 | ||||||
|  | |(getBit1(BitPA3)<<3) | ||||||
|  | #endif | ||||||
|  | #ifdef BitPA4 | ||||||
|  | |(getBit1(BitPA4)<<4) | ||||||
|  | #endif | ||||||
|  | #ifdef BitPA5 | ||||||
|  | |(getBit1(BitPA5)<<5) | ||||||
|  | #endif | ||||||
|  | #ifdef BitPA6 | ||||||
|  | |(getBit1(BitPA6)<<6) | ||||||
|  | #endif | ||||||
|  | #ifdef BitPA7 | ||||||
|  | |(getBit1(BitPA7)<<7) | ||||||
|  | #endif | ||||||
|  | |0; | ||||||
|  | 
 | ||||||
|  | PORTA&=~(0 | ||||||
|  | #ifdef BitPA0 | ||||||
|  | |(getBit0(BitPA0)<<0) | ||||||
|  | #endif | ||||||
|  | #ifdef BitPA1 | ||||||
|  | |(getBit0(BitPA1)<<1) | ||||||
|  | #endif | ||||||
|  | #ifdef BitPA2 | ||||||
|  | |(getBit0(BitPA2)<<2) | ||||||
|  | #endif | ||||||
|  | #ifdef BitPA3 | ||||||
|  | |(getBit0(BitPA3)<<3) | ||||||
|  | #endif | ||||||
|  | #ifdef BitPA4 | ||||||
|  | |(getBit0(BitPA4)<<4) | ||||||
|  | #endif | ||||||
|  | #ifdef BitPA5 | ||||||
|  | |(getBit0(BitPA5)<<5) | ||||||
|  | #endif | ||||||
|  | #ifdef BitPA6 | ||||||
|  | |(getBit0(BitPA6)<<6) | ||||||
|  | #endif | ||||||
|  | #ifdef BitPA7 | ||||||
|  | |(getBit0(BitPA7)<<7) | ||||||
|  | #endif | ||||||
|  | |0); | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  | """ | ||||||
|  | 
 | ||||||
|  | pin=""" | ||||||
|  | #ifdef PINA | ||||||
|  | #ifdef BitPinA0 | ||||||
|  | ioHelperCpBit(PINA,0,BitPinA0); | ||||||
|  | #endif | ||||||
|  | #ifdef BitPinA1 | ||||||
|  | ioHelperCpBit(PINA,1,BitPinA1); | ||||||
|  | #endif | ||||||
|  | #ifdef BitPinA2 | ||||||
|  | ioHelperCpBit(PINA,2,BitPinA2); | ||||||
|  | #endif | ||||||
|  | #ifdef BitPinA3 | ||||||
|  | ioHelperCpBit(PINA,3,BitPinA3); | ||||||
|  | #endif | ||||||
|  | #ifdef BitPinA4 | ||||||
|  | ioHelperCpBit(PINA,4,BitPinA4); | ||||||
|  | #endif | ||||||
|  | #ifdef BitPinA5 | ||||||
|  | ioHelperCpBit(PINA,5,BitPinA5); | ||||||
|  | #endif | ||||||
|  | #ifdef BitPinA6 | ||||||
|  | ioHelperCpBit(PINA,6,BitPinA6); | ||||||
|  | #endif | ||||||
|  | #ifdef BitPinA7 | ||||||
|  | ioHelperCpBit(PINA,7,BitPinA7); | ||||||
|  | #endif | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  | """ | ||||||
|  | 
 | ||||||
|  | port_letters=list(string.ascii_uppercase); | ||||||
|  | 
 | ||||||
|  | allddr=[] | ||||||
|  | for x in range(0,len(port_letters)): | ||||||
|  |     allddr.append(ddr) | ||||||
|  |     allddr[x]=allddr[x].replace("DDRA","DDR"+port_letters[x]) | ||||||
|  |     allddr[x]=allddr[x].replace("BitPA","BitP"+port_letters[x]) | ||||||
|  | 
 | ||||||
|  | allport=[] | ||||||
|  | for x in range(0,len(port_letters)): | ||||||
|  |     allport.append(port) | ||||||
|  |     allport[x]=allport[x].replace("PORTA","PORT"+port_letters[x]) | ||||||
|  |     allport[x]=allport[x].replace("BitPA","BitP"+port_letters[x]) | ||||||
|  | 
 | ||||||
|  | allpin=[] | ||||||
|  | for x in range(0,len(port_letters)): | ||||||
|  |     allpin.append(pin) | ||||||
|  |     allpin[x]=allpin[x].replace("PINA","PIN"+port_letters[x]) | ||||||
|  |     allpin[x]=allpin[x].replace("BitPinA","BitPin"+port_letters[x]) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | for x in allddr: | ||||||
|  |     #print(x) | ||||||
|  |     pass | ||||||
|  | 
 | ||||||
|  | for x in allport: | ||||||
|  |     #print(x) | ||||||
|  |     pass | ||||||
|  | 
 | ||||||
|  | for x in allpin: | ||||||
|  |     print(x) | ||||||
|  |     pass | ||||||
		Reference in New Issue