github.com/f-secure-foundry/tamago@v0.0.0-20220307101044-d73fcdd7f11b/board/f-secure/usbarmory/mark-two/led.go (about) 1 // USB armory Mk II support for tamago/arm 2 // https://github.com/f-secure-foundry/tamago 3 // 4 // Copyright (c) F-Secure Corporation 5 // https://foundry.f-secure.com 6 // 7 // Use of this source code is governed by the license 8 // that can be found in the LICENSE file. 9 10 package usbarmory 11 12 import ( 13 "errors" 14 15 "github.com/f-secure-foundry/tamago/soc/imx6" 16 ) 17 18 // LED configuration constants 19 // 20 // On the USB armory Mk II the following LEDs are connected: 21 // * pad CSI_DATA00, GPIO4_IO21: white 22 // * pad CSI_DATA01, GPIO4_IO22: blue 23 const ( 24 // GPIO number 25 WHITE = 21 26 // mux control 27 IOMUXC_SW_MUX_CTL_PAD_CSI_DATA00 = 0x020e01e4 28 // pad control 29 IOMUXC_SW_PAD_CTL_PAD_CSI_DATA00 = 0x020e0470 30 31 // GPIO number 32 BLUE = 22 33 // mux control 34 IOMUXC_SW_MUX_CTL_PAD_CSI_DATA01 = 0x020e01e8 35 // pad control 36 IOMUXC_SW_PAD_CTL_PAD_CSI_DATA01 = 0x020e0474 37 ) 38 39 var white *imx6.GPIO 40 var blue *imx6.GPIO 41 42 func init() { 43 var err error 44 45 ctl := uint32((1 << imx6.SW_PAD_CTL_PKE) | 46 (imx6.SW_PAD_CTL_SPEED_100MHZ << imx6.SW_PAD_CTL_SPEED) | 47 (imx6.SW_PAD_CTL_DSE_2_R0_6 << imx6.SW_PAD_CTL_DSE)) 48 49 white, err = imx6.NewGPIO(WHITE, 4, 50 IOMUXC_SW_MUX_CTL_PAD_CSI_DATA00, IOMUXC_SW_PAD_CTL_PAD_CSI_DATA00) 51 52 if err != nil { 53 panic(err) 54 } 55 56 blue, err = imx6.NewGPIO(BLUE, 4, 57 IOMUXC_SW_MUX_CTL_PAD_CSI_DATA01, IOMUXC_SW_PAD_CTL_PAD_CSI_DATA01) 58 59 if err != nil { 60 panic(err) 61 } 62 63 if !imx6.Native { 64 return 65 } 66 67 white.Pad.Ctl(ctl) 68 white.Out() 69 70 blue.Pad.Ctl(ctl) 71 blue.Out() 72 } 73 74 // LED turns on/off an LED by name. 75 func LED(name string, on bool) (err error) { 76 var led *imx6.GPIO 77 78 switch name { 79 case "white", "White", "WHITE": 80 led = white 81 case "blue", "Blue", "BLUE": 82 led = blue 83 default: 84 return errors.New("invalid LED") 85 } 86 87 if !imx6.Native { 88 return 89 } 90 91 if on { 92 led.Low() 93 } else { 94 led.High() 95 } 96 97 return 98 }