all: use less magic in memory-mapped IO

Don't store addresses in the values of registers, this leads to problems
with char arrays (among others). Instead, do it like it's done in C with
raw addresses cast to struct pointers.

This commit also splits gen-device.py, as AVR and ARM have very
different ideas of what a register is. It's easier to just keep them
separate.
This commit is contained in:
Ayke van Laethem
2018-09-05 11:29:15 +02:00
parent 93248c93ed
commit 17b5b6ec5b
7 changed files with 296 additions and 209 deletions
+8 -8
View File
@@ -19,15 +19,15 @@ const LED = 13
func (p GPIO) Configure(config GPIOConfig) {
if config.Mode == GPIO_OUTPUT { // set output bit
if p.Pin < 8 {
avr.PORT.DDRD |= 1 << p.Pin
*avr.DDRD |= 1 << p.Pin
} else {
avr.PORT.DDRB |= 1 << (p.Pin - 8)
*avr.DDRB |= 1 << (p.Pin - 8)
}
} else { // configure input: clear output bit
if p.Pin < 8 {
avr.PORT.DDRD &^= 1 << p.Pin
*avr.DDRD &^= 1 << p.Pin
} else {
avr.PORT.DDRB &^= 1 << (p.Pin - 8)
*avr.DDRB &^= 1 << (p.Pin - 8)
}
}
}
@@ -35,15 +35,15 @@ func (p GPIO) Configure(config GPIOConfig) {
func (p GPIO) Set(value bool) {
if value { // set bits
if p.Pin < 8 {
avr.PORT.PORTD |= 1 << p.Pin
*avr.PORTD |= 1 << p.Pin
} else {
avr.PORT.PORTB |= 1 << (p.Pin - 8)
*avr.PORTB |= 1 << (p.Pin - 8)
}
} else { // clear bits
if p.Pin < 8 {
avr.PORT.PORTB &^= 1 << p.Pin
*avr.PORTB &^= 1 << p.Pin
} else {
avr.PORT.PORTB &^= 1 << (p.Pin - 8)
*avr.PORTB &^= 1 << (p.Pin - 8)
}
}
}