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

     1  //go:build arduino_mega2560
     2  
     3  package machine
     4  
     5  import (
     6  	"device/avr"
     7  	"runtime/interrupt"
     8  )
     9  
    10  // Return the current CPU frequency in hertz.
    11  func CPUFrequency() uint32 {
    12  	return 16000000
    13  }
    14  
    15  const (
    16  	A0  Pin = PF0
    17  	A1  Pin = PF1
    18  	A2  Pin = PF2
    19  	A3  Pin = PF3
    20  	A4  Pin = PF4
    21  	A5  Pin = PF5
    22  	A6  Pin = PF6
    23  	A7  Pin = PF7
    24  	A8  Pin = PK0
    25  	A9  Pin = PK1
    26  	A10 Pin = PK2
    27  	A11 Pin = PK3
    28  	A12 Pin = PK4
    29  	A13 Pin = PK5
    30  	A14 Pin = PK6
    31  	A15 Pin = PK7
    32  
    33  	// Analog Input
    34  	ADC0  Pin = PF0
    35  	ADC1  Pin = PF1
    36  	ADC2  Pin = PF2
    37  	ADC3  Pin = PF3
    38  	ADC4  Pin = PF4
    39  	ADC5  Pin = PF5
    40  	ADC6  Pin = PF6
    41  	ADC7  Pin = PF7
    42  	ADC8  Pin = PK0
    43  	ADC9  Pin = PK1
    44  	ADC10 Pin = PK2
    45  	ADC11 Pin = PK3
    46  	ADC12 Pin = PK4
    47  	ADC13 Pin = PK5
    48  	ADC14 Pin = PK6
    49  	ADC15 Pin = PK7
    50  
    51  	// Digital pins
    52  	D0  Pin = PE0
    53  	D1  Pin = PE1
    54  	D2  Pin = PE4
    55  	D3  Pin = PE5
    56  	D4  Pin = PG5
    57  	D5  Pin = PE3
    58  	D6  Pin = PH3
    59  	D7  Pin = PH4
    60  	D8  Pin = PH5
    61  	D9  Pin = PH6
    62  	D10 Pin = PB4
    63  	D11 Pin = PB5
    64  	D12 Pin = PB6
    65  	D13 Pin = PB7
    66  	D14 Pin = PJ1 // TX3
    67  	D15 Pin = PJ0 // RX3
    68  	D16 Pin = PH1 // TX2
    69  	D17 Pin = PH0 // RX2
    70  	D18 Pin = PD3 // TX1
    71  	D19 Pin = PD2 // RX1
    72  	D20 Pin = PD1
    73  	D21 Pin = PD0
    74  	D22 Pin = PA0
    75  	D23 Pin = PA1
    76  	D24 Pin = PA2
    77  	D25 Pin = PA3
    78  	D26 Pin = PA4
    79  	D27 Pin = PA5
    80  	D28 Pin = PA6
    81  	D29 Pin = PA7
    82  	D30 Pin = PC7
    83  	D31 Pin = PC6
    84  	D32 Pin = PC5
    85  	D33 Pin = PC4
    86  	D34 Pin = PC3
    87  	D35 Pin = PC2
    88  	D36 Pin = PC1
    89  	D37 Pin = PC0
    90  	D38 Pin = PD7
    91  	D39 Pin = PG2
    92  	D40 Pin = PG1
    93  	D41 Pin = PG0
    94  	D42 Pin = PL7
    95  	D43 Pin = PL6
    96  	D44 Pin = PL5
    97  	D45 Pin = PL4
    98  	D46 Pin = PL3
    99  	D47 Pin = PL2
   100  	D48 Pin = PL1
   101  	D49 Pin = PL0
   102  	D50 Pin = PB3
   103  	D51 Pin = PB2
   104  	D52 Pin = PB1
   105  	D53 Pin = PB0
   106  
   107  	AREF Pin = NoPin
   108  	LED  Pin = PB7
   109  )
   110  
   111  // UART pins
   112  const (
   113  	UART_TX_PIN  Pin = UART0_TX_PIN
   114  	UART_RX_PIN  Pin = UART0_RX_PIN
   115  	UART0_TX_PIN Pin = D1
   116  	UART0_RX_PIN Pin = D0
   117  	UART1_TX_PIN Pin = D18
   118  	UART1_RX_PIN Pin = D19
   119  	UART2_TX_PIN Pin = D16
   120  	UART2_RX_PIN Pin = D17
   121  	UART3_TX_PIN Pin = D14
   122  	UART3_RX_PIN Pin = D15
   123  )
   124  
   125  var (
   126  	UART1  = &_UART1
   127  	_UART1 = UART{
   128  		Buffer: NewRingBuffer(),
   129  
   130  		dataReg:    avr.UDR1,
   131  		baudRegH:   avr.UBRR1H,
   132  		baudRegL:   avr.UBRR1L,
   133  		statusRegA: avr.UCSR1A,
   134  		statusRegB: avr.UCSR1B,
   135  		statusRegC: avr.UCSR1C,
   136  	}
   137  	UART2  = &_UART2
   138  	_UART2 = UART{
   139  		Buffer: NewRingBuffer(),
   140  
   141  		dataReg:    avr.UDR2,
   142  		baudRegH:   avr.UBRR2H,
   143  		baudRegL:   avr.UBRR2L,
   144  		statusRegA: avr.UCSR2A,
   145  		statusRegB: avr.UCSR2B,
   146  		statusRegC: avr.UCSR2C,
   147  	}
   148  	UART3  = &_UART3
   149  	_UART3 = UART{
   150  		Buffer: NewRingBuffer(),
   151  
   152  		dataReg:    avr.UDR3,
   153  		baudRegH:   avr.UBRR3H,
   154  		baudRegL:   avr.UBRR3L,
   155  		statusRegA: avr.UCSR3A,
   156  		statusRegB: avr.UCSR3B,
   157  		statusRegC: avr.UCSR3C,
   158  	}
   159  )
   160  
   161  func init() {
   162  	interrupt.New(irq_USART1_RX, _UART1.handleInterrupt)
   163  	interrupt.New(irq_USART2_RX, _UART2.handleInterrupt)
   164  	interrupt.New(irq_USART3_RX, _UART3.handleInterrupt)
   165  }