This is a creation in Article, where the information may have evolved or changed. The statement of the go language is simple, and it is as simple as a dynamic language. But although the code symbol is simple, but just contact when it is some do not adapt, here is the use of GoRK3288 library when you need to use the syntax to enumerate, other advanced things to learn later.
1. Operator:
+ 、-、 *,/,%, &, |, ^, <<, >>, = =,! =, |= and so on these and C languages are the same, but in the reverse of the time is not the ~ symbol, but ^. Or the same symbol, how to distinguish it? Monocular operation is to take the reverse, binocular operation is also or. In addition to a position of 0 words &= ^x is not right, but &^= X, remember.
2. Variables:
variable declarations can be identified with Var, such as var i int = 0, the variable name is in front, the type is behind, and the end of the statement does not require a semicolon. Assigning initial values to multiple variables var i, j = 0, 0
like some dynamic languages, go variables can be automatically judged based on the return value of the function. such as
I: = GetIndex (). The variable i is automatically assigned according to the type of the function GetIndex () return value, but it is important to note that the operator becomes: =, and uses = To assign a value to the declared variable directly.
3. return value:
The return value is one of the biggest changes in the go language and other languages, and the go language supports multiple return values. For example:
func GetInfo () (Index int, Info string, Result float32) {}
&NBS P Returns three values at once without having to define a structure, which is a lot easier. And if you just want to use a return value and not care about the other values, you can receive: Index, _, _: = GetInfo (), it is too convenient.
4. Threads (co-thread):
said earlier, Go is good for high concurrency, and high concurrency is accomplished through multithreading. The so-called threads used in Go are actually a little bit more expensive than the thread resource overhead, so you can theoretically create hundreds of thousands of The threads work in parallel. Of course it's just a theory, but create thousands of tens of thousands the process is generally sufficient for use.
5. Channel:
the message communication mechanism provided by the go language is called the channel, which can be The language level provides the means of communication between goroutine. "Do not communicate through shared memory, but should use communication to share memory." This is the way the channel works in the Go language. Channels are used in a variety of ways, usually first define a channel, one side to write, the other to read, and read the party before the arrival of the message is blocked. For example:
CH: = make (chan int)//Create Channel
CH <-1//write message to channel
msg: = <-ch//Read message from channel to a variable
While other usages are select not for the time being. Please refer to the manual for detailed usage information.
6. Process Control:
if x = = y {return }//Conditional judgment part not ()
No while ... Or do ... while ..., go language only for {}
switch (x) {
Case a:< br> case B, C, D:fallthrough
Default:return
& nbsp }
switch Instead of ending each case with a break in C, use Fallthrough to achieve this effect if needed.
7.Go keywords:
Break case Chan Const continue default defer else Fallthrough for func go goto if Import Interface map package range Retur n Select struct Switch type var
8.Go Type:
byte int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 float32 float64 complex64 complex128 uintptr string
9. Project documents:
The go language actually does not have the project file this thing, the similar concept actually is the folder, according to the folder includes the go file as well as the reference situation to decide whether in a project. However, each project must have an entry point, which must be the beginning of the package main, and Func main () {} as the file where the main function resides. With this file to compile and run correctly.
think of so much, and other things to add later.
The syntax is probably understood, and then look at the structure of the project file for GoRK3288.
The documents currently included are:
1. Rk3288.go
2.grf.go
3. Gpio.go
4.pwm.go
5. Tsadc.go
6.wdt.go
....
First the Rk3288.go file is a basic file, and the mapping and release of the memory is done by it. This file itself is not related to the RK3288, generally do not need to use, but at the beginning of the project need to call a sentence defer RK3288. FreeRK3288 () is used to release resources when the program exits.
The second is the Grf.go file, which is used to set the function multiplexing of RK3288 per port. Of course it has been packaged well and does not need to be called directly.
These two files are necessary for the project, and the missing will not compile. Other file functions and filenames are the same, needless to say, can not be included in the project.
The use of each file is followed by a succession of instructions.
GoRK3288 Library please download in https://github.com/tjCFeng/GoRK3288 .