mirror of
https://github.com/kidoman/embd
synced 2024-12-22 21:00:05 +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:
parent
6ad940090c
commit
9401acd013
18
detect.go
18
detect.go
@ -4,6 +4,7 @@ package embd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -76,6 +77,22 @@ func kernelVersion() (major, minor, patch int, err error) {
|
|||||||
return parseVersion(output)
|
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.
|
// DetectHost returns the detected host and its revision number.
|
||||||
func DetectHost() (Host, int, error) {
|
func DetectHost() (Host, int, error) {
|
||||||
major, minor, patch, err := kernelVersion()
|
major, minor, patch, err := kernelVersion()
|
||||||
@ -98,6 +115,7 @@ func DetectHost() (Host, int, error) {
|
|||||||
switch node {
|
switch node {
|
||||||
case "raspberrypi":
|
case "raspberrypi":
|
||||||
host = HostRPi
|
host = HostRPi
|
||||||
|
rev, _ = getPiRevision()
|
||||||
case "beaglebone":
|
case "beaglebone":
|
||||||
host = HostBBB
|
host = HostBBB
|
||||||
default:
|
default:
|
||||||
|
@ -61,9 +61,9 @@ var ledMap = embd.LEDMap{
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
embd.Register(embd.HostRPi, func(rev int) *embd.Descriptor {
|
embd.Register(embd.HostRPi, func(rev int) *embd.Descriptor {
|
||||||
var pins = rev1Pins
|
var pins = rev2Pins
|
||||||
if rev > 1 {
|
if rev < 4 {
|
||||||
pins = rev2Pins
|
pins = rev1Pins
|
||||||
}
|
}
|
||||||
|
|
||||||
return &embd.Descriptor{
|
return &embd.Descriptor{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user