From f87bbfeeac9531b29fd9c74368a6431cb63b9fc3 Mon Sep 17 00:00:00 2001 From: majikd83 Date: Mon, 17 Jul 2023 19:50:16 -0400 Subject: [PATCH] lib deps --- Marlin/src/libs/Arduino.h | 58 ++++++++ Marlin/src/libs/SPI.h | 301 ++++++++++++++++++++++++++++++++++++++ Marlin/src/libs/wiring.h | 57 ++++++++ platformio.ini | 43 +++--- 4 files changed, 438 insertions(+), 21 deletions(-) create mode 100644 Marlin/src/libs/Arduino.h create mode 100644 Marlin/src/libs/SPI.h create mode 100644 Marlin/src/libs/wiring.h diff --git a/Marlin/src/libs/Arduino.h b/Marlin/src/libs/Arduino.h new file mode 100644 index 0000000000000..674cec4c14799 --- /dev/null +++ b/Marlin/src/libs/Arduino.h @@ -0,0 +1,58 @@ +/* + Arduino.h - Main include file for the Arduino SDK + Copyright (c) 2005-2013 Arduino Team. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef Arduino_h +#define Arduino_h + +#ifndef GCC_VERSION +#define GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) +#endif +#if GCC_VERSION < 60300 + #error "GCC version 6.3 or higher is required" +#endif + +#ifdef __IN_ECLIPSE__ + #include "SrcWrapper.h" +#endif + +#include "wiring.h" + +/* sketch */ + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus +// Weak empty variant initialization function. +// May be redefined by variant files. +extern void initVariant() __attribute__((weak)); + +extern void setup(void) ; +extern void loop(void) ; + +void yield(void); +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + +// Include pins variant +#include "pins_arduino.h" + +#endif // Arduino_h diff --git a/Marlin/src/libs/SPI.h b/Marlin/src/libs/SPI.h new file mode 100644 index 0000000000000..4e40ff8a94b8f --- /dev/null +++ b/Marlin/src/libs/SPI.h @@ -0,0 +1,301 @@ +/* + * Copyright (c) 2010 by Cristian Maglie + * Copyright (c) 2014 by Paul Stoffregen (Transaction API) + * SPI Master library for arduino. + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of either the GNU General Public License version 2 + * or the GNU Lesser General Public License version 2.1, both as + * published by the Free Software Foundation. + */ + +#ifndef _SPI_H_INCLUDED +#define _SPI_H_INCLUDED + +#include "Arduino.h" +#include +extern "C" { +#include "utility/spi_com.h" +} + +// SPI_HAS_TRANSACTION means SPI has +// - beginTransaction() +// - endTransaction() +// - usingInterrupt() +// - SPISetting(clock, bitOrder, dataMode) +#define SPI_HAS_TRANSACTION 1 + +// Compatibility with sketches designed for AVR @ 16 MHz could not +// be ensured as SPI frequency depends of system clock configuration. +// user have to use appropriate divider for the SPI clock +// This function should not be used in new project. +// Use SPISettings with SPI.beginTransaction() to configure SPI parameters. +#define SPI_CLOCK_DIV2 2 +#define SPI_CLOCK_DIV4 4 +#define SPI_CLOCK_DIV8 8 +#define SPI_CLOCK_DIV16 16 +#define SPI_CLOCK_DIV32 32 +#define SPI_CLOCK_DIV64 64 +#define SPI_CLOCK_DIV128 128 + +// SPI mode parameters for SPISettings +#define SPI_MODE0 0x00 +#define SPI_MODE1 0x01 +#define SPI_MODE2 0x02 +#define SPI_MODE3 0x03 + +#define SPI_TRANSMITRECEIVE 0x0 +#define SPI_TRANSMITONLY 0x1 + +// Transfer mode +enum SPITransferMode { + SPI_CONTINUE, /* Transfer not finished: CS pin kept active */ + SPI_LAST /* Transfer ended: CS pin released */ +}; + +// Indicates the user controls himself the CS pin outside of the spi class +#define CS_PIN_CONTROLLED_BY_USER NUM_DIGITAL_PINS + +// Indicates there is no configuration selected +#define NO_CONFIG ((int16_t)(-1)) + +// Defines a default timeout delay in milliseconds for the SPI transfer +#ifndef SPI_TRANSFER_TIMEOUT + #define SPI_TRANSFER_TIMEOUT 1000 +#endif + +/* + * Defines the number of settings saved per SPI instance. Must be in range 1 to 254. + * Can be redefined in variant.h + */ +#ifndef NB_SPI_SETTINGS + #define NB_SPI_SETTINGS 4 +#endif + +class SPISettings { + public: + SPISettings(uint32_t clock, BitOrder bitOrder, uint8_t dataMode, bool noRecv = SPI_TRANSMITRECEIVE) + { + clk = clock; + bOrder = bitOrder; + noReceive = noRecv; + + if (SPI_MODE0 == dataMode) { + dMode = SPI_MODE_0; + } else if (SPI_MODE1 == dataMode) { + dMode = SPI_MODE_1; + } else if (SPI_MODE2 == dataMode) { + dMode = SPI_MODE_2; + } else if (SPI_MODE3 == dataMode) { + dMode = SPI_MODE_3; + } + } + SPISettings() + { + pinCS = -1; + clk = SPI_SPEED_CLOCK_DEFAULT; + bOrder = MSBFIRST; + dMode = SPI_MODE_0; + } + private: + int16_t pinCS; //CS pin associated to the configuration + uint32_t clk; //specifies the spi bus maximum clock speed + BitOrder bOrder; //bit order (MSBFirst or LSBFirst) + spi_mode_e dMode; //one of the data mode + //Mode Clock Polarity (CPOL) Clock Phase (CPHA) + //SPI_MODE0 0 0 + //SPI_MODE1 0 1 + //SPI_MODE2 1 0 + //SPI_MODE3 1 1 + friend class SPIClass; + bool noReceive; +}; + +class SPIClass { + public: + SPIClass(); + SPIClass(uint8_t mosi, uint8_t miso, uint8_t sclk, uint8_t ssel = (uint8_t)NC); + + // setMISO/MOSI/SCLK/SSEL have to be called before begin() + void setMISO(uint32_t miso) + { + _spi.pin_miso = digitalPinToPinName(miso); + }; + void setMOSI(uint32_t mosi) + { + _spi.pin_mosi = digitalPinToPinName(mosi); + }; + void setSCLK(uint32_t sclk) + { + _spi.pin_sclk = digitalPinToPinName(sclk); + }; + void setSSEL(uint32_t ssel) + { + _spi.pin_ssel = digitalPinToPinName(ssel); + }; + + void setMISO(PinName miso) + { + _spi.pin_miso = (miso); + }; + void setMOSI(PinName mosi) + { + _spi.pin_mosi = (mosi); + }; + void setSCLK(PinName sclk) + { + _spi.pin_sclk = (sclk); + }; + void setSSEL(PinName ssel) + { + _spi.pin_ssel = (ssel); + }; + + void begin(uint8_t _pin = CS_PIN_CONTROLLED_BY_USER); + void end(void); + + /* This function should be used to configure the SPI instance in case you + * don't use default parameters. + * You can attach another CS pin to the SPI instance and each CS pin can be + * attach with specific SPI settings. + */ + void beginTransaction(uint8_t pin, SPISettings settings); + void beginTransaction(SPISettings settings) + { + beginTransaction(CS_PIN_CONTROLLED_BY_USER, settings); + } + + void endTransaction(uint8_t pin); + void endTransaction(void) + { + endTransaction(CS_PIN_CONTROLLED_BY_USER); + } + + /* Transfer functions: must be called after initialization of the SPI + * instance with begin() or beginTransaction(). + * You can specify the CS pin to use. + */ + byte transfer(uint8_t pin, uint8_t _data, SPITransferMode _mode = SPI_LAST); + uint16_t transfer16(uint8_t pin, uint16_t _data, SPITransferMode _mode = SPI_LAST); + void transfer(uint8_t pin, void *_buf, size_t _count, SPITransferMode _mode = SPI_LAST); + void transfer(byte _pin, void *_bufout, void *_bufin, size_t _count, SPITransferMode _mode = SPI_LAST); + + // Transfer functions when user controls himself the CS pin. + byte transfer(uint8_t _data, SPITransferMode _mode = SPI_LAST) + { + return transfer(CS_PIN_CONTROLLED_BY_USER, _data, _mode); + } + + uint16_t transfer16(uint16_t _data, SPITransferMode _mode = SPI_LAST) + { + return transfer16(CS_PIN_CONTROLLED_BY_USER, _data, _mode); + } + + void transfer(void *_buf, size_t _count, SPITransferMode _mode = SPI_LAST) + { + transfer(CS_PIN_CONTROLLED_BY_USER, _buf, _count, _mode); + } + + void transfer(void *_bufout, void *_bufin, size_t _count, SPITransferMode _mode = SPI_LAST) + { + transfer(CS_PIN_CONTROLLED_BY_USER, _bufout, _bufin, _count, _mode); + } + + /* These methods are deprecated and kept for compatibility. + * Use SPISettings with SPI.beginTransaction() to configure SPI parameters. + */ + void setBitOrder(uint8_t _pin, BitOrder); + void setBitOrder(BitOrder _order) + { + setBitOrder(CS_PIN_CONTROLLED_BY_USER, _order); + } + + void setDataMode(uint8_t _pin, uint8_t); + void setDataMode(uint8_t _mode) + { + setDataMode(CS_PIN_CONTROLLED_BY_USER, _mode); + } + + void setClockDivider(uint8_t _pin, uint8_t); + void setClockDivider(uint8_t _div) + { + setClockDivider(CS_PIN_CONTROLLED_BY_USER, _div); + } + + // Not implemented functions. Kept for backward compatibility. + void usingInterrupt(uint8_t interruptNumber); + void attachInterrupt(void); + void detachInterrupt(void); + + private: + /* Contains various spiSettings for the same spi instance. Each spi spiSettings + is associated to a CS pin. */ + SPISettings spiSettings[NB_SPI_SETTINGS]; + + // Use to know which configuration is selected. + int16_t _CSPinConfig; + + // spi instance + spi_t _spi; + + + typedef enum { + GET_IDX = 0, + ADD_NEW_PIN = 1 + } pin_option_t; + + uint8_t pinIdx(uint8_t _pin, pin_option_t option) + { + uint8_t i; + + if ((_pin > NUM_DIGITAL_PINS) && (!digitalPinIsValid(_pin))) { + return NB_SPI_SETTINGS; + } + + for (i = 0; i < NB_SPI_SETTINGS; i++) { + if (_pin == spiSettings[i].pinCS) { + return i; + } + } + + if (option == ADD_NEW_PIN) { + for (i = 0; i < NB_SPI_SETTINGS; i++) { + if (spiSettings[i].pinCS == -1) { + spiSettings[i].pinCS = _pin; + return i; + } + } + } + return i; + } + + void RemovePin(uint8_t _pin) + { + if ((_pin > NUM_DIGITAL_PINS) && (!digitalPinIsValid(_pin))) { + return; + } + + for (uint8_t i = 0; i < NB_SPI_SETTINGS; i++) { + if (spiSettings[i].pinCS == _pin) { + spiSettings[i].pinCS = -1; + spiSettings[i].clk = SPI_SPEED_CLOCK_DEFAULT; + spiSettings[i].bOrder = MSBFIRST; + spiSettings[i].dMode = SPI_MODE_0; + } + } + } + + void RemoveAllPin(void) + { + for (uint8_t i = 0; i < NB_SPI_SETTINGS; i++) { + spiSettings[i].pinCS = -1; + spiSettings[i].clk = SPI_SPEED_CLOCK_DEFAULT; + spiSettings[i].bOrder = MSBFIRST; + spiSettings[i].dMode = SPI_MODE_0; + } + } +}; + +extern SPIClass SPI; + +#endif diff --git a/Marlin/src/libs/wiring.h b/Marlin/src/libs/wiring.h new file mode 100644 index 0000000000000..1c7808882730a --- /dev/null +++ b/Marlin/src/libs/wiring.h @@ -0,0 +1,57 @@ +/* + Copyright (c) 2011 Arduino. All right reserved. + Copyright (c) 2013 by Paul Stoffregen (delayMicroseconds) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _WIRING_H_ +#define _WIRING_H_ + +#include +#include +#include +#include +#include + +#include "avr/dtostrf.h" +#include "binary.h" +#include "itoa.h" + +#include "wiring_analog.h" +#include "wiring_constants.h" +#include "wiring_digital.h" +#include "wiring_pulse.h" +#include "wiring_shift.h" +#include "wiring_time.h" +#include "WInterrupts.h" + +#include + +#ifdef __cplusplus + #include "HardwareTimer.h" + #include "Tone.h" + #include "WCharacter.h" + #include "WSerial.h" + #include "WMath.h" + #include "WString.h" +#endif // __cplusplus + + +#define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L ) +#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCoreClock / 1000L) ) +#define microsecondsToClockCycles(a) ( (a) * (SystemCoreClock / 1000000L) ) + +#endif /* _WIRING_H_ */ diff --git a/platformio.ini b/platformio.ini index 54fa7209f6d44..4e88005cc9038 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,30 +9,30 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -src_dir = E:\repositories\Marlin-1\Marlin\src -boards_dir = E:\repositories\Marlin-1\buildroot\share\PlatformIO\boards +src_dir = Marlin\src +boards_dir = buildroot\share\PlatformIO\boards default_envs = STM32F446ZE_btt_USB -include_dir = E:\repositories\Marlin-1 +include_dir = Marlin extra_configs = Marlin/config.ini - ini/avr.ini - ini/due.ini - ini/esp32.ini + ; ini/avr.ini + ; ini/due.ini + ; ini/esp32.ini ini/features.ini - ini/lpc176x.ini - ini/native.ini - ini/samd21.ini - ini/samd51.ini + ; ini/lpc176x.ini + ; ini/native.ini + ; ini/samd21.ini + ; ini/samd51.ini ini/stm32-common.ini - ini/stm32f0.ini - ini/stm32f1-maple.ini - ini/stm32f1.ini + ; ini/stm32f0.ini + ; ini/stm32f1-maple.ini + ; ini/stm32f1.ini ini/stm32f4.ini - ini/stm32f7.ini - ini/stm32h7.ini - ini/stm32g0.ini - ini/teensy.ini - ini/renamed.ini + ; ini/stm32f7.ini + ; ini/stm32h7.ini + ; ini/stm32g0.ini + ; ini/teensy.ini + ; ini/renamed.ini [common] build_flags = @@ -45,9 +45,9 @@ extra_scripts = pre:buildroot/share/PlatformIO/scripts/preflight-checks.py post:buildroot/share/PlatformIO/scripts/common-dependencies-post.py lib_deps = - SPI - SoftwareSerial - Wire + ; SPI + ; SoftwareSerial + ; Wire default_src_filter = + - - - - - - - @@ -74,6 +74,7 @@ default_src_filter = - - - + - - - - -