1
0
mirror of https://github.com/kidoman/embd synced 2024-12-22 04:40:04 +01:00

embd, rpi: determine pi revision, make rev2 pinmap default

added a function to determine the revision of the pi the program is
running on from "Revision" field in /proc/cpuinfo, also made the rev2
gpio pinmap the default
This commit is contained in:
alsm 2014-09-09 15:57:27 +01:00
parent 6ad940090c
commit 9401acd013
2 changed files with 21 additions and 3 deletions

View File

@ -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:

View File

@ -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{