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

     1  //go:build attiny1616
     2  
     3  package machine
     4  
     5  import (
     6  	"device/avr"
     7  )
     8  
     9  const (
    10  	portA Pin = iota * 8
    11  	portB
    12  	portC
    13  )
    14  
    15  const (
    16  	PA0 = portA + 0
    17  	PA1 = portA + 1
    18  	PA2 = portA + 2
    19  	PA3 = portA + 3
    20  	PA4 = portA + 4
    21  	PA5 = portA + 5
    22  	PA6 = portA + 6
    23  	PA7 = portA + 7
    24  	PB0 = portB + 0
    25  	PB1 = portB + 1
    26  	PB2 = portB + 2
    27  	PB3 = portB + 3
    28  	PB4 = portB + 4
    29  	PB5 = portB + 5
    30  	PB6 = portB + 6
    31  	PB7 = portB + 7
    32  	PC0 = portC + 0
    33  	PC1 = portC + 1
    34  	PC2 = portC + 2
    35  	PC3 = portC + 3
    36  	PC4 = portC + 4
    37  	PC5 = portC + 5
    38  	PC6 = portC + 6
    39  	PC7 = portC + 7
    40  )
    41  
    42  // getPortMask returns the PORT peripheral and mask for the pin.
    43  func (p Pin) getPortMask() (*avr.PORT_Type, uint8) {
    44  	switch {
    45  	case p >= PA0 && p <= PA7: // port A
    46  		return avr.PORTA, 1 << uint8(p-portA)
    47  	case p >= PB0 && p <= PB7: // port B
    48  		return avr.PORTB, 1 << uint8(p-portB)
    49  	default: // port C
    50  		return avr.PORTC, 1 << uint8(p-portC)
    51  	}
    52  }