Skip to content

Commit

Permalink
Fix GPIO assigments for SPI (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Jul 5, 2022
1 parent b6d6dd7 commit d4acfdc
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 22 deletions.
8 changes: 2 additions & 6 deletions M5StackCommon/Core2ToughCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,23 +406,19 @@ static Tough()

#endif

// Setup SPI1
// Setup SPI2 (LCD and SD Card)
Configuration.SetPinFunction(23, DeviceFunction.SPI1_MOSI);
Configuration.SetPinFunction(38, DeviceFunction.SPI1_MISO);
Configuration.SetPinFunction(18, DeviceFunction.SPI1_CLOCK);

// Setup the screen with SP2 and SD Card
Configuration.SetPinFunction(23, DeviceFunction.SPI2_MOSI);
Configuration.SetPinFunction(38, DeviceFunction.SPI2_MISO);
Configuration.SetPinFunction(18, DeviceFunction.SPI2_CLOCK);

// Second serial port
Configuration.SetPinFunction(13, DeviceFunction.COM2_RX);
Configuration.SetPinFunction(14, DeviceFunction.COM2_TX);

// Setup second I2C bus (port A)
Configuration.SetPinFunction(33, DeviceFunction.I2C2_CLOCK);
Configuration.SetPinFunction(32, DeviceFunction.I2C2_DATA);

// The portA is the second I2C
_portANumber = 2;

Expand Down
18 changes: 17 additions & 1 deletion M5StackCommon/Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,23 @@ public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap)
#endif

// Create the screen
DisplayControl.Initialize(new SpiConfiguration(2, ChipSelect, DataCommand, Reset, BackLightPin), new ScreenConfiguration(0, 0, 320, 240), (uint)MemoryAllocationBitmap);
var displaySpiConfig = new SpiConfiguration(
1,
ChipSelect,
DataCommand,
Reset,
BackLightPin);

var screenConfig = new ScreenConfiguration(
0,
0,
320,
240);

_ = DisplayControl.Initialize(
displaySpiConfig,
screenConfig,
(uint)MemoryAllocationBitmap);

// set initial value for brightness
BrightnessPercentage = DefaultScreenBrightness;
Expand Down
6 changes: 3 additions & 3 deletions nanoFramework.Fire/Fire.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ static Fire()
_gpio = new();

// Config GPIOs for SPI (screen and SD Card)
Configuration.SetPinFunction(23, DeviceFunction.SPI2_MOSI);
Configuration.SetPinFunction(19, DeviceFunction.SPI2_MISO);
Configuration.SetPinFunction(18, DeviceFunction.SPI2_CLOCK);
Configuration.SetPinFunction(23, DeviceFunction.SPI1_MOSI);
Configuration.SetPinFunction(19, DeviceFunction.SPI1_MISO);
Configuration.SetPinFunction(18, DeviceFunction.SPI1_CLOCK);

// Second serial port
Configuration.SetPinFunction(16, DeviceFunction.COM2_RX);
Expand Down
20 changes: 19 additions & 1 deletion nanoFramework.Fire/Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,25 @@ public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap)
Controller = new();
Controller.OpenPin(BackLightPin, PinMode.Output);
Enabled = true;
DisplayControl.Initialize(new SpiConfiguration(2, ChipSelect, DataCommand, Reset, BackLightPin), new ScreenConfiguration(0, 0, 320, 240), (uint)MemoryAllocationBitmap);

var displaySpiConfig = new SpiConfiguration(
1,
ChipSelect,
DataCommand,
Reset,
BackLightPin);

var screenConfig = new ScreenConfiguration(
0,
0,
320,
240);

_ = DisplayControl.Initialize(
displaySpiConfig,
screenConfig,
(uint)MemoryAllocationBitmap);

_isInitialized = true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions nanoFramework.M5Core/M5Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ static M5Core()
_gpio = new();

// Config GPIOs for SPI (screen and SD Card)
Configuration.SetPinFunction(23, DeviceFunction.SPI2_MOSI);
Configuration.SetPinFunction(19, DeviceFunction.SPI2_MISO);
Configuration.SetPinFunction(18, DeviceFunction.SPI2_CLOCK);
Configuration.SetPinFunction(23, DeviceFunction.SPI1_MOSI);
Configuration.SetPinFunction(19, DeviceFunction.SPI1_MISO);
Configuration.SetPinFunction(18, DeviceFunction.SPI1_CLOCK);

// Second serial port
Configuration.SetPinFunction(16, DeviceFunction.COM2_RX);
Expand Down
20 changes: 19 additions & 1 deletion nanoFramework.M5Core/Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,25 @@ public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap)
Controller = new();
Controller.OpenPin(BackLightPin, PinMode.Output);
Enabled = true;
DisplayControl.Initialize(new SpiConfiguration(2, ChipSelect, DataCommand, Reset, BackLightPin), new ScreenConfiguration(0, 0, 320, 240), (uint)MemoryAllocationBitmap);

var displaySpiConfig = new SpiConfiguration(
1,
ChipSelect,
DataCommand,
Reset,
BackLightPin);

var screenConfig = new ScreenConfiguration(
0,
0,
320,
240);

_ = DisplayControl.Initialize(
displaySpiConfig,
screenConfig,
(uint)MemoryAllocationBitmap);

_isInitialized = true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions nanoFramework.M5StickCommon/M5StickCBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ static M5StickCPlus()
Configuration.SetPinFunction(32, DeviceFunction.I2C2_DATA);

// Set the pins for the screen
Configuration.SetPinFunction(15, DeviceFunction.SPI2_MOSI);
Configuration.SetPinFunction(13, DeviceFunction.SPI2_CLOCK);
Configuration.SetPinFunction(15, DeviceFunction.SPI1_MOSI);
Configuration.SetPinFunction(13, DeviceFunction.SPI1_CLOCK);
// This is not used but must be defined
Configuration.SetPinFunction(4, DeviceFunction.SPI2_MISO);
Configuration.SetPinFunction(4, DeviceFunction.SPI1_MISO);

// Setup the time if any
_rtc = new Pcf8563(I2cDevice.Create(new I2cConnectionSettings(1, Pcf8563.DefaultI2cAddress)));
Expand Down
31 changes: 29 additions & 2 deletions nanoFramework.M5StickCommon/Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,42 @@ public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap)
MemoryAllocationBitmap = memoryBitMapAllocation;
// Not used in Stick versions, AXP is doing this
BackLightPin = -1;

#if M5STICKC
_power = M5StickC.Power;
DisplayControl.Initialize(new SpiConfiguration(2, ChipSelect, DataCommand, Reset, BackLightPin), new ScreenConfiguration(26, 1, 80, 160), (uint)MemoryAllocationBitmap);
#else
_power = M5StickCPlus.Power;
DisplayControl.Initialize(new SpiConfiguration(2, ChipSelect, DataCommand, Reset, BackLightPin), new ScreenConfiguration(52, 40, 135, 240), (uint)MemoryAllocationBitmap);
#endif

var displaySpiConfig = new SpiConfiguration(
1,
ChipSelect,
DataCommand,
Reset,
BackLightPin);

#if M5STICKC
var screenConfig = new ScreenConfiguration(
26,
1,
80,
160);
#else
var screenConfig = new ScreenConfiguration(
52,
40,
135,
240);
#endif

_ = DisplayControl.Initialize(
displaySpiConfig,
screenConfig,
(uint)MemoryAllocationBitmap);

// Enable the screen
Enabled = true;

// For M5Stick, values from 2.6 to 3V are working fine
LuminosityPercentage = 100;
_power.EnableLDO3(true);
Expand Down
4 changes: 2 additions & 2 deletions version.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.0",
"version": "1.1",
"assemblyVersion": {
"precision": "revision"
},
"semVer1NumericIdentifierPadding": 3,
"nuGetPackageVersion": {
"semVer": 2.0,
"precision": "revision"
"precision": "build"
},
"publicReleaseRefSpec": [
"^refs/heads/main$",
Expand Down

0 comments on commit d4acfdc

Please sign in to comment.