Commit e9637253 authored by MagoKimbra's avatar MagoKimbra

Update 4.2.5

parent 82a14412
#ifndef CONFIGURATION_MECHANISM
#define CONFIGURATION_MECHANISM
#define KNOWN_MECH 1
#define KNOWN_MECH
/*
* This configuration file contains mechanism settings for cartesian printer.
*
......
#ifndef CONFIGURATION_MECHANISM
#define CONFIGURATION_MECHANISM
#define KNOWN_MECH 1
#define KNOWN_MECH
/*
* This configuration file contains mechanism settings for cartesian printer.
*
......
#ifndef CONFIGURATION_MECHANISM
#define CONFIGURATION_MECHANISM
#define KNOWN_MECH 1
#define KNOWN_MECH
/*
* This configuration file contains mechanism settings for cartesian printer.
*
......
#ifndef CONFIGURATION_MECHANISM
#define CONFIGURATION_MECHANISM
#define KNOWN_MECH 1
#define KNOWN_MECH
/*
* This configuration file contains mechanism settings for cartesian printer.
*
......
......@@ -626,6 +626,9 @@
#if ENABLED(RA_CONTROL_PANEL)
#define SDSS 53
#define SCK_PIN 52
#define MISO_PIN 50
#define MOSI_PIN 51
#define SD_DETECT_PIN 28
#define BTN_EN1 14
......@@ -785,6 +788,9 @@
#define SDPOWER 48
#define SDSS 53
#define SCK_PIN 52
#define MISO_PIN 50
#define MOSI_PIN 51
#define LED_PIN 13
#define ORIG_PS_ON_PIN -1
#define KILL_PIN -1
......@@ -881,6 +887,9 @@
#define SDPOWER -1
#define SDSS 53
#define SCK_PIN 52
#define MISO_PIN 50
#define MOSI_PIN 51
#define LED_PIN 13
#define ORIG_FAN_PIN 9
......@@ -1019,15 +1028,7 @@
#endif // ULTRA_LCD
// SPI for Max6675 Thermocouple
#if DISABLED(SDSUPPORT)
// these pins are defined in the SD library if building with SD support
#define SCK_PIN 52
#define MISO_PIN 50
#define MOSI_PIN 51
#define MAX6675_SS 66 // Do not use pin 53 if there is even the remote possibility of using Display/SD card
#else
#define MAX6675_SS 66 // Do not use pin 49 as this is tied to the switch inside the SD card socket to detect if there is an SD card present
#endif
#endif // RAMPS_13_HFB
/****************************************************************************************/
......@@ -1089,6 +1090,9 @@
#define SDPOWER -1
#define SDSS 53
#define SCK_PIN 52
#define MISO_PIN 50
#define MOSI_PIN 51
#define LED_PIN 13
#define ORIG_FAN_PIN 4
......@@ -1221,15 +1225,7 @@
#endif // ULTRA_LCD
// SPI for Max6675 Thermocouple
#if DISABLED(SDSUPPORT)
// these pins are defined in the SD library if building with SD support
#define SCK_PIN 52
#define MISO_PIN 50
#define MOSI_PIN 51
#define MAX6675_SS 66 // Do not use pin 53 if there is even the remote possibility of using Display/SD card
#else
#define MAX6675_SS 66 // Do not use pin 49 as this is tied to the switch inside the SD card socket to detect if there is an SD card present
#endif
#endif // RAMPS_13_HHB
/****************************************************************************************/
......@@ -1291,6 +1287,9 @@
#define SDPOWER -1
#define SDSS 53
#define SCK_PIN 52
#define MISO_PIN 50
#define MOSI_PIN 51
#define LED_PIN 13
#define ORIG_FAN_PIN 9
......@@ -1423,15 +1422,7 @@
#endif // ULTRA_LCD
// SPI for Max6675 Thermocouple
#if DISABLED(SDSUPPORT)
// these pins are defined in the SD library if building with SD support
#define SCK_PIN 52
#define MISO_PIN 50
#define MOSI_PIN 51
#define MAX6675_SS 66 // Do not use pin 53 if there is even the remote possibility of using Display/SD card
#else
#define MAX6675_SS 66 // Do not use pin 49 as this is tied to the switch inside the SD card socket to detect if there is an SD card present
#endif
#endif // RAMPS_13_HFF
/****************************************************************************************/
......@@ -1493,6 +1484,9 @@
#define SDPOWER -1
#define SDSS 53
#define SCK_PIN 52
#define MISO_PIN 50
#define MOSI_PIN 51
#define LED_PIN 13
#define ORIG_FAN_PIN 8
......@@ -1625,15 +1619,7 @@
#endif // ULTRA_LCD
// SPI for Max6675 Thermocouple
#if DISABLED(SDSUPPORT)
// these pins are defined in the SD library if building with SD support
#define SCK_PIN 52
#define MISO_PIN 50
#define MOSI_PIN 51
#define MAX6675_SS 66 // Do not use pin 53 if there is even the remote possibility of using Display/SD card
#else
#define MAX6675_SS 66 // Do not use pin 49 as this is tied to the switch inside the SD card socket to detect if there is an SD card present
#endif
#endif // RAMPS_13_HHF
/****************************************************************************************/
......@@ -1695,6 +1681,9 @@
#define SDPOWER -1
#define SDSS 53
#define SCK_PIN 52
#define MISO_PIN 50
#define MOSI_PIN 51
#define LED_PIN 13
#define ORIG_FAN_PIN 8
......@@ -1827,15 +1816,7 @@
#endif // ULTRA_LCD
// SPI for Max6675 Thermocouple
#if DISABLED(SDSUPPORT)
// these pins are defined in the SD library if building with SD support
#define SCK_PIN 52
#define MISO_PIN 50
#define MOSI_PIN 51
#define MAX6675_SS 66 // Do not use pin 53 if there is even the remote possibility of using Display/SD card
#else
#define MAX6675_SS 66 // Do not use pin 49 as this is tied to the switch inside the SD card socket to detect if there is an SD card present
#endif
#endif // RAMPS_13_HHH
/****************************************************************************************/
......@@ -1913,6 +1894,9 @@
#define SDPOWER -1
#define SDSS 53
#define SCK_PIN 52
#define MISO_PIN 50
#define MOSI_PIN 51
#define LED_PIN 13
#define ORIG_FAN_PIN 8
#define ORIG_PS_ON_PIN 4
......@@ -2083,6 +2067,9 @@
#define SDPOWER -1
#define SDSS 53
#define SCK_PIN 52
#define MISO_PIN 50
#define MOSI_PIN 51
#define LED_PIN 13
#define ORIG_FAN_PIN 9
......@@ -2221,15 +2208,7 @@
#endif // ULTRA_LCD
// SPI for Max6675 Thermocouple
#if DISABLED(SDSUPPORT)
// these pins are defined in the SD library if building with SD support
#define SCK_PIN 52
#define MISO_PIN 50
#define MOSI_PIN 51
#define MAX6675_SS 66 // Do not use pin 53 if there is even the remote possibility of using Display/SD card
#else
#define MAX6675_SS 66 // Do not use pin 49 as this is tied to the switch inside the SD card socket to detect if there is an SD card present
#endif
#endif // MKS_BASE
/****************************************************************************************/
......
......@@ -11,9 +11,7 @@
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#define ENABLED defined
#define DISABLED !defined
#include "module/macros.h"
#include "Boards.h"
#include "module/mechanics.h"
......@@ -36,14 +34,14 @@
#include "Configuration_Feature.h"
#include "Configuration_Overall.h"
#include "module/conditionals.h"
#include "module/sanitycheck.h"
#include "module/HAL/HAL.h"
#include "module/communication/communication.h"
#include "Configuration_Store.h"
#include "module/language/language.h"
#include "module/conditionals.h"
#include "module/sanitycheck.h"
#include "module/MK_Main.h"
#include "module/motion/stepper.h"
#include "module/motion/stepper_indirection.h"
......@@ -59,7 +57,7 @@
#if ENABLED(AUTO_BED_LEVELING_GRID)
#include "module/motion/qr_solve.h"
#endif
#endif // AUTO_BED_LEVELING_FEATURE
#endif
#if MB(ALLIGATOR)
#include "module/alligator/external_dac.h"
......
......@@ -25,7 +25,6 @@
#ifndef HAL_H
#define HAL_H
#include <avr/io.h>
#include "fastio.h"
// Arduino < 1.0.0 does not define this, so we need to do it ourselves
......@@ -33,42 +32,6 @@
#define analogInputToDigitalPin(p) ((p) + 0xA0)
#endif
/**
* Defines & Macros
*/
// Compiler warning on unused varable.
#define UNUSED(x) (void) (x)
// Macros for bit
#define BIT(b) (1<<(b))
#define TEST(n, b) (((n)&BIT(b))!=0)
#define SET_BIT(n, b, value) (n) ^= ((-value)^(n)) & (BIT(b))
// Macros for maths shortcuts
#ifndef M_PI
#define M_PI 3.1415926536
#endif
#define RADIANS(d) ((d)*M_PI/180.0)
#define DEGREES(r) ((r)*180.0/M_PI)
#define SIN_60 0.8660254037844386
#define COS_60 0.5
// Macros to support option testing
#define PIN_EXISTS(PN) (defined(PN##_PIN) && PN##_PIN >= 0)
#define HAS(FE) (HAS_##FE)
#define HASNT(FE) (!(HAS_##FE))
// Macros to contrain values
#define NOLESS(v,n) do{ if (v < n) v = n; }while(0)
#define NOMORE(v,n) do{ if (v > n) v = n; }while(0)
#define COUNT(a) (sizeof(a)/sizeof(*a))
#define FORCE_INLINE __attribute__((always_inline)) inline
#ifndef CRITICAL_SECTION_START
#define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
#define CRITICAL_SECTION_END SREG = _sreg;
#endif
//#define EXTERNALSERIAL // Force using arduino serial
#ifndef EXTERNALSERIAL
#include "HardwareSerial.h"
......@@ -119,6 +82,83 @@
static void showStartReason();
static int getFreeRam();
static void resetHardware();
// SPI related functions
static void spiBegin() {
#if SDSS >= 0
SET_INPUT(MISO_PIN);
SET_OUTPUT(MOSI_PIN);
SET_OUTPUT(SCK_PIN);
// SS must be in output mode even it is not chip select
SET_OUTPUT(SDSS);
// set SS high - may be chip select for another SPI device
WRITE(SDSS, HIGH);
#endif
}
static inline void spiInit(uint8_t spiRate) {
uint8_t r = 0;
for (uint8_t b = 2; spiRate > b && r < 6; b <<= 1, r++);
SET_OUTPUT(SDSS);
WRITE(SDSS, HIGH);
SET_OUTPUT(SCK_PIN);
SET_OUTPUT(MOSI_PIN);
SET_INPUT(MISO_PIN);
#ifdef PRR
PRR &= ~(1<<PRSPI);
#elif defined PRR0
PRR0 &= ~(1<<PRSPI);
#endif
// See avr processor documentation
SPCR = (1 << SPE) | (1 << MSTR) | (r >> 1);
SPSR = (r & 1 || r == 6 ? 0 : 1) << SPI2X;
}
static inline uint8_t spiReceive(uint8_t send = 0xFF) {
SPDR = send;
while (!(SPSR & (1 << SPIF))) {}
return SPDR;
}
static inline void spiReadBlock(uint8_t* buf, size_t nbyte) {
if (nbyte-- == 0) return;
SPDR = 0XFF;
for (size_t i = 0; i < nbyte; i++) {
while (!(SPSR & (1 << SPIF))) {}
buf[i] = SPDR;
SPDR = 0XFF;
}
while (!(SPSR & (1 << SPIF))) {}
buf[nbyte] = SPDR;
}
static inline void spiSend(uint8_t b) {
SPDR = b;
while (!(SPSR & (1 << SPIF))) {}
}
static inline void spiSend(const uint8_t* buf, size_t n) {
if (n == 0) return;
SPDR = buf[0];
if (n > 1) {
uint8_t b = buf[1];
size_t i = 2;
while (1) {
while (!(SPSR & (1 << SPIF))) {}
SPDR = b;
if (i == n) break;
b = buf[i++];
}
}
while (!(SPSR & (1 << SPIF))) {}
}
static inline __attribute__((always_inline))
void spiSendBlock(uint8_t token, const uint8_t* buf) {
SPDR = token;
for (uint16_t i = 0; i < 512; i += 2) {
while (!(SPSR & (1 << SPIF))) {}
SPDR = buf[i];
while (!(SPSR & (1 << SPIF))) {}
SPDR = buf[i + 1];
}
while (!(SPSR & (1 << SPIF))) {}
}
protected:
private:
};
......
......@@ -937,10 +937,10 @@
#define TXD DIO1
// SPI
#define SCK DIO52
#define SCK 52
#define MISO DIO50
#define MOSI DIO51
#define SS DIO53
#define SS 53
// TWI (I2C)
#define SCL DIO21
......
#ifndef MACROS_H
#define MACROS_H
// Compiler warning on unused varable.
#define UNUSED(x) (void) (x)
// Macros for bit masks
#define BIT(b) (1<<(b))
#define TEST(n,b) (((n)&BIT(b))!=0)
#define SET_BIT(n,b,value) (n) ^= ((-value)^(n)) & (BIT(b))
// Macros for maths shortcuts
#define M_PI 3.1415926536
#define RADIANS(d) ((d)*M_PI/180.0)
#define DEGREES(r) ((r)*180.0/M_PI)
#define SIN_60 0.8660254037844386
#define COS_60 0.5
// Macros to support option testing
#define ENABLED defined
#define DISABLED !defined
#define PIN_EXISTS(PN) (defined(PN##_PIN) && PN##_PIN >= 0)
#define HAS(FE) (HAS_##FE)
#define HASNT(FE) (!(HAS_##FE))
// Macros to contrain values
#define NOLESS(v,n) do{ if (v < n) v = n; }while(0)
#define NOMORE(v,n) do{ if (v > n) v = n; }while(0)
#define COUNT(a) (sizeof(a)/sizeof(*a))
// Function macro
#define FORCE_INLINE __attribute__((always_inline)) inline
#if DISABLED(CRITICAL_SECTION_START)
#define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
#define CRITICAL_SECTION_END SREG = _sreg;
#endif
#endif //__MACROS_H
This diff is collapsed.
......@@ -29,8 +29,8 @@
* \brief Sd2Card class for V2 SD/SDHC cards
*/
#include "SdFatConfig.h"
#include "Sd2PinMap.h"
#include "SdInfo.h"
//------------------------------------------------------------------------------
// SPI speed is F_CPU/2^(1 + index), 0 <= index <= 6
/** Set SCK to max rate of F_CPU/2. See Sd2Card::setSckRate(). */
......@@ -129,7 +129,7 @@ uint8_t const SD_CARD_TYPE_SDHC = 3;
#if DISABLED(SOFTWARE_SPI)
// hardware pin defs
/** The default chip select pin for the SD card is SS. */
uint8_t const SD_CHIP_SELECT_PIN = SS_PIN;
uint8_t const SD_CHIP_SELECT_PIN = SDSS;
// The following three pins must not be redefined for hardware SPI.
/** SPI Master Out Slave In pin */
uint8_t const SPI_MOSI_PIN = MOSI_PIN;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment