1
0
mirror of https://github.com/kidoman/embd synced 2024-12-21 20:30:05 +01:00

gpio: CapNormal -> CapAnalog

This commit is contained in:
Karan Misra 2014-03-23 14:11:09 +05:30
parent 0002d02c28
commit 2d627aad67
6 changed files with 104 additions and 104 deletions

110
bbb.go
View File

@ -30,62 +30,62 @@ func init() {
} }
var bbbPins = PinMap{ var bbbPins = PinMap{
&PinDesc{ID: "P8_07", Aliases: []string{"66", "GPIO_66", "Caps: TIMER4"}, Caps: CapNormal | CapGPMC, DigitalLogical: 66}, &PinDesc{ID: "P8_07", Aliases: []string{"66", "GPIO_66", "Caps: TIMER4"}, Caps: CapDigital | CapGPMC, DigitalLogical: 66},
&PinDesc{ID: "P8_08", Aliases: []string{"67", "GPIO_67", "TIMER7"}, Caps: CapNormal | CapGPMC, DigitalLogical: 67}, &PinDesc{ID: "P8_08", Aliases: []string{"67", "GPIO_67", "TIMER7"}, Caps: CapDigital | CapGPMC, DigitalLogical: 67},
&PinDesc{ID: "P8_09", Aliases: []string{"69", "GPIO_69", "TIMER5"}, Caps: CapNormal | CapGPMC, DigitalLogical: 69}, &PinDesc{ID: "P8_09", Aliases: []string{"69", "GPIO_69", "TIMER5"}, Caps: CapDigital | CapGPMC, DigitalLogical: 69},
&PinDesc{ID: "P8_10", Aliases: []string{"68", "GPIO_68", "TIMER6"}, Caps: CapNormal | CapGPMC, DigitalLogical: 68}, &PinDesc{ID: "P8_10", Aliases: []string{"68", "GPIO_68", "TIMER6"}, Caps: CapDigital | CapGPMC, DigitalLogical: 68},
&PinDesc{ID: "P8_11", Aliases: []string{"45", "GPIO_45"}, Caps: CapNormal | CapGPMC, DigitalLogical: 45}, &PinDesc{ID: "P8_11", Aliases: []string{"45", "GPIO_45"}, Caps: CapDigital | CapGPMC, DigitalLogical: 45},
&PinDesc{ID: "P8_12", Aliases: []string{"44", "GPIO_44"}, Caps: CapNormal | CapGPMC, DigitalLogical: 44}, &PinDesc{ID: "P8_12", Aliases: []string{"44", "GPIO_44"}, Caps: CapDigital | CapGPMC, DigitalLogical: 44},
&PinDesc{ID: "P8_13", Aliases: []string{"23", "GPIO_23", "EHRPWM2B"}, Caps: CapNormal | CapGPMC, DigitalLogical: 23}, &PinDesc{ID: "P8_13", Aliases: []string{"23", "GPIO_23", "EHRPWM2B"}, Caps: CapDigital | CapGPMC, DigitalLogical: 23},
&PinDesc{ID: "P8_14", Aliases: []string{"26", "GPIO_26"}, Caps: CapNormal | CapGPMC, DigitalLogical: 26}, &PinDesc{ID: "P8_14", Aliases: []string{"26", "GPIO_26"}, Caps: CapDigital | CapGPMC, DigitalLogical: 26},
&PinDesc{ID: "P8_15", Aliases: []string{"47", "GPIO_47"}, Caps: CapNormal | CapGPMC, DigitalLogical: 47}, &PinDesc{ID: "P8_15", Aliases: []string{"47", "GPIO_47"}, Caps: CapDigital | CapGPMC, DigitalLogical: 47},
&PinDesc{ID: "P8_16", Aliases: []string{"46", "GPIO_46"}, Caps: CapNormal | CapGPMC, DigitalLogical: 46}, &PinDesc{ID: "P8_16", Aliases: []string{"46", "GPIO_46"}, Caps: CapDigital | CapGPMC, DigitalLogical: 46},
&PinDesc{ID: "P8_17", Aliases: []string{"27", "GPIO_27"}, Caps: CapNormal | CapGPMC, DigitalLogical: 27}, &PinDesc{ID: "P8_17", Aliases: []string{"27", "GPIO_27"}, Caps: CapDigital | CapGPMC, DigitalLogical: 27},
&PinDesc{ID: "P8_18", Aliases: []string{"65", "GPIO_65"}, Caps: CapNormal | CapGPMC, DigitalLogical: 65}, &PinDesc{ID: "P8_18", Aliases: []string{"65", "GPIO_65"}, Caps: CapDigital | CapGPMC, DigitalLogical: 65},
&PinDesc{ID: "P8_19", Aliases: []string{"22", "GPIO_22", "EHRPWM2A"}, Caps: CapNormal | CapGPMC, DigitalLogical: 22}, &PinDesc{ID: "P8_19", Aliases: []string{"22", "GPIO_22", "EHRPWM2A"}, Caps: CapDigital | CapGPMC, DigitalLogical: 22},
&PinDesc{ID: "P8_26", Aliases: []string{"61", "GPIO_61"}, Caps: CapNormal | CapGPMC, DigitalLogical: 61}, &PinDesc{ID: "P8_26", Aliases: []string{"61", "GPIO_61"}, Caps: CapDigital | CapGPMC, DigitalLogical: 61},
&PinDesc{ID: "P8_27", Aliases: []string{"86", "GPIO_86"}, Caps: CapNormal | CapLCD, DigitalLogical: 86}, &PinDesc{ID: "P8_27", Aliases: []string{"86", "GPIO_86"}, Caps: CapDigital | CapLCD, DigitalLogical: 86},
&PinDesc{ID: "P8_28", Aliases: []string{"88", "GPIO_88"}, Caps: CapNormal | CapLCD, DigitalLogical: 88}, &PinDesc{ID: "P8_28", Aliases: []string{"88", "GPIO_88"}, Caps: CapDigital | CapLCD, DigitalLogical: 88},
&PinDesc{ID: "P8_29", Aliases: []string{"87", "GPIO_87"}, Caps: CapNormal | CapLCD, DigitalLogical: 87}, &PinDesc{ID: "P8_29", Aliases: []string{"87", "GPIO_87"}, Caps: CapDigital | CapLCD, DigitalLogical: 87},
&PinDesc{ID: "P8_30", Aliases: []string{"89", "GPIO_89"}, Caps: CapNormal | CapLCD, DigitalLogical: 89}, &PinDesc{ID: "P8_30", Aliases: []string{"89", "GPIO_89"}, Caps: CapDigital | CapLCD, DigitalLogical: 89},
&PinDesc{ID: "P8_31", Aliases: []string{"10", "GPIO_10", "UART5_CTSN"}, Caps: CapNormal | CapLCD, DigitalLogical: 10}, &PinDesc{ID: "P8_31", Aliases: []string{"10", "GPIO_10", "UART5_CTSN"}, Caps: CapDigital | CapLCD, DigitalLogical: 10},
&PinDesc{ID: "P8_32", Aliases: []string{"11", "GPIO_11", "UART5_RTSN"}, Caps: CapNormal | CapLCD, DigitalLogical: 11}, &PinDesc{ID: "P8_32", Aliases: []string{"11", "GPIO_11", "UART5_RTSN"}, Caps: CapDigital | CapLCD, DigitalLogical: 11},
&PinDesc{ID: "P8_33", Aliases: []string{"9", "GPIO_9 ", "UART4_RTSN"}, Caps: CapNormal | CapLCD, DigitalLogical: 9}, &PinDesc{ID: "P8_33", Aliases: []string{"9", "GPIO_9 ", "UART4_RTSN"}, Caps: CapDigital | CapLCD, DigitalLogical: 9},
&PinDesc{ID: "P8_34", Aliases: []string{"81", "GPIO_81", "UART3_RTSN"}, Caps: CapNormal | CapLCD, DigitalLogical: 81}, &PinDesc{ID: "P8_34", Aliases: []string{"81", "GPIO_81", "UART3_RTSN"}, Caps: CapDigital | CapLCD, DigitalLogical: 81},
&PinDesc{ID: "P8_35", Aliases: []string{"8", "GPIO_8 ", "UART4_CTSN"}, Caps: CapNormal | CapLCD, DigitalLogical: 8}, &PinDesc{ID: "P8_35", Aliases: []string{"8", "GPIO_8 ", "UART4_CTSN"}, Caps: CapDigital | CapLCD, DigitalLogical: 8},
&PinDesc{ID: "P8_36", Aliases: []string{"80", "GPIO_80", "UART3_CTSN"}, Caps: CapNormal | CapLCD, DigitalLogical: 80}, &PinDesc{ID: "P8_36", Aliases: []string{"80", "GPIO_80", "UART3_CTSN"}, Caps: CapDigital | CapLCD, DigitalLogical: 80},
&PinDesc{ID: "P8_37", Aliases: []string{"78", "GPIO_78", "UART5_TXD"}, Caps: CapNormal | CapLCD, DigitalLogical: 78}, &PinDesc{ID: "P8_37", Aliases: []string{"78", "GPIO_78", "UART5_TXD"}, Caps: CapDigital | CapLCD, DigitalLogical: 78},
&PinDesc{ID: "P8_38", Aliases: []string{"79", "GPIO_79", "UART5_RXD"}, Caps: CapNormal | CapLCD, DigitalLogical: 79}, &PinDesc{ID: "P8_38", Aliases: []string{"79", "GPIO_79", "UART5_RXD"}, Caps: CapDigital | CapLCD, DigitalLogical: 79},
&PinDesc{ID: "P8_39", Aliases: []string{"76", "GPIO_76"}, Caps: CapNormal | CapLCD, DigitalLogical: 76}, &PinDesc{ID: "P8_39", Aliases: []string{"76", "GPIO_76"}, Caps: CapDigital | CapLCD, DigitalLogical: 76},
&PinDesc{ID: "P8_40", Aliases: []string{"77", "GPIO_77"}, Caps: CapNormal | CapLCD, DigitalLogical: 77}, &PinDesc{ID: "P8_40", Aliases: []string{"77", "GPIO_77"}, Caps: CapDigital | CapLCD, DigitalLogical: 77},
&PinDesc{ID: "P8_41", Aliases: []string{"74", "GPIO_74"}, Caps: CapNormal | CapLCD, DigitalLogical: 74}, &PinDesc{ID: "P8_41", Aliases: []string{"74", "GPIO_74"}, Caps: CapDigital | CapLCD, DigitalLogical: 74},
&PinDesc{ID: "P8_42", Aliases: []string{"75", "GPIO_75"}, Caps: CapNormal | CapLCD, DigitalLogical: 75}, &PinDesc{ID: "P8_42", Aliases: []string{"75", "GPIO_75"}, Caps: CapDigital | CapLCD, DigitalLogical: 75},
&PinDesc{ID: "P8_43", Aliases: []string{"72", "GPIO_72"}, Caps: CapNormal | CapLCD, DigitalLogical: 72}, &PinDesc{ID: "P8_43", Aliases: []string{"72", "GPIO_72"}, Caps: CapDigital | CapLCD, DigitalLogical: 72},
&PinDesc{ID: "P8_44", Aliases: []string{"73", "GPIO_73"}, Caps: CapNormal | CapLCD, DigitalLogical: 73}, &PinDesc{ID: "P8_44", Aliases: []string{"73", "GPIO_73"}, Caps: CapDigital | CapLCD, DigitalLogical: 73},
&PinDesc{ID: "P8_45", Aliases: []string{"70", "GPIO_70"}, Caps: CapNormal | CapLCD, DigitalLogical: 70}, &PinDesc{ID: "P8_45", Aliases: []string{"70", "GPIO_70"}, Caps: CapDigital | CapLCD, DigitalLogical: 70},
&PinDesc{ID: "P8_46", Aliases: []string{"71", "GPIO_71"}, Caps: CapNormal | CapLCD, DigitalLogical: 71}, &PinDesc{ID: "P8_46", Aliases: []string{"71", "GPIO_71"}, Caps: CapDigital | CapLCD, DigitalLogical: 71},
&PinDesc{ID: "P9_11", Aliases: []string{"30", "GPIO_30", "UART4_RXD"}, Caps: CapNormal | CapUART, DigitalLogical: 30}, &PinDesc{ID: "P9_11", Aliases: []string{"30", "GPIO_30", "UART4_RXD"}, Caps: CapDigital | CapUART, DigitalLogical: 30},
&PinDesc{ID: "P9_12", Aliases: []string{"60", "GPIO_60", "GPIO1_28"}, Caps: CapNormal, DigitalLogical: 60}, &PinDesc{ID: "P9_12", Aliases: []string{"60", "GPIO_60", "GPIO1_28"}, Caps: CapDigital, DigitalLogical: 60},
&PinDesc{ID: "P9_13", Aliases: []string{"31", "GPIO_31", "UART4_TXD"}, Caps: CapNormal | CapUART, DigitalLogical: 31}, &PinDesc{ID: "P9_13", Aliases: []string{"31", "GPIO_31", "UART4_TXD"}, Caps: CapDigital | CapUART, DigitalLogical: 31},
&PinDesc{ID: "P9_14", Aliases: []string{"50", "GPIO_50", "EHRPWM1A"}, Caps: CapNormal | CapPWM, DigitalLogical: 50}, &PinDesc{ID: "P9_14", Aliases: []string{"50", "GPIO_50", "EHRPWM1A"}, Caps: CapDigital | CapPWM, DigitalLogical: 50},
&PinDesc{ID: "P9_15", Aliases: []string{"48", "GPIO_48", "GPIO1_16"}, Caps: CapNormal, DigitalLogical: 48}, &PinDesc{ID: "P9_15", Aliases: []string{"48", "GPIO_48", "GPIO1_16"}, Caps: CapDigital, DigitalLogical: 48},
&PinDesc{ID: "P9_16", Aliases: []string{"51", "GPIO_51", "EHRPWM1B"}, Caps: CapNormal | CapPWM, DigitalLogical: 51}, &PinDesc{ID: "P9_16", Aliases: []string{"51", "GPIO_51", "EHRPWM1B"}, Caps: CapDigital | CapPWM, DigitalLogical: 51},
&PinDesc{ID: "P9_17", Aliases: []string{"5", "GPIO_5", "I2C1_SCL"}, Caps: CapNormal | CapI2C, DigitalLogical: 5}, &PinDesc{ID: "P9_17", Aliases: []string{"5", "GPIO_5", "I2C1_SCL"}, Caps: CapDigital | CapI2C, DigitalLogical: 5},
&PinDesc{ID: "P9_18", Aliases: []string{"4", "GPIO_4", "I2C1_SDA"}, Caps: CapNormal | CapI2C, DigitalLogical: 4}, &PinDesc{ID: "P9_18", Aliases: []string{"4", "GPIO_4", "I2C1_SDA"}, Caps: CapDigital | CapI2C, DigitalLogical: 4},
&PinDesc{ID: "P9_19", Aliases: []string{"13", "GPIO_13", "I2C2_SCL"}, Caps: CapNormal | CapI2C, DigitalLogical: 13}, &PinDesc{ID: "P9_19", Aliases: []string{"13", "GPIO_13", "I2C2_SCL"}, Caps: CapDigital | CapI2C, DigitalLogical: 13},
&PinDesc{ID: "P9_20", Aliases: []string{"12", "GPIO_12", "I2C2_SDA"}, Caps: CapNormal | CapI2C, DigitalLogical: 12}, &PinDesc{ID: "P9_20", Aliases: []string{"12", "GPIO_12", "I2C2_SDA"}, Caps: CapDigital | CapI2C, DigitalLogical: 12},
&PinDesc{ID: "P9_21", Aliases: []string{"3", "GPIO_3", "UART2_TXD"}, Caps: CapNormal | CapUART, DigitalLogical: 3}, &PinDesc{ID: "P9_21", Aliases: []string{"3", "GPIO_3", "UART2_TXD"}, Caps: CapDigital | CapUART, DigitalLogical: 3},
&PinDesc{ID: "P9_22", Aliases: []string{"2", "GPIO_2", "UART2_RXD"}, Caps: CapNormal | CapUART, DigitalLogical: 2}, &PinDesc{ID: "P9_22", Aliases: []string{"2", "GPIO_2", "UART2_RXD"}, Caps: CapDigital | CapUART, DigitalLogical: 2},
&PinDesc{ID: "P9_23", Aliases: []string{"49", "GPIO_49", "GPIO1_17"}, Caps: CapNormal, DigitalLogical: 49}, &PinDesc{ID: "P9_23", Aliases: []string{"49", "GPIO_49", "GPIO1_17"}, Caps: CapDigital, DigitalLogical: 49},
&PinDesc{ID: "P9_24", Aliases: []string{"15", "GPIO_15", "UART1_TXD"}, Caps: CapNormal | CapUART, DigitalLogical: 15}, &PinDesc{ID: "P9_24", Aliases: []string{"15", "GPIO_15", "UART1_TXD"}, Caps: CapDigital | CapUART, DigitalLogical: 15},
&PinDesc{ID: "P9_25", Aliases: []string{"117", "GPIO_117", "GPIO3_21"}, Caps: CapNormal, DigitalLogical: 117}, &PinDesc{ID: "P9_25", Aliases: []string{"117", "GPIO_117", "GPIO3_21"}, Caps: CapDigital, DigitalLogical: 117},
&PinDesc{ID: "P9_26", Aliases: []string{"14", "GPIO_14", "UART1_RXD"}, Caps: CapNormal | CapUART, DigitalLogical: 14}, &PinDesc{ID: "P9_26", Aliases: []string{"14", "GPIO_14", "UART1_RXD"}, Caps: CapDigital | CapUART, DigitalLogical: 14},
&PinDesc{ID: "P9_27", Aliases: []string{"115", "GPIO_115", "GPIO3_19"}, Caps: CapNormal, DigitalLogical: 115}, &PinDesc{ID: "P9_27", Aliases: []string{"115", "GPIO_115", "GPIO3_19"}, Caps: CapDigital, DigitalLogical: 115},
&PinDesc{ID: "P9_28", Aliases: []string{"113", "GPIO_113", "SPI1_CS0"}, Caps: CapNormal | CapSPI, DigitalLogical: 113}, &PinDesc{ID: "P9_28", Aliases: []string{"113", "GPIO_113", "SPI1_CS0"}, Caps: CapDigital | CapSPI, DigitalLogical: 113},
&PinDesc{ID: "P9_29", Aliases: []string{"111", "GPIO_111", "SPI1_D0"}, Caps: CapNormal | CapSPI, DigitalLogical: 111}, &PinDesc{ID: "P9_29", Aliases: []string{"111", "GPIO_111", "SPI1_D0"}, Caps: CapDigital | CapSPI, DigitalLogical: 111},
&PinDesc{ID: "P9_30", Aliases: []string{"112", "GPIO_112", "SPI1_D1"}, Caps: CapNormal | CapSPI, DigitalLogical: 112}, &PinDesc{ID: "P9_30", Aliases: []string{"112", "GPIO_112", "SPI1_D1"}, Caps: CapDigital | CapSPI, DigitalLogical: 112},
&PinDesc{ID: "P9_31", Aliases: []string{"110", "GPIO_110", "SPI1_SCLK"}, Caps: CapNormal | CapSPI, DigitalLogical: 110}, &PinDesc{ID: "P9_31", Aliases: []string{"110", "GPIO_110", "SPI1_SCLK"}, Caps: CapDigital | CapSPI, DigitalLogical: 110},
&PinDesc{ID: "P9_32", Aliases: []string{"VADC"}}, &PinDesc{ID: "P9_32", Aliases: []string{"VADC"}},
&PinDesc{ID: "P9_33", Aliases: []string{"4", "AIN4"}, Caps: CapAnalog, AnalogLogical: 4}, &PinDesc{ID: "P9_33", Aliases: []string{"4", "AIN4"}, Caps: CapAnalog, AnalogLogical: 4},
&PinDesc{ID: "P9_34", Aliases: []string{"AGND"}}, &PinDesc{ID: "P9_34", Aliases: []string{"AGND"}},

View File

@ -35,7 +35,7 @@ func (io *gpioDriver) DigitalPin(key interface{}) (DigitalPin, error) {
return nil, errors.New("gpio: digital io not supported on this host") return nil, errors.New("gpio: digital io not supported on this host")
} }
pd, found := io.pinMap.Lookup(key, CapNormal) pd, found := io.pinMap.Lookup(key, CapDigital)
if !found { if !found {
return nil, fmt.Errorf("gpio: could not find pin matching %v", key) return nil, fmt.Errorf("gpio: could not find pin matching %v", key)
} }

View File

@ -50,7 +50,7 @@ func TestGpioDriverDigitalPin(t *testing.T) {
{1, 1}, {1, 1},
} }
var pinMap = PinMap{ var pinMap = PinMap{
&PinDesc{ID: "P1_1", Aliases: []string{"1"}, Caps: CapNormal, DigitalLogical: 1}, &PinDesc{ID: "P1_1", Aliases: []string{"1"}, Caps: CapDigital, DigitalLogical: 1},
} }
driver := newGPIODriver(pinMap, newFakeDigitalPin, nil) driver := newGPIODriver(pinMap, newFakeDigitalPin, nil)
for _, test := range tests { for _, test := range tests {
@ -114,7 +114,7 @@ func TestGpioDriverAnalogPin(t *testing.T) {
func TestGpioDriverUnavailablePinType(t *testing.T) { func TestGpioDriverUnavailablePinType(t *testing.T) {
var pinMap = PinMap{ var pinMap = PinMap{
&PinDesc{ID: "P1_1", Aliases: []string{"1"}, Caps: CapNormal, DigitalLogical: 1}, &PinDesc{ID: "P1_1", Aliases: []string{"1"}, Caps: CapDigital, DigitalLogical: 1},
&PinDesc{ID: "P1_2", Aliases: []string{"1"}, Caps: CapAnalog, AnalogLogical: 1}, &PinDesc{ID: "P1_2", Aliases: []string{"1"}, Caps: CapAnalog, AnalogLogical: 1},
} }
driver := newGPIODriver(pinMap, nil, nil) driver := newGPIODriver(pinMap, nil, nil)

8
pin.go
View File

@ -8,8 +8,8 @@ import (
) )
const ( const (
// CapNormal represents the digital IO capability. // CapDigital represents the digital IO capability.
CapNormal int = 1 << iota CapDigital int = 1 << iota
// CapI2C represents pins with the I2C capability. // CapI2C represents pins with the I2C capability.
CapI2C CapI2C
@ -50,10 +50,10 @@ type PinMap []*PinDesc
// combination. This allows the same keys to be used across pins with differing // combination. This allows the same keys to be used across pins with differing
// capabilities. For example, it is perfectly fine to have: // capabilities. For example, it is perfectly fine to have:
// //
// pin1: {Aliases: [10, GPIO10], Cap: CapNormal} // pin1: {Aliases: [10, GPIO10], Cap: CapDigital}
// pin2: {Aliases: [10, AIN0], Cap: CapAnalog} // pin2: {Aliases: [10, AIN0], Cap: CapAnalog}
// //
// Searching for 10 with CapNormal will return pin1 and searching for // Searching for 10 with CapDigital will return pin1 and searching for
// 10 with CapAnalog will return pin2. This makes for a very pleasant to use API. // 10 with CapAnalog will return pin2. This makes for a very pleasant to use API.
func (m PinMap) Lookup(k interface{}, cap int) (*PinDesc, bool) { func (m PinMap) Lookup(k interface{}, cap int) (*PinDesc, bool) {
var ks string var ks string

View File

@ -12,15 +12,15 @@ func TestPinMapLookup(t *testing.T) {
}{ }{
{"10", CapAnalog, "P1_1", true}, {"10", CapAnalog, "P1_1", true},
{10, CapAnalog, "P1_1", true}, {10, CapAnalog, "P1_1", true},
{"10", CapNormal, "P1_2", true}, {"10", CapDigital, "P1_2", true},
{"P1_2", CapNormal, "P1_2", true}, {"P1_2", CapDigital, "P1_2", true},
{"P1_2", CapAnalog, "P1_2", true}, {"P1_2", CapAnalog, "P1_2", true},
{"GPIO10", CapNormal, "P1_2", true}, {"GPIO10", CapDigital, "P1_2", true},
{key: "NOTTHERE", found: false}, {key: "NOTTHERE", found: false},
} }
var pinMap = PinMap{ var pinMap = PinMap{
&PinDesc{ID: "P1_1", Aliases: []string{"AN1", "10"}, Caps: CapAnalog}, &PinDesc{ID: "P1_1", Aliases: []string{"AN1", "10"}, Caps: CapAnalog},
&PinDesc{ID: "P1_2", Aliases: []string{"10", "GPIO10"}, Caps: CapNormal}, &PinDesc{ID: "P1_2", Aliases: []string{"10", "GPIO10"}, Caps: CapDigital},
} }
for _, test := range tests { for _, test := range tests {
pd, found := pinMap.Lookup(test.key, test.cap) pd, found := pinMap.Lookup(test.key, test.cap)
@ -34,8 +34,8 @@ func TestPinMapLookup(t *testing.T) {
if pd.ID != test.id { if pd.ID != test.id {
var capStr string var capStr string
switch test.cap { switch test.cap {
case CapNormal: case CapDigital:
capStr = "CapNormal" capStr = "CapDigital"
case CapAnalog: case CapAnalog:
capStr = "CapAnalog" capStr = "CapAnalog"
default: default:
@ -49,9 +49,9 @@ func TestPinMapLookup(t *testing.T) {
func BenchmarkPinMapLookup(b *testing.B) { func BenchmarkPinMapLookup(b *testing.B) {
var pinMap = PinMap{ var pinMap = PinMap{
&PinDesc{ID: "P1_1", Aliases: []string{"AN1", "10"}, Caps: CapAnalog}, &PinDesc{ID: "P1_1", Aliases: []string{"AN1", "10"}, Caps: CapAnalog},
&PinDesc{ID: "P1_2", Aliases: []string{"10", "GPIO10"}, Caps: CapNormal}, &PinDesc{ID: "P1_2", Aliases: []string{"10", "GPIO10"}, Caps: CapDigital},
} }
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
pinMap.Lookup("GPIO10", CapNormal) pinMap.Lookup("GPIO10", CapDigital)
} }
} }

68
rpi.go
View File

@ -23,41 +23,41 @@ func init() {
} }
var rpiRev1Pins = PinMap{ var rpiRev1Pins = PinMap{
&PinDesc{ID: "P1_3", Aliases: []string{"0", "GPIO_0", "SDA", "I2C0_SDA"}, Caps: CapNormal | CapI2C, DigitalLogical: 0}, &PinDesc{ID: "P1_3", Aliases: []string{"0", "GPIO_0", "SDA", "I2C0_SDA"}, Caps: CapDigital | CapI2C, DigitalLogical: 0},
&PinDesc{ID: "P1_5", Aliases: []string{"1", "GPIO_1", "SCL", "I2C0_SCL"}, Caps: CapNormal | CapI2C, DigitalLogical: 1}, &PinDesc{ID: "P1_5", Aliases: []string{"1", "GPIO_1", "SCL", "I2C0_SCL"}, Caps: CapDigital | CapI2C, DigitalLogical: 1},
&PinDesc{ID: "P1_7", Aliases: []string{"4", "GPIO_4", "GPCLK0"}, Caps: CapNormal, DigitalLogical: 4}, &PinDesc{ID: "P1_7", Aliases: []string{"4", "GPIO_4", "GPCLK0"}, Caps: CapDigital, DigitalLogical: 4},
&PinDesc{ID: "P1_8", Aliases: []string{"14", "GPIO_14", "TXD", "UART0_TXD"}, Caps: CapNormal | CapUART, DigitalLogical: 14}, &PinDesc{ID: "P1_8", Aliases: []string{"14", "GPIO_14", "TXD", "UART0_TXD"}, Caps: CapDigital | CapUART, DigitalLogical: 14},
&PinDesc{ID: "P1_10", Aliases: []string{"15", "GPIO_15", "RXD", "UART0_RXD"}, Caps: CapNormal | CapUART, DigitalLogical: 15}, &PinDesc{ID: "P1_10", Aliases: []string{"15", "GPIO_15", "RXD", "UART0_RXD"}, Caps: CapDigital | CapUART, DigitalLogical: 15},
&PinDesc{ID: "P1_11", Aliases: []string{"17", "GPIO_17"}, Caps: CapNormal, DigitalLogical: 17}, &PinDesc{ID: "P1_11", Aliases: []string{"17", "GPIO_17"}, Caps: CapDigital, DigitalLogical: 17},
&PinDesc{ID: "P1_12", Aliases: []string{"18", "GPIO_18", "PCM_CLK"}, Caps: CapNormal, DigitalLogical: 18}, &PinDesc{ID: "P1_12", Aliases: []string{"18", "GPIO_18", "PCM_CLK"}, Caps: CapDigital, DigitalLogical: 18},
&PinDesc{ID: "P1_13", Aliases: []string{"21", "GPIO_21"}, Caps: CapNormal, DigitalLogical: 21}, &PinDesc{ID: "P1_13", Aliases: []string{"21", "GPIO_21"}, Caps: CapDigital, DigitalLogical: 21},
&PinDesc{ID: "P1_15", Aliases: []string{"22", "GPIO_22"}, Caps: CapNormal, DigitalLogical: 22}, &PinDesc{ID: "P1_15", Aliases: []string{"22", "GPIO_22"}, Caps: CapDigital, DigitalLogical: 22},
&PinDesc{ID: "P1_16", Aliases: []string{"23", "GPIO_23"}, Caps: CapNormal, DigitalLogical: 23}, &PinDesc{ID: "P1_16", Aliases: []string{"23", "GPIO_23"}, Caps: CapDigital, DigitalLogical: 23},
&PinDesc{ID: "P1_18", Aliases: []string{"24", "GPIO_24"}, Caps: CapNormal, DigitalLogical: 24}, &PinDesc{ID: "P1_18", Aliases: []string{"24", "GPIO_24"}, Caps: CapDigital, DigitalLogical: 24},
&PinDesc{ID: "P1_19", Aliases: []string{"10", "GPIO_10", "MOSI", "SPI0_MOSI"}, Caps: CapNormal | CapSPI, DigitalLogical: 10}, &PinDesc{ID: "P1_19", Aliases: []string{"10", "GPIO_10", "MOSI", "SPI0_MOSI"}, Caps: CapDigital | CapSPI, DigitalLogical: 10},
&PinDesc{ID: "P1_21", Aliases: []string{"9", "GPIO_9", "MISO", "SPI0_MISO"}, Caps: CapNormal | CapSPI, DigitalLogical: 9}, &PinDesc{ID: "P1_21", Aliases: []string{"9", "GPIO_9", "MISO", "SPI0_MISO"}, Caps: CapDigital | CapSPI, DigitalLogical: 9},
&PinDesc{ID: "P1_22", Aliases: []string{"25", "GPIO_25"}, Caps: CapNormal, DigitalLogical: 25}, &PinDesc{ID: "P1_22", Aliases: []string{"25", "GPIO_25"}, Caps: CapDigital, DigitalLogical: 25},
&PinDesc{ID: "P1_23", Aliases: []string{"11", "GPIO_11", "SCLK", "SPI0_SCLK"}, Caps: CapNormal | CapSPI, DigitalLogical: 11}, &PinDesc{ID: "P1_23", Aliases: []string{"11", "GPIO_11", "SCLK", "SPI0_SCLK"}, Caps: CapDigital | CapSPI, DigitalLogical: 11},
&PinDesc{ID: "P1_24", Aliases: []string{"8", "GPIO_8", "CE0", "SPI0_CE0_N"}, Caps: CapNormal | CapSPI, DigitalLogical: 8}, &PinDesc{ID: "P1_24", Aliases: []string{"8", "GPIO_8", "CE0", "SPI0_CE0_N"}, Caps: CapDigital | CapSPI, DigitalLogical: 8},
&PinDesc{ID: "P1_26", Aliases: []string{"7", "GPIO_7", "CE1", "SPI0_CE1_N"}, Caps: CapNormal | CapSPI, DigitalLogical: 7}, &PinDesc{ID: "P1_26", Aliases: []string{"7", "GPIO_7", "CE1", "SPI0_CE1_N"}, Caps: CapDigital | CapSPI, DigitalLogical: 7},
} }
var rpiRev2Pins = PinMap{ var rpiRev2Pins = PinMap{
&PinDesc{ID: "P1_3", Aliases: []string{"2", "GPIO_2", "SDA", "I2C1_SDA"}, Caps: CapNormal | CapI2C, DigitalLogical: 2}, &PinDesc{ID: "P1_3", Aliases: []string{"2", "GPIO_2", "SDA", "I2C1_SDA"}, Caps: CapDigital | CapI2C, DigitalLogical: 2},
&PinDesc{ID: "P1_5", Aliases: []string{"3", "GPIO_3", "SCL", "I2C1_SCL"}, Caps: CapNormal | CapI2C, DigitalLogical: 3}, &PinDesc{ID: "P1_5", Aliases: []string{"3", "GPIO_3", "SCL", "I2C1_SCL"}, Caps: CapDigital | CapI2C, DigitalLogical: 3},
&PinDesc{ID: "P1_7", Aliases: []string{"4", "GPIO_4", "GPCLK0"}, Caps: CapNormal, DigitalLogical: 4}, &PinDesc{ID: "P1_7", Aliases: []string{"4", "GPIO_4", "GPCLK0"}, Caps: CapDigital, DigitalLogical: 4},
&PinDesc{ID: "P1_8", Aliases: []string{"14", "GPIO_14", "TXD", "UART0_TXD"}, Caps: CapNormal | CapUART, DigitalLogical: 14}, &PinDesc{ID: "P1_8", Aliases: []string{"14", "GPIO_14", "TXD", "UART0_TXD"}, Caps: CapDigital | CapUART, DigitalLogical: 14},
&PinDesc{ID: "P1_10", Aliases: []string{"15", "GPIO_15", "RXD", "UART0_RXD"}, Caps: CapNormal | CapUART, DigitalLogical: 15}, &PinDesc{ID: "P1_10", Aliases: []string{"15", "GPIO_15", "RXD", "UART0_RXD"}, Caps: CapDigital | CapUART, DigitalLogical: 15},
&PinDesc{ID: "P1_11", Aliases: []string{"17", "GPIO_17"}, Caps: CapNormal, DigitalLogical: 17}, &PinDesc{ID: "P1_11", Aliases: []string{"17", "GPIO_17"}, Caps: CapDigital, DigitalLogical: 17},
&PinDesc{ID: "P1_12", Aliases: []string{"18", "GPIO_18", "PCM_CLK"}, Caps: CapNormal, DigitalLogical: 18}, &PinDesc{ID: "P1_12", Aliases: []string{"18", "GPIO_18", "PCM_CLK"}, Caps: CapDigital, DigitalLogical: 18},
&PinDesc{ID: "P1_13", Aliases: []string{"27", "GPIO_27"}, Caps: CapNormal, DigitalLogical: 27}, &PinDesc{ID: "P1_13", Aliases: []string{"27", "GPIO_27"}, Caps: CapDigital, DigitalLogical: 27},
&PinDesc{ID: "P1_15", Aliases: []string{"22", "GPIO_22"}, Caps: CapNormal, DigitalLogical: 22}, &PinDesc{ID: "P1_15", Aliases: []string{"22", "GPIO_22"}, Caps: CapDigital, DigitalLogical: 22},
&PinDesc{ID: "P1_16", Aliases: []string{"23", "GPIO_23"}, Caps: CapNormal, DigitalLogical: 23}, &PinDesc{ID: "P1_16", Aliases: []string{"23", "GPIO_23"}, Caps: CapDigital, DigitalLogical: 23},
&PinDesc{ID: "P1_18", Aliases: []string{"24", "GPIO_24"}, Caps: CapNormal, DigitalLogical: 24}, &PinDesc{ID: "P1_18", Aliases: []string{"24", "GPIO_24"}, Caps: CapDigital, DigitalLogical: 24},
&PinDesc{ID: "P1_19", Aliases: []string{"10", "GPIO_10", "MOSI", "SPI0_MOSI"}, Caps: CapNormal | CapSPI, DigitalLogical: 10}, &PinDesc{ID: "P1_19", Aliases: []string{"10", "GPIO_10", "MOSI", "SPI0_MOSI"}, Caps: CapDigital | CapSPI, DigitalLogical: 10},
&PinDesc{ID: "P1_21", Aliases: []string{"9", "GPIO_9", "MISO", "SPI0_MISO"}, Caps: CapNormal | CapSPI, DigitalLogical: 9}, &PinDesc{ID: "P1_21", Aliases: []string{"9", "GPIO_9", "MISO", "SPI0_MISO"}, Caps: CapDigital | CapSPI, DigitalLogical: 9},
&PinDesc{ID: "P1_22", Aliases: []string{"25", "GPIO_25"}, Caps: CapNormal, DigitalLogical: 25}, &PinDesc{ID: "P1_22", Aliases: []string{"25", "GPIO_25"}, Caps: CapDigital, DigitalLogical: 25},
&PinDesc{ID: "P1_23", Aliases: []string{"11", "GPIO_11", "SCLK", "SPI0_SCLK"}, Caps: CapNormal | CapSPI, DigitalLogical: 11}, &PinDesc{ID: "P1_23", Aliases: []string{"11", "GPIO_11", "SCLK", "SPI0_SCLK"}, Caps: CapDigital | CapSPI, DigitalLogical: 11},
&PinDesc{ID: "P1_24", Aliases: []string{"8", "GPIO_8", "CE0", "SPI0_CE0_N"}, Caps: CapNormal | CapSPI, DigitalLogical: 8}, &PinDesc{ID: "P1_24", Aliases: []string{"8", "GPIO_8", "CE0", "SPI0_CE0_N"}, Caps: CapDigital | CapSPI, DigitalLogical: 8},
&PinDesc{ID: "P1_26", Aliases: []string{"7", "GPIO_7", "CE1", "SPI0_CE1_N"}, Caps: CapNormal | CapSPI, DigitalLogical: 7}, &PinDesc{ID: "P1_26", Aliases: []string{"7", "GPIO_7", "CE1", "SPI0_CE1_N"}, Caps: CapDigital | CapSPI, DigitalLogical: 7},
} }