mirror of
https://github.com/kidoman/embd
synced 2024-12-22 12:50:19 +01:00
Merge pull request #13 from alsm/master
embd, rpi: determine pi revision, make rev2 pinmap default
This commit is contained in:
commit
b70d632937
18
detect.go
18
detect.go
@ -4,6 +4,7 @@ package embd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -76,6 +77,22 @@ func kernelVersion() (major, minor, patch int, err error) {
|
||||
return parseVersion(output)
|
||||
}
|
||||
|
||||
func getPiRevision() (int, error) {
|
||||
//default return code of a rev2 board
|
||||
cpuinfo, err := ioutil.ReadFile("/proc/cpuinfo")
|
||||
if err != nil {
|
||||
return 4, err
|
||||
}
|
||||
for _, line := range strings.Split(string(cpuinfo), "\n") {
|
||||
fields := strings.Fields(line)
|
||||
if len(fields) > 0 && fields[0] == "Revision" {
|
||||
rev, err := strconv.ParseInt(fields[2], 16, 8)
|
||||
return int(rev), err
|
||||
}
|
||||
}
|
||||
return 4, nil
|
||||
}
|
||||
|
||||
// DetectHost returns the detected host and its revision number.
|
||||
func DetectHost() (Host, int, error) {
|
||||
major, minor, patch, err := kernelVersion()
|
||||
@ -98,6 +115,7 @@ func DetectHost() (Host, int, error) {
|
||||
switch node {
|
||||
case "raspberrypi":
|
||||
host = HostRPi
|
||||
rev, _ = getPiRevision()
|
||||
case "beaglebone":
|
||||
host = HostBBB
|
||||
default:
|
||||
|
@ -61,9 +61,9 @@ var ledMap = embd.LEDMap{
|
||||
|
||||
func init() {
|
||||
embd.Register(embd.HostRPi, func(rev int) *embd.Descriptor {
|
||||
var pins = rev1Pins
|
||||
if rev > 1 {
|
||||
pins = rev2Pins
|
||||
var pins = rev2Pins
|
||||
if rev < 4 {
|
||||
pins = rev1Pins
|
||||
}
|
||||
|
||||
return &embd.Descriptor{
|
||||
|
Loading…
x
Reference in New Issue
Block a user