Browse Source

Merge pull request #11267 from teemuatlut/bf2_lpc_spi

[2.0.x] LPC1768: Expand hardware SPI class
pull/1/head
Scott Lahteine 7 years ago
committed by GitHub
parent
commit
be7d1dfb3c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp
  2. 0
      Marlin/src/HAL/HAL_LPC1768/include/HardwareSerial.cpp
  3. 4
      Marlin/src/HAL/HAL_LPC1768/include/HardwareSerial.h
  4. 7
      Marlin/src/HAL/HAL_LPC1768/include/SPI.h
  5. 6
      Marlin/src/HAL/HAL_LPC1768/include/SoftwareSerial.cpp
  6. 0
      Marlin/src/HAL/HAL_LPC1768/include/SoftwareSerial.h

17
Marlin/src/HAL/HAL_LPC1768/HAL_spi.cpp

@ -150,7 +150,7 @@
} }
void spiInit(uint8_t spiRate) { void spiInit(uint8_t spiRate) {
SSP_Cmd(LPC_SSP0, DISABLE); // Disable SSP0 before changing rate
// table to convert Marlin spiRates (0-5 plus default) into bit rates // table to convert Marlin spiRates (0-5 plus default) into bit rates
uint32_t Marlin_speed[7]; // CPSR is always 2 uint32_t Marlin_speed[7]; // CPSR is always 2
Marlin_speed[0] = 8333333; //(SCR: 2) desired: 8,000,000 actual: 8,333,333 +4.2% SPI_FULL_SPEED Marlin_speed[0] = 8333333; //(SCR: 2) desired: 8,000,000 actual: 8,333,333 +4.2% SPI_FULL_SPEED
@ -242,6 +242,21 @@
void SPIClass::begin() { spiBegin(); } void SPIClass::begin() { spiBegin(); }
void SPIClass::beginTransaction(SPISettings cfg) {
uint8_t spiRate;
switch(cfg.spiRate()) {
case 8000000: spiRate=0 ;break;
case 4000000: spiRate=1 ;break;
case 2000000: spiRate=2 ;break;
case 1000000: spiRate=3 ;break;
case 500000: spiRate=4 ;break;
case 250000: spiRate=5 ;break;
case 125000: spiRate=6 ;break;
default: spiRate=2; break;
}
spiInit(spiRate);
}
uint8_t SPIClass::transfer(uint8_t B) { uint8_t SPIClass::transfer(uint8_t B) {
return spiTransfer(B); return spiTransfer(B);
} }

0
Marlin/src/HAL/HAL_LPC1768/HardwareSerial.cpp → Marlin/src/HAL/HAL_LPC1768/include/HardwareSerial.cpp

4
Marlin/src/HAL/HAL_LPC1768/HardwareSerial.h → Marlin/src/HAL/HAL_LPC1768/include/HardwareSerial.h

@ -23,9 +23,9 @@
#ifndef HARDWARE_SERIAL_H_ #ifndef HARDWARE_SERIAL_H_
#define HARDWARE_SERIAL_H_ #define HARDWARE_SERIAL_H_
#include "../../inc/MarlinConfigPre.h" #include "../../../inc/MarlinConfigPre.h"
#if ENABLED(EMERGENCY_PARSER) #if ENABLED(EMERGENCY_PARSER)
#include "../../feature/emergency_parser.h" #include "../../../feature/emergency_parser.h"
#endif #endif
#include <stdarg.h> #include <stdarg.h>

7
Marlin/src/HAL/HAL_LPC1768/include/SPI.h

@ -31,13 +31,16 @@
class SPISettings { class SPISettings {
public: public:
SPISettings(int a, int b, int c) {}; SPISettings(uint32_t speed, int, int) : spi_speed(speed) {};
uint32_t spiRate() { return spi_speed; }
private:
uint32_t spi_speed;
}; };
class SPIClass { class SPIClass {
public: public:
void begin(); void begin();
void beginTransaction(SPISettings foo) {}; void beginTransaction(SPISettings);
void endTransaction() {}; void endTransaction() {};
uint8_t transfer(uint8_t data); uint8_t transfer(uint8_t data);
uint16_t transfer16(uint16_t data); uint16_t transfer16(uint16_t data);

6
Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp → Marlin/src/HAL/HAL_LPC1768/include/SoftwareSerial.cpp

@ -36,13 +36,13 @@
// Includes // Includes
// //
//#include <WInterrupts.h> //#include <WInterrupts.h>
#include "../../inc/MarlinConfig.h" #include "../../../inc/MarlinConfig.h"
#include "../Delay.h" #include "../../Delay.h"
#include <stdint.h> #include <stdint.h>
#include <stdarg.h> #include <stdarg.h>
#include <Arduino.h> #include <Arduino.h>
#include <pinmapping.h> #include <pinmapping.h>
#include "fastio.h" #include "../fastio.h"
#include "SoftwareSerial.h" #include "SoftwareSerial.h"
void GpioEnableInt(uint32_t port, uint32_t pin, uint32_t mode); void GpioEnableInt(uint32_t port, uint32_t pin, uint32_t mode);

0
Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h → Marlin/src/HAL/HAL_LPC1768/include/SoftwareSerial.h

Loading…
Cancel
Save