Skip to content

Commit

Permalink
Merge pull request #385 from WildernessLabs/feature/init-gpio-input
Browse files Browse the repository at this point in the history
initialize GPIOs to inputs, not outputs
  • Loading branch information
adrianstevens authored Oct 24, 2023
2 parents 4122f1c + 7eeb9c5 commit 9907cb2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public override void Initialize(string[]? reservedPins)
{
base.Initialize(reservedPins);

ConfigureOutput(STM32.GpioPort.PortA, 0, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureOutput(STM32.GpioPort.PortD, 5, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureOutput(STM32.GpioPort.PortA, 10, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureOutput(STM32.GpioPort.PortC, 8, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureInput(STM32.GpioPort.PortA, 0);
ConfigureInput(STM32.GpioPort.PortD, 5);
ConfigureInput(STM32.GpioPort.PortA, 10);
ConfigureInput(STM32.GpioPort.PortC, 8);
}
}

Expand Down
34 changes: 19 additions & 15 deletions source/implementations/f7/Meadow.F7/Devices/F7GPIOManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,21 @@ public virtual void Initialize(string[]? reservedPinList)
{
UPD.DumpClockRegisters();
}

// these are the "unallocated" pins on the meadow
ConfigureOutput(STM32.GpioPort.PortI, 9, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureOutput(STM32.GpioPort.PortH, 13, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureOutput(STM32.GpioPort.PortC, 6, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureOutput(STM32.GpioPort.PortB, 8, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureOutput(STM32.GpioPort.PortB, 9, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureOutput(STM32.GpioPort.PortC, 7, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureOutput(STM32.GpioPort.PortB, 0, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureOutput(STM32.GpioPort.PortB, 1, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureOutput(STM32.GpioPort.PortH, 10, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureOutput(STM32.GpioPort.PortC, 9, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureOutput(STM32.GpioPort.PortB, 14, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureOutput(STM32.GpioPort.PortB, 15, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureOutput(STM32.GpioPort.PortG, 3, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureOutput(STM32.GpioPort.PortE, 3, STM32.ResistorMode.Float, STM32.GPIOSpeed.Speed_50MHz, STM32.OutputType.PushPull, false);
ConfigureInput(STM32.GpioPort.PortI, 9);
ConfigureInput(STM32.GpioPort.PortH, 13);
ConfigureInput(STM32.GpioPort.PortC, 6);
ConfigureInput(STM32.GpioPort.PortB, 8);
ConfigureInput(STM32.GpioPort.PortB, 9);
ConfigureInput(STM32.GpioPort.PortC, 7);
ConfigureInput(STM32.GpioPort.PortB, 0);
ConfigureInput(STM32.GpioPort.PortB, 1);
ConfigureInput(STM32.GpioPort.PortH, 10);
ConfigureInput(STM32.GpioPort.PortC, 9);
ConfigureInput(STM32.GpioPort.PortB, 14);
ConfigureInput(STM32.GpioPort.PortB, 15);
ConfigureInput(STM32.GpioPort.PortG, 3);
ConfigureInput(STM32.GpioPort.PortE, 3);
}

/// <summary>
Expand Down Expand Up @@ -269,6 +268,11 @@ private bool ConfigureOutput(IPin pin, STM32.ResistorMode resistor, STM32.GPIOSp
return ConfigureGpio(pin, STM32.GpioMode.Output, resistor, speed, type, initialState, InterruptMode.None, TimeSpan.Zero, TimeSpan.Zero, true, true);
}

internal bool ConfigureInput(STM32.GpioPort port, int pin, STM32.ResistorMode resistor = STM32.ResistorMode.Float)
{
return ConfigureGpio(port, pin, STM32.GpioMode.Input, resistor, STM32.GPIOSpeed.Speed_2MHz, STM32.OutputType.PushPull, false, InterruptMode.None);
}

internal bool ConfigureOutput(STM32.GpioPort port, int pin, STM32.ResistorMode resistor, STM32.GPIOSpeed speed, STM32.OutputType type, bool initialState)
{
return ConfigureGpio(port, pin, STM32.GpioMode.Output, resistor, speed, type, initialState, InterruptMode.None);
Expand Down

0 comments on commit 9907cb2

Please sign in to comment.