From 28d471197d58535be9aea0ecbdd4bd0fe289f2a3 Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Sat, 25 Jun 2022 17:35:07 +0800 Subject: [PATCH] Add default pins for each mcu Add pins for SPI screens Add platformio.ini generation --- build/index.html | 2 +- images/PlatformIO_logo.svg | 1 + src/components/App/version.js | 2 +- src/configuration.json | 61 +++++ src/tabs/generate/footer.js | 2 +- src/tabs/generate/header.js | 4 +- src/tabs/generate/index.js | 409 ++++++++++++++++++++++++++++++++- src/tabs/generate/piofooter.js | 23 ++ src/tabs/generate/pioheader.js | 40 ++++ 9 files changed, 538 insertions(+), 6 deletions(-) create mode 100644 images/PlatformIO_logo.svg create mode 100644 src/tabs/generate/piofooter.js create mode 100644 src/tabs/generate/pioheader.js diff --git a/build/index.html b/build/index.html index 92aad49..10babdb 100644 --- a/build/index.html +++ b/build/index.html @@ -1 +1 @@ -ESP3D-Configurator \ No newline at end of file +ESP3D-Configurator \ No newline at end of file diff --git a/images/PlatformIO_logo.svg b/images/PlatformIO_logo.svg new file mode 100644 index 0000000..3dfaa71 --- /dev/null +++ b/images/PlatformIO_logo.svg @@ -0,0 +1 @@ + diff --git a/src/components/App/version.js b/src/components/App/version.js index 1ebc1c9..1314521 100644 --- a/src/components/App/version.js +++ b/src/components/App/version.js @@ -16,4 +16,4 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ import { h } from "preact" -export const Version = "1.0.0-a4" +export const Version = "1.0.0-a5" diff --git a/src/configuration.json b/src/configuration.json index 5a34d51..ffd9c9d 100644 --- a/src/configuration.json +++ b/src/configuration.json @@ -50,6 +50,7 @@ { "label": "1MB", "value": "1", + "depend":{"id":"targetmcu","value":["esp8266"]}, "help":"No OTA/ Web update possible" }, { @@ -947,6 +948,66 @@ "depend":{"id":"displaytype","value":["TFT_SPI_ST7789_135X240","TFT_SPI_ST7789_240X240"]}, "setting":true, "usedescforoptions":true + }, + { + "id":"tftDCpin", + "define":"DISPLAY_DC_PIN", + "label":"TFT DC pin", + "description":"The dc pin used for the display", + "type":"select", + "ispin":true, + "value":"-1", + "depend":{"id":"displaytype","value":["TFT_SPI_ST7789_135X240","TFT_SPI_ST7789_240X240"]}, + "setting":true, + "usedescforoptions":true + }, + { + "id":"tftRSTpin", + "define":"DISPLAY_RST_PIN", + "label":"TFT RST pin", + "description":"The pin used to reset display", + "type":"select", + "ispin":true, + "value":"-1", + "depend":{"id":"displaytype","value":["TFT_SPI_ST7789_135X240","TFT_SPI_ST7789_240X240"]}, + "setting":true, + "usedescforoptions":true + }, + { + "id":"tftCSpin", + "define":"DISPLAY_CS_PIN", + "label":"TFT CS pin", + "description":"The CS pin used by display", + "type":"select", + "ispin":true, + "value":"-1", + "depend":{"id":"displaytype","value":["TFT_SPI_ST7789_135X240","TFT_SPI_ST7789_240X240"]}, + "setting":true, + "usedescforoptions":true + }, + { + "id":"tftMOSIpin", + "define":"DISPLAY_MOSI_PIN", + "label":"TFT MOSI pin", + "description":"The MOSI pin used by display", + "type":"select", + "ispin":true, + "value":"-1", + "depend":{"id":"displaytype","value":["TFT_SPI_ST7789_135X240","TFT_SPI_ST7789_240X240"]}, + "setting":true, + "usedescforoptions":true + }, + { + "id":"tftSCKpin", + "define":"DISPLAY_SCK_PIN", + "label":"TFT SCK pin", + "description":"The SCK pin used by display", + "type":"select", + "ispin":true, + "value":"-1", + "depend":{"id":"displaytype","value":["TFT_SPI_ST7789_135X240","TFT_SPI_ST7789_240X240"]}, + "setting":true, + "usedescforoptions":true } ] }, diff --git a/src/tabs/generate/footer.js b/src/tabs/generate/footer.js index 13eb9a8..552269e 100644 --- a/src/tabs/generate/footer.js +++ b/src/tabs/generate/footer.js @@ -1,5 +1,5 @@ /* - index.js - ESP3D WebUI navigation tab file + footer.js - ESP3D-configurator footer for configuration.h file Copyright (c) 2020 Luc Lebosse. All rights reserved. diff --git a/src/tabs/generate/header.js b/src/tabs/generate/header.js index 9a7d2f4..52c0303 100644 --- a/src/tabs/generate/header.js +++ b/src/tabs/generate/header.js @@ -1,5 +1,5 @@ /* - index.js - ESP3D WebUI navigation tab file + header.js - ESP3D-configurator header for configuration.h file Copyright (c) 2020 Luc Lebosse. All rights reserved. @@ -19,7 +19,7 @@ */ import { h } from "preact" const header = - '\n\ + '\ /*\n\ configuration.h - ESP3D configuration file\n\ \n\ diff --git a/src/tabs/generate/index.js b/src/tabs/generate/index.js index 01daf69..a9516b0 100644 --- a/src/tabs/generate/index.js +++ b/src/tabs/generate/index.js @@ -28,9 +28,37 @@ import { useDatasContextFn, } from "../../contexts" import header from "./header" +import pioheader from "./pioheader" import footer from "./footer" +import piofooter from "./piofooter" import { Version } from "../../components/App/version" import { useEffect, useState } from "preact/hooks" +const pioIcon = ( + + + + + + +) const configurationFile = (data) => { return ( @@ -41,6 +69,341 @@ const configurationFile = (data) => { ) } +const pioFile = () => { + return ( + `;This file was generated by ESP3D-Configurator V${Version} \n` + + pioheader + + convertPioToText() + + piofooter + ) +} + +const sections = { + esp32: { + common: + "platform = espressif32@4.4.0\n" + + "board = esp32dev\n" + + "framework = arduino\n" + + "monitor_speed = 115200\n" + + "monitor_flags = --echo\n" + + "monitor_filters = send_on_enter, colorize, esp32_exception_decoder\n" + + "; set frequency to 240MHz\n" + + ";board_build.f_cpu = 240000000L\n" + + "; set frequency to 80MHz\n" + + ";board_build.f_flash = 80000000L\n" + + ";board_build.flash_mode = qio\n" + + "upload_speed = 460800\n" + + "extra_scripts = pre:platformIO/extra_script.py\n", + build_flags: " -DCORE_DEBUG_LEVEL=0\n", + defaultMosi: 23, + defaultSck: 18, + defaultCs: 5, + defaultMiso: 19, + defaultSda: 21, + defaultScl: 22, + }, + esp32s2: { + common: + "platform = espressif32@4.4.0\n" + + "board = esp32-s2-saola-1\n" + + "framework = arduino\n" + + "board_build.mcu = esp32s2\n" + + "board_build.variant = esp32s2\n" + + "monitor_speed = 115200\n" + + "monitor_flags = --echo\n" + + "monitor_filters = send_on_enter, colorize, esp32_exception_decoder\n" + + "set frequency to 240MHz\n" + + "board_build.f_cpu = 240000000L\n" + + "set frequency to 80MHz\n" + + "board_build.f_flash = 80000000L\n" + + "board_build.flash_mode = qio\n" + + "upload_speed = 460800\n" + + "extra_scripts = pre:platformIO/extra_script.py\n", + build_flags: + " -DCORE_DEBUG_LEVEL=0\n-DARDUINO_USB_CDC_ON_BOOT=0\n-DARDUINO_USB_MSC_ON_BOOT=0\n-DARDUINO_USB_DFU_ON_BOOT=0\n-DCONFIG_IDF_TARGET_ESP32S2=1\n", + lib_ignore: "TFT_eSPI\n", + defaultMosi: 35, + defaultSck: 36, + defaultCs: 34, + defaultMiso: 37, + defaultSda: 8, + defaultScl: 9, + }, + esp32s3: { + common: + "platform = espressif32@4.4.0\n" + + "board = esp32-s3-devkitc-1\n" + + "framework = arduino\n" + + "board_build.mcu = esp32s3\n" + + "board_build.variant = esp32s3\n" + + "monitor_speed = 115200\n" + + "monitor_flags = --echo\n" + + "monitor_filters = send_on_enter, colorize, esp32_exception_decoder\n" + + "set frequency to 240MHz\n" + + "board_build.f_cpu = 240000000L\n" + + "set frequency to 80MHz\n" + + "board_build.f_flash = 80000000L\n" + + "board_build.flash_mode = qio\n" + + "upload_speed = 460800\n" + + "extra_scripts = pre:platformIO/extra_script.py\n", + build_flags: + " -DCORE_DEBUG_LEVEL=0\n-DARDUINO_USB_CDC_ON_BOOT=0\n-DARDUINO_USB_MSC_ON_BOOT=0\n-DARDUINO_USB_DFU_ON_BOOT=0\n-DCONFIG_IDF_TARGET_ESP32S3=1\n", + lib_ignore: "TFT_eSPI\n", + defaultMosi: 11, + defaultSck: 12, + defaultCs: 10, + defaultMiso: 13, + defaultSda: 8, + defaultScl: 9, + }, + esp32c3: { + common: + "platform = espressif32@4.4.0\n" + + "board = esp32-c3-devkitm-1\n" + + "framework = arduino\n" + + "board_build.mcu = esp32c3\n" + + "board_build.variant = esp32c3\n" + + "monitor_speed = 115200\n" + + "monitor_flags = --echo\n" + + "monitor_filters = send_on_enter, colorize, esp32_exception_decoder\n" + + "set frequency to 240MHz\n" + + "board_build.f_cpu = 240000000L\n" + + "set frequency to 80MHz\n" + + "board_build.f_flash = 80000000L\n" + + "board_build.flash_mode = qio\n" + + "upload_speed = 460800\n" + + "extra_scripts = pre:platformIO/extra_script.py\n", + build_flags: " -DCORE_DEBUG_LEVEL=0\n-DCONFIG_IDF_TARGET_ESP32C3=1\n", + lib_ignore: "TFT_eSPI\n", + defaultMosi: 6, + defaultSck: 4, + defaultCs: 7, + defaultMiso: 5, + defaultSda: 8, + defaultScl: 9, + }, + esp8266: { + common: + "platform = https://github.com/platformio/platform-espressif8266.git\n" + + "board = esp12e\n" + + "framework = arduino\n" + + "monitor_speed = 115200\n" + + "monitor_flags = --echo\n" + + "monitor_filters = send_on_enter, colorize, esp8266_exception_decoder\n" + + "; set frequency to 160MHz\n" + + "board_build.f_cpu = 160000000L\n" + + "; set frequency to 40MHz\n" + + "board_build.f_flash = 40000000L\n" + + "board_build.flash_mode = dout\n" + + "upload_resetmethod = nodemcu\n" + + "upload_speed = 115200\n" + + "extra_scripts = pre:platformIO/extra_script.py\n", + build_flags: + " -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY\n-DNONOSDK221=1\n-DNDEBUG -DVTABLES_IN_FLASH\n-DWAVEFORM_LOCKED_PWM\n", + lib_ignore: "ESP32SSPD\n", + defaultMosi: 13, + defaultSck: 14, + defaultCs: 15, + defaultMiso: 12, + defaultSda: 4, + defaultScl: 5, + }, +} + +const libIgnore = ({ + target, + targetsize, + hasWifi, + hasEthernet, + hasBT, + cameraName, + displayName, + envName, +}) => { + return sections[target].lib_ignore + ? "lib_ignore = " + sections[target].lib_ignore + "\n" + : "" +} + +const cameraBuildFlags = (target, cameraName) => { + if (cameraName != "-1") { + return ` -DBOARD_HAS_PSRAM\n${ + target == "esp32" ? " -mfix-esp32-psram-cache-issue\n" : "" + }` + } + return "" +} + +const displayBuildFlags = (target, displayName) => { + if ( + displayName == "TFT_SPI_ST7789_240X240" || + displayName == "TFT_SPI_ST7789_135X240" + ) { + const width = displayName == "TFT_SPI_ST7789_135X240" ? 135 : 240 + const height = 240 + const rstpin = useDatasContextFn.getValueId("tftRSTpin") + const dcpin = useDatasContextFn.getValueId("tftDCpin") + const cspin = useDatasContextFn.getValueId("tftCSpin") + const mosipin = useDatasContextFn.getValueId("tftMOSIpin") + const sckpin = useDatasContextFn.getValueId("tftSCKpin") + + const backlightpin = useDatasContextFn.getValueId("tftledpin") + const defaultMosi = sections[target].defaultMosi + const defaultSck = sections[target].defaultSck + const defaultCs = sections[target].defaultCs + return ( + " -Os\n" + + "-DUSER_SETUP_LOADED=1\n" + + "-DST7789_DRIVER=1\n" + + "-DTFT_SDA_READY=1\n" + + "-DCGRAM_OFFSET=1\n" + + `-DTFT_WIDTH=${width}\n` + + `-DTFT_HEIGHT=${height}\n` + + `-DTFT_MOSI=${mosipin == "-1" ? defaultMosi : mosipin}\n` + + `-DTFT_SCLK=${sckpin == "-1" ? defaultSck : sckpin}\n` + + `-DTFT_CS=${cspin == "-1" ? defaultCs : cspin}\n` + + `-DTFT_DC=${dcpin}\n` + + `-DTFT_RST=${rstpin}\n` + + `-DTFT_BL=${backlightpin}\n` + + `-DTFT_BACKLIGHT_ON=${backlightpin == "-1" ? 0 : 1}\n` + + "-DLOAD_GLCD=1\n" + + "-DLOAD_FONT2=1\n" + + "-DLOAD_FONT4=1\n" + + "-DLOAD_FONT6=1\n" + + "-DLOAD_FONT7=1\n" + + "-DLOAD_FONT8=1\n" + + "-DLOAD_GFXFF=1\n" + + "-DSMOOTH_FONT=1\n" + + "-DSPI_FREQUENCY=40000000\n" + + "-DSPI_READ_FREQUENCY=6000000" + ) + } + return "" +} + +const buildFlags = ({ + target, + targetsize, + hasWifi, + hasEthernet, + hasBT, + cameraName, + displayName, +}) => { + //todo add Cam + return ( + "build_flags = " + + sections[target].build_flags + + displayBuildFlags(target, displayName) + + cameraBuildFlags(target, cameraName) + ) +} + +const partitionScheme = (target, targetsize, hasWifi, hasEthernet, hasBT) => { + if (target === "esp8266") { + switch (targetsize) { + case "1": + return "board_build.ldscript = eagle.flash.1m256.ld\n" + case "2": + return "board_build.ldscript = eagle.flash.2m256.ld\n" + case "4": + return "board_build.ldscript = eagle.flash.4m2m.ld\n" + case "8": + return "board_build.ldscript = eagle.flash.8m6m.ld\n" + case "16": + return "board_build.ldscript = eagle.flash.16m14m.ld\n" + default: + return "" + } + } else { + switch (targetsize) { + case "2": + return "board_upload.flash_size = 4MB\nboard_build.partitions = minimal.csv" + case "4": + if ((hasWifi || hasEthernet) && hasBT) { + return "board_upload.flash_size = 4MB\nboard_build.partitions = min_spiffs.csv\n" + } + return "board_upload.flash_size = 4MB\nboard_build.partitions = default.csv\n" + case "8": + return "board_upload.flash_size = 8MB\nboard_build.partitions = default_8MB.csv\n" + case "16": + return "board_upload.flash_size = 16MB\nboard_build.partitions = large_spiffs_16MB.csv\n" + default: + return "" + } + } +} + +const convertToPioEnv = ({ + target, + targetsize, + hasWifi, + hasEthernet, + hasBT, + cameraName, + displayName, + envName, +}) => { + /* + "build_flags":"build_flags = -DCORE_DEBUG_LEVEL=0\n", + + */ + return ( + "[" + + envName + + "]\n" + + sections[target].common + + partitionScheme(target, targetsize, hasWifi, hasEthernet, hasBT) + + libIgnore({ + target, + targetsize, + hasWifi, + hasEthernet, + hasBT, + cameraName, + displayName, + }) + + buildFlags({ + target, + targetsize, + hasWifi, + hasEthernet, + hasBT, + cameraName, + displayName, + }) + ) +} + +const convertPioToText = () => { + const target = useDatasContextFn.getValueId("targetmcu") + const targetsize = useDatasContextFn.getValueId("targetflashsize") + const hasWifi = useDatasContextFn.getValueId("wifi") + const hasEthernet = useDatasContextFn.getValueId("ethernet") + const hasBT = useDatasContextFn.getValueId("bluetooth") + const cameraName = useDatasContextFn.getValueId("cameratype") + const displayName = useDatasContextFn.getValueId("displaytype") + let res = "" + const envName = `${target}_${targetsize}MB${ + cameraName == "-1" ? "" : "_cam" + }${displayName == "-1" ? "" : "_disp"}${hasWifi ? "_wifi" : ""}${ + hasEthernet ? "_eth" : "" + }${hasBT ? "_bt" : ""}` + return ( + `default_envs = ${envName}\n\n` + + convertToPioEnv({ + target, + targetsize, + hasWifi, + hasEthernet, + hasBT, + cameraName, + displayName, + envName, + }) + ) +} + const sectionFormated = (title, description) => { return `\n/************************************\n*\n* ${title}\n*\n* ${description}\n*\n************************************/\n` } @@ -83,7 +446,7 @@ const canshow = (depend, pinvalue, currentvalue) => { } const convertToText = (data) => { - console.log(data) + //console.log(data) let config = "" return Object.keys(data).reduce((acc, item) => { return data[item].reduce((acc2, item2) => { @@ -200,6 +563,7 @@ const exportFile = (filecontent, filename) => { } let showconfig = false +let showini = false const NavButtons = ({ previous, next }) => { const { configuration } = useDatasContext() @@ -228,6 +592,14 @@ const NavButtons = ({ previous, next }) => { ) }} /> + { + exportFile(pioFile(), "platformio.ini") + }} + /> } @@ -269,6 +641,7 @@ const NavButtons = ({ previous, next }) => { const GenerateTab = ({ previous }) => { const { configuration } = useDatasContext() const [showContent, setshowContent] = useState(showconfig) + const [showIniContent, setshowIniContent] = useState(showini) return (
@@ -303,6 +676,40 @@ const GenerateTab = ({ previous }) => { )}
+
+ + + {showIniContent && ( +
+ +
{pioFile()}
+
+
+ )} +
+
+ {showContent && }
diff --git a/src/tabs/generate/piofooter.js b/src/tabs/generate/piofooter.js new file mode 100644 index 0000000..bd9c187 --- /dev/null +++ b/src/tabs/generate/piofooter.js @@ -0,0 +1,23 @@ +/* + piofooter.js - ESP3D-configurator footer for configuration.h file + + Copyright (c) 2020 Luc Lebosse. All rights reserved. + + This code 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 code 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 code; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +import { h } from "preact" +const piofooter = "\n\ +" +export default piofooter diff --git a/src/tabs/generate/pioheader.js b/src/tabs/generate/pioheader.js new file mode 100644 index 0000000..730b63e --- /dev/null +++ b/src/tabs/generate/pioheader.js @@ -0,0 +1,40 @@ +/* + pioheader.js - ESP3D-configurator header for configuration.h file + + Copyright (c) 2020 Luc Lebosse. All rights reserved. + + This code 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 code 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 code; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +import { h } from "preact" +const pioheader = + "\ +; PlatformIO Project Configuration File\n\ +;\n\ +; Build options: build flags, source filter\n\ +; Upload options: custom upload port, speed and extra flags\n\ +; Library options: dependencies, extra library storages\n\ +; Advanced options: extra scripting\n\ +;\n\ +; Please visit documentation for the other options and examples\n\ +; https://docs.platformio.org/page/projectconf.html\n\ +\n\ +[platformio]\n\ +src_dir = esp3d\n\ +build_dir = .pioenvs\n\ +lib_dir = libraries\n\ +libdeps_dir = .piolibdeps\n\ +data_dir = esp3d/data\n\ +" +export default pioheader