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

     1  //go:build avr && atmega2560
     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  const irq_USART1_RX = avr.IRQ_USART1_RX
    12  const irq_USART2_RX = avr.IRQ_USART2_RX
    13  const irq_USART3_RX = avr.IRQ_USART3_RX
    14  
    15  const (
    16  	portA Pin = iota * 8
    17  	portB
    18  	portC
    19  	portD
    20  	portE
    21  	portF
    22  	portG
    23  	portH
    24  	portJ
    25  	portK
    26  	portL
    27  )
    28  
    29  const (
    30  	PA0 = portA + 0
    31  	PA1 = portA + 1
    32  	PA2 = portA + 2
    33  	PA3 = portA + 3
    34  	PA4 = portA + 4
    35  	PA5 = portA + 5
    36  	PA6 = portA + 6
    37  	PA7 = portA + 7
    38  	PB0 = portB + 0
    39  	PB1 = portB + 1
    40  	PB2 = portB + 2
    41  	PB3 = portB + 3
    42  	PB4 = portB + 4
    43  	PB5 = portB + 5
    44  	PB6 = portB + 6
    45  	PB7 = portB + 7
    46  	PC0 = portC + 0
    47  	PC1 = portC + 1
    48  	PC2 = portC + 2
    49  	PC3 = portC + 3
    50  	PC4 = portC + 4
    51  	PC5 = portC + 5
    52  	PC6 = portC + 6
    53  	PC7 = portC + 7
    54  	PD0 = portD + 0
    55  	PD1 = portD + 1
    56  	PD2 = portD + 2
    57  	PD3 = portD + 3
    58  	PD7 = portD + 7
    59  	PE0 = portE + 0
    60  	PE1 = portE + 1
    61  	PE3 = portE + 3
    62  	PE4 = portE + 4
    63  	PE5 = portE + 5
    64  	PE6 = portE + 6
    65  	PF0 = portF + 0
    66  	PF1 = portF + 1
    67  	PF2 = portF + 2
    68  	PF3 = portF + 3
    69  	PF4 = portF + 4
    70  	PF5 = portF + 5
    71  	PF6 = portF + 6
    72  	PF7 = portF + 7
    73  	PG0 = portG + 0
    74  	PG1 = portG + 1
    75  	PG2 = portG + 2
    76  	PG5 = portG + 5
    77  	PH0 = portH + 0
    78  	PH1 = portH + 1
    79  	PH3 = portH + 3
    80  	PH4 = portH + 4
    81  	PH5 = portH + 5
    82  	PH6 = portH + 6
    83  	PJ0 = portJ + 0
    84  	PJ1 = portJ + 1
    85  	PK0 = portK + 0
    86  	PK1 = portK + 1
    87  	PK2 = portK + 2
    88  	PK3 = portK + 3
    89  	PK4 = portK + 4
    90  	PK5 = portK + 5
    91  	PK6 = portK + 6
    92  	PK7 = portK + 7
    93  	PL0 = portL + 0
    94  	PL1 = portL + 1
    95  	PL2 = portL + 2
    96  	PL3 = portL + 3
    97  	PL4 = portL + 4
    98  	PL5 = portL + 5
    99  	PL6 = portL + 6
   100  	PL7 = portL + 7
   101  )
   102  
   103  // getPortMask returns the PORTx register and mask for the pin.
   104  func (p Pin) getPortMask() (*volatile.Register8, uint8) {
   105  	switch {
   106  	case p >= PA0 && p <= PA7:
   107  		return avr.PORTA, 1 << uint8(p-portA)
   108  	case p >= PB0 && p <= PB7:
   109  		return avr.PORTB, 1 << uint8(p-portB)
   110  	case p >= PC0 && p <= PC7:
   111  		return avr.PORTC, 1 << uint8(p-portC)
   112  	case p >= PD0 && p <= PD7:
   113  		return avr.PORTD, 1 << uint8(p-portD)
   114  	case p >= PE0 && p <= PE6:
   115  		return avr.PORTE, 1 << uint8(p-portE)
   116  	case p >= PF0 && p <= PF7:
   117  		return avr.PORTF, 1 << uint8(p-portF)
   118  	case p >= PG0 && p <= PG5:
   119  		return avr.PORTG, 1 << uint8(p-portG)
   120  	case p >= PH0 && p <= PH6:
   121  		return avr.PORTH, 1 << uint8(p-portH)
   122  	case p >= PJ0 && p <= PJ1:
   123  		return avr.PORTJ, 1 << uint8(p-portJ)
   124  	case p >= PK0 && p <= PK7:
   125  		return avr.PORTK, 1 << uint8(p-portK)
   126  	case p >= PL0 && p <= PL7:
   127  		return avr.PORTL, 1 << uint8(p-portL)
   128  	default:
   129  		return avr.PORTA, 255
   130  	}
   131  }
   132  
   133  // SPI configuration
   134  var SPI0 = SPI{
   135  	spcr: avr.SPCR,
   136  	spdr: avr.SPDR,
   137  	spsr: avr.SPSR,
   138  	sck:  PB1,
   139  	sdo:  PB2,
   140  	sdi:  PB3,
   141  	cs:   PB0}