From a61eef0f99971bae182a243518f23cb27e08c6a6 Mon Sep 17 00:00:00 2001 From: coreglitch Date: Fri, 13 Nov 2020 01:26:49 +0600 Subject: [PATCH] FL-186 Add vibro demo (#234) * add vibro demo * add F2 support --- applications/applications.h | 5 +++ applications/applications.mk | 8 +++++ applications/examples/vibro.c | 34 +++++++++++++++++++ firmware/targets/f2/Inc/main.h | 3 ++ .../targets/f2/api-hal/api-hal-resources.c | 3 +- .../targets/f2/api-hal/api-hal-resources.h | 3 +- firmware/targets/f3/Inc/main.h | 3 ++ .../targets/f3/api-hal/api-hal-resources.c | 1 + .../targets/f3/api-hal/api-hal-resources.h | 1 + 9 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 applications/examples/vibro.c diff --git a/applications/applications.h b/applications/applications.h index 697f2f9a..673ed461 100644 --- a/applications/applications.h +++ b/applications/applications.h @@ -32,6 +32,7 @@ void lf_rfid_workaround(void* p); void nfc_task(void* p); void irukagotchi_task(void* p); void power_task(void* p); +void application_vibro(void* p); const FlipperStartupApp FLIPPER_STARTUP[] = { #ifdef APP_DISPLAY @@ -138,4 +139,8 @@ const FlipperStartupApp FLIPPER_APPS[] = { #ifdef BUILD_SPEAKER_DEMO {.app = coreglitch_demo_0, .name = "coreglitch_demo_0", .libs = {0}}, #endif + +#ifdef BUILD_VIBRO_DEMO + {.app = application_vibro, .name = "application_vibro", .libs = {1, FURI_LIB{"input_task"}}}, +#endif }; \ No newline at end of file diff --git a/applications/applications.mk b/applications/applications.mk index 5a5f9970..2bd65f9c 100644 --- a/applications/applications.mk +++ b/applications/applications.mk @@ -19,6 +19,7 @@ BUILD_EXAMPLE_INPUT_DUMP = 1 BUILD_CC1101 = 1 BUILD_LF_RFID = 1 BUILD_SPEAKER_DEMO = 1 +BUILD_VIBRO_DEMO = 1 endif APP_NFC ?= 0 @@ -204,6 +205,13 @@ APP_INPUT = 1 APP_GUI = 1 endif +BUILD_VIBRO_DEMO ?= 0 +ifeq ($(BUILD_VIBRO_DEMO), 1) +CFLAGS += -DBUILD_VIBRO_DEMO +C_SOURCES += $(wildcard $(APP_DIR)/examples/vibro.c) +APP_INPUT = 1 +endif + # device drivers APP_GUI ?= 0 diff --git a/applications/examples/vibro.c b/applications/examples/vibro.c new file mode 100644 index 00000000..51b9fae3 --- /dev/null +++ b/applications/examples/vibro.c @@ -0,0 +1,34 @@ +#include "flipper_v2.h" + +typedef struct { + GpioPin* led; + GpioPin* vibro; +} Ctx; + +static void button_handler(const void* value, void* _ctx) { + const InputEvent* event = value; + Ctx* ctx = (Ctx*)_ctx; + + if(event->input == InputOk) { + gpio_write(ctx->vibro, event->state); + gpio_write(ctx->led, !event->state); + } +} + +void application_vibro(void* p) { + Ctx ctx = {.led = (GpioPin*)&led_gpio[1], .vibro = (GpioPin*)&vibro_gpio}; + + gpio_init(ctx.led, GpioModeOutputOpenDrain); + gpio_init(ctx.vibro, GpioModeOutputPushPull); + gpio_write(ctx.led, true); + gpio_write(ctx.vibro, false); + + // subscribe on buttons + PubSub* event_record = furi_open("input_events"); + furi_check(event_record); + subscribe_pubsub(event_record, button_handler, &ctx); + + while(1) { + osDelay(osWaitForever); + } +} \ No newline at end of file diff --git a/firmware/targets/f2/Inc/main.h b/firmware/targets/f2/Inc/main.h index 0e8ffcea..af026f01 100644 --- a/firmware/targets/f2/Inc/main.h +++ b/firmware/targets/f2/Inc/main.h @@ -152,6 +152,9 @@ extern TIM_HandleTypeDef htim15; #define NFC_IRQ_Pin RFID_PULL_Pin #define NFC_IRQ_GPIO_Port RFID_PULL_GPIO_Port +#define VIBRO_Pin GPIO_PIN_6 +#define VIBRO_GPIO_Port GPIOC + /* USER CODE END Private defines */ #ifdef __cplusplus diff --git a/firmware/targets/f2/api-hal/api-hal-resources.c b/firmware/targets/f2/api-hal/api-hal-resources.c index 4c7e4d46..70e4279b 100644 --- a/firmware/targets/f2/api-hal/api-hal-resources.c +++ b/firmware/targets/f2/api-hal/api-hal-resources.c @@ -27,4 +27,5 @@ const GpioPin led_gpio[3] = { {LED_GREEN_GPIO_Port, LED_GREEN_Pin}, {LED_BLUE_GPIO_Port, LED_BLUE_Pin}}; -const GpioPin backlight_gpio = {DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin}; \ No newline at end of file +const GpioPin backlight_gpio = {DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin}; +const GpioPin vibro_gpio = {VIBRO_GPIO_Port, VIBRO_Pin}; diff --git a/firmware/targets/f2/api-hal/api-hal-resources.h b/firmware/targets/f2/api-hal/api-hal-resources.h index 9e2ea425..c829f355 100644 --- a/firmware/targets/f2/api-hal/api-hal-resources.h +++ b/firmware/targets/f2/api-hal/api-hal-resources.h @@ -9,4 +9,5 @@ extern const GpioPin input_gpio[GPIO_INPUT_PINS_COUNT]; extern const bool input_invert[GPIO_INPUT_PINS_COUNT]; extern const GpioPin led_gpio[3]; -extern const GpioPin backlight_gpio; \ No newline at end of file +extern const GpioPin backlight_gpio; +extern const GpioPin vibro_gpio; diff --git a/firmware/targets/f3/Inc/main.h b/firmware/targets/f3/Inc/main.h index 070ff06e..980b864a 100644 --- a/firmware/targets/f3/Inc/main.h +++ b/firmware/targets/f3/Inc/main.h @@ -186,6 +186,9 @@ extern TIM_HandleTypeDef htim16; #define NFC_IRQ_Pin RFID_PULL_Pin #define NFC_IRQ_GPIO_Port RFID_PULL_GPIO_Port +#define VIBRO_Pin GPIO_PIN_10 +#define VIBRO_GPIO_Port GPIOC + /* USER CODE END Private defines */ #ifdef __cplusplus diff --git a/firmware/targets/f3/api-hal/api-hal-resources.c b/firmware/targets/f3/api-hal/api-hal-resources.c index 07647ee4..4bb80dd4 100644 --- a/firmware/targets/f3/api-hal/api-hal-resources.c +++ b/firmware/targets/f3/api-hal/api-hal-resources.c @@ -26,3 +26,4 @@ const GpioPin led_gpio[3] = { const GpioPin backlight_gpio = {DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin}; const GpioPin sd_cs_gpio = {SD_CS_GPIO_Port, SD_CS_Pin}; +const GpioPin vibro_gpio = {VIBRO_GPIO_Port, VIBRO_Pin}; diff --git a/firmware/targets/f3/api-hal/api-hal-resources.h b/firmware/targets/f3/api-hal/api-hal-resources.h index 40c99b41..ccbfe6e9 100644 --- a/firmware/targets/f3/api-hal/api-hal-resources.h +++ b/firmware/targets/f3/api-hal/api-hal-resources.h @@ -11,3 +11,4 @@ extern const bool input_invert[GPIO_INPUT_PINS_COUNT]; extern const GpioPin led_gpio[3]; extern const GpioPin backlight_gpio; extern const GpioPin sd_cs_gpio; +extern const GpioPin vibro_gpio;