Skip to content

Commit c245ee9

Browse files
committed
move and cli bridge
0 parents  commit c245ee9

33 files changed

+2389
-0
lines changed

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# flipperzero-gpioreader
2+
3+
![image info](./gpioreader.png)
4+
5+
This is a fork of the `gpio` app built into the flipper, with added functionality to read GPIO inputs.
6+
7+
Supports pulling high or low.
8+
9+
Does not (yet) support analog reads.
10+
11+
Installation instructions (Linux):
12+
13+
- Clone the following repo: https://github.com/flipperdevices/flipperzero-firmware
14+
- Clone this repo into flipperzero-firmware/applications_user
15+
- Plug in your FlipperZero
16+
- Run `./fbt launch_app APPSRC=flipperzero-gpioreader` from within the flipperzero-firmware folder

application.fam

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
App(
2+
appid="gpioreader2",
3+
name="[GPIO] Input Reader 2",
4+
apptype=FlipperAppType.EXTERNAL,
5+
entry_point="gpio_app",
6+
requires=["gui"],
7+
stack_size=1 * 1024,
8+
order=50,
9+
fap_category="GPIO",
10+
fap_icon="icon.png",
11+
fap_icon_assets="icons",
12+
)

gpio_app.c

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#include "gpio_app_i.h"
2+
3+
#include <furi.h>
4+
#include <furi_hal.h>
5+
6+
static bool gpio_app_custom_event_callback(void* context, uint32_t event) {
7+
furi_assert(context);
8+
GpioApp* app = context;
9+
return scene_manager_handle_custom_event(app->scene_manager, event);
10+
}
11+
12+
static bool gpio_app_back_event_callback(void* context) {
13+
furi_assert(context);
14+
GpioApp* app = context;
15+
return scene_manager_handle_back_event(app->scene_manager);
16+
}
17+
18+
static void gpio_app_tick_event_callback(void* context) {
19+
furi_assert(context);
20+
GpioApp* app = context;
21+
scene_manager_handle_tick_event(app->scene_manager);
22+
}
23+
24+
GpioApp* gpio_app_alloc() {
25+
GpioApp* app = malloc(sizeof(GpioApp));
26+
27+
app->gui = furi_record_open(RECORD_GUI);
28+
29+
app->view_dispatcher = view_dispatcher_alloc();
30+
app->scene_manager = scene_manager_alloc(&gpio_scene_handlers, app);
31+
view_dispatcher_enable_queue(app->view_dispatcher);
32+
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
33+
34+
view_dispatcher_set_custom_event_callback(
35+
app->view_dispatcher, gpio_app_custom_event_callback);
36+
view_dispatcher_set_navigation_event_callback(
37+
app->view_dispatcher, gpio_app_back_event_callback);
38+
view_dispatcher_set_tick_event_callback(
39+
app->view_dispatcher, gpio_app_tick_event_callback, 100);
40+
41+
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
42+
43+
app->notifications = furi_record_open(RECORD_NOTIFICATION);
44+
45+
app->var_item_list = variable_item_list_alloc();
46+
view_dispatcher_add_view(
47+
app->view_dispatcher,
48+
GpioAppViewVarItemList,
49+
variable_item_list_get_view(app->var_item_list));
50+
app->gpio_test = gpio_test_alloc();
51+
view_dispatcher_add_view(
52+
app->view_dispatcher, GpioAppViewGpioTest, gpio_test_get_view(app->gpio_test));
53+
app->gpio_reader = gpio_reader_alloc();
54+
view_dispatcher_add_view(
55+
app->view_dispatcher, GpioAppViewGpioReader, gpio_reader_get_view(app->gpio_reader));
56+
57+
app->widget = widget_alloc();
58+
view_dispatcher_add_view(
59+
app->view_dispatcher, GpioAppViewUsbUartCloseRpc, widget_get_view(app->widget));
60+
61+
app->gpio_usb_uart = gpio_usb_uart_alloc();
62+
view_dispatcher_add_view(
63+
app->view_dispatcher, GpioAppViewUsbUart, gpio_usb_uart_get_view(app->gpio_usb_uart));
64+
65+
view_dispatcher_add_view(
66+
app->view_dispatcher,
67+
GpioAppViewUsbUartCfg,
68+
variable_item_list_get_view(app->var_item_list));
69+
70+
scene_manager_next_scene(app->scene_manager, GpioSceneStart);
71+
72+
return app;
73+
}
74+
75+
void gpio_app_free(GpioApp* app) {
76+
furi_assert(app);
77+
78+
// Views
79+
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewVarItemList);
80+
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewGpioTest);
81+
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewGpioReader);
82+
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewUsbUart);
83+
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewUsbUartCfg);
84+
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewUsbUartCloseRpc);
85+
variable_item_list_free(app->var_item_list);
86+
widget_free(app->widget);
87+
gpio_test_free(app->gpio_test);
88+
gpio_reader_free(app->gpio_reader);
89+
gpio_usb_uart_free(app->gpio_usb_uart);
90+
91+
// View dispatcher
92+
view_dispatcher_free(app->view_dispatcher);
93+
scene_manager_free(app->scene_manager);
94+
95+
// Close records
96+
furi_record_close(RECORD_GUI);
97+
furi_record_close(RECORD_NOTIFICATION);
98+
99+
free(app);
100+
}
101+
102+
int32_t gpio_app(void* p) {
103+
UNUSED(p);
104+
GpioApp* gpio_app = gpio_app_alloc();
105+
106+
view_dispatcher_run(gpio_app->view_dispatcher);
107+
108+
gpio_app_free(gpio_app);
109+
110+
return 0;
111+
}

gpio_app.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
typedef struct GpioApp GpioApp;
8+
9+
#ifdef __cplusplus
10+
}
11+
#endif

gpio_app_i.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#pragma once
2+
3+
#include "gpio_app.h"
4+
#include "gpio_item.h"
5+
#include "scenes/gpio_scene.h"
6+
#include "gpio_custom_event.h"
7+
#include "usb_uart_bridge.h"
8+
9+
#include <gui/gui.h>
10+
#include <gui/view_dispatcher.h>
11+
#include <gui/scene_manager.h>
12+
#include <gui/modules/submenu.h>
13+
#include <notification/notification_messages.h>
14+
#include <gui/modules/variable_item_list.h>
15+
#include <gui/modules/widget.h>
16+
#include "views/gpio_test.h"
17+
#include "views/gpio_reader.h"
18+
#include "views/gpio_usb_uart.h"
19+
#include <gpioreader2_icons.h>
20+
21+
struct GpioApp {
22+
Gui* gui;
23+
NotificationApp* notifications;
24+
ViewDispatcher* view_dispatcher;
25+
SceneManager* scene_manager;
26+
Widget* widget;
27+
28+
VariableItemList* var_item_list;
29+
VariableItem* var_item_flow;
30+
GpioTest* gpio_test;
31+
GpioReader* gpio_reader;
32+
GpioUsbUart* gpio_usb_uart;
33+
UsbUartBridge* usb_uart_bridge;
34+
UsbUartConfig* usb_uart_cfg;
35+
};
36+
37+
typedef enum {
38+
GpioAppViewVarItemList,
39+
GpioAppViewGpioTest,
40+
GpioAppViewGpioReader,
41+
GpioAppViewUsbUart,
42+
GpioAppViewUsbUartCfg,
43+
GpioAppViewUsbUartCloseRpc,
44+
} GpioAppView;

gpio_custom_event.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
typedef enum {
4+
GpioStartEventOtgOff = 0,
5+
GpioStartEventOtgOn,
6+
GpioStartEventManualControl,
7+
GpioStartEventReader,
8+
GpioStartEventUsbUart,
9+
10+
GpioCustomEventErrorBack,
11+
12+
GpioUsbUartEventConfig,
13+
GpioUsbUartEventConfigSet,
14+
} GpioCustomEvent;

gpio_item.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include "gpio_item.h"
2+
3+
#include <furi_hal_resources.h>
4+
5+
typedef struct {
6+
const char* name;
7+
const GpioPin* pin;
8+
} GpioItem;
9+
10+
static const GpioItem gpio_item[GPIO_ITEM_COUNT] = {
11+
{"1.2: PA7", &gpio_ext_pa7},
12+
{"1.3: PA6", &gpio_ext_pa6},
13+
{"1.4: PA4", &gpio_ext_pa4},
14+
{"1.5: PB3", &gpio_ext_pb3},
15+
{"1.6: PB2", &gpio_ext_pb2},
16+
{"1.7: PC3", &gpio_ext_pc3},
17+
{"2.7: PC1", &gpio_ext_pc1},
18+
{"2.8: PC0", &gpio_ext_pc0},
19+
};
20+
21+
void gpio_item_configure_pin(uint8_t index, GpioMode mode, GpioPull pull) {
22+
furi_assert(index < GPIO_ITEM_COUNT);
23+
furi_hal_gpio_write(gpio_item[index].pin, false);
24+
furi_hal_gpio_init(gpio_item[index].pin, mode, pull, GpioSpeedVeryHigh);
25+
}
26+
27+
void gpio_item_configure_all_pins(GpioMode mode) {
28+
GpioPull pull = GpioPullNo;
29+
if(mode == GpioModeInput) {
30+
pull = GpioPullDown;
31+
}
32+
for(uint8_t i = 0; i < GPIO_ITEM_COUNT; i++) {
33+
gpio_item_configure_pin(i, mode, pull);
34+
}
35+
}
36+
37+
void gpio_item_set_pin(uint8_t index, bool level) {
38+
furi_assert(index < GPIO_ITEM_COUNT);
39+
furi_hal_gpio_write(gpio_item[index].pin, level);
40+
}
41+
42+
bool gpio_item_get_pin(uint8_t index) {
43+
furi_assert(index < GPIO_ITEM_COUNT);
44+
return furi_hal_gpio_read(gpio_item[index].pin);
45+
}
46+
47+
void gpio_item_set_all_pins(bool level) {
48+
for(uint8_t i = 0; i < GPIO_ITEM_COUNT; i++) {
49+
gpio_item_set_pin(i, level);
50+
}
51+
}
52+
53+
const char* gpio_item_get_pin_name(uint8_t index) {
54+
furi_assert(index < GPIO_ITEM_COUNT + 1);
55+
if(index == GPIO_ITEM_COUNT) {
56+
return "ALL";
57+
} else {
58+
return gpio_item[index].name;
59+
}
60+
}

gpio_item.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include <furi_hal_gpio.h>
4+
5+
#define GPIO_ITEM_COUNT 8
6+
7+
void gpio_item_configure_pin(uint8_t index, GpioMode mode, GpioPull pull);
8+
9+
void gpio_item_configure_all_pins(GpioMode mode);
10+
11+
void gpio_item_set_pin(uint8_t index, bool level);
12+
13+
void gpio_item_set_all_pins(bool level);
14+
15+
const char* gpio_item_get_pin_name(uint8_t index);
16+
17+
bool gpio_item_get_pin(uint8_t index);

gpioreader.png

1.87 KB
Loading

0 commit comments

Comments
 (0)