Tweaky LPC1768 SPI spacing/style

This commit is contained in:
Scott Lahteine 2018-02-03 20:25:57 -06:00
parent dbd2189945
commit 33ec599ca0
3 changed files with 31 additions and 57 deletions

View file

@ -47,7 +47,7 @@
* https://github.com/MarlinFirmware/Marlin/tree/071c7a78f27078fd4aee9a3ef365fcf5e143531e
*/
#include "src/inc/MarlinConfig.h"
#include "../../inc/MarlinConfig.h"
#ifdef TARGET_LPC1768

View file

@ -26,11 +26,10 @@
*/
/**
*
* For TARGET_LPC1768
*/
#include "src/inc/MarlinConfig.h"
#include "../../inc/MarlinConfig.h"
#ifdef TARGET_LPC1768
@ -49,68 +48,43 @@
* 6 - about 125 kHz peak
*/
uint8_t swSpiTransfer(uint8_t b, uint8_t spi_speed, pin_t sck_pin, pin_t miso_pin, pin_t mosi_pin) {
uint8_t swSpiTransfer(uint8_t b, const uint8_t spi_speed, const pin_t sck_pin, const pin_t miso_pin, const pin_t mosi_pin) {
for (uint8_t i = 0; i < 8; i++) {
if (spi_speed == 0) {
if (b & 0x80)
WRITE(mosi_pin, HIGH);
else
WRITE(mosi_pin, LOW);
WRITE(mosi_pin, !!(b & 0x80));
WRITE(sck_pin, HIGH);
b <<= 1;
if (miso_pin >= 0)
if (READ(miso_pin)) b |= 1;
if (miso_pin >= 0 && READ(miso_pin)) b |= 1;
WRITE(sck_pin, LOW);
}
else {
if (b & 0x80)
const uint8_t state = (b & 0x80) ? HIGH : LOW;
for (uint8_t j = 0; j < spi_speed; j++)
WRITE(mosi_pin, HIGH);
else
for (uint8_t j = 0; j < spi_speed; j++)
WRITE(mosi_pin, LOW);
WRITE(mosi_pin, state);
for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
WRITE(sck_pin, HIGH);
b <<= 1;
if (miso_pin >= 0)
if (READ(miso_pin)) b |= 1;
if (miso_pin >= 0 && READ(miso_pin)) b |= 1;
for (uint8_t j = 0; j < spi_speed; j++)
WRITE(sck_pin, LOW);
}
}
return b;
}
void swSpiBegin(pin_t sck_pin, pin_t miso_pin, pin_t mosi_pin) {
void swSpiBegin(const pin_t sck_pin, const pin_t miso_pin, const pin_t mosi_pin) {
SET_OUTPUT(sck_pin);
if (VALID_PIN(miso_pin))
SET_INPUT(miso_pin);
if (VALID_PIN(miso_pin)) SET_INPUT(miso_pin);
SET_OUTPUT(mosi_pin);
}
uint8_t swSpiInit(uint8_t spiRate, pin_t sck_pin, pin_t mosi_pin) {
uint8_t spi_speed = 0;
spiRate = MIN(spiRate, 6);
if (SystemCoreClock == 120000000)
spi_speed = 44 / POW(2, 6 - spiRate);
else
spi_speed = 38 / POW(2, 6 - spiRate);
uint8_t swSpiInit(const uint8_t spiRate, const pin_t sck_pin, const pin_t mosi_pin) {
WRITE(mosi_pin, HIGH);
WRITE(sck_pin, LOW);
return spi_speed;
return (SystemCoreClock == 120000000 ? 44 : 38) / POW(2, 6 - min(spiRate, 6));
}
#endif // TARGET_LPC1768

View file

@ -23,13 +23,13 @@
#ifndef _SOFTWARE_SPI_H_
#define _SOFTWARE_SPI_H_
#include "pinmapping.h"
#include "pinmapping.h"
// --------------------------------------------------------------------------
// software SPI
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// Software SPI
// --------------------------------------------------------------------------
/**
/**
* This software SPI runs at multiple rates. The SD software provides an index
* (spiRate) of 0-6. The mapping is:
* 0 - about 5 MHz peak (6 MHz on LPC1769)
@ -40,11 +40,11 @@
* 6 - about 125 kHz peak
*/
void swSpiBegin(pin_t sck_pin, pin_t miso_pin, pin_t mosi_pin);
void swSpiBegin(const pin_t sck_pin, const pin_t miso_pin, const pin_t mosi_pin);
// Returns the spi_speed value to be passed to swSpiTransfer
uint8_t swSpiInit(uint8_t spiRate, pin_t sck_pin, pin_t mosi_pin);
// Returns the spi_speed value to be passed to swSpiTransfer
uint8_t swSpiInit(const uint8_t spiRate, const pin_t sck_pin, const pin_t mosi_pin);
uint8_t swSpiTransfer(uint8_t b, uint8_t spi_speed, pin_t sck_pin, pin_t miso_pin, pin_t mosi_pin);
uint8_t swSpiTransfer(uint8_t b, const uint8_t spi_speed, const pin_t sck_pin, const pin_t miso_pin, const pin_t mosi_pin);
#endif // _SOFTWARE_SPI_H_