Skip to content

Commit d4acfdc

Browse files
authored
Fix GPIO assigments for SPI (#186)
1 parent b6d6dd7 commit d4acfdc

File tree

9 files changed

+97
-22
lines changed

9 files changed

+97
-22
lines changed

M5StackCommon/Core2ToughCommon.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,23 +406,19 @@ static Tough()
406406

407407
#endif
408408

409-
// Setup SPI1
409+
// Setup SPI2 (LCD and SD Card)
410410
Configuration.SetPinFunction(23, DeviceFunction.SPI1_MOSI);
411411
Configuration.SetPinFunction(38, DeviceFunction.SPI1_MISO);
412412
Configuration.SetPinFunction(18, DeviceFunction.SPI1_CLOCK);
413413

414-
// Setup the screen with SP2 and SD Card
415-
Configuration.SetPinFunction(23, DeviceFunction.SPI2_MOSI);
416-
Configuration.SetPinFunction(38, DeviceFunction.SPI2_MISO);
417-
Configuration.SetPinFunction(18, DeviceFunction.SPI2_CLOCK);
418-
419414
// Second serial port
420415
Configuration.SetPinFunction(13, DeviceFunction.COM2_RX);
421416
Configuration.SetPinFunction(14, DeviceFunction.COM2_TX);
422417

423418
// Setup second I2C bus (port A)
424419
Configuration.SetPinFunction(33, DeviceFunction.I2C2_CLOCK);
425420
Configuration.SetPinFunction(32, DeviceFunction.I2C2_DATA);
421+
426422
// The portA is the second I2C
427423
_portANumber = 2;
428424

M5StackCommon/Screen.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,23 @@ public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap)
7070
#endif
7171

7272
// Create the screen
73-
DisplayControl.Initialize(new SpiConfiguration(2, ChipSelect, DataCommand, Reset, BackLightPin), new ScreenConfiguration(0, 0, 320, 240), (uint)MemoryAllocationBitmap);
73+
var displaySpiConfig = new SpiConfiguration(
74+
1,
75+
ChipSelect,
76+
DataCommand,
77+
Reset,
78+
BackLightPin);
79+
80+
var screenConfig = new ScreenConfiguration(
81+
0,
82+
0,
83+
320,
84+
240);
85+
86+
_ = DisplayControl.Initialize(
87+
displaySpiConfig,
88+
screenConfig,
89+
(uint)MemoryAllocationBitmap);
7490

7591
// set initial value for brightness
7692
BrightnessPercentage = DefaultScreenBrightness;

nanoFramework.Fire/Fire.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ static Fire()
170170
_gpio = new();
171171

172172
// Config GPIOs for SPI (screen and SD Card)
173-
Configuration.SetPinFunction(23, DeviceFunction.SPI2_MOSI);
174-
Configuration.SetPinFunction(19, DeviceFunction.SPI2_MISO);
175-
Configuration.SetPinFunction(18, DeviceFunction.SPI2_CLOCK);
173+
Configuration.SetPinFunction(23, DeviceFunction.SPI1_MOSI);
174+
Configuration.SetPinFunction(19, DeviceFunction.SPI1_MISO);
175+
Configuration.SetPinFunction(18, DeviceFunction.SPI1_CLOCK);
176176

177177
// Second serial port
178178
Configuration.SetPinFunction(16, DeviceFunction.COM2_RX);

nanoFramework.Fire/Screen.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,25 @@ public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap)
3737
Controller = new();
3838
Controller.OpenPin(BackLightPin, PinMode.Output);
3939
Enabled = true;
40-
DisplayControl.Initialize(new SpiConfiguration(2, ChipSelect, DataCommand, Reset, BackLightPin), new ScreenConfiguration(0, 0, 320, 240), (uint)MemoryAllocationBitmap);
40+
41+
var displaySpiConfig = new SpiConfiguration(
42+
1,
43+
ChipSelect,
44+
DataCommand,
45+
Reset,
46+
BackLightPin);
47+
48+
var screenConfig = new ScreenConfiguration(
49+
0,
50+
0,
51+
320,
52+
240);
53+
54+
_ = DisplayControl.Initialize(
55+
displaySpiConfig,
56+
screenConfig,
57+
(uint)MemoryAllocationBitmap);
58+
4159
_isInitialized = true;
4260
}
4361
}

nanoFramework.M5Core/M5Core.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ static M5Core()
155155
_gpio = new();
156156

157157
// Config GPIOs for SPI (screen and SD Card)
158-
Configuration.SetPinFunction(23, DeviceFunction.SPI2_MOSI);
159-
Configuration.SetPinFunction(19, DeviceFunction.SPI2_MISO);
160-
Configuration.SetPinFunction(18, DeviceFunction.SPI2_CLOCK);
158+
Configuration.SetPinFunction(23, DeviceFunction.SPI1_MOSI);
159+
Configuration.SetPinFunction(19, DeviceFunction.SPI1_MISO);
160+
Configuration.SetPinFunction(18, DeviceFunction.SPI1_CLOCK);
161161

162162
// Second serial port
163163
Configuration.SetPinFunction(16, DeviceFunction.COM2_RX);

nanoFramework.M5Core/Screen.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,25 @@ public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap)
3737
Controller = new();
3838
Controller.OpenPin(BackLightPin, PinMode.Output);
3939
Enabled = true;
40-
DisplayControl.Initialize(new SpiConfiguration(2, ChipSelect, DataCommand, Reset, BackLightPin), new ScreenConfiguration(0, 0, 320, 240), (uint)MemoryAllocationBitmap);
40+
41+
var displaySpiConfig = new SpiConfiguration(
42+
1,
43+
ChipSelect,
44+
DataCommand,
45+
Reset,
46+
BackLightPin);
47+
48+
var screenConfig = new ScreenConfiguration(
49+
0,
50+
0,
51+
320,
52+
240);
53+
54+
_ = DisplayControl.Initialize(
55+
displaySpiConfig,
56+
screenConfig,
57+
(uint)MemoryAllocationBitmap);
58+
4159
_isInitialized = true;
4260
}
4361
}

nanoFramework.M5StickCommon/M5StickCBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ static M5StickCPlus()
185185
Configuration.SetPinFunction(32, DeviceFunction.I2C2_DATA);
186186

187187
// Set the pins for the screen
188-
Configuration.SetPinFunction(15, DeviceFunction.SPI2_MOSI);
189-
Configuration.SetPinFunction(13, DeviceFunction.SPI2_CLOCK);
188+
Configuration.SetPinFunction(15, DeviceFunction.SPI1_MOSI);
189+
Configuration.SetPinFunction(13, DeviceFunction.SPI1_CLOCK);
190190
// This is not used but must be defined
191-
Configuration.SetPinFunction(4, DeviceFunction.SPI2_MISO);
191+
Configuration.SetPinFunction(4, DeviceFunction.SPI1_MISO);
192192

193193
// Setup the time if any
194194
_rtc = new Pcf8563(I2cDevice.Create(new I2cConnectionSettings(1, Pcf8563.DefaultI2cAddress)));

nanoFramework.M5StickCommon/Screen.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,42 @@ public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap)
3939
MemoryAllocationBitmap = memoryBitMapAllocation;
4040
// Not used in Stick versions, AXP is doing this
4141
BackLightPin = -1;
42+
4243
#if M5STICKC
4344
_power = M5StickC.Power;
44-
DisplayControl.Initialize(new SpiConfiguration(2, ChipSelect, DataCommand, Reset, BackLightPin), new ScreenConfiguration(26, 1, 80, 160), (uint)MemoryAllocationBitmap);
4545
#else
4646
_power = M5StickCPlus.Power;
47-
DisplayControl.Initialize(new SpiConfiguration(2, ChipSelect, DataCommand, Reset, BackLightPin), new ScreenConfiguration(52, 40, 135, 240), (uint)MemoryAllocationBitmap);
4847
#endif
48+
49+
var displaySpiConfig = new SpiConfiguration(
50+
1,
51+
ChipSelect,
52+
DataCommand,
53+
Reset,
54+
BackLightPin);
55+
56+
#if M5STICKC
57+
var screenConfig = new ScreenConfiguration(
58+
26,
59+
1,
60+
80,
61+
160);
62+
#else
63+
var screenConfig = new ScreenConfiguration(
64+
52,
65+
40,
66+
135,
67+
240);
68+
#endif
69+
70+
_ = DisplayControl.Initialize(
71+
displaySpiConfig,
72+
screenConfig,
73+
(uint)MemoryAllocationBitmap);
74+
4975
// Enable the screen
5076
Enabled = true;
77+
5178
// For M5Stick, values from 2.6 to 3V are working fine
5279
LuminosityPercentage = 100;
5380
_power.EnableLDO3(true);

version.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "1.0",
3+
"version": "1.1",
44
"assemblyVersion": {
55
"precision": "revision"
66
},
77
"semVer1NumericIdentifierPadding": 3,
88
"nuGetPackageVersion": {
99
"semVer": 2.0,
10-
"precision": "revision"
10+
"precision": "build"
1111
},
1212
"publicReleaseRefSpec": [
1313
"^refs/heads/main$",

0 commit comments

Comments
 (0)