Skip to content

Shell

The shell of pico-jxglib is a powerful interactive command-line interface that allows you to interact with your firmware in real-time. It provides a bash-like experience, enabling you to execute various built-in commands for debugging, file management, and more. With the shell, you can easily test and modify the behavior of your firmware without the need for recompilation, making your development process more efficient and enjoyable.

How Shell Works

The following code is the minimal code to run the shell:

shell-with-stdio.cpp
#include <stdio.h>
#include "pico/stdlib.h"
#include "jxglib/Serial.h"
#include "jxglib/Shell.h"

using namespace jxglib;

int main()
{
    ::stdio_init_all();
    Serial::Terminal terminal;
    terminal.Initialize();
    Shell::AttachTerminal(terminal);
    for (;;) {
        Tickable::Tick();
    }
}

It runs the shell with stdio as the serial interface. If you enable USB stdio, you can access the shell through USB serial interface.

Even though there is no code to register any commands, you can still use various commands such as file system commands, logic analyzer commands, and so on. Where do they come from?

Hard coded in the shell itself? No. The shell is designed to be flexible and extensible, and the commands are implemented as extensions. You can add commands by linking libraries in CMakeLists.txt that implement the commands.

For example, the file system commands are implemented in the jxglib_ShellCmd_FS library. By linking this library, you can use the file system commands in the shell.

CMakeLists.txt
target_link_libraries(shell-with-stdio PRIVATE
    jxglib_ShellCmd_FS)

pico-jxglib provides many libraries that implement various commands as listed here. You can link any number of command libraries as long as there is enough room in the flash memory and RAM.

CMakeLists.txt
1
2
3
4
target_link_libraries(shell-with-stdio PRIVATE
    jxglib_ShellCmd_FS
    jxglib_ShellCmd_LogicAnalyzer
    jxglib_ShellCmd_NetUtil)

In these libraries, commands are implemeted by ShellCmd macro, which automatically registers the commands when the library is linked. This design allows for easy embedding and removal of commands without the need for explicit registration. Learn More

Library Name Description
jxglib_Shell Shell support