Skip to content

Commit

Permalink
Further tweaks before PinFunc
Browse files Browse the repository at this point in the history
- Remove unused headers-list -n flag
- Standardize JTAG_TCK, JTAG_TMS, JTAG_TDO, JTAG_TDI.
- Reorganise gpio_test.go in preparation for PinFunc testing.
- Remove unnecessary gpion variable in bcm283x.
  • Loading branch information
maruel committed Aug 11, 2018
1 parent b45c457 commit 6e2faaa
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 29 deletions.
7 changes: 3 additions & 4 deletions cmd/headers-list/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func printFailures(state *periph.State) {
}
}

func printHardware(invalid bool, all map[string][][]pin.Pin) {
func printHardware(all map[string][][]pin.Pin) {
names := make([]string, 0, len(all))
for name := range all {
names = append(names, name)
Expand Down Expand Up @@ -88,7 +88,6 @@ func printHardware(invalid bool, all map[string][][]pin.Pin) {
}

func mainImpl() error {
invalid := flag.Bool("n", false, "show not connected/INVALID pins")
verbose := flag.Bool("v", false, "verbose mode")
flag.Parse()
if !*verbose {
Expand All @@ -110,14 +109,14 @@ func mainImpl() error {
return errors.New("no header found")
}
if flag.NArg() == 0 {
printHardware(*invalid, all)
printHardware(all)
} else {
for _, name := range flag.Args() {
hdr, ok := all[name]
if !ok {
return fmt.Errorf("header %q is not registered", name)
}
printHardware(*invalid, map[string][][]pin.Pin{name: hdr})
printHardware(map[string][][]pin.Pin{name: hdr})
}
}
return nil
Expand Down
19 changes: 13 additions & 6 deletions conn/gpio/gpio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
"time"

"periph.io/x/periph/conn"
"periph.io/x/periph/conn/physic"
)

func TestStrings(t *testing.T) {
Expand Down Expand Up @@ -103,16 +103,23 @@ func TestParseDuty(t *testing.T) {
}

func TestInvalid(t *testing.T) {
if INVALID.String() != "INVALID" || INVALID.Name() != "INVALID" || INVALID.Number() != -1 || INVALID.Function() != "" {
// conn.Resource
if INVALID.String() != "INVALID" {
t.Fail()
}
if INVALID.In(Float, NoEdge) != errInvalidPin || INVALID.Read() != Low || INVALID.WaitForEdge(time.Minute) || INVALID.Pull() != PullNoChange {
if err := INVALID.Halt(); err != nil {
t.Fatal(err)
}
// pin.Pin
if INVALID.Name() != "INVALID" || INVALID.Number() != -1 || INVALID.Function() != "" {
t.Fail()
}
if INVALID.Out(Low) != errInvalidPin {
// gpio.PinIn
if INVALID.In(Float, NoEdge) != errInvalidPin || INVALID.Read() != Low || INVALID.WaitForEdge(time.Minute) || INVALID.Pull() != PullNoChange || INVALID.DefaultPull() != PullNoChange {
t.Fail()
}
if err := INVALID.(conn.Resource).Halt(); err != nil {
t.Fatal(err)
// gpio.PinOut
if INVALID.Out(Low) != errInvalidPin || INVALID.PWM(DutyMax, physic.Hertz) != errInvalidPin {
t.Fail()
}
}
16 changes: 8 additions & 8 deletions host/allwinner/a64.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ func init() {
// - NAND connects to a NAND flash controller.
// - CSI and CCI are for video capture.
var mappingA64 = map[string][5]string{
"PB0": {"UART2_TX", "", "JTAG_MS0", "", "PB_EINT0"},
"PB1": {"UART2_RX", "", "JTAG_CK0", "SIM_PWREN", "PB_EINT1"},
"PB2": {"UART2_RTS", "", "JTAG_DO0", "SIM_VPPEN", "PB_EINT2"},
"PB3": {"UART2_CTS", "I2S0_MCLK", "JTAG_DI0", "SIM_VPPPP", "PB_EINT3"},
"PB0": {"UART2_TX", "", "JTAG0_TMS", "", "PB_EINT0"},
"PB1": {"UART2_RX", "", "JTAG0_TCK", "SIM_PWREN", "PB_EINT1"},
"PB2": {"UART2_RTS", "", "JTAG0_TDO", "SIM_VPPEN", "PB_EINT2"},
"PB3": {"UART2_CTS", "I2S0_MCLK", "JTAG0_TDI", "SIM_VPPPP", "PB_EINT3"},
"PB4": {"AIF2_SYNC", "I2S0_WS", "", "SIM_CLK", "PB_EINT4"},
"PB5": {"AIF2_BCLK", "I2S0_SCK", "", "SIM_DATA", "PB_EINT5"},
"PB6": {"AIF2_DOUT", "I2S0_DOUT", "", "SIM_RST", "PB_EINT6"},
Expand Down Expand Up @@ -120,12 +120,12 @@ var mappingA64 = map[string][5]string{
"PE15": {"", "I2C2_SDA"},
"PE16": {""},
"PE17": {""},
"PF0": {"SDC0_D1", "JTAG_MS1"},
"PF1": {"SDC0_D0", "JTAG_DI1"},
"PF0": {"SDC0_D1", "JTAG1_TMS"},
"PF1": {"SDC0_D0", "JTAG1_TDI"},
"PF2": {"SDC0_CLK", "UART0_TX"},
"PF3": {"SDC0_CMD", "JTAG_DO1"},
"PF3": {"SDC0_CMD", "JTAG1_TDO"},
"PF4": {"SDC0_D3", "UART0_RX"},
"PF5": {"SDC0_D2", "JTAG_CK1"},
"PF5": {"SDC0_D2", "JTAG1_TCK"},
"PF6": {""},
"PG0": {"SDC1_CLK", "", "", "", "PG_EINT0"},
"PG1": {"SDC1_CMD", "", "", "", "PG_EINT1"},
Expand Down
8 changes: 4 additions & 4 deletions host/allwinner/gpio_pl.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@ var mapping = [13][5]string{
{"RSB_SDA", "I2C_SDA", "", "", "PL_EINT1"}, // PL1
{"UART_TX", "", "", "", "PL_EINT2"}, // PL2
{"UART_RX", "", "", "", "PL_EINT3"}, // PL3
{"JTAG_MS", "", "", "", "PL_EINT4"}, // PL4
{"JTAG_CK", "", "", "", "PL_EINT5"}, // PL5
{"JTAG_DO", "", "", "", "PL_EINT6"}, // PL6
{"JTAG_DI", "", "", "", "PL_EINT7"}, // PL7
{"JTAG_TMS", "", "", "", "PL_EINT4"}, // PL4
{"JTAG_TCK", "", "", "", "PL_EINT5"}, // PL5
{"JTAG_TDO", "", "", "", "PL_EINT6"}, // PL6
{"JTAG_TDI", "", "", "", "PL_EINT7"}, // PL7
{"I2C_CSK", "", "", "", "PL_EINT8"}, // PL8
{"I2C_SDA", "", "", "", "PL_EINT9"}, // PL9
{"PWM0", "", "", "", "PL_EINT10"}, // PL10
Expand Down
8 changes: 4 additions & 4 deletions host/allwinner/r8.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ var mappingR8 = map[string][5]string{
"PE9": {"TS_D5", "CSI_D5", "SDC2_CLK"},
"PE10": {"TS_D6", "CSI_D6", "UART1_TX"},
"PE11": {"TS_D7", "CSI_D7", "UART1_RX"},
"PF0": {"SDC0_D1", "", "JTAG_MS1"},
"PF1": {"SDC0_D0", "", "JTAG_DI1"},
"PF0": {"SDC0_D1", "", "JTAG1_TMS"},
"PF1": {"SDC0_D0", "", "JTAG1_TDI"},
"PF2": {"SDC0_CLK", "", "UART0_TX"},
"PF3": {"SDC0_CMD", "", "JTAG_DO1"},
"PF3": {"SDC0_CMD", "", "JTAG1_TDO"},
"PF4": {"SDC0_D3", "", "UART0_RX"},
"PF5": {"SDC0_D2", "", "JTAG_CK1"},
"PF5": {"SDC0_D2", "", "JTAG1_TCK"},
"PG0": {"GPS_CLK", "", "", "", "EINT0"},
"PG1": {"GPS_SIGN", "", "", "", "EINT1"},
"PG2": {"GPS_MAG", "", "", "", "EINT2"},
Expand Down
5 changes: 2 additions & 3 deletions host/bcm283x/gpio.go
Original file line number Diff line number Diff line change
Expand Up @@ -1157,14 +1157,13 @@ func (d *driverGPIO) Init() (bool, error) {
for i := range cpuPins {
name := cpuPins[i].name
num := strconv.Itoa(cpuPins[i].number)
gpion := "GPIO" + num

// Initializes the sysfs corresponding pin right away.
cpuPins[i].sysfsPin = sysfs.Pins[cpuPins[i].number]

// Unregister the pin if already registered. This happens with sysfs-gpio.
// Do not error on it, since sysfs-gpio may have failed to load.
_ = gpioreg.Unregister(gpion)
_ = gpioreg.Unregister(name)
_ = gpioreg.Unregister(num)

if err := gpioreg.Register(&cpuPins[i]); err != nil {
Expand All @@ -1183,7 +1182,7 @@ func (d *driverGPIO) Init() (bool, error) {
// functionality is changed.
if _, ok := functions[f]; !ok {
functions[f] = struct{}{}
if err := gpioreg.RegisterAlias(f, gpion); err != nil {
if err := gpioreg.RegisterAlias(f, name); err != nil {
return true, err
}
}
Expand Down

0 comments on commit 6e2faaa

Please sign in to comment.