From 60af705e6d68bc972fbdcd232e78a775efe53128 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 19 Oct 2017 00:42:16 -0500 Subject: [PATCH] Relocate SPI.h to the HAL folder --- Marlin/src/HAL/HAL.h | 2 +- .../src/HAL/HAL_STM32F1/HAL_spi_Stm32f1.cpp | 2 +- Marlin/src/HAL/SPI.h | 78 +++++++++++++++++++ Marlin/src/inc/MarlinConfig.h | 2 +- Marlin/src/inc/SPI.h | 52 ------------- 5 files changed, 81 insertions(+), 55 deletions(-) create mode 100644 Marlin/src/HAL/SPI.h delete mode 100644 Marlin/src/inc/SPI.h diff --git a/Marlin/src/HAL/HAL.h b/Marlin/src/HAL/HAL.h index 60e0df6f2d..bc7d285e81 100644 --- a/Marlin/src/HAL/HAL.h +++ b/Marlin/src/HAL/HAL.h @@ -29,7 +29,7 @@ #ifndef _HAL_H #define _HAL_H -#include "../inc/SPI.h" +#include "SPI.h" #ifdef __AVR__ #include "HAL_AVR/HAL_AVR.h" diff --git a/Marlin/src/HAL/HAL_STM32F1/HAL_spi_Stm32f1.cpp b/Marlin/src/HAL/HAL_STM32F1/HAL_spi_Stm32f1.cpp index 3b4109f0c3..fc1bfb7550 100644 --- a/Marlin/src/HAL/HAL_STM32F1/HAL_spi_Stm32f1.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/HAL_spi_Stm32f1.cpp @@ -37,7 +37,7 @@ // -------------------------------------------------------------------------- #include "../HAL.h" -#include "SPI.h" +#include "../SPI.h" #include "pins_arduino.h" #include "spi_pins.h" #include "../../core/macros.h" diff --git a/Marlin/src/HAL/SPI.h b/Marlin/src/HAL/SPI.h new file mode 100644 index 0000000000..78e867a1fa --- /dev/null +++ b/Marlin/src/HAL/SPI.h @@ -0,0 +1,78 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/** + * HAL/SPI.h + * Core Marlin definitions for SPI, implemented in the HALs + */ + +#ifndef _SPI_H_ +#define _SPI_H_ + +//#include "../inc/MarlinConfig.h" + +#include + +#ifndef SPI_FULL_SPEED + +/** + * SPI speed where 0 <= index <= 6 + * + * Approximate rates : + * + * 0 : 8 - 10 MHz + * 1 : 4 - 5 MHz + * 2 : 2 - 2.5 MHz + * 3 : 1 - 1.25 MHz + * 4 : 500 - 625 kHz + * 5 : 250 - 312 kHz + * 6 : 125 - 156 kHz + * + * On AVR, actual speed is F_CPU/2^(1 + index). + * On other platforms, speed should be in range given above where possible. + */ + +#define SPI_FULL_SPEED 0 // Set SCK to max rate +#define SPI_HALF_SPEED 1 // Set SCK rate to half of max rate +#define SPI_QUARTER_SPEED 2 // Set SCK rate to quarter of max rate +#define SPI_EIGHTH_SPEED 3 // Set SCK rate to 1/8 of max rate +#define SPI_SIXTEENTH_SPEED 4 // Set SCK rate to 1/16 of max rate +#define SPI_SPEED_5 5 // Set SCK rate to 1/32 of max rate +#define SPI_SPEED_6 6 // Set SCK rate to 1/64 of max rate + +// Standard SPI functions +/** Initialise SPI bus */ +void spiBegin(void); +/** Configure SPI for specified SPI speed */ +void spiInit(uint8_t spiRate); +/** Write single byte to SPI */ +void spiSend(uint8_t b); +/** Read single byte from SPI */ +uint8_t spiRec(void); +/** Read from SPI into buffer */ +void spiRead(uint8_t* buf, uint16_t nbyte); +/** Write token and then write from 512 byte buffer to SPI (for SD card) */ +void spiSendBlock(uint8_t token, const uint8_t* buf); + +#endif // SPI_FULL_SPEED + +#endif // _SPI_H_ diff --git a/Marlin/src/inc/MarlinConfig.h b/Marlin/src/inc/MarlinConfig.h index 25d56cf006..ea542fcda3 100644 --- a/Marlin/src/inc/MarlinConfig.h +++ b/Marlin/src/inc/MarlinConfig.h @@ -26,7 +26,7 @@ #include "../core/boards.h" #include "../core/macros.h" #include "Version.h" -#include "SPI.h" +#include "../HAL/SPI.h" #include "../../Configuration.h" #include "Conditionals_LCD.h" #include "../../Configuration_adv.h" diff --git a/Marlin/src/inc/SPI.h b/Marlin/src/inc/SPI.h deleted file mode 100644 index 3fa0cecceb..0000000000 --- a/Marlin/src/inc/SPI.h +++ /dev/null @@ -1,52 +0,0 @@ -#include - - -#ifndef SPI_FULL_SPEED - -/** - * SPI speed where 0 <= index <= 6 - * - * Approximate rates : - * - * 0 : 8 - 10 MHz - * 1 : 4 - 5 MHz - * 2 : 2 - 2.5 MHz - * 3 : 1 - 1.25 MHz - * 4 : 500 - 625 kHz - * 5 : 250 - 312 kHz - * 6 : 125 - 156 kHz - * - * On AVR, actual speed is F_CPU/2^(1 + index). - * On other platforms, speed should be in range given above where possible. - */ - -/** Set SCK to max rate */ -#define SPI_FULL_SPEED 0 -/** Set SCK rate to half max rate. */ -#define SPI_HALF_SPEED 1 -/** Set SCK rate to quarter max rate. */ -#define SPI_QUARTER_SPEED 2 -/** Set SCK rate to 1/8 max rate. */ -#define SPI_EIGHTH_SPEED 3 -/** Set SCK rate to 1/16 of max rate. */ -#define SPI_SIXTEENTH_SPEED 4 -/** Set SCK rate to 1/32 of max rate. */ -#define SPI_SPEED_5 5 -/** Set SCK rate to 1/64 of max rate. */ -#define SPI_SPEED_6 6 - -// Standard SPI functions -/** Initialise SPI bus */ -void spiBegin(void); -/** Configure SPI for specified SPI speed */ -void spiInit(uint8_t spiRate); -/** Write single byte to SPI */ -void spiSend(uint8_t b); -/** Read single byte from SPI */ -uint8_t spiRec(void); -/** Read from SPI into buffer */ -void spiRead(uint8_t* buf, uint16_t nbyte); -/** Write token and then write from 512 byte buffer to SPI (for SD card) */ -void spiSendBlock(uint8_t token, const uint8_t* buf); - -#endif