|
6 | 6 | * 13 -> 16 (USART TX to LPUART RX)
|
7 | 7 | * 14 -> 15 (USART RX to LPUART TX)
|
8 | 8 | *
|
| 9 | + * Optional: Connect an LED with an appropriate series resistor |
| 10 | + * between pins 1 and 8. It will always be on if the device is |
| 11 | + * connected to USB power, so unplug it before running the app. |
| 12 | + * |
9 | 13 | * What this application does:
|
10 | 14 | *
|
11 | 15 | * - Enables module support and emulates the module on a single device
|
12 | 16 | * (hence the above connection),
|
13 | 17 | * - Connects to the expansion module service, sets baud rate,
|
| 18 | + * - Enables OTG (5V) on GPIO via plain expansion protocol, |
| 19 | + * - Waits 5 cycles of idle loop (1 second), |
14 | 20 | * - Starts the RPC session,
|
| 21 | + * - Disables OTG (5V) on GPIO via RPC messages, |
| 22 | + * - Waits 5 cycles of idle loop (1 second), |
15 | 23 | * - Creates a directory at `/ext/ExpansionTest` and writes a file
|
16 | 24 | * named `test.txt` under it,
|
17 | 25 | * - Plays an audiovisual alert (sound and blinking display),
|
18 |
| - * - Waits 10 cycles of idle loop, |
| 26 | + * - Enables OTG (5V) on GPIO via RPC messages, |
| 27 | + * - Waits 5 cycles of idle loop (1 second), |
19 | 28 | * - Stops the RPC session,
|
20 |
| - * - Waits another 10 cycles of idle loop, |
| 29 | + * - Disables OTG (5V) on GPIO via plain expansion protocol, |
21 | 30 | * - Exits (plays a sound if any of the above steps failed).
|
22 | 31 | */
|
23 | 32 | #include <furi.h>
|
@@ -302,6 +311,22 @@ static bool expansion_test_app_handshake(ExpansionTestApp* instance) {
|
302 | 311 | return success;
|
303 | 312 | }
|
304 | 313 |
|
| 314 | +static bool expansion_test_app_enable_otg(ExpansionTestApp* instance, bool enable) { |
| 315 | + bool success = false; |
| 316 | + |
| 317 | + do { |
| 318 | + const ExpansionFrameControlCommand command = enable ? |
| 319 | + ExpansionFrameControlCommandEnableOtg : |
| 320 | + ExpansionFrameControlCommandDisableOtg; |
| 321 | + if(!expansion_test_app_send_control_request(instance, command)) break; |
| 322 | + if(!expansion_test_app_receive_frame(instance, &instance->frame)) break; |
| 323 | + if(!expansion_test_app_is_success_response(&instance->frame)) break; |
| 324 | + success = true; |
| 325 | + } while(false); |
| 326 | + |
| 327 | + return success; |
| 328 | +} |
| 329 | + |
305 | 330 | static bool expansion_test_app_start_rpc(ExpansionTestApp* instance) {
|
306 | 331 | bool success = false;
|
307 | 332 |
|
@@ -396,6 +421,27 @@ static bool expansion_test_app_rpc_alert(ExpansionTestApp* instance) {
|
396 | 421 | return success;
|
397 | 422 | }
|
398 | 423 |
|
| 424 | +static bool expansion_test_app_rpc_enable_otg(ExpansionTestApp* instance, bool enable) { |
| 425 | + bool success = false; |
| 426 | + |
| 427 | + instance->msg.command_id++; |
| 428 | + instance->msg.command_status = PB_CommandStatus_OK; |
| 429 | + instance->msg.which_content = PB_Main_gpio_set_otg_mode_tag; |
| 430 | + instance->msg.content.gpio_set_otg_mode.mode = enable ? PB_Gpio_GpioOtgMode_ON : |
| 431 | + PB_Gpio_GpioOtgMode_OFF; |
| 432 | + instance->msg.has_next = false; |
| 433 | + |
| 434 | + do { |
| 435 | + if(!expansion_test_app_send_rpc_request(instance, &instance->msg)) break; |
| 436 | + if(!expansion_test_app_receive_rpc_request(instance, &instance->msg)) break; |
| 437 | + if(instance->msg.which_content != PB_Main_empty_tag) break; |
| 438 | + if(instance->msg.command_status != PB_CommandStatus_OK) break; |
| 439 | + success = true; |
| 440 | + } while(false); |
| 441 | + |
| 442 | + return success; |
| 443 | +} |
| 444 | + |
399 | 445 | static bool expansion_test_app_idle(ExpansionTestApp* instance, uint32_t num_cycles) {
|
400 | 446 | uint32_t num_cycles_done;
|
401 | 447 | for(num_cycles_done = 0; num_cycles_done < num_cycles; ++num_cycles_done) {
|
@@ -434,13 +480,18 @@ int32_t expansion_test_app(void* p) {
|
434 | 480 | if(!expansion_test_app_send_presence(instance)) break;
|
435 | 481 | if(!expansion_test_app_wait_ready(instance)) break;
|
436 | 482 | if(!expansion_test_app_handshake(instance)) break;
|
| 483 | + if(!expansion_test_app_enable_otg(instance, true)) break; |
| 484 | + if(!expansion_test_app_idle(instance, 5)) break; |
437 | 485 | if(!expansion_test_app_start_rpc(instance)) break;
|
| 486 | + if(!expansion_test_app_rpc_enable_otg(instance, false)) break; |
| 487 | + if(!expansion_test_app_idle(instance, 5)) break; |
438 | 488 | if(!expansion_test_app_rpc_mkdir(instance)) break;
|
439 | 489 | if(!expansion_test_app_rpc_write(instance)) break;
|
440 | 490 | if(!expansion_test_app_rpc_alert(instance)) break;
|
441 |
| - if(!expansion_test_app_idle(instance, 10)) break; |
| 491 | + if(!expansion_test_app_rpc_enable_otg(instance, true)) break; |
| 492 | + if(!expansion_test_app_idle(instance, 5)) break; |
442 | 493 | if(!expansion_test_app_stop_rpc(instance)) break;
|
443 |
| - if(!expansion_test_app_idle(instance, 10)) break; |
| 494 | + if(!expansion_test_app_enable_otg(instance, false)) break; |
444 | 495 | success = true;
|
445 | 496 | } while(false);
|
446 | 497 |
|
|
0 commit comments