avr: attempt to abstract IO code.
doesn't work with avra because of macro argument problems.
This commit is contained in:
257
avr/devices/all/io_1.asm
Normal file
257
avr/devices/all/io_1.asm
Normal file
@@ -0,0 +1,257 @@
|
||||
; ***************************************************************************
|
||||
; copyright : (C) 2026 by Martin Preuss
|
||||
; email : martin@libchipcard.de
|
||||
;
|
||||
; ***************************************************************************
|
||||
; * This file is part of the project "AqHome". *
|
||||
; * Please see toplevel file COPYING of that project for license details. *
|
||||
; ***************************************************************************
|
||||
|
||||
#ifndef AQH_AVR_DEVICES_ALL_IO1_ASM
|
||||
#define AQH_AVR_DEVICES_ALL_IO1_ASM
|
||||
|
||||
|
||||
.equ IO_PORT_A = 0
|
||||
.equ IO_PORT_B = 1
|
||||
.equ IO_PORT_C = 2
|
||||
.equ IO_PORT_D = 3
|
||||
.equ IO_PORT_E = 4
|
||||
|
||||
|
||||
.equ IO_PIN_0 = 0
|
||||
.equ IO_PIN_1 = 1
|
||||
.equ IO_PIN_2 = 2
|
||||
.equ IO_PIN_3 = 3
|
||||
.equ IO_PIN_4 = 4
|
||||
.equ IO_PIN_5 = 5
|
||||
.equ IO_PIN_6 = 6
|
||||
.equ IO_PIN_7 = 7
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @macro IO_SET_INPUT
|
||||
;
|
||||
; @param %0 port
|
||||
; @param %1 pin
|
||||
|
||||
.macro IO_SET_INPUT
|
||||
.if (@0 == IO_PORT_A)
|
||||
cbi DDRA, @1
|
||||
.elif (@0 == IO_PORT_B)
|
||||
cbi DDRB, @1
|
||||
.elif (@0 == IO_PORT_C)
|
||||
.ifdef DDRC
|
||||
cbi DDRC, @1
|
||||
.else
|
||||
.error "No port C for this device"
|
||||
.endif
|
||||
.elif (@0 == IO_PORT_D)
|
||||
.ifdef DDRD
|
||||
cbi DDRD, @1
|
||||
.else
|
||||
.error "No port D for this device"
|
||||
.endif
|
||||
.elif (@0 == IO_PORT_E)
|
||||
.ifdef DDRE
|
||||
cbi DDRE, @1
|
||||
.else
|
||||
.error "No port E for this device"
|
||||
.endif
|
||||
.else
|
||||
.error "Invalid Port @0"
|
||||
.endif
|
||||
.endmacro
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @macro IO_SET_OUTPUT
|
||||
;
|
||||
; @param %0 port
|
||||
; @param %1 pin
|
||||
|
||||
.macro IO_SET_OUTPUT
|
||||
.if @0 == IO_PORT_A
|
||||
sbi DDRA, @1
|
||||
.elif @0 == IO_PORT_B
|
||||
sbi DDRB, @1
|
||||
.elif @0 == IO_PORT_C
|
||||
.ifdef DDRC
|
||||
sbi DDRC, @1
|
||||
.else
|
||||
.error "No port C for this device"
|
||||
.endif
|
||||
.elif @0 == IO_PORT_D
|
||||
.ifdef DDRD
|
||||
sbi DDRD, @1
|
||||
.else
|
||||
.error "No port D for this device"
|
||||
.endif
|
||||
.elif @0 == IO_PORT_E
|
||||
.ifdef DDRE
|
||||
sbi DDRE, @1
|
||||
.else
|
||||
.error "No port E for this device"
|
||||
.endif
|
||||
.else
|
||||
.error "Invalid Port @0"
|
||||
.endif
|
||||
.endmacro
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @macro IO_CLR_PIN
|
||||
;
|
||||
; @param %0 port
|
||||
; @param %1 pin
|
||||
|
||||
.macro IO_CLR_PIN
|
||||
.if @0 == IO_PORT_A
|
||||
cbi PORTA, @1
|
||||
.elif @0 == IO_PORT_B
|
||||
cbi PORTB, @1
|
||||
.elif @0 == IO_PORT_C
|
||||
.ifdef PORTC
|
||||
cbi PORTC, @1
|
||||
.else
|
||||
.error "No port C for this device"
|
||||
.endif
|
||||
.elif @0 == IO_PORT_D
|
||||
.ifdef PORTD
|
||||
cbi PORTD, @1
|
||||
.else
|
||||
.error "No port D for this device"
|
||||
.endif
|
||||
.elif @0 == IO_PORT_E
|
||||
.ifdef PORTE
|
||||
cbi PORTE, @1
|
||||
.else
|
||||
.error "No port E for this device"
|
||||
.endif
|
||||
.else
|
||||
.error "Invalid Port @0"
|
||||
.endif
|
||||
.endmacro
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @macro IO_SET_PIN
|
||||
;
|
||||
; @param %0 port
|
||||
; @param %1 pin
|
||||
|
||||
.macro IO_SET_PIN
|
||||
.if @0 == IO_PORT_A
|
||||
sbi PORTA, @1
|
||||
.elif @0 == IO_PORT_B
|
||||
sbi PORTB, @1
|
||||
.elif @0 == IO_PORT_C
|
||||
.ifdef PORTC
|
||||
sbi PORTC, @1
|
||||
.else
|
||||
.error "No port C for this device"
|
||||
.endif
|
||||
.elif @0 == IO_PORT_D
|
||||
.ifdef PORTD
|
||||
sbi PORTD, @1
|
||||
.else
|
||||
.error "No port D for this device"
|
||||
.endif
|
||||
.elif @0 == IO_PORT_E
|
||||
.ifdef PORTE
|
||||
sbi PORTE, @1
|
||||
.else
|
||||
.error "No port E for this device"
|
||||
.endif
|
||||
.else
|
||||
.error "Invalid Port @0"
|
||||
.endif
|
||||
.endmacro
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @macro IO_READ_PORT
|
||||
;
|
||||
; @param %0 port
|
||||
; @param %1 dest register
|
||||
|
||||
.macro IO_READ_PORT
|
||||
.if @0 == IO_PORT_A
|
||||
inr @1, PINA
|
||||
.elif @0 == IO_PORT_B
|
||||
inr @1, PINB
|
||||
.elif @0 == IO_PORT_C
|
||||
.ifdef PINC
|
||||
inr @1, PINC
|
||||
.else
|
||||
.error "No port C for this device"
|
||||
.endif
|
||||
.elif @0 == IO_PORT_D
|
||||
.ifdef PIND
|
||||
inr @1, PIND
|
||||
.else
|
||||
.error "No port D for this device"
|
||||
.endif
|
||||
.elif @0 == IO_PORT_E
|
||||
.ifdef PINE
|
||||
inr @1, PINE
|
||||
.else
|
||||
.error "No port E for this device"
|
||||
.endif
|
||||
.else
|
||||
.error "Invalid Port @0"
|
||||
.endif
|
||||
.endmacro
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @macro IO_WRITE_PORT
|
||||
;
|
||||
; @param %0 port
|
||||
; @param %1 dest register
|
||||
|
||||
.macro IO_WRITE_PORT
|
||||
.if @0 == IO_PORT_A
|
||||
outr PORTA, @1
|
||||
.elif @0 == IO_PORT_B
|
||||
outr PORTB, @1
|
||||
.elif @0 == IO_PORT_C
|
||||
.ifdef PORTC
|
||||
outr PORTC, @1
|
||||
.else
|
||||
.error "No port C for this device"
|
||||
.endif
|
||||
.elif @0 == IO_PORT_D
|
||||
.ifdef PORTD
|
||||
outr PORTD, @1
|
||||
.else
|
||||
.error "No port D for this device"
|
||||
.endif
|
||||
.elif @0 == IO_PORT_E
|
||||
.ifdef PORTE
|
||||
outr PORTE, @1
|
||||
.else
|
||||
.error "No port E for this device"
|
||||
.endif
|
||||
.else
|
||||
.error "Invalid Port @0"
|
||||
.endif
|
||||
.endmacro
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user