Add basic atmega32u support (#3337)
machine/atmega32u: add support for arduino leonardo
Этот коммит содержится в:
родитель
6cdc718bfb
коммит
e71e289e8b
6 изменённых файлов: 139 добавлений и 1 удалений
2
Makefile
2
Makefile
|
@ -680,6 +680,8 @@ endif
|
||||||
@$(MD5SUM) test.hex
|
@$(MD5SUM) test.hex
|
||||||
$(TINYGO) build -size short -o test.hex -target=arduino examples/blinky1
|
$(TINYGO) build -size short -o test.hex -target=arduino examples/blinky1
|
||||||
@$(MD5SUM) test.hex
|
@$(MD5SUM) test.hex
|
||||||
|
$(TINYGO) build -size short -o test.hex -target=arduino-leonardo examples/blinky1
|
||||||
|
@$(MD5SUM) test.hex
|
||||||
$(TINYGO) build -size short -o test.hex -target=arduino examples/pwm
|
$(TINYGO) build -size short -o test.hex -target=arduino examples/pwm
|
||||||
@$(MD5SUM) test.hex
|
@$(MD5SUM) test.hex
|
||||||
$(TINYGO) build -size short -o test.hex -target=arduino -scheduler=tasks examples/blinky1
|
$(TINYGO) build -size short -o test.hex -target=arduino -scheduler=tasks examples/blinky1
|
||||||
|
|
39
src/machine/board_arduino_leonardo.go
Обычный файл
39
src/machine/board_arduino_leonardo.go
Обычный файл
|
@ -0,0 +1,39 @@
|
||||||
|
//go:build arduino_leonardo
|
||||||
|
|
||||||
|
package machine
|
||||||
|
|
||||||
|
// Return the current CPU frequency in hertz.
|
||||||
|
func CPUFrequency() uint32 {
|
||||||
|
return 16000000
|
||||||
|
}
|
||||||
|
|
||||||
|
// Digital pins, marked as plain numbers on the board.
|
||||||
|
const (
|
||||||
|
D0 = PD2 // RX
|
||||||
|
D1 = PD3 // TX
|
||||||
|
D2 = PD1
|
||||||
|
D3 = PD0
|
||||||
|
D4 = PD4
|
||||||
|
D5 = PC6
|
||||||
|
D6 = PD7
|
||||||
|
D7 = PE6
|
||||||
|
D8 = PB4
|
||||||
|
D9 = PB5
|
||||||
|
D10 = PB6
|
||||||
|
D11 = PB7
|
||||||
|
D12 = PD6
|
||||||
|
D13 = PC7
|
||||||
|
)
|
||||||
|
|
||||||
|
// LED on the Arduino
|
||||||
|
const LED Pin = D13
|
||||||
|
|
||||||
|
// ADC on the Arduino
|
||||||
|
const (
|
||||||
|
ADC0 Pin = PF7
|
||||||
|
ADC1 Pin = PF6
|
||||||
|
ADC2 Pin = PF5
|
||||||
|
ADC3 Pin = PF4
|
||||||
|
ADC4 Pin = PF1
|
||||||
|
ADC5 Pin = PF0
|
||||||
|
)
|
76
src/machine/machine_atmega32u4.go
Обычный файл
76
src/machine/machine_atmega32u4.go
Обычный файл
|
@ -0,0 +1,76 @@
|
||||||
|
//go:build avr && atmega32u4
|
||||||
|
|
||||||
|
package machine
|
||||||
|
|
||||||
|
import (
|
||||||
|
"device/avr"
|
||||||
|
"runtime/volatile"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Note: start at port B because there is no port A.
|
||||||
|
portB Pin = iota * 8
|
||||||
|
portC
|
||||||
|
portD
|
||||||
|
portE
|
||||||
|
portF
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
PB0 = portB + 0
|
||||||
|
PB1 = portB + 1 // peripherals: Timer1 channel A
|
||||||
|
PB2 = portB + 2 // peripherals: Timer1 channel B
|
||||||
|
PB3 = portB + 3 // peripherals: Timer2 channel A
|
||||||
|
PB4 = portB + 4
|
||||||
|
PB5 = portB + 5
|
||||||
|
PB6 = portB + 6
|
||||||
|
PB7 = portB + 7
|
||||||
|
PC0 = portC + 0
|
||||||
|
PC1 = portC + 1
|
||||||
|
PC2 = portC + 2
|
||||||
|
PC3 = portC + 3
|
||||||
|
PC4 = portC + 4
|
||||||
|
PC5 = portC + 5
|
||||||
|
PC6 = portC + 6
|
||||||
|
PC7 = portC + 7
|
||||||
|
PD0 = portD + 0
|
||||||
|
PD1 = portD + 1
|
||||||
|
PD2 = portD + 2
|
||||||
|
PD3 = portD + 3
|
||||||
|
PD4 = portD + 4
|
||||||
|
PD5 = portD + 5
|
||||||
|
PD6 = portD + 6
|
||||||
|
PD7 = portD + 7
|
||||||
|
PE0 = portE + 0
|
||||||
|
PE1 = portE + 1
|
||||||
|
PE2 = portE + 2
|
||||||
|
PE3 = portE + 3
|
||||||
|
PE4 = portE + 4
|
||||||
|
PE5 = portE + 5
|
||||||
|
PE6 = portE + 6
|
||||||
|
PE7 = portE + 7
|
||||||
|
PF0 = portF + 0
|
||||||
|
PF1 = portF + 1
|
||||||
|
PF2 = portF + 2
|
||||||
|
PF3 = portF + 3
|
||||||
|
PF4 = portF + 4
|
||||||
|
PF5 = portF + 5
|
||||||
|
PF6 = portF + 6
|
||||||
|
PF7 = portF + 7
|
||||||
|
)
|
||||||
|
|
||||||
|
// getPortMask returns the PORTx register and mask for the pin.
|
||||||
|
func (p Pin) getPortMask() (*volatile.Register8, uint8) {
|
||||||
|
switch {
|
||||||
|
case p >= PB0 && p <= PB7: // port B
|
||||||
|
return avr.PORTB, 1 << uint8(p-portB)
|
||||||
|
case p >= PC0 && p <= PC7: // port C
|
||||||
|
return avr.PORTC, 1 << uint8(p-portC)
|
||||||
|
case p >= PD0 && p <= PD7: // port D
|
||||||
|
return avr.PORTD, 1 << uint8(p-portD)
|
||||||
|
case p >= PE0 && p <= PE7: // port E
|
||||||
|
return avr.PORTE, 1 << uint8(p-portE)
|
||||||
|
default: // port F
|
||||||
|
return avr.PORTF, 1 << uint8(p-portF)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
//go:build avr && atmega
|
//go:build avr && (atmega || atmega32u4)
|
||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
|
|
10
targets/arduino-leonardo.json
Обычный файл
10
targets/arduino-leonardo.json
Обычный файл
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"inherits": ["atmega32u4"],
|
||||||
|
"build-tags": ["arduino_leonardo"],
|
||||||
|
"ldflags": [
|
||||||
|
"--defsym=_bootloader_size=512",
|
||||||
|
"--defsym=_stack_size=512"
|
||||||
|
],
|
||||||
|
"flash-command": "avrdude -c avr109 -p atmega32u4 -b 57600 -P {port} -U flash:w:{hex}:i",
|
||||||
|
"emulator": "simavr -m atmega32u4 -f 16000000 {}"
|
||||||
|
}
|
11
targets/atmega32u4.json
Обычный файл
11
targets/atmega32u4.json
Обычный файл
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"inherits": ["avr"],
|
||||||
|
"cpu": "atmega32u4",
|
||||||
|
"build-tags": ["atmega32u4", "avr5"],
|
||||||
|
"serial": "none",
|
||||||
|
"linkerscript": "src/device/avr/atmega32u4.ld",
|
||||||
|
"extra-files": [
|
||||||
|
"targets/avr.S",
|
||||||
|
"src/device/avr/atmega32u4.s"
|
||||||
|
]
|
||||||
|
}
|
Загрузка…
Создание таблицы
Сослаться в новой задаче