Browse Source

Merge pull request #11267 from teemuatlut/bf2_lpc_spi

[2.0.x] LPC1768: Expand hardware SPI class
Scott Lahteine 6 years ago
parent
commit
be7d1dfb3c
No account linked to committer's email address

+ 16
- 1
Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp View File

@@ -150,7 +150,7 @@
150 150
   }
151 151
 
152 152
   void spiInit(uint8_t spiRate) {
153
-
153
+    SSP_Cmd(LPC_SSP0, DISABLE); // Disable SSP0 before changing rate
154 154
     // table to convert Marlin spiRates (0-5 plus default) into bit rates
155 155
     uint32_t Marlin_speed[7]; // CPSR is always 2
156 156
     Marlin_speed[0] = 8333333; //(SCR:  2)  desired: 8,000,000  actual: 8,333,333  +4.2%  SPI_FULL_SPEED
@@ -242,6 +242,21 @@
242 242
 
243 243
 void SPIClass::begin() { spiBegin(); }
244 244
 
245
+void SPIClass::beginTransaction(SPISettings cfg) {
246
+  uint8_t spiRate;
247
+  switch(cfg.spiRate()) {
248
+    case 8000000: spiRate=0 ;break;
249
+    case 4000000: spiRate=1 ;break;
250
+    case 2000000: spiRate=2 ;break;
251
+    case 1000000: spiRate=3 ;break;
252
+    case  500000: spiRate=4 ;break;
253
+    case  250000: spiRate=5 ;break;
254
+    case  125000: spiRate=6 ;break;
255
+    default: spiRate=2; break;
256
+  }
257
+  spiInit(spiRate);
258
+}
259
+
245 260
 uint8_t SPIClass::transfer(uint8_t B) {
246 261
   return spiTransfer(B);
247 262
 }

Marlin/src/HAL/HAL_LPC1768/HardwareSerial.cpp → Marlin/src/HAL/HAL_LPC1768/include/HardwareSerial.cpp View File


Marlin/src/HAL/HAL_LPC1768/HardwareSerial.h → Marlin/src/HAL/HAL_LPC1768/include/HardwareSerial.h View File

@@ -23,9 +23,9 @@
23 23
 #ifndef HARDWARE_SERIAL_H_
24 24
 #define HARDWARE_SERIAL_H_
25 25
 
26
-#include "../../inc/MarlinConfigPre.h"
26
+#include "../../../inc/MarlinConfigPre.h"
27 27
 #if ENABLED(EMERGENCY_PARSER)
28
-  #include "../../feature/emergency_parser.h"
28
+  #include "../../../feature/emergency_parser.h"
29 29
 #endif
30 30
 
31 31
 #include <stdarg.h>

+ 5
- 2
Marlin/src/HAL/HAL_LPC1768/include/SPI.h View File

@@ -31,13 +31,16 @@
31 31
 
32 32
 class SPISettings {
33 33
   public:
34
-    SPISettings(int a, int b, int c) {};
34
+    SPISettings(uint32_t speed, int, int) : spi_speed(speed) {};
35
+    uint32_t spiRate() { return spi_speed; }
36
+  private:
37
+    uint32_t spi_speed;
35 38
 };
36 39
 
37 40
 class SPIClass {
38 41
   public:
39 42
     void begin();
40
-    void beginTransaction(SPISettings foo) {};
43
+    void beginTransaction(SPISettings);
41 44
     void endTransaction() {};
42 45
     uint8_t transfer(uint8_t data);
43 46
     uint16_t transfer16(uint16_t data);

Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp → Marlin/src/HAL/HAL_LPC1768/include/SoftwareSerial.cpp View File

@@ -36,13 +36,13 @@
36 36
 // Includes
37 37
 //
38 38
 //#include <WInterrupts.h>
39
-#include "../../inc/MarlinConfig.h"
40
-#include "../Delay.h"
39
+#include "../../../inc/MarlinConfig.h"
40
+#include "../../Delay.h"
41 41
 #include <stdint.h>
42 42
 #include <stdarg.h>
43 43
 #include <Arduino.h>
44 44
 #include <pinmapping.h>
45
-#include "fastio.h"
45
+#include "../fastio.h"
46 46
 #include "SoftwareSerial.h"
47 47
 
48 48
 void GpioEnableInt(uint32_t port, uint32_t pin, uint32_t mode);

Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h → Marlin/src/HAL/HAL_LPC1768/include/SoftwareSerial.h View File


Loading…
Cancel
Save