### Build Specific Example for Linux Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/examples/Blink-app Command to build a specific example, 'example_blink', for the Linux target. This is useful for testing individual examples without building the entire firmware. ```bash docker-compose exec dev make -C target_lo example_blink ``` -------------------------------- ### Control GPIO Pin (LED Example) Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_gpio.md Example of getting a GPIO pin, initializing it as an output, and controlling its state to blink an LED. ```javascript let eventLoop = require("event_loop"); let gpio = require("gpio"); let led = gpio.get("pc3"); led.init({ direction: "out", outMode: "push_pull" }); led.write(true); delay(1000); led.write(false); delay(1000); ``` -------------------------------- ### Build Specific Example for Flipper Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/examples/Blink-app Command to build a specific example, 'example_blink', for the Flipper Zero hardware. This allows for targeted compilation of individual examples. ```bash docker-compose exec dev make -C target_f1 example_blink ``` -------------------------------- ### Run Flipper Zero Firmware Examples with Docker Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/Home Run example applications for the Flipper Zero firmware using Docker. Refer to applications.mk for a list of available applications and examples. ```bash docker-compose exec dev make -C firmware TARGET=local APP_*=1 run ``` -------------------------------- ### Install qFlipper on macOS Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/applications/main/bad_usb/resources/badusb/Install_qFlipper_macOS.txt This script automates the installation of qFlipper on macOS. It first opens the Terminal, then downloads the qFlipper DMG, mounts it, copies the application to the Applications folder, detaches the DMG, and finally opens qFlipper. It's recommended to run the initial REM lines only once per target to bypass the macOS keyboard setup assistant. ```badusb REM Keep these 3 lines IF (and only if) it's the first time you are performing a badKB attack against a specific macOS target. REM In fact, it helps Flipper Zero bypass the macOS keyboard setup assistant. Otherwise the attack will not start. REM Author: 47LeCoste REM Version 1.0 (Flipper Ducky) REM Target: macOS DELAY 3000 F4 DELAY 2500 STRING Terminal DELAY 2500 ENTER DELAY 1500 STRING (cd /tmp && curl -L -o qFlipper.dmg https://update.flipperzero.one/qFlipper/release/macos-amd64/dmg && hdiutil attach qFlipper.dmg && app_volume=$(ls /Volumes | grep -i "qFlipper") && (test -e /Applications/qFlipper.app && rm -rf /Applications/qFlipper.app ); cp -R "/Volumes/$app_volume/qFlipper.app" /Applications/ && hdiutil detach "/Volumes/$app_volume" && rm qFlipper.dmg && open /Applications/qFlipper.app) DELAY 1000 ENTER ``` -------------------------------- ### Automated qFlipper Installation Script for Windows Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/applications/main/bad_usb/resources/badusb/Install_qFlipper_windows.txt This script automates the download, extraction, and setup of qFlipper on a Windows system. It handles downloading the latest release, extracting it to the user's Documents folder, installing necessary drivers, and creating a desktop shortcut. It also attempts to run the qFlipper executable. ```batch REM Written by @dexv DELAY 2000 GUI r DELAY 500 STRING powershell ENTER DELAY 1000 STRING $url = "https://update.flipperzero.one/qFlipper/release/windows-amd64/portable" ENTER STRING $output = "$env:USERPROFILE\Documents\qFlipper.zip" ENTER STRING $destination = "$env:USERPROFILE\Documents\qFlipper" ENTER STRING $shortcutPath = "$env:USERPROFILE\Desktop\qFlipper.lnk" ENTER STRING $scriptPath = "$env:USERPROFILE\Documents\qFlipperInstall.ps1" ENTER STRING $driverPath = "$destination\STM32 Driver" ENTER STRING $installBat = "$driverPath\install.bat" ENTER STRING (New-Object System.Net.WebClient).DownloadFile($url, $output) ENTER STRING Expand-Archive -Path $output -DestinationPath $destination -Force ENTER STRING Set-Location -Path $destination ENTER STRING Start-Process -FilePath ".\qFlipper.exe" ENTER STRING Start-Process -Wait -FilePath "cmd.exe" -ArgumentList "/c $installBat" ENTER STRING $shell = New-Object -ComObject WScript.Shell ENTER STRING $shortcut = $shell.CreateShortcut($shortcutPath) ENTER STRING $shortcut.TargetPath = "$destination\qFlipper.exe" ENTER STRING $shortcut.Save() ENTER DELAY 500 STRING "powershell -ExecutionPolicy Bypass -File $scriptPath" ENTER ``` -------------------------------- ### Start Flipper Application Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/fw/api/Basic-API Starts a new application or daemon. It calls the provided entrypoint function with the given parameter. Useful for background tasks. ```c FlappHandler* flapp_start(void(app*)(void*), char* name, void* param); ``` -------------------------------- ### PubSub Example Usage Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/fw/api/Basic-API An example demonstrating the PubSub system. It initializes a PubSub instance, subscribes a handler function, and then repeatedly notifies subscribers with an incrementing counter. ```C /* MANIFEST name="test" stack=128 */ void example_pubsub_handler(void* arg, void* ctx) { printf("get %d from %s\n", *(uint32_t*)arg, (const char*)ctx); } void pubsub_test() { const char* app_name = "test app"; PubSub example_pubsub; init_pubsub(&example_pubsub); if(!subscribe_pubsub(&example_pubsub, example_pubsub_handler, (void*)app_name)) { printf("critical error\n"); flapp_exit(NULL); } uint32_t counter = 0; while(1) { notify_pubsub(&example_pubsub, (void*)&counter); counter++; osDelay(100); } } ``` -------------------------------- ### Mifare Ultralight C Key Dictionary File Format Example Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/file_formats/NfcFileFormats.md This example demonstrates the format for a Mifare Ultralight C key dictionary file. Keys are represented as hex strings, and the file supports comments starting with '#' and ignores blank lines. ```Key Dictionary File # Hexadecimal-Reversed Sample Key 12E4143455F495649454D4B414542524 # Byte-Reversed Sample Key (!NACUOYFIEMKAERB) 214E4143554F594649454D4B41455242 # Sample Key (BREAKMEIFYOUCAN!) 425245414B4D454946594F5543414E21 # Semnox Key (IEMKAERB!NACUOY ) 49454D4B41455242214E4143554F5900 # Modified Semnox Key (IEMKAERB!NACUOYF) 49454D4B41455242214E4143554F5946 ... ``` -------------------------------- ### Flipper iButton Key File Example Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/file_formats/iButtonFileFormat.md This example shows the structure of a Flipper iButton key file for protocol DS1992, including file type, version, protocol, ROM data, and SRAM data. ```text Filetype: Flipper iButton key Version: 2 Protocol: DS1992 Rom Data: 08 DE AD BE EF FA CE 4E Sram Data: 4E 65 76 65 72 47 6F 6E 6E 61 47 69 76 65 59 6F 75 55 70 4E 65 76 65 72 47 6F 6E 6E 61 4C 65 74 59 6F 75 44 6F 77 6E 4E 65 76 65 72 47 6F 6E 6E 61 52 75 6E 41 72 6F 75 6E 64 41 6E 64 44 65 73 65 72 74 59 6F 75 4E 65 76 65 72 47 6F 6E 6E 61 4D 61 6B 65 59 6F 75 43 72 79 4E 65 76 65 72 47 6F 6E 6E 61 53 61 79 47 6F 6F 64 62 79 65 4E 65 76 65 72 47 6F 6E 6E 61 54 65 6C 6C 41 4C 69 65 ``` -------------------------------- ### GPIO Usage Example Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/fw/api/HAL-API Demonstrates how to open a GPIO pin, initialize it as an output, and then toggle it ON and OFF indefinitely with delays. ```C void gpio_example() { GpioPin* pin = open_gpio("PB6"); if(pin == NULL) { printf("pin not available\n"); return; } gpio_init(pin, GpioModeOutput); while(1) { gpio_write(pin, true); delay(100); gpio_write(pin, false); delay(100); } } ``` -------------------------------- ### Example connection on macOS Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/devboard/Reading logs via the Dev Board.md Example command to connect to a specific Developer Board serial port on macOS. ```bash minicom -D /dev/cu.usbmodemblackmagic3 -b 230400 ``` -------------------------------- ### Build and Run APP_EXAMPLE_INPUT_DUMP on Local Target Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/testing/General-building-test This command builds and runs the APP_EXAMPLE_INPUT_DUMP application on the local target. Note: This example is not yet implemented. ```bash docker-compose exec dev make -C firmware TARGET=local APP_EXAMPLE_INPUT_DUMP=1 run ``` -------------------------------- ### Install micro Flipper Build Tool (uFBT) on Windows Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/devboard/Firmware update on Developer Board.md Installs the uFBT tool on Windows using pipx. This requires Python and pipx to be installed and added to the system's PATH. ```powershell py -m pip install --user pipx ``` ```powershell py -m pipx ensurepath ``` ```powershell pipx install ufbt ``` -------------------------------- ### Mifare Classic Key Dictionary File Format Example Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/file_formats/NfcFileFormats.md This example illustrates the format for a Mifare Classic key dictionary file. Each line represents a key as a hex string, with lines starting with '#' treated as comments and blank lines ignored. ```Key Dictionary File # Key dictionary from https://github.com/ikarus23/MifareClassicTool.git # More well known keys! # Standard keys FFFFFFFFFFFF A0A1A2A3A4A5 D3F7D3F7D3F7 000000000000 # Keys from mfoc B0B1B2B3B4B5 4D3A99C351DD 1A982C7E459A AABBCCDDEEFF 714C5C886E97 587EE5F9350F A0478CC39091 533CB6C723F6 8FD0A4F256E9 ... ``` -------------------------------- ### Execute Input Dump Example Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/testing/Input-test Run the example input dump command within the development Docker container. This is typically used to generate test data or verify input handling mechanisms. ```bash docker-compose exec dev make -C target_f2 example_input_dump ``` -------------------------------- ### LED Control Example Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/fw/api/LED-API Demonstrates how to open the LED API, subscribe to state changes, read the current state, initialize a composer, and write new RGB values to the LED. ```c void handle_led_state(Rgb* rgb, void* _ctx) { printf("led: #%02X%02X%02X\n", rgb->red, rgb->green, rgb->blue); } void led_example(void* p) { LedApi* led_api = open_led("/dev/led"); if(led_api == NULL) return; // led not available, critical error // subscribe to led state updates subscribe_led_changes(led_api, handle_led_state, NULL); // get current led value Rgb led_value; if(read_led(led_api, &led_value, OsWaitForever)) { printf( "initial led: #%02X%02X%02X\n", led_value->red, led_value->green, led_value->blue ); } // create compose to control led SystemLed system_led; if(!init_led_composer(&system_led, led_api, UiLayerBelowNotify)) return; // write RGB value write_led(&system_led, &(Rgb{.red = 0xFA, green = 0xCE, .blue = 0x8D})); } ``` -------------------------------- ### Install qFlipper AppImage on Linux GNOME Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/applications/main/bad_usb/resources/badusb/Install_qFlipper_gnome.txt Automates the installation of qFlipper on Linux/GNOME by downloading the latest AppImage, making it executable, and integrating it with the desktop environment. Ensures necessary directories are created and desktop entries are updated. ```bash ALT F2 DELAY 1000 STRINGLN gnome-terminal --maximize DELAY 1000 STRINGLN mkdir -p $HOME/.local/bin STRINGLN curl -fsSL "https://update.flipperzero.one/qFlipper/release/linux-amd64/AppImage" -o "$HOME/.local/bin/qFlipper" DELAY 1000 STRINGLN chmod +x $HOME/.local/bin/qFlipper STRINGLN cd /tmp STRINGLN $HOME/.local/bin/qFlipper --appimage-extract > /dev/null STRINGLN sed "s@Exec=qFlipper@Exec=$HOME/.local/bin/qFlipper@" squashfs-root/usr/share/applications/qFlipper.desktop > $HOME/.local/share/applications/qFlipper.desktop STRINGLN mkdir -p $HOME/.local/share/icons/hicolor/512x512/apps STRINGLN cp squashfs-root/usr/share/icons/hicolor/512x512/apps/qFlipper.png $HOME/.local/share/icons/hicolor/512x512/apps/qFlipper.png STRINGLN rm -rf squashfs-root STRINGLN cd STRINGLN xdg-desktop-menu forceupdate || true STRINGLN update-desktop-database ~/.local/share/applications || true STRINGLN echo " ENTER REPEAT 60 STRINGLN ========================================================================================== STRINGLN qFlipper has been installed to $HOME/.local/bin/ STRINGLN It should appear in your Applications menu. STRINGLN If it does not, you might want to log out and log in again. ENTER STRINGLN If you prefer to run qFlipper from your terminal, either use the absolute path STRINGLN or make sure $HOME/.local/bin/ is included in your PATH environment variable. ENTER STRINGLN Additional configurations might be required by your Linux distribution such as STRINGLN group membership, udev rules or else. STRINGLN ========================================================================================== STRINGLN " ENTER ``` -------------------------------- ### Install micro Flipper Build Tool (uFBT) on Linux/macOS Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/devboard/Firmware update on Developer Board.md Installs the uFBT tool using pipx on Linux and macOS systems. Ensure pipx is installed first by following the official instructions. ```bash pipx install ufbt ``` -------------------------------- ### Backlight Usage Example Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/fw/api/Backlight-API Demonstrates how to open the Backlight API, subscribe to state changes, read the initial state, initialize a composer, and write a new backlight value. ```c void handle_backlight_state(uint8_t* value, void* _ctx) { printf("backlight: %d %%\n", (*value * 100) / 256); } void backlight_example(void* p) { BacklightApi* backlight_api = open_backlight("/dev/backlight"); if(backlight_api == NULL) return; subscribe_backlight_changes(backlight_api, handle_backlight_state, NULL); uint8_t backlight_value; if(read_backlight(backlight_api, &backlight_value, OsWaitForever)) { printf( "initial backlight: %d %%\n", backlight_value * 100 / 256 ); } Backlight backlight; if(!init_led_composer(&backlight, backlight_api, UiLayerBelowNotify)) return; write_backlight(&backlight, 127); } ``` -------------------------------- ### Example .sub File Key Data (Princeton Format) Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/file_formats/SubGhzFileFormats.md This example shows the structure of key data within a .sub file using the Princeton protocol. It includes the protocol name, bit length, key value, and quantization interval. ```text ... Protocol: Princeton Bit: 24 Key: 00 00 00 00 00 95 D5 D4 TE: 400 ``` -------------------------------- ### Example: Multiple Views with ViewDispatcher Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_gui.md Demonstrates how to set up and manage multiple views (loading, empty, submenu) using the ViewDispatcher. It includes event subscriptions for view switching and navigation. ```javascript let eventLoop = require("event_loop"); let gui = require("gui"); let loadingView = require("gui/loading"); let submenuView = require("gui/submenu"); let emptyView = require("gui/empty_screen"); // Common pattern: declare all the views in an object. This is absolutely not // required, but adds clarity to the script. let views = { // the view dispatcher auto-✨magically✨ remembers views as they are created loading: loadingView.make(), empty: emptyView.make(), demos: submenuView.makeWith({ items: [ "Hourglass screen", "Empty screen", "Exit app", ], }), }; // go to different screens depending on what was selected eventLoop.subscribe(views.demos.chosen, function (_sub, index, gui, eventLoop, views) { if (index === 0) { gui.viewDispatcher.switchTo(views.loading); } else if (index === 1) { gui.viewDispatcher.switchTo(views.empty); } else if (index === 2) { eventLoop.stop(); } }, gui, eventLoop, views); // go to the demo chooser screen when the back key is pressed eventLoop.subscribe(gui.viewDispatcher.navigation, function (_sub, _, gui, views) { gui.viewDispatcher.switchTo(views.demos); }, gui, views); // run UI gui.viewDispatcher.switchTo(views.demos); eventLoop.run(); ``` -------------------------------- ### Pin.pwmWrite() Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_gpio.md Configures and starts PWM on the pin. ```APIDOC ## Pin.pwmWrite() Sets PWM parameters and starts the PWM. Configures the pin with `{ direction: "out", outMode: "push_pull" }`. Throws an error if PWM is not supported on this pin. ### Parameters - `freq`: Frequency in Hz - `duty`: Duty cycle in % ``` -------------------------------- ### Input API Usage Example Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/fw/api/Input-API Demonstrates how to open the Input API, subscribe to events, and read the button state in a loop. Includes handling of null API instance and infinite waiting for state. ```c // function used to handle keyboard events void handle_keyboard(InputEvent* event, void* _ctx) { if(event->state) { printf("you press %d", event->input); } else { printf("you release %d", event->input); } } void input_example(void* p) { Input* input = open_input("/dev/kb"); if(input == NULL) return; // keyboard not available, critical error // async way subscribe_input_events(input->events, handle_keyboard, NULL); // blocking way InputState state; while(1) { if(read_state(input, &state, OsWaitForever)) { if(state.up) { printf("up is pressed"); delay(1000); } } delay(10); } } ``` -------------------------------- ### CC1101 Example Usage Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/fw/api/SPI-Devices-API Demonstrates how to interact with the CC1101 Sub-GHz radio using `SpiIrqDevice`. ```APIDOC ### Application example ```C // Be careful, this function called from IRQ context void handle_irq(void* _arg, void* _ctx) { } void cc1101_example() { SpiIrqDevice* cc1101_device = open_input("/dev/cc1101_bus"); if(cc1101_device == NULL) return; // bus not available, critical error subscribe_pubsub(cc1101_device->irq, handle_irq, NULL); { // acquire device as device bus SpiBus* spi_bus = acquire_mutex(cc1101_device->bus, 0); if(spi_bus == NULL) { printf("Device busy\n"); // wait for device spi_bus = acquire_mutex_block(cc1101_device->bus); } // make transaction uint8_t request[4] = {0xDE, 0xAD, 0xBE, 0xEF}; uint8_t response[4]; { SPI_HandleTypeDef* spi = acquire_mutex_block(spi_bus->spi); gpio_write(spi_bus->cs, false); spi_xfer_block(spi, request, response, 4); gpio_write(spi_bus->cs, true); release_mutex(cc1101_device->spi, spi); } // release device (device bus) release_mutex(cc1101_device->bus, spi_bus); } } ``` ``` -------------------------------- ### PWM Sound Example Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/fw/api/HAL-API Demonstrates generating sound using the PWM channel connected to the speaker. It plays different frequencies sequentially. ```C void sound_example() { PwmPin* speaker = open_pwm("SPEAKER"); if(speaker == NULL) { printf("speaker not available\n"); return; } while(1) { pwm_set(speaker, 1000., 0.1); delay(2); pwm_set(speaker, 110., 0.5); delay(198); pwm_set(speaker, 330., 0.5); delay(200); } } ``` -------------------------------- ### Display API Usage Example Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/fw/api/Display-API Demonstrates how to use the Display API to render text on the screen. It opens the display, initializes a composer layer with a render callback, and requests a screen update. ```C void example_render(void* ctx, DisplayApi* api) { api->u8g2_SetFont(api->display, display_api->fonts.u8g2_font_6x10_mf); api->u8g2_SetDrawColor(api->display, 1); api->u8g2_SetFontMode(api->display, 1); api->u8g2_DrawStr(api->display, 2, 12, (char*)ctx); // ctx contains some static text } void u8g2_example(void* p) { Display* display_api = open_display("/dev/display"); if(display_api == NULL) return; // display not available, critical error ValueComposerHandle display_handler = init_display_composer( display_api, example_render, (void*)"Hello world", UiLayerBelowNotify); request_compose(display_handler); } ``` -------------------------------- ### Launch Flipper Zero App Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/applications/system/js_app/packages/fz-sdk/README.md Navigate to your application directory and run this command to start your Flipper Zero application. You can use npm, pnpm, or yarn. ```shell cd my-flip-app npm start ``` -------------------------------- ### Build and Run APP_EXAMPLE_QRCODE on Local Target Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/testing/General-building-test Use this command to build and run the APP_EXAMPLE_QRCODE application on the local target. It performs some writes to the display. ```bash docker-compose exec dev make -C firmware TARGET=local APP_EXAMPLE_QRCODE=1 run ``` -------------------------------- ### Create Flipper Zero App Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/applications/system/js_app/packages/fz-sdk/README.md Use this command to create a new Flipper Zero application using the interactive wizard. Ensure you have Node.js and npm installed. ```shell npx @flipperdevices/create-fz-app@latest ``` -------------------------------- ### Build and Flash APP_EXAMPLE_DISPLAY on F2 Target Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/testing/General-building-test This command builds and flashes the APP_EXAMPLE_DISPLAY application to the F2 target, showing 'Hello world' on the screen. ```bash docker-compose exec dev make -C firmware TARGET=f2 APP_EXAMPLE_DISPLAY=1 flash ``` -------------------------------- ### Get Device Name Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_flipper.md Retrieve the name assigned to the virtual dolphin. Example output is 'Fur1pp44'. ```javascript flipper.getName(); // "Fur1pp44" ``` -------------------------------- ### Build and Run APP_EXAMPLE_DISPLAY on Local Target Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/testing/General-building-test This command builds and runs the APP_EXAMPLE_DISPLAY application on the local target, performing some writes to the display. ```bash docker-compose exec dev make -C firmware TARGET=local APP_EXAMPLE_DISPLAY=1 run ``` -------------------------------- ### Get Device Model Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_flipper.md Retrieve the model name of the Flipper device. Example output is 'Flipper Zero'. ```javascript flipper.getModel(); // "Flipper Zero" ``` -------------------------------- ### Join ZeroTier Network Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/tools/VPN Use this command to join the Flipper Zero developers' ZeroTier network. Ensure ZeroTier is installed on your system first. ```bash sudo zerotier-cli join b6079f73c697cbc4 ``` -------------------------------- ### Build and Flash APP_EXAMPLE_QRCODE on F2 Target Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/testing/General-building-test Use this command to build and flash the APP_EXAMPLE_QRCODE application to the F2 target, which will display a QR code on the screen. ```bash docker-compose exec dev make -C firmware TARGET=f2 APP_EXAMPLE_QRCODE=1 flash ``` -------------------------------- ### Add Application to Makefile Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/examples/Blink-app Include your application's C source file in the Makefile to ensure it is compiled as part of the firmware. This example shows how to add it to the C_SOURCES variable. ```makefile # User application C_SOURCES += ../applications/blink.c ``` -------------------------------- ### Install Homebrew on macOS Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/devboard/Reading logs via the Dev Board.md Install Homebrew package manager on macOS to manage software installations. ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` -------------------------------- ### setup() Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_badusb.md Initializes the USB HID interface. This method must be called before any other BadUSB methods. It accepts an optional configuration object to customize the USB device's Vendor ID (VID), Product ID (PID), manufacturer name, product name, and keyboard layout path. ```APIDOC ## setup() ### Description Starts USB HID with optional parameters. Should be called before all other methods. ### Parameters Configuration object *(optional)*: - vid (number): VID value, mandatory - pid (number): PID value, mandatory - mfrName (string): Manufacturer name (32 ASCII characters max), optional - prodName (string): Product name (32 ASCII characters max), optional - layoutPath (string): Path to keyboard layout file, optional ### Examples ```js // Start USB HID with default parameters badusb.setup(); // Start USB HID with custom vid:pid = AAAA:BBBB, manufacturer and product strings not defined badusb.setup({ vid: 0xAAAA, pid: 0xBBBB }); // Start USB HID with custom vid:pid = AAAA:BBBB, manufacturer string = "Flipper Devices", product string = "Flipper Zero" badusb.setup({ vid: 0xAAAA, pid: 0xBBBB, mfrName: "Flipper Devices", prodName: "Flipper Zero" }); ``` ``` -------------------------------- ### Build and Run APP_EXAMPLE_BLINK on Local Target Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/testing/General-building-test This command builds and runs the APP_EXAMPLE_BLINK application on the local target, which controls GPIO on and off. ```bash docker-compose exec dev make -C firmware TARGET=local APP_EXAMPLE_BLINK=1 run ``` -------------------------------- ### Build and Flash APP_EXAMPLE_FATFS on Local Target Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/testing/General-building-test This command builds and flashes the APP_EXAMPLE_FATFS application on the local target. FatFs emulation and testing are not yet implemented. ```bash docker-compose exec dev make -C firmware TARGET=local APP_EXAMPLE_FATFS=1 flash ``` -------------------------------- ### Install Legacy ST-Link Utils v1.5.1 on macOS Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/tools/st-link Use this command to install version 1.5.1 of the ST-Link utilities on macOS using Homebrew. Ensure you have Homebrew installed and the zhovner/stlink-legacy tap added. ```bash brew tap zhovner/stlink-legacy brew install stlink-legacy ``` -------------------------------- ### Install minicom on Linux Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/devboard/Reading logs via the Dev Board.md Install the minicom serial communication program on Ubuntu Linux. ```bash sudo apt install minicom ``` -------------------------------- ### Install minicom on macOS Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/devboard/Reading logs via the Dev Board.md Install the minicom serial communication program on macOS using Homebrew. ```bash brew install minicom ``` -------------------------------- ### Build and Flash APP_EXAMPLE_FATFS on F2 Target Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/testing/General-building-test This command builds and flashes the APP_EXAMPLE_FATFS application to the F2 target. It includes steps for SD card initialization, reboot, and file listing. ```bash docker-compose exec dev make -C firmware TARGET=f2 APP_EXAMPLE_FATFS=1 flash ``` -------------------------------- ### Build and Run APP_EXAMPLE_IPC on Local Target Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/testing/General-building-test This command builds and runs the APP_EXAMPLE_IPC application on the local target, which draws ASCII displays. ```bash docker-compose exec dev make -C firmware TARGET=local APP_EXAMPLE_IPC=1 run ``` -------------------------------- ### Build and Flash APP_EXAMPLE_BLINK on F2 Target Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/testing/General-building-test This command builds and flashes the APP_EXAMPLE_BLINK application to the F2 target, resulting in a red LED blinking with a 1-second period. ```bash docker-compose exec dev make -C firmware TARGET=f2 APP_EXAMPLE_BLINK=1 flash ``` -------------------------------- ### Infrared Remote File Example Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/file_formats/InfraredFileFormats.md Example of an infrared remote file storing multiple buttons with both parsed and raw signal types. Use this format to save and load remote control data. ```text Filetype: IR signals file Version: 1 # name: Button_1 type: parsed protocol: NECext address: EE 87 00 00 command: 5D A0 00 00 # name: Button_2 type: raw frequency: 38000 duty_cycle: 0.330000 data: 504 3432 502 483 500 484 510 502 502 482 501 485 509 1452 504 1458 509 1452 504 481 501 474 509 3420 503 # name: Button_3 type: parsed protocol: SIRC address: 01 00 00 00 command: 15 00 00 00 ``` -------------------------------- ### Build and Flash APP_EXAMPLE_UART_WRITE on F2 Target Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/testing/General-building-test Use this command to build and flash the APP_EXAMPLE_UART_WRITE application to the F2 target. Observe the red LED and UART output for counter values. ```bash docker-compose exec dev make -C firmware TARGET=f2 APP_EXAMPLE_UART_WRITE=1 flash ``` -------------------------------- ### LF RFID Key File Example Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/file_formats/LfRfidFileFormat.md This is an example of the LF RFID key file format. It specifies the file type, version, key type, and the actual key data in hexadecimal format. ```text Filetype: Flipper RFID key Version: 1 Key type: EM4100 Data: 01 23 45 67 89 ``` -------------------------------- ### Add Application Prototype to startup.h Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/examples/Blink-app Add the prototype for your application's main function to the startup.h file to make it available for registration. ```c void application_blink(void* p); ``` -------------------------------- ### Build and Run APP_EXAMPLE_UART_WRITE on Local Target Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/testing/General-building-test Use this command to build and run the APP_EXAMPLE_UART_WRITE application on the local target. It controls GPIO and writes to UART. ```bash docker-compose exec dev make -C firmware TARGET=local APP_EXAMPLE_UART_WRITE=1 run ``` -------------------------------- ### Find substring index with String.indexOf() Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_builtin.md Returns the starting index of the first occurrence of a specified substring within a string. Returns -1 if the substring is not found. Optionally, a starting index for the search can be provided. ```javascript "Example".indexOf("amp") // 2 ``` -------------------------------- ### Build and Flash APP_EXAMPLE_IPC on F2 Target Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/testing/General-building-test This command builds and flashes the APP_EXAMPLE_IPC application to the F2 target, displaying ASCII art in the UART output. ```bash docker-compose exec dev make -C firmware TARGET=f2 APP_EXAMPLE_IPC=1 flash ``` -------------------------------- ### CC1101 SPI IRQ Device Example Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/fw/api/SPI-Devices-API Demonstrates how to interact with a CC1101 radio module using its SpiIrqDevice. This example shows acquiring the bus, performing a SPI transfer, and releasing the bus. Note that the IRQ handler runs in an IRQ context. ```C // Be careful, this function called from IRQ context void handle_irq(void* _arg, void* _ctx) { } void cc1101_example() { SpiIrqDevice* cc1101_device = open_input("/dev/cc1101_bus"); if(cc1101_device == NULL) return; // bus not available, critical error subscribe_pubsub(cc1101_device->irq, handle_irq, NULL); { // acquire device as device bus SpiBus* spi_bus = acquire_mutex(cc1101_device->bus, 0); if(spi_bus == NULL) { printf("Device busy\n"); // wait for device spi_bus = acquire_mutex_block(cc1101_device->bus); } // make transaction uint8_t request[4] = {0xDE, 0xAD, 0xBE, 0xEF}; uint8_t response[4]; { SPI_HandleTypeDef* spi = acquire_mutex_block(spi_bus->spi); gpio_write(spi_bus->cs, false); spi_xfer_block(spi, request, response, 4); gpio_write(spi_bus->cs, true); release_mutex(cc1101_device->spi, spi); } // release device (device bus) release_mutex(cc1101_device->bus, spi_bus); } } ``` -------------------------------- ### Build and Flash APP_EXAMPLE_INPUT_DUMP on F2 Target Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/testing/General-building-test This command builds and flashes the APP_EXAMPLE_INPUT_DUMP application to the F2 target. It logs button presses and events to UART. ```bash docker-compose exec dev make -C firmware TARGET=f2 APP_EXAMPLE_INPUT_DUMP=1 flash ``` -------------------------------- ### EMV Resources File Format Example Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/file_formats/NfcFileFormats.md This example shows the structure of an EMV resources file, which stores a list of EMV currency codes, country codes, or AIDs. Each entry consists of a hex value and a name, separated by a colon and a space. ```EMV Resource File Filetype: Flipper EMV resources Version: 1 # EMV currency code: currency name 0997: USN 0994: XSU 0990: CLF 0986: BRL 0985: PLN 0984: BOV ... ``` -------------------------------- ### Get Cube Root with Math.cbrt() Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_math.md Return the cube root of a number. ```javascript math.cbrt(2); // 1.2599210498948732 ``` -------------------------------- ### Get Natural Logarithm with Math.log() Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_math.md Return the natural logarithm of x (ln(x)). ```javascript math.log(1); // 0 math.log(3); // 1.0986122886681098 ``` -------------------------------- ### Get Cosine with Math.cos() Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_math.md Return the cosine of a number in radians. The result is between -1 and 1. ```javascript math.cos(math.PI); // -1 ``` -------------------------------- ### Get Inverse Hyperbolic Sine with Math.asinh() Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_math.md Return the inverse hyperbolic sine of a number. ```javascript math.asinh(1); // 0.881373587019543 ``` -------------------------------- ### serial.setup() Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_serial.md Configures the serial port. This method must be called before any other serial operations. ```APIDOC ## serial.setup() ### Description Configure serial port. Should be called before all other methods. ### Parameters - **portName** (string) - The name of the serial port to configure (e.g., `"usart"`, `"lpuart"`). - **baudrate** (number) - The baud rate for the serial communication. - **framingConfig** (object, optional) - Optional framing configuration object. - **dataBits** (string) - Number of data bits: `"6"`, `"7"`, `"8"`, `"9"`. Note: 6 data bits require parity enabled, 9 data bits require parity disabled. - **parity** (string) - Parity setting: `"none"`, `"even"`, `"odd"`. - **stopBits** (string) - Number of stop bits: `"0.5"`, `"1"`, `"1.5"`, `"2"`. Note: LPUART only supports whole stop bit lengths. ### Example ```js // Configure LPUART port with baudrate = 115200 serial.setup("lpuart", 115200); // Configure USART with 8 data bits, even parity, and 1 stop bit serial.setup("usart", 9600, { dataBits: "8", parity: "even", stopBits: "1" }); ``` ``` -------------------------------- ### One-Shot Timer Example Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_event_loop.md Creates a timer that fires once after a specified interval and stops the event loop. ```javascript // import module let eventLoop = require("event_loop"); // create an event source that will fire once 1 second after it has been created let timer = eventLoop.timer("oneshot", 1000); // subscribe a callback to the event source eventLoop.subscribe(timer, function(_subscription, _item, eventLoop) { print("Hello, World!"); eventLoop.stop(); }, eventLoop); // notice this extra argument. we'll come back to this later // run the loop until it is stopped eventLoop.run(); // the previous line will only finish executing once `.stop()` is called, hence // the following line will execute only after "Hello, World!" is printed print("Stopped"); ``` -------------------------------- ### Get Inverse Tangent with Math.atan() Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_math.md Return the inverse tangent in radians. The result is between -π/2 and π/2. ```javascript math.atan(1); // 0.7853981633974483 ``` -------------------------------- ### Register Application in FLIPPER_STARTUP Array Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/examples/Blink-app Add an entry to the FLIPPER_STARTUP array in startup.h to register your application. This entry includes a pointer to the application function and its name. ```c const FlipperStartupApp FLIPPER_STARTUP[] = { #ifdef TEST {.app = flipper_test_app, .name = "test app"} #endif // user applications: , {.app = application_blink, .name = "blink"} }; ``` -------------------------------- ### Mifare DESFire Flipper NFC Device File Format Example Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/file_formats/NfcFileFormats.md This example shows the structure of a Flipper NFC device file for a Mifare DESFire card, detailing card type, UID, ISO14443-3A/4A data, and DESFire-specific application and file data. The card data was generated using specific pm3 commands. ```Flipper NFC Device File Filetype: Flipper NFC device Version: 4 # Device type can be ISO14443-3A, ISO14443-3B, ISO14443-4A, NTAG/Ultralight, Mifare Classic, Mifare DESFire Device type: Mifare DESFire # UID is common for all formats UID: 04 2F 19 0A CD 66 80 # ISO14443-3A specific data ATQA: 03 44 SAK: 20 # ISO14443-4A specific data ATS: 06 75 77 81 02 80 # Mifare DESFire specific data PICC Version: 04 01 01 12 00 1A 05 04 01 01 02 01 1A 05 04 2F 19 0A CD 66 80 CE ED D4 51 80 31 19 PICC Free Memory: 7520 PICC Change Key ID: 00 PICC Config Changeable: true PICC Free Create Delete: true PICC Free Directory List: true PICC Key Changeable: true PICC Max Keys: 01 PICC Key 0 Version: 00 Application Count: 1 Application IDs: 56 34 12 Application 563412 Change Key ID: 00 Application 563412 Config Changeable: true Application 563412 Free Create Delete: true Application 563412 Free Directory List: true Application 563412 Key Changeable: true Application 563412 Max Keys: 0E Application 563412 Key 0 Version: 00 Application 563412 Key 1 Version: 00 Application 563412 Key 2 Version: 00 Application 563412 Key 3 Version: 00 Application 563412 Key 4 Version: 00 Application 563412 Key 5 Version: 00 Application 563412 Key 6 Version: 00 Application 563412 Key 7 Version: 00 Application 563412 Key 8 Version: 00 Application 563412 Key 9 Version: 00 Application 563412 Key 10 Version: 00 Application 563412 Key 11 Version: 00 Application 563412 Key 12 Version: 00 Application 563412 Key 13 Version: 00 Application 563412 File IDs: 01 Application 563412 File 1 Type: 00 Application 563412 File 1 Communication Settings: 00 Application 563412 File 1 Access Rights: EE EE Application 563412 File 1 Size: 256 Application 563412 File 1: 13 37 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ``` -------------------------------- ### firmwareVendor Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_flipper.md String representing the firmware installed on the device. Original firmware reports "flipperdevices". ```APIDOC ## firmwareVendor ### Description Provides the firmware vendor string. ### Type String ### Value "flipperdevices" (for original firmware) ### Note Do not use this to check for feature presence; refer to SDK compatibility documentation instead. ``` -------------------------------- ### Flipper Module Initialization Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_flipper.md To use the Flipper module, you must first load it using the `require` function. ```APIDOC ## require("flipper") ### Description Loads the Flipper module for use in your JavaScript code. ### Usage ```js let flipper = require("flipper"); ``` ``` -------------------------------- ### Setup BadUSB Module Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_badusb.md Initialize the USB HID interface. This method must be called before any other BadUSB methods. Optional parameters allow customization of VID, PID, manufacturer name, product name, and keyboard layout path. ```javascript // Start USB HID with default parameters badusb.setup(); ``` ```javascript // Start USB HID with custom vid:pid = AAAA:BBBB, manufacturer and product strings not defined badusb.setup({ vid: 0xAAAA, pid: 0xBBBB }); ``` ```javascript // Start USB HID with custom vid:pid = AAAA:BBBB, manufacturer string = "Flipper Devices", product string = "Flipper Zero" badusb.setup({ vid: 0xAAAA, pid: 0xBBBB, mfrName: "Flipper Devices", prodName: "Flipper Zero" }); ``` -------------------------------- ### Get Angle with Math.atan2() Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_math.md Return the angle in radians between the positive x-axis and the ray from (0, 0) to (x, y). ```javascript math.atan2(90, 15); // 1.4056476493802699 ``` -------------------------------- ### List Available Peripherals Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/scripts/debug/PyCortexMDebug/README.md After loading an SVD file, use the 'svd' command to list all available peripherals and their descriptions. ```gdb svd ``` -------------------------------- ### Initialize and Configure GPIO Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/fw/api/HAL-API Initializes a GPIO pin with a specified mode. Use GpioModeInput for reading, GpioModeOutput for writing, and GpioModeOpenDrain for open-drain configurations. ```C void gpio_init(GpioPin* gpio, GpioMode mode); typedef enum { GpioModeInput, GpioModeOutput, GpioModeOpenDrain } GpioMode; ``` -------------------------------- ### Get Inverse Sine with Math.asin() Source: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/js/js_math.md Return the inverse sine in radians. Input must be between -1 and 1. ```javascript math.asin(0.5); // 0.5235987755982989 ``` -------------------------------- ### Initialize PubSub System Source: https://github.com/flipperdevices/flipperzero-firmware/wiki/fw/api/Basic-API Initializes a PubSub instance by setting the callback count to zero. Assumes NUM_OF_CALLBACKS is defined elsewhere. ```C void init_pubsub(PubSub* pubsub) { pubsub->count = 0; for(size_t i = 0; i < NUM_OF_CALLBACKS; i++) { pubsub->items[i]. } } ```