This is a demostration of using GPIO interrupts to interpret data from the Memsic 2125 (Mx2125) Dual-Axis Accelerometer.
This project is intended to be overlayed on top of an existing firmware repo.
The Memsic Mx2125 is a 6-pin IC. From the top view the pins look like the following:
The pins should be connected to the Flipper Zero as follows:
| Memsic | Name | Purpose | Flipper |
|---|---|---|---|
| Pin 1 | Tout | Temperature Out | not connected |
| Pin 2 | Yout | Y-axis PWM Out (100Hz, duty cycle = value) | C0 |
| Pin 3 | GND | Ground | GND |
| Pin 4 | GND | Ground | GND |
| Pin 5 | Xout | X-axis PWM Out (100Hz, duty cycle = value) | C1 |
| Pin 6 | Vdd | Drain voltage (3.3V to 5V DC) | 3v3 |
These directions assume you are starting at the flipper desktop. If not, please press the back button until you are at the desktop.
Choose "Memsic 2125"
The flipper should say "Memsic 2125 C1:X C0:Y". This is a reminder that the X-Axis (pin 5) connects to pin C1 and Y-Axis (pin 2) connects to pin C0.
A circle should show in the middle of the screen when the Mx2125 is on a level surface.
Tilting along the X and Y axis should move the circle.
The values at the bottom of the screen show the X and Y duty cycle amounts.
Press the BACK button to exit.
application.fam
basic_demo.png
basic_demo_app.c
GPIO specific:
AxisData is a structure to hold information about an axis.
DemoData has two AxisData references (for x-axis data and y-axis data.)
Our entry point initializes xData with the c1 pin & yData with the c0 pin.
furi_hal_gpio_init(xData->pin, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedVeryHigh) initializes an interrupt to happen on the Rise or Fall of the c1 pin. We don't need a pull-up since the pin will be set to GND or 3.3V by the Mx2125.
furi_hal_gpio_add_int_callback(xData->pin, pulse_callback, xData) sets the callback routine to pulse_callback and will pass our xData whenever the pin changes state.
We do the same process as the xData for the yData using the c0 pin.
pulse_callback(void *) is our GPIO interrupt callback.
When exiting we remove the callback routine using furi_hal_gpio_remove_int_callback.
In our render_callback(Canvas, void) we render the UI