2.5 KiB
First, let's create a simple led blinking application.
Preparing for launch
We will use integrated LED. Look at the schematic:
This led connect between power rail and GPIO PA8 and we should configure this pin as open drain to properly control led behaviour.
You can find GPIO API in target_*/flipper_hal.h. Or if you prefer to use Arduino API, you can find bindings in core/flipper.h.
For work with pin we should:
- Create
GpioPininstance and specify pin and port. - Configure mode of pin by
pinModefunction. - Control state of pin by
digitalWritefunction.
Creating application
- Create new file (for example,
blink.c) inapplicationsfolder. - Create code like this:
#include "flipper.h"
void application_blink(void* p) {
// create pin
GpioPin led = {.pin = GPIO_PIN_8, .port = GPIOA};
// configure pin
pinMode(led, GpioModeOutput);
while(1) {
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
}
}
-
To start your application on Flipper startup, add it to autorun:
- in
applications/startup.hadd prototype of main application function:
void application_blink(void* p);- add entry to
FLIPPER_STARTUParray (pointer to application function and application name):
const FlipperStartupApp FLIPPER_STARTUP[] = { #ifdef TEST {.app = flipper_test_app, .name = "test app"} #endif // user applications: , {.app = application_blink, .name = "blink"} }; - in
-
Add your application file to Makefile (for each target,
target_lo/Makefileandtarget_f1/Makefile, we add one common makefile later):
# User application
C_SOURCES += ../applications/blink.c
Build and run for linux (target_lo):
docker-compose exec dev make -C target_lo
Run:
docker-compose exec dev target_lo/build/target_lo.
Linux version has no LED or GPIO, but we can see debug messages how state of GPIO is changing:
You also run found source of this example in applications/examples/blink.c and run by docker-compose exec dev make -C target_lo example_blink


