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

     1  package machine
     2  
     3  import "errors"
     4  
     5  var (
     6  	ErrTimeoutRNG         = errors.New("machine: RNG Timeout")
     7  	ErrClockRNG           = errors.New("machine: RNG Clock Error")
     8  	ErrSeedRNG            = errors.New("machine: RNG Seed Error")
     9  	ErrInvalidInputPin    = errors.New("machine: invalid input pin")
    10  	ErrInvalidOutputPin   = errors.New("machine: invalid output pin")
    11  	ErrInvalidClockPin    = errors.New("machine: invalid clock pin")
    12  	ErrInvalidDataPin     = errors.New("machine: invalid data pin")
    13  	ErrNoPinChangeChannel = errors.New("machine: no channel available for pin interrupt")
    14  )
    15  
    16  // Device is the running program's chip name, such as "ATSAMD51J19A" or
    17  // "nrf52840". It is not the same as the CPU name.
    18  //
    19  // The constant is some hardcoded default value if the program does not target a
    20  // particular chip but instead runs in WebAssembly for example.
    21  const Device = deviceName
    22  
    23  // Generic constants.
    24  const (
    25  	KHz = 1000
    26  	MHz = 1000_000
    27  	GHz = 1000_000_000
    28  )
    29  
    30  // PinMode sets the direction and pull mode of the pin. For example, PinOutput
    31  // sets the pin as an output and PinInputPullup sets the pin as an input with a
    32  // pull-up.
    33  type PinMode uint8
    34  
    35  type PinConfig struct {
    36  	Mode PinMode
    37  }
    38  
    39  // Pin is a single pin on a chip, which may be connected to other hardware
    40  // devices. It can either be used directly as GPIO pin or it can be used in
    41  // other peripherals like ADC, I2C, etc.
    42  type Pin uint8
    43  
    44  // NoPin explicitly indicates "not a pin". Use this pin if you want to leave one
    45  // of the pins in a peripheral unconfigured (if supported by the hardware).
    46  const NoPin = Pin(0xff)
    47  
    48  // High sets this GPIO pin to high, assuming it has been configured as an output
    49  // pin. It is hardware dependent (and often undefined) what happens if you set a
    50  // pin to high that is not configured as an output pin.
    51  func (p Pin) High() {
    52  	p.Set(true)
    53  }
    54  
    55  // Low sets this GPIO pin to low, assuming it has been configured as an output
    56  // pin. It is hardware dependent (and often undefined) what happens if you set a
    57  // pin to low that is not configured as an output pin.
    58  func (p Pin) Low() {
    59  	p.Set(false)
    60  }
    61  
    62  type ADC struct {
    63  	Pin Pin
    64  }