Browse Source

machine: add Device constant

This field contains the microcontroller name that we're compiling for,
or "generic" if we're not running on a microcontroller.
pull/2328/head
Ayke van Laethem 3 years ago
committed by Ron Evans
parent
commit
3d73ee77d3
  1. 7
      src/machine/machine.go
  2. 2
      src/machine/machine_atsamd21.go
  3. 2
      src/machine/machine_atsamd51.go
  4. 2
      src/machine/machine_avr.go
  5. 2
      src/machine/machine_esp32.go
  6. 2
      src/machine/machine_esp32c3.go
  7. 2
      src/machine/machine_esp8266.go
  8. 2
      src/machine/machine_fe310.go
  9. 4
      src/machine/machine_gameboyadvance.go
  10. 2
      src/machine/machine_generic.go
  11. 2
      src/machine/machine_k210.go
  12. 2
      src/machine/machine_mimxrt1062.go
  13. 2
      src/machine/machine_nrf.go
  14. 2
      src/machine/machine_nxpmk66f18.go
  15. 2
      src/machine/machine_rp2040.go
  16. 4
      src/machine/machine_stm32.go

7
src/machine/machine.go

@ -10,6 +10,13 @@ var (
ErrNoPinChangeChannel = errors.New("machine: no channel available for pin interrupt") ErrNoPinChangeChannel = errors.New("machine: no channel available for pin interrupt")
) )
// Device is the running program's chip name, such as "ATSAMD51J19A" or
// "nrf52840". It is not the same as the CPU name.
//
// The constant is some hardcoded default value if the program does not target a
// particular chip but instead runs in WebAssembly for example.
const Device = deviceName
// PinMode sets the direction and pull mode of the pin. For example, PinOutput // PinMode sets the direction and pull mode of the pin. For example, PinOutput
// sets the pin as an output and PinInputPullup sets the pin as an input with a // sets the pin as an output and PinInputPullup sets the pin as an input with a
// pull-up. // pull-up.

2
src/machine/machine_atsamd21.go

@ -16,6 +16,8 @@ import (
"unsafe" "unsafe"
) )
const deviceName = sam.Device
const ( const (
PinAnalog PinMode = 1 PinAnalog PinMode = 1
PinSERCOM PinMode = 2 PinSERCOM PinMode = 2

2
src/machine/machine_atsamd51.go

@ -16,6 +16,8 @@ import (
"unsafe" "unsafe"
) )
const deviceName = sam.Device
func CPUFrequency() uint32 { func CPUFrequency() uint32 {
return 120000000 return 120000000
} }

2
src/machine/machine_avr.go

@ -8,6 +8,8 @@ import (
"unsafe" "unsafe"
) )
const deviceName = avr.DEVICE
const ( const (
PinInput PinMode = iota PinInput PinMode = iota
PinInputPullup PinInputPullup

2
src/machine/machine_esp32.go

@ -9,6 +9,8 @@ import (
"unsafe" "unsafe"
) )
const deviceName = esp.Device
const peripheralClock = 80000000 // 80MHz const peripheralClock = 80000000 // 80MHz
// CPUFrequency returns the current CPU frequency of the chip. // CPUFrequency returns the current CPU frequency of the chip.

2
src/machine/machine_esp32c3.go

@ -8,6 +8,8 @@ import (
"unsafe" "unsafe"
) )
const deviceName = esp.Device
// CPUFrequency returns the current CPU frequency of the chip. // CPUFrequency returns the current CPU frequency of the chip.
// Currently it is a fixed frequency but it may allow changing in the future. // Currently it is a fixed frequency but it may allow changing in the future.
func CPUFrequency() uint32 { func CPUFrequency() uint32 {

2
src/machine/machine_esp8266.go

@ -7,6 +7,8 @@ import (
"runtime/volatile" "runtime/volatile"
) )
const deviceName = esp.Device
func CPUFrequency() uint32 { func CPUFrequency() uint32 {
return 80000000 // 80MHz return 80000000 // 80MHz
} }

2
src/machine/machine_fe310.go

@ -8,6 +8,8 @@ import (
"unsafe" "unsafe"
) )
const deviceName = sifive.Device
func CPUFrequency() uint32 { func CPUFrequency() uint32 {
return 320000000 // 320MHz return 320000000 // 320MHz
} }

4
src/machine/machine_gameboyadvance.go

@ -9,6 +9,10 @@ import (
"unsafe" "unsafe"
) )
// Not sure what name to pick here. Not using ARM7TDMI because that's the CPU
// name, not the device name.
const deviceName = "GBA"
// Interrupt numbers as used on the GameBoy Advance. Register them with // Interrupt numbers as used on the GameBoy Advance. Register them with
// runtime/interrupt.New. // runtime/interrupt.New.
const ( const (

2
src/machine/machine_generic.go

@ -4,6 +4,8 @@ package machine
// Dummy machine package that calls out to external functions. // Dummy machine package that calls out to external functions.
const deviceName = "generic"
var ( var (
UART0 = &UART{0} UART0 = &UART{0}
USB = &UART{100} USB = &UART{100}

2
src/machine/machine_k210.go

@ -10,6 +10,8 @@ import (
"unsafe" "unsafe"
) )
const deviceName = kendryte.Device
func CPUFrequency() uint32 { func CPUFrequency() uint32 {
return 390000000 return 390000000
} }

2
src/machine/machine_mimxrt1062.go

@ -11,6 +11,8 @@ import (
// Peripheral abstraction layer for the MIMXRT1062 // Peripheral abstraction layer for the MIMXRT1062
const deviceName = nxp.Device
func CPUFrequency() uint32 { func CPUFrequency() uint32 {
return 600000000 return 600000000
} }

2
src/machine/machine_nrf.go

@ -13,6 +13,8 @@ var (
ErrTxInvalidSliceSize = errors.New("SPI write and read slices must be same size") ErrTxInvalidSliceSize = errors.New("SPI write and read slices must be same size")
) )
const deviceName = nrf.Device
const ( const (
PinInput PinMode = (nrf.GPIO_PIN_CNF_DIR_Input << nrf.GPIO_PIN_CNF_DIR_Pos) | (nrf.GPIO_PIN_CNF_INPUT_Connect << nrf.GPIO_PIN_CNF_INPUT_Pos) PinInput PinMode = (nrf.GPIO_PIN_CNF_DIR_Input << nrf.GPIO_PIN_CNF_DIR_Pos) | (nrf.GPIO_PIN_CNF_INPUT_Connect << nrf.GPIO_PIN_CNF_INPUT_Pos)
PinInputPullup PinMode = PinInput | (nrf.GPIO_PIN_CNF_PULL_Pullup << nrf.GPIO_PIN_CNF_PULL_Pos) PinInputPullup PinMode = PinInput | (nrf.GPIO_PIN_CNF_PULL_Pullup << nrf.GPIO_PIN_CNF_PULL_Pos)

2
src/machine/machine_nxpmk66f18.go

@ -37,6 +37,8 @@ import (
"unsafe" "unsafe"
) )
const deviceName = nxp.Device
const ( const (
PinInput PinMode = iota PinInput PinMode = iota
PinInputPullUp PinInputPullUp

2
src/machine/machine_rp2040.go

@ -8,6 +8,8 @@ import (
"runtime/interrupt" "runtime/interrupt"
) )
const deviceName = rp.Device
const ( const (
// GPIO pins // GPIO pins
GPIO0 Pin = 0 GPIO0 Pin = 0

4
src/machine/machine_stm32.go

@ -2,6 +2,10 @@
package machine package machine
import "device/stm32"
const deviceName = stm32.Device
// Peripheral abstraction layer for the stm32. // Peripheral abstraction layer for the stm32.
const ( const (

Loading…
Cancel
Save