Skip to content

Commit

Permalink
Merge pull request #85 from raspberrypi/micropico-interop
Browse files Browse the repository at this point in the history
Micropico interop
  • Loading branch information
paulober authored Sep 17, 2024
2 parents 03b22e9 + 36d972e commit d937fb6
Show file tree
Hide file tree
Showing 13 changed files with 996 additions and 58 deletions.
6 changes: 4 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"files.exclude": {
// set them to true to hide them in vscode
"out": false,
"dist": false,
"**/*.vsix": true
"dist": true,
"**/*.vsix": true,
".yarn": true,
".pnp.*": true
},
"search.exclude": {
"out": true,
Expand Down
50 changes: 33 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Raspberry Pi Pico Visual Studio Code extension

> NOTE: The extension is currently under development.
> **Note: The extension is currently under development.**
This is the official Visual Studio Code extension for Raspberry Pi Pico development. This extension equips you with a suite of tools designed to streamline your Pico projects using Visual Studio Code and the official [Pico SDK](https://github.com/raspberrypi/pico-sdk).

Expand All @@ -10,18 +10,34 @@ For comprehensive setup instructions, refer to the [Getting Started guide](https

## Features

- Project Generator: Easily create new projects targeting the Ninja build system.
- Automatic CMake Configuration: Automatically configures CMake when loading a project.
- Version Switching: Seamlessly switch between different versions of the Pico SDK and tools.
- No Manual Setup Required: The extension handles environment variables, toolchain, SDK, and tool management for you.
- One-Click Compilation: Compile projects directly from the status bar with your selected SDK and tools.
- Offline Documentation: Access Pico SDK documentation offline.
- Quick Project Setup: Quickly create new Pico projects from the Explorer view when no workspace is open.
- Includes an Uninstaller: Easily remove the extension along with all automatically installed tools and SDKs.
### Project Setup and Management

- **Project Generator**: Easily create and configure new projects with support for advanced Pico features like I2C and PIO. The generator targets the Ninja build system and allows customization during project creation.
- **Quick Project Setup**: Initiate new Pico projects directly from the Explorer view, when no workspace is open.
- **MicroPython Support**: Create and develop MicroPython-based Pico projects with support provided through the [MicroPico](https://github.com/paulober/MicroPico) extension.

### Configuration and Tool Management

- **Automatic CMake Configuration**: Automatically configures CMake when loading a project.
- **Version Switching**: Seamlessly switch between different versions of the Pico SDK and tools.
- **No Manual Setup Required**: Automatically handles environment variables, toolchain, SDK, and tool management.
- **Includes an Uninstaller**: Easily remove the extension along with all automatically installed tools and SDKs.

### Build, Debug, and Documentation

- **One-Click Compilation and Debugging**: Automatically configure OpenOCD, Ninja, and CMake, allowing you to compile and debug with a single click.
- **Offline Documentation**: Conveniently access Pico SDK documentation directly within the editor, even when offline.

- **Version Switching**: Seamlessly switch between different versions of the Pico SDK and tools.
- **No Manual Setup Required**: The extension handles environment variables, toolchain, SDK, and tool management for you.
- **One-Click Compilation**: Compile projects directly from the status bar with your selected SDK and tools.
- **Offline Documentation**: Access Pico SDK documentation offline.
- **Quick Project Setup**: Quickly create new Pico projects from the Explorer view when no workspace is open.
- **MicroPython Support**: Create MicroPython-based Pico projects with support provided through the MicroPico extension.

## Requirements by OS

> Supported Platforms: Raspberry Pi OS (64-bit), Windows 10/11 (x86_64), macOS Sonoma (14.0) and newer, Linux x64 and arm64
> **Supported Platforms: Raspberry Pi OS (64-bit), Windows 10/11 (x86_64), macOS Sonoma (14.0) and newer, Linux x64 and arm64**
- Visual Studio Code v1.87.0 or later

Expand All @@ -38,19 +54,19 @@ To meet the requirements for macOS, run the following command in Terminal to ins
xcode-select --install
```
This command installs all of the necessary tools, including but not limited to:
- Git 2.28 or later (ensure it's in your PATH)
- Tar (ensure it's in your PATH)
- **Git 2.28 or later** (ensure it's in your PATH)
- **Tar** (ensure it's in your PATH)

### Windows

No additional requirements are needed for Windows.

### Linux
- Python 3.9 or later (ensure it’s in your PATH or set in settings)
- Git 2.28 or later (ensure it’s in your PATH)
- Tar (ensure it’s in your PATH)
- \[Optional\] gdb-multiarch for debugging (x86_64 only)
- For \[Ubuntu 22.04\], install `libftdi1-2` and `libhidapi-hidraw0` packages to use OpenOCD
- **Python 3.9 or later** (ensure it’s in your PATH or set in settings)
- **Git 2.28 or later** (ensure it’s in your PATH)
- **Tar** (ensure it’s in your PATH)
- **\[Optional\]** gdb-multiarch for debugging (x86_64 only)
- For **\[Ubuntu 22.04\]**, install `libftdi1-2` and `libhidapi-hidraw0` packages to use OpenOCD

## Extension Settings

Expand Down
6 changes: 3 additions & 3 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import tseslint from "typescript-eslint";
import js from "@eslint/js";
import eslintConfigPrettier from "eslint-config-prettier";

export default [
export default tseslint.config(
js.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
eslintConfigPrettier,
Expand All @@ -19,7 +19,7 @@ export default [
...globals.commonjs
},
parserOptions: {
project: true,
projectService: true,
tsconfigRootDir: import.meta.dirname
}
},
Expand Down Expand Up @@ -55,4 +55,4 @@ export default [
"web/**/*.js",
]
}
];
);
18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"url": "https://github.com/raspberrypi/pico-vscode/"
},
"engines": {
"vscode": "^1.87.0",
"node": ">=18.17.1"
"vscode": "^1.92.1",
"node": ">=20.14.0"
},
"os": [
"win32",
Expand Down Expand Up @@ -46,11 +46,13 @@
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"ms-vscode.vscode-serial-monitor",
"marus25.cortex-debug"
"marus25.cortex-debug",
"paulober.pico-w-go",
"ms-python.python"
],
"main": "./dist/extension.cjs",
"markdown": "github",
"minimumNodeVersion": 18,
"minimumNodeVersion": 20,
"capabilities": {
"virtualWorkspaces": {
"supported": false,
Expand All @@ -63,7 +65,8 @@
},
"activationEvents": [
"workspaceContains:./pico_sdk_import.cmake",
"onWebviewPanel:newPicoProject"
"onWebviewPanel:newPicoProject",
"onWebviewPanel:newPicoMicroPythonProject"
],
"contributes": {
"commands": [
Expand Down Expand Up @@ -279,9 +282,9 @@
"@rollup/plugin-typescript": "^11.1.6",
"@types/adm-zip": "^0.5.5",
"@types/ini": "^4.1.1",
"@types/node": "18.17.x",
"@types/node": "20.14.0",
"@types/uuid": "^10.0.0",
"@types/vscode": "^1.87.0",
"@types/vscode": "^1.92.0",
"@types/which": "^3.0.4",
"eslint": "^9.9.0",
"eslint-config-prettier": "^9.1.0",
Expand All @@ -292,6 +295,7 @@
"typescript-eslint": "^8.1.0"
},
"dependencies": {
"@vscode/python-extension": "^1.0.5",
"adm-zip": "^0.5.14 <0.5.15",
"got": "^14.4.2",
"ini": "^4.1.3",
Expand Down
56 changes: 50 additions & 6 deletions src/commands/newProject.mts
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import { Command } from "./command.mjs";
import { CommandWithArgs } from "./command.mjs";
import Logger from "../logger.mjs";
import { type Uri } from "vscode";
import { window, type Uri } from "vscode";
import { NewProjectPanel } from "../webview/newProjectPanel.mjs";
// eslint-disable-next-line max-len
import { NewMicroPythonProjectPanel } from "../webview/newMicroPythonProjectPanel.mjs";

export default class NewProjectCommand extends Command {
/**
* Enum for the language of the project.
* Can be used to specify the language of the project
* in the `NewProjectCommand` class.
*/
export enum ProjectLang {
cCpp = 1,
micropython = 2,
}

export default class NewProjectCommand extends CommandWithArgs {
private readonly _logger: Logger = new Logger("NewProjectCommand");
private readonly _extensionUri: Uri;
private static readonly micropythonOption = "MicroPython";
private static readonly cCppOption = "C/C++";

public static readonly id = "newProject";

Expand All @@ -15,8 +29,38 @@ export default class NewProjectCommand extends Command {
this._extensionUri = extensionUri;
}

execute(): void {
// show webview where the process of creating a new project is continued
NewProjectPanel.createOrShow(this._extensionUri);
private preSelectedTypeToStr(preSelectedType?: number): string | undefined {
return preSelectedType === ProjectLang.cCpp
? NewProjectCommand.cCppOption
: preSelectedType === ProjectLang.micropython
? NewProjectCommand.micropythonOption
: undefined;
}

async execute(preSelectedType?: number): Promise<void> {
// ask the user what language to use
const lang =
this.preSelectedTypeToStr(preSelectedType) ??
(await window.showQuickPick(
[NewProjectCommand.cCppOption, NewProjectCommand.micropythonOption],
{
placeHolder: "Select which language to use for your new project",
canPickMany: false,
ignoreFocusOut: false,
title: "New Pico Project",
}
));

if (lang === undefined) {
return;
}

if (lang === NewProjectCommand.micropythonOption) {
// create a new project with MicroPython
NewMicroPythonProjectPanel.createOrShow(this._extensionUri);
} else {
// show webview where the process of creating a new project is continued
NewProjectPanel.createOrShow(this._extensionUri);
}
}
}
13 changes: 13 additions & 0 deletions src/extension.mts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ import NewExampleProjectCommand from "./commands/newExampleProject.mjs";
import SwitchBoardCommand from "./commands/switchBoard.mjs";
import UninstallPicoSDKCommand from "./commands/uninstallPicoSDK.mjs";
import FlashProjectSWDCommand from "./commands/flashProjectSwd.mjs";
// eslint-disable-next-line max-len
import { NewMicroPythonProjectPanel } from "./webview/newMicroPythonProjectPanel.mjs";

export async function activate(context: ExtensionContext): Promise<void> {
Logger.info(LoggerSource.extension, "Extension activation triggered");
Expand Down Expand Up @@ -144,6 +146,17 @@ export async function activate(context: ExtensionContext): Promise<void> {
})
);

context.subscriptions.push(
window.registerWebviewPanelSerializer(NewMicroPythonProjectPanel.viewType, {
// eslint-disable-next-line @typescript-eslint/require-await
async deserializeWebviewPanel(webviewPanel: WebviewPanel): Promise<void> {
// Reset the webview options so we use latest uri for `localResourceRoots`.
webviewPanel.webview.options = getWebviewOptions(context.extensionUri);
NewMicroPythonProjectPanel.revive(webviewPanel, context.extensionUri);
},
})
);

context.subscriptions.push(
window.registerTreeDataProvider(
PicoProjectActivityBar.viewType,
Expand Down
6 changes: 2 additions & 4 deletions src/utils/githubREST.mts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ export const PYENV_REPOSITORY_URL = "https://github.com/pyenv/pyenv.git";
export function ownerOfRepository(repository: GithubRepository): string {
switch (repository) {
case GithubRepository.picoSDK:
case GithubRepository.tools:
case GithubRepository.picotool:
return "raspberrypi";
case GithubRepository.cmake:
return "Kitware";
case GithubRepository.ninja:
return "ninja-build";
case GithubRepository.tools:
return "raspberrypi";
case GithubRepository.picotool:
return "raspberrypi";
}
}

Expand Down
24 changes: 19 additions & 5 deletions src/webview/activityBar.mts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "vscode";
import Logger from "../logger.mjs";
import { extensionName } from "../commands/command.mjs";
import NewProjectCommand from "../commands/newProject.mjs";
import NewProjectCommand, { ProjectLang } from "../commands/newProject.mjs";
import CompileProjectCommand from "../commands/compileProject.mjs";
import RunProjectCommand from "../commands/runProject.mjs";
import SwitchSDKCommand from "../commands/switchSDK.mjs";
Expand Down Expand Up @@ -39,7 +39,8 @@ const COMMON_COMMANDS_PARENT_LABEL = "General";
const PROJECT_COMMANDS_PARENT_LABEL = "Project";
const DOCUMENTATION_COMMANDS_PARENT_LABEL = "Documentation";

const NEW_PROJECT_LABEL = "New Project";
const NEW_C_CPP_PROJECT_LABEL = "New C/C++ Project";
const NEW_MICROPYTHON_PROJECT_LABEL = "New MicroPython Project";
const IMPORT_PROJECT_LABEL = "Import Project";
const EXAMPLE_PROJECT_LABEL = "New Project From Example";
const SWITCH_SDK_LABEL = "Switch SDK";
Expand Down Expand Up @@ -78,10 +79,13 @@ export class PicoProjectActivityBar
element: QuickAccessCommand
): TreeItem | Thenable<TreeItem> {
switch (element.label) {
case NEW_PROJECT_LABEL:
case NEW_C_CPP_PROJECT_LABEL:
// alt. "new-folder"
element.iconPath = new ThemeIcon("file-directory-create");
break;
case NEW_MICROPYTHON_PROJECT_LABEL:
element.iconPath = new ThemeIcon("file-directory-create");
break;
case IMPORT_PROJECT_LABEL:
// alt. "repo-pull"
element.iconPath = new ThemeIcon("repo-clone");
Expand Down Expand Up @@ -158,11 +162,21 @@ export class PicoProjectActivityBar
} else if (element.label === COMMON_COMMANDS_PARENT_LABEL) {
return [
new QuickAccessCommand(
NEW_PROJECT_LABEL,
NEW_C_CPP_PROJECT_LABEL,
TreeItemCollapsibleState.None,
{
command: `${extensionName}.${NewProjectCommand.id}`,
title: NEW_C_CPP_PROJECT_LABEL,
arguments: [ProjectLang.cCpp],
}
),
new QuickAccessCommand(
NEW_MICROPYTHON_PROJECT_LABEL,
TreeItemCollapsibleState.None,
{
command: `${extensionName}.${NewProjectCommand.id}`,
title: NEW_PROJECT_LABEL,
title: NEW_MICROPYTHON_PROJECT_LABEL,
arguments: [ProjectLang.micropython],
}
),
new QuickAccessCommand(
Expand Down
Loading

0 comments on commit d937fb6

Please sign in to comment.