github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/machine/machine_atmega32u4.go (about)

     1  //go:build avr && atmega32u4
     2  
     3  package machine
     4  
     5  import (
     6  	"device/avr"
     7  	"runtime/volatile"
     8  )
     9  
    10  const (
    11  	// Note: start at port B because there is no port A.
    12  	portB Pin = iota * 8
    13  	portC
    14  	portD
    15  	portE
    16  	portF
    17  )
    18  
    19  const (
    20  	PB0 = portB + 0
    21  	PB1 = portB + 1 // peripherals: Timer1 channel A
    22  	PB2 = portB + 2 // peripherals: Timer1 channel B
    23  	PB3 = portB + 3 // peripherals: Timer2 channel A
    24  	PB4 = portB + 4
    25  	PB5 = portB + 5
    26  	PB6 = portB + 6
    27  	PB7 = portB + 7
    28  	PC0 = portC + 0
    29  	PC1 = portC + 1
    30  	PC2 = portC + 2
    31  	PC3 = portC + 3
    32  	PC4 = portC + 4
    33  	PC5 = portC + 5
    34  	PC6 = portC + 6
    35  	PC7 = portC + 7
    36  	PD0 = portD + 0
    37  	PD1 = portD + 1
    38  	PD2 = portD + 2
    39  	PD3 = portD + 3
    40  	PD4 = portD + 4
    41  	PD5 = portD + 5
    42  	PD6 = portD + 6
    43  	PD7 = portD + 7
    44  	PE0 = portE + 0
    45  	PE1 = portE + 1
    46  	PE2 = portE + 2
    47  	PE3 = portE + 3
    48  	PE4 = portE + 4
    49  	PE5 = portE + 5
    50  	PE6 = portE + 6
    51  	PE7 = portE + 7
    52  	PF0 = portF + 0
    53  	PF1 = portF + 1
    54  	PF2 = portF + 2
    55  	PF3 = portF + 3
    56  	PF4 = portF + 4
    57  	PF5 = portF + 5
    58  	PF6 = portF + 6
    59  	PF7 = portF + 7
    60  )
    61  
    62  // getPortMask returns the PORTx register and mask for the pin.
    63  func (p Pin) getPortMask() (*volatile.Register8, uint8) {
    64  	switch {
    65  	case p >= PB0 && p <= PB7: // port B
    66  		return avr.PORTB, 1 << uint8(p-portB)
    67  	case p >= PC0 && p <= PC7: // port C
    68  		return avr.PORTC, 1 << uint8(p-portC)
    69  	case p >= PD0 && p <= PD7: // port D
    70  		return avr.PORTD, 1 << uint8(p-portD)
    71  	case p >= PE0 && p <= PE7: // port E
    72  		return avr.PORTE, 1 << uint8(p-portE)
    73  	default: // port F
    74  		return avr.PORTF, 1 << uint8(p-portF)
    75  	}
    76  }