Firefly-RK3288/Go Firefly-RK3288/en

来自Firefly wiki
跳转至: 导航搜索

Go language

Go, also know as golang, is a program language developed by Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson.
Go is an open source program language which makes it easy to a build simple, reliable, and efficient software. The Go language is used in some of mainstream operating systems, such as: Windows, Linux and Mac OS X.

Today, Go language began to be known by more and more programers. So many companies started to use the Go language to develop projects. So what kind of features make Go Language attract so many eyes? Let’s take a look at some of the features about Go language:

  1. Go language retention but significantly simplifies the pointer.
  2. Go Language support multi-parameter return.
  3. Goroutine, this is the signature feature of the Go language. We just use a simple word of go, then you can achieve a similar effect like thread without the need for tedious lock operation and thread operations.
  4. Interface, it's one of the many users favorite properties. It's interchangeable between the interface and the struct.

After reading the Introduction of the Go language, do you have an interest about the Go language?
Here is the installation tutorial about Golang. Let's GO! GO !! GO !!!

Install Go in RK3288

Golang official website: http://www.golang.org

Download the Firefly-RK3288_Ubuntu14.04 and upgrading the firmware.
Here are two installation methods. We recommend to use the second, because the first version is lower than the second.

Install from warehouse

$ sudo apt-get install golang

If the installation fails, try:

$ sudo add-apt-repository ppa:gophers/go
$ sudo apt-get update
$ sudo apt-get install golang-stable

Install from package

If you want to install golang, you need to install gcc tools first. Because some features of golang are written with C language.

$ sudo apt-get install bison gawk gcc libc6-dev make

If the installation is unsuccessful, retry after update.

$ sudo apt-get update

Download and unzip:

$ cd /home/firefly/
$ wget golangtc.com/static/go/go1.4.2.linux-386.tar.gz
$ sudo tar -C /usr/local -xzf go1.4.2.linux-386.tar.gz

Install:

$ cd /usr/local/go/src
$ sudo ./all.bash

If all.bash not run, modify the permissions and try again.

$ chmod a+x all.bash

If the installation is successful, show:

---
Installed Go for linux/arm in /usr/local/go
Installed commands in /usr/local/go/bin
*** You need to add /usr/local/go/bin to your PATH.

Modify the configuration:

$ vi $HOME/.profile

Added to the end:

$ export PATH=$PATH:/usr/local/go/bin 
$ export GOPATH=/home/firefly/go

Save and exit.
Then take effect the profile:

$ source $HOME/.profile 

Detects whether the installation was successful:

$ go version

Show:

go version go1.4.2 linux/arm

Go_Led

Then we take the author tjCFeng's program for example.
Install git.(Skip this step if you have installed)

$ sudo apt-get install git

Download GoRK3288 Library:

$ go get github.com/tjCFeng/GoRK3288

Create goled.go file:

$ cd /home/firefly/go
$ mkdir src/goled
$ vi src/goled/goled.go

Enter the following:

package main
import (
	"fmt"
	"github.com/tjCFeng/GoRK3288/RK3288"
)
func main() {
	defer RK3288.FreeRK3288()
	P8A1, ok := RK3288.CreateGPIO(RK3288.P8, RK3288.A1)
	if ok {
		P8A1.Flip()
		if P8A1.GetData(){
			fmt.Println("power_led off")
		}else{
			fmt.Println("power_led on")
		}	
		RK3288.FreeGPIO(P8A1)
	}
}

Save exit and return to the src directory.Generate executable files:

$ go install goled/
$ sudo ./bin/goled

You can see PowerLED Off.
Run again,PowerLED ON.

GoRK3288 library download

https://github.com/tjCFeng/GoRK3288