github.com/usbarmory/tamago@v0.0.0-20240508072735-8612bbe1e454/board/raspberrypi/pizero/led.go (about)

     1  // Raspberry Pi Zero LED support
     2  // https://github.com/usbarmory/tamago
     3  //
     4  // Copyright (c) the pizero 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 pizero
    10  
    11  import (
    12  	"errors"
    13  
    14  	"github.com/usbarmory/tamago/soc/bcm2835"
    15  )
    16  
    17  // LED GPIO lines
    18  const (
    19  	// Activity LED
    20  	ACTIVITY = 0x2f
    21  )
    22  
    23  var activity *bcm2835.GPIO
    24  
    25  func init() {
    26  	var err error
    27  
    28  	activity, err = bcm2835.NewGPIO(ACTIVITY)
    29  
    30  	if err != nil {
    31  		panic(err)
    32  	}
    33  
    34  	activity.Out()
    35  }
    36  
    37  // LED turns on/off an LED by name.
    38  func (b *board) LED(name string, on bool) (err error) {
    39  	var led *bcm2835.GPIO
    40  
    41  	switch name {
    42  	case "activity", "Activity", "ACTIVITY":
    43  		led = activity
    44  	default:
    45  		return errors.New("invalid LED")
    46  	}
    47  
    48  	if on {
    49  		led.High()
    50  	} else {
    51  		led.Low()
    52  	}
    53  
    54  	return
    55  }