From 6e06cd455012b82130b78a1d67bcb98a42a4824b Mon Sep 17 00:00:00 2001 From: Derek Jamison Date: Thu, 10 Aug 2023 12:34:49 -0700 Subject: [PATCH] GPIO Badge v1.0 --- gpio/gpio_badge/README.md | 6 +++ gpio/gpio_badge/application.fam | 10 ++++ gpio/gpio_badge/gpio_badge.c | 89 ++++++++++++++++++++++++++++++++ gpio/gpio_badge/gpio_badge.png | Bin 0 -> 1822 bytes 4 files changed, 105 insertions(+) create mode 100644 gpio/gpio_badge/README.md create mode 100644 gpio/gpio_badge/application.fam create mode 100644 gpio/gpio_badge/gpio_badge.c create mode 100644 gpio/gpio_badge/gpio_badge.png diff --git a/gpio/gpio_badge/README.md b/gpio/gpio_badge/README.md new file mode 100644 index 0000000..20b40df --- /dev/null +++ b/gpio/gpio_badge/README.md @@ -0,0 +1,6 @@ +#gpio_badge +This is an app for the [GPIO Diagnostics Card](https://tindie.com/stores/MakeItHackin) by MakeItHackin. + +## Instructions +Left/Right buttons to change speed. +Back button to exit. \ No newline at end of file diff --git a/gpio/gpio_badge/application.fam b/gpio/gpio_badge/application.fam new file mode 100644 index 0000000..c47a677 --- /dev/null +++ b/gpio/gpio_badge/application.fam @@ -0,0 +1,10 @@ +App( + appid="gpio_badge", + name="GPIO Badge", + apptype=FlipperAppType.EXTERNAL, + entry_point="gpio_diag_lights_app", + requires=["gui", "subghz"], + stack_size=2 * 1024, + fap_icon="gpio_badge.png", + fap_category="Utilities", +) diff --git a/gpio/gpio_badge/gpio_badge.c b/gpio/gpio_badge/gpio_badge.c new file mode 100644 index 0000000..dcba303 --- /dev/null +++ b/gpio/gpio_badge/gpio_badge.c @@ -0,0 +1,89 @@ +#include +#include + +const GpioPin* const pin_leds[] = { + &gpio_ext_pa7, + &gpio_ext_pa6, + &gpio_ext_pa4, + &gpio_ext_pb3, + &gpio_ext_pb2, + &gpio_ext_pc3, + &gpio_swclk, + &gpio_swdio, + &gpio_usart_tx, + &gpio_usart_rx, + &gpio_ext_pc1, + &gpio_ext_pc0, + &gpio_ibutton, +}; + +uint32_t speed = 80; + +const GpioPin* const pin_back = &gpio_button_back; + +static void my_draw_callback(Canvas* canvas, void* context) { + UNUSED(context); + canvas_set_font(canvas, FontPrimary); + canvas_draw_str(canvas, 5, 8, "GPIO BADGE"); +} + +static void my_input_callback(InputEvent* event, void* context) { + UNUSED(context); + if(event->type == InputTypePress) { + uint32_t last_speed = speed; + if(event->key == InputKeyLeft) { + speed *= 0.8; + if(speed < 1) { + speed = 1; + } + } else if(event->key == InputKeyRight) { + speed *= 1.2; + if(speed < last_speed + 5) { + speed += 5; + } + } + } +} + +int gpio_diag_lights_app(void* p) { + UNUSED(p); + + Gui* gui = furi_record_open(RECORD_GUI); + ViewPort* view_port = view_port_alloc(); + view_port_draw_callback_set(view_port, my_draw_callback, NULL); + view_port_input_callback_set(view_port, my_input_callback, NULL); + gui_add_view_port(gui, view_port, GuiLayerFullscreen); + + for(size_t i = 0; i < COUNT_OF(pin_leds); i++) { + furi_hal_gpio_init_simple(pin_leds[i], GpioModeOutputPushPull); + } + + int i = 0; + int d = 1; + do { + furi_hal_gpio_write(pin_leds[i], true); + furi_delay_ms(speed); + furi_hal_gpio_write(pin_leds[i], false); + i += d; + if(i == COUNT_OF(pin_leds) || i < 0) { + if(i < 1) + i++; + else + i--; + d = d * -1; + } + + // Hold the back button to exit (since we only scan it when restarting loop). + } while(furi_hal_gpio_read(pin_back)); + + // Typically when a pin is no longer in use, it is set to analog mode. + // but we need to use open drain for the 1Wire pin. + for(size_t i = 0; i < COUNT_OF(pin_leds); i++) { + furi_hal_gpio_init_simple(pin_leds[i], GpioModeAnalog); + } + furi_hal_gpio_init_simple(&gpio_ibutton, GpioModeOutputOpenDrain); + + // Remove the directions from the screen. + gui_remove_view_port(gui, view_port); + return 0; +} \ No newline at end of file diff --git a/gpio/gpio_badge/gpio_badge.png b/gpio/gpio_badge/gpio_badge.png new file mode 100644 index 0000000000000000000000000000000000000000..62a492b79bdb70c128006c929e59a587f2eba110 GIT binary patch literal 1822 zcma)6eM}o=7(a&NGq_CAk-3=5v1Lrw-u3tz7rF{<2UU)BeB&28dT;5Cws+oLY553Y zqqj_;%_hAbHH*BJvjYT4 z7(d)Ro@m$>JFK(VzSu)XN5B5oOip_yZGW@H+nT(8TiDT-v~%B#dIr+IW>48qCVY6O z>a+6m#bt@cci9b96-{qX^}pZTEAaQ)#{axpmv^r%x~RFkHK}Xh(4|$=w?8Rw**~_S zC;NxwAKQ=i9NA&(Xg43y4Syf=@TKzKo;&mVz z!PdR&ya!*YlWUIM?&}c$af5PWRp{ntPuw5mTi*%4*1!9s`gIN5idSDU z;zg(LzG!=)>5Zw^9-rJb;j*2XsHna9yg1VJOy{-x5vz}XRUhe^svaM?vF2(PTQvB~ zvX9-z3T~yT>qCyHDrY`V8d2^g%$!?joSmJ8%c2Vt4e%8y+A2#ri|IDUL}hp=$lw4ngL)ixr$l+Qn2(r(YsHLXs1G7nX|Yn;jOuw2 zpegDUHG#o!6wMG>E0u595(tMoEoPHtfx>aO+pTsdsd=#y*QBSX;{=J5qzWQbQjJq) zJSwLY?pk~~K&71js< z&j%9k5-q@34V-d3hAIW1^t_!H3t$%jEv5@3t|)Te6FQ&Ux>8Xl@tiZVHvN{|bjm9ou$;DWV;V}p!J zB6gQ@<3&ymrcMSZN*5ejERDqHsLTFthj&5Iuv1w^W(}EueSqbk?i)C7^98A9kH7k9KYSbD+ojQkg+W=$;&PkI@5u4_6 z!j}}_>!l?G`0f8sfFHY*fS{r-7Lb7}U+&_nWZ+8`(2ra6#ru-*Tj4l?I~X@No0Q%B zd;?B6)I>PFmNhc5aPna$LuO%IiRJ0Aef##AckNsm!Q^@qsvEmwMj!fl==lDfAxL;X V67Oh#B3v1iCS#tVCu{qzzW{ZFcYgo? literal 0 HcmV?d00001