github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/machine/machine_atmega1284p.go (about) 1 //go:build avr && atmega1284p 2 3 package machine 4 5 import ( 6 "device/avr" 7 "runtime/volatile" 8 ) 9 10 const irq_USART0_RX = avr.IRQ_USART0_RX 11 12 // Return the current CPU frequency in hertz. 13 func CPUFrequency() uint32 { 14 return 20000000 15 } 16 17 const ( 18 portA Pin = iota * 8 19 portB 20 portC 21 portD 22 ) 23 24 const ( 25 PA0 = portA + 0 26 PA1 = portA + 1 27 PA2 = portA + 2 28 PA3 = portA + 3 29 PA4 = portA + 4 30 PA5 = portA + 5 31 PA6 = portA + 6 32 PA7 = portA + 7 33 PB0 = portB + 0 34 PB1 = portB + 1 35 PB2 = portB + 2 36 PB3 = portB + 3 37 PB4 = portB + 4 38 PB5 = portB + 5 39 PB6 = portB + 6 40 PB7 = portB + 7 41 PC0 = portC + 0 42 PC1 = portC + 1 43 PC2 = portC + 2 44 PC3 = portC + 3 45 PC4 = portC + 4 46 PC5 = portC + 5 47 PC6 = portC + 6 48 PC7 = portC + 7 49 PD0 = portD + 0 50 PD1 = portD + 1 51 PD2 = portD + 2 52 PD3 = portD + 3 53 PD4 = portD + 4 54 PD5 = portD + 5 55 PD6 = portD + 6 56 PD7 = portD + 7 57 ) 58 59 // getPortMask returns the PORTx register and mask for the pin. 60 func (p Pin) getPortMask() (*volatile.Register8, uint8) { 61 switch { 62 case p >= PA0 && p <= PA7: 63 return avr.PORTA, 1 << uint8(p-portA) 64 case p >= PB0 && p <= PB7: 65 return avr.PORTB, 1 << uint8(p-portB) 66 case p >= PC0 && p <= PC7: 67 return avr.PORTC, 1 << uint8(p-portC) 68 default: 69 return avr.PORTD, 1 << uint8(p-portD) 70 } 71 } 72 73 // SPI configuration 74 var SPI0 = SPI{ 75 spcr: avr.SPCR, 76 spsr: avr.SPSR, 77 spdr: avr.SPDR, 78 sck: PB7, 79 sdo: PB5, 80 sdi: PB6, 81 cs: PB4}