Skip to content
This repository was archived by the owner on Jul 9, 2020. It is now read-only.

Commit 8b7a4e5

Browse files
sdavisdavi
authored andcommitted
Board config to support Software SPI
1 parent 5678fab commit 8b7a4e5

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

src/LPC/BoardConfig.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "RepRapFirmware.h"
1717
#include "GCodes/GCodeResult.h"
1818
#include "sd_mmc.h"
19+
#include "SharedSPI.h"
1920

2021
#include "Platform.h"
2122

@@ -68,7 +69,7 @@ static const boardConfigEntry_t boardConfigs[]=
6869
{"externalSDCard.csPin", &SdSpiCSPins[1], nullptr, cvPinType},
6970
{"externalSDCard.cardDetectPin", &SdCardDetectPins[1], nullptr, cvPinType},
7071
{"lpc.externalSDCard.spiFrequencyHz", &ExternalSDCardFrequency, nullptr, cvUint32Type},
71-
72+
{"lpc.externalSDCard.spiChannel", &ExternalSDCardSSPChannel, nullptr, cvUint8Type},
7273

7374
{"lcd.lcdCSPin", &LcdCSPin, nullptr, cvPinType},
7475
{"lcd.lcdBeepPin", &LcdBeepPin, nullptr, cvPinType},
@@ -77,10 +78,12 @@ static const boardConfigEntry_t boardConfigs[]=
7778
{"lcd.encoderPinSw", &EncoderPinSw, nullptr, cvPinType},
7879
{"lcd.lcdDCPin", &LcdDCPin, nullptr, cvPinType},
7980
{"lcd.panelButtonPin", &PanelButtonPin, nullptr, cvPinType},
81+
{"lcd.spiChannel", &LcdSpiChannel, nullptr, cvUint8Type},
8082

83+
{"lpc.softwareSPI.pins", SoftwareSPIPins, &NumSoftwareSPIPins, cvPinType}, //SCK, MISO, MOSI
84+
8185
{"lpc.uartPanelDueMode", &UARTPanelDueMode, nullptr, cvBoolType},
8286

83-
8487
};
8588

8689

@@ -164,6 +167,8 @@ void BoardConfig::Init() {
164167
}
165168
}
166169

170+
//Setup the Software SPI Pins
171+
sspi_setPinsForChannel(SWSPI0, SoftwareSPIPins[0], SoftwareSPIPins[1], SoftwareSPIPins[2]);
167172

168173
//Configure the HW Timers
169174
ConfigureTimerForPWM(0, Timer1Frequency); //Timer1 is channel 0
@@ -177,15 +182,22 @@ void BoardConfig::Init() {
177182
//Configure the External SDCard
178183
if(SdSpiCSPins[1] != NoPin)
179184
{
185+
setPullup(SdCardDetectPins[1], true);
186+
//set the SSP Channel for External SDCard
187+
if(ExternalSDCardSSPChannel == SSP0 || ExternalSDCardSSPChannel == SSP1 || ExternalSDCardSSPChannel == SWSPI0){
188+
sd_mmc_setSSPChannel(1, ExternalSDCardSSPChannel); //must be called before reinit
189+
}
180190
//set the CSPin and the frequency for the External SDCard
181191
sd_mmc_reinit_slot(1, SdSpiCSPins[1], ExternalSDCardFrequency);
182192
}
183193

184-
//Init Extra pins from LCD (not used anywhere yet)
194+
//Init pins from LCD (not used anywhere yet)
185195
//make sure to init ButtonPin as input incase user presses button
186-
if(PanelButtonPin != NoPin) pinMode(PanelButtonPin, INPUT);
187-
if(LcdDCPin != NoPin) pinMode(LcdDCPin, OUTPUT_HIGH);
188-
196+
if(PanelButtonPin != NoPin) pinMode(PanelButtonPin, INPUT); //unused
197+
if(LcdDCPin != NoPin) pinMode(LcdDCPin, OUTPUT_HIGH); //unused
198+
if(LcdBeepPin != NoPin) pinMode(LcdBeepPin, OUTPUT_LOW);
199+
// Set the 12864 display CS pin low to prevent it from receiving garbage due to other SPI traffic
200+
if(LcdCSPin != NoPin) pinMode(LcdCSPin, OUTPUT_LOW);
189201

190202

191203
}

src/LPC/Pins_LPC.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ Pin TachoPins[NumTachos] = { NoPin };
3030
Pin SdCardDetectPins[NumSdCards] = { NoPin, NoPin };
3131
Pin SdSpiCSPins[NumSdCards] = { P0_6, NoPin };// Internal, external. Note:: ("slot" 0 in CORE is configured to be LCP SSP1 to match default RRF behaviour)
3232
uint32_t ExternalSDCardFrequency = 2000000; //default to 2MHz
33+
uint32_t InternalSDCardFrequency = 25000000; //default to 25MHz
34+
SSPChannel ExternalSDCardSSPChannel = SSP0;
3335

34-
uint32_t InternalSDCardFrequency = 10000000; //default to 10MHz
3536

3637
Pin SpecialPinMap[MaxNumberSpecialPins] = { NoPin, NoPin, NoPin, NoPin, NoPin, NoPin, NoPin, NoPin, NoPin, NoPin };
3738

@@ -43,6 +44,8 @@ Pin EncoderPinA = NoPin;
4344
Pin EncoderPinB = NoPin;
4445
Pin EncoderPinSw = NoPin; //click
4546
Pin PanelButtonPin = NoPin; //Extra button on Viki and RRD Panels (reset/back etc)
47+
SSPChannel LcdSpiChannel = SSP0;
48+
4649

4750
//Pin LED1 = NoPin;
4851
//Pin LED2 = NoPin;
@@ -67,5 +70,6 @@ float digipotFactor = 113.33; //factor for converting current to digipot value
6770

6871
bool UARTPanelDueMode = false; //disable PanelDue support by default
6972

73+
Pin SoftwareSPIPins[3] = {NoPin, NoPin, NoPin}; //GPIO pins for softwareSPI (used with SharedSPI)
7074

7175

src/LPC/Pins_LPC.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,15 @@ constexpr Pin SdWriteProtectPins[NumSdCards] = { NoPin, NoPin }; //unused on LPC
144144
extern Pin SdSpiCSPins[NumSdCards];
145145
extern uint32_t ExternalSDCardFrequency;
146146
extern uint32_t InternalSDCardFrequency;
147+
extern SSPChannel ExternalSDCardSSPChannel;
147148

148149

149150
// Definition of which pins we allow to be controlled using M42 etc
150151
constexpr size_t MaxNumberSpecialPins = 10;
151152
extern Pin SpecialPinMap[MaxNumberSpecialPins];
152153

153154
constexpr uint32_t LcdSpiClockFrequency = 2000000; // 2.0MHz
154-
constexpr SSPChannel LcdSpiChannel = SSP0;
155+
extern SSPChannel LcdSpiChannel;
155156
extern Pin LcdCSPin;
156157
extern Pin LcdDCPin;
157158
extern Pin LcdBeepPin;
@@ -160,7 +161,6 @@ extern Pin EncoderPinB;
160161
extern Pin EncoderPinSw;
161162
extern Pin PanelButtonPin;
162163

163-
164164
//LEDs
165165
extern Pin StatusLEDPin;
166166
extern Pin DiagPin;
@@ -169,6 +169,8 @@ extern Pin DiagPin;
169169
constexpr size_t NUM_SERIAL_CHANNELS = 2;
170170
extern bool UARTPanelDueMode;
171171

172+
constexpr size_t NumSoftwareSPIPins = 3;
173+
extern Pin SoftwareSPIPins[3]; //GPIO pins for softwareSPI (used with SharedSPI)
172174

173175
// Use TX0/RX0 for the auxiliary serial line
174176
#if defined(__MBED__)

0 commit comments

Comments
 (0)