github.com/f-secure-foundry/tamago@v0.0.0-20220307101044-d73fcdd7f11b/board/raspberrypi/pi2/led.go (about)

     1  // Raspberry Pi 2 LED support
     2  // https://github.com/f-secure-foundry/tamago
     3  //
     4  // Copyright (c) the pi2 package authors
     5  //
     6  // Use of this source code is governed by the license
     7  // that can be found in the LICENSE file.
     8  
     9  package pi2
    10  
    11  import (
    12  	"errors"
    13  
    14  	"github.com/f-secure-foundry/tamago/soc/bcm2835"
    15  )
    16  
    17  // LED GPIO lines
    18  const (
    19  	// Activity LED
    20  	ACTIVITY = 0x2f
    21  	// Power LED
    22  	POWER = 0x23
    23  )
    24  
    25  var activity *bcm2835.GPIO
    26  var power *bcm2835.GPIO
    27  
    28  func init() {
    29  	var err error
    30  
    31  	activity, err = bcm2835.NewGPIO(ACTIVITY)
    32  
    33  	if err != nil {
    34  		panic(err)
    35  	}
    36  
    37  	power, err = bcm2835.NewGPIO(POWER)
    38  
    39  	if err != nil {
    40  		panic(err)
    41  	}
    42  
    43  	activity.Out()
    44  	power.Out()
    45  }
    46  
    47  // LED turns on/off an LED by name.
    48  func (b *board) LED(name string, on bool) (err error) {
    49  	var led *bcm2835.GPIO
    50  
    51  	switch name {
    52  	case "activity", "Activity", "ACTIVITY":
    53  		led = activity
    54  	case "power", "Power", "POWER":
    55  		led = power
    56  	default:
    57  		return errors.New("invalid LED")
    58  	}
    59  
    60  	if on {
    61  		led.High()
    62  	} else {
    63  		led.Low()
    64  	}
    65  
    66  	return
    67  }