mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-10 06:54:19 +00:00
Merge remote-tracking branch 'upstream/dev' into dev
This commit is contained in:
commit
ce80586822
135 changed files with 5759 additions and 1223 deletions
|
@ -1,5 +1,5 @@
|
|||
diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c
|
||||
index 5769ced..c5d3088 100644
|
||||
index 9baa738..91ad7c1 100644
|
||||
--- a/applications/services/notification/notification_app.c
|
||||
+++ b/applications/services/notification/notification_app.c
|
||||
@@ -9,6 +9,7 @@
|
||||
|
@ -19,7 +19,7 @@ index 5769ced..c5d3088 100644
|
|||
}
|
||||
|
||||
diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c
|
||||
index 1955012..19d953d 100644
|
||||
index 2a1d988..dda86f3 100644
|
||||
--- a/applications/settings/notification_settings/notification_settings_app.c
|
||||
+++ b/applications/settings/notification_settings/notification_settings_app.c
|
||||
@@ -3,6 +3,7 @@
|
||||
|
@ -30,16 +30,16 @@ index 1955012..19d953d 100644
|
|||
|
||||
#define MAX_NOTIFICATION_SETTINGS 4
|
||||
|
||||
@@ -20,6 +21,8 @@ static const NotificationSequence sequence_note_c = {
|
||||
NULL,
|
||||
};
|
||||
@@ -13,6 +14,8 @@ typedef struct {
|
||||
VariableItemList* variable_item_list;
|
||||
} NotificationAppSettings;
|
||||
|
||||
+static VariableItem* temp_item;
|
||||
+
|
||||
#define CONTRAST_COUNT 11
|
||||
const char* const contrast_text[CONTRAST_COUNT] = {
|
||||
"-5",
|
||||
@@ -156,6 +159,59 @@ static void vibro_changed(VariableItem* item) {
|
||||
static const NotificationSequence sequence_note_c = {
|
||||
&message_note_c5,
|
||||
&message_delay_100,
|
||||
@@ -168,6 +171,59 @@ static void vibro_changed(VariableItem* item) {
|
||||
notification_message(app->notification, &sequence_single_vibro);
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ index 1955012..19d953d 100644
|
|||
static uint32_t notification_app_settings_exit(void* context) {
|
||||
UNUSED(context);
|
||||
return VIEW_NONE;
|
||||
@@ -180,8 +236,40 @@ static NotificationAppSettings* alloc_settings() {
|
||||
@@ -192,8 +248,40 @@ static NotificationAppSettings* alloc_settings() {
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, contrast_text[value_index]);
|
||||
|
||||
|
@ -462,54 +462,6 @@ index 0000000..68dacda
|
|||
+ */
|
||||
+const char* rgb_backlight_get_color_text(uint8_t index);
|
||||
\ No newline at end of file
|
||||
diff --git a/targets/f7/furi_hal/furi_hal_light.c b/targets/f7/furi_hal/furi_hal_light.c
|
||||
index 83e1603..45798ca 100644
|
||||
--- a/targets/f7/furi_hal/furi_hal_light.c
|
||||
+++ b/targets/f7/furi_hal/furi_hal_light.c
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <furi_hal_light.h>
|
||||
#include <lp5562.h>
|
||||
#include <stdint.h>
|
||||
+#include <applications/settings/notification_settings/rgb_backlight.h>
|
||||
|
||||
#define LED_CURRENT_RED 50
|
||||
#define LED_CURRENT_GREEN 50
|
||||
@@ -31,22 +32,21 @@ void furi_hal_light_init() {
|
||||
}
|
||||
|
||||
void furi_hal_light_set(Light light, uint8_t value) {
|
||||
- furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
||||
- if(light & LightRed) {
|
||||
- lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelRed, value);
|
||||
- }
|
||||
- if(light & LightGreen) {
|
||||
- lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelGreen, value);
|
||||
- }
|
||||
- if(light & LightBlue) {
|
||||
- lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelBlue, value);
|
||||
- }
|
||||
if(light & LightBacklight) {
|
||||
- uint8_t prev = lp5562_get_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelWhite);
|
||||
- lp5562_execute_ramp(
|
||||
- &furi_hal_i2c_handle_power, LP5562Engine1, LP5562ChannelWhite, prev, value, 100);
|
||||
+ rgb_backlight_update(value, false);
|
||||
+ } else {
|
||||
+ furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
||||
+ if(light & LightRed) {
|
||||
+ lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelRed, value);
|
||||
+ }
|
||||
+ if(light & LightGreen) {
|
||||
+ lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelGreen, value);
|
||||
+ }
|
||||
+ if(light & LightBlue) {
|
||||
+ lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelBlue, value);
|
||||
+ }
|
||||
+ furi_hal_i2c_release(&furi_hal_i2c_handle_power);
|
||||
}
|
||||
- furi_hal_i2c_release(&furi_hal_i2c_handle_power);
|
||||
}
|
||||
|
||||
void furi_hal_light_blink_start(Light light, uint8_t brightness, uint16_t on_time, uint16_t period) {
|
||||
diff --git a/lib/drivers/SK6805.c b/lib/drivers/SK6805.c
|
||||
new file mode 100644
|
||||
index 0000000..572e1df
|
||||
|
@ -675,3 +627,51 @@ index 0000000..7c58956
|
|||
+
|
||||
+#endif /* SK6805_H_ */
|
||||
\ No newline at end of file
|
||||
diff --git a/targets/f7/furi_hal/furi_hal_light.c b/targets/f7/furi_hal/furi_hal_light.c
|
||||
index 83e1603..45798ca 100644
|
||||
--- a/targets/f7/furi_hal/furi_hal_light.c
|
||||
+++ b/targets/f7/furi_hal/furi_hal_light.c
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <furi_hal_light.h>
|
||||
#include <lp5562.h>
|
||||
#include <stdint.h>
|
||||
+#include <applications/settings/notification_settings/rgb_backlight.h>
|
||||
|
||||
#define LED_CURRENT_RED 50
|
||||
#define LED_CURRENT_GREEN 50
|
||||
@@ -31,22 +32,21 @@ void furi_hal_light_init() {
|
||||
}
|
||||
|
||||
void furi_hal_light_set(Light light, uint8_t value) {
|
||||
- furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
||||
- if(light & LightRed) {
|
||||
- lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelRed, value);
|
||||
- }
|
||||
- if(light & LightGreen) {
|
||||
- lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelGreen, value);
|
||||
- }
|
||||
- if(light & LightBlue) {
|
||||
- lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelBlue, value);
|
||||
- }
|
||||
if(light & LightBacklight) {
|
||||
- uint8_t prev = lp5562_get_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelWhite);
|
||||
- lp5562_execute_ramp(
|
||||
- &furi_hal_i2c_handle_power, LP5562Engine1, LP5562ChannelWhite, prev, value, 100);
|
||||
+ rgb_backlight_update(value, false);
|
||||
+ } else {
|
||||
+ furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
||||
+ if(light & LightRed) {
|
||||
+ lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelRed, value);
|
||||
+ }
|
||||
+ if(light & LightGreen) {
|
||||
+ lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelGreen, value);
|
||||
+ }
|
||||
+ if(light & LightBlue) {
|
||||
+ lp5562_set_channel_value(&furi_hal_i2c_handle_power, LP5562ChannelBlue, value);
|
||||
+ }
|
||||
+ furi_hal_i2c_release(&furi_hal_i2c_handle_power);
|
||||
}
|
||||
- furi_hal_i2c_release(&furi_hal_i2c_handle_power);
|
||||
}
|
||||
|
||||
void furi_hal_light_blink_start(Light light, uint8_t brightness, uint16_t on_time, uint16_t period) {
|
||||
|
|
|
@ -375,7 +375,7 @@ trigger:
|
|||
- tag
|
||||
|
||||
node:
|
||||
typ: haupt
|
||||
typ: dev1
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
|
@ -678,4 +678,4 @@ trigger:
|
|||
- push
|
||||
|
||||
node:
|
||||
typ: haupt
|
||||
typ: dev1
|
||||
|
|
22
CHANGELOG.md
22
CHANGELOG.md
|
@ -1,9 +1,29 @@
|
|||
## New changes
|
||||
* Archive: Fix two filebrowser bugs
|
||||
* SubGHz: Programming mode for Dea Mio (right arrow button)
|
||||
* SubGHz: Keeloq fix emulation for multiple systems and extend add manually support for 2 of them (Dea Mio, Genius Bravo, GSN, Normstahl)
|
||||
* SubGHz: Fixed hopper state when entering Read via Freq analyzer
|
||||
* SubGHz: Subghz save files with receive time (by @Willy-JL)
|
||||
* NFC: Fix NFC V dumps with v3 (pre refactor saves) crashing at info page
|
||||
* NFC: Zolotaya Korona Online parser added (by @Leptopt1los)
|
||||
* NFC: Add NFC NDEF parser (by @Willy-JL)
|
||||
* LF RFID: Write T5577 with random password added (clear password via Extra actions) (by @Leptopt1los)
|
||||
* LF RFID: Write T5577 with random and custom password added (clear password via Extra actions) (by @Leptopt1los)
|
||||
* SubGHz: Update honeywell protocol (by @Willy-JL)
|
||||
* System: More contrast values for replacement displays (up to +8 or -8)
|
||||
* USB/BLE HID: Add macOS Music app volume control
|
||||
* Apps: **Check out Apps updates by following** [this link](https://github.com/xMasterX/all-the-plugins/commits/dev)
|
||||
* OFW PR 3401: it-IT-mac layout - by nminaylov
|
||||
* OFW: 0.98.0-rc various fixes
|
||||
* OFW: RFID CLI: better usage
|
||||
* OFW: Mf DESFire fixes
|
||||
* OFW: NFC UI refactor
|
||||
* OFW: Expansion module protocol
|
||||
* OFW: Bugfix: Strip last parity bit from decoded FDX-B data
|
||||
* OFW: FuriHal: interrupt priorities and documentation
|
||||
* OFW: FuriHal: UART refactoring
|
||||
* OFW: SubGhz: add `subghz tx_from_file` CLI cmd, major TX flow refactoring, various improvements and bug fixes
|
||||
* OFW: Furi_hal_rtc: new function
|
||||
* OFW: NFC UI refactor
|
||||
* OFW: assets: checking limits on image size; ufbt: cdb target
|
||||
* OFW: NFC: system dict skip when user dict is skipped fix (replaces our fix)
|
||||
* OFW: FuriHal: fix start duration furi_hal_subghz_async_tx
|
||||
|
|
12
applications/debug/expansion_test/application.fam
Normal file
12
applications/debug/expansion_test/application.fam
Normal file
|
@ -0,0 +1,12 @@
|
|||
App(
|
||||
appid="expansion_test",
|
||||
name="Expansion Module Test",
|
||||
apptype=FlipperAppType.DEBUG,
|
||||
entry_point="expansion_test_app",
|
||||
requires=["expansion_start"],
|
||||
fap_libs=["assets"],
|
||||
stack_size=1 * 1024,
|
||||
order=20,
|
||||
fap_category="Debug",
|
||||
fap_file_assets="assets",
|
||||
)
|
9
applications/debug/expansion_test/assets/test.txt
Normal file
9
applications/debug/expansion_test/assets/test.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
"Did you ever hear the tragedy of Darth Plagueis the Wise?"
|
||||
"No."
|
||||
"I thought not. It's not a story the Jedi would tell you. It's a Sith legend. Darth Plagueis... was a Dark Lord of the Sith so powerful and so wise, he could use the Force to influence the midi-chlorians... to create... life. He had such a knowledge of the dark side, he could even keep the ones he cared about... from dying."
|
||||
"He could actually... save people from death?"
|
||||
"The dark side of the Force is a pathway to many abilities... some consider to be unnatural."
|
||||
"Wh– What happened to him?"
|
||||
"He became so powerful, the only thing he was afraid of was... losing his power. Which eventually, of course, he did. Unfortunately, he taught his apprentice everything he knew. Then his apprentice killed him in his sleep. It's ironic. He could save others from death, but not himself."
|
||||
"Is it possible to learn this power?"
|
||||
"Not from a Jedi."
|
455
applications/debug/expansion_test/expansion_test.c
Normal file
455
applications/debug/expansion_test/expansion_test.c
Normal file
|
@ -0,0 +1,455 @@
|
|||
/**
|
||||
* @file expansion_test.c
|
||||
* @brief Expansion module support testing application.
|
||||
*
|
||||
* Before running, connect pins using the following scheme:
|
||||
* 13 -> 16 (USART TX to LPUART RX)
|
||||
* 14 -> 15 (USART RX to LPUART TX)
|
||||
*
|
||||
* What this application does:
|
||||
*
|
||||
* - Enables module support and emulates the module on a single device
|
||||
* (hence the above connection),
|
||||
* - Connects to the expansion module service, sets baud rate,
|
||||
* - Starts the RPC session,
|
||||
* - Creates a directory at `/ext/ExpansionTest` and writes a file
|
||||
* named `test.txt` under it,
|
||||
* - Plays an audiovisual alert (sound and blinking display),
|
||||
* - Waits 10 cycles of idle loop,
|
||||
* - Stops the RPC session,
|
||||
* - Waits another 10 cycles of idle loop,
|
||||
* - Exits (plays a sound if any of the above steps failed).
|
||||
*/
|
||||
#include <furi.h>
|
||||
|
||||
#include <furi_hal_resources.h>
|
||||
|
||||
#include <furi_hal_serial.h>
|
||||
#include <furi_hal_serial_control.h>
|
||||
|
||||
#include <pb.h>
|
||||
#include <pb_decode.h>
|
||||
#include <pb_encode.h>
|
||||
|
||||
#include <flipper.pb.h>
|
||||
|
||||
#include <storage/storage.h>
|
||||
#include <expansion/expansion.h>
|
||||
#include <notification/notification_messages.h>
|
||||
#include <expansion/expansion_protocol.h>
|
||||
|
||||
#define TAG "ExpansionTest"
|
||||
|
||||
#define TEST_DIR_PATH EXT_PATH(TAG)
|
||||
#define TEST_FILE_NAME "test.txt"
|
||||
#define TEST_FILE_PATH EXT_PATH(TAG "/" TEST_FILE_NAME)
|
||||
|
||||
#define HOST_SERIAL_ID (FuriHalSerialIdLpuart)
|
||||
#define MODULE_SERIAL_ID (FuriHalSerialIdUsart)
|
||||
|
||||
#define RECEIVE_BUFFER_SIZE (sizeof(ExpansionFrame) + sizeof(ExpansionFrameChecksum))
|
||||
|
||||
typedef enum {
|
||||
ExpansionTestAppFlagData = 1U << 0,
|
||||
ExpansionTestAppFlagExit = 1U << 1,
|
||||
} ExpansionTestAppFlag;
|
||||
|
||||
#define EXPANSION_TEST_APP_ALL_FLAGS (ExpansionTestAppFlagData | ExpansionTestAppFlagExit)
|
||||
|
||||
typedef struct {
|
||||
FuriThreadId thread_id;
|
||||
Expansion* expansion;
|
||||
FuriHalSerialHandle* handle;
|
||||
FuriStreamBuffer* buf;
|
||||
ExpansionFrame frame;
|
||||
PB_Main msg;
|
||||
Storage* storage;
|
||||
} ExpansionTestApp;
|
||||
|
||||
static void expansion_test_app_serial_rx_callback(
|
||||
FuriHalSerialHandle* handle,
|
||||
FuriHalSerialRxEvent event,
|
||||
void* context) {
|
||||
furi_assert(handle);
|
||||
furi_assert(context);
|
||||
ExpansionTestApp* app = context;
|
||||
|
||||
if(event == FuriHalSerialRxEventData) {
|
||||
const uint8_t data = furi_hal_serial_async_rx(handle);
|
||||
furi_stream_buffer_send(app->buf, &data, sizeof(data), 0);
|
||||
furi_thread_flags_set(app->thread_id, ExpansionTestAppFlagData);
|
||||
}
|
||||
}
|
||||
|
||||
static ExpansionTestApp* expansion_test_app_alloc() {
|
||||
ExpansionTestApp* instance = malloc(sizeof(ExpansionTestApp));
|
||||
instance->buf = furi_stream_buffer_alloc(RECEIVE_BUFFER_SIZE, 1);
|
||||
return instance;
|
||||
}
|
||||
|
||||
static void expansion_test_app_free(ExpansionTestApp* instance) {
|
||||
furi_stream_buffer_free(instance->buf);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
static void expansion_test_app_start(ExpansionTestApp* instance) {
|
||||
instance->thread_id = furi_thread_get_current_id();
|
||||
instance->expansion = furi_record_open(RECORD_EXPANSION);
|
||||
instance->handle = furi_hal_serial_control_acquire(MODULE_SERIAL_ID);
|
||||
furi_check(instance->handle);
|
||||
// Configure the serial port
|
||||
furi_hal_serial_init(instance->handle, EXPANSION_PROTOCOL_DEFAULT_BAUD_RATE);
|
||||
// Start waiting for the initial pulse
|
||||
expansion_enable(instance->expansion, HOST_SERIAL_ID);
|
||||
|
||||
furi_hal_serial_async_rx_start(
|
||||
instance->handle, expansion_test_app_serial_rx_callback, instance, false);
|
||||
}
|
||||
|
||||
static void expansion_test_app_stop(ExpansionTestApp* instance) {
|
||||
// Give back the module handle
|
||||
furi_hal_serial_control_release(instance->handle);
|
||||
// Turn expansion module support off
|
||||
expansion_disable(instance->expansion);
|
||||
furi_record_close(RECORD_EXPANSION);
|
||||
}
|
||||
|
||||
static inline bool expansion_test_app_is_success_response(const ExpansionFrame* response) {
|
||||
return response->header.type == ExpansionFrameTypeStatus &&
|
||||
response->content.status.error == ExpansionFrameErrorNone;
|
||||
}
|
||||
|
||||
static inline bool expansion_test_app_is_success_rpc_message(const PB_Main* message) {
|
||||
return (message->command_status == PB_CommandStatus_OK ||
|
||||
message->command_status == PB_CommandStatus_ERROR_STORAGE_EXIST) &&
|
||||
(message->which_content == PB_Main_empty_tag);
|
||||
}
|
||||
|
||||
static size_t expansion_test_app_receive_callback(uint8_t* data, size_t data_size, void* context) {
|
||||
ExpansionTestApp* instance = context;
|
||||
|
||||
size_t received_size = 0;
|
||||
|
||||
while(true) {
|
||||
received_size += furi_stream_buffer_receive(
|
||||
instance->buf, data + received_size, data_size - received_size, 0);
|
||||
if(received_size == data_size) break;
|
||||
|
||||
const uint32_t flags = furi_thread_flags_wait(
|
||||
EXPANSION_TEST_APP_ALL_FLAGS, FuriFlagWaitAny, EXPANSION_PROTOCOL_TIMEOUT_MS);
|
||||
|
||||
// Exit on any error
|
||||
if(flags & FuriFlagError) break;
|
||||
}
|
||||
|
||||
return received_size;
|
||||
}
|
||||
|
||||
static size_t
|
||||
expansion_test_app_send_callback(const uint8_t* data, size_t data_size, void* context) {
|
||||
ExpansionTestApp* instance = context;
|
||||
|
||||
furi_hal_serial_tx(instance->handle, data, data_size);
|
||||
furi_hal_serial_tx_wait_complete(instance->handle);
|
||||
|
||||
return data_size;
|
||||
}
|
||||
|
||||
static bool expansion_test_app_receive_frame(ExpansionTestApp* instance, ExpansionFrame* frame) {
|
||||
return expansion_protocol_decode(frame, expansion_test_app_receive_callback, instance) ==
|
||||
ExpansionProtocolStatusOk;
|
||||
}
|
||||
|
||||
static bool
|
||||
expansion_test_app_send_status_response(ExpansionTestApp* instance, ExpansionFrameError error) {
|
||||
ExpansionFrame frame = {
|
||||
.header.type = ExpansionFrameTypeStatus,
|
||||
.content.status.error = error,
|
||||
};
|
||||
return expansion_protocol_encode(&frame, expansion_test_app_send_callback, instance) ==
|
||||
ExpansionProtocolStatusOk;
|
||||
}
|
||||
|
||||
static bool expansion_test_app_send_heartbeat(ExpansionTestApp* instance) {
|
||||
ExpansionFrame frame = {
|
||||
.header.type = ExpansionFrameTypeHeartbeat,
|
||||
.content.heartbeat = {},
|
||||
};
|
||||
return expansion_protocol_encode(&frame, expansion_test_app_send_callback, instance) ==
|
||||
ExpansionProtocolStatusOk;
|
||||
}
|
||||
|
||||
static bool
|
||||
expansion_test_app_send_baud_rate_request(ExpansionTestApp* instance, uint32_t baud_rate) {
|
||||
ExpansionFrame frame = {
|
||||
.header.type = ExpansionFrameTypeBaudRate,
|
||||
.content.baud_rate.baud = baud_rate,
|
||||
};
|
||||
return expansion_protocol_encode(&frame, expansion_test_app_send_callback, instance) ==
|
||||
ExpansionProtocolStatusOk;
|
||||
}
|
||||
|
||||
static bool expansion_test_app_send_control_request(
|
||||
ExpansionTestApp* instance,
|
||||
ExpansionFrameControlCommand command) {
|
||||
ExpansionFrame frame = {
|
||||
.header.type = ExpansionFrameTypeControl,
|
||||
.content.control.command = command,
|
||||
};
|
||||
return expansion_protocol_encode(&frame, expansion_test_app_send_callback, instance) ==
|
||||
ExpansionProtocolStatusOk;
|
||||
}
|
||||
|
||||
static bool expansion_test_app_send_data_request(
|
||||
ExpansionTestApp* instance,
|
||||
const uint8_t* data,
|
||||
size_t data_size) {
|
||||
furi_assert(data_size <= EXPANSION_PROTOCOL_MAX_DATA_SIZE);
|
||||
|
||||
ExpansionFrame frame = {
|
||||
.header.type = ExpansionFrameTypeData,
|
||||
.content.data.size = data_size,
|
||||
};
|
||||
|
||||
memcpy(frame.content.data.bytes, data, data_size);
|
||||
return expansion_protocol_encode(&frame, expansion_test_app_send_callback, instance) ==
|
||||
ExpansionProtocolStatusOk;
|
||||
}
|
||||
|
||||
static bool expansion_test_app_rpc_encode_callback(
|
||||
pb_ostream_t* stream,
|
||||
const pb_byte_t* data,
|
||||
size_t data_size) {
|
||||
ExpansionTestApp* instance = stream->state;
|
||||
|
||||
size_t size_sent = 0;
|
||||
|
||||
while(size_sent < data_size) {
|
||||
const size_t current_size = MIN(data_size - size_sent, EXPANSION_PROTOCOL_MAX_DATA_SIZE);
|
||||
if(!expansion_test_app_send_data_request(instance, data + size_sent, current_size)) break;
|
||||
if(!expansion_test_app_receive_frame(instance, &instance->frame)) break;
|
||||
if(!expansion_test_app_is_success_response(&instance->frame)) break;
|
||||
size_sent += current_size;
|
||||
}
|
||||
|
||||
return size_sent == data_size;
|
||||
}
|
||||
|
||||
static bool expansion_test_app_send_rpc_request(ExpansionTestApp* instance, PB_Main* message) {
|
||||
pb_ostream_t stream = {
|
||||
.callback = expansion_test_app_rpc_encode_callback,
|
||||
.state = instance,
|
||||
.max_size = SIZE_MAX,
|
||||
.bytes_written = 0,
|
||||
.errmsg = NULL,
|
||||
};
|
||||
|
||||
const bool success = pb_encode_ex(&stream, &PB_Main_msg, message, PB_ENCODE_DELIMITED);
|
||||
pb_release(&PB_Main_msg, message);
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool expansion_test_app_receive_rpc_request(ExpansionTestApp* instance, PB_Main* message) {
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
if(!expansion_test_app_receive_frame(instance, &instance->frame)) break;
|
||||
if(!expansion_test_app_send_status_response(instance, ExpansionFrameErrorNone)) break;
|
||||
if(instance->frame.header.type != ExpansionFrameTypeData) break;
|
||||
pb_istream_t stream = pb_istream_from_buffer(
|
||||
instance->frame.content.data.bytes, instance->frame.content.data.size);
|
||||
if(!pb_decode_ex(&stream, &PB_Main_msg, message, PB_DECODE_DELIMITED)) break;
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool expansion_test_app_send_presence(ExpansionTestApp* instance) {
|
||||
// Send pulses to emulate module insertion
|
||||
const uint8_t init = 0xAA;
|
||||
furi_hal_serial_tx(instance->handle, &init, sizeof(init));
|
||||
furi_hal_serial_tx_wait_complete(instance->handle);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool expansion_test_app_wait_ready(ExpansionTestApp* instance) {
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
if(!expansion_test_app_receive_frame(instance, &instance->frame)) break;
|
||||
if(instance->frame.header.type != ExpansionFrameTypeHeartbeat) break;
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool expansion_test_app_handshake(ExpansionTestApp* instance) {
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
if(!expansion_test_app_send_baud_rate_request(instance, 230400)) break;
|
||||
if(!expansion_test_app_receive_frame(instance, &instance->frame)) break;
|
||||
if(!expansion_test_app_is_success_response(&instance->frame)) break;
|
||||
furi_hal_serial_set_br(instance->handle, 230400);
|
||||
furi_delay_ms(EXPANSION_PROTOCOL_BAUD_CHANGE_DT_MS);
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool expansion_test_app_start_rpc(ExpansionTestApp* instance) {
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
if(!expansion_test_app_send_control_request(instance, ExpansionFrameControlCommandStartRpc))
|
||||
break;
|
||||
if(!expansion_test_app_receive_frame(instance, &instance->frame)) break;
|
||||
if(!expansion_test_app_is_success_response(&instance->frame)) break;
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool expansion_test_app_rpc_mkdir(ExpansionTestApp* instance) {
|
||||
bool success = false;
|
||||
|
||||
instance->msg.command_id++;
|
||||
instance->msg.command_status = PB_CommandStatus_OK;
|
||||
instance->msg.which_content = PB_Main_storage_mkdir_request_tag;
|
||||
instance->msg.has_next = false;
|
||||
instance->msg.content.storage_mkdir_request.path = TEST_DIR_PATH;
|
||||
|
||||
do {
|
||||
if(!expansion_test_app_send_rpc_request(instance, &instance->msg)) break;
|
||||
if(!expansion_test_app_receive_rpc_request(instance, &instance->msg)) break;
|
||||
if(!expansion_test_app_is_success_rpc_message(&instance->msg)) break;
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool expansion_test_app_rpc_write(ExpansionTestApp* instance) {
|
||||
bool success = false;
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(storage);
|
||||
|
||||
do {
|
||||
if(!storage_file_open(file, APP_ASSETS_PATH(TEST_FILE_NAME), FSAM_READ, FSOM_OPEN_EXISTING))
|
||||
break;
|
||||
|
||||
const uint64_t file_size = storage_file_size(file);
|
||||
|
||||
instance->msg.command_id++;
|
||||
instance->msg.command_status = PB_CommandStatus_OK;
|
||||
instance->msg.which_content = PB_Main_storage_write_request_tag;
|
||||
instance->msg.has_next = false;
|
||||
instance->msg.content.storage_write_request.path = TEST_FILE_PATH;
|
||||
instance->msg.content.storage_write_request.has_file = true;
|
||||
instance->msg.content.storage_write_request.file.data =
|
||||
malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(file_size));
|
||||
instance->msg.content.storage_write_request.file.data->size = file_size;
|
||||
|
||||
const size_t bytes_read = storage_file_read(
|
||||
file, instance->msg.content.storage_write_request.file.data->bytes, file_size);
|
||||
|
||||
if(bytes_read != file_size) {
|
||||
pb_release(&PB_Main_msg, &instance->msg);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!expansion_test_app_send_rpc_request(instance, &instance->msg)) break;
|
||||
if(!expansion_test_app_receive_rpc_request(instance, &instance->msg)) break;
|
||||
if(!expansion_test_app_is_success_rpc_message(&instance->msg)) break;
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
storage_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool expansion_test_app_rpc_alert(ExpansionTestApp* instance) {
|
||||
bool success = false;
|
||||
|
||||
instance->msg.command_id++;
|
||||
instance->msg.command_status = PB_CommandStatus_OK;
|
||||
instance->msg.which_content = PB_Main_system_play_audiovisual_alert_request_tag;
|
||||
instance->msg.has_next = false;
|
||||
|
||||
do {
|
||||
if(!expansion_test_app_send_rpc_request(instance, &instance->msg)) break;
|
||||
if(!expansion_test_app_receive_rpc_request(instance, &instance->msg)) break;
|
||||
if(instance->msg.which_content != PB_Main_empty_tag) break;
|
||||
if(instance->msg.command_status != PB_CommandStatus_OK) break;
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool expansion_test_app_idle(ExpansionTestApp* instance, uint32_t num_cycles) {
|
||||
uint32_t num_cycles_done;
|
||||
for(num_cycles_done = 0; num_cycles_done < num_cycles; ++num_cycles_done) {
|
||||
if(!expansion_test_app_send_heartbeat(instance)) break;
|
||||
if(!expansion_test_app_receive_frame(instance, &instance->frame)) break;
|
||||
if(instance->frame.header.type != ExpansionFrameTypeHeartbeat) break;
|
||||
furi_delay_ms(EXPANSION_PROTOCOL_TIMEOUT_MS - 50);
|
||||
}
|
||||
|
||||
return num_cycles_done == num_cycles;
|
||||
}
|
||||
|
||||
static bool expansion_test_app_stop_rpc(ExpansionTestApp* instance) {
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
if(!expansion_test_app_send_control_request(instance, ExpansionFrameControlCommandStopRpc))
|
||||
break;
|
||||
if(!expansion_test_app_receive_frame(instance, &instance->frame)) break;
|
||||
if(!expansion_test_app_is_success_response(&instance->frame)) break;
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
int32_t expansion_test_app(void* p) {
|
||||
UNUSED(p);
|
||||
|
||||
ExpansionTestApp* instance = expansion_test_app_alloc();
|
||||
expansion_test_app_start(instance);
|
||||
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
if(!expansion_test_app_send_presence(instance)) break;
|
||||
if(!expansion_test_app_wait_ready(instance)) break;
|
||||
if(!expansion_test_app_handshake(instance)) break;
|
||||
if(!expansion_test_app_start_rpc(instance)) break;
|
||||
if(!expansion_test_app_rpc_mkdir(instance)) break;
|
||||
if(!expansion_test_app_rpc_write(instance)) break;
|
||||
if(!expansion_test_app_rpc_alert(instance)) break;
|
||||
if(!expansion_test_app_idle(instance, 10)) break;
|
||||
if(!expansion_test_app_stop_rpc(instance)) break;
|
||||
if(!expansion_test_app_idle(instance, 10)) break;
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
expansion_test_app_stop(instance);
|
||||
expansion_test_app_free(instance);
|
||||
|
||||
if(!success) {
|
||||
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
|
||||
notification_message(notification, &sequence_error);
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,13 +1,14 @@
|
|||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include <notification/notification.h>
|
||||
#include <notification/notification_messages.h>
|
||||
#include <gui/elements.h>
|
||||
#include <furi_hal_uart.h>
|
||||
#include <furi_hal_console.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
|
||||
#include <notification/notification.h>
|
||||
#include <notification/notification_messages.h>
|
||||
|
||||
#define LINES_ON_SCREEN 6
|
||||
#define COLUMNS_ON_SCREEN 21
|
||||
#define TAG "UartEcho"
|
||||
|
@ -22,6 +23,7 @@ typedef struct {
|
|||
View* view;
|
||||
FuriThread* worker_thread;
|
||||
FuriStreamBuffer* rx_stream;
|
||||
FuriHalSerialHandle* serial_handle;
|
||||
} UartEchoApp;
|
||||
|
||||
typedef struct {
|
||||
|
@ -39,10 +41,16 @@ struct UartDumpModel {
|
|||
typedef enum {
|
||||
WorkerEventReserved = (1 << 0), // Reserved for StreamBuffer internal event
|
||||
WorkerEventStop = (1 << 1),
|
||||
WorkerEventRx = (1 << 2),
|
||||
WorkerEventRxData = (1 << 2),
|
||||
WorkerEventRxIdle = (1 << 3),
|
||||
WorkerEventRxOverrunError = (1 << 4),
|
||||
WorkerEventRxFramingError = (1 << 5),
|
||||
WorkerEventRxNoiseError = (1 << 6),
|
||||
} WorkerEventFlags;
|
||||
|
||||
#define WORKER_EVENTS_MASK (WorkerEventStop | WorkerEventRx)
|
||||
#define WORKER_EVENTS_MASK \
|
||||
(WorkerEventStop | WorkerEventRxData | WorkerEventRxIdle | WorkerEventRxOverrunError | \
|
||||
WorkerEventRxFramingError | WorkerEventRxNoiseError)
|
||||
|
||||
const NotificationSequence sequence_notification = {
|
||||
&message_display_backlight_on,
|
||||
|
@ -91,14 +99,39 @@ static uint32_t uart_echo_exit(void* context) {
|
|||
return VIEW_NONE;
|
||||
}
|
||||
|
||||
static void uart_echo_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
|
||||
static void
|
||||
uart_echo_on_irq_cb(FuriHalSerialHandle* handle, FuriHalSerialRxEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
UNUSED(handle);
|
||||
UartEchoApp* app = context;
|
||||
volatile FuriHalSerialRxEvent event_copy = event;
|
||||
UNUSED(event_copy);
|
||||
|
||||
if(ev == UartIrqEventRXNE) {
|
||||
WorkerEventFlags flag = 0;
|
||||
|
||||
if(event & FuriHalSerialRxEventData) {
|
||||
uint8_t data = furi_hal_serial_async_rx(handle);
|
||||
furi_stream_buffer_send(app->rx_stream, &data, 1, 0);
|
||||
furi_thread_flags_set(furi_thread_get_id(app->worker_thread), WorkerEventRx);
|
||||
flag |= WorkerEventRxData;
|
||||
}
|
||||
|
||||
if(event & FuriHalSerialRxEventIdle) {
|
||||
//idle line detected, packet transmission may have ended
|
||||
flag |= WorkerEventRxIdle;
|
||||
}
|
||||
|
||||
//error detected
|
||||
if(event & FuriHalSerialRxEventFrameError) {
|
||||
flag |= WorkerEventRxFramingError;
|
||||
}
|
||||
if(event & FuriHalSerialRxEventNoiseError) {
|
||||
flag |= WorkerEventRxNoiseError;
|
||||
}
|
||||
if(event & FuriHalSerialRxEventOverrunError) {
|
||||
flag |= WorkerEventRxOverrunError;
|
||||
}
|
||||
|
||||
furi_thread_flags_set(furi_thread_get_id(app->worker_thread), flag);
|
||||
}
|
||||
|
||||
static void uart_echo_push_to_list(UartDumpModel* model, const char data) {
|
||||
|
@ -153,13 +186,13 @@ static int32_t uart_echo_worker(void* context) {
|
|||
furi_check((events & FuriFlagError) == 0);
|
||||
|
||||
if(events & WorkerEventStop) break;
|
||||
if(events & WorkerEventRx) {
|
||||
if(events & WorkerEventRxData) {
|
||||
size_t length = 0;
|
||||
do {
|
||||
uint8_t data[64];
|
||||
length = furi_stream_buffer_receive(app->rx_stream, data, 64, 0);
|
||||
if(length > 0) {
|
||||
furi_hal_uart_tx(FuriHalUartIdUSART1, data, length);
|
||||
furi_hal_serial_tx(app->serial_handle, data, length);
|
||||
with_view_model(
|
||||
app->view,
|
||||
UartDumpModel * model,
|
||||
|
@ -176,6 +209,23 @@ static int32_t uart_echo_worker(void* context) {
|
|||
with_view_model(
|
||||
app->view, UartDumpModel * model, { UNUSED(model); }, true);
|
||||
}
|
||||
|
||||
if(events & WorkerEventRxIdle) {
|
||||
furi_hal_serial_tx(app->serial_handle, (uint8_t*)"\r\nDetect IDLE\r\n", 15);
|
||||
}
|
||||
|
||||
if(events &
|
||||
(WorkerEventRxOverrunError | WorkerEventRxFramingError | WorkerEventRxNoiseError)) {
|
||||
if(events & WorkerEventRxOverrunError) {
|
||||
furi_hal_serial_tx(app->serial_handle, (uint8_t*)"\r\nDetect ORE\r\n", 14);
|
||||
}
|
||||
if(events & WorkerEventRxFramingError) {
|
||||
furi_hal_serial_tx(app->serial_handle, (uint8_t*)"\r\nDetect FE\r\n", 13);
|
||||
}
|
||||
if(events & WorkerEventRxNoiseError) {
|
||||
furi_hal_serial_tx(app->serial_handle, (uint8_t*)"\r\nDetect NE\r\n", 13);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -221,9 +271,11 @@ static UartEchoApp* uart_echo_app_alloc(uint32_t baudrate) {
|
|||
furi_thread_start(app->worker_thread);
|
||||
|
||||
// Enable uart listener
|
||||
furi_hal_console_disable();
|
||||
furi_hal_uart_set_br(FuriHalUartIdUSART1, baudrate);
|
||||
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, uart_echo_on_irq_cb, app);
|
||||
app->serial_handle = furi_hal_serial_control_acquire(FuriHalSerialIdUsart);
|
||||
furi_check(app->serial_handle);
|
||||
furi_hal_serial_init(app->serial_handle, baudrate);
|
||||
|
||||
furi_hal_serial_async_rx_start(app->serial_handle, uart_echo_on_irq_cb, app, true);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
@ -231,12 +283,13 @@ static UartEchoApp* uart_echo_app_alloc(uint32_t baudrate) {
|
|||
static void uart_echo_app_free(UartEchoApp* app) {
|
||||
furi_assert(app);
|
||||
|
||||
furi_hal_console_enable(); // this will also clear IRQ callback so thread is no longer referenced
|
||||
|
||||
furi_thread_flags_set(furi_thread_get_id(app->worker_thread), WorkerEventStop);
|
||||
furi_thread_join(app->worker_thread);
|
||||
furi_thread_free(app->worker_thread);
|
||||
|
||||
furi_hal_serial_deinit(app->serial_handle);
|
||||
furi_hal_serial_control_release(app->serial_handle);
|
||||
|
||||
// Free views
|
||||
view_dispatcher_remove_view(app->view_dispatcher, 0);
|
||||
|
||||
|
|
157
applications/debug/unit_tests/expansion/expansion_test.c
Normal file
157
applications/debug/unit_tests/expansion/expansion_test.c
Normal file
|
@ -0,0 +1,157 @@
|
|||
#include "../minunit.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <expansion/expansion_protocol.h>
|
||||
|
||||
MU_TEST(test_expansion_encoded_size) {
|
||||
ExpansionFrame frame = {};
|
||||
|
||||
frame.header.type = ExpansionFrameTypeHeartbeat;
|
||||
mu_assert_int_eq(1, expansion_frame_get_encoded_size(&frame));
|
||||
|
||||
frame.header.type = ExpansionFrameTypeStatus;
|
||||
mu_assert_int_eq(2, expansion_frame_get_encoded_size(&frame));
|
||||
|
||||
frame.header.type = ExpansionFrameTypeBaudRate;
|
||||
mu_assert_int_eq(5, expansion_frame_get_encoded_size(&frame));
|
||||
|
||||
frame.header.type = ExpansionFrameTypeControl;
|
||||
mu_assert_int_eq(2, expansion_frame_get_encoded_size(&frame));
|
||||
|
||||
frame.header.type = ExpansionFrameTypeData;
|
||||
for(size_t i = 0; i <= EXPANSION_PROTOCOL_MAX_DATA_SIZE; ++i) {
|
||||
frame.content.data.size = i;
|
||||
mu_assert_int_eq(i + 2, expansion_frame_get_encoded_size(&frame));
|
||||
}
|
||||
}
|
||||
|
||||
MU_TEST(test_expansion_remaining_size) {
|
||||
ExpansionFrame frame = {};
|
||||
|
||||
mu_assert_int_eq(1, expansion_frame_get_remaining_size(&frame, 0));
|
||||
|
||||
frame.header.type = ExpansionFrameTypeHeartbeat;
|
||||
mu_assert_int_eq(1, expansion_frame_get_remaining_size(&frame, 0));
|
||||
mu_assert_int_eq(0, expansion_frame_get_remaining_size(&frame, 1));
|
||||
mu_assert_int_eq(0, expansion_frame_get_remaining_size(&frame, 100));
|
||||
|
||||
frame.header.type = ExpansionFrameTypeStatus;
|
||||
mu_assert_int_eq(1, expansion_frame_get_remaining_size(&frame, 0));
|
||||
mu_assert_int_eq(1, expansion_frame_get_remaining_size(&frame, 1));
|
||||
mu_assert_int_eq(0, expansion_frame_get_remaining_size(&frame, 2));
|
||||
mu_assert_int_eq(0, expansion_frame_get_remaining_size(&frame, 100));
|
||||
|
||||
frame.header.type = ExpansionFrameTypeBaudRate;
|
||||
mu_assert_int_eq(1, expansion_frame_get_remaining_size(&frame, 0));
|
||||
mu_assert_int_eq(4, expansion_frame_get_remaining_size(&frame, 1));
|
||||
mu_assert_int_eq(0, expansion_frame_get_remaining_size(&frame, 5));
|
||||
mu_assert_int_eq(0, expansion_frame_get_remaining_size(&frame, 100));
|
||||
|
||||
frame.header.type = ExpansionFrameTypeControl;
|
||||
mu_assert_int_eq(1, expansion_frame_get_remaining_size(&frame, 0));
|
||||
mu_assert_int_eq(1, expansion_frame_get_remaining_size(&frame, 1));
|
||||
mu_assert_int_eq(0, expansion_frame_get_remaining_size(&frame, 2));
|
||||
mu_assert_int_eq(0, expansion_frame_get_remaining_size(&frame, 100));
|
||||
|
||||
frame.header.type = ExpansionFrameTypeData;
|
||||
frame.content.data.size = EXPANSION_PROTOCOL_MAX_DATA_SIZE;
|
||||
mu_assert_int_eq(1, expansion_frame_get_remaining_size(&frame, 0));
|
||||
mu_assert_int_eq(1, expansion_frame_get_remaining_size(&frame, 1));
|
||||
mu_assert_int_eq(
|
||||
EXPANSION_PROTOCOL_MAX_DATA_SIZE, expansion_frame_get_remaining_size(&frame, 2));
|
||||
for(size_t i = 0; i <= EXPANSION_PROTOCOL_MAX_DATA_SIZE; ++i) {
|
||||
mu_assert_int_eq(
|
||||
EXPANSION_PROTOCOL_MAX_DATA_SIZE - i,
|
||||
expansion_frame_get_remaining_size(&frame, i + 2));
|
||||
}
|
||||
mu_assert_int_eq(0, expansion_frame_get_remaining_size(&frame, 100));
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
void* data_out;
|
||||
size_t size_available;
|
||||
size_t size_sent;
|
||||
} TestExpansionSendStream;
|
||||
|
||||
static size_t test_expansion_send_callback(const uint8_t* data, size_t data_size, void* context) {
|
||||
TestExpansionSendStream* stream = context;
|
||||
const size_t size_sent = MIN(data_size, stream->size_available);
|
||||
|
||||
memcpy(stream->data_out + stream->size_sent, data, size_sent);
|
||||
|
||||
stream->size_available -= size_sent;
|
||||
stream->size_sent += size_sent;
|
||||
|
||||
return size_sent;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
const void* data_in;
|
||||
size_t size_available;
|
||||
size_t size_received;
|
||||
} TestExpansionReceiveStream;
|
||||
|
||||
static size_t test_expansion_receive_callback(uint8_t* data, size_t data_size, void* context) {
|
||||
TestExpansionReceiveStream* stream = context;
|
||||
const size_t size_received = MIN(data_size, stream->size_available);
|
||||
|
||||
memcpy(data, stream->data_in + stream->size_received, size_received);
|
||||
|
||||
stream->size_available -= size_received;
|
||||
stream->size_received += size_received;
|
||||
|
||||
return size_received;
|
||||
}
|
||||
|
||||
MU_TEST(test_expansion_encode_decode_frame) {
|
||||
const ExpansionFrame frame_in = {
|
||||
.header.type = ExpansionFrameTypeData,
|
||||
.content.data.size = 8,
|
||||
.content.data.bytes = {0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed, 0xca, 0xfe},
|
||||
};
|
||||
|
||||
uint8_t encoded_data[sizeof(ExpansionFrame) + sizeof(ExpansionFrameChecksum)];
|
||||
memset(encoded_data, 0, sizeof(encoded_data));
|
||||
|
||||
TestExpansionSendStream send_stream = {
|
||||
.data_out = &encoded_data,
|
||||
.size_available = sizeof(encoded_data),
|
||||
.size_sent = 0,
|
||||
};
|
||||
|
||||
const size_t encoded_size = expansion_frame_get_encoded_size(&frame_in);
|
||||
|
||||
mu_assert_int_eq(
|
||||
expansion_protocol_encode(&frame_in, test_expansion_send_callback, &send_stream),
|
||||
ExpansionProtocolStatusOk);
|
||||
mu_assert_int_eq(encoded_size + sizeof(ExpansionFrameChecksum), send_stream.size_sent);
|
||||
mu_assert_int_eq(
|
||||
expansion_protocol_get_checksum((const uint8_t*)&frame_in, encoded_size),
|
||||
encoded_data[encoded_size]);
|
||||
mu_assert_mem_eq(&frame_in, &encoded_data, encoded_size);
|
||||
|
||||
TestExpansionReceiveStream stream = {
|
||||
.data_in = encoded_data,
|
||||
.size_available = send_stream.size_sent,
|
||||
.size_received = 0,
|
||||
};
|
||||
|
||||
ExpansionFrame frame_out;
|
||||
|
||||
mu_assert_int_eq(
|
||||
expansion_protocol_decode(&frame_out, test_expansion_receive_callback, &stream),
|
||||
ExpansionProtocolStatusOk);
|
||||
mu_assert_int_eq(encoded_size + sizeof(ExpansionFrameChecksum), stream.size_received);
|
||||
mu_assert_mem_eq(&frame_in, &frame_out, encoded_size);
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(test_expansion_suite) {
|
||||
MU_RUN_TEST(test_expansion_encoded_size);
|
||||
MU_RUN_TEST(test_expansion_remaining_size);
|
||||
MU_RUN_TEST(test_expansion_encode_decode_frame);
|
||||
}
|
||||
|
||||
int run_minunit_test_expansion() {
|
||||
MU_RUN_SUITE(test_expansion_suite);
|
||||
return MU_EXIT_CODE;
|
||||
}
|
|
@ -1,8 +1,11 @@
|
|||
#include "furi_hal_rtc.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <lp5562_reg.h>
|
||||
#include "../minunit.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define DATA_SIZE 4
|
||||
#define EEPROM_ADDRESS 0b10101000
|
||||
|
@ -211,6 +214,37 @@ MU_TEST(furi_hal_i2c_ext_eeprom) {
|
|||
}
|
||||
}
|
||||
|
||||
MU_TEST(furi_hal_rtc_timestamp2datetime_min) {
|
||||
uint32_t test_value = 0;
|
||||
FuriHalRtcDateTime min_datetime_expected = {0, 0, 0, 1, 1, 1970, 0};
|
||||
|
||||
FuriHalRtcDateTime result = {0};
|
||||
furi_hal_rtc_timestamp_to_datetime(test_value, &result);
|
||||
|
||||
mu_assert_mem_eq(&min_datetime_expected, &result, sizeof(result));
|
||||
}
|
||||
|
||||
MU_TEST(furi_hal_rtc_timestamp2datetime_max) {
|
||||
uint32_t test_value = UINT32_MAX;
|
||||
FuriHalRtcDateTime max_datetime_expected = {6, 28, 15, 7, 2, 2106, 0};
|
||||
|
||||
FuriHalRtcDateTime result = {0};
|
||||
furi_hal_rtc_timestamp_to_datetime(test_value, &result);
|
||||
|
||||
mu_assert_mem_eq(&max_datetime_expected, &result, sizeof(result));
|
||||
}
|
||||
|
||||
MU_TEST(furi_hal_rtc_timestamp2datetime2timestamp) {
|
||||
uint32_t test_value = random();
|
||||
|
||||
FuriHalRtcDateTime datetime = {0};
|
||||
furi_hal_rtc_timestamp_to_datetime(test_value, &datetime);
|
||||
|
||||
uint32_t result = furi_hal_rtc_datetime_to_timestamp(&datetime);
|
||||
|
||||
mu_assert_int_eq(test_value, result);
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(furi_hal_i2c_int_suite) {
|
||||
MU_SUITE_CONFIGURE(&furi_hal_i2c_int_setup, &furi_hal_i2c_int_teardown);
|
||||
MU_RUN_TEST(furi_hal_i2c_int_1b);
|
||||
|
@ -224,8 +258,15 @@ MU_TEST_SUITE(furi_hal_i2c_ext_suite) {
|
|||
MU_RUN_TEST(furi_hal_i2c_ext_eeprom);
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(furi_hal_rtc_datetime_suite) {
|
||||
MU_RUN_TEST(furi_hal_rtc_timestamp2datetime_min);
|
||||
MU_RUN_TEST(furi_hal_rtc_timestamp2datetime_max);
|
||||
MU_RUN_TEST(furi_hal_rtc_timestamp2datetime2timestamp);
|
||||
}
|
||||
|
||||
int run_minunit_test_furi_hal() {
|
||||
MU_RUN_SUITE(furi_hal_i2c_int_suite);
|
||||
MU_RUN_SUITE(furi_hal_i2c_ext_suite);
|
||||
MU_RUN_SUITE(furi_hal_rtc_datetime_suite);
|
||||
return MU_EXIT_CODE;
|
||||
}
|
||||
|
|
|
@ -209,6 +209,25 @@ const int8_t indala26_test_timings[INDALA26_EMULATION_TIMINGS_COUNT] = {
|
|||
-1, 1, -1, 1, -1, 1, -1, 1,
|
||||
};
|
||||
|
||||
#define FDXB_TEST_DATA \
|
||||
{ 0x44, 0x88, 0x23, 0xF2, 0x5A, 0x6F, 0x00, 0x01, 0x00, 0x00, 0x00 }
|
||||
#define FDXB_TEST_DATA_SIZE 11
|
||||
#define FDXB_TEST_EMULATION_TIMINGS_COUNT (206)
|
||||
|
||||
const int8_t fdxb_test_timings[FDXB_TEST_EMULATION_TIMINGS_COUNT] = {
|
||||
32, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16,
|
||||
-16, 16, -32, 16, -16, 32, -16, 16, -16, 16, -16, 16, -32, 16, -16, 16, -16, 32, -32,
|
||||
16, -16, 16, -16, 16, -16, 32, -16, 16, -16, 16, -16, 16, -32, 16, -16, 16, -16, 32,
|
||||
-16, 16, -16, 16, -16, 16, -32, 32, -32, 32, -32, 32, -32, 16, -16, 16, -16, 32, -16,
|
||||
16, -32, 16, -16, 32, -16, 16, -32, 32, -16, 16, -32, 16, -16, 32, -16, 16, -32, 32,
|
||||
-16, 16, -32, 32, -32, 32, -32, 16, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16, -16,
|
||||
16, -16, 16, -16, 32, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16,
|
||||
-32, 32, -32, 32, -32, 32, -32, 16, -16, 32, -32, 32, -16, 16, -16, 16, -32, 32, -32,
|
||||
32, -32, 32, -32, 16, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16,
|
||||
-16, 32, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16, -32,
|
||||
16, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16, -16, 16, -16,
|
||||
};
|
||||
|
||||
MU_TEST(test_lfrfid_protocol_em_read_simple) {
|
||||
ProtocolDict* dict = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax);
|
||||
mu_assert_int_eq(EM_TEST_DATA_SIZE, protocol_dict_get_data_size(dict, LFRFIDProtocolEM4100));
|
||||
|
@ -445,6 +464,73 @@ MU_TEST(test_lfrfid_protocol_inadala26_emulate_simple) {
|
|||
protocol_dict_free(dict);
|
||||
}
|
||||
|
||||
MU_TEST(test_lfrfid_protocol_fdxb_emulate_simple) {
|
||||
ProtocolDict* dict = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax);
|
||||
mu_assert_int_eq(FDXB_TEST_DATA_SIZE, protocol_dict_get_data_size(dict, LFRFIDProtocolFDXB));
|
||||
mu_assert_string_eq("FDX-B", protocol_dict_get_name(dict, LFRFIDProtocolFDXB));
|
||||
mu_assert_string_eq("ISO", protocol_dict_get_manufacturer(dict, LFRFIDProtocolFDXB));
|
||||
|
||||
const uint8_t data[FDXB_TEST_DATA_SIZE] = FDXB_TEST_DATA;
|
||||
|
||||
protocol_dict_set_data(dict, LFRFIDProtocolFDXB, data, FDXB_TEST_DATA_SIZE);
|
||||
mu_check(protocol_dict_encoder_start(dict, LFRFIDProtocolFDXB));
|
||||
|
||||
for(size_t i = 0; i < FDXB_TEST_EMULATION_TIMINGS_COUNT; i++) {
|
||||
LevelDuration level_duration = protocol_dict_encoder_yield(dict, LFRFIDProtocolFDXB);
|
||||
|
||||
if(level_duration_get_level(level_duration)) {
|
||||
mu_assert_int_eq(fdxb_test_timings[i], level_duration_get_duration(level_duration));
|
||||
} else {
|
||||
mu_assert_int_eq(fdxb_test_timings[i], -level_duration_get_duration(level_duration));
|
||||
}
|
||||
}
|
||||
|
||||
protocol_dict_free(dict);
|
||||
}
|
||||
|
||||
MU_TEST(test_lfrfid_protocol_fdxb_read_simple) {
|
||||
ProtocolDict* dict = protocol_dict_alloc(lfrfid_protocols, LFRFIDProtocolMax);
|
||||
mu_assert_int_eq(FDXB_TEST_DATA_SIZE, protocol_dict_get_data_size(dict, LFRFIDProtocolFDXB));
|
||||
mu_assert_string_eq("FDX-B", protocol_dict_get_name(dict, LFRFIDProtocolFDXB));
|
||||
mu_assert_string_eq("ISO", protocol_dict_get_manufacturer(dict, LFRFIDProtocolFDXB));
|
||||
|
||||
const uint8_t data[FDXB_TEST_DATA_SIZE] = FDXB_TEST_DATA;
|
||||
|
||||
protocol_dict_decoders_start(dict);
|
||||
|
||||
ProtocolId protocol = PROTOCOL_NO;
|
||||
PulseGlue* pulse_glue = pulse_glue_alloc();
|
||||
|
||||
for(size_t i = 0; i < FDXB_TEST_EMULATION_TIMINGS_COUNT * 10; i++) {
|
||||
bool pulse_pop = pulse_glue_push(
|
||||
pulse_glue,
|
||||
fdxb_test_timings[i % FDXB_TEST_EMULATION_TIMINGS_COUNT] >= 0,
|
||||
abs(fdxb_test_timings[i % FDXB_TEST_EMULATION_TIMINGS_COUNT]) *
|
||||
LF_RFID_READ_TIMING_MULTIPLIER);
|
||||
|
||||
if(pulse_pop) {
|
||||
uint32_t length, period;
|
||||
pulse_glue_pop(pulse_glue, &length, &period);
|
||||
|
||||
protocol = protocol_dict_decoders_feed(dict, true, period);
|
||||
if(protocol != PROTOCOL_NO) break;
|
||||
|
||||
protocol = protocol_dict_decoders_feed(dict, false, length - period);
|
||||
if(protocol != PROTOCOL_NO) break;
|
||||
}
|
||||
}
|
||||
|
||||
pulse_glue_free(pulse_glue);
|
||||
|
||||
mu_assert_int_eq(LFRFIDProtocolFDXB, protocol);
|
||||
uint8_t received_data[FDXB_TEST_DATA_SIZE] = {0};
|
||||
protocol_dict_get_data(dict, protocol, received_data, FDXB_TEST_DATA_SIZE);
|
||||
|
||||
mu_assert_mem_eq(data, received_data, FDXB_TEST_DATA_SIZE);
|
||||
|
||||
protocol_dict_free(dict);
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(test_lfrfid_protocols_suite) {
|
||||
MU_RUN_TEST(test_lfrfid_protocol_em_read_simple);
|
||||
MU_RUN_TEST(test_lfrfid_protocol_em_emulate_simple);
|
||||
|
@ -456,6 +542,9 @@ MU_TEST_SUITE(test_lfrfid_protocols_suite) {
|
|||
MU_RUN_TEST(test_lfrfid_protocol_ioprox_xsf_emulate_simple);
|
||||
|
||||
MU_RUN_TEST(test_lfrfid_protocol_inadala26_emulate_simple);
|
||||
|
||||
MU_RUN_TEST(test_lfrfid_protocol_fdxb_read_simple);
|
||||
MU_RUN_TEST(test_lfrfid_protocol_fdxb_emulate_simple);
|
||||
}
|
||||
|
||||
int run_minunit_test_lfrfid_protocols() {
|
||||
|
|
|
@ -29,6 +29,7 @@ int run_minunit_test_bit_lib();
|
|||
int run_minunit_test_float_tools();
|
||||
int run_minunit_test_bt();
|
||||
int run_minunit_test_dialogs_file_browser_options();
|
||||
int run_minunit_test_expansion();
|
||||
|
||||
typedef int (*UnitTestEntry)();
|
||||
|
||||
|
@ -60,6 +61,7 @@ const UnitTest unit_tests[] = {
|
|||
{.name = "bt", .entry = run_minunit_test_bt},
|
||||
{.name = "dialogs_file_browser_options",
|
||||
.entry = run_minunit_test_dialogs_file_browser_options},
|
||||
{.name = "expansion", .entry = run_minunit_test_expansion},
|
||||
};
|
||||
|
||||
void minunit_print_progress() {
|
||||
|
|
|
@ -48,7 +48,6 @@ typedef enum {
|
|||
SubGhzDeviceCC1101ExtStateIdle, /**< Idle, energy save mode */
|
||||
SubGhzDeviceCC1101ExtStateAsyncRx, /**< Async RX started */
|
||||
SubGhzDeviceCC1101ExtStateAsyncTx, /**< Async TX started, DMA and timer is on */
|
||||
SubGhzDeviceCC1101ExtStateAsyncTxEnd, /**< Async TX complete, cleanup needed */
|
||||
} SubGhzDeviceCC1101ExtState;
|
||||
|
||||
/** SubGhz regulation, receive transmission on the current frequency for the
|
||||
|
@ -417,6 +416,9 @@ void subghz_device_cc1101_ext_reset() {
|
|||
void subghz_device_cc1101_ext_idle() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_switch_to_idle(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
//waiting for the chip to switch to IDLE mode
|
||||
furi_check(cc1101_wait_status_state(
|
||||
subghz_device_cc1101_ext->spi_bus_handle, CC1101StateIDLE, 10000));
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
if(subghz_device_cc1101_ext->power_amp) {
|
||||
furi_hal_gpio_write(SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO, 0);
|
||||
|
@ -426,6 +428,9 @@ void subghz_device_cc1101_ext_idle() {
|
|||
void subghz_device_cc1101_ext_rx() {
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_switch_to_rx(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
//waiting for the chip to switch to Rx mode
|
||||
furi_check(
|
||||
cc1101_wait_status_state(subghz_device_cc1101_ext->spi_bus_handle, CC1101StateRX, 10000));
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
if(subghz_device_cc1101_ext->power_amp) {
|
||||
furi_hal_gpio_write(SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO, 0);
|
||||
|
@ -436,6 +441,9 @@ bool subghz_device_cc1101_ext_tx() {
|
|||
if(subghz_device_cc1101_ext->regulation != SubGhzDeviceCC1101ExtRegulationTxRx) return false;
|
||||
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
cc1101_switch_to_tx(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
//waiting for the chip to switch to Tx mode
|
||||
furi_check(
|
||||
cc1101_wait_status_state(subghz_device_cc1101_ext->spi_bus_handle, CC1101StateTX, 10000));
|
||||
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
|
||||
if(subghz_device_cc1101_ext->power_amp) {
|
||||
furi_hal_gpio_write(SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO, 1);
|
||||
|
@ -706,7 +714,6 @@ static void subghz_device_cc1101_ext_async_tx_refill(uint32_t* buffer, size_t sa
|
|||
if(LL_DMA_IsActiveFlag_TC3(SUBGHZ_DEVICE_CC1101_EXT_DMA)) {
|
||||
LL_DMA_ClearFlag_TC3(SUBGHZ_DEVICE_CC1101_EXT_DMA);
|
||||
}
|
||||
LL_TIM_EnableIT_UPDATE(TIM17);
|
||||
break;
|
||||
} else {
|
||||
// Lowest possible value is 4us
|
||||
|
@ -742,22 +749,6 @@ static void subghz_device_cc1101_ext_async_tx_dma_isr() {
|
|||
#endif
|
||||
}
|
||||
|
||||
static void subghz_device_cc1101_ext_async_tx_timer_isr() {
|
||||
if(LL_TIM_IsActiveFlag_UPDATE(TIM17)) {
|
||||
if(LL_TIM_GetAutoReload(TIM17) == 0) {
|
||||
if(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTx) {
|
||||
LL_DMA_DisableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
|
||||
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateAsyncTxEnd;
|
||||
furi_hal_gpio_write(subghz_device_cc1101_ext->g0_pin, false);
|
||||
if(subghz_device_cc1101_ext->async_mirror_pin != NULL)
|
||||
furi_hal_gpio_write(subghz_device_cc1101_ext->async_mirror_pin, false);
|
||||
LL_TIM_DisableCounter(TIM17);
|
||||
}
|
||||
}
|
||||
LL_TIM_ClearFlag_UPDATE(TIM17);
|
||||
}
|
||||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_start_async_tx(SubGhzDeviceCC1101ExtCallback callback, void* context) {
|
||||
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateIdle);
|
||||
furi_assert(callback);
|
||||
|
@ -786,7 +777,7 @@ bool subghz_device_cc1101_ext_start_async_tx(SubGhzDeviceCC1101ExtCallback callb
|
|||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF,
|
||||
LL_DMA_DIRECTION_MEMORY_TO_PERIPH | LL_DMA_MODE_CIRCULAR | LL_DMA_PERIPH_NOINCREMENT |
|
||||
LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_WORD | LL_DMA_MDATAALIGN_WORD |
|
||||
LL_DMA_MODE_NORMAL);
|
||||
LL_DMA_PRIORITY_VERYHIGH);
|
||||
LL_DMA_SetDataLength(
|
||||
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF, SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL);
|
||||
LL_DMA_SetPeriphRequest(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF, LL_DMAMUX_REQ_TIM17_UP);
|
||||
|
@ -809,9 +800,6 @@ bool subghz_device_cc1101_ext_start_async_tx(SubGhzDeviceCC1101ExtCallback callb
|
|||
LL_TIM_SetClockSource(TIM17, LL_TIM_CLOCKSOURCE_INTERNAL);
|
||||
LL_TIM_DisableARRPreload(TIM17);
|
||||
|
||||
furi_hal_interrupt_set_isr(
|
||||
FuriHalInterruptIdTim1TrgComTim17, subghz_device_cc1101_ext_async_tx_timer_isr, NULL);
|
||||
|
||||
subghz_device_cc1101_ext_async_tx_middleware_idle(
|
||||
&subghz_device_cc1101_ext->async_tx.middleware);
|
||||
subghz_device_cc1101_ext_async_tx_refill(
|
||||
|
@ -869,22 +857,21 @@ bool subghz_device_cc1101_ext_start_async_tx(SubGhzDeviceCC1101ExtCallback callb
|
|||
}
|
||||
|
||||
bool subghz_device_cc1101_ext_is_async_tx_complete() {
|
||||
return subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTxEnd;
|
||||
return (
|
||||
(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTx) &&
|
||||
(LL_TIM_GetAutoReload(TIM17) == 0));
|
||||
}
|
||||
|
||||
void subghz_device_cc1101_ext_stop_async_tx() {
|
||||
furi_assert(
|
||||
subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTx ||
|
||||
subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTxEnd);
|
||||
|
||||
// Deinitialize GPIO
|
||||
furi_hal_gpio_write(subghz_device_cc1101_ext->g0_pin, false);
|
||||
furi_hal_gpio_init(
|
||||
subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullDown, GpioSpeedLow);
|
||||
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTx);
|
||||
|
||||
// Shutdown radio
|
||||
subghz_device_cc1101_ext_idle();
|
||||
|
||||
// Deinitialize GPIO
|
||||
furi_hal_gpio_write(subghz_device_cc1101_ext->g0_pin, false);
|
||||
furi_hal_gpio_init(subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
// Deinitialize Timer
|
||||
furi_hal_bus_disable(FuriHalBusTIM17);
|
||||
furi_hal_interrupt_set_isr(FuriHalInterruptIdTim1TrgComTim17, NULL, NULL);
|
||||
|
|
|
@ -153,7 +153,9 @@ void archive_update_focus(ArchiveBrowserView* browser, const char* target) {
|
|||
|
||||
archive_get_items(browser, furi_string_get_cstr(browser->path));
|
||||
|
||||
if(!archive_file_get_array_size(browser) && archive_is_home(browser)) {
|
||||
ArchiveTabEnum tab = archive_get_tab(browser);
|
||||
if(!archive_file_get_array_size(browser) && archive_is_home(browser) &&
|
||||
(tab != ArchiveTabBrowser)) {
|
||||
archive_switch_tab(browser, TAB_LEFT);
|
||||
} else {
|
||||
with_view_model(
|
||||
|
@ -220,7 +222,8 @@ void archive_file_array_rm_selected(ArchiveBrowserView* browser) {
|
|||
},
|
||||
false);
|
||||
|
||||
if((items_cnt == 0) && (archive_is_home(browser))) {
|
||||
ArchiveTabEnum tab = archive_get_tab(browser);
|
||||
if((items_cnt == 0) && (archive_is_home(browser)) && (tab != ArchiveTabBrowser)) {
|
||||
archive_switch_tab(browser, TAB_LEFT);
|
||||
}
|
||||
|
||||
|
|
|
@ -585,6 +585,10 @@ static bool archive_view_input(InputEvent* event, void* context) {
|
|||
((model->item_idx - scroll_speed) + model->item_cnt) %
|
||||
model->item_cnt;
|
||||
}
|
||||
// Fix for empty folders, we can't select -1 item
|
||||
if(model->item_idx < 0) {
|
||||
model->item_idx = 0;
|
||||
}
|
||||
if(is_file_list_load_required(model)) {
|
||||
model->list_loading = true;
|
||||
browser->callback(ArchiveBrowserEventLoadPrevItems, browser->context);
|
||||
|
|
Binary file not shown.
|
@ -3,7 +3,7 @@ App(
|
|||
name="GPIO",
|
||||
apptype=FlipperAppType.MENUEXTERNAL,
|
||||
entry_point="gpio_app",
|
||||
stack_size=1 * 1024,
|
||||
stack_size=2 * 1024,
|
||||
icon="A_GPIO_14",
|
||||
order=50,
|
||||
fap_libs=["assets"],
|
||||
|
|
|
@ -70,7 +70,12 @@ GpioApp* gpio_app_alloc() {
|
|||
GpioAppViewUsbUartCfg,
|
||||
variable_item_list_get_view(app->var_item_list));
|
||||
|
||||
scene_manager_next_scene(app->scene_manager, GpioSceneStart);
|
||||
if(furi_hal_serial_control_is_busy(FuriHalSerialIdUsart) ||
|
||||
furi_hal_serial_control_is_busy(FuriHalSerialIdLpuart)) {
|
||||
scene_manager_next_scene(app->scene_manager, GpioSceneErrorExpansion);
|
||||
} else {
|
||||
scene_manager_next_scene(app->scene_manager, GpioSceneStart);
|
||||
}
|
||||
|
||||
return app;
|
||||
}
|
||||
|
|
|
@ -3,4 +3,5 @@ ADD_SCENE(gpio, test, Test)
|
|||
ADD_SCENE(gpio, usb_uart, UsbUart)
|
||||
ADD_SCENE(gpio, usb_uart_cfg, UsbUartCfg)
|
||||
ADD_SCENE(gpio, usb_uart_close_rpc, UsbUartCloseRpc)
|
||||
ADD_SCENE(gpio, error_expansion, ErrorExpansion)
|
||||
ADD_SCENE(gpio, exit_confirm, ExitConfirm)
|
||||
|
|
43
applications/main/gpio/scenes/gpio_scene_error_expansion.c
Normal file
43
applications/main/gpio/scenes/gpio_scene_error_expansion.c
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "../gpio_app_i.h"
|
||||
#include "../gpio_custom_event.h"
|
||||
|
||||
void gpio_scene_error_expansion_on_enter(void* context) {
|
||||
GpioApp* app = context;
|
||||
|
||||
widget_add_icon_element(app->widget, 78, 0, &I_ActiveConnection_50x64);
|
||||
widget_add_string_multiline_element(
|
||||
app->widget, 3, 2, AlignLeft, AlignTop, FontPrimary, "Ext. Module\nis connected!");
|
||||
widget_add_string_multiline_element(
|
||||
app->widget,
|
||||
3,
|
||||
30,
|
||||
AlignLeft,
|
||||
AlignTop,
|
||||
FontSecondary,
|
||||
"Disconnect External\n"
|
||||
"Module\n"
|
||||
"to use this function.");
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewUsbUartCloseRpc);
|
||||
}
|
||||
|
||||
bool gpio_scene_error_expansion_on_event(void* context, SceneManagerEvent event) {
|
||||
GpioApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GpioCustomEventErrorBack) {
|
||||
if(!scene_manager_previous_scene(app->scene_manager)) {
|
||||
scene_manager_stop(app->scene_manager);
|
||||
view_dispatcher_stop(app->view_dispatcher);
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void gpio_scene_error_expansion_on_exit(void* context) {
|
||||
GpioApp* app = context;
|
||||
widget_reset(app->widget);
|
||||
}
|
|
@ -46,7 +46,7 @@ void line_ensure_flow_invariant(GpioApp* app) {
|
|||
// selected. This function enforces that invariant by resetting flow_pins
|
||||
// to None if it is configured to 16,15 when LPUART is selected.
|
||||
|
||||
uint8_t available_flow_pins = app->usb_uart_cfg->uart_ch == FuriHalUartIdLPUART1 ? 3 : 4;
|
||||
uint8_t available_flow_pins = app->usb_uart_cfg->uart_ch == FuriHalSerialIdLpuart ? 3 : 4;
|
||||
VariableItem* item = app->var_item_flow;
|
||||
variable_item_set_values_count(item, available_flow_pins);
|
||||
|
||||
|
@ -77,9 +77,9 @@ static void line_port_cb(VariableItem* item) {
|
|||
variable_item_set_current_value_text(item, uart_ch[index]);
|
||||
|
||||
if(index == 0)
|
||||
app->usb_uart_cfg->uart_ch = FuriHalUartIdUSART1;
|
||||
app->usb_uart_cfg->uart_ch = FuriHalSerialIdUsart;
|
||||
else if(index == 1)
|
||||
app->usb_uart_cfg->uart_ch = FuriHalUartIdLPUART1;
|
||||
app->usb_uart_cfg->uart_ch = FuriHalSerialIdLpuart;
|
||||
|
||||
line_ensure_flow_invariant(app);
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, GpioUsbUartEventConfigSet);
|
||||
|
|
|
@ -29,17 +29,18 @@ typedef enum {
|
|||
|
||||
WorkerEvtTxStop = (1 << 2),
|
||||
WorkerEvtCdcRx = (1 << 3),
|
||||
WorkerEvtCdcTxComplete = (1 << 4),
|
||||
|
||||
WorkerEvtCfgChange = (1 << 4),
|
||||
WorkerEvtCfgChange = (1 << 5),
|
||||
|
||||
WorkerEvtLineCfgSet = (1 << 5),
|
||||
WorkerEvtCtrlLineSet = (1 << 6),
|
||||
WorkerEvtLineCfgSet = (1 << 6),
|
||||
WorkerEvtCtrlLineSet = (1 << 7),
|
||||
|
||||
} WorkerEvtFlags;
|
||||
|
||||
#define WORKER_ALL_RX_EVENTS \
|
||||
(WorkerEvtStop | WorkerEvtRxDone | WorkerEvtCfgChange | WorkerEvtLineCfgSet | \
|
||||
WorkerEvtCtrlLineSet)
|
||||
WorkerEvtCtrlLineSet | WorkerEvtCdcTxComplete)
|
||||
#define WORKER_ALL_TX_EVENTS (WorkerEvtTxStop | WorkerEvtCdcRx)
|
||||
|
||||
struct UsbUartBridge {
|
||||
|
@ -50,6 +51,7 @@ struct UsbUartBridge {
|
|||
FuriThread* tx_thread;
|
||||
|
||||
FuriStreamBuffer* rx_stream;
|
||||
FuriHalSerialHandle* serial_handle;
|
||||
|
||||
FuriMutex* usb_mutex;
|
||||
|
||||
|
@ -80,11 +82,23 @@ static const CdcCallbacks cdc_cb = {
|
|||
|
||||
static int32_t usb_uart_tx_thread(void* context);
|
||||
|
||||
static void usb_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
|
||||
static void usb_uart_on_irq_rx_dma_cb(
|
||||
FuriHalSerialHandle* handle,
|
||||
FuriHalSerialRxEvent ev,
|
||||
size_t size,
|
||||
void* context) {
|
||||
UsbUartBridge* usb_uart = (UsbUartBridge*)context;
|
||||
|
||||
if(ev == UartIrqEventRXNE) {
|
||||
furi_stream_buffer_send(usb_uart->rx_stream, &data, 1, 0);
|
||||
if(ev & (FuriHalSerialRxEventData | FuriHalSerialRxEventIdle)) {
|
||||
uint8_t data[FURI_HAL_SERIAL_DMA_BUFFER_SIZE] = {0};
|
||||
while(size) {
|
||||
size_t ret = furi_hal_serial_dma_rx(
|
||||
handle,
|
||||
data,
|
||||
(size > FURI_HAL_SERIAL_DMA_BUFFER_SIZE) ? FURI_HAL_SERIAL_DMA_BUFFER_SIZE : size);
|
||||
furi_stream_buffer_send(usb_uart->rx_stream, data, ret, 0);
|
||||
size -= ret;
|
||||
};
|
||||
furi_thread_flags_set(furi_thread_get_id(usb_uart->thread), WorkerEvtRxDone);
|
||||
}
|
||||
}
|
||||
|
@ -116,32 +130,33 @@ static void usb_uart_vcp_deinit(UsbUartBridge* usb_uart, uint8_t vcp_ch) {
|
|||
}
|
||||
|
||||
static void usb_uart_serial_init(UsbUartBridge* usb_uart, uint8_t uart_ch) {
|
||||
if(uart_ch == FuriHalUartIdUSART1) {
|
||||
furi_hal_console_disable();
|
||||
} else if(uart_ch == FuriHalUartIdLPUART1) {
|
||||
furi_hal_uart_init(uart_ch, 115200);
|
||||
}
|
||||
furi_hal_uart_set_irq_cb(uart_ch, usb_uart_on_irq_cb, usb_uart);
|
||||
furi_assert(!usb_uart->serial_handle);
|
||||
|
||||
usb_uart->serial_handle = furi_hal_serial_control_acquire(uart_ch);
|
||||
furi_assert(usb_uart->serial_handle);
|
||||
|
||||
furi_hal_serial_init(usb_uart->serial_handle, 115200);
|
||||
furi_hal_serial_dma_rx_start(
|
||||
usb_uart->serial_handle, usb_uart_on_irq_rx_dma_cb, usb_uart, false);
|
||||
}
|
||||
|
||||
static void usb_uart_serial_deinit(UsbUartBridge* usb_uart, uint8_t uart_ch) {
|
||||
UNUSED(usb_uart);
|
||||
furi_hal_uart_set_irq_cb(uart_ch, NULL, NULL);
|
||||
if(uart_ch == FuriHalUartIdUSART1)
|
||||
furi_hal_console_enable();
|
||||
else if(uart_ch == FuriHalUartIdLPUART1)
|
||||
furi_hal_uart_deinit(uart_ch);
|
||||
static void usb_uart_serial_deinit(UsbUartBridge* usb_uart) {
|
||||
furi_assert(usb_uart->serial_handle);
|
||||
|
||||
furi_hal_serial_deinit(usb_uart->serial_handle);
|
||||
furi_hal_serial_control_release(usb_uart->serial_handle);
|
||||
usb_uart->serial_handle = NULL;
|
||||
}
|
||||
|
||||
static void usb_uart_set_baudrate(UsbUartBridge* usb_uart, uint32_t baudrate) {
|
||||
if(baudrate != 0) {
|
||||
furi_hal_uart_set_br(usb_uart->cfg.uart_ch, baudrate);
|
||||
furi_hal_serial_set_br(usb_uart->serial_handle, baudrate);
|
||||
usb_uart->st.baudrate_cur = baudrate;
|
||||
} else {
|
||||
struct usb_cdc_line_coding* line_cfg =
|
||||
furi_hal_cdc_get_port_settings(usb_uart->cfg.vcp_ch);
|
||||
if(line_cfg->dwDTERate > 0) {
|
||||
furi_hal_uart_set_br(usb_uart->cfg.uart_ch, line_cfg->dwDTERate);
|
||||
furi_hal_serial_set_br(usb_uart->serial_handle, line_cfg->dwDTERate);
|
||||
usb_uart->st.baudrate_cur = line_cfg->dwDTERate;
|
||||
}
|
||||
}
|
||||
|
@ -191,7 +206,7 @@ static int32_t usb_uart_worker(void* context) {
|
|||
furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever);
|
||||
furi_check(!(events & FuriFlagError));
|
||||
if(events & WorkerEvtStop) break;
|
||||
if(events & WorkerEvtRxDone) {
|
||||
if(events & (WorkerEvtRxDone | WorkerEvtCdcTxComplete)) {
|
||||
size_t len = furi_stream_buffer_receive(
|
||||
usb_uart->rx_stream, usb_uart->rx_buf, USB_CDC_PKT_LEN, 0);
|
||||
if(len > 0) {
|
||||
|
@ -223,7 +238,7 @@ static int32_t usb_uart_worker(void* context) {
|
|||
furi_thread_flags_set(furi_thread_get_id(usb_uart->tx_thread), WorkerEvtTxStop);
|
||||
furi_thread_join(usb_uart->tx_thread);
|
||||
|
||||
usb_uart_serial_deinit(usb_uart, usb_uart->cfg.uart_ch);
|
||||
usb_uart_serial_deinit(usb_uart);
|
||||
usb_uart_serial_init(usb_uart, usb_uart->cfg_new.uart_ch);
|
||||
|
||||
usb_uart->cfg.uart_ch = usb_uart->cfg_new.uart_ch;
|
||||
|
@ -274,7 +289,7 @@ static int32_t usb_uart_worker(void* context) {
|
|||
}
|
||||
}
|
||||
usb_uart_vcp_deinit(usb_uart, usb_uart->cfg.vcp_ch);
|
||||
usb_uart_serial_deinit(usb_uart, usb_uart->cfg.uart_ch);
|
||||
usb_uart_serial_deinit(usb_uart);
|
||||
|
||||
furi_hal_gpio_init(USB_USART_DE_RE_PIN, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
|
@ -320,18 +335,10 @@ static int32_t usb_uart_tx_thread(void* context) {
|
|||
if(usb_uart->cfg.software_de_re != 0)
|
||||
furi_hal_gpio_write(USB_USART_DE_RE_PIN, false);
|
||||
|
||||
furi_hal_uart_tx(usb_uart->cfg.uart_ch, data, len);
|
||||
furi_hal_serial_tx(usb_uart->serial_handle, data, len);
|
||||
|
||||
if(usb_uart->cfg.software_de_re != 0) {
|
||||
//TODO: FL-3276 port to new USART API
|
||||
if(usb_uart->cfg.uart_ch == FuriHalUartIdUSART1) {
|
||||
while(!LL_USART_IsActiveFlag_TC(USART1))
|
||||
;
|
||||
} else if(usb_uart->cfg.uart_ch == FuriHalUartIdLPUART1) {
|
||||
while(!LL_LPUART_IsActiveFlag_TC(LPUART1))
|
||||
;
|
||||
}
|
||||
|
||||
furi_hal_serial_tx_wait_complete(usb_uart->serial_handle);
|
||||
furi_hal_gpio_write(USB_USART_DE_RE_PIN, true);
|
||||
}
|
||||
}
|
||||
|
@ -345,6 +352,7 @@ static int32_t usb_uart_tx_thread(void* context) {
|
|||
static void vcp_on_cdc_tx_complete(void* context) {
|
||||
UsbUartBridge* usb_uart = (UsbUartBridge*)context;
|
||||
furi_semaphore_release(usb_uart->tx_sem);
|
||||
furi_thread_flags_set(furi_thread_get_id(usb_uart->thread), WorkerEvtCdcTxComplete);
|
||||
}
|
||||
|
||||
static void vcp_on_cdc_rx(void* context) {
|
||||
|
|
|
@ -1,6 +1,30 @@
|
|||
#include "lfrfid_i.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
//TODO: use .txt file in resources for passwords.
|
||||
const uint32_t default_passwords[] = {
|
||||
0x51243648, 0x000D8787, 0x19920427, 0x50524F58, 0xF9DCEBA0, 0x65857569, 0x05D73B9F, 0x89A69E60,
|
||||
0x314159E0, 0xAA55BBBB, 0xA5B4C3D2, 0x1C0B5848, 0x00434343, 0x444E4752, 0x4E457854, 0x44B44CAE,
|
||||
0x88661858, 0xE9920427, 0x575F4F4B, 0x50520901, 0x20206666, 0x65857569, 0x5469616E, 0x7686962A,
|
||||
0xC0F5009A, 0x07CEE75D, 0xfeedbeef, 0xdeadc0de, 0x00000000, 0x11111111, 0x22222222, 0x33333333,
|
||||
0x44444444, 0x55555555, 0x66666666, 0x77777777, 0x88888888, 0x99999999, 0xAAAAAAAA, 0xBBBBBBBB,
|
||||
0xCCCCCCCC, 0xDDDDDDDD, 0xEEEEEEEE, 0xFFFFFFFF, 0xa0a1a2a3, 0xb0b1b2b3, 0x50415353, 0x00000001,
|
||||
0x00000002, 0x0000000a, 0x0000000b, 0x01020304, 0x02030405, 0x03040506, 0x04050607, 0x05060708,
|
||||
0x06070809, 0x0708090A, 0x08090A0B, 0x090A0B0C, 0x0A0B0C0D, 0x0B0C0D0E, 0x0C0D0E0F, 0x01234567,
|
||||
0x12345678, 0x10000000, 0x20000000, 0x30000000, 0x40000000, 0x50000000, 0x60000000, 0x70000000,
|
||||
0x80000000, 0x90000000, 0xA0000000, 0xB0000000, 0xC0000000, 0xD0000000, 0xE0000000, 0xF0000000,
|
||||
0x10101010, 0x01010101, 0x11223344, 0x22334455, 0x33445566, 0x44556677, 0x55667788, 0x66778899,
|
||||
0x778899AA, 0x8899AABB, 0x99AABBCC, 0xAABBCCDD, 0xBBCCDDEE, 0xCCDDEEFF, 0x0CB7E7FC, 0xFABADA11,
|
||||
0x87654321, 0x12341234, 0x69696969, 0x12121212, 0x12344321, 0x1234ABCD, 0x11112222, 0x13131313,
|
||||
0x10041004, 0x31415926, 0xabcd1234, 0x20002000, 0x19721972, 0xaa55aa55, 0x55aa55aa, 0x4f271149,
|
||||
0x07d7bb0b, 0x9636ef8f, 0xb5f44686, 0x9E3779B9, 0xC6EF3720, 0x7854794A, 0xF1EA5EED, 0x69314718,
|
||||
0x57721566, 0x93C467E3, 0x27182818, 0x50415353};
|
||||
|
||||
const uint32_t* lfrfid_get_t5577_default_passwords(uint8_t* len) {
|
||||
*len = sizeof(default_passwords) / sizeof(uint32_t);
|
||||
return default_passwords;
|
||||
}
|
||||
|
||||
static bool lfrfid_debug_custom_event_callback(void* context, uint32_t event) {
|
||||
furi_assert(context);
|
||||
LfRfid* app = context;
|
||||
|
|
|
@ -25,11 +25,13 @@ void lfrfid_on_system_start() {
|
|||
|
||||
static void lfrfid_cli_print_usage() {
|
||||
printf("Usage:\r\n");
|
||||
printf("rfid read <optional: normal | indala>\r\n");
|
||||
printf("rfid <write | emulate> <key_type> <key_data>\r\n");
|
||||
printf("rfid raw_read <ask | psk> <filename>\r\n");
|
||||
printf("rfid raw_emulate <filename>\r\n");
|
||||
printf("rfid raw_analyze <filename>\r\n");
|
||||
printf("rfid read <optional: normal | indala> - read in ASK/PSK mode\r\n");
|
||||
printf("rfid <write | emulate> <key_type> <key_data> - write or emulate a card\r\n");
|
||||
printf("rfid raw_read <ask | psk> <filename> - read and save raw data to a file\r\n");
|
||||
printf(
|
||||
"rfid raw_emulate <filename> - emulate raw data (not very useful, but helps debug protocols)\r\n");
|
||||
printf(
|
||||
"rfid raw_analyze <filename> - outputs raw data to the cli and tries to decode it (useful for protocol development)\r\n");
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -98,6 +98,8 @@ struct LfRfid {
|
|||
uint8_t* old_key_data;
|
||||
uint8_t* new_key_data;
|
||||
|
||||
uint8_t password[4];
|
||||
|
||||
RpcAppSystem* rpc_ctx;
|
||||
LfRfidRpcState rpc_state;
|
||||
|
||||
|
@ -145,3 +147,5 @@ void lfrfid_popup_timeout_callback(void* context);
|
|||
void lfrfid_widget_callback(GuiButtonType result, InputType type, void* context);
|
||||
|
||||
void lfrfid_text_input_callback(void* context);
|
||||
|
||||
const uint32_t* lfrfid_get_t5577_default_passwords(uint8_t* len);
|
|
@ -1,4 +1,5 @@
|
|||
#include "../lfrfid_i.h"
|
||||
#include "tools/t5577.h"
|
||||
#define TAG "Clear T5577"
|
||||
|
||||
static void lfrfid_clear_t5577_password_and_config_to_EM(LfRfid* app) {
|
||||
|
@ -6,7 +7,7 @@ static void lfrfid_clear_t5577_password_and_config_to_EM(LfRfid* app) {
|
|||
char curr_buf[32] = {};
|
||||
|
||||
uint8_t default_passwords_len;
|
||||
const uint32_t* default_passwords = t5577_get_default_passwords(&default_passwords_len);
|
||||
const uint32_t* default_passwords = lfrfid_get_t5577_default_passwords(&default_passwords_len);
|
||||
|
||||
popup_set_header(popup, "Removing\npassword", 90, 36, AlignCenter, AlignCenter);
|
||||
popup_set_icon(popup, 0, 3, &I_RFIDDolphinSend_97x61);
|
||||
|
@ -15,14 +16,26 @@ static void lfrfid_clear_t5577_password_and_config_to_EM(LfRfid* app) {
|
|||
|
||||
LFRFIDT5577 data = {
|
||||
.block[0] = 0b00000000000101001000000001000000,
|
||||
.blocks_to_write = 1,
|
||||
.block[7] = 0,
|
||||
.mask = 0b10000001,
|
||||
};
|
||||
|
||||
// Clear custom password
|
||||
uint32_t custom_pass = (app->password[0] << 24) | (app->password[1] << 16) |
|
||||
(app->password[2] << 8) | (app->password[3]);
|
||||
snprintf(curr_buf, sizeof(curr_buf), "Custom password");
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewPopup);
|
||||
|
||||
t5577_write_with_mask(&data, 0, true, custom_pass);
|
||||
|
||||
furi_delay_ms(8);
|
||||
|
||||
// Clear default passwords
|
||||
for(uint8_t i = 0; i < default_passwords_len; i++) {
|
||||
snprintf(curr_buf, sizeof(curr_buf), "Pass %d of %d", i, default_passwords_len);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewPopup);
|
||||
|
||||
t5577_write_with_pass(&data, default_passwords[i]);
|
||||
t5577_write_with_mask(&data, 0, true, default_passwords[i]);
|
||||
furi_delay_ms(8);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ ADD_SCENE(lfrfid, exit_confirm, ExitConfirm)
|
|||
ADD_SCENE(lfrfid, delete_confirm, DeleteConfirm)
|
||||
ADD_SCENE(lfrfid, read_key_menu, ReadKeyMenu)
|
||||
ADD_SCENE(lfrfid, write, Write)
|
||||
ADD_SCENE(lfrfid, write_with_pass, WriteWithPass)
|
||||
ADD_SCENE(lfrfid, write_and_set_pass, WriteAndSetPass)
|
||||
ADD_SCENE(lfrfid, write_success, WriteSuccess)
|
||||
ADD_SCENE(lfrfid, emulate, Emulate)
|
||||
ADD_SCENE(lfrfid, save_name, SaveName)
|
||||
|
@ -18,6 +18,7 @@ ADD_SCENE(lfrfid, save_type, SaveType)
|
|||
ADD_SCENE(lfrfid, saved_info, SavedInfo)
|
||||
ADD_SCENE(lfrfid, clear_t5577, ClearT5577)
|
||||
ADD_SCENE(lfrfid, clear_t5577_confirm, ClearT5577Confirm)
|
||||
ADD_SCENE(lfrfid, enter_password, EnterPassword)
|
||||
ADD_SCENE(lfrfid, delete_success, DeleteSuccess)
|
||||
ADD_SCENE(lfrfid, extra_actions, ExtraActions)
|
||||
ADD_SCENE(lfrfid, raw_info, RawInfo)
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
#include "../lfrfid_i.h"
|
||||
#include "gui/scene_manager.h"
|
||||
|
||||
int next_scene;
|
||||
|
||||
void lfrfid_scene_enter_password_on_enter(void* context) {
|
||||
LfRfid* app = context;
|
||||
ByteInput* byte_input = app->byte_input;
|
||||
|
||||
// true - use password for write, false - use password for clear pass
|
||||
next_scene = scene_manager_get_scene_state(app->scene_manager, LfRfidSceneEnterPassword);
|
||||
|
||||
bool password_set = app->password[0] | app->password[1] | app->password[2] | app->password[3];
|
||||
|
||||
if(next_scene == LfRfidSceneWriteAndSetPass && !password_set) {
|
||||
uint8_t password_list_size;
|
||||
const uint32_t* password_list = lfrfid_get_t5577_default_passwords(&password_list_size);
|
||||
uint32_t pass = password_list[furi_get_tick() % password_list_size];
|
||||
|
||||
for(uint8_t i = 0; i < 4; i++) app->password[i] = (pass >> (8 * i)) & 0xFF;
|
||||
}
|
||||
|
||||
byte_input_set_header_text(byte_input, "Enter the password in hex");
|
||||
|
||||
byte_input_set_result_callback(
|
||||
byte_input, lfrfid_text_input_callback, NULL, app, app->password, 4);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewByteInput);
|
||||
}
|
||||
|
||||
bool lfrfid_scene_enter_password_on_event(void* context, SceneManagerEvent event) {
|
||||
LfRfid* app = context;
|
||||
SceneManager* scene_manager = app->scene_manager;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == LfRfidEventNext) {
|
||||
consumed = true;
|
||||
|
||||
scene_manager_next_scene(scene_manager, next_scene);
|
||||
scene_manager_set_scene_state(scene_manager, LfRfidSceneEnterPassword, 1);
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeBack) {
|
||||
uint32_t prev_scenes[] = {LfRfidSceneExtraActions, LfRfidSceneSavedKeyMenu};
|
||||
scene_manager_set_scene_state(scene_manager, LfRfidSceneEnterPassword, 0);
|
||||
scene_manager_search_and_switch_to_previous_scene_one_of(
|
||||
scene_manager, prev_scenes, sizeof(prev_scenes[0]));
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void lfrfid_scene_enter_password_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
}
|
|
@ -80,7 +80,9 @@ bool lfrfid_scene_extra_actions_on_event(void* context, SceneManagerEvent event)
|
|||
dolphin_deed(DolphinDeedRfidRead);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexClearT5577) {
|
||||
scene_manager_next_scene(app->scene_manager, LfRfidSceneClearT5577Confirm);
|
||||
scene_manager_set_scene_state(
|
||||
app->scene_manager, LfRfidSceneEnterPassword, LfRfidSceneClearT5577Confirm);
|
||||
scene_manager_next_scene(app->scene_manager, LfRfidSceneEnterPassword);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexRAW) {
|
||||
scene_manager_next_scene(app->scene_manager, LfRfidSceneRawName);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
typedef enum {
|
||||
SubmenuIndexEmulate,
|
||||
SubmenuIndexWrite,
|
||||
SubmenuIndexWriteWithPass,
|
||||
SubmenuIndexWriteAndSetPass,
|
||||
SubmenuIndexEdit,
|
||||
SubmenuIndexDelete,
|
||||
SubmenuIndexInfo,
|
||||
|
@ -26,8 +26,8 @@ void lfrfid_scene_saved_key_menu_on_enter(void* context) {
|
|||
submenu, "Write", SubmenuIndexWrite, lfrfid_scene_saved_key_menu_submenu_callback, app);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Write with pass",
|
||||
SubmenuIndexWriteWithPass,
|
||||
"Write and set pass",
|
||||
SubmenuIndexWriteAndSetPass,
|
||||
lfrfid_scene_saved_key_menu_submenu_callback,
|
||||
app);
|
||||
submenu_add_item(
|
||||
|
@ -55,8 +55,10 @@ bool lfrfid_scene_saved_key_menu_on_event(void* context, SceneManagerEvent event
|
|||
} else if(event.event == SubmenuIndexWrite) {
|
||||
scene_manager_next_scene(app->scene_manager, LfRfidSceneWrite);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexWriteWithPass) {
|
||||
scene_manager_next_scene(app->scene_manager, LfRfidSceneWriteWithPass);
|
||||
} else if(event.event == SubmenuIndexWriteAndSetPass) {
|
||||
scene_manager_set_scene_state(
|
||||
app->scene_manager, LfRfidSceneEnterPassword, LfRfidSceneWriteAndSetPass);
|
||||
scene_manager_next_scene(app->scene_manager, LfRfidSceneEnterPassword);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexEdit) {
|
||||
scene_manager_next_scene(app->scene_manager, LfRfidSceneSaveData);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "../lfrfid_i.h"
|
||||
#include "gui/scene_manager.h"
|
||||
|
||||
static void lfrfid_write_with_pass_callback(LFRFIDWorkerWriteResult result, void* context) {
|
||||
static void lfrfid_write_and_set_pass_callback(LFRFIDWorkerWriteResult result, void* context) {
|
||||
LfRfid* app = context;
|
||||
uint32_t event = 0;
|
||||
|
||||
|
@ -17,22 +18,11 @@ static void lfrfid_write_with_pass_callback(LFRFIDWorkerWriteResult result, void
|
|||
view_dispatcher_send_custom_event(app->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void lfrfid_scene_write_with_pass_on_enter(void* context) {
|
||||
void lfrfid_scene_write_and_set_pass_on_enter(void* context) {
|
||||
LfRfid* app = context;
|
||||
Popup* popup = app->popup;
|
||||
|
||||
popup_set_header(popup, "Writing", 89, 30, AlignCenter, AlignTop);
|
||||
if(!furi_string_empty(app->file_name)) {
|
||||
popup_set_text(popup, furi_string_get_cstr(app->file_name), 89, 43, AlignCenter, AlignTop);
|
||||
} else {
|
||||
popup_set_text(
|
||||
popup,
|
||||
protocol_dict_get_name(app->dict, app->protocol_id),
|
||||
89,
|
||||
43,
|
||||
AlignCenter,
|
||||
AlignTop);
|
||||
}
|
||||
popup_set_header(popup, "Writing\nwith password", 89, 30, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 3, &I_RFIDDolphinSend_97x61);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewPopup);
|
||||
|
@ -41,12 +31,12 @@ void lfrfid_scene_write_with_pass_on_enter(void* context) {
|
|||
protocol_dict_get_data(app->dict, app->protocol_id, app->old_key_data, size);
|
||||
|
||||
lfrfid_worker_start_thread(app->lfworker);
|
||||
lfrfid_worker_write_with_pass_start(
|
||||
app->lfworker, (LFRFIDProtocol)app->protocol_id, lfrfid_write_with_pass_callback, app);
|
||||
lfrfid_worker_write_and_set_pass_start(
|
||||
app->lfworker, (LFRFIDProtocol)app->protocol_id, lfrfid_write_and_set_pass_callback, app);
|
||||
notification_message(app->notifications, &sequence_blink_start_magenta);
|
||||
}
|
||||
|
||||
bool lfrfid_scene_write_with_pass_on_event(void* context, SceneManagerEvent event) {
|
||||
bool lfrfid_scene_write_and_set_pass_on_event(void* context, SceneManagerEvent event) {
|
||||
LfRfid* app = context;
|
||||
Popup* popup = app->popup;
|
||||
bool consumed = false;
|
||||
|
@ -82,7 +72,7 @@ bool lfrfid_scene_write_with_pass_on_event(void* context, SceneManagerEvent even
|
|||
return consumed;
|
||||
}
|
||||
|
||||
void lfrfid_scene_write_with_pass_on_exit(void* context) {
|
||||
void lfrfid_scene_write_and_set_pass_on_exit(void* context) {
|
||||
LfRfid* app = context;
|
||||
notification_message(app->notifications, &sequence_blink_stop);
|
||||
popup_reset(app->popup);
|
|
@ -18,20 +18,20 @@ void nfc_render_iso15693_3_info(
|
|||
}
|
||||
|
||||
void nfc_render_iso15693_3_brief(const Iso15693_3Data* data, FuriString* str) {
|
||||
furi_string_cat_printf(str, "UID:");
|
||||
furi_string_cat_printf(str, "UID:\n");
|
||||
|
||||
size_t uid_len;
|
||||
const uint8_t* uid = iso15693_3_get_uid(data, &uid_len);
|
||||
|
||||
for(size_t i = 0; i < uid_len; i++) {
|
||||
furi_string_cat_printf(str, " %02X", uid[i]);
|
||||
furi_string_cat_printf(str, "%02X ", uid[i]);
|
||||
}
|
||||
|
||||
if(data->system_info.flags & ISO15693_3_SYSINFO_FLAG_MEMORY) {
|
||||
const uint16_t block_count = iso15693_3_get_block_count(data);
|
||||
const uint8_t block_size = iso15693_3_get_block_size(data);
|
||||
|
||||
furi_string_cat_printf(str, "Memory: %u bytes\n", block_count * block_size);
|
||||
furi_string_cat_printf(str, "\nMemory: %u bytes\n", block_count * block_size);
|
||||
furi_string_cat_printf(str, "(%u blocks x %u bytes)", block_count, block_size);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ static void nfc_scene_info_on_enter_mf_classic(NfcApp* instance) {
|
|||
FuriString* temp_str = furi_string_alloc();
|
||||
furi_string_cat_printf(
|
||||
temp_str, "\e#%s\n", nfc_device_get_name(device, NfcDeviceNameTypeFull));
|
||||
furi_string_replace(temp_str, "Mifare", "MIFARE");
|
||||
|
||||
nfc_render_mf_classic_info(data, NfcProtocolFormatTypeFull, temp_str);
|
||||
|
||||
widget_add_text_scroll_element(
|
||||
|
@ -119,13 +121,15 @@ static void nfc_scene_read_menu_on_enter_mf_classic(NfcApp* instance) {
|
|||
}
|
||||
}
|
||||
|
||||
static void nfc_scene_read_success_on_enter_mf_classic(NfcApp* instance) {
|
||||
static void nfc_scene_read_success_on_enter_mf_classic(NfcApp* instance) { //-V524
|
||||
const NfcDevice* device = instance->nfc_device;
|
||||
const MfClassicData* data = nfc_device_get_data(device, NfcProtocolMfClassic);
|
||||
|
||||
FuriString* temp_str = furi_string_alloc();
|
||||
furi_string_cat_printf(
|
||||
temp_str, "\e#%s\n", nfc_device_get_name(device, NfcDeviceNameTypeFull));
|
||||
furi_string_replace(temp_str, "Mifare", "MIFARE");
|
||||
|
||||
nfc_render_mf_classic_info(data, NfcProtocolFormatTypeShort, temp_str);
|
||||
|
||||
widget_add_text_scroll_element(
|
||||
|
@ -168,7 +172,7 @@ static void nfc_scene_emulate_on_enter_mf_classic(NfcApp* instance) {
|
|||
|
||||
static bool nfc_scene_read_menu_on_event_mf_classic(NfcApp* instance, uint32_t event) {
|
||||
if(event == SubmenuIndexDetectReader) {
|
||||
scene_manager_next_scene(instance->scene_manager, NfcSceneMfClassicDetectReader);
|
||||
scene_manager_next_scene(instance->scene_manager, NfcSceneSaveConfirm);
|
||||
dolphin_deed(DolphinDeedNfcDetectReader);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -391,12 +391,15 @@ static void nfc_protocol_support_scene_saved_menu_on_enter(NfcApp* instance) {
|
|||
nfc_protocol_support[protocol]->scene_saved_menu.on_enter(instance);
|
||||
|
||||
// Trailer submenu items
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Info",
|
||||
SubmenuIndexCommonInfo,
|
||||
nfc_protocol_support_common_submenu_callback,
|
||||
instance);
|
||||
if(nfc_has_shadow_file(instance)) {
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Restore to Original State",
|
||||
SubmenuIndexCommonRestore,
|
||||
nfc_protocol_support_common_submenu_callback,
|
||||
instance);
|
||||
}
|
||||
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Rename",
|
||||
|
@ -409,15 +412,12 @@ static void nfc_protocol_support_scene_saved_menu_on_enter(NfcApp* instance) {
|
|||
SubmenuIndexCommonDelete,
|
||||
nfc_protocol_support_common_submenu_callback,
|
||||
instance);
|
||||
|
||||
if(nfc_has_shadow_file(instance)) {
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Restore Data Changes",
|
||||
SubmenuIndexCommonRestore,
|
||||
nfc_protocol_support_common_submenu_callback,
|
||||
instance);
|
||||
}
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Info",
|
||||
SubmenuIndexCommonInfo,
|
||||
nfc_protocol_support_common_submenu_callback,
|
||||
instance);
|
||||
|
||||
submenu_set_selected_item(
|
||||
instance->submenu,
|
||||
|
@ -582,9 +582,18 @@ static void nfc_protocol_support_scene_emulate_on_enter(NfcApp* instance) {
|
|||
|
||||
} else {
|
||||
widget_add_string_element(widget, 90, 13, AlignCenter, AlignTop, FontPrimary, "Emulating");
|
||||
furi_string_set(
|
||||
temp_str, nfc_device_get_name(instance->nfc_device, NfcDeviceNameTypeFull));
|
||||
furi_string_cat_printf(temp_str, "\n%s", furi_string_get_cstr(instance->file_name));
|
||||
if(!furi_string_empty(instance->file_name)) {
|
||||
furi_string_printf(
|
||||
temp_str,
|
||||
"%s\n%s",
|
||||
nfc_device_get_name(instance->nfc_device, NfcDeviceNameTypeFull),
|
||||
furi_string_get_cstr(instance->file_name));
|
||||
} else {
|
||||
furi_string_printf(
|
||||
temp_str,
|
||||
"Unsaved\n%s",
|
||||
nfc_device_get_name(instance->nfc_device, NfcDeviceNameTypeFull));
|
||||
}
|
||||
}
|
||||
|
||||
widget_add_text_box_element(
|
||||
|
|
|
@ -23,6 +23,7 @@ ADD_SCENE(nfc, debug, Debug)
|
|||
ADD_SCENE(nfc, field, Field)
|
||||
ADD_SCENE(nfc, retry_confirm, RetryConfirm)
|
||||
ADD_SCENE(nfc, exit_confirm, ExitConfirm)
|
||||
ADD_SCENE(nfc, save_confirm, SaveConfirm)
|
||||
|
||||
ADD_SCENE(nfc, mf_ultralight_write, MfUltralightWrite)
|
||||
ADD_SCENE(nfc, mf_ultralight_write_success, MfUltralightWriteSuccess)
|
||||
|
|
|
@ -24,7 +24,7 @@ void nfc_scene_extra_actions_on_enter(void* context) {
|
|||
instance);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Mifare Classic Keys",
|
||||
"MIFARE Classic Keys",
|
||||
SubmenuIndexMfClassicKeys,
|
||||
nfc_scene_extra_actions_submenu_callback,
|
||||
instance);
|
||||
|
|
|
@ -134,6 +134,13 @@ bool nfc_scene_mf_classic_detect_reader_on_event(void* context, SceneManagerEven
|
|||
instance->listener = NULL;
|
||||
}
|
||||
mfkey32_logger_free(instance->mfkey32_logger);
|
||||
if(scene_manager_has_previous_scene(instance->scene_manager, NfcSceneSaveSuccess)) {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
instance->scene_manager, NfcSceneStart);
|
||||
} else if(scene_manager_has_previous_scene(instance->scene_manager, NfcSceneReadSuccess)) {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
instance->scene_manager, NfcSceneReadSuccess);
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
|
|
|
@ -18,15 +18,16 @@ void nfc_scene_mf_classic_mfkey_complete_on_enter(void* context) {
|
|||
widget_add_string_multiline_element(
|
||||
instance->widget,
|
||||
64,
|
||||
32,
|
||||
AlignCenter,
|
||||
13,
|
||||
AlignCenter,
|
||||
AlignTop,
|
||||
FontSecondary,
|
||||
"Now use Mfkey32\nto extract keys");
|
||||
"Now use Mfkey32 to extract \nkeys: lab.flipper.net/nfc-tools");
|
||||
widget_add_icon_element(instance->widget, 50, 39, &I_MFKey_qr_25x25);
|
||||
widget_add_button_element(
|
||||
instance->widget,
|
||||
GuiButtonTypeCenter,
|
||||
"OK",
|
||||
GuiButtonTypeRight,
|
||||
"Finish",
|
||||
nfc_scene_mf_classic_mfkey_complete_callback,
|
||||
instance);
|
||||
|
||||
|
@ -38,7 +39,7 @@ bool nfc_scene_mf_classic_mfkey_complete_on_event(void* context, SceneManagerEve
|
|||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GuiButtonTypeCenter) {
|
||||
if(event.event == GuiButtonTypeRight) {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
instance->scene_manager, NfcSceneStart);
|
||||
}
|
||||
|
|
|
@ -65,8 +65,9 @@ static void nfc_scene_mf_classic_write_initial_setup_view(NfcApp* instance) {
|
|||
scene_manager_get_scene_state(instance->scene_manager, NfcSceneMfClassicWriteInitial);
|
||||
|
||||
if(state == NfcSceneMfClassicWriteInitialStateCardSearch) {
|
||||
popup_set_header(instance->popup, "Writing", 95, 20, AlignCenter, AlignCenter);
|
||||
popup_set_text(
|
||||
instance->popup, "Apply the initial\ncard only", 128, 32, AlignRight, AlignCenter);
|
||||
instance->popup, "Apply the initial\ncard only", 95, 38, AlignCenter, AlignCenter);
|
||||
popup_set_icon(instance->popup, 0, 8, &I_NFC_manual_60x50);
|
||||
} else {
|
||||
popup_set_header(popup, "Writing\nDon't move...", 52, 32, AlignLeft, AlignCenter);
|
||||
|
|
|
@ -46,8 +46,9 @@ static void nfc_scene_mf_ultralight_write_setup_view(NfcApp* instance) {
|
|||
scene_manager_get_scene_state(instance->scene_manager, NfcSceneMfUltralightWrite);
|
||||
|
||||
if(state == NfcSceneMfUltralightWriteStateCardSearch) {
|
||||
popup_set_header(instance->popup, "Writing", 95, 20, AlignCenter, AlignCenter);
|
||||
popup_set_text(
|
||||
instance->popup, "Apply the initial\ncard only", 128, 32, AlignRight, AlignCenter);
|
||||
instance->popup, "Apply the initial\ncard only", 95, 38, AlignCenter, AlignCenter);
|
||||
popup_set_icon(instance->popup, 0, 8, &I_NFC_manual_60x50);
|
||||
} else {
|
||||
popup_set_header(popup, "Writing\nDon't move...", 52, 32, AlignLeft, AlignCenter);
|
||||
|
|
44
applications/main/nfc/scenes/nfc_scene_save_confirm.c
Normal file
44
applications/main/nfc/scenes/nfc_scene_save_confirm.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include "../nfc_app_i.h"
|
||||
|
||||
void nfc_scene_save_confirm_dialog_callback(DialogExResult result, void* context) {
|
||||
NfcApp* nfc = context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
|
||||
}
|
||||
|
||||
void nfc_scene_save_confirm_on_enter(void* context) {
|
||||
NfcApp* nfc = context;
|
||||
DialogEx* dialog_ex = nfc->dialog_ex;
|
||||
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Skip");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "Save");
|
||||
dialog_ex_set_header(dialog_ex, "Save the Key?", 64, 0, AlignCenter, AlignTop);
|
||||
dialog_ex_set_text(dialog_ex, "All unsaved data will be lost", 64, 12, AlignCenter, AlignTop);
|
||||
dialog_ex_set_context(dialog_ex, nfc);
|
||||
dialog_ex_set_result_callback(dialog_ex, nfc_scene_save_confirm_dialog_callback);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewDialogEx);
|
||||
}
|
||||
|
||||
bool nfc_scene_save_confirm_on_event(void* context, SceneManagerEvent event) {
|
||||
NfcApp* nfc = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == DialogExResultRight) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveName);
|
||||
consumed = true;
|
||||
} else if(event.event == DialogExResultLeft) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicDetectReader);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void nfc_scene_save_confirm_on_exit(void* context) {
|
||||
NfcApp* nfc = context;
|
||||
|
||||
// Clean view
|
||||
dialog_ex_reset(nfc->dialog_ex);
|
||||
}
|
|
@ -28,6 +28,9 @@ bool nfc_scene_save_success_on_event(void* context, SceneManagerEvent event) {
|
|||
if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneMfClassicKeys)) {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
nfc->scene_manager, NfcSceneMfClassicKeys);
|
||||
} else if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSaveConfirm)) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicDetectReader);
|
||||
consumed = true;
|
||||
} else {
|
||||
consumed = scene_manager_search_and_switch_to_another_scene(
|
||||
nfc->scene_manager, NfcSceneFileSelect);
|
||||
|
|
|
@ -32,10 +32,20 @@ void nfc_scene_set_type_on_enter(void* context) {
|
|||
nfc_protocol_support_common_submenu_callback,
|
||||
instance);
|
||||
|
||||
FuriString* str = furi_string_alloc();
|
||||
for(size_t i = 0; i < NfcDataGeneratorTypeNum; i++) {
|
||||
const char* name = nfc_data_generator_get_name(i);
|
||||
submenu_add_item(submenu, name, i, nfc_protocol_support_common_submenu_callback, instance);
|
||||
furi_string_cat_str(str, nfc_data_generator_get_name(i));
|
||||
furi_string_replace_str(str, "Mifare", "MIFARE");
|
||||
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
furi_string_get_cstr(str),
|
||||
i,
|
||||
nfc_protocol_support_common_submenu_callback,
|
||||
instance);
|
||||
furi_string_reset(str);
|
||||
}
|
||||
furi_string_free(str);
|
||||
|
||||
view_dispatcher_switch_to_view(instance->view_dispatcher, NfcViewMenu);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ static void detect_reader_draw_callback(Canvas* canvas, void* model) {
|
|||
if(m->state == DetectReaderStateDone) {
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str_aligned(canvas, 51, 22, AlignLeft, AlignTop, "Completed!");
|
||||
canvas_draw_icon(canvas, 20, 23, &I_check_big_20x17);
|
||||
canvas_draw_icon(canvas, 24, 23, &I_check_big_20x17);
|
||||
} else {
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str_aligned(canvas, 51, 22, AlignLeft, AlignTop, "Collecting...");
|
||||
|
|
|
@ -24,12 +24,14 @@ typedef enum {
|
|||
SubmenuIndexSommer_FM_868,
|
||||
SubmenuIndexStilmatic,
|
||||
SubmenuIndexDTMNeo433,
|
||||
SubmenuIndexDeaMio433,
|
||||
SubmenuIndexGibidi433,
|
||||
SubmenuIndexNiceMHouse_433_92,
|
||||
SubmenuIndexJCM_433_92,
|
||||
SubmenuIndexFAACRCXT_433_92,
|
||||
SubmenuIndexFAACRCXT_868,
|
||||
SubmenuIndexNormstahl_433_92,
|
||||
SubmenuIndexGeniusBravo433,
|
||||
SubmenuIndexGSN,
|
||||
SubmenuIndexAprimatic,
|
||||
SubmenuIndexHCS101_433_92,
|
||||
|
|
|
@ -81,7 +81,6 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) {
|
|||
uint32_t frequency = 0;
|
||||
float rssi_temp = 0;
|
||||
uint32_t frequency_temp = 0;
|
||||
CC1101Status status;
|
||||
|
||||
FuriHalSpiBusHandle* spi_bus = instance->spi_bus;
|
||||
const SubGhzDevice* radio_device = instance->radio_device;
|
||||
|
@ -143,9 +142,8 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) {
|
|||
frequency = cc1101_set_frequency(spi_bus, current_frequency);
|
||||
|
||||
cc1101_calibrate(spi_bus);
|
||||
do {
|
||||
status = cc1101_get_status(spi_bus);
|
||||
} while(status.STATE != CC1101StateIDLE);
|
||||
|
||||
furi_check(cc1101_wait_status_state(spi_bus, CC1101StateIDLE, 10000));
|
||||
|
||||
cc1101_switch_to_rx(spi_bus);
|
||||
furi_hal_spi_release(spi_bus);
|
||||
|
@ -191,9 +189,8 @@ static int32_t subghz_frequency_analyzer_worker_thread(void* context) {
|
|||
frequency = cc1101_set_frequency(spi_bus, i);
|
||||
|
||||
cc1101_calibrate(spi_bus);
|
||||
do {
|
||||
status = cc1101_get_status(spi_bus);
|
||||
} while(status.STATE != CC1101StateIDLE);
|
||||
|
||||
furi_check(cc1101_wait_status_state(spi_bus, CC1101StateIDLE, 10000));
|
||||
|
||||
cc1101_switch_to_rx(spi_bus);
|
||||
furi_hal_spi_release(spi_bus);
|
||||
|
|
|
@ -63,6 +63,10 @@ bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent e
|
|||
#ifdef FURI_DEBUG
|
||||
subghz_last_settings_log(subghz->last_settings);
|
||||
#endif
|
||||
// Disable Hopping before opening the receiver scene!
|
||||
if(subghz->last_settings->enable_hopping) {
|
||||
subghz->last_settings->enable_hopping = false;
|
||||
}
|
||||
subghz_last_settings_save(subghz->last_settings);
|
||||
}
|
||||
|
||||
|
|
|
@ -165,6 +165,9 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
|
|||
if(subghz_txrx_protocol_is_serializable(subghz->txrx)) {
|
||||
subghz_file_name_clear(subghz);
|
||||
|
||||
subghz->save_datetime =
|
||||
subghz_history_get_datetime(subghz->history, subghz->idx_menu_chosen);
|
||||
subghz->save_datetime_set = true;
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -6,44 +6,12 @@
|
|||
#include <dolphin/dolphin.h>
|
||||
#include <toolbox/name_generator.h>
|
||||
|
||||
#define MAX_TEXT_INPUT_LEN 23
|
||||
|
||||
void subghz_scene_save_name_text_input_callback(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhz* subghz = context;
|
||||
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneSaveName);
|
||||
}
|
||||
|
||||
void subghz_scene_save_name_get_timefilename(
|
||||
FuriString* name,
|
||||
const char* proto_name,
|
||||
bool fulldate) {
|
||||
FuriHalRtcDateTime datetime = {0};
|
||||
furi_hal_rtc_get_datetime(&datetime);
|
||||
if(fulldate) {
|
||||
furi_string_printf(
|
||||
name,
|
||||
"%s_%.4d%.2d%.2d-%.2d%.2d%.2d",
|
||||
proto_name,
|
||||
datetime.year,
|
||||
datetime.month,
|
||||
datetime.day,
|
||||
datetime.hour,
|
||||
datetime.minute,
|
||||
datetime.second);
|
||||
} else {
|
||||
furi_string_printf(
|
||||
name,
|
||||
"%s_%.2d%.2d-%.2d%.2d%.2d",
|
||||
proto_name,
|
||||
datetime.month,
|
||||
datetime.day,
|
||||
datetime.hour,
|
||||
datetime.minute,
|
||||
datetime.second);
|
||||
}
|
||||
}
|
||||
|
||||
void subghz_scene_save_name_on_enter(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
|
||||
|
@ -54,35 +22,33 @@ void subghz_scene_save_name_on_enter(void* context) {
|
|||
FuriString* file_name = furi_string_alloc();
|
||||
FuriString* dir_name = furi_string_alloc();
|
||||
|
||||
char file_name_buf[SUBGHZ_MAX_LEN_NAME] = {0};
|
||||
FuriHalRtcDateTime* datetime = subghz->save_datetime_set ? &subghz->save_datetime : NULL;
|
||||
subghz->save_datetime_set = false;
|
||||
if(!subghz_path_is_file(subghz->file_path)) {
|
||||
char file_name_buf[SUBGHZ_MAX_LEN_NAME] = {0};
|
||||
if(subghz->last_settings->timestamp_file_names) {
|
||||
SubGhzProtocolDecoderBase* decoder_result = subghz_txrx_get_decoder(subghz->txrx);
|
||||
if(decoder_result != 0x0) {
|
||||
if(decoder_result != NULL) {
|
||||
if(strlen(decoder_result->protocol->name) != 0) {
|
||||
if(scene_manager_has_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneSetType)) {
|
||||
subghz_scene_save_name_get_timefilename(file_name, "S", true);
|
||||
} else {
|
||||
subghz_scene_save_name_get_timefilename(
|
||||
file_name, decoder_result->protocol->name, false);
|
||||
}
|
||||
SubGhzProtocolDecoderBase* decoder_result = subghz_txrx_get_decoder(subghz->txrx);
|
||||
|
||||
} else {
|
||||
subghz_scene_save_name_get_timefilename(file_name, "S", true);
|
||||
bool skip_dec_is_present = false;
|
||||
if(decoder_result != 0x0) {
|
||||
if(decoder_result != NULL) {
|
||||
if(strlen(decoder_result->protocol->name) != 0 &&
|
||||
subghz->last_settings->timestamp_file_names) {
|
||||
if(!scene_manager_has_previous_scene(
|
||||
subghz->scene_manager, SubGhzSceneSetType)) {
|
||||
name_generator_make_auto_datetime(
|
||||
file_name_buf,
|
||||
SUBGHZ_MAX_LEN_NAME,
|
||||
decoder_result->protocol->name,
|
||||
datetime);
|
||||
skip_dec_is_present = true;
|
||||
}
|
||||
} else {
|
||||
subghz_scene_save_name_get_timefilename(file_name, "S", true);
|
||||
}
|
||||
} else {
|
||||
subghz_scene_save_name_get_timefilename(file_name, "S", true);
|
||||
}
|
||||
} else {
|
||||
name_generator_make_auto(
|
||||
file_name_buf, SUBGHZ_MAX_LEN_NAME, SUBGHZ_APP_FILENAME_PREFIX);
|
||||
furi_string_set(file_name, file_name_buf);
|
||||
}
|
||||
if(!skip_dec_is_present) {
|
||||
name_generator_make_auto_datetime(file_name_buf, SUBGHZ_MAX_LEN_NAME, NULL, datetime);
|
||||
}
|
||||
furi_string_set(file_name, file_name_buf);
|
||||
furi_string_set(subghz->file_path, SUBGHZ_APP_FOLDER);
|
||||
//highlighting the entire filename by default
|
||||
dev_name_empty = true;
|
||||
|
@ -96,7 +62,9 @@ void subghz_scene_save_name_on_enter(void* context) {
|
|||
if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) ==
|
||||
SubGhzCustomEventManagerSetRAW) {
|
||||
dev_name_empty = true;
|
||||
subghz_scene_save_name_get_timefilename(file_name, "RAW", true);
|
||||
name_generator_make_auto_datetime(
|
||||
file_name_buf, SUBGHZ_MAX_LEN_NAME, "RAW", datetime);
|
||||
furi_string_set(file_name, file_name_buf);
|
||||
}
|
||||
}
|
||||
furi_string_set(subghz->file_path, dir_name);
|
||||
|
@ -109,7 +77,7 @@ void subghz_scene_save_name_on_enter(void* context) {
|
|||
subghz_scene_save_name_text_input_callback,
|
||||
subghz,
|
||||
subghz->file_name_tmp,
|
||||
MAX_TEXT_INPUT_LEN,
|
||||
SUBGHZ_MAX_LEN_NAME,
|
||||
dev_name_empty);
|
||||
|
||||
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
||||
|
|
|
@ -24,5 +24,7 @@ bool subghz_scene_saved_on_event(void* context, SceneManagerEvent event) {
|
|||
}
|
||||
|
||||
void subghz_scene_saved_on_exit(void* context) {
|
||||
SubGhz* subghz = context;
|
||||
scene_manager_set_scene_state(subghz->scene_manager, SubGhzSceneSavedMenu, 0);
|
||||
UNUSED(context);
|
||||
}
|
||||
|
|
|
@ -139,6 +139,12 @@ void subghz_scene_set_type_on_enter(void* context) {
|
|||
SubmenuIndexIronLogic,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"KL: DEA Mio 433MHz",
|
||||
SubmenuIndexDeaMio433,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"KL: DTM Neo 433MHz",
|
||||
|
@ -193,6 +199,12 @@ void subghz_scene_set_type_on_enter(void* context) {
|
|||
SubmenuIndexFAACRCXT_868,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"KL: Genius Bravo 433MHz",
|
||||
SubmenuIndexGeniusBravo433,
|
||||
subghz_scene_set_type_submenu_callback,
|
||||
subghz);
|
||||
submenu_add_item(
|
||||
subghz->submenu,
|
||||
"KL: Nice Mhouse 433MHz",
|
||||
|
@ -747,6 +759,30 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) {
|
|||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexDeaMio433:
|
||||
generated_protocol = subghz_txrx_gen_keeloq_protocol(
|
||||
subghz->txrx,
|
||||
"AM650",
|
||||
433920000,
|
||||
(key & 0x0FFFF000) | 0x00000869,
|
||||
0x2,
|
||||
0x0003,
|
||||
"Dea_Mio");
|
||||
if(!generated_protocol) {
|
||||
furi_string_set(
|
||||
subghz->error_str, "Function requires\nan SD card with\nfresh databases.");
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexGeniusBravo433:
|
||||
generated_protocol = subghz_txrx_gen_keeloq_protocol(
|
||||
subghz->txrx, "AM650", 433920000, key & 0x00FFFFFF, 0x6, 0x0003, "Genius_Bravo");
|
||||
if(!generated_protocol) {
|
||||
furi_string_set(
|
||||
subghz->error_str, "Function requires\nan SD card with\nfresh databases.");
|
||||
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError);
|
||||
}
|
||||
break;
|
||||
case SubmenuIndexJCM_433_92:
|
||||
generated_protocol = subghz_txrx_gen_keeloq_protocol(
|
||||
subghz->txrx, "AM650", 433920000, key & 0x00FFFFFF, 0x2, 0x0003, "JCM_Tech");
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#include <notification/notification_messages.h>
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
|
||||
#include <lib/subghz/blocks/custom_btn.h>
|
||||
|
||||
#define SUBGHZ_FREQUENCY_RANGE_STR \
|
||||
"299999755...348000000 or 386999938...464000000 or 778999847...928000000"
|
||||
|
||||
|
@ -49,6 +51,26 @@ static void subghz_cli_radio_device_power_off() {
|
|||
if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg();
|
||||
}
|
||||
|
||||
static SubGhzEnvironment* subghz_cli_environment_init(void) {
|
||||
SubGhzEnvironment* environment = subghz_environment_alloc();
|
||||
if(subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_NAME)) {
|
||||
printf("Load_keystore keeloq_mfcodes \033[0;32mOK\033[0m\r\n");
|
||||
} else {
|
||||
printf("Load_keystore keeloq_mfcodes \033[0;31mERROR\033[0m\r\n");
|
||||
}
|
||||
if(subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_USER_NAME)) {
|
||||
printf("Load_keystore keeloq_mfcodes_user \033[0;32mOK\033[0m\r\n");
|
||||
} else {
|
||||
printf("Load_keystore keeloq_mfcodes_user \033[0;33mAbsent\033[0m\r\n");
|
||||
}
|
||||
subghz_environment_set_alutech_at_4n_rainbow_table_file_name(
|
||||
environment, SUBGHZ_ALUTECH_AT_4N_DIR_NAME);
|
||||
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||
environment, SUBGHZ_NICE_FLOR_S_DIR_NAME);
|
||||
subghz_environment_set_protocol_registry(environment, (void*)&subghz_protocol_registry);
|
||||
return environment;
|
||||
}
|
||||
|
||||
void subghz_cli_command_tx_carrier(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(context);
|
||||
uint32_t frequency = 433920000;
|
||||
|
@ -323,14 +345,7 @@ void subghz_cli_command_rx(Cli* cli, FuriString* args, void* context) {
|
|||
furi_stream_buffer_alloc(sizeof(LevelDuration) * 1024, sizeof(LevelDuration));
|
||||
furi_check(instance->stream);
|
||||
|
||||
SubGhzEnvironment* environment = subghz_environment_alloc();
|
||||
subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_NAME);
|
||||
subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_USER_NAME);
|
||||
subghz_environment_set_alutech_at_4n_rainbow_table_file_name(
|
||||
environment, SUBGHZ_ALUTECH_AT_4N_DIR_NAME);
|
||||
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||
environment, SUBGHZ_NICE_FLOR_S_DIR_NAME);
|
||||
subghz_environment_set_protocol_registry(environment, (void*)&subghz_protocol_registry);
|
||||
SubGhzEnvironment* environment = subghz_cli_environment_init();
|
||||
|
||||
SubGhzReceiver* receiver = subghz_receiver_alloc_init(environment);
|
||||
subghz_receiver_set_filter(receiver, SubGhzProtocolFlag_Decodable);
|
||||
|
@ -512,23 +527,7 @@ void subghz_cli_command_decode_raw(Cli* cli, FuriString* args, void* context) {
|
|||
// Allocate context
|
||||
SubGhzCliCommandRx* instance = malloc(sizeof(SubGhzCliCommandRx));
|
||||
|
||||
SubGhzEnvironment* environment = subghz_environment_alloc();
|
||||
if(subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_NAME)) {
|
||||
printf("SubGhz decode_raw: Load_keystore keeloq_mfcodes \033[0;32mOK\033[0m\r\n");
|
||||
} else {
|
||||
printf("SubGhz decode_raw: Load_keystore keeloq_mfcodes \033[0;31mERROR\033[0m\r\n");
|
||||
}
|
||||
if(subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_USER_NAME)) {
|
||||
printf("SubGhz decode_raw: Load_keystore keeloq_mfcodes_user \033[0;32mOK\033[0m\r\n");
|
||||
} else {
|
||||
printf(
|
||||
"SubGhz decode_raw: Load_keystore keeloq_mfcodes_user \033[0;31mERROR\033[0m\r\n");
|
||||
}
|
||||
subghz_environment_set_alutech_at_4n_rainbow_table_file_name(
|
||||
environment, SUBGHZ_ALUTECH_AT_4N_DIR_NAME);
|
||||
subghz_environment_set_nice_flor_s_rainbow_table_file_name(
|
||||
environment, SUBGHZ_NICE_FLOR_S_DIR_NAME);
|
||||
subghz_environment_set_protocol_registry(environment, (void*)&subghz_protocol_registry);
|
||||
SubGhzEnvironment* environment = subghz_cli_environment_init();
|
||||
|
||||
SubGhzReceiver* receiver = subghz_receiver_alloc_init(environment);
|
||||
subghz_receiver_set_filter(receiver, SubGhzProtocolFlag_Decodable);
|
||||
|
@ -573,6 +572,267 @@ void subghz_cli_command_decode_raw(Cli* cli, FuriString* args, void* context) {
|
|||
furi_string_free(file_name);
|
||||
}
|
||||
|
||||
static FuriHalSubGhzPreset subghz_cli_get_preset_name(const char* preset_name) {
|
||||
FuriHalSubGhzPreset preset = FuriHalSubGhzPresetIDLE;
|
||||
if(!strcmp(preset_name, "FuriHalSubGhzPresetOok270Async")) {
|
||||
preset = FuriHalSubGhzPresetOok270Async;
|
||||
} else if(!strcmp(preset_name, "FuriHalSubGhzPresetOok650Async")) {
|
||||
preset = FuriHalSubGhzPresetOok650Async;
|
||||
} else if(!strcmp(preset_name, "FuriHalSubGhzPreset2FSKDev238Async")) {
|
||||
preset = FuriHalSubGhzPreset2FSKDev238Async;
|
||||
} else if(!strcmp(preset_name, "FuriHalSubGhzPreset2FSKDev476Async")) {
|
||||
preset = FuriHalSubGhzPreset2FSKDev476Async;
|
||||
} else if(!strcmp(preset_name, "FuriHalSubGhzPresetCustom")) {
|
||||
preset = FuriHalSubGhzPresetCustom;
|
||||
} else {
|
||||
printf("subghz tx_from_file: unknown preset");
|
||||
}
|
||||
return preset;
|
||||
}
|
||||
|
||||
void subghz_cli_command_tx_from_file(Cli* cli, FuriString* args, void* context) { // -V524
|
||||
UNUSED(context);
|
||||
FuriString* file_name;
|
||||
file_name = furi_string_alloc();
|
||||
furi_string_set(file_name, ANY_PATH("subghz/test.sub"));
|
||||
uint32_t repeat = 10;
|
||||
uint32_t device_ind = 0; // 0 - CC1101_INT, 1 - CC1101_EXT
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
|
||||
FlipperFormat* fff_data_raw = flipper_format_string_alloc();
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
uint32_t temp_data32;
|
||||
bool check_file = false;
|
||||
const SubGhzDevice* device = NULL;
|
||||
|
||||
uint32_t frequency = 0;
|
||||
SubGhzTransmitter* transmitter = NULL;
|
||||
|
||||
subghz_devices_init();
|
||||
|
||||
SubGhzEnvironment* environment = subghz_cli_environment_init();
|
||||
|
||||
do {
|
||||
if(furi_string_size(args)) {
|
||||
if(!args_read_string_and_trim(args, file_name)) {
|
||||
cli_print_usage(
|
||||
"subghz tx_from_file: ",
|
||||
"<file_name: path_file> <Repeat count> <Device: 0 - CC1101_INT, 1 - CC1101_EXT>",
|
||||
furi_string_get_cstr(args));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(furi_string_size(args)) {
|
||||
int ret = sscanf(furi_string_get_cstr(args), "%lu %lu", &repeat, &device_ind);
|
||||
if(ret != 2) {
|
||||
printf("sscanf returned %d, repeat: %lu device: %lu\r\n", ret, repeat, device_ind);
|
||||
cli_print_usage(
|
||||
"subghz tx_from_file:",
|
||||
"<file_name: path_file> <Repeat count> <Device: 0 - CC1101_INT, 1 - CC1101_EXT>",
|
||||
furi_string_get_cstr(args));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
device = subghz_cli_command_get_device(&device_ind);
|
||||
if(device == NULL) {
|
||||
printf("subghz tx_from_file: \033[0;31mError device not found\033[0m\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
|
||||
printf(
|
||||
"subghz tx_from_file: \033[0;31mError open file\033[0m %s\r\n",
|
||||
furi_string_get_cstr(file_name));
|
||||
break;
|
||||
}
|
||||
|
||||
if(!flipper_format_read_header(fff_data_file, temp_str, &temp_data32)) {
|
||||
printf("subghz tx_from_file: \033[0;31mMissing or incorrect header\033[0m\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if(((!strcmp(furi_string_get_cstr(temp_str), SUBGHZ_KEY_FILE_TYPE)) ||
|
||||
(!strcmp(furi_string_get_cstr(temp_str), SUBGHZ_RAW_FILE_TYPE))) &&
|
||||
temp_data32 == SUBGHZ_KEY_FILE_VERSION) {
|
||||
} else {
|
||||
printf("subghz tx_from_file: \033[0;31mType or version mismatch\033[0m\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
//Load frequency
|
||||
if(!flipper_format_read_uint32(fff_data_file, "Frequency", &frequency, 1)) {
|
||||
printf("subghz tx_from_file: \033[0;31mMissing Frequency\033[0m\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if(!subghz_devices_is_frequency_valid(device, frequency)) {
|
||||
printf("subghz tx_from_file: \033[0;31mFrequency not supported\033[0m\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
//Load preset
|
||||
if(!flipper_format_read_string(fff_data_file, "Preset", temp_str)) {
|
||||
printf("subghz tx_from_file: \033[0;31mMissing Preset\033[0m\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
subghz_devices_begin(device);
|
||||
subghz_devices_reset(device);
|
||||
|
||||
if(!strcmp(furi_string_get_cstr(temp_str), "FuriHalSubGhzPresetCustom")) {
|
||||
uint8_t* custom_preset_data;
|
||||
uint32_t custom_preset_data_size;
|
||||
if(!flipper_format_get_value_count(fff_data_file, "Custom_preset_data", &temp_data32))
|
||||
break;
|
||||
if(!temp_data32 || (temp_data32 % 2)) {
|
||||
printf("subghz tx_from_file: \033[0;31mCustom_preset_data size error\033[0m\r\n");
|
||||
break;
|
||||
}
|
||||
custom_preset_data_size = sizeof(uint8_t) * temp_data32;
|
||||
custom_preset_data = malloc(custom_preset_data_size);
|
||||
if(!flipper_format_read_hex(
|
||||
fff_data_file,
|
||||
"Custom_preset_data",
|
||||
custom_preset_data,
|
||||
custom_preset_data_size)) {
|
||||
printf("subghz tx_from_file: \033[0;31mCustom_preset_data read error\033[0m\r\n");
|
||||
break;
|
||||
}
|
||||
subghz_devices_load_preset(
|
||||
device,
|
||||
subghz_cli_get_preset_name(furi_string_get_cstr(temp_str)),
|
||||
custom_preset_data);
|
||||
free(custom_preset_data);
|
||||
} else {
|
||||
subghz_devices_load_preset(
|
||||
device, subghz_cli_get_preset_name(furi_string_get_cstr(temp_str)), NULL);
|
||||
}
|
||||
|
||||
subghz_devices_set_frequency(device, frequency);
|
||||
|
||||
//Load protocol
|
||||
if(!flipper_format_read_string(fff_data_file, "Protocol", temp_str)) {
|
||||
printf("subghz tx_from_file: \033[0;31mMissing protocol\033[0m\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
SubGhzProtocolStatus status;
|
||||
bool is_init_protocol = true;
|
||||
if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) { // if RAW protocol
|
||||
subghz_protocol_raw_gen_fff_data(
|
||||
fff_data_raw, furi_string_get_cstr(file_name), subghz_devices_get_name(device));
|
||||
|
||||
transmitter =
|
||||
subghz_transmitter_alloc_init(environment, furi_string_get_cstr(temp_str));
|
||||
if(transmitter == NULL) {
|
||||
printf("subghz tx_from_file: \033[0;31mError transmitter\033[0m\r\n");
|
||||
is_init_protocol = false;
|
||||
}
|
||||
|
||||
if(is_init_protocol) {
|
||||
status = subghz_transmitter_deserialize(transmitter, fff_data_raw);
|
||||
if(status != SubGhzProtocolStatusOk) {
|
||||
printf(
|
||||
"subghz tx_from_file: \033[0;31mError deserialize protocol\033[0m %d\r\n",
|
||||
status);
|
||||
is_init_protocol = false;
|
||||
}
|
||||
}
|
||||
|
||||
} else { //if not RAW protocol
|
||||
flipper_format_insert_or_update_uint32(fff_data_file, "Repeat", &repeat, 1);
|
||||
|
||||
transmitter =
|
||||
subghz_transmitter_alloc_init(environment, furi_string_get_cstr(temp_str));
|
||||
if(transmitter == NULL) {
|
||||
printf("subghz tx_from_file: \033[0;31mError transmitter\033[0m\r\n");
|
||||
is_init_protocol = false;
|
||||
}
|
||||
if(is_init_protocol) {
|
||||
status = subghz_transmitter_deserialize(transmitter, fff_data_file);
|
||||
if(status != SubGhzProtocolStatusOk) {
|
||||
printf(
|
||||
"subghz tx_from_file: \033[0;31mError deserialize protocol\033[0m %d\r\n",
|
||||
status);
|
||||
is_init_protocol = false;
|
||||
}
|
||||
}
|
||||
|
||||
flipper_format_delete_key(fff_data_file, "Repeat");
|
||||
}
|
||||
|
||||
if(is_init_protocol) {
|
||||
check_file = true;
|
||||
} else {
|
||||
subghz_devices_sleep(device);
|
||||
subghz_devices_end(device);
|
||||
subghz_transmitter_free(transmitter);
|
||||
}
|
||||
|
||||
} while(false);
|
||||
|
||||
flipper_format_free(fff_data_file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
if(check_file) {
|
||||
furi_hal_power_suppress_charge_enter();
|
||||
|
||||
printf(
|
||||
"Listening at \033[0;33m%s\033[0m. Frequency=%lu, Protocol=%s\r\n\r\nPress CTRL+C to stop\r\n\r\n",
|
||||
furi_string_get_cstr(file_name),
|
||||
frequency,
|
||||
furi_string_get_cstr(temp_str));
|
||||
do {
|
||||
//delay in downloading files and other preparatory processes
|
||||
furi_delay_ms(200);
|
||||
if(subghz_devices_start_async_tx(device, subghz_transmitter_yield, transmitter)) {
|
||||
while(
|
||||
!(subghz_devices_is_async_complete_tx(device) ||
|
||||
cli_cmd_interrupt_received(cli))) {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
furi_delay_ms(333);
|
||||
}
|
||||
subghz_devices_stop_async_tx(device);
|
||||
|
||||
} else {
|
||||
printf("Transmission on this frequency is restricted in your settings\r\n");
|
||||
}
|
||||
|
||||
if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) {
|
||||
subghz_transmitter_stop(transmitter);
|
||||
repeat--;
|
||||
if(!cli_cmd_interrupt_received(cli) && repeat)
|
||||
subghz_transmitter_deserialize(transmitter, fff_data_raw);
|
||||
}
|
||||
|
||||
} while(!cli_cmd_interrupt_received(cli) &&
|
||||
(repeat && !strcmp(furi_string_get_cstr(temp_str), "RAW")));
|
||||
|
||||
subghz_devices_sleep(device);
|
||||
subghz_devices_end(device);
|
||||
subghz_cli_radio_device_power_off();
|
||||
|
||||
furi_hal_power_suppress_charge_exit();
|
||||
|
||||
subghz_transmitter_free(transmitter);
|
||||
}
|
||||
flipper_format_free(fff_data_raw);
|
||||
furi_string_free(file_name);
|
||||
furi_string_free(temp_str);
|
||||
subghz_devices_deinit();
|
||||
// Reset custom settings
|
||||
subghz_environment_reset_keeloq(environment);
|
||||
faac_slh_reset_prog_mode();
|
||||
subghz_custom_btns_reset();
|
||||
// Free environment
|
||||
subghz_environment_free(environment);
|
||||
}
|
||||
|
||||
static void subghz_cli_command_print_usage() {
|
||||
printf("Usage:\r\n");
|
||||
printf("subghz <cmd> <args>\r\n");
|
||||
|
@ -585,11 +845,13 @@ static void subghz_cli_command_print_usage() {
|
|||
printf("\trx <frequency:in Hz> <device: 0 - CC1101_INT, 1 - CC1101_EXT>\t - Receive\r\n");
|
||||
printf("\trx_raw <frequency:in Hz>\t - Receive RAW\r\n");
|
||||
printf("\tdecode_raw <file_name: path_RAW_file>\t - Testing\r\n");
|
||||
printf(
|
||||
"\ttx_from_file <file_name: path_file> <repeat: count> <device: 0 - CC1101_INT, 1 - CC1101_EXT>\t - Transmitting from file\r\n");
|
||||
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||
printf("\r\n");
|
||||
printf(" debug cmd:\r\n");
|
||||
printf("\ttx_carrier <frequency:in Hz>\t - Transmit carrier\r\n");
|
||||
printf("\ttx_carrier <frequency:in Hz>\t - Transmitting carrier\r\n");
|
||||
printf("\trx_carrier <frequency:in Hz>\t - Receive carrier\r\n");
|
||||
printf(
|
||||
"\tencrypt_keeloq <path_decrypted_file> <path_encrypted_file> <IV:16 bytes in hex>\t - Encrypt keeloq manufacture keys\r\n");
|
||||
|
@ -901,6 +1163,11 @@ static void subghz_cli_command(Cli* cli, FuriString* args, void* context) {
|
|||
break;
|
||||
}
|
||||
|
||||
if(furi_string_cmp_str(cmd, "tx_from_file") == 0) {
|
||||
subghz_cli_command_tx_from_file(cli, args, context);
|
||||
break;
|
||||
}
|
||||
|
||||
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
|
||||
if(furi_string_cmp_str(cmd, "encrypt_keeloq") == 0) {
|
||||
subghz_cli_command_encrypt_keeloq(cli, args);
|
||||
|
|
|
@ -131,6 +131,16 @@ const char* subghz_history_get_protocol_name(SubGhzHistory* instance, uint16_t i
|
|||
return furi_string_get_cstr(instance->tmp_string);
|
||||
}
|
||||
|
||||
FuriHalRtcDateTime subghz_history_get_datetime(SubGhzHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
|
||||
if(item) {
|
||||
return item->datetime;
|
||||
} else {
|
||||
return (FuriHalRtcDateTime){};
|
||||
}
|
||||
}
|
||||
|
||||
FlipperFormat* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx) {
|
||||
furi_assert(instance);
|
||||
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
|
||||
|
|
|
@ -70,6 +70,14 @@ uint8_t subghz_history_get_type_protocol(SubGhzHistory* instance, uint16_t idx);
|
|||
*/
|
||||
const char* subghz_history_get_protocol_name(SubGhzHistory* instance, uint16_t idx);
|
||||
|
||||
/** Get datetime from history[idx]
|
||||
*
|
||||
* @param instance - SubGhzHistory instance
|
||||
* @param idx - record index
|
||||
* @return datetime - FuriHalRtcDateTime received timestamp
|
||||
*/
|
||||
FuriHalRtcDateTime subghz_history_get_datetime(SubGhzHistory* instance, uint16_t idx);
|
||||
|
||||
/** Get string item menu to history[idx]
|
||||
*
|
||||
* @param instance - SubGhzHistory instance
|
||||
|
|
|
@ -79,6 +79,9 @@ struct SubGhz {
|
|||
SubGhzReadRAW* subghz_read_raw;
|
||||
bool raw_send_only;
|
||||
|
||||
bool save_datetime_set;
|
||||
FuriHalRtcDateTime save_datetime;
|
||||
|
||||
SubGhzLastSettings* last_settings;
|
||||
|
||||
SubGhzProtocolFlag filter;
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
#include <furi_hal_usb_hid_u2f.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
#include <furi_hal_console.h>
|
||||
|
||||
#define TAG "U2fHid"
|
||||
#define WORKER_TAG TAG "Worker"
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ App(
|
|||
provides=[
|
||||
"crypto_start",
|
||||
"rpc_start",
|
||||
"expansion_start",
|
||||
"bt",
|
||||
"desktop",
|
||||
"loader",
|
||||
|
|
|
@ -221,7 +221,12 @@ void cli_command_log(Cli* cli, FuriString* args, void* context) {
|
|||
furi_log_level_to_string(furi_log_get_level(), ¤t_level);
|
||||
printf("Current log level: %s\r\n", current_level);
|
||||
|
||||
furi_hal_console_set_tx_callback(cli_command_log_tx_callback, ring);
|
||||
FuriLogHandler log_handler = {
|
||||
.callback = cli_command_log_tx_callback,
|
||||
.context = ring,
|
||||
};
|
||||
|
||||
furi_log_add_handler(log_handler);
|
||||
|
||||
printf("Use <log ?> to list available log levels\r\n");
|
||||
printf("Press CTRL+C to stop...\r\n");
|
||||
|
@ -230,7 +235,7 @@ void cli_command_log(Cli* cli, FuriString* args, void* context) {
|
|||
cli_write(cli, buffer, ret);
|
||||
}
|
||||
|
||||
furi_hal_console_set_tx_callback(NULL, NULL);
|
||||
furi_log_remove_handler(log_handler);
|
||||
|
||||
if(restore_log_level) {
|
||||
// There will be strange behaviour if log level is set from settings while log command is running
|
||||
|
|
12
applications/services/expansion/application.fam
Normal file
12
applications/services/expansion/application.fam
Normal file
|
@ -0,0 +1,12 @@
|
|||
App(
|
||||
appid="expansion_start",
|
||||
apptype=FlipperAppType.STARTUP,
|
||||
entry_point="expansion_on_system_start",
|
||||
cdefines=["SRV_EXPANSION"],
|
||||
sdk_headers=[
|
||||
"expansion.h",
|
||||
],
|
||||
requires=["rpc_start"],
|
||||
provides=["expansion_settings"],
|
||||
order=10,
|
||||
)
|
436
applications/services/expansion/expansion.c
Normal file
436
applications/services/expansion/expansion.c
Normal file
|
@ -0,0 +1,436 @@
|
|||
#include "expansion.h"
|
||||
|
||||
#include <furi_hal_power.h>
|
||||
#include <furi_hal_serial.h>
|
||||
#include <furi_hal_serial_control.h>
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
|
||||
#include "expansion_settings.h"
|
||||
#include "expansion_protocol.h"
|
||||
|
||||
#define TAG "ExpansionSrv"
|
||||
|
||||
#define EXPANSION_BUFFER_SIZE (sizeof(ExpansionFrame) + sizeof(ExpansionFrameChecksum))
|
||||
|
||||
typedef enum {
|
||||
ExpansionStateDisabled,
|
||||
ExpansionStateEnabled,
|
||||
ExpansionStateRunning,
|
||||
} ExpansionState;
|
||||
|
||||
typedef enum {
|
||||
ExpansionSessionStateHandShake,
|
||||
ExpansionSessionStateConnected,
|
||||
ExpansionSessionStateRpcActive,
|
||||
} ExpansionSessionState;
|
||||
|
||||
typedef enum {
|
||||
ExpansionSessionExitReasonUnknown,
|
||||
ExpansionSessionExitReasonUser,
|
||||
ExpansionSessionExitReasonError,
|
||||
ExpansionSessionExitReasonTimeout,
|
||||
} ExpansionSessionExitReason;
|
||||
|
||||
typedef enum {
|
||||
ExpansionFlagStop = 1 << 0,
|
||||
ExpansionFlagData = 1 << 1,
|
||||
ExpansionFlagError = 1 << 2,
|
||||
} ExpansionFlag;
|
||||
|
||||
#define EXPANSION_ALL_FLAGS (ExpansionFlagData | ExpansionFlagStop)
|
||||
|
||||
struct Expansion {
|
||||
ExpansionState state;
|
||||
ExpansionSessionState session_state;
|
||||
ExpansionSessionExitReason exit_reason;
|
||||
FuriStreamBuffer* rx_buf;
|
||||
FuriSemaphore* tx_semaphore;
|
||||
FuriMutex* state_mutex;
|
||||
FuriThread* worker_thread;
|
||||
FuriHalSerialId serial_id;
|
||||
FuriHalSerialHandle* serial_handle;
|
||||
RpcSession* rpc_session;
|
||||
};
|
||||
|
||||
static void expansion_detect_callback(void* context);
|
||||
|
||||
// Called in UART IRQ context
|
||||
static void expansion_serial_rx_callback(
|
||||
FuriHalSerialHandle* handle,
|
||||
FuriHalSerialRxEvent event,
|
||||
void* context) {
|
||||
furi_assert(handle);
|
||||
furi_assert(context);
|
||||
|
||||
Expansion* instance = context;
|
||||
|
||||
if(event == FuriHalSerialRxEventData) {
|
||||
const uint8_t data = furi_hal_serial_async_rx(handle);
|
||||
furi_stream_buffer_send(instance->rx_buf, &data, sizeof(data), 0);
|
||||
furi_thread_flags_set(furi_thread_get_id(instance->worker_thread), ExpansionFlagData);
|
||||
}
|
||||
}
|
||||
|
||||
static size_t expansion_receive_callback(uint8_t* data, size_t data_size, void* context) {
|
||||
Expansion* instance = context;
|
||||
|
||||
size_t received_size = 0;
|
||||
|
||||
while(true) {
|
||||
received_size += furi_stream_buffer_receive(
|
||||
instance->rx_buf, data + received_size, data_size - received_size, 0);
|
||||
|
||||
if(received_size == data_size) break;
|
||||
|
||||
const uint32_t flags = furi_thread_flags_wait(
|
||||
EXPANSION_ALL_FLAGS, FuriFlagWaitAny, furi_ms_to_ticks(EXPANSION_PROTOCOL_TIMEOUT_MS));
|
||||
|
||||
if(flags & FuriFlagError) {
|
||||
if(flags == (unsigned)FuriFlagErrorTimeout) {
|
||||
// Exiting due to timeout
|
||||
instance->exit_reason = ExpansionSessionExitReasonTimeout;
|
||||
} else {
|
||||
// Exiting due to an unspecified error
|
||||
instance->exit_reason = ExpansionSessionExitReasonError;
|
||||
}
|
||||
break;
|
||||
} else if(flags & ExpansionFlagStop) {
|
||||
// Exiting due to explicit request
|
||||
instance->exit_reason = ExpansionSessionExitReasonUser;
|
||||
break;
|
||||
} else if(flags & ExpansionFlagError) {
|
||||
// Exiting due to RPC error
|
||||
instance->exit_reason = ExpansionSessionExitReasonError;
|
||||
break;
|
||||
} else if(flags & ExpansionFlagData) {
|
||||
// Go to buffer reading
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return received_size;
|
||||
}
|
||||
|
||||
static inline bool expansion_receive_frame(Expansion* instance, ExpansionFrame* frame) {
|
||||
return expansion_protocol_decode(frame, expansion_receive_callback, instance) ==
|
||||
ExpansionProtocolStatusOk;
|
||||
}
|
||||
|
||||
static size_t expansion_send_callback(const uint8_t* data, size_t data_size, void* context) {
|
||||
Expansion* instance = context;
|
||||
furi_hal_serial_tx(instance->serial_handle, data, data_size);
|
||||
furi_hal_serial_tx_wait_complete(instance->serial_handle);
|
||||
return data_size;
|
||||
}
|
||||
|
||||
static inline bool expansion_send_frame(Expansion* instance, const ExpansionFrame* frame) {
|
||||
return expansion_protocol_encode(frame, expansion_send_callback, instance) ==
|
||||
ExpansionProtocolStatusOk;
|
||||
}
|
||||
|
||||
static bool expansion_send_heartbeat(Expansion* instance) {
|
||||
const ExpansionFrame frame = {
|
||||
.header.type = ExpansionFrameTypeHeartbeat,
|
||||
.content.heartbeat = {},
|
||||
};
|
||||
|
||||
return expansion_send_frame(instance, &frame);
|
||||
}
|
||||
|
||||
static bool expansion_send_status_response(Expansion* instance, ExpansionFrameError error) {
|
||||
const ExpansionFrame frame = {
|
||||
.header.type = ExpansionFrameTypeStatus,
|
||||
.content.status.error = error,
|
||||
};
|
||||
|
||||
return expansion_send_frame(instance, &frame);
|
||||
}
|
||||
|
||||
static bool
|
||||
expansion_send_data_response(Expansion* instance, const uint8_t* data, size_t data_size) {
|
||||
furi_assert(data_size <= EXPANSION_PROTOCOL_MAX_DATA_SIZE);
|
||||
|
||||
ExpansionFrame frame = {
|
||||
.header.type = ExpansionFrameTypeData,
|
||||
.content.data.size = data_size,
|
||||
};
|
||||
|
||||
memcpy(frame.content.data.bytes, data, data_size);
|
||||
return expansion_send_frame(instance, &frame);
|
||||
}
|
||||
|
||||
// Called in Rpc session thread context
|
||||
static void expansion_rpc_send_callback(void* context, uint8_t* data, size_t data_size) {
|
||||
Expansion* instance = context;
|
||||
|
||||
for(size_t sent_data_size = 0; sent_data_size < data_size;) {
|
||||
if(furi_semaphore_acquire(
|
||||
instance->tx_semaphore, furi_ms_to_ticks(EXPANSION_PROTOCOL_TIMEOUT_MS)) !=
|
||||
FuriStatusOk) {
|
||||
furi_thread_flags_set(furi_thread_get_id(instance->worker_thread), ExpansionFlagError);
|
||||
break;
|
||||
}
|
||||
|
||||
const size_t current_data_size =
|
||||
MIN(data_size - sent_data_size, EXPANSION_PROTOCOL_MAX_DATA_SIZE);
|
||||
if(!expansion_send_data_response(instance, data + sent_data_size, current_data_size))
|
||||
break;
|
||||
sent_data_size += current_data_size;
|
||||
}
|
||||
}
|
||||
|
||||
static bool expansion_rpc_session_open(Expansion* instance) {
|
||||
Rpc* rpc = furi_record_open(RECORD_RPC);
|
||||
instance->rpc_session = rpc_session_open(rpc, RpcOwnerUart);
|
||||
|
||||
if(instance->rpc_session) {
|
||||
instance->tx_semaphore = furi_semaphore_alloc(1, 1);
|
||||
rpc_session_set_context(instance->rpc_session, instance);
|
||||
rpc_session_set_send_bytes_callback(instance->rpc_session, expansion_rpc_send_callback);
|
||||
}
|
||||
|
||||
return instance->rpc_session != NULL;
|
||||
}
|
||||
|
||||
static void expansion_rpc_session_close(Expansion* instance) {
|
||||
if(instance->rpc_session) {
|
||||
rpc_session_close(instance->rpc_session);
|
||||
furi_semaphore_free(instance->tx_semaphore);
|
||||
}
|
||||
|
||||
furi_record_close(RECORD_RPC);
|
||||
}
|
||||
|
||||
static bool
|
||||
expansion_handle_session_state_handshake(Expansion* instance, const ExpansionFrame* rx_frame) {
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
if(rx_frame->header.type != ExpansionFrameTypeBaudRate) break;
|
||||
const uint32_t baud_rate = rx_frame->content.baud_rate.baud;
|
||||
|
||||
FURI_LOG_D(TAG, "Proposed baud rate: %lu", baud_rate);
|
||||
|
||||
if(furi_hal_serial_is_baud_rate_supported(instance->serial_handle, baud_rate)) {
|
||||
instance->session_state = ExpansionSessionStateConnected;
|
||||
// Send response at previous baud rate
|
||||
if(!expansion_send_status_response(instance, ExpansionFrameErrorNone)) break;
|
||||
furi_hal_serial_set_br(instance->serial_handle, baud_rate);
|
||||
|
||||
} else {
|
||||
if(!expansion_send_status_response(instance, ExpansionFrameErrorBaudRate)) break;
|
||||
FURI_LOG_E(TAG, "Bad baud rate");
|
||||
}
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool
|
||||
expansion_handle_session_state_connected(Expansion* instance, const ExpansionFrame* rx_frame) {
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
if(rx_frame->header.type == ExpansionFrameTypeControl) {
|
||||
if(rx_frame->content.control.command != ExpansionFrameControlCommandStartRpc) break;
|
||||
instance->session_state = ExpansionSessionStateRpcActive;
|
||||
if(!expansion_rpc_session_open(instance)) break;
|
||||
if(!expansion_send_status_response(instance, ExpansionFrameErrorNone)) break;
|
||||
|
||||
} else if(rx_frame->header.type == ExpansionFrameTypeHeartbeat) {
|
||||
if(!expansion_send_heartbeat(instance)) break;
|
||||
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool
|
||||
expansion_handle_session_state_rpc_active(Expansion* instance, const ExpansionFrame* rx_frame) {
|
||||
bool success = false;
|
||||
|
||||
do {
|
||||
if(rx_frame->header.type == ExpansionFrameTypeData) {
|
||||
if(!expansion_send_status_response(instance, ExpansionFrameErrorNone)) break;
|
||||
|
||||
const size_t size_consumed = rpc_session_feed(
|
||||
instance->rpc_session,
|
||||
rx_frame->content.data.bytes,
|
||||
rx_frame->content.data.size,
|
||||
EXPANSION_PROTOCOL_TIMEOUT_MS);
|
||||
if(size_consumed != rx_frame->content.data.size) break;
|
||||
|
||||
} else if(rx_frame->header.type == ExpansionFrameTypeControl) {
|
||||
if(rx_frame->content.control.command != ExpansionFrameControlCommandStopRpc) break;
|
||||
instance->session_state = ExpansionSessionStateConnected;
|
||||
expansion_rpc_session_close(instance);
|
||||
if(!expansion_send_status_response(instance, ExpansionFrameErrorNone)) break;
|
||||
|
||||
} else if(rx_frame->header.type == ExpansionFrameTypeStatus) {
|
||||
if(rx_frame->content.status.error != ExpansionFrameErrorNone) break;
|
||||
furi_semaphore_release(instance->tx_semaphore);
|
||||
|
||||
} else if(rx_frame->header.type == ExpansionFrameTypeHeartbeat) {
|
||||
if(!expansion_send_heartbeat(instance)) break;
|
||||
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
success = true;
|
||||
} while(false);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static inline void expansion_state_machine(Expansion* instance) {
|
||||
typedef bool (*ExpansionSessionStateHandler)(Expansion*, const ExpansionFrame*);
|
||||
|
||||
static const ExpansionSessionStateHandler expansion_handlers[] = {
|
||||
[ExpansionSessionStateHandShake] = expansion_handle_session_state_handshake,
|
||||
[ExpansionSessionStateConnected] = expansion_handle_session_state_connected,
|
||||
[ExpansionSessionStateRpcActive] = expansion_handle_session_state_rpc_active,
|
||||
};
|
||||
|
||||
ExpansionFrame rx_frame;
|
||||
|
||||
while(true) {
|
||||
if(!expansion_receive_frame(instance, &rx_frame)) break;
|
||||
if(!expansion_handlers[instance->session_state](instance, &rx_frame)) break;
|
||||
}
|
||||
}
|
||||
|
||||
static void expansion_worker_pending_callback(void* context, uint32_t arg) {
|
||||
furi_assert(context);
|
||||
UNUSED(arg);
|
||||
|
||||
Expansion* instance = context;
|
||||
furi_thread_join(instance->worker_thread);
|
||||
|
||||
// Do not re-enable detection interrupt on user-requested exit
|
||||
if(instance->exit_reason != ExpansionSessionExitReasonUser) {
|
||||
furi_check(furi_mutex_acquire(instance->state_mutex, FuriWaitForever) == FuriStatusOk);
|
||||
instance->state = ExpansionStateEnabled;
|
||||
furi_hal_serial_control_set_expansion_callback(
|
||||
instance->serial_id, expansion_detect_callback, instance);
|
||||
furi_mutex_release(instance->state_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t expansion_worker(void* context) {
|
||||
furi_assert(context);
|
||||
Expansion* instance = context;
|
||||
|
||||
furi_hal_power_insomnia_enter();
|
||||
furi_hal_serial_control_set_expansion_callback(instance->serial_id, NULL, NULL);
|
||||
|
||||
instance->serial_handle = furi_hal_serial_control_acquire(instance->serial_id);
|
||||
furi_check(instance->serial_handle);
|
||||
|
||||
FURI_LOG_D(TAG, "Service started");
|
||||
|
||||
instance->rx_buf = furi_stream_buffer_alloc(EXPANSION_BUFFER_SIZE, 1);
|
||||
instance->session_state = ExpansionSessionStateHandShake;
|
||||
instance->exit_reason = ExpansionSessionExitReasonUnknown;
|
||||
|
||||
furi_hal_serial_init(instance->serial_handle, EXPANSION_PROTOCOL_DEFAULT_BAUD_RATE);
|
||||
|
||||
furi_hal_serial_async_rx_start(
|
||||
instance->serial_handle, expansion_serial_rx_callback, instance, false);
|
||||
|
||||
if(expansion_send_heartbeat(instance)) {
|
||||
expansion_state_machine(instance);
|
||||
}
|
||||
|
||||
if(instance->session_state == ExpansionSessionStateRpcActive) {
|
||||
expansion_rpc_session_close(instance);
|
||||
}
|
||||
|
||||
FURI_LOG_D(TAG, "Service stopped");
|
||||
|
||||
furi_hal_serial_control_release(instance->serial_handle);
|
||||
furi_stream_buffer_free(instance->rx_buf);
|
||||
|
||||
furi_hal_power_insomnia_exit();
|
||||
furi_timer_pending_callback(expansion_worker_pending_callback, instance, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Called from the serial control thread
|
||||
static void expansion_detect_callback(void* context) {
|
||||
furi_assert(context);
|
||||
Expansion* instance = context;
|
||||
|
||||
furi_check(furi_mutex_acquire(instance->state_mutex, FuriWaitForever) == FuriStatusOk);
|
||||
|
||||
if(instance->state == ExpansionStateEnabled) {
|
||||
instance->state = ExpansionStateRunning;
|
||||
furi_thread_start(instance->worker_thread);
|
||||
}
|
||||
|
||||
furi_mutex_release(instance->state_mutex);
|
||||
}
|
||||
|
||||
static Expansion* expansion_alloc() {
|
||||
Expansion* instance = malloc(sizeof(Expansion));
|
||||
|
||||
instance->state_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
instance->worker_thread = furi_thread_alloc_ex(TAG, 768, expansion_worker, instance);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void expansion_on_system_start(void* arg) {
|
||||
UNUSED(arg);
|
||||
|
||||
Expansion* instance = expansion_alloc();
|
||||
furi_record_create(RECORD_EXPANSION, instance);
|
||||
|
||||
ExpansionSettings settings = {};
|
||||
expansion_settings_load(&settings);
|
||||
if(settings.uart_index < FuriHalSerialIdMax) {
|
||||
expansion_enable(instance, settings.uart_index);
|
||||
}
|
||||
}
|
||||
|
||||
// Public API functions
|
||||
|
||||
void expansion_enable(Expansion* instance, FuriHalSerialId serial_id) {
|
||||
expansion_disable(instance);
|
||||
|
||||
furi_check(furi_mutex_acquire(instance->state_mutex, FuriWaitForever) == FuriStatusOk);
|
||||
|
||||
instance->serial_id = serial_id;
|
||||
instance->state = ExpansionStateEnabled;
|
||||
|
||||
furi_hal_serial_control_set_expansion_callback(
|
||||
instance->serial_id, expansion_detect_callback, instance);
|
||||
|
||||
furi_mutex_release(instance->state_mutex);
|
||||
|
||||
FURI_LOG_D(TAG, "Detection enabled");
|
||||
}
|
||||
|
||||
void expansion_disable(Expansion* instance) {
|
||||
furi_check(furi_mutex_acquire(instance->state_mutex, FuriWaitForever) == FuriStatusOk);
|
||||
|
||||
if(instance->state == ExpansionStateRunning) {
|
||||
furi_thread_flags_set(furi_thread_get_id(instance->worker_thread), ExpansionFlagStop);
|
||||
furi_thread_join(instance->worker_thread);
|
||||
} else if(instance->state == ExpansionStateEnabled) {
|
||||
FURI_LOG_D(TAG, "Detection disabled");
|
||||
furi_hal_serial_control_set_expansion_callback(instance->serial_id, NULL, NULL);
|
||||
}
|
||||
|
||||
instance->state = ExpansionStateDisabled;
|
||||
|
||||
furi_mutex_release(instance->state_mutex);
|
||||
}
|
50
applications/services/expansion/expansion.h
Normal file
50
applications/services/expansion/expansion.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* @file expansion.h
|
||||
* @brief Expansion module support library.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <furi_hal_serial_types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief FURI record key to access the expansion object.
|
||||
*/
|
||||
#define RECORD_EXPANSION "expansion"
|
||||
|
||||
/**
|
||||
* @brief Expansion opaque type declaration.
|
||||
*/
|
||||
typedef struct Expansion Expansion;
|
||||
|
||||
/**
|
||||
* @brief Enable support for expansion modules on designated serial port.
|
||||
*
|
||||
* Only one serial port can be used to communicate with an expansion
|
||||
* module at a time.
|
||||
*
|
||||
* Calling this function when expansion module support is already enabled
|
||||
* will first disable the previous setting, then enable the current one.
|
||||
*
|
||||
* @param[in,out] instance pointer to the Expansion instance.
|
||||
* @param[in] serial_id numerical identifier of the serial.
|
||||
*/
|
||||
void expansion_enable(Expansion* instance, FuriHalSerialId serial_id);
|
||||
|
||||
/**
|
||||
* @brief Disable support for expansion modules.
|
||||
*
|
||||
* Calling this function will cease all communications with the
|
||||
* expansion module (if any), release the serial handle and
|
||||
* reset the respective pins to the default state.
|
||||
*
|
||||
* @param[in,out] instance pointer to the Expansion instance.
|
||||
*/
|
||||
void expansion_disable(Expansion* instance);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
338
applications/services/expansion/expansion_protocol.h
Normal file
338
applications/services/expansion/expansion_protocol.h
Normal file
|
@ -0,0 +1,338 @@
|
|||
/**
|
||||
* @file expansion_protocol.h
|
||||
* @brief Flipper Expansion Protocol parser reference implementation.
|
||||
*
|
||||
* This file is licensed separately under The Unlicense.
|
||||
* See https://unlicense.org/ for more details.
|
||||
*
|
||||
* This parser is written with low-spec hardware in mind. It does not use
|
||||
* dynamic memory allocation or Flipper-specific libraries and can be
|
||||
* included directly into any module's firmware's sources.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Default baud rate to start all communications at.
|
||||
*/
|
||||
#define EXPANSION_PROTOCOL_DEFAULT_BAUD_RATE (9600UL)
|
||||
|
||||
/**
|
||||
* @brief Maximum data size per frame, in bytes.
|
||||
*/
|
||||
#define EXPANSION_PROTOCOL_MAX_DATA_SIZE (64U)
|
||||
|
||||
/**
|
||||
* @brief Maximum allowed inactivity period, in milliseconds.
|
||||
*/
|
||||
#define EXPANSION_PROTOCOL_TIMEOUT_MS (250U)
|
||||
|
||||
/**
|
||||
* @brief Dead time after changing connection baud rate.
|
||||
*/
|
||||
#define EXPANSION_PROTOCOL_BAUD_CHANGE_DT_MS (25U)
|
||||
|
||||
/**
|
||||
* @brief Enumeration of supported frame types.
|
||||
*/
|
||||
typedef enum {
|
||||
ExpansionFrameTypeHeartbeat = 1, /**< Heartbeat frame. */
|
||||
ExpansionFrameTypeStatus = 2, /**< Status report frame. */
|
||||
ExpansionFrameTypeBaudRate = 3, /**< Baud rate negotiation frame. */
|
||||
ExpansionFrameTypeControl = 4, /**< Control frame. */
|
||||
ExpansionFrameTypeData = 5, /**< Data frame. */
|
||||
ExpansionFrameTypeReserved, /**< Special value. */
|
||||
} ExpansionFrameType;
|
||||
|
||||
/**
|
||||
* @brief Enumeration of possible error types.
|
||||
*/
|
||||
typedef enum {
|
||||
ExpansionFrameErrorNone = 0x00, /**< No error occurred. */
|
||||
ExpansionFrameErrorUnknown = 0x01, /**< An unknown error has occurred (generic response). */
|
||||
ExpansionFrameErrorBaudRate = 0x02, /**< Requested baud rate is not supported. */
|
||||
} ExpansionFrameError;
|
||||
|
||||
/**
|
||||
* @brief Enumeration of suported control commands.
|
||||
*/
|
||||
typedef enum {
|
||||
ExpansionFrameControlCommandStartRpc = 0x00, /**< Start an RPC session. */
|
||||
ExpansionFrameControlCommandStopRpc = 0x01, /**< Stop an open RPC session. */
|
||||
} ExpansionFrameControlCommand;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
/**
|
||||
* @brief Frame header structure.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t type; /**< Type of the frame. @see ExpansionFrameType. */
|
||||
} ExpansionFrameHeader;
|
||||
|
||||
/**
|
||||
* @brief Heartbeat frame contents.
|
||||
*/
|
||||
typedef struct {
|
||||
/** Empty. */
|
||||
} ExpansionFrameHeartbeat;
|
||||
|
||||
/**
|
||||
* @brief Status frame contents.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t error; /**< Reported error code. @see ExpansionFrameError. */
|
||||
} ExpansionFrameStatus;
|
||||
|
||||
/**
|
||||
* @brief Baud rate frame contents.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t baud; /**< Requested baud rate. */
|
||||
} ExpansionFrameBaudRate;
|
||||
|
||||
/**
|
||||
* @brief Control frame contents.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t command; /**< Control command number. @see ExpansionFrameControlCommand. */
|
||||
} ExpansionFrameControl;
|
||||
|
||||
/**
|
||||
* @brief Data frame contents.
|
||||
*/
|
||||
typedef struct {
|
||||
/** Size of the data. Must be less than EXPANSION_PROTOCOL_MAX_DATA_SIZE. */
|
||||
uint8_t size;
|
||||
/** Data bytes. Valid only up to ExpansionFrameData::size bytes. */
|
||||
uint8_t bytes[EXPANSION_PROTOCOL_MAX_DATA_SIZE];
|
||||
} ExpansionFrameData;
|
||||
|
||||
/**
|
||||
* @brief Expansion protocol frame structure.
|
||||
*/
|
||||
typedef struct {
|
||||
ExpansionFrameHeader header; /**< Header of the frame. Required. */
|
||||
union {
|
||||
ExpansionFrameHeartbeat heartbeat; /**< Heartbeat frame contents. */
|
||||
ExpansionFrameStatus status; /**< Status frame contents. */
|
||||
ExpansionFrameBaudRate baud_rate; /**< Baud rate frame contents. */
|
||||
ExpansionFrameControl control; /**< Control frame contents. */
|
||||
ExpansionFrameData data; /**< Data frame contents. */
|
||||
} content; /**< Contents of the frame. */
|
||||
} ExpansionFrame;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
/**
|
||||
* @brief Expansion checksum type.
|
||||
*/
|
||||
typedef uint8_t ExpansionFrameChecksum;
|
||||
|
||||
/**
|
||||
* @brief Receive function type declaration.
|
||||
*
|
||||
* @see expansion_frame_decode().
|
||||
*
|
||||
* @param[out] data pointer to the buffer to reveive the data into.
|
||||
* @param[in] data_size maximum output buffer capacity, in bytes.
|
||||
* @param[in,out] context pointer to a user-defined context object.
|
||||
* @returns number of bytes written into the output buffer.
|
||||
*/
|
||||
typedef size_t (*ExpansionFrameReceiveCallback)(uint8_t* data, size_t data_size, void* context);
|
||||
|
||||
/**
|
||||
* @brief Send function type declaration.
|
||||
*
|
||||
* @see expansion_frame_encode().
|
||||
*
|
||||
* @param[in] data pointer to the buffer containing the data to be sent.
|
||||
* @param[in] data_size size of the data to send, in bytes.
|
||||
* @param[in,out] context pointer to a user-defined context object.
|
||||
* @returns number of bytes actually sent.
|
||||
*/
|
||||
typedef size_t (*ExpansionFrameSendCallback)(const uint8_t* data, size_t data_size, void* context);
|
||||
|
||||
/**
|
||||
* @brief Get encoded frame size.
|
||||
*
|
||||
* The frame MUST be complete and properly formed.
|
||||
*
|
||||
* @param[in] frame pointer to the frame to be evaluated.
|
||||
* @returns encoded frame size, in bytes.
|
||||
*/
|
||||
static inline size_t expansion_frame_get_encoded_size(const ExpansionFrame* frame) {
|
||||
switch(frame->header.type) {
|
||||
case ExpansionFrameTypeHeartbeat:
|
||||
return sizeof(frame->header);
|
||||
case ExpansionFrameTypeStatus:
|
||||
return sizeof(frame->header) + sizeof(frame->content.status);
|
||||
case ExpansionFrameTypeBaudRate:
|
||||
return sizeof(frame->header) + sizeof(frame->content.baud_rate);
|
||||
case ExpansionFrameTypeControl:
|
||||
return sizeof(frame->header) + sizeof(frame->content.control);
|
||||
case ExpansionFrameTypeData:
|
||||
return sizeof(frame->header) + sizeof(frame->content.data.size) + frame->content.data.size;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get remaining number of bytes needed to properly decode a frame.
|
||||
*
|
||||
* The return value will vary depending on the received_size parameter value.
|
||||
* The frame is considered complete when the function returns 0.
|
||||
*
|
||||
* @param[in] frame pointer to the frame to be evaluated.
|
||||
* @param[in] received_size number of bytes currently availabe for evaluation.
|
||||
* @returns number of bytes needed for a complete frame.
|
||||
*/
|
||||
static inline size_t
|
||||
expansion_frame_get_remaining_size(const ExpansionFrame* frame, size_t received_size) {
|
||||
if(received_size < sizeof(ExpansionFrameHeader)) return sizeof(ExpansionFrameHeader);
|
||||
|
||||
const size_t received_content_size = received_size - sizeof(ExpansionFrameHeader);
|
||||
size_t content_size;
|
||||
|
||||
switch(frame->header.type) {
|
||||
case ExpansionFrameTypeHeartbeat:
|
||||
content_size = 0;
|
||||
break;
|
||||
case ExpansionFrameTypeStatus:
|
||||
content_size = sizeof(frame->content.status);
|
||||
break;
|
||||
case ExpansionFrameTypeBaudRate:
|
||||
content_size = sizeof(frame->content.baud_rate);
|
||||
break;
|
||||
case ExpansionFrameTypeControl:
|
||||
content_size = sizeof(frame->content.control);
|
||||
break;
|
||||
case ExpansionFrameTypeData:
|
||||
if(received_content_size < sizeof(frame->content.data.size)) {
|
||||
content_size = sizeof(frame->content.data.size);
|
||||
} else {
|
||||
content_size = sizeof(frame->content.data.size) + frame->content.data.size;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return SIZE_MAX;
|
||||
}
|
||||
|
||||
return content_size > received_content_size ? content_size - received_content_size : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enumeration of protocol parser statuses.
|
||||
*/
|
||||
typedef enum {
|
||||
ExpansionProtocolStatusOk, /**< No error has occurred. */
|
||||
ExpansionProtocolStatusErrorFormat, /**< Invalid frame type. */
|
||||
ExpansionProtocolStatusErrorChecksum, /**< Checksum mismatch. */
|
||||
ExpansionProtocolStatusErrorCommunication, /**< Input/output error. */
|
||||
} ExpansionProtocolStatus;
|
||||
|
||||
/**
|
||||
* @brief Get the checksum byte corresponding to the frame
|
||||
*
|
||||
* Lightweight XOR checksum algorithm for basic error detection.
|
||||
*
|
||||
* @param[in] data pointer to a byte buffer containing the data.
|
||||
* @param[in] data_size size of the data buffer.
|
||||
* @returns checksum byte of the frame.
|
||||
*/
|
||||
static inline ExpansionFrameChecksum
|
||||
expansion_protocol_get_checksum(const uint8_t* data, size_t data_size) {
|
||||
ExpansionFrameChecksum checksum = 0;
|
||||
for(size_t i = 0; i < data_size; ++i) {
|
||||
checksum ^= data[i];
|
||||
}
|
||||
return checksum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Receive and decode a frame.
|
||||
*
|
||||
* Will repeatedly call the receive callback function until enough data is received.
|
||||
*
|
||||
* @param[out] frame pointer to the frame to contain decoded data.
|
||||
* @param[in] receive pointer to the function used to receive data.
|
||||
* @param[in,out] context pointer to a user-defined context object. Will be passed to the receive callback function.
|
||||
* @returns ExpansionProtocolStatusOk on success, any other error code on failure.
|
||||
*/
|
||||
static inline ExpansionProtocolStatus expansion_protocol_decode(
|
||||
ExpansionFrame* frame,
|
||||
ExpansionFrameReceiveCallback receive,
|
||||
void* context) {
|
||||
size_t total_size = 0;
|
||||
size_t remaining_size;
|
||||
|
||||
while(true) {
|
||||
remaining_size = expansion_frame_get_remaining_size(frame, total_size);
|
||||
|
||||
if(remaining_size == SIZE_MAX) {
|
||||
return ExpansionProtocolStatusErrorFormat;
|
||||
} else if(remaining_size == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
const size_t received_size =
|
||||
receive((uint8_t*)frame + total_size, remaining_size, context);
|
||||
|
||||
if(received_size == 0) {
|
||||
return ExpansionProtocolStatusErrorCommunication;
|
||||
}
|
||||
|
||||
total_size += received_size;
|
||||
}
|
||||
|
||||
ExpansionFrameChecksum checksum;
|
||||
const size_t received_size = receive(&checksum, sizeof(checksum), context);
|
||||
|
||||
if(received_size != sizeof(checksum)) {
|
||||
return ExpansionProtocolStatusErrorCommunication;
|
||||
} else if(checksum != expansion_protocol_get_checksum((const uint8_t*)frame, total_size)) {
|
||||
return ExpansionProtocolStatusErrorChecksum;
|
||||
} else {
|
||||
return ExpansionProtocolStatusOk;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode and send a frame.
|
||||
*
|
||||
* @param[in] frame pointer to the frame to be encoded and sent.
|
||||
* @param[in] send pointer to the function used to send data.
|
||||
* @param[in,out] context pointer to a user-defined context object. Will be passed to the send callback function.
|
||||
* @returns ExpansionProtocolStatusOk on success, any other error code on failure.
|
||||
*/
|
||||
static inline ExpansionProtocolStatus expansion_protocol_encode(
|
||||
const ExpansionFrame* frame,
|
||||
ExpansionFrameSendCallback send,
|
||||
void* context) {
|
||||
const size_t encoded_size = expansion_frame_get_encoded_size(frame);
|
||||
if(encoded_size == 0) {
|
||||
return ExpansionProtocolStatusErrorFormat;
|
||||
}
|
||||
|
||||
const ExpansionFrameChecksum checksum =
|
||||
expansion_protocol_get_checksum((const uint8_t*)frame, encoded_size);
|
||||
|
||||
if((send((const uint8_t*)frame, encoded_size, context) != encoded_size) ||
|
||||
(send(&checksum, sizeof(checksum), context) != sizeof(checksum))) {
|
||||
return ExpansionProtocolStatusErrorCommunication;
|
||||
} else {
|
||||
return ExpansionProtocolStatusOk;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
34
applications/services/expansion/expansion_settings.c
Normal file
34
applications/services/expansion/expansion_settings.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include "expansion_settings.h"
|
||||
|
||||
#include <storage/storage.h>
|
||||
#include <toolbox/saved_struct.h>
|
||||
#include <furi_hal_serial.h>
|
||||
|
||||
#include "expansion_settings_filename.h"
|
||||
|
||||
#define EXPANSION_SETTINGS_PATH INT_PATH(EXPANSION_SETTINGS_FILE_NAME)
|
||||
#define EXPANSION_SETTINGS_VERSION (0)
|
||||
#define EXPANSION_SETTINGS_MAGIC (0xEA)
|
||||
|
||||
bool expansion_settings_load(ExpansionSettings* settings) {
|
||||
furi_assert(settings);
|
||||
if(!saved_struct_load(
|
||||
EXPANSION_SETTINGS_PATH,
|
||||
settings,
|
||||
sizeof(ExpansionSettings),
|
||||
EXPANSION_SETTINGS_MAGIC,
|
||||
EXPANSION_SETTINGS_VERSION)) {
|
||||
settings->uart_index = FuriHalSerialIdMax;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool expansion_settings_save(ExpansionSettings* settings) {
|
||||
furi_assert(settings);
|
||||
return saved_struct_save(
|
||||
EXPANSION_SETTINGS_PATH,
|
||||
settings,
|
||||
sizeof(ExpansionSettings),
|
||||
EXPANSION_SETTINGS_MAGIC,
|
||||
EXPANSION_SETTINGS_VERSION);
|
||||
}
|
43
applications/services/expansion/expansion_settings.h
Normal file
43
applications/services/expansion/expansion_settings.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* @file expansion_settings.h
|
||||
* @brief Expansion module support settings.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Expansion module support settings storage type.
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* Numerical index of serial port used to communicate
|
||||
* with expansion modules.
|
||||
*/
|
||||
uint8_t uart_index;
|
||||
} ExpansionSettings;
|
||||
|
||||
/**
|
||||
* @brief Load expansion module support settings from file.
|
||||
*
|
||||
* @param[out] settings pointer to an ExpansionSettings instance to load settings into.
|
||||
* @returns true if the settings were successfully loaded, false otherwise.
|
||||
*/
|
||||
bool expansion_settings_load(ExpansionSettings* settings);
|
||||
|
||||
/**
|
||||
* @brief Save expansion module support settings to file.
|
||||
*
|
||||
* @param[in] settings pointer to an ExpansionSettings instance to save settings from.
|
||||
* @returns true if the settings were successfully saved, false otherwise.
|
||||
*/
|
||||
bool expansion_settings_save(ExpansionSettings* settings);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,9 @@
|
|||
/**
|
||||
* @file expansion_settings_filename.h
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @brief File name used for expansion settings.
|
||||
*/
|
||||
#define EXPANSION_SETTINGS_FILE_NAME ".expansion.settings"
|
|
@ -160,8 +160,11 @@ void rpc_session_set_terminated_callback(
|
|||
* command is gets processed - it's safe either way. But case of it is quite
|
||||
* odd: client sends close request and sends command after.
|
||||
*/
|
||||
size_t
|
||||
rpc_session_feed(RpcSession* session, uint8_t* encoded_bytes, size_t size, uint32_t timeout) {
|
||||
size_t rpc_session_feed(
|
||||
RpcSession* session,
|
||||
const uint8_t* encoded_bytes,
|
||||
size_t size,
|
||||
uint32_t timeout) {
|
||||
furi_assert(session);
|
||||
furi_assert(encoded_bytes);
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ typedef enum {
|
|||
RpcOwnerUnknown = 0,
|
||||
RpcOwnerBle,
|
||||
RpcOwnerUsb,
|
||||
RpcOwnerUart,
|
||||
RpcOwnerCount,
|
||||
} RpcOwner;
|
||||
|
||||
|
@ -124,7 +125,7 @@ void rpc_session_set_terminated_callback(
|
|||
*
|
||||
* @return actually consumed bytes
|
||||
*/
|
||||
size_t rpc_session_feed(RpcSession* session, uint8_t* buffer, size_t size, uint32_t timeout);
|
||||
size_t rpc_session_feed(RpcSession* session, const uint8_t* buffer, size_t size, uint32_t timeout);
|
||||
|
||||
/** Get available size of RPC buffer
|
||||
*
|
||||
|
@ -136,4 +137,4 @@ size_t rpc_session_get_available_size(RpcSession* session);
|
|||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -265,7 +265,7 @@ static void rpc_system_gui_virtual_display_input_callback(InputEvent* event, voi
|
|||
RpcGuiSystem* rpc_gui = context;
|
||||
RpcSession* session = rpc_gui->session;
|
||||
|
||||
FURI_LOG_D(TAG, "VirtulDisplay: SendInputEvent");
|
||||
FURI_LOG_D(TAG, "VirtualDisplay: SendInputEvent");
|
||||
|
||||
PB_Main rpc_message = {
|
||||
.command_id = 0,
|
||||
|
@ -317,7 +317,7 @@ static void rpc_system_gui_start_virtual_display_process(const PB_Main* request,
|
|||
rpc_gui);
|
||||
|
||||
if(request->content.gui_start_virtual_display_request.send_input) {
|
||||
FURI_LOG_D(TAG, "VirtulDisplay: input forwarding requested");
|
||||
FURI_LOG_D(TAG, "VirtualDisplay: input forwarding requested");
|
||||
view_port_input_callback_set(
|
||||
rpc_gui->virtual_display_view_port,
|
||||
rpc_system_gui_virtual_display_input_callback,
|
||||
|
@ -464,4 +464,4 @@ void rpc_system_gui_free(void* context) {
|
|||
}
|
||||
furi_record_close(RECORD_GUI);
|
||||
free(rpc_gui);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
App(
|
||||
appid="expansion_settings",
|
||||
name="Expansion Modules",
|
||||
apptype=FlipperAppType.SETTINGS,
|
||||
entry_point="expansion_settings_app",
|
||||
requires=["gui"],
|
||||
stack_size=1 * 1024,
|
||||
order=80,
|
||||
)
|
|
@ -0,0 +1,89 @@
|
|||
#include "expansion_settings_app.h"
|
||||
|
||||
static const char* const expansion_uart_text[] = {
|
||||
"USART",
|
||||
"LPUART",
|
||||
"None",
|
||||
};
|
||||
|
||||
static void expansion_settings_app_uart_changed(VariableItem* item) {
|
||||
ExpansionSettingsApp* app = variable_item_get_context(item);
|
||||
const uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, expansion_uart_text[index]);
|
||||
app->settings.uart_index = index;
|
||||
|
||||
if(index < FuriHalSerialIdMax) {
|
||||
expansion_enable(app->expansion, index);
|
||||
} else {
|
||||
expansion_disable(app->expansion);
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t expansion_settings_app_exit(void* context) {
|
||||
UNUSED(context);
|
||||
return VIEW_NONE;
|
||||
}
|
||||
|
||||
static ExpansionSettingsApp* expansion_settings_app_alloc() {
|
||||
ExpansionSettingsApp* app = malloc(sizeof(ExpansionSettingsApp));
|
||||
|
||||
expansion_settings_load(&app->settings);
|
||||
|
||||
app->gui = furi_record_open(RECORD_GUI);
|
||||
app->expansion = furi_record_open(RECORD_EXPANSION);
|
||||
|
||||
app->view_dispatcher = view_dispatcher_alloc();
|
||||
view_dispatcher_enable_queue(app->view_dispatcher);
|
||||
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
|
||||
|
||||
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
||||
|
||||
app->var_item_list = variable_item_list_alloc();
|
||||
|
||||
VariableItem* item;
|
||||
uint8_t value_index;
|
||||
|
||||
item = variable_item_list_add(
|
||||
app->var_item_list,
|
||||
"Listen UART",
|
||||
COUNT_OF(expansion_uart_text),
|
||||
expansion_settings_app_uart_changed,
|
||||
app);
|
||||
value_index = app->settings.uart_index;
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, expansion_uart_text[value_index]);
|
||||
|
||||
view_set_previous_callback(
|
||||
variable_item_list_get_view(app->var_item_list), expansion_settings_app_exit);
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher,
|
||||
ExpansionSettingsViewVarItemList,
|
||||
variable_item_list_get_view(app->var_item_list));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, ExpansionSettingsViewVarItemList);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
static void expansion_settings_app_free(ExpansionSettingsApp* app) {
|
||||
furi_assert(app);
|
||||
|
||||
expansion_settings_save(&app->settings);
|
||||
|
||||
view_dispatcher_remove_view(app->view_dispatcher, ExpansionSettingsViewVarItemList);
|
||||
variable_item_list_free(app->var_item_list);
|
||||
view_dispatcher_free(app->view_dispatcher);
|
||||
|
||||
furi_record_close(RECORD_EXPANSION);
|
||||
furi_record_close(RECORD_GUI);
|
||||
|
||||
free(app);
|
||||
}
|
||||
|
||||
int32_t expansion_settings_app(void* p) {
|
||||
UNUSED(p);
|
||||
ExpansionSettingsApp* app = expansion_settings_app_alloc();
|
||||
view_dispatcher_run(app->view_dispatcher);
|
||||
expansion_settings_app_free(app);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view_dispatcher.h>
|
||||
#include <gui/modules/variable_item_list.h>
|
||||
|
||||
#include <expansion/expansion.h>
|
||||
#include <expansion/expansion_settings.h>
|
||||
|
||||
typedef struct {
|
||||
Gui* gui;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
VariableItemList* var_item_list;
|
||||
Expansion* expansion;
|
||||
ExpansionSettings settings;
|
||||
} ExpansionSettingsApp;
|
||||
|
||||
typedef enum {
|
||||
ExpansionSettingsViewVarItemList,
|
||||
} ExpansionSettingsView;
|
|
@ -20,8 +20,11 @@ static const NotificationSequence sequence_note_c = {
|
|||
NULL,
|
||||
};
|
||||
|
||||
#define CONTRAST_COUNT 11
|
||||
#define CONTRAST_COUNT 17
|
||||
const char* const contrast_text[CONTRAST_COUNT] = {
|
||||
"-8",
|
||||
"-7",
|
||||
"-6",
|
||||
"-5",
|
||||
"-4",
|
||||
"-3",
|
||||
|
@ -33,8 +36,14 @@ const char* const contrast_text[CONTRAST_COUNT] = {
|
|||
"+3",
|
||||
"+4",
|
||||
"+5",
|
||||
"+6",
|
||||
"+7",
|
||||
"+8",
|
||||
};
|
||||
const int32_t contrast_value[CONTRAST_COUNT] = {
|
||||
-8,
|
||||
-7,
|
||||
-6,
|
||||
-5,
|
||||
-4,
|
||||
-3,
|
||||
|
@ -46,6 +55,9 @@ const int32_t contrast_value[CONTRAST_COUNT] = {
|
|||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
};
|
||||
|
||||
#define BACKLIGHT_COUNT 21
|
||||
|
|
|
@ -24,12 +24,56 @@ const uint32_t log_level_value[] = {
|
|||
};
|
||||
|
||||
static void log_level_changed(VariableItem* item) {
|
||||
// SystemSettings* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, log_level_text[index]);
|
||||
furi_hal_rtc_set_log_level(log_level_value[index]);
|
||||
}
|
||||
|
||||
const char* const log_device_text[] = {
|
||||
"USART",
|
||||
"LPUART",
|
||||
"None",
|
||||
};
|
||||
|
||||
const uint32_t log_device_value[] = {
|
||||
FuriHalRtcLogDeviceUsart,
|
||||
FuriHalRtcLogDeviceLpuart,
|
||||
FuriHalRtcLogDeviceNone};
|
||||
|
||||
static void log_device_changed(VariableItem* item) {
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, log_device_text[index]);
|
||||
furi_hal_rtc_set_log_device(log_device_value[index]);
|
||||
}
|
||||
|
||||
const char* const log_baud_rate_text[] = {
|
||||
"9600",
|
||||
"38400",
|
||||
"57600",
|
||||
"115200",
|
||||
"230400",
|
||||
"460800",
|
||||
"921600",
|
||||
"1843200",
|
||||
};
|
||||
|
||||
const uint32_t log_baud_rate_value[] = {
|
||||
FuriHalRtcLogBaudRate9600,
|
||||
FuriHalRtcLogBaudRate38400,
|
||||
FuriHalRtcLogBaudRate57600,
|
||||
FuriHalRtcLogBaudRate115200,
|
||||
FuriHalRtcLogBaudRate230400,
|
||||
FuriHalRtcLogBaudRate460800,
|
||||
FuriHalRtcLogBaudRate921600,
|
||||
FuriHalRtcLogBaudRate1843200,
|
||||
};
|
||||
|
||||
static void log_baud_rate_changed(VariableItem* item) {
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, log_baud_rate_text[index]);
|
||||
furi_hal_rtc_set_log_baud_rate(log_baud_rate_value[index]);
|
||||
}
|
||||
|
||||
const char* const debug_text[] = {
|
||||
"OFF",
|
||||
"ON",
|
||||
|
@ -64,7 +108,6 @@ const uint32_t heap_trace_mode_value[] = {
|
|||
};
|
||||
|
||||
static void heap_trace_mode_changed(VariableItem* item) {
|
||||
// SystemSettings* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, heap_trace_mode_text[index]);
|
||||
furi_hal_rtc_set_heap_track_mode(heap_trace_mode_value[index]);
|
||||
|
@ -81,7 +124,6 @@ const uint32_t measurement_units_value[] = {
|
|||
};
|
||||
|
||||
static void measurement_units_changed(VariableItem* item) {
|
||||
// SystemSettings* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, measurement_units_text[index]);
|
||||
locale_set_measurement_unit(measurement_units_value[index]);
|
||||
|
@ -98,7 +140,6 @@ const uint32_t time_format_value[] = {
|
|||
};
|
||||
|
||||
static void time_format_changed(VariableItem* item) {
|
||||
// SystemSettings* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, time_format_text[index]);
|
||||
locale_set_time_format(time_format_value[index]);
|
||||
|
@ -117,7 +158,6 @@ const uint32_t date_format_value[] = {
|
|||
};
|
||||
|
||||
static void date_format_changed(VariableItem* item) {
|
||||
// SystemSettings* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, date_format_text[index]);
|
||||
locale_set_date_format(date_format_value[index]);
|
||||
|
@ -227,6 +267,24 @@ SystemSettings* system_settings_alloc() {
|
|||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, log_level_text[value_index]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
app->var_item_list, "Log Device", COUNT_OF(log_device_text), log_device_changed, app);
|
||||
value_index = value_index_uint32(
|
||||
furi_hal_rtc_get_log_device(), log_device_value, COUNT_OF(log_device_text));
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, log_device_text[value_index]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
app->var_item_list,
|
||||
"Log Baud Rate",
|
||||
COUNT_OF(log_baud_rate_text),
|
||||
log_baud_rate_changed,
|
||||
app);
|
||||
value_index = value_index_uint32(
|
||||
furi_hal_rtc_get_log_baud_rate(), log_baud_rate_value, COUNT_OF(log_baud_rate_text));
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, log_baud_rate_text[value_index]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
app->var_item_list, "Debug", COUNT_OF(debug_text), debug_changed, app);
|
||||
value_index = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug) ? 1 : 0;
|
||||
|
|
|
@ -11,6 +11,7 @@ enum HidDebugSubmenuIndex {
|
|||
HidSubmenuIndexKeyboard,
|
||||
HidSubmenuIndexNumpad,
|
||||
HidSubmenuIndexMedia,
|
||||
HidSubmenuIndexMusicMacOs,
|
||||
HidSubmenuIndexMovie,
|
||||
HidSubmenuIndexTikShorts,
|
||||
HidSubmenuIndexMouse,
|
||||
|
@ -39,6 +40,9 @@ static void hid_submenu_callback(void* context, uint32_t index) {
|
|||
} else if(index == HidSubmenuIndexMedia) {
|
||||
app->view_id = HidViewMedia;
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewMedia);
|
||||
} else if(index == HidSubmenuIndexMusicMacOs) {
|
||||
app->view_id = HidViewMusicMacOs;
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewMusicMacOs);
|
||||
} else if(index == HidSubmenuIndexMovie) {
|
||||
app->view_id = HidViewMovie;
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewMovie);
|
||||
|
@ -75,6 +79,7 @@ static void bt_hid_connection_status_changed_callback(BtStatus status, void* con
|
|||
hid_keyboard_set_connected_status(hid->hid_keyboard, connected);
|
||||
hid_numpad_set_connected_status(hid->hid_numpad, connected);
|
||||
hid_media_set_connected_status(hid->hid_media, connected);
|
||||
hid_music_macos_set_connected_status(hid->hid_music_macos, connected);
|
||||
hid_movie_set_connected_status(hid->hid_movie, connected);
|
||||
hid_mouse_set_connected_status(hid->hid_mouse, connected);
|
||||
hid_mouse_clicker_set_connected_status(hid->hid_mouse_clicker, connected);
|
||||
|
@ -131,6 +136,12 @@ Hid* hid_alloc(HidTransport transport) {
|
|||
app->device_type_submenu, "Numpad", HidSubmenuIndexNumpad, hid_submenu_callback, app);
|
||||
submenu_add_item(
|
||||
app->device_type_submenu, "Media", HidSubmenuIndexMedia, hid_submenu_callback, app);
|
||||
submenu_add_item(
|
||||
app->device_type_submenu,
|
||||
"Apple Music macOS",
|
||||
HidSubmenuIndexMusicMacOs,
|
||||
hid_submenu_callback,
|
||||
app);
|
||||
submenu_add_item(
|
||||
app->device_type_submenu, "Movie", HidSubmenuIndexMovie, hid_submenu_callback, app);
|
||||
submenu_add_item(
|
||||
|
@ -156,7 +167,11 @@ Hid* hid_alloc(HidTransport transport) {
|
|||
hid_submenu_callback,
|
||||
app);
|
||||
submenu_add_item(
|
||||
app->device_type_submenu, "PushToTalk", HidSubmenuIndexPushToTalk, hid_submenu_callback, app);
|
||||
app->device_type_submenu,
|
||||
"PushToTalk",
|
||||
HidSubmenuIndexPushToTalk,
|
||||
hid_submenu_callback,
|
||||
app);
|
||||
view_set_previous_callback(submenu_get_view(app->device_type_submenu), hid_exit);
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, HidViewSubmenu, submenu_get_view(app->device_type_submenu));
|
||||
|
@ -192,7 +207,13 @@ Hid* hid_app_alloc_view(void* context) {
|
|||
view_set_previous_callback(hid_media_get_view(app->hid_media), hid_menu_view);
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, HidViewMedia, hid_media_get_view(app->hid_media));
|
||||
|
||||
|
||||
// Music MacOs view
|
||||
app->hid_music_macos = hid_music_macos_alloc(app);
|
||||
view_set_previous_callback(hid_music_macos_get_view(app->hid_music_macos), hid_menu_view);
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, HidViewMusicMacOs, hid_music_macos_get_view(app->hid_music_macos));
|
||||
|
||||
// Movie view
|
||||
app->hid_movie = hid_movie_alloc(app);
|
||||
view_set_previous_callback(hid_movie_get_view(app->hid_movie), hid_menu_view);
|
||||
|
@ -213,8 +234,7 @@ Hid* hid_app_alloc_view(void* context) {
|
|||
|
||||
// Mouse clicker view
|
||||
app->hid_mouse_clicker = hid_mouse_clicker_alloc(app);
|
||||
view_set_previous_callback(
|
||||
hid_mouse_clicker_get_view(app->hid_mouse_clicker), hid_menu_view);
|
||||
view_set_previous_callback(hid_mouse_clicker_get_view(app->hid_mouse_clicker), hid_menu_view);
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher,
|
||||
HidViewMouseClicker,
|
||||
|
@ -222,8 +242,7 @@ Hid* hid_app_alloc_view(void* context) {
|
|||
|
||||
// Mouse jiggler view
|
||||
app->hid_mouse_jiggler = hid_mouse_jiggler_alloc(app);
|
||||
view_set_previous_callback(
|
||||
hid_mouse_jiggler_get_view(app->hid_mouse_jiggler), hid_menu_view);
|
||||
view_set_previous_callback(hid_mouse_jiggler_get_view(app->hid_mouse_jiggler), hid_menu_view);
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher,
|
||||
HidViewMouseJiggler,
|
||||
|
@ -233,7 +252,7 @@ Hid* hid_app_alloc_view(void* context) {
|
|||
app->hid_ptt_menu = hid_ptt_menu_alloc(app);
|
||||
view_set_previous_callback(hid_ptt_menu_get_view(app->hid_ptt_menu), hid_menu_view);
|
||||
view_dispatcher_add_view(
|
||||
app->view_dispatcher, HidViewPushToTalkMenu, hid_ptt_menu_get_view(app->hid_ptt_menu));
|
||||
app->view_dispatcher, HidViewPushToTalkMenu, hid_ptt_menu_get_view(app->hid_ptt_menu));
|
||||
app->hid_ptt = hid_ptt_alloc(app);
|
||||
view_set_previous_callback(hid_ptt_get_view(app->hid_ptt), hid_ptt_menu_view);
|
||||
view_dispatcher_add_view(
|
||||
|
@ -261,6 +280,8 @@ void hid_free(Hid* app) {
|
|||
hid_numpad_free(app->hid_numpad);
|
||||
view_dispatcher_remove_view(app->view_dispatcher, HidViewMedia);
|
||||
hid_media_free(app->hid_media);
|
||||
view_dispatcher_remove_view(app->view_dispatcher, HidViewMusicMacOs);
|
||||
hid_music_macos_free(app->hid_music_macos);
|
||||
view_dispatcher_remove_view(app->view_dispatcher, HidViewMovie);
|
||||
hid_movie_free(app->hid_movie);
|
||||
view_dispatcher_remove_view(app->view_dispatcher, HidViewMouse);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "views/hid_keyboard.h"
|
||||
#include "views/hid_numpad.h"
|
||||
#include "views/hid_media.h"
|
||||
#include "views/hid_music_macos.h"
|
||||
#include "views/hid_movie.h"
|
||||
#include "views/hid_mouse.h"
|
||||
#include "views/hid_mouse_clicker.h"
|
||||
|
@ -48,6 +49,7 @@ struct Hid {
|
|||
HidKeyboard* hid_keyboard;
|
||||
HidNumpad* hid_numpad;
|
||||
HidMedia* hid_media;
|
||||
HidMusicMacos* hid_music_macos;
|
||||
HidMovie* hid_movie;
|
||||
HidMouse* hid_mouse;
|
||||
HidMouseClicker* hid_mouse_clicker;
|
||||
|
|
|
@ -4,6 +4,7 @@ typedef enum {
|
|||
HidViewKeyboard,
|
||||
HidViewNumpad,
|
||||
HidViewMedia,
|
||||
HidViewMusicMacOs,
|
||||
HidViewMovie,
|
||||
HidViewMouse,
|
||||
HidViewMouseClicker,
|
||||
|
|
242
applications/system/hid_app/views/hid_music_macos.c
Normal file
242
applications/system/hid_app/views/hid_music_macos.c
Normal file
|
@ -0,0 +1,242 @@
|
|||
#include "hid_music_macos.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal_bt_hid.h>
|
||||
#include <furi_hal_usb_hid.h>
|
||||
#include <gui/elements.h>
|
||||
#include "../hid.h"
|
||||
|
||||
#include "hid_icons.h"
|
||||
|
||||
#define TAG "HidMusicMacos"
|
||||
|
||||
struct HidMusicMacos {
|
||||
View* view;
|
||||
Hid* hid;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
bool left_pressed;
|
||||
bool up_pressed;
|
||||
bool right_pressed;
|
||||
bool down_pressed;
|
||||
bool ok_pressed;
|
||||
bool connected;
|
||||
bool back_pressed;
|
||||
HidTransport transport;
|
||||
} HidMusicMacosModel;
|
||||
|
||||
static void hid_music_macos_draw_arrow(Canvas* canvas, uint8_t x, uint8_t y, CanvasDirection dir) {
|
||||
canvas_draw_triangle(canvas, x, y, 5, 3, dir);
|
||||
if(dir == CanvasDirectionBottomToTop) {
|
||||
canvas_draw_dot(canvas, x, y - 1);
|
||||
} else if(dir == CanvasDirectionTopToBottom) {
|
||||
canvas_draw_dot(canvas, x, y + 1);
|
||||
} else if(dir == CanvasDirectionRightToLeft) {
|
||||
canvas_draw_dot(canvas, x - 1, y);
|
||||
} else if(dir == CanvasDirectionLeftToRight) {
|
||||
canvas_draw_dot(canvas, x + 1, y);
|
||||
}
|
||||
}
|
||||
|
||||
static void hid_music_macos_draw_callback(Canvas* canvas, void* context) {
|
||||
furi_assert(context);
|
||||
HidMusicMacosModel* model = context;
|
||||
|
||||
// Header
|
||||
if(model->transport == HidTransportBle) {
|
||||
if(model->connected) {
|
||||
canvas_draw_icon(canvas, 0, 0, &I_Ble_connected_15x15);
|
||||
} else {
|
||||
canvas_draw_icon(canvas, 0, 0, &I_Ble_disconnected_15x15);
|
||||
}
|
||||
}
|
||||
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
elements_multiline_text_aligned(canvas, 17, 3, AlignLeft, AlignTop, "Music");
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
|
||||
// Keypad circles
|
||||
canvas_draw_icon(canvas, 58, 3, &I_OutCircles_70x51);
|
||||
|
||||
// Up
|
||||
if(model->up_pressed) {
|
||||
canvas_set_bitmap_mode(canvas, 1);
|
||||
canvas_draw_icon(canvas, 68, 6, &I_S_UP_31x15);
|
||||
canvas_set_bitmap_mode(canvas, 0);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
}
|
||||
canvas_draw_icon(canvas, 79, 9, &I_Volup_8x6);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
// Down
|
||||
if(model->down_pressed) {
|
||||
canvas_set_bitmap_mode(canvas, 1);
|
||||
canvas_draw_icon(canvas, 68, 36, &I_S_DOWN_31x15);
|
||||
canvas_set_bitmap_mode(canvas, 0);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
}
|
||||
canvas_draw_icon(canvas, 80, 41, &I_Voldwn_6x6);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
// Left
|
||||
if(model->left_pressed) {
|
||||
canvas_set_bitmap_mode(canvas, 1);
|
||||
canvas_draw_icon(canvas, 61, 13, &I_S_LEFT_15x31);
|
||||
canvas_set_bitmap_mode(canvas, 0);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
}
|
||||
hid_music_macos_draw_arrow(canvas, 67, 28, CanvasDirectionRightToLeft);
|
||||
hid_music_macos_draw_arrow(canvas, 70, 28, CanvasDirectionRightToLeft);
|
||||
canvas_draw_line(canvas, 64, 26, 64, 30);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
// Right
|
||||
if(model->right_pressed) {
|
||||
canvas_set_bitmap_mode(canvas, 1);
|
||||
canvas_draw_icon(canvas, 91, 13, &I_S_RIGHT_15x31);
|
||||
canvas_set_bitmap_mode(canvas, 0);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
}
|
||||
hid_music_macos_draw_arrow(canvas, 96, 28, CanvasDirectionLeftToRight);
|
||||
hid_music_macos_draw_arrow(canvas, 99, 28, CanvasDirectionLeftToRight);
|
||||
canvas_draw_line(canvas, 102, 26, 102, 30);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
// Ok
|
||||
if(model->ok_pressed) {
|
||||
canvas_set_bitmap_mode(canvas, 1);
|
||||
canvas_draw_icon(canvas, 74, 19, &I_Pressed_Button_19x19);
|
||||
canvas_set_bitmap_mode(canvas, 0);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
}
|
||||
hid_music_macos_draw_arrow(canvas, 80, 28, CanvasDirectionLeftToRight);
|
||||
canvas_draw_line(canvas, 84, 26, 84, 30);
|
||||
canvas_draw_line(canvas, 86, 26, 86, 30);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
// Exit
|
||||
if(model->back_pressed) {
|
||||
canvas_set_bitmap_mode(canvas, 1);
|
||||
canvas_draw_icon(canvas, 107, 33, &I_Pressed_Button_19x19);
|
||||
canvas_set_bitmap_mode(canvas, 0);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
}
|
||||
canvas_draw_icon(canvas, 111, 38, &I_Pin_back_arrow_10x10);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
canvas_draw_icon(canvas, 0, 54, &I_Pin_back_arrow_10x8);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
elements_multiline_text_aligned(canvas, 13, 62, AlignLeft, AlignBottom, "Hold to exit");
|
||||
}
|
||||
|
||||
static void hid_music_macos_process_press(HidMusicMacos* hid_music_macos, InputEvent* event) {
|
||||
with_view_model(
|
||||
hid_music_macos->view,
|
||||
HidMusicMacosModel * model,
|
||||
{
|
||||
if(event->key == InputKeyUp) {
|
||||
model->up_pressed = true;
|
||||
hid_hal_keyboard_press(
|
||||
hid_music_macos->hid, KEY_MOD_LEFT_GUI | HID_KEYBOARD_UP_ARROW);
|
||||
hid_hal_keyboard_release(
|
||||
hid_music_macos->hid, KEY_MOD_LEFT_GUI | HID_KEYBOARD_UP_ARROW);
|
||||
} else if(event->key == InputKeyDown) {
|
||||
model->down_pressed = true;
|
||||
hid_hal_keyboard_press(
|
||||
hid_music_macos->hid, KEY_MOD_LEFT_GUI | HID_KEYBOARD_DOWN_ARROW);
|
||||
hid_hal_keyboard_release(
|
||||
hid_music_macos->hid, KEY_MOD_LEFT_GUI | HID_KEYBOARD_DOWN_ARROW);
|
||||
} else if(event->key == InputKeyLeft) {
|
||||
model->left_pressed = true;
|
||||
hid_hal_consumer_key_press(hid_music_macos->hid, HID_CONSUMER_SCAN_PREVIOUS_TRACK);
|
||||
} else if(event->key == InputKeyRight) {
|
||||
model->right_pressed = true;
|
||||
hid_hal_consumer_key_press(hid_music_macos->hid, HID_CONSUMER_SCAN_NEXT_TRACK);
|
||||
} else if(event->key == InputKeyOk) {
|
||||
model->ok_pressed = true;
|
||||
hid_hal_consumer_key_press(hid_music_macos->hid, HID_CONSUMER_PLAY_PAUSE);
|
||||
} else if(event->key == InputKeyBack) {
|
||||
model->back_pressed = true;
|
||||
}
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
static void hid_music_macos_process_release(HidMusicMacos* hid_music_macos, InputEvent* event) {
|
||||
with_view_model(
|
||||
hid_music_macos->view,
|
||||
HidMusicMacosModel * model,
|
||||
{
|
||||
if(event->key == InputKeyUp) {
|
||||
model->up_pressed = false;
|
||||
} else if(event->key == InputKeyDown) {
|
||||
model->down_pressed = false;
|
||||
} else if(event->key == InputKeyLeft) {
|
||||
model->left_pressed = false;
|
||||
hid_hal_consumer_key_release(
|
||||
hid_music_macos->hid, HID_CONSUMER_SCAN_PREVIOUS_TRACK);
|
||||
} else if(event->key == InputKeyRight) {
|
||||
model->right_pressed = false;
|
||||
hid_hal_consumer_key_release(hid_music_macos->hid, HID_CONSUMER_SCAN_NEXT_TRACK);
|
||||
} else if(event->key == InputKeyOk) {
|
||||
model->ok_pressed = false;
|
||||
hid_hal_consumer_key_release(hid_music_macos->hid, HID_CONSUMER_PLAY_PAUSE);
|
||||
} else if(event->key == InputKeyBack) {
|
||||
model->back_pressed = false;
|
||||
}
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
static bool hid_music_macos_input_callback(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
HidMusicMacos* hid_music_macos = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == InputTypeLong && event->key == InputKeyBack) {
|
||||
hid_hal_keyboard_release_all(hid_music_macos->hid);
|
||||
} else {
|
||||
consumed = true;
|
||||
if(event->type == InputTypePress) {
|
||||
hid_music_macos_process_press(hid_music_macos, event);
|
||||
} else if(event->type == InputTypeRelease) {
|
||||
hid_music_macos_process_release(hid_music_macos, event);
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
HidMusicMacos* hid_music_macos_alloc(Hid* hid) {
|
||||
HidMusicMacos* hid_music_macos = malloc(sizeof(HidMusicMacos));
|
||||
hid_music_macos->view = view_alloc();
|
||||
hid_music_macos->hid = hid;
|
||||
view_set_context(hid_music_macos->view, hid_music_macos);
|
||||
view_allocate_model(hid_music_macos->view, ViewModelTypeLocking, sizeof(HidMusicMacosModel));
|
||||
view_set_draw_callback(hid_music_macos->view, hid_music_macos_draw_callback);
|
||||
view_set_input_callback(hid_music_macos->view, hid_music_macos_input_callback);
|
||||
|
||||
with_view_model(
|
||||
hid_music_macos->view,
|
||||
HidMusicMacosModel * model,
|
||||
{ model->transport = hid->transport; },
|
||||
true);
|
||||
|
||||
return hid_music_macos;
|
||||
}
|
||||
|
||||
void hid_music_macos_free(HidMusicMacos* hid_music_macos) {
|
||||
furi_assert(hid_music_macos);
|
||||
view_free(hid_music_macos->view);
|
||||
free(hid_music_macos);
|
||||
}
|
||||
|
||||
View* hid_music_macos_get_view(HidMusicMacos* hid_music_macos) {
|
||||
furi_assert(hid_music_macos);
|
||||
return hid_music_macos->view;
|
||||
}
|
||||
|
||||
void hid_music_macos_set_connected_status(HidMusicMacos* hid_music_macos, bool connected) {
|
||||
furi_assert(hid_music_macos);
|
||||
with_view_model(
|
||||
hid_music_macos->view, HidMusicMacosModel * model, { model->connected = connected; }, true);
|
||||
}
|
13
applications/system/hid_app/views/hid_music_macos.h
Normal file
13
applications/system/hid_app/views/hid_music_macos.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
|
||||
typedef struct HidMusicMacos HidMusicMacos;
|
||||
|
||||
HidMusicMacos* hid_music_macos_alloc();
|
||||
|
||||
void hid_music_macos_free(HidMusicMacos* hid_music_macos);
|
||||
|
||||
View* hid_music_macos_get_view(HidMusicMacos* hid_music_macos);
|
||||
|
||||
void hid_music_macos_set_connected_status(HidMusicMacos* hid_music_macos, bool connected);
|
|
@ -28,6 +28,10 @@ static void storage_move_to_sd_remove_region() {
|
|||
if(storage_common_exists(storage, INT_PATH(".region_data"))) {
|
||||
storage_common_remove(storage, INT_PATH(".region_data"));
|
||||
}
|
||||
// No expansion modules yet
|
||||
if(storage_common_exists(storage, INT_PATH(".expansion.settings"))) {
|
||||
storage_common_remove(storage, INT_PATH(".expansion.settings"));
|
||||
}
|
||||
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
|
|
@ -348,6 +348,8 @@ int32_t update_task_worker_flash_writer(void* context) {
|
|||
// Production
|
||||
furi_hal_rtc_set_log_level(FuriLogLevelDefault);
|
||||
furi_hal_rtc_reset_flag(FuriHalRtcFlagDebug);
|
||||
furi_hal_rtc_reset_flag(FuriHalRtcFlagLegacySleep);
|
||||
furi_hal_rtc_set_heap_track_mode(FuriHalRtcHeapTrackModeNone);
|
||||
#endif
|
||||
update_task_set_progress(update_task, UpdateTaskStageCompleted, 100);
|
||||
success = true;
|
||||
|
|
BIN
assets/icons/NFC/MFKey_qr_25x25.png
Normal file
BIN
assets/icons/NFC/MFKey_qr_25x25.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 218 B |
Binary file not shown.
Before Width: | Height: | Size: 199 B After Width: | Height: | Size: 994 B |
164
documentation/ExpansionModules.md
Normal file
164
documentation/ExpansionModules.md
Normal file
|
@ -0,0 +1,164 @@
|
|||
# Expansion Module Protocol - Draft
|
||||
|
||||
## Terms and definitions
|
||||
|
||||
- Expansion Module: A third-party hardware unit meant for use with Flipper Zero by connecting it to its GPIO header.
|
||||
- Expansion Module Protocol: A serial-based, byte-oriented, synchronous communication protocol described in this document.
|
||||
- Host: Hardware unit tasked with serving requests. Used interchangeably with Flipper, Server, Host etc. throughout this document.
|
||||
- Device: Used interchangeably with Expansion Module, Module, Client, etc.
|
||||
- RPC: Remote Procedure Call, a protobuf-based communication protocol widely used by Flipper Zero companion applications.
|
||||
- Timeout Interval: Period of inactivity to be treated as a loss of connection, also denoted as Tto. Equals to 250 ms.
|
||||
- Baud Rate Switch Dead Time: Period of time after baud rate change during which no communication is allowed, also denoted Tdt. Equals to 25 ms.
|
||||
|
||||
## Features
|
||||
|
||||
- Automatic expansion module detection
|
||||
- Baud rate negotiation
|
||||
- Basic error detection
|
||||
- Request-response communication flow
|
||||
- Integration with Flipper RPC protocol
|
||||
|
||||
## Hardware
|
||||
|
||||
Depending on the UART selected for communication, the following pins area available for the expansion modules to connect to:
|
||||
|
||||
| UART | Tx pin | Rx pin |
|
||||
|--------|--------|--------|
|
||||
| USART | 13 | 14 |
|
||||
| LPUART | 15 | 16 |
|
||||
|
||||
## Frame structure
|
||||
|
||||
Each frame consists of a header (1 byte), contents (size depends of frame type) and checksum (1 byte) fields:
|
||||
|
||||
| Header (1 byte) | Contents (0 or more bytes) | Checksum (1 byte) |
|
||||
|-----------------|----------------------------|-------------------|
|
||||
| Frame type | Frame payload | XOR checksum |
|
||||
|
||||
### Heartbeat frame
|
||||
|
||||
HEARTBEAT frames are used to maintain an idle connection. In the event of not receiving any frames within Tto, either side must cease all communications and be ready to initiate the connection again.
|
||||
|
||||
| Header (1 byte) | Checksum (1 byte) |
|
||||
|-----------------|-------------------|
|
||||
| 0x01 | XOR checksum |
|
||||
|
||||
Note that the contents field is not present (0 bytes length).
|
||||
|
||||
### Status frame
|
||||
|
||||
STATUS frames are used to report the status of a transaction. Every received frame MUST be confirmed by a matching STATUS response.
|
||||
|
||||
| Header (1 byte) | Contents (1 byte) | Checksum (1 byte) |
|
||||
|-----------------|-------------------|-------------------|
|
||||
| 0x02 | Error code | XOR checksum |
|
||||
|
||||
The `Error code` field SHALL have one of the following values:
|
||||
|
||||
| Error code | Meaning |
|
||||
|------------|-------------------------|
|
||||
| 0x00 | OK (No error) |
|
||||
| 0x01 | Unknown error |
|
||||
| 0x02 | Baud rate not supported |
|
||||
|
||||
### Baud rate frame
|
||||
|
||||
BAUD RATE frames are used to negotiate communication speed. The initial connection SHALL always happen at 9600 baud. The first message sent by the module MUST be a BAUD RATE frame, even if a different speed is not required.
|
||||
|
||||
| Header (1 byte) | Contents (4 bytes) | Checksum (1 byte) |
|
||||
|-----------------|--------------------|-------------------|
|
||||
| 0x03 | Baud rate | XOR checksum |
|
||||
|
||||
If the requested baud rate is supported by the host, it SHALL respond with a STATUS frame with an OK error code, otherwise the error code SHALL be 0x02 (Baud rate not supported). Until the negotiation succeeds, the speed SHALL remain at 9600 baud. The module MAY send additional BAUD RATE frames with alternative speeds in case the initial request was refused. No other frames are allowed until the speed negotiation succeeds.
|
||||
|
||||
### Control frame
|
||||
|
||||
CONTROL frames are used to control various aspects of the communication. As of now, the sole purpose of CONTROL frames is to start and stop the RPC session.
|
||||
|
||||
| Header (1 byte) | Contents (1 byte) | Checksum (1 byte) |
|
||||
|-----------------|-------------------|-------------------|
|
||||
| 0x04 | Command | XOR checksum |
|
||||
|
||||
The `Command` field SHALL have one of the followind values:
|
||||
|
||||
| Command | Meaning |
|
||||
|---------|-------------------|
|
||||
| 0x00 | Start RPC session |
|
||||
| 0x01 | Stop RPC session |
|
||||
|
||||
### Data frame
|
||||
|
||||
DATA frames are used to transmit arbitrary data in either direction. Each DATA frame can hold up to 64 bytes. If an RPC session is curretly open, all received bytes are forwarded to it.
|
||||
|
||||
| Header (1 byte) | Contents (1 to 65 byte(s)) | Checksum (1 byte) |
|
||||
|-----------------|----------------------------|-------------------|
|
||||
| 0x05 | Data | XOR checksum |
|
||||
|
||||
The `Data` field SHALL have the following structure:
|
||||
|
||||
| Data size (1 byte) | Data (0 to 64 bytes) |
|
||||
|--------------------|----------------------|
|
||||
| 0x00 ... 0x40 | Arbitrary data |
|
||||
|
||||
## Communication flow
|
||||
|
||||
In order for the host to be able to detect the module, the respective feature must be enabled first. This can be done via the GUI by going to `Settings -> Expansion Modules` and selecting the required `Listen UART` or programmatically by calling `expansion_enable()`. Likewise, disabling this feature via the same GUI or by calling `expansion_disable()` will result in ceasing all communications and not being able to detect any connected modules.
|
||||
|
||||
The communication is always initiated by the module by the means of shortly pulling the RX pin down. The host SHALL respond with a HEARTBEAT frame indicating that it is ready to receive requests. The module then MUST issue a BAUDRATE request within Tto. Failure to do so will result in the host dropping the connection and returning to its initial state.
|
||||
|
||||
```
|
||||
MODULE | FLIPPER
|
||||
-----------------------------+---------------------------
|
||||
| (Start)
|
||||
Pull down RX -->
|
||||
<-- Heartbeat
|
||||
Baud Rate -->
|
||||
<-- Status [OK | Error]
|
||||
|
|
||||
(Module changes baud rate | (Flipper changes
|
||||
and waits for Tdt) | baud rate)
|
||||
|
|
||||
Control [Start RPC] -->
|
||||
<-- Status [OK | Error]
|
||||
-----------------------------+--------------------------- (1)
|
||||
Data [RPC Request] -->
|
||||
<-- Status [OK | Error]
|
||||
<-- Data [RPC Response]
|
||||
Status [OK | Error] -->
|
||||
-----------------------------+--------------------------- (2)
|
||||
Data [RPC Request pt.1] -->
|
||||
<-- Status [OK | Error]
|
||||
Data [RPC Request pt.2] -->
|
||||
<-- Status [OK | Error]
|
||||
Data [RPC Request pt.3] -->
|
||||
<-- Status [OK | Error]
|
||||
<-- Data [RPC Response]
|
||||
Status [OK | Error] -->
|
||||
-----------------------------+--------------------------- (3)
|
||||
Heartbeat -->
|
||||
<-- Heartbeat
|
||||
Heartbeat -->
|
||||
<-- Heartbeat
|
||||
-----------------------------+---------------------------
|
||||
Control [Stop RPC] -->
|
||||
<-- Status [OK | Error]
|
||||
(Module disconnected) |
|
||||
| (No activity within Tto
|
||||
| return to start)
|
||||
|
||||
(1) The module MUST confirm all implicitly requested frames (e.g. DATA frames containing RPC responses) with a STATUS frame.
|
||||
(2) RPC requests larger than 64 bytes are split into multiple frames. Every DATA frame MUST be confirmed with a STATUS frame.
|
||||
(3) When the module has no data to send, it MUST send HEARTBEAT frames with a period < Tto in order to maintain the connection.
|
||||
The host SHALL respond with a HEARTBEAT frame each time.
|
||||
```
|
||||
|
||||
## Error detection
|
||||
|
||||
Error detection is implemented via adding an extra checksum byte to every frame (see above).
|
||||
|
||||
The checksum is calculated by bitwise XOR-ing every byte in the frame (excluding the checksum byte itself), with an initial value of 0.
|
||||
|
||||
### Error recovery behaviour
|
||||
|
||||
In the event of a detected error, the concerned side MUST cease all communications and reset to initial state. The other side will then experience
|
||||
a communication timeout and the connection will be re-established automatically.
|
|
@ -58,7 +58,7 @@ When not using the API, these peripherals MUST be enabled by the user code and t
|
|||
| SPI2 | -- |
|
||||
| I2C1 | `furi_hal_i2c.h` |
|
||||
| I2C3 | -- |
|
||||
| USART1 | `furi_hal_uart.h` |
|
||||
| USART1 | `furi_hal_serial.h` |
|
||||
| LPUART1 | -- |
|
||||
| USB | `furi_hal_usb.h` |
|
||||
|
||||
|
@ -102,8 +102,8 @@ Below is the list of DMA channels and their usage by the system.
|
|||
| -- | 3 | | |
|
||||
| -- | 4 | yes | pulse reader |
|
||||
| -- | 5 | | |
|
||||
| -- | 6 | | |
|
||||
| -- | 7 | | |
|
||||
| -- | 6 | yes | USART_Rx |
|
||||
| -- | 7 | yes | LPUART_Rx |
|
||||
| DMA2 | 1 | yes | infrared, lfrfid, subghz, |
|
||||
| -- | 2 | yes | -- |
|
||||
| -- | 3 | yes | cc1101_ext |
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include "common_defines.h"
|
||||
|
||||
#include <stm32wbxx.h>
|
||||
#include <furi_hal_console.h>
|
||||
#include <furi_hal_power.h>
|
||||
#include <furi_hal_rtc.h>
|
||||
#include <furi_hal_debug.h>
|
||||
|
@ -59,69 +58,69 @@ extern size_t xPortGetTotalHeapSize(void);
|
|||
static void __furi_put_uint32_as_text(uint32_t data) {
|
||||
char tmp_str[] = "-2147483648";
|
||||
itoa(data, tmp_str, 10);
|
||||
furi_hal_console_puts(tmp_str);
|
||||
furi_log_puts(tmp_str);
|
||||
}
|
||||
|
||||
static void __furi_put_uint32_as_hex(uint32_t data) {
|
||||
char tmp_str[] = "0xFFFFFFFF";
|
||||
itoa(data, tmp_str, 16);
|
||||
furi_hal_console_puts(tmp_str);
|
||||
furi_log_puts(tmp_str);
|
||||
}
|
||||
|
||||
static void __furi_print_register_info() {
|
||||
// Print registers
|
||||
for(uint8_t i = 0; i < 12; i++) {
|
||||
furi_hal_console_puts("\r\n\tr");
|
||||
furi_log_puts("\r\n\tr");
|
||||
__furi_put_uint32_as_text(i);
|
||||
furi_hal_console_puts(" : ");
|
||||
furi_log_puts(" : ");
|
||||
__furi_put_uint32_as_hex(__furi_check_registers[i]);
|
||||
}
|
||||
|
||||
furi_hal_console_puts("\r\n\tlr : ");
|
||||
furi_log_puts("\r\n\tlr : ");
|
||||
__furi_put_uint32_as_hex(__furi_check_registers[12]);
|
||||
}
|
||||
|
||||
static void __furi_print_stack_info() {
|
||||
furi_hal_console_puts("\r\n\tstack watermark: ");
|
||||
furi_log_puts("\r\n\tstack watermark: ");
|
||||
__furi_put_uint32_as_text(uxTaskGetStackHighWaterMark(NULL) * 4);
|
||||
}
|
||||
|
||||
static void __furi_print_bt_stack_info() {
|
||||
const FuriHalBtHardfaultInfo* fault_info = furi_hal_bt_get_hardfault_info();
|
||||
if(fault_info == NULL) {
|
||||
furi_hal_console_puts("\r\n\tcore2: not faulted");
|
||||
furi_log_puts("\r\n\tcore2: not faulted");
|
||||
} else {
|
||||
furi_hal_console_puts("\r\n\tcore2: hardfaulted.\r\n\tPC: ");
|
||||
furi_log_puts("\r\n\tcore2: hardfaulted.\r\n\tPC: ");
|
||||
__furi_put_uint32_as_hex(fault_info->source_pc);
|
||||
furi_hal_console_puts("\r\n\tLR: ");
|
||||
furi_log_puts("\r\n\tLR: ");
|
||||
__furi_put_uint32_as_hex(fault_info->source_lr);
|
||||
furi_hal_console_puts("\r\n\tSP: ");
|
||||
furi_log_puts("\r\n\tSP: ");
|
||||
__furi_put_uint32_as_hex(fault_info->source_sp);
|
||||
}
|
||||
}
|
||||
|
||||
static void __furi_print_heap_info() {
|
||||
furi_hal_console_puts("\r\n\t heap total: ");
|
||||
furi_log_puts("\r\n\t heap total: ");
|
||||
__furi_put_uint32_as_text(xPortGetTotalHeapSize());
|
||||
furi_hal_console_puts("\r\n\t heap free: ");
|
||||
furi_log_puts("\r\n\t heap free: ");
|
||||
__furi_put_uint32_as_text(xPortGetFreeHeapSize());
|
||||
furi_hal_console_puts("\r\n\t heap watermark: ");
|
||||
furi_log_puts("\r\n\t heap watermark: ");
|
||||
__furi_put_uint32_as_text(xPortGetMinimumEverFreeHeapSize());
|
||||
}
|
||||
|
||||
static void __furi_print_name(bool isr) {
|
||||
if(isr) {
|
||||
furi_hal_console_puts("[ISR ");
|
||||
furi_log_puts("[ISR ");
|
||||
__furi_put_uint32_as_text(__get_IPSR());
|
||||
furi_hal_console_puts("] ");
|
||||
furi_log_puts("] ");
|
||||
} else {
|
||||
const char* name = pcTaskGetName(NULL);
|
||||
if(name == NULL) {
|
||||
furi_hal_console_puts("[main] ");
|
||||
furi_log_puts("[main] ");
|
||||
} else {
|
||||
furi_hal_console_puts("[");
|
||||
furi_hal_console_puts(name);
|
||||
furi_hal_console_puts("] ");
|
||||
furi_log_puts("[");
|
||||
furi_log_puts(name);
|
||||
furi_log_puts("] ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,9 +139,9 @@ FURI_NORETURN void __furi_crash_implementation() {
|
|||
__furi_check_message = "furi_check failed";
|
||||
}
|
||||
|
||||
furi_hal_console_puts("\r\n\033[0;31m[CRASH]");
|
||||
furi_log_puts("\r\n\033[0;31m[CRASH]");
|
||||
__furi_print_name(isr);
|
||||
furi_hal_console_puts(__furi_check_message);
|
||||
furi_log_puts(__furi_check_message);
|
||||
|
||||
__furi_print_register_info();
|
||||
if(!isr) {
|
||||
|
@ -157,8 +156,8 @@ FURI_NORETURN void __furi_crash_implementation() {
|
|||
#ifdef FURI_NDEBUG
|
||||
if(debug) {
|
||||
#endif
|
||||
furi_hal_console_puts("\r\nSystem halted. Connect debugger for more info\r\n");
|
||||
furi_hal_console_puts("\033[0m\r\n");
|
||||
furi_log_puts("\r\nSystem halted. Connect debugger for more info\r\n");
|
||||
furi_log_puts("\033[0m\r\n");
|
||||
furi_hal_debug_enable();
|
||||
|
||||
RESTORE_REGISTERS_AND_HALT_MCU(debug);
|
||||
|
@ -169,8 +168,8 @@ FURI_NORETURN void __furi_crash_implementation() {
|
|||
ptr = (uint32_t) "Check serial logs";
|
||||
}
|
||||
furi_hal_rtc_set_fault_data(ptr);
|
||||
furi_hal_console_puts("\r\nRebooting system.\r\n");
|
||||
furi_hal_console_puts("\033[0m\r\n");
|
||||
furi_log_puts("\r\nRebooting system.\r\n");
|
||||
furi_log_puts("\033[0m\r\n");
|
||||
furi_hal_power_reset();
|
||||
}
|
||||
#endif
|
||||
|
@ -187,11 +186,11 @@ FURI_NORETURN void __furi_halt_implementation() {
|
|||
__furi_check_message = "System halt requested.";
|
||||
}
|
||||
|
||||
furi_hal_console_puts("\r\n\033[0;31m[HALT]");
|
||||
furi_log_puts("\r\n\033[0;31m[HALT]");
|
||||
__furi_print_name(isr);
|
||||
furi_hal_console_puts(__furi_check_message);
|
||||
furi_hal_console_puts("\r\nSystem halted. Bye-bye!\r\n");
|
||||
furi_hal_console_puts("\033[0m\r\n");
|
||||
furi_log_puts(__furi_check_message);
|
||||
furi_log_puts("\r\nSystem halted. Bye-bye!\r\n");
|
||||
furi_log_puts("\033[0m\r\n");
|
||||
|
||||
// Check if debug enabled by DAP
|
||||
// https://developer.arm.com/documentation/ddi0403/d/Debug-Architecture/ARMv7-M-Debug/Debug-register-support-in-the-SCS/Debug-Halting-Control-and-Status-Register--DHCSR?lang=en
|
||||
|
|
109
furi/core/log.c
109
furi/core/log.c
|
@ -2,17 +2,19 @@
|
|||
#include "check.h"
|
||||
#include "mutex.h"
|
||||
#include <furi_hal.h>
|
||||
#include <m-list.h>
|
||||
|
||||
LIST_DEF(FuriLogHandlersList, FuriLogHandler, M_POD_OPLIST)
|
||||
|
||||
#define FURI_LOG_LEVEL_DEFAULT FuriLogLevelInfo
|
||||
|
||||
typedef struct {
|
||||
FuriLogLevel log_level;
|
||||
FuriLogPuts puts;
|
||||
FuriLogTimestamp timestamp;
|
||||
FuriMutex* mutex;
|
||||
FuriLogHandlersList_t tx_handlers;
|
||||
} FuriLogParams;
|
||||
|
||||
static FuriLogParams furi_log;
|
||||
static FuriLogParams furi_log = {0};
|
||||
|
||||
typedef struct {
|
||||
const char* str;
|
||||
|
@ -32,9 +34,77 @@ static const FuriLogLevelDescription FURI_LOG_LEVEL_DESCRIPTIONS[] = {
|
|||
void furi_log_init() {
|
||||
// Set default logging parameters
|
||||
furi_log.log_level = FURI_LOG_LEVEL_DEFAULT;
|
||||
furi_log.puts = furi_hal_console_puts;
|
||||
furi_log.timestamp = furi_get_tick;
|
||||
furi_log.mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
furi_log.mutex = furi_mutex_alloc(FuriMutexTypeRecursive);
|
||||
FuriLogHandlersList_init(furi_log.tx_handlers);
|
||||
}
|
||||
|
||||
bool furi_log_add_handler(FuriLogHandler handler) {
|
||||
furi_check(handler.callback);
|
||||
|
||||
bool ret = true;
|
||||
|
||||
furi_check(furi_mutex_acquire(furi_log.mutex, FuriWaitForever) == FuriStatusOk);
|
||||
|
||||
FuriLogHandlersList_it_t it;
|
||||
FuriLogHandlersList_it(it, furi_log.tx_handlers);
|
||||
while(!FuriLogHandlersList_end_p(it)) {
|
||||
if(memcmp(FuriLogHandlersList_ref(it), &handler, sizeof(FuriLogHandler)) == 0) {
|
||||
ret = false;
|
||||
} else {
|
||||
FuriLogHandlersList_next(it);
|
||||
}
|
||||
}
|
||||
|
||||
if(ret) {
|
||||
FuriLogHandlersList_push_back(furi_log.tx_handlers, handler);
|
||||
}
|
||||
|
||||
furi_mutex_release(furi_log.mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool furi_log_remove_handler(FuriLogHandler handler) {
|
||||
bool ret = false;
|
||||
|
||||
furi_check(furi_mutex_acquire(furi_log.mutex, FuriWaitForever) == FuriStatusOk);
|
||||
|
||||
FuriLogHandlersList_it_t it;
|
||||
FuriLogHandlersList_it(it, furi_log.tx_handlers);
|
||||
while(!FuriLogHandlersList_end_p(it)) {
|
||||
if(memcmp(FuriLogHandlersList_ref(it), &handler, sizeof(FuriLogHandler)) == 0) {
|
||||
FuriLogHandlersList_remove(furi_log.tx_handlers, it);
|
||||
ret = true;
|
||||
} else {
|
||||
FuriLogHandlersList_next(it);
|
||||
}
|
||||
}
|
||||
|
||||
furi_mutex_release(furi_log.mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void furi_log_tx(const uint8_t* data, size_t size) {
|
||||
if(!FURI_IS_ISR()) {
|
||||
furi_check(furi_mutex_acquire(furi_log.mutex, FuriWaitForever) == FuriStatusOk);
|
||||
} else {
|
||||
if(furi_mutex_get_owner(furi_log.mutex)) return;
|
||||
}
|
||||
|
||||
FuriLogHandlersList_it_t it;
|
||||
FuriLogHandlersList_it(it, furi_log.tx_handlers);
|
||||
while(!FuriLogHandlersList_end_p(it)) {
|
||||
FuriLogHandlersList_ref(it)->callback(data, size, FuriLogHandlersList_ref(it)->context);
|
||||
FuriLogHandlersList_next(it);
|
||||
}
|
||||
|
||||
if(!FURI_IS_ISR()) furi_mutex_release(furi_log.mutex);
|
||||
}
|
||||
|
||||
void furi_log_puts(const char* data) {
|
||||
furi_check(data);
|
||||
furi_log_tx((const uint8_t*)data, strlen(data));
|
||||
}
|
||||
|
||||
void furi_log_print_format(FuriLogLevel level, const char* tag, const char* format, ...) {
|
||||
|
@ -72,13 +142,8 @@ void furi_log_print_format(FuriLogLevel level, const char* tag, const char* form
|
|||
|
||||
// Timestamp
|
||||
furi_string_printf(
|
||||
string,
|
||||
"%lu %s[%s][%s] " _FURI_LOG_CLR_RESET,
|
||||
furi_log.timestamp(),
|
||||
color,
|
||||
log_letter,
|
||||
tag);
|
||||
furi_log.puts(furi_string_get_cstr(string));
|
||||
string, "%lu %s[%s][%s] " _FURI_LOG_CLR_RESET, furi_get_tick(), color, log_letter, tag);
|
||||
furi_log_puts(furi_string_get_cstr(string));
|
||||
furi_string_reset(string);
|
||||
|
||||
va_list args;
|
||||
|
@ -86,10 +151,10 @@ void furi_log_print_format(FuriLogLevel level, const char* tag, const char* form
|
|||
furi_string_vprintf(string, format, args);
|
||||
va_end(args);
|
||||
|
||||
furi_log.puts(furi_string_get_cstr(string));
|
||||
furi_log_puts(furi_string_get_cstr(string));
|
||||
furi_string_free(string);
|
||||
|
||||
furi_log.puts("\r\n");
|
||||
furi_log_puts("\r\n");
|
||||
|
||||
furi_mutex_release(furi_log.mutex);
|
||||
}
|
||||
|
@ -105,7 +170,7 @@ void furi_log_print_raw_format(FuriLogLevel level, const char* format, ...) {
|
|||
furi_string_vprintf(string, format, args);
|
||||
va_end(args);
|
||||
|
||||
furi_log.puts(furi_string_get_cstr(string));
|
||||
furi_log_puts(furi_string_get_cstr(string));
|
||||
furi_string_free(string);
|
||||
|
||||
furi_mutex_release(furi_log.mutex);
|
||||
|
@ -123,16 +188,6 @@ FuriLogLevel furi_log_get_level(void) {
|
|||
return furi_log.log_level;
|
||||
}
|
||||
|
||||
void furi_log_set_puts(FuriLogPuts puts) {
|
||||
furi_assert(puts);
|
||||
furi_log.puts = puts;
|
||||
}
|
||||
|
||||
void furi_log_set_timestamp(FuriLogTimestamp timestamp) {
|
||||
furi_assert(timestamp);
|
||||
furi_log.timestamp = timestamp;
|
||||
}
|
||||
|
||||
bool furi_log_level_to_string(FuriLogLevel level, const char** str) {
|
||||
for(size_t i = 0; i < COUNT_OF(FURI_LOG_LEVEL_DESCRIPTIONS); i++) {
|
||||
if(level == FURI_LOG_LEVEL_DESCRIPTIONS[i].level) {
|
||||
|
@ -151,4 +206,4 @@ bool furi_log_level_from_string(const char* str, FuriLogLevel* level) {
|
|||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,11 +39,44 @@ typedef enum {
|
|||
#define _FURI_LOG_CLR_D _FURI_LOG_CLR(_FURI_LOG_CLR_BLUE)
|
||||
#define _FURI_LOG_CLR_T _FURI_LOG_CLR(_FURI_LOG_CLR_PURPLE)
|
||||
|
||||
typedef void (*FuriLogPuts)(const char* data);
|
||||
typedef uint32_t (*FuriLogTimestamp)(void);
|
||||
typedef void (*FuriLogHandlerCallback)(const uint8_t* data, size_t size, void* context);
|
||||
|
||||
typedef struct {
|
||||
FuriLogHandlerCallback callback;
|
||||
void* context;
|
||||
} FuriLogHandler;
|
||||
|
||||
/** Initialize logging */
|
||||
void furi_log_init();
|
||||
void furi_log_init(void);
|
||||
|
||||
/** Add log TX callback
|
||||
*
|
||||
* @param[in] callback The callback
|
||||
*
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
bool furi_log_add_handler(FuriLogHandler handler);
|
||||
|
||||
/** Remove log TX callback
|
||||
*
|
||||
* @param[in] callback The callback
|
||||
*
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
bool furi_log_remove_handler(FuriLogHandler handler);
|
||||
|
||||
/** Transmit data through log IO callbacks
|
||||
*
|
||||
* @param[in] data The data
|
||||
* @param[in] size The size
|
||||
*/
|
||||
void furi_log_tx(const uint8_t* data, size_t size);
|
||||
|
||||
/** Transmit data through log IO callbacks
|
||||
*
|
||||
* @param[in] data The data, null-terminated C-string
|
||||
*/
|
||||
void furi_log_puts(const char* data);
|
||||
|
||||
/** Print log record
|
||||
*
|
||||
|
@ -74,19 +107,7 @@ void furi_log_set_level(FuriLogLevel level);
|
|||
*
|
||||
* @return The furi log level.
|
||||
*/
|
||||
FuriLogLevel furi_log_get_level();
|
||||
|
||||
/** Set log output callback
|
||||
*
|
||||
* @param[in] puts The puts callback
|
||||
*/
|
||||
void furi_log_set_puts(FuriLogPuts puts);
|
||||
|
||||
/** Set timestamp callback
|
||||
*
|
||||
* @param[in] timestamp The timestamp callback
|
||||
*/
|
||||
void furi_log_set_timestamp(FuriLogTimestamp timestamp);
|
||||
FuriLogLevel furi_log_get_level(void);
|
||||
|
||||
/** Log level to string
|
||||
*
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stm32wbxx.h>
|
||||
#include <furi_hal_console.h>
|
||||
#include <core/log.h>
|
||||
#include <core/common_defines.h>
|
||||
|
||||
/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
|
||||
|
@ -52,6 +52,10 @@ task.h is included from an application file. */
|
|||
|
||||
#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
|
||||
|
||||
#ifdef HEAP_PRINT_DEBUG
|
||||
#error This feature is broken, logging transport must be replaced with RTT
|
||||
#endif
|
||||
|
||||
#if(configSUPPORT_DYNAMIC_ALLOCATION == 0)
|
||||
#error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0
|
||||
#endif
|
||||
|
@ -286,13 +290,13 @@ static void print_heap_init() {
|
|||
|
||||
// {PHStart|heap_start|heap_end}
|
||||
FURI_CRITICAL_ENTER();
|
||||
furi_hal_console_puts("{PHStart|");
|
||||
furi_log_puts("{PHStart|");
|
||||
ultoa(heap_start, tmp_str, 16);
|
||||
furi_hal_console_puts(tmp_str);
|
||||
furi_hal_console_puts("|");
|
||||
furi_log_puts(tmp_str);
|
||||
furi_log_puts("|");
|
||||
ultoa(heap_end, tmp_str, 16);
|
||||
furi_hal_console_puts(tmp_str);
|
||||
furi_hal_console_puts("}\r\n");
|
||||
furi_log_puts(tmp_str);
|
||||
furi_log_puts("}\r\n");
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
|
||||
|
@ -305,15 +309,15 @@ static void print_heap_malloc(void* ptr, size_t size) {
|
|||
|
||||
// {thread name|m|address|size}
|
||||
FURI_CRITICAL_ENTER();
|
||||
furi_hal_console_puts("{");
|
||||
furi_hal_console_puts(name);
|
||||
furi_hal_console_puts("|m|0x");
|
||||
furi_log_puts("{");
|
||||
furi_log_puts(name);
|
||||
furi_log_puts("|m|0x");
|
||||
ultoa((unsigned long)ptr, tmp_str, 16);
|
||||
furi_hal_console_puts(tmp_str);
|
||||
furi_hal_console_puts("|");
|
||||
furi_log_puts(tmp_str);
|
||||
furi_log_puts("|");
|
||||
utoa(size, tmp_str, 10);
|
||||
furi_hal_console_puts(tmp_str);
|
||||
furi_hal_console_puts("}\r\n");
|
||||
furi_log_puts(tmp_str);
|
||||
furi_log_puts("}\r\n");
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
|
||||
|
@ -326,12 +330,12 @@ static void print_heap_free(void* ptr) {
|
|||
|
||||
// {thread name|f|address}
|
||||
FURI_CRITICAL_ENTER();
|
||||
furi_hal_console_puts("{");
|
||||
furi_hal_console_puts(name);
|
||||
furi_hal_console_puts("|f|0x");
|
||||
furi_log_puts("{");
|
||||
furi_log_puts(name);
|
||||
furi_log_puts("|f|0x");
|
||||
ultoa((unsigned long)ptr, tmp_str, 16);
|
||||
furi_hal_console_puts(tmp_str);
|
||||
furi_hal_console_puts("}\r\n");
|
||||
furi_log_puts(tmp_str);
|
||||
furi_log_puts("}\r\n");
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -114,8 +114,10 @@ FuriThreadId furi_mutex_get_owner(FuriMutex* instance) {
|
|||
|
||||
hMutex = (SemaphoreHandle_t)((uint32_t)instance & ~1U);
|
||||
|
||||
if((FURI_IS_IRQ_MODE()) || (hMutex == NULL)) {
|
||||
if((hMutex == NULL)) {
|
||||
owner = 0;
|
||||
} else if(FURI_IS_IRQ_MODE()) {
|
||||
owner = (FuriThreadId)xSemaphoreGetMutexHolderFromISR(hMutex);
|
||||
} else {
|
||||
owner = (FuriThreadId)xSemaphoreGetMutexHolder(hMutex);
|
||||
}
|
||||
|
|
|
@ -149,4 +149,4 @@ FuriStatus furi_stream_buffer_reset(FuriStreamBuffer* stream_buffer);
|
|||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
#include "log.h"
|
||||
#include <furi_hal_rtc.h>
|
||||
#include <furi_hal_console.h>
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
|
@ -570,7 +569,7 @@ static size_t __furi_thread_stdout_write(FuriThread* thread, const char* data, s
|
|||
if(thread->output.write_callback != NULL) {
|
||||
thread->output.write_callback(data, size);
|
||||
} else {
|
||||
furi_hal_console_tx((const uint8_t*)data, size);
|
||||
furi_log_tx((const uint8_t*)data, size);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
|
|
@ -78,6 +78,20 @@ CC1101Status cc1101_get_status(FuriHalSpiBusHandle* handle) {
|
|||
return cc1101_strobe(handle, CC1101_STROBE_SNOP);
|
||||
}
|
||||
|
||||
bool cc1101_wait_status_state(FuriHalSpiBusHandle* handle, CC1101State state, uint32_t timeout_us) {
|
||||
bool result = false;
|
||||
CC1101Status status = {0};
|
||||
FuriHalCortexTimer timer = furi_hal_cortex_timer_get(timeout_us);
|
||||
while(!furi_hal_cortex_timer_is_expired(timer)) {
|
||||
status = cc1101_strobe(handle, CC1101_STROBE_SNOP);
|
||||
if(status.STATE == state) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
CC1101Status cc1101_shutdown(FuriHalSpiBusHandle* handle) {
|
||||
return cc1101_strobe(handle, CC1101_STROBE_SPWD);
|
||||
}
|
||||
|
|
|
@ -59,6 +59,16 @@ CC1101Status cc1101_reset(FuriHalSpiBusHandle* handle);
|
|||
*/
|
||||
CC1101Status cc1101_get_status(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Wait specific chip state
|
||||
*
|
||||
* @param handle The SPI bus handle
|
||||
* @param[in] state The state to wait
|
||||
* @param[in] timeout_us The timeout in microseconds
|
||||
*
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
bool cc1101_wait_status_state(FuriHalSpiBusHandle* handle, CC1101State state, uint32_t timeout_us);
|
||||
|
||||
/** Enable shutdown mode
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
|
|
|
@ -8,13 +8,13 @@ typedef enum {
|
|||
LFRFIDEventStopMode = (1 << 1),
|
||||
LFRFIDEventRead = (1 << 2),
|
||||
LFRFIDEventWrite = (1 << 3),
|
||||
LFRFIDEventWriteWithPass = (1 << 4),
|
||||
LFRFIDEventWriteAndSetPass = (1 << 4),
|
||||
LFRFIDEventEmulate = (1 << 5),
|
||||
LFRFIDEventReadRaw = (1 << 6),
|
||||
LFRFIDEventEmulateRaw = (1 << 7),
|
||||
LFRFIDEventAll =
|
||||
(LFRFIDEventStopThread | LFRFIDEventStopMode | LFRFIDEventRead | LFRFIDEventWrite |
|
||||
LFRFIDEventWriteWithPass | LFRFIDEventEmulate | LFRFIDEventReadRaw |
|
||||
LFRFIDEventWriteAndSetPass | LFRFIDEventEmulate | LFRFIDEventReadRaw |
|
||||
LFRFIDEventEmulateRaw),
|
||||
} LFRFIDEventType;
|
||||
|
||||
|
@ -71,7 +71,7 @@ void lfrfid_worker_write_start(
|
|||
furi_thread_flags_set(furi_thread_get_id(worker->thread), LFRFIDEventWrite);
|
||||
}
|
||||
|
||||
void lfrfid_worker_write_with_pass_start(
|
||||
void lfrfid_worker_write_and_set_pass_start(
|
||||
LFRFIDWorker* worker,
|
||||
LFRFIDProtocol protocol,
|
||||
LFRFIDWorkerWriteCallback callback,
|
||||
|
@ -80,7 +80,7 @@ void lfrfid_worker_write_with_pass_start(
|
|||
worker->protocol = protocol;
|
||||
worker->write_cb = callback;
|
||||
worker->cb_ctx = context;
|
||||
furi_thread_flags_set(furi_thread_get_id(worker->thread), LFRFIDEventWriteWithPass);
|
||||
furi_thread_flags_set(furi_thread_get_id(worker->thread), LFRFIDEventWriteAndSetPass);
|
||||
}
|
||||
|
||||
void lfrfid_worker_emulate_start(LFRFIDWorker* worker, LFRFIDProtocol protocol) {
|
||||
|
@ -159,7 +159,8 @@ static int32_t lfrfid_worker_thread(void* thread_context) {
|
|||
// switch mode
|
||||
if(flags & LFRFIDEventRead) worker->mode_index = LFRFIDWorkerRead;
|
||||
if(flags & LFRFIDEventWrite) worker->mode_index = LFRFIDWorkerWrite;
|
||||
if(flags & LFRFIDEventWriteWithPass) worker->mode_index = LFRFIDWorkerWriteWithPass;
|
||||
if(flags & LFRFIDEventWriteAndSetPass)
|
||||
worker->mode_index = LFRFIDWorkerWriteAndSetPass;
|
||||
if(flags & LFRFIDEventEmulate) worker->mode_index = LFRFIDWorkerEmulate;
|
||||
if(flags & LFRFIDEventReadRaw) worker->mode_index = LFRFIDWorkerReadRaw;
|
||||
if(flags & LFRFIDEventEmulateRaw) worker->mode_index = LFRFIDWorkerEmulateRaw;
|
||||
|
|
|
@ -107,14 +107,14 @@ void lfrfid_worker_write_start(
|
|||
void* context);
|
||||
|
||||
/**
|
||||
* @brief Start write with pass mode
|
||||
* @brief Start write and set pass mode
|
||||
*
|
||||
* @param worker
|
||||
* @param protocol
|
||||
* @param callback
|
||||
* @param context
|
||||
*/
|
||||
void lfrfid_worker_write_with_pass_start(
|
||||
void lfrfid_worker_write_and_set_pass_start(
|
||||
LFRFIDWorker* worker,
|
||||
LFRFIDProtocol protocol,
|
||||
LFRFIDWorkerWriteCallback callback,
|
||||
|
|
|
@ -22,7 +22,7 @@ typedef enum {
|
|||
LFRFIDWorkerIdle,
|
||||
LFRFIDWorkerRead,
|
||||
LFRFIDWorkerWrite,
|
||||
LFRFIDWorkerWriteWithPass,
|
||||
LFRFIDWorkerWriteAndSetPass,
|
||||
LFRFIDWorkerEmulate,
|
||||
LFRFIDWorkerReadRaw,
|
||||
LFRFIDWorkerEmulateRaw,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "lfrfid/lfrfid_i.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include "lfrfid_worker_i.h"
|
||||
|
@ -48,6 +49,15 @@ void lfrfid_worker_delay(LFRFIDWorker* worker, uint32_t milliseconds) {
|
|||
}
|
||||
}
|
||||
|
||||
void t5577_trace(LFRFIDT5577 t5577, const char* message) {
|
||||
if(furi_log_get_level() == FuriLogLevelTrace) {
|
||||
FURI_LOG_T(TAG, "%s", message);
|
||||
for(uint8_t i = 0; i < 8; i++) FURI_LOG_T(TAG, "\nBlock %u %08lX", i, t5577.block[i]);
|
||||
FURI_LOG_T(TAG, "Mask: %u", t5577.mask);
|
||||
FURI_LOG_T(TAG, "Blocks to write: %lu", t5577.blocks_to_write);
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************************************/
|
||||
/********************************************** READ **********************************************/
|
||||
/**************************************************************************************************/
|
||||
|
@ -574,7 +584,7 @@ static void lfrfid_worker_mode_write_process(LFRFIDWorker* worker) {
|
|||
free(read_data);
|
||||
}
|
||||
|
||||
static void lfrfid_worker_mode_write_with_pass_process(LFRFIDWorker* worker) {
|
||||
static void lfrfid_worker_mode_write_and_set_pass_process(LFRFIDWorker* worker) {
|
||||
LFRFIDProtocol protocol = worker->protocol;
|
||||
LFRFIDWriteRequest* request = malloc(sizeof(LFRFIDWriteRequest));
|
||||
request->write_type = LFRFIDWriteTypeT5577;
|
||||
|
@ -592,18 +602,22 @@ static void lfrfid_worker_mode_write_with_pass_process(LFRFIDWorker* worker) {
|
|||
|
||||
if(can_be_written) {
|
||||
while(!lfrfid_worker_check_for_stop(worker)) {
|
||||
FURI_LOG_D(TAG, "Data write");
|
||||
FURI_LOG_D(TAG, "Data write with pass");
|
||||
|
||||
uint8_t size;
|
||||
const uint32_t* password_list = t5577_get_default_passwords(&size);
|
||||
LfRfid* app = worker->cb_ctx;
|
||||
uint32_t pass = (app->password[0] << 24) | (app->password[1] << 16) |
|
||||
(app->password[2] << 8) | (app->password[3]);
|
||||
|
||||
uint32_t pass = password_list[rand() % size];
|
||||
request->t5577.mask = 0b10000001;
|
||||
for(uint8_t i = 0; i < request->t5577.blocks_to_write; i++)
|
||||
request->t5577.mask |= (1 << i);
|
||||
|
||||
request->t5577.mask = 0b1111111;
|
||||
request->t5577.block[0] |= 0b10000;
|
||||
request->t5577.block[0] |= (1 << 4);
|
||||
request->t5577.block[7] = pass;
|
||||
|
||||
t5577_write_with_mask(&request->t5577, 0, 0);
|
||||
t5577_trace(request->t5577, "Write with password");
|
||||
|
||||
t5577_write_with_mask(&request->t5577, 0, true, 0);
|
||||
|
||||
ProtocolId read_result = PROTOCOL_NO;
|
||||
LFRFIDWorkerReadState state = lfrfid_worker_read_internal(
|
||||
|
@ -719,7 +733,7 @@ const LFRFIDWorkerModeType lfrfid_worker_modes[] = {
|
|||
[LFRFIDWorkerIdle] = {.process = NULL},
|
||||
[LFRFIDWorkerRead] = {.process = lfrfid_worker_mode_read_process},
|
||||
[LFRFIDWorkerWrite] = {.process = lfrfid_worker_mode_write_process},
|
||||
[LFRFIDWorkerWriteWithPass] = {.process = lfrfid_worker_mode_write_with_pass_process},
|
||||
[LFRFIDWorkerWriteAndSetPass] = {.process = lfrfid_worker_mode_write_and_set_pass_process},
|
||||
[LFRFIDWorkerEmulate] = {.process = lfrfid_worker_mode_emulate_process},
|
||||
[LFRFIDWorkerReadRaw] = {.process = lfrfid_worker_mode_read_raw_process},
|
||||
[LFRFIDWorkerEmulateRaw] = {.process = lfrfid_worker_mode_emulate_raw_process},
|
||||
|
|
|
@ -101,7 +101,7 @@ static bool protocol_fdx_b_can_be_decoded(ProtocolFDXB* protocol) {
|
|||
|
||||
void protocol_fdx_b_decode(ProtocolFDXB* protocol) {
|
||||
// remove parity
|
||||
bit_lib_remove_bit_every_nth(protocol->encoded_data, 3, 13 * 9, 9);
|
||||
bit_lib_remove_bit_every_nth(protocol->encoded_data, 3, 14 * 9, 9);
|
||||
|
||||
// remove header pattern
|
||||
for(size_t i = 0; i < 11; i++)
|
||||
|
@ -119,7 +119,7 @@ void protocol_fdx_b_decode(ProtocolFDXB* protocol) {
|
|||
// 72 xxxxxxxx
|
||||
// 80 eeeeeeee 24 bits of extra data if present.
|
||||
// 88 eeeeeeee eg. $123456.
|
||||
// 92 eeeeeeee
|
||||
// 96 eeeeeeee
|
||||
|
||||
// copy data without checksum
|
||||
bit_lib_copy_bits(protocol->data, 0, 64, protocol->encoded_data, 0);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "t5577.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal_rfid.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define T5577_TIMING_WAIT_TIME 400
|
||||
#define T5577_TIMING_START_GAP 30
|
||||
|
@ -16,30 +17,6 @@
|
|||
#define T5577_BLOCKS_IN_PAGE_0 8
|
||||
#define T5577_BLOCKS_IN_PAGE_1 4
|
||||
|
||||
//TODO: use .txt file in resources for passwords.
|
||||
const uint32_t default_passwords[] = {
|
||||
0x51243648, 0x000D8787, 0x19920427, 0x50524F58, 0xF9DCEBA0, 0x65857569, 0x05D73B9F, 0x89A69E60,
|
||||
0x314159E0, 0xAA55BBBB, 0xA5B4C3D2, 0x1C0B5848, 0x00434343, 0x444E4752, 0x4E457854, 0x44B44CAE,
|
||||
0x88661858, 0xE9920427, 0x575F4F4B, 0x50520901, 0x20206666, 0x65857569, 0x5469616E, 0x7686962A,
|
||||
0xC0F5009A, 0x07CEE75D, 0xfeedbeef, 0xdeadc0de, 0x00000000, 0x11111111, 0x22222222, 0x33333333,
|
||||
0x44444444, 0x55555555, 0x66666666, 0x77777777, 0x88888888, 0x99999999, 0xAAAAAAAA, 0xBBBBBBBB,
|
||||
0xCCCCCCCC, 0xDDDDDDDD, 0xEEEEEEEE, 0xFFFFFFFF, 0xa0a1a2a3, 0xb0b1b2b3, 0x50415353, 0x00000001,
|
||||
0x00000002, 0x0000000a, 0x0000000b, 0x01020304, 0x02030405, 0x03040506, 0x04050607, 0x05060708,
|
||||
0x06070809, 0x0708090A, 0x08090A0B, 0x090A0B0C, 0x0A0B0C0D, 0x0B0C0D0E, 0x0C0D0E0F, 0x01234567,
|
||||
0x12345678, 0x10000000, 0x20000000, 0x30000000, 0x40000000, 0x50000000, 0x60000000, 0x70000000,
|
||||
0x80000000, 0x90000000, 0xA0000000, 0xB0000000, 0xC0000000, 0xD0000000, 0xE0000000, 0xF0000000,
|
||||
0x10101010, 0x01010101, 0x11223344, 0x22334455, 0x33445566, 0x44556677, 0x55667788, 0x66778899,
|
||||
0x778899AA, 0x8899AABB, 0x99AABBCC, 0xAABBCCDD, 0xBBCCDDEE, 0xCCDDEEFF, 0x0CB7E7FC, 0xFABADA11,
|
||||
0x87654321, 0x12341234, 0x69696969, 0x12121212, 0x12344321, 0x1234ABCD, 0x11112222, 0x13131313,
|
||||
0x10041004, 0x31415926, 0xabcd1234, 0x20002000, 0x19721972, 0xaa55aa55, 0x55aa55aa, 0x4f271149,
|
||||
0x07d7bb0b, 0x9636ef8f, 0xb5f44686, 0x9E3779B9, 0xC6EF3720, 0x7854794A, 0xF1EA5EED, 0x69314718,
|
||||
0x57721566, 0x93C467E3, 0x27182818, 0x50415353};
|
||||
|
||||
const uint32_t* t5577_get_default_passwords(uint8_t* len) {
|
||||
*len = sizeof(default_passwords) / sizeof(uint32_t);
|
||||
return default_passwords;
|
||||
}
|
||||
|
||||
static void t5577_start() {
|
||||
furi_hal_rfid_tim_read_start(125000, 0.5);
|
||||
|
||||
|
@ -145,7 +122,7 @@ void t5577_write_with_pass(LFRFIDT5577* data, uint32_t password) {
|
|||
t5577_stop();
|
||||
}
|
||||
|
||||
void t5577_write_with_mask(LFRFIDT5577* data, uint8_t page, uint32_t password) {
|
||||
void t5577_write_with_mask(LFRFIDT5577* data, uint8_t page, bool with_pass, uint32_t password) {
|
||||
t5577_start();
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
|
@ -157,7 +134,7 @@ void t5577_write_with_mask(LFRFIDT5577* data, uint8_t page, uint32_t password) {
|
|||
bool need_to_write = mask & 1;
|
||||
mask >>= 1;
|
||||
if(!need_to_write) continue;
|
||||
t5577_write_block_pass(page, i, false, data->block[i], true, password);
|
||||
t5577_write_block_pass(page, i, false, data->block[i], with_pass, password);
|
||||
}
|
||||
t5577_write_reset();
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
|
|
@ -45,8 +45,6 @@ typedef struct {
|
|||
uint8_t mask;
|
||||
} LFRFIDT5577;
|
||||
|
||||
const uint32_t* t5577_get_default_passwords(uint8_t* len);
|
||||
|
||||
/**
|
||||
* @brief Write T5577 tag data to tag
|
||||
*
|
||||
|
@ -56,7 +54,7 @@ void t5577_write(LFRFIDT5577* data);
|
|||
|
||||
void t5577_write_with_pass(LFRFIDT5577* data, uint32_t password);
|
||||
|
||||
void t5577_write_with_mask(LFRFIDT5577* data, uint8_t page, uint32_t password);
|
||||
void t5577_write_with_mask(LFRFIDT5577* data, uint8_t page, bool with_pass, uint32_t password);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -252,7 +252,12 @@ const uint8_t* iso14443_4a_get_historical_bytes(const Iso14443_4aData* data, uin
|
|||
furi_assert(count);
|
||||
|
||||
*count = simple_array_get_count(data->ats_data.t1_tk);
|
||||
return simple_array_cget_data(data->ats_data.t1_tk);
|
||||
const uint8_t* hist_bytes = NULL;
|
||||
if(*count > 0) {
|
||||
hist_bytes = simple_array_cget_data(data->ats_data.t1_tk);
|
||||
}
|
||||
|
||||
return hist_bytes;
|
||||
}
|
||||
|
||||
bool iso14443_4a_supports_bit_rate(const Iso14443_4aData* data, Iso14443_4aBitRate bit_rate) {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue