Skip to content

Building an App

William Stevens edited this page Jul 16, 2018 · 8 revisions

Currently, the console doesn't have the ability to create applications for the device automatically. This functionality is on the way. In the mean time, we will have to create the directory structure of an app ourselves.

An app has a main() function which is called when it is loaded onto a device. An app gives the same functionality to Flipper that a .ino or "Sketch" gives to competing development platforms.

Create an App Directory

First, create a directory to house the files that will be built into an application for the device. We will call the app that we're creating in this example my_app.

mkdir my_app
cd my_app

Create the Directory Structure

Once inside, we need to create the necessary files so that Flipper's build system knows how to build the app. The directory tree for an app is below.

.
├── src
│   └── main.c
└── makefile
mkdir src
touch src/main.c makefile

Populate the Makefile

# This sets the name of the Flipper package being built
MODULE := my_app

# This next line *MUST* come after MODULE has been set
include flipper.mk

Create the Main Function

Next, we need to create the function that will be run when the application is loaded.

src/main.c

#include <flipper.h>

int main(int argc, char *argv[]) {

    led.rgb(0, 0, 10); // Set the LED blue
    gpio.enable(IO_1, 0); // enable IO1
    gpio.write(IO_1, 0); // Turn IO1 on

    return 0;
}

Since Flipper doesn't support command line arguments, the signature of the main function is a bit different than a regular C program. Instead of putting int argc, char *argv[] as the function arguments, we just put void to tell the compiler that the function doesn't accept any arguments.

Build and Install

To build the package, simply

make

To install the package onto the attached hardware

make install

Run

Once the app is installed on the device, it will automatically begin to run. To rerun the application, simply install it again.