Skip to content

Commit e76664a

Browse files
committed
Merge remote-tracking branch 'origin/dev' into portasynthinca3/3734-uart-mode-selection
2 parents b39ef92 + 290a6dc commit e76664a

File tree

66 files changed

+1324
-243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1324
-243
lines changed

.vscode/example/settings.json.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"SConstruct": "python",
1313
"*.fam": "python"
1414
},
15+
"clangd.checkUpdates": false,
1516
"clangd.path": "${workspaceFolder}/toolchain/current/bin/clangd@FBT_PLATFORM_EXECUTABLE_EXT@",
1617
"clangd.arguments": [
1718
"--query-driver=**/arm-none-eabi-*",

applications/debug/accessor/accessor_app.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <furi.h>
33
#include <furi_hal.h>
44
#include <stdarg.h>
5+
#include <power/power_service/power.h>
56

67
void AccessorApp::run(void) {
78
AccessorEvent event;
@@ -35,16 +36,18 @@ AccessorApp::AccessorApp()
3536
: text_store{0} {
3637
notification = static_cast<NotificationApp*>(furi_record_open(RECORD_NOTIFICATION));
3738
expansion = static_cast<Expansion*>(furi_record_open(RECORD_EXPANSION));
39+
power = static_cast<Power*>(furi_record_open(RECORD_POWER));
3840
onewire_host = onewire_host_alloc(&gpio_ibutton);
3941
expansion_disable(expansion);
40-
furi_hal_power_enable_otg();
42+
power_enable_otg(power, true);
4143
}
4244

4345
AccessorApp::~AccessorApp() {
44-
furi_hal_power_disable_otg();
46+
power_enable_otg(power, false);
4547
expansion_enable(expansion);
4648
furi_record_close(RECORD_EXPANSION);
4749
furi_record_close(RECORD_NOTIFICATION);
50+
furi_record_close(RECORD_POWER);
4851
onewire_host_free(onewire_host);
4952
}
5053

applications/debug/accessor/accessor_app.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <one_wire/one_wire_host.h>
88
#include <notification/notification_messages.h>
99
#include <expansion/expansion.h>
10+
#include <power/power_service/power.h>
1011

1112
class AccessorApp {
1213
public:
@@ -53,4 +54,5 @@ class AccessorApp {
5354

5455
NotificationApp* notification;
5556
Expansion* expansion;
57+
Power* power;
5658
};

applications/debug/unit_tests/tests/furi/furi_event_loop_test.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,55 @@ static int32_t test_furi_event_loop_consumer(void* p) {
446446
return 0;
447447
}
448448

449+
typedef struct {
450+
FuriEventLoop* event_loop;
451+
FuriSemaphore* semaphore;
452+
size_t counter;
453+
} SelfUnsubTestTimerContext;
454+
455+
static void test_self_unsub_semaphore_callback(FuriEventLoopObject* object, void* context) {
456+
furi_event_loop_unsubscribe(context, object); // shouldn't crash here
457+
}
458+
459+
static void test_self_unsub_timer_callback(void* arg) {
460+
SelfUnsubTestTimerContext* context = arg;
461+
462+
if(context->counter == 0) {
463+
furi_semaphore_release(context->semaphore);
464+
} else if(context->counter == 1) {
465+
furi_event_loop_stop(context->event_loop);
466+
}
467+
468+
context->counter++;
469+
}
470+
471+
void test_furi_event_loop_self_unsubscribe(void) {
472+
FuriEventLoop* event_loop = furi_event_loop_alloc();
473+
474+
FuriSemaphore* semaphore = furi_semaphore_alloc(1, 0);
475+
furi_event_loop_subscribe_semaphore(
476+
event_loop,
477+
semaphore,
478+
FuriEventLoopEventIn,
479+
test_self_unsub_semaphore_callback,
480+
event_loop);
481+
482+
SelfUnsubTestTimerContext timer_context = {
483+
.event_loop = event_loop,
484+
.semaphore = semaphore,
485+
.counter = 0,
486+
};
487+
FuriEventLoopTimer* timer = furi_event_loop_timer_alloc(
488+
event_loop, test_self_unsub_timer_callback, FuriEventLoopTimerTypePeriodic, &timer_context);
489+
furi_event_loop_timer_start(timer, furi_ms_to_ticks(20));
490+
491+
furi_event_loop_run(event_loop);
492+
493+
furi_event_loop_timer_free(timer);
494+
furi_semaphore_free(semaphore);
495+
furi_event_loop_free(event_loop);
496+
}
497+
449498
void test_furi_event_loop(void) {
450499
TestFuriEventLoopData data = {};
451500

applications/debug/unit_tests/tests/furi/furi_test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ void test_furi_concurrent_access(void);
88
void test_furi_pubsub(void);
99
void test_furi_memmgr(void);
1010
void test_furi_event_loop(void);
11+
void test_furi_event_loop_self_unsubscribe(void);
1112
void test_errno_saving(void);
1213
void test_furi_primitives(void);
1314
void test_stdin(void);
@@ -46,6 +47,10 @@ MU_TEST(mu_test_furi_event_loop) {
4647
test_furi_event_loop();
4748
}
4849

50+
MU_TEST(mu_test_furi_event_loop_self_unsubscribe) {
51+
test_furi_event_loop_self_unsubscribe();
52+
}
53+
4954
MU_TEST(mu_test_errno_saving) {
5055
test_errno_saving();
5156
}
@@ -68,6 +73,7 @@ MU_TEST_SUITE(test_suite) {
6873
MU_RUN_TEST(mu_test_furi_pubsub);
6974
MU_RUN_TEST(mu_test_furi_memmgr);
7075
MU_RUN_TEST(mu_test_furi_event_loop);
76+
MU_RUN_TEST(mu_test_furi_event_loop_self_unsubscribe);
7177
MU_RUN_TEST(mu_test_stdio);
7278
MU_RUN_TEST(mu_test_errno_saving);
7379
MU_RUN_TEST(mu_test_furi_primitives);

applications/examples/example_thermo/example_thermo.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <one_wire/maxim_crc.h>
2323
#include <one_wire/one_wire_host.h>
2424

25-
#include <furi_hal_power.h>
25+
#include <power/power_service/power.h>
2626

2727
#define UPDATE_PERIOD_MS 1000UL
2828
#define TEXT_STORE_SIZE 64U
@@ -76,6 +76,7 @@ typedef struct {
7676
FuriThread* reader_thread;
7777
FuriMessageQueue* event_queue;
7878
OneWireHost* onewire;
79+
Power* power;
7980
float temp_celsius;
8081
bool has_device;
8182
} ExampleThermoContext;
@@ -273,7 +274,7 @@ static void example_thermo_input_callback(InputEvent* event, void* ctx) {
273274
/* Starts the reader thread and handles the input */
274275
static void example_thermo_run(ExampleThermoContext* context) {
275276
/* Enable power on external pins */
276-
furi_hal_power_enable_otg();
277+
power_enable_otg(context->power, true);
277278

278279
/* Configure the hardware in host mode */
279280
onewire_host_start(context->onewire);
@@ -309,7 +310,7 @@ static void example_thermo_run(ExampleThermoContext* context) {
309310
onewire_host_stop(context->onewire);
310311

311312
/* Disable power on external pins */
312-
furi_hal_power_disable_otg();
313+
power_enable_otg(context->power, false);
313314
}
314315

315316
/******************** Initialisation & startup *****************************/
@@ -334,6 +335,8 @@ static ExampleThermoContext* example_thermo_context_alloc(void) {
334335

335336
context->onewire = onewire_host_alloc(&THERMO_GPIO_PIN);
336337

338+
context->power = furi_record_open(RECORD_POWER);
339+
337340
return context;
338341
}
339342

@@ -348,6 +351,7 @@ static void example_thermo_context_free(ExampleThermoContext* context) {
348351
view_port_free(context->view_port);
349352

350353
furi_record_close(RECORD_GUI);
354+
furi_record_close(RECORD_POWER);
351355
}
352356

353357
/* The application's entry point. Execution starts from here. */

applications/main/bad_usb/helpers/bad_usb_hid.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,31 @@ bool hid_usb_kb_release(void* inst, uint16_t button) {
3737
return furi_hal_hid_kb_release(button);
3838
}
3939

40+
bool hid_usb_mouse_press(void* inst, uint8_t button) {
41+
UNUSED(inst);
42+
return furi_hal_hid_mouse_press(button);
43+
}
44+
45+
bool hid_usb_mouse_release(void* inst, uint8_t button) {
46+
UNUSED(inst);
47+
return furi_hal_hid_mouse_release(button);
48+
}
49+
50+
bool hid_usb_mouse_scroll(void* inst, int8_t delta) {
51+
UNUSED(inst);
52+
return furi_hal_hid_mouse_scroll(delta);
53+
}
54+
55+
bool hid_usb_mouse_move(void* inst, int8_t dx, int8_t dy) {
56+
UNUSED(inst);
57+
return furi_hal_hid_mouse_move(dx, dy);
58+
}
59+
60+
bool hid_usb_mouse_release_all(void* inst) {
61+
UNUSED(inst);
62+
return furi_hal_hid_mouse_release(0);
63+
}
64+
4065
bool hid_usb_consumer_press(void* inst, uint16_t button) {
4166
UNUSED(inst);
4267
return furi_hal_hid_consumer_key_press(button);
@@ -51,6 +76,7 @@ bool hid_usb_release_all(void* inst) {
5176
UNUSED(inst);
5277
bool state = furi_hal_hid_kb_release_all();
5378
state &= furi_hal_hid_consumer_key_release_all();
79+
state &= hid_usb_mouse_release_all(inst);
5480
return state;
5581
}
5682

@@ -67,6 +93,10 @@ static const BadUsbHidApi hid_api_usb = {
6793

6894
.kb_press = hid_usb_kb_press,
6995
.kb_release = hid_usb_kb_release,
96+
.mouse_press = hid_usb_mouse_press,
97+
.mouse_release = hid_usb_mouse_release,
98+
.mouse_scroll = hid_usb_mouse_scroll,
99+
.mouse_move = hid_usb_mouse_move,
70100
.consumer_press = hid_usb_consumer_press,
71101
.consumer_release = hid_usb_consumer_release,
72102
.release_all = hid_usb_release_all,
@@ -157,6 +187,27 @@ bool hid_ble_kb_release(void* inst, uint16_t button) {
157187
return ble_profile_hid_kb_release(ble_hid->profile, button);
158188
}
159189

190+
bool hid_ble_mouse_press(void* inst, uint8_t button) {
191+
BleHidInstance* ble_hid = inst;
192+
furi_assert(ble_hid);
193+
return ble_profile_hid_mouse_press(ble_hid->profile, button);
194+
}
195+
bool hid_ble_mouse_release(void* inst, uint8_t button) {
196+
BleHidInstance* ble_hid = inst;
197+
furi_assert(ble_hid);
198+
return ble_profile_hid_mouse_release(ble_hid->profile, button);
199+
}
200+
bool hid_ble_mouse_scroll(void* inst, int8_t delta) {
201+
BleHidInstance* ble_hid = inst;
202+
furi_assert(ble_hid);
203+
return ble_profile_hid_mouse_scroll(ble_hid->profile, delta);
204+
}
205+
bool hid_ble_mouse_move(void* inst, int8_t dx, int8_t dy) {
206+
BleHidInstance* ble_hid = inst;
207+
furi_assert(ble_hid);
208+
return ble_profile_hid_mouse_move(ble_hid->profile, dx, dy);
209+
}
210+
160211
bool hid_ble_consumer_press(void* inst, uint16_t button) {
161212
BleHidInstance* ble_hid = inst;
162213
furi_assert(ble_hid);
@@ -174,6 +225,7 @@ bool hid_ble_release_all(void* inst) {
174225
furi_assert(ble_hid);
175226
bool state = ble_profile_hid_kb_release_all(ble_hid->profile);
176227
state &= ble_profile_hid_consumer_key_release_all(ble_hid->profile);
228+
state &= ble_profile_hid_mouse_release_all(ble_hid->profile);
177229
return state;
178230
}
179231

@@ -191,6 +243,10 @@ static const BadUsbHidApi hid_api_ble = {
191243

192244
.kb_press = hid_ble_kb_press,
193245
.kb_release = hid_ble_kb_release,
246+
.mouse_press = hid_ble_mouse_press,
247+
.mouse_release = hid_ble_mouse_release,
248+
.mouse_scroll = hid_ble_mouse_scroll,
249+
.mouse_move = hid_ble_mouse_move,
194250
.consumer_press = hid_ble_consumer_press,
195251
.consumer_release = hid_ble_consumer_release,
196252
.release_all = hid_ble_release_all,

applications/main/bad_usb/helpers/bad_usb_hid.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ typedef struct {
2020

2121
bool (*kb_press)(void* inst, uint16_t button);
2222
bool (*kb_release)(void* inst, uint16_t button);
23+
bool (*mouse_press)(void* inst, uint8_t button);
24+
bool (*mouse_release)(void* inst, uint8_t button);
25+
bool (*mouse_scroll)(void* inst, int8_t delta);
26+
bool (*mouse_move)(void* inst, int8_t dx, int8_t dy);
2327
bool (*consumer_press)(void* inst, uint16_t button);
2428
bool (*consumer_release)(void* inst, uint16_t button);
2529
bool (*release_all)(void* inst);

applications/main/bad_usb/helpers/ducky_script.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,16 @@ static int32_t ducky_parse_line(BadUsbScript* bad_usb, FuriString* line) {
193193
return cmd_result;
194194
}
195195

196+
// Mouse Keys
197+
uint16_t key = ducky_get_mouse_keycode_by_name(line_tmp);
198+
if(key != HID_MOUSE_INVALID) {
199+
bad_usb->hid->mouse_press(bad_usb->hid_inst, key);
200+
bad_usb->hid->mouse_release(bad_usb->hid_inst, key);
201+
return 0;
202+
}
203+
196204
// Special keys + modifiers
197-
uint16_t key = ducky_get_keycode(bad_usb, line_tmp, false);
205+
key = ducky_get_keycode(bad_usb, line_tmp, false);
198206
if(key == HID_KEYBOARD_NONE) {
199207
return ducky_error(bad_usb, "No keycode defined for %s", line_tmp);
200208
}

0 commit comments

Comments
 (0)