Initial check in

This commit is contained in:
Earle F. Philhower, III
2023-09-25 18:39:54 -07:00
commit d714e1f351
14 changed files with 3085 additions and 0 deletions

24
.eslintrc.json Normal file
View File

@ -0,0 +1,24 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
},
"ignorePatterns": [
"out",
"dist",
"**/*.d.ts"
]
}

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
out
dist
node_modules
.vscode-test/
*.vsix

7
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint"
]
}

34
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,34 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}

11
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,11 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
}

20
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,20 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

10
.vscodeignore Normal file
View File

@ -0,0 +1,10 @@
.vscode/**
.vscode-test/**
src/**
.gitignore
.yarnrc
vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json
**/*.map
**/*.ts

9
LICENSE.md Normal file
View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2023 Earle F. Philhower, III <earlephilhower@yahoo.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

19
README.md Normal file
View File

@ -0,0 +1,19 @@
# pico-littlefs-upload README
(C) 2023 Earle F. Philhower, III
MIT licensed, see LICENSE.md
Really rough LittleFS uploader compatiblew with IDE 2.2.1 or higher.
## Usage
`[Ctrl]+[Shift]+[P]``, then "`Upload LittleFS to Pico`"
## Glitches
The first sketch auto-opened by the IDE presently has corrupted state and uploads cannot be done on it.
You need to open another sketch, close the first auto-opened sketch, and then re-open it to upload for that one.
You also need to run a build/compile (upload of sketch is uptional) one time for certain file system parameters to be available.
## Installation
Copy the VSIX file to `~/.arduinoIDE/plugins/` (you may need to make this directory yourself beforehand) and restart the IDE.

2732
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

49
package.json Normal file
View File

@ -0,0 +1,49 @@
{
"name": "pico-littlefs-upload",
"displayName": "pico-littlefs-upload",
"description": "Build and uploads LittleFS filesystems for the Arduino-Pico RP2040 core under Arduino IDE 2.2.1 or higher",
"version": "0.0.2",
"engines": {
"vscode": "^1.82.0"
},
"license": "MIT",
"repository": {
"url": "https://github.com/earlephilhower/pico-littlefs-upload"
},
"categories": [
"Other"
],
"activationEvents": [],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "pico-littlefs-upload.uploadLittleFS",
"title": "Upload LittleFS to Pico"
}
]
},
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@types/mocha": "^10.0.1",
"@types/node": "16.x",
"@types/vscode": "^1.82.0",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.1",
"@vscode/test-electron": "^2.3.4",
"eslint": "^8.47.0",
"glob": "^10.3.3",
"mocha": "^10.2.0",
"typescript": "^5.1.6"
},
"dependencies": {
"execa": "^8.0.1"
}
}

106
src/extension.ts Normal file
View File

@ -0,0 +1,106 @@
import * as vscode from 'vscode';
import * as fs from 'fs';
import type { ArduinoContext } from 'vscode-arduino-api';
import { platform } from 'node:os';
export function activate(context: vscode.ExtensionContext) {
// Get the Arduino info extension loaded
const arduinoContext: ArduinoContext = vscode.extensions.getExtension(
'dankeboy36.vscode-arduino-api'
)?.exports;
if (!arduinoContext) {
// Failed to load the Arduino API.
vscode.window.showErrorMessage("Unable to load the Arduino IDE Context extension.");
return;
}
// Register the command
let disposable = vscode.commands.registerCommand('pico-littlefs-upload.uploadLittleFS', () => {
// let str = JSON.stringify(arduinoContext, null, 4);
// console.log(str);
if ((arduinoContext.boardDetails === undefined) || (arduinoContext.fqbn === undefined)){
vscode.window.showErrorMessage("Board details not available. Compile the sketch once.");
return;
}
if (!arduinoContext.fqbn.startsWith("pico:rp2040")) { //} && !arduinoContext.compileSummary?.buildProperties.fqbn.startsWith("esp8266com:esp8266")) {
vscode.window.showErrorMessage("Only Arduino-Pico RP2040 supported"); //and the ESP8266 supported");
return;
}
if ((arduinoContext.compileSummary?.buildProperties["build.fs_start"] === undefined) || (arduinoContext.compileSummary?.buildProperties["build.fs_end"] === undefined)) {
vscode.window.showErrorMessage("No filesystem settings defined. Compile the sketch once.");
return;
}
let fsStart = Number(arduinoContext.compileSummary?.buildProperties["build.fs_start"]);
let fsEnd = Number(arduinoContext.compileSummary?.buildProperties["build.fs_end"]);
let page = 256;
let blocksize = 4096;
if (fsEnd <= fsStart) {
vscode.window.showErrorMessage("No filesystem specified, check flash size menu");
return;
}
let mklittlefs = "mklittlefs";
if (arduinoContext.compileSummary?.buildProperties["runtime.os"].includes("windows")) {
mklittlefs = mklittlefs + ".exe";
}
if (arduinoContext.compileSummary?.buildProperties["runtime.tools.pqt-mklittlefs.path"] !== undefined) {
mklittlefs = arduinoContext.compileSummary?.buildProperties["runtime.tools.pqt-mklittlefs.path"] + "/" + mklittlefs;
} // OTW, assume it's in the path is best we can do
// TBD - add non-serial UF2 upload via OpenOCD
let serialPort = "";
if (arduinoContext.port?.address === undefined) {
vscode.window.showErrorMessage("No port specified, check IDE menus");
return;
} else {
serialPort = arduinoContext.port?.address;
}
if (arduinoContext.port?.protocol !== "serial") {
vscode.window.showErrorMessage("Only serial port upload supported at this time");
return;
}
let python3 = "python3";
if (arduinoContext.compileSummary?.buildProperties["runtime.tools.pqt-python3.path"] !== undefined) {
python3 = arduinoContext.compileSummary?.buildProperties["runtime.tools.pqt-python3.path"] + "/" + python3;
} // OTW, assume it's in the path is best we can do
if (arduinoContext.compileSummary?.buildProperties["runtime.os"].includes("windows")) {
python3 = python3 + ".exe";
}
let uf2conv = "tools/uf2conv.py";
if (arduinoContext.compileSummary?.buildProperties["runtime.platform.path"] !== undefined) {
uf2conv = arduinoContext.compileSummary?.buildProperties["runtime.platform.path"] + "/" + uf2conv;
} // OTW, assume it's in the path is best we can do
let dataFolder = arduinoContext.sketchPath + "/data";
var path = require('path');
let imageFile = "/" + path.basename(arduinoContext.sketchPath);
if (arduinoContext.compileSummary?.buildPath !== undefined) {
imageFile = arduinoContext.compileSummary?.buildPath + imageFile;
}
imageFile = imageFile + ".mklittlefs.bin";
let buildCmd = ["-c", dataFolder, "-p", String(page), "-b", String(blocksize), "-s", String(fsEnd - fsStart), imageFile];
let uploadCmd = [uf2conv, "--base", String(fsStart), "--serial", serialPort, "--family", "RP2040", imageFile];
const { spawnSync } = require('child_process');
console.log("Building the file system image: " + mklittlefs + " " + buildCmd.join(" "));
spawnSync(mklittlefs, buildCmd);
console.log("Uploading the file system image: " + python3 + " " + uploadCmd.join(" "));
spawnSync(python3, uploadCmd);
console.log("Completed upload");
vscode.window.showInformationMessage("LittleFS upload completed!");
});
context.subscriptions.push(disposable);
}
export function deactivate() {}

17
tsconfig.json Normal file
View File

@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "ES2020",
"outDir": "out",
"lib": [
"ES2020"
],
"sourceMap": true,
"rootDir": "src",
"strict": true /* enable all strict type-checking options */
/* Additional Checks */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
}
}

View File

@ -0,0 +1,42 @@
# Welcome to your VS Code Extension
## What's in the folder
* This folder contains all of the files necessary for your extension.
* `package.json` - this is the manifest file in which you declare your extension and command.
* The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesnt yet need to load the plugin.
* `src/extension.ts` - this is the main file where you will provide the implementation of your command.
* The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`.
* We pass the function containing the implementation of the command as the second parameter to `registerCommand`.
## Get up and running straight away
* Press `F5` to open a new window with your extension loaded.
* Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`.
* Set breakpoints in your code inside `src/extension.ts` to debug your extension.
* Find output from your extension in the debug console.
## Make changes
* You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`.
* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes.
## Explore the API
* You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`.
## Run tests
* Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Extension Tests`.
* Press `F5` to run the tests in a new window with your extension loaded.
* See the output of the test result in the debug console.
* Make changes to `src/test/suite/extension.test.ts` or create new test files inside the `test/suite` folder.
* The provided test runner will only consider files matching the name pattern `**.test.ts`.
* You can create folders inside the `test` folder to structure your tests any way you want.
## Go further
* [Follow UX guidelines](https://code.visualstudio.com/api/ux-guidelines/overview) to create extensions that seamlessly integrate with VS Code's native interface and patterns.
* Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension).
* [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VS Code extension marketplace.
* Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration).