mirror of
https://github.com/kidoman/embd
synced 2025-07-03 11:57:38 +02:00
simplify package structure
This commit is contained in:
parent
3cae4064dc
commit
36f2c0486d
41 changed files with 736 additions and 885 deletions
|
@ -1,64 +0,0 @@
|
|||
package bbb
|
||||
|
||||
import (
|
||||
"github.com/kidoman/embd/driver/linux/gpio"
|
||||
)
|
||||
|
||||
var pins = gpio.PinMap{
|
||||
&gpio.PinDesc{66, []string{"P8_07", "GPIO_66", "TIMER4"}, gpio.Normal | gpio.GPMC},
|
||||
&gpio.PinDesc{67, []string{"P8_08", "GPIO_67", "TIMER7"}, gpio.Normal | gpio.GPMC},
|
||||
&gpio.PinDesc{69, []string{"P8_09", "GPIO_69", "TIMER5"}, gpio.Normal | gpio.GPMC},
|
||||
&gpio.PinDesc{68, []string{"P8_10", "GPIO_68", "TIMER6"}, gpio.Normal | gpio.GPMC},
|
||||
&gpio.PinDesc{45, []string{"P8_11", "GPIO_45"}, gpio.Normal | gpio.GPMC},
|
||||
&gpio.PinDesc{44, []string{"P8_12", "GPIO_44"}, gpio.Normal | gpio.GPMC},
|
||||
&gpio.PinDesc{23, []string{"P8_13", "GPIO_23", "EHRPWM2B"}, gpio.Normal | gpio.GPMC},
|
||||
&gpio.PinDesc{26, []string{"P8_14", "GPIO_26"}, gpio.Normal | gpio.GPMC},
|
||||
&gpio.PinDesc{47, []string{"P8_15", "GPIO_47"}, gpio.Normal | gpio.GPMC},
|
||||
&gpio.PinDesc{46, []string{"P8_16", "GPIO_46"}, gpio.Normal | gpio.GPMC},
|
||||
&gpio.PinDesc{27, []string{"P8_17", "GPIO_27"}, gpio.Normal | gpio.GPMC},
|
||||
&gpio.PinDesc{65, []string{"P8_18", "GPIO_65"}, gpio.Normal | gpio.GPMC},
|
||||
&gpio.PinDesc{22, []string{"P8_19", "GPIO_22", "EHRPWM2A"}, gpio.Normal | gpio.GPMC},
|
||||
&gpio.PinDesc{61, []string{"P8_26", "GPIO_61"}, gpio.Normal | gpio.GPMC},
|
||||
&gpio.PinDesc{86, []string{"P8_27", "GPIO_86"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{88, []string{"P8_28", "GPIO_88"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{87, []string{"P8_29", "GPIO_87"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{89, []string{"P8_30", "GPIO_89"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{10, []string{"P8_31", "GPIO_10", "UART5_CTSN"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{11, []string{"P8_32", "GPIO_11", "UART5_RTSN"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{9, []string{"P8_33", "GPIO_9 ", "UART4_RTSN"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{81, []string{"P8_34", "GPIO_81", "UART3_RTSN"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{8, []string{"P8_35", "GPIO_8 ", "UART4_CTSN"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{80, []string{"P8_36", "GPIO_80", "UART3_CTSN"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{78, []string{"P8_37", "GPIO_78", "UART5_TXD"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{79, []string{"P8_38", "GPIO_79", "UART5_RXD"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{76, []string{"P8_39", "GPIO_76"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{77, []string{"P8_40", "GPIO_77"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{74, []string{"P8_41", "GPIO_74"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{75, []string{"P8_42", "GPIO_75"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{72, []string{"P8_43", "GPIO_72"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{73, []string{"P8_44", "GPIO_73"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{70, []string{"P8_45", "GPIO_70"}, gpio.Normal | gpio.LCD},
|
||||
&gpio.PinDesc{71, []string{"P8_46", "GPIO_71"}, gpio.Normal | gpio.LCD},
|
||||
|
||||
&gpio.PinDesc{30, []string{"P9_11", "GPIO_30", "UART4_RXD"}, gpio.Normal | gpio.UART},
|
||||
&gpio.PinDesc{60, []string{"P9_12", "GPIO_60", "GPIO1_28"}, gpio.Normal},
|
||||
&gpio.PinDesc{31, []string{"P9_13", "GPIO_31", "UART4_TXD"}, gpio.Normal | gpio.UART},
|
||||
&gpio.PinDesc{50, []string{"P9_14", "GPIO_50", "EHRPWM1A"}, gpio.Normal | gpio.PWM},
|
||||
&gpio.PinDesc{48, []string{"P9_15", "GPIO_48", "GPIO1_16"}, gpio.Normal},
|
||||
&gpio.PinDesc{51, []string{"P9_16", "GPIO_51", "EHRPWM1B"}, gpio.Normal | gpio.PWM},
|
||||
&gpio.PinDesc{5, []string{"P9_17", "GPIO_5", "I2C1_SCL"}, gpio.Normal | gpio.I2C},
|
||||
&gpio.PinDesc{4, []string{"P9_18", "GPIO_4", "I2C1_SDA"}, gpio.Normal | gpio.I2C},
|
||||
&gpio.PinDesc{13, []string{"P9_19", "GPIO_13", "I2C2_SCL"}, gpio.Normal | gpio.I2C},
|
||||
&gpio.PinDesc{12, []string{"P9_20", "GPIO_12", "I2C2_SDA"}, gpio.Normal | gpio.I2C},
|
||||
&gpio.PinDesc{3, []string{"P9_21", "GPIO_3", "UART2_TXD"}, gpio.Normal | gpio.UART},
|
||||
&gpio.PinDesc{2, []string{"P9_22", "GPIO_2", "UART2_RXD"}, gpio.Normal | gpio.UART},
|
||||
&gpio.PinDesc{49, []string{"P9_23", "GPIO_49", "GPIO1_17"}, gpio.Normal},
|
||||
&gpio.PinDesc{15, []string{"P9_24", "GPIO_15", "UART1_TXD"}, gpio.Normal | gpio.UART},
|
||||
&gpio.PinDesc{117, []string{"P9_25", "GPIO_117", "GPIO3_21"}, gpio.Normal},
|
||||
&gpio.PinDesc{14, []string{"P9_26", "GPIO_14", "UART1_RXD"}, gpio.Normal | gpio.UART},
|
||||
&gpio.PinDesc{115, []string{"P9_27", "GPIO_115", "GPIO3_19"}, gpio.Normal},
|
||||
&gpio.PinDesc{113, []string{"P9_28", "GPIO_113", "SPI1_CS0"}, gpio.Normal | gpio.SPI},
|
||||
&gpio.PinDesc{111, []string{"P9_29", "GPIO_111", "SPI1_D0"}, gpio.Normal | gpio.SPI},
|
||||
&gpio.PinDesc{112, []string{"P9_30", "GPIO_112", "SPI1_D1"}, gpio.Normal | gpio.SPI},
|
||||
&gpio.PinDesc{110, []string{"P9_31", "GPIO_110", "SPI1_SCLK"}, gpio.Normal | gpio.SPI},
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package bbb
|
||||
|
||||
import (
|
||||
lgpio "github.com/kidoman/embd/driver/linux/gpio"
|
||||
li2c "github.com/kidoman/embd/driver/linux/i2c"
|
||||
"github.com/kidoman/embd/host"
|
||||
)
|
||||
|
||||
func init() {
|
||||
host.Describers[host.BBB] = describer
|
||||
}
|
||||
|
||||
func describer(rev int) *host.Descriptor {
|
||||
return &host.Descriptor{
|
||||
GPIO: func() interface{} {
|
||||
return lgpio.New(pins)
|
||||
},
|
||||
I2C: func() interface{} {
|
||||
return li2c.New()
|
||||
},
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package host
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Descriptor struct {
|
||||
GPIO func() interface{}
|
||||
I2C func() interface{}
|
||||
}
|
||||
|
||||
type Describer func(rev int) *Descriptor
|
||||
|
||||
var Describers = map[Host]Describer{}
|
||||
|
||||
func Describe() (*Descriptor, error) {
|
||||
host, rev, err := Detect()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
describer, ok := Describers[host]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("host: invalid host %q", host)
|
||||
}
|
||||
|
||||
return describer(rev), nil
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
package host
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Host int
|
||||
|
||||
const (
|
||||
Null Host = iota
|
||||
RPi
|
||||
BBB
|
||||
CubieTruck
|
||||
Galileo
|
||||
)
|
||||
|
||||
func execOutput(name string, arg ...string) (output string, err error) {
|
||||
var out []byte
|
||||
if out, err = exec.Command(name, arg...).Output(); err != nil {
|
||||
return
|
||||
}
|
||||
output = strings.TrimSpace(string(out))
|
||||
return
|
||||
}
|
||||
|
||||
func nodeName() (string, error) {
|
||||
return execOutput("uname", "-n")
|
||||
}
|
||||
|
||||
func parseVersion(str string) (major, minor, patch int, err error) {
|
||||
parts := strings.Split(str, ".")
|
||||
len := len(parts)
|
||||
|
||||
if major, err = strconv.Atoi(parts[0]); err != nil {
|
||||
return 0, 0, 0, err
|
||||
}
|
||||
if minor, err = strconv.Atoi(parts[1]); err != nil {
|
||||
return 0, 0, 0, err
|
||||
}
|
||||
if len > 2 {
|
||||
part := parts[2]
|
||||
part = strings.TrimSuffix(part, "+")
|
||||
if patch, err = strconv.Atoi(part); err != nil {
|
||||
return 0, 0, 0, err
|
||||
}
|
||||
}
|
||||
|
||||
return major, minor, patch, err
|
||||
}
|
||||
|
||||
func kernelVersion() (major, minor, patch int, err error) {
|
||||
output, err := execOutput("uname", "-r")
|
||||
if err != nil {
|
||||
return 0, 0, 0, err
|
||||
}
|
||||
|
||||
return parseVersion(output)
|
||||
}
|
||||
|
||||
func Detect() (Host, int, error) {
|
||||
major, minor, patch, err := kernelVersion()
|
||||
if err != nil {
|
||||
return Null, 0, err
|
||||
}
|
||||
|
||||
if major < 3 || (major == 3 && minor < 8) {
|
||||
err = fmt.Errorf("embd: linux kernel versions lower than 3.8 are not supported. you have %v.%v.%v", major, minor, patch)
|
||||
return Null, 0, err
|
||||
}
|
||||
|
||||
node, err := nodeName()
|
||||
if err != nil {
|
||||
return Null, 0, err
|
||||
}
|
||||
|
||||
var host Host
|
||||
var rev int
|
||||
|
||||
switch node {
|
||||
case "raspberrypi":
|
||||
host = RPi
|
||||
case "beaglebone":
|
||||
host = BBB
|
||||
default:
|
||||
err = fmt.Errorf("embd: your host %q is not supported at this moment. please request support at https://github.com/kidoman/embd/issues", node)
|
||||
return Null, 0, err
|
||||
}
|
||||
|
||||
return host, rev, nil
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package host
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestKernelVersionParse(t *testing.T) {
|
||||
var tests = []struct {
|
||||
versionStr string
|
||||
major, minor, patch int
|
||||
}{
|
||||
{
|
||||
"3.8.2",
|
||||
3, 8, 2,
|
||||
},
|
||||
{
|
||||
"3.8.10+",
|
||||
3, 8, 10,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
major, minor, patch, err := parseVersion(test.versionStr)
|
||||
if err != nil {
|
||||
t.Errorf("Failed parsing %q: %v", test.versionStr, err)
|
||||
continue
|
||||
}
|
||||
if major != test.major || minor != test.minor || patch != test.patch {
|
||||
t.Errorf("Parse of %q: got (%v, %v, %v) want (%v, %v, %v)", test.versionStr, major, minor, patch, test.major, test.minor, test.patch)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package rpi
|
||||
|
||||
import (
|
||||
"github.com/kidoman/embd/driver/linux/gpio"
|
||||
)
|
||||
|
||||
var rev1Pins = gpio.PinMap{
|
||||
&gpio.PinDesc{0, []string{"P1_3", "GPIO_0", "SDA", "I2C0_SDA"}, gpio.Normal | gpio.I2C},
|
||||
&gpio.PinDesc{1, []string{"P1_5", "GPIO_1", "SCL", "I2C0_SCL"}, gpio.Normal | gpio.I2C},
|
||||
&gpio.PinDesc{4, []string{"P1_7", "GPIO_4", "GPCLK0"}, gpio.Normal},
|
||||
&gpio.PinDesc{14, []string{"P1_8", "GPIO_14", "TXD", "UART0_TXD"}, gpio.Normal | gpio.UART},
|
||||
&gpio.PinDesc{15, []string{"P1_10", "GPIO_15", "RXD", "UART0_RXD"}, gpio.Normal | gpio.UART},
|
||||
&gpio.PinDesc{17, []string{"P1_11", "GPIO_17"}, gpio.Normal},
|
||||
&gpio.PinDesc{18, []string{"P1_12", "GPIO_18", "PCM_CLK"}, gpio.Normal},
|
||||
&gpio.PinDesc{21, []string{"P1_13", "GPIO_21"}, gpio.Normal},
|
||||
&gpio.PinDesc{22, []string{"P1_15", "GPIO_22"}, gpio.Normal},
|
||||
&gpio.PinDesc{23, []string{"P1_16", "GPIO_23"}, gpio.Normal},
|
||||
&gpio.PinDesc{24, []string{"P1_18", "GPIO_24"}, gpio.Normal},
|
||||
&gpio.PinDesc{10, []string{"P1_19", "GPIO_10", "MOSI", "SPI0_MOSI"}, gpio.Normal | gpio.SPI},
|
||||
&gpio.PinDesc{9, []string{"P1_21", "GPIO_9", "MISO", "SPI0_MISO"}, gpio.Normal | gpio.SPI},
|
||||
&gpio.PinDesc{25, []string{"P1_22", "GPIO_25"}, gpio.Normal},
|
||||
&gpio.PinDesc{11, []string{"P1_23", "GPIO_11", "SCLK", "SPI0_SCLK"}, gpio.Normal | gpio.SPI},
|
||||
&gpio.PinDesc{8, []string{"P1_24", "GPIO_8", "CE0", "SPI0_CE0_N"}, gpio.Normal | gpio.SPI},
|
||||
&gpio.PinDesc{7, []string{"P1_26", "GPIO_7", "CE1", "SPI0_CE1_N"}, gpio.Normal | gpio.SPI},
|
||||
}
|
||||
|
||||
var rev2Pins = gpio.PinMap{
|
||||
&gpio.PinDesc{2, []string{"P1_3", "GPIO_2", "SDA", "I2C1_SDA"}, gpio.Normal | gpio.I2C},
|
||||
&gpio.PinDesc{3, []string{"P1_5", "GPIO_3", "SCL", "I2C1_SCL"}, gpio.Normal | gpio.I2C},
|
||||
&gpio.PinDesc{4, []string{"P1_7", "GPIO_4", "GPCLK0"}, gpio.Normal},
|
||||
&gpio.PinDesc{14, []string{"P1_8", "GPIO_14", "TXD", "UART0_TXD"}, gpio.Normal | gpio.UART},
|
||||
&gpio.PinDesc{15, []string{"P1_10", "GPIO_15", "RXD", "UART0_RXD"}, gpio.Normal | gpio.UART},
|
||||
&gpio.PinDesc{17, []string{"P1_11", "GPIO_17"}, gpio.Normal},
|
||||
&gpio.PinDesc{18, []string{"P1_12", "GPIO_18", "PCM_CLK"}, gpio.Normal},
|
||||
&gpio.PinDesc{27, []string{"P1_13", "GPIO_27"}, gpio.Normal},
|
||||
&gpio.PinDesc{22, []string{"P1_15", "GPIO_22"}, gpio.Normal},
|
||||
&gpio.PinDesc{23, []string{"P1_16", "GPIO_23"}, gpio.Normal},
|
||||
&gpio.PinDesc{24, []string{"P1_18", "GPIO_24"}, gpio.Normal},
|
||||
&gpio.PinDesc{10, []string{"P1_19", "GPIO_10", "MOSI", "SPI0_MOSI"}, gpio.Normal | gpio.SPI},
|
||||
&gpio.PinDesc{9, []string{"P1_21", "GPIO_9", "MISO", "SPI0_MISO"}, gpio.Normal | gpio.SPI},
|
||||
&gpio.PinDesc{25, []string{"P1_22", "GPIO_25"}, gpio.Normal},
|
||||
&gpio.PinDesc{11, []string{"P1_23", "GPIO_11", "SCLK", "SPI0_SCLK"}, gpio.Normal | gpio.SPI},
|
||||
&gpio.PinDesc{8, []string{"P1_24", "GPIO_8", "CE0", "SPI0_CE0_N"}, gpio.Normal | gpio.SPI},
|
||||
&gpio.PinDesc{7, []string{"P1_26", "GPIO_7", "CE1", "SPI0_CE1_N"}, gpio.Normal | gpio.SPI},
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package rpi
|
||||
|
||||
import (
|
||||
lgpio "github.com/kidoman/embd/driver/linux/gpio"
|
||||
li2c "github.com/kidoman/embd/driver/linux/i2c"
|
||||
"github.com/kidoman/embd/host"
|
||||
)
|
||||
|
||||
func init() {
|
||||
host.Describers[host.RPi] = describer
|
||||
}
|
||||
|
||||
func describer(rev int) *host.Descriptor {
|
||||
var pins = rev1Pins
|
||||
if rev > 1 {
|
||||
pins = rev2Pins
|
||||
}
|
||||
|
||||
return &host.Descriptor{
|
||||
GPIO: func() interface{} {
|
||||
return lgpio.New(pins)
|
||||
},
|
||||
I2C: func() interface{} {
|
||||
return li2c.New()
|
||||
},
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue