From d6f080f7d0a1bc9793bedcd73402ad6bffff57ee Mon Sep 17 00:00:00 2001 From: SG Date: Fri, 10 Dec 2021 02:53:29 +1000 Subject: [PATCH 1/3] [FL-2125] Cli: input_dump (#887) * Cli: input_dump * Tied together input_dump and input service * input_dump and input service are now very tightly tied * Input: remove record open in input_dump. Co-authored-by: Aleksandr Kutuzov --- applications/input/input.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/applications/input/input.c b/applications/input/input.c index 1d160e55..fb393f97 100644 --- a/applications/input/input.c +++ b/applications/input/input.c @@ -92,6 +92,37 @@ void input_cli_send(Cli* cli, string_t args, void* context) { furi_pubsub_publish(input->event_pubsub, &event); } +static void input_cli_dump_events_callback(const void* value, void* ctx) { + furi_assert(value); + furi_assert(ctx); + osMessageQueueId_t input_queue = ctx; + osMessageQueuePut(input_queue, value, 0, osWaitForever); +} + +static void input_cli_dump(Cli* cli, string_t args, void* context) { + osMessageQueueId_t input_queue = osMessageQueueNew(8, sizeof(InputEvent), NULL); + FuriPubSubSubscription* input_subscription = + furi_pubsub_subscribe(input->event_pubsub, input_cli_dump_events_callback, input_queue); + + bool stop = false; + InputEvent input_event; + while(!stop) { + if(osMessageQueueGet(input_queue, &input_event, NULL, 100) == osOK) { + printf( + "key: %s type: %s\r\n", + input_get_key_name(input_event.key), + input_get_type_name(input_event.type)); + } + + if(cli_cmd_interrupt_received(cli)) { + stop = true; + } + } + + furi_pubsub_unsubscribe(input->event_pubsub, input_subscription); + osMessageQueueDelete(input_queue); +} + const char* input_get_key_name(InputKey key) { for(size_t i = 0; i < input_pins_count; i++) { if(input_pins[i].key == key) { @@ -126,7 +157,9 @@ int32_t input_srv() { input->cli = furi_record_open("cli"); if(input->cli) { cli_add_command( - input->cli, "input_send", CliCommandFlagParallelSafe, input_cli_send, input); + input->cli, "input_send", CliCommandFlagParallelSafe, input_cli_send, NULL); + cli_add_command( + input->cli, "input_dump", CliCommandFlagParallelSafe, input_cli_dump, NULL); } input->pin_states = furi_alloc(input_pins_count * sizeof(InputPinState)); From 195f422bb9c2a1154b511536448d3104202e0e51 Mon Sep 17 00:00:00 2001 From: Anna Prosvetova Date: Fri, 10 Dec 2021 14:51:36 +0300 Subject: [PATCH 2/3] Rpc: implement SystemFactoryReset (#890) * Rpc: update protobuf sources * Rpc: implement SystemFactoryReset --- applications/rpc/rpc_system.c | 13 +++++++++++++ assets/compiled/flipper.pb.h | 6 +++++- assets/compiled/system.pb.c | 3 +++ assets/compiled/system.pb.h | 14 ++++++++++++++ assets/protobuf | 2 +- 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/applications/rpc/rpc_system.c b/applications/rpc/rpc_system.c index 92a770ad..2ce23129 100644 --- a/applications/rpc/rpc_system.c +++ b/applications/rpc/rpc_system.c @@ -3,6 +3,7 @@ #include "status.pb.h" #include +#include #include void rpc_system_system_ping_process(const PB_Main* msg_request, void* context) { @@ -98,6 +99,15 @@ void rpc_system_system_device_info_process(const PB_Main* request, void* context free(response); } +void rpc_system_system_factory_reset_process(const PB_Main* request, void* context) { + furi_assert(request); + furi_assert(request->which_content == PB_Main_system_factory_reset_request_tag); + furi_assert(context); + + furi_hal_bootloader_set_flags(FuriHalBootloaderFlagFactoryReset); + power_reboot(PowerBootModeNormal); +} + void* rpc_system_system_alloc(Rpc* rpc) { RpcHandler rpc_handler = { .message_handler = NULL, @@ -114,5 +124,8 @@ void* rpc_system_system_alloc(Rpc* rpc) { rpc_handler.message_handler = rpc_system_system_device_info_process; rpc_add_handler(rpc, PB_Main_system_device_info_request_tag, &rpc_handler); + rpc_handler.message_handler = rpc_system_system_factory_reset_process; + rpc_add_handler(rpc, PB_Main_system_factory_reset_request_tag, &rpc_handler); + return NULL; } diff --git a/assets/compiled/flipper.pb.h b/assets/compiled/flipper.pb.h index 7599e3c5..5ce575fd 100644 --- a/assets/compiled/flipper.pb.h +++ b/assets/compiled/flipper.pb.h @@ -91,6 +91,7 @@ typedef struct _PB_Main { PB_System_RebootRequest system_reboot_request; PB_System_DeviceInfoRequest system_device_info_request; PB_System_DeviceInfoResponse system_device_info_response; + PB_System_FactoryResetRequest system_factory_reset_request; } content; } PB_Main; @@ -147,6 +148,7 @@ extern "C" { #define PB_Main_system_reboot_request_tag 31 #define PB_Main_system_device_info_request_tag 32 #define PB_Main_system_device_info_response_tag 33 +#define PB_Main_system_factory_reset_request_tag 34 /* Struct field encoding specification for nanopb */ #define PB_Empty_FIELDLIST(X, a) \ @@ -192,7 +194,8 @@ X(a, STATIC, ONEOF, MSG_W_CB, (content,storage_info_response,content.storag X(a, STATIC, ONEOF, MSG_W_CB, (content,storage_rename_request,content.storage_rename_request), 30) \ X(a, STATIC, ONEOF, MSG_W_CB, (content,system_reboot_request,content.system_reboot_request), 31) \ X(a, STATIC, ONEOF, MSG_W_CB, (content,system_device_info_request,content.system_device_info_request), 32) \ -X(a, STATIC, ONEOF, MSG_W_CB, (content,system_device_info_response,content.system_device_info_response), 33) +X(a, STATIC, ONEOF, MSG_W_CB, (content,system_device_info_response,content.system_device_info_response), 33) \ +X(a, STATIC, ONEOF, MSG_W_CB, (content,system_factory_reset_request,content.system_factory_reset_request), 34) #define PB_Main_CALLBACK NULL #define PB_Main_DEFAULT NULL #define PB_Main_content_empty_MSGTYPE PB_Empty @@ -225,6 +228,7 @@ X(a, STATIC, ONEOF, MSG_W_CB, (content,system_device_info_response,content. #define PB_Main_content_system_reboot_request_MSGTYPE PB_System_RebootRequest #define PB_Main_content_system_device_info_request_MSGTYPE PB_System_DeviceInfoRequest #define PB_Main_content_system_device_info_response_MSGTYPE PB_System_DeviceInfoResponse +#define PB_Main_content_system_factory_reset_request_MSGTYPE PB_System_FactoryResetRequest extern const pb_msgdesc_t PB_Empty_msg; extern const pb_msgdesc_t PB_StopSession_msg; diff --git a/assets/compiled/system.pb.c b/assets/compiled/system.pb.c index 128e1c08..dd1bc623 100644 --- a/assets/compiled/system.pb.c +++ b/assets/compiled/system.pb.c @@ -21,5 +21,8 @@ PB_BIND(PB_System_DeviceInfoRequest, PB_System_DeviceInfoRequest, AUTO) PB_BIND(PB_System_DeviceInfoResponse, PB_System_DeviceInfoResponse, AUTO) +PB_BIND(PB_System_FactoryResetRequest, PB_System_FactoryResetRequest, AUTO) + + diff --git a/assets/compiled/system.pb.h b/assets/compiled/system.pb.h index 84120fc9..dbb23ff7 100644 --- a/assets/compiled/system.pb.h +++ b/assets/compiled/system.pb.h @@ -25,6 +25,10 @@ typedef struct _PB_System_DeviceInfoResponse { char *value; } PB_System_DeviceInfoResponse; +typedef struct _PB_System_FactoryResetRequest { + char dummy_field; +} PB_System_FactoryResetRequest; + typedef struct _PB_System_PingRequest { pb_bytes_array_t *data; } PB_System_PingRequest; @@ -54,11 +58,13 @@ extern "C" { #define PB_System_RebootRequest_init_default {_PB_System_RebootRequest_RebootMode_MIN} #define PB_System_DeviceInfoRequest_init_default {0} #define PB_System_DeviceInfoResponse_init_default {NULL, NULL} +#define PB_System_FactoryResetRequest_init_default {0} #define PB_System_PingRequest_init_zero {NULL} #define PB_System_PingResponse_init_zero {NULL} #define PB_System_RebootRequest_init_zero {_PB_System_RebootRequest_RebootMode_MIN} #define PB_System_DeviceInfoRequest_init_zero {0} #define PB_System_DeviceInfoResponse_init_zero {NULL, NULL} +#define PB_System_FactoryResetRequest_init_zero {0} /* Field tags (for use in manual encoding/decoding) */ #define PB_System_DeviceInfoResponse_key_tag 1 @@ -94,11 +100,17 @@ X(a, POINTER, SINGULAR, STRING, value, 2) #define PB_System_DeviceInfoResponse_CALLBACK NULL #define PB_System_DeviceInfoResponse_DEFAULT NULL +#define PB_System_FactoryResetRequest_FIELDLIST(X, a) \ + +#define PB_System_FactoryResetRequest_CALLBACK NULL +#define PB_System_FactoryResetRequest_DEFAULT NULL + extern const pb_msgdesc_t PB_System_PingRequest_msg; extern const pb_msgdesc_t PB_System_PingResponse_msg; extern const pb_msgdesc_t PB_System_RebootRequest_msg; extern const pb_msgdesc_t PB_System_DeviceInfoRequest_msg; extern const pb_msgdesc_t PB_System_DeviceInfoResponse_msg; +extern const pb_msgdesc_t PB_System_FactoryResetRequest_msg; /* Defines for backwards compatibility with code written before nanopb-0.4.0 */ #define PB_System_PingRequest_fields &PB_System_PingRequest_msg @@ -106,12 +118,14 @@ extern const pb_msgdesc_t PB_System_DeviceInfoResponse_msg; #define PB_System_RebootRequest_fields &PB_System_RebootRequest_msg #define PB_System_DeviceInfoRequest_fields &PB_System_DeviceInfoRequest_msg #define PB_System_DeviceInfoResponse_fields &PB_System_DeviceInfoResponse_msg +#define PB_System_FactoryResetRequest_fields &PB_System_FactoryResetRequest_msg /* Maximum encoded size of messages (where known) */ /* PB_System_PingRequest_size depends on runtime parameters */ /* PB_System_PingResponse_size depends on runtime parameters */ /* PB_System_DeviceInfoResponse_size depends on runtime parameters */ #define PB_System_DeviceInfoRequest_size 0 +#define PB_System_FactoryResetRequest_size 0 #define PB_System_RebootRequest_size 2 #ifdef __cplusplus diff --git a/assets/protobuf b/assets/protobuf index 5761a237..f6fdc10e 160000 --- a/assets/protobuf +++ b/assets/protobuf @@ -1 +1 @@ -Subproject commit 5761a23786b4729303bfa49142effea51870e549 +Subproject commit f6fdc10e6d111b289188e88ac1d432698bb739cf From 58ce937321cb259714fbdf38335df174d4c221ad Mon Sep 17 00:00:00 2001 From: SG Date: Sun, 12 Dec 2021 21:03:39 +1000 Subject: [PATCH 3/3] [FL-1891] Release 0.42 bugfixes (#891) * Fixed the "ibutton can only emulate after reading" bug * Fixed previous fix. FIXES FOR THE FIX GOD! BUGS FOR THE BUG THRONE! * Fixed "Repeat code" position on code input screen * Changed CAME protocol icon * Brewfile: add imagemagick missing assets compiler dependency * Correct fix for "Repeat code" position on code input screen Co-authored-by: Aleksandr Kutuzov --- Brewfile | 3 ++- applications/gui/modules/code_input.c | 2 +- applications/ibutton/helpers/key-emulator.cpp | 4 ++++ applications/ibutton/helpers/key-reader.cpp | 13 ++++++++----- applications/ibutton/helpers/pulse-sequencer.cpp | 2 +- applications/lfrfid/helpers/rfid-writer.cpp | 4 +++- firmware/targets/f6/furi-hal/furi-hal-rfid.c | 8 ++++++++ firmware/targets/f7/furi-hal/furi-hal-rfid.c | 8 ++++++++ firmware/targets/furi-hal-include/furi-hal-rfid.h | 8 ++++++++ lib/subghz/protocols/subghz_protocol_came_atomo.c | 2 +- 10 files changed, 44 insertions(+), 10 deletions(-) diff --git a/Brewfile b/Brewfile index aa88d642..64f9d9bc 100644 --- a/Brewfile +++ b/Brewfile @@ -3,4 +3,5 @@ brew "protobuf" brew "heatshrink" brew "open-ocd" brew "clang-format" -brew "dfu-util" \ No newline at end of file +brew "dfu-util" +brew "imagemagick" \ No newline at end of file diff --git a/applications/gui/modules/code_input.c b/applications/gui/modules/code_input.c index 9e220d54..988742f9 100644 --- a/applications/gui/modules/code_input.c +++ b/applications/gui/modules/code_input.c @@ -312,7 +312,7 @@ static void code_input_view_draw_callback(Canvas* canvas, void* _model) { 44 + y_offset, model->current); - if(model->current) canvas_draw_str(canvas, 2, 39 - y_offset, "Repeat code"); + if(model->current) canvas_draw_str(canvas, 2, 39 + y_offset, "Repeat code"); break; default: diff --git a/applications/ibutton/helpers/key-emulator.cpp b/applications/ibutton/helpers/key-emulator.cpp index 7c8c5c97..a09d83e8 100644 --- a/applications/ibutton/helpers/key-emulator.cpp +++ b/applications/ibutton/helpers/key-emulator.cpp @@ -17,6 +17,9 @@ void KeyEmulator::start(iButtonKey* key) { anything_emulated = false; stop(); + // pulldown pull pin, to prevent low-pass filtering by the RFID part of the schematic + furi_hal_rfid_pin_pull_pulldown(); + switch(key->get_key_type()) { case iButtonKeyType::KeyDallas: start_dallas_emulate(key); @@ -44,6 +47,7 @@ bool KeyEmulator::emulated() { void KeyEmulator::stop() { onewire_slave->stop(); pulser.stop(); + furi_hal_rfid_pins_reset(); } void KeyEmulator::start_cyfral_emulate(iButtonKey* key) { diff --git a/applications/ibutton/helpers/key-reader.cpp b/applications/ibutton/helpers/key-reader.cpp index fcb2a480..7abe5df7 100644 --- a/applications/ibutton/helpers/key-reader.cpp +++ b/applications/ibutton/helpers/key-reader.cpp @@ -115,12 +115,10 @@ bool KeyReader::verify_key(iButtonKeyType key_type, const uint8_t* const data, u } void KeyReader::start_comaparator(void) { - // pulldown lf-rfid pins to prevent interference - hal_gpio_init(&gpio_rfid_pull, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow); - hal_gpio_write(&gpio_rfid_pull, false); + furi_hal_rfid_pins_reset(); - hal_gpio_init(&gpio_rfid_carrier_out, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow); - hal_gpio_write(&gpio_rfid_carrier_out, false); + // pulldown pull pin, we sense the signal through the analog part of the RFID schematic + furi_hal_rfid_pin_pull_pulldown(); comparator_callback_pointer = cbc::obtain_connector(this, &KeyReader::comparator_trigger_callback); @@ -130,6 +128,11 @@ void KeyReader::start_comaparator(void) { } void KeyReader::stop_comaparator(void) { + furi_hal_rfid_pins_reset(); + + // rfid_pins_reset will disable ibutton pin + furi_hal_ibutton_start(); + HAL_COMP_Stop(&hcomp1); api_interrupt_remove(comparator_callback_pointer, InterruptTypeComparatorTrigger); } diff --git a/applications/ibutton/helpers/pulse-sequencer.cpp b/applications/ibutton/helpers/pulse-sequencer.cpp index 328df7ac..9a8b0d98 100644 --- a/applications/ibutton/helpers/pulse-sequencer.cpp +++ b/applications/ibutton/helpers/pulse-sequencer.cpp @@ -56,7 +56,7 @@ void PulseSequencer::init_timer(uint32_t period) { HAL_NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn); - hal_gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow); + hal_gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedVeryHigh); } void PulseSequencer::deinit_timer() { diff --git a/applications/lfrfid/helpers/rfid-writer.cpp b/applications/lfrfid/helpers/rfid-writer.cpp index f983ce35..0f4b8c96 100644 --- a/applications/lfrfid/helpers/rfid-writer.cpp +++ b/applications/lfrfid/helpers/rfid-writer.cpp @@ -37,7 +37,9 @@ void RfidWriter::start() { furi_hal_rfid_tim_read(125000, 0.5); furi_hal_rfid_pins_read(); furi_hal_rfid_tim_read_start(); - hal_gpio_write(&gpio_rfid_pull, true); + + // do not ground the antenna + furi_hal_rfid_pin_pull_release(); } void RfidWriter::stop() { diff --git a/firmware/targets/f6/furi-hal/furi-hal-rfid.c b/firmware/targets/f6/furi-hal/furi-hal-rfid.c index d7092f88..c14d48fd 100644 --- a/firmware/targets/f6/furi-hal/furi-hal-rfid.c +++ b/firmware/targets/f6/furi-hal/furi-hal-rfid.c @@ -61,6 +61,14 @@ void furi_hal_rfid_pins_read() { hal_gpio_init(&gpio_rfid_data_in, GpioModeAnalog, GpioPullNo, GpioSpeedLow); } +void furi_hal_rfid_pin_pull_release() { + hal_gpio_write(&gpio_rfid_pull, true); +} + +void furi_hal_rfid_pin_pull_pulldown() { + hal_gpio_write(&gpio_rfid_pull, false); +} + void furi_hal_rfid_tim_read(float freq, float duty_cycle) { // TODO LL init uint32_t period = (uint32_t)((SystemCoreClock) / freq) - 1; diff --git a/firmware/targets/f7/furi-hal/furi-hal-rfid.c b/firmware/targets/f7/furi-hal/furi-hal-rfid.c index 02a82bd1..b4b5af50 100644 --- a/firmware/targets/f7/furi-hal/furi-hal-rfid.c +++ b/firmware/targets/f7/furi-hal/furi-hal-rfid.c @@ -66,6 +66,14 @@ void furi_hal_rfid_pins_read() { hal_gpio_init(&gpio_rfid_data_in, GpioModeAnalog, GpioPullNo, GpioSpeedLow); } +void furi_hal_rfid_pin_pull_release() { + hal_gpio_write(&gpio_rfid_pull, true); +} + +void furi_hal_rfid_pin_pull_pulldown() { + hal_gpio_write(&gpio_rfid_pull, false); +} + void furi_hal_rfid_tim_read(float freq, float duty_cycle) { // TODO LL init uint32_t period = (uint32_t)((SystemCoreClock) / freq) - 1; diff --git a/firmware/targets/furi-hal-include/furi-hal-rfid.h b/firmware/targets/furi-hal-include/furi-hal-rfid.h index 5e11c6d6..68ac18c1 100644 --- a/firmware/targets/furi-hal-include/furi-hal-rfid.h +++ b/firmware/targets/furi-hal-include/furi-hal-rfid.h @@ -29,6 +29,14 @@ void furi_hal_rfid_pins_emulate(); */ void furi_hal_rfid_pins_read(); +/** Release rfid pull pin + */ +void furi_hal_rfid_pin_pull_release(); + +/** Pulldown rfid pull pin + */ +void furi_hal_rfid_pin_pull_pulldown(); + /** Config rfid timer to read state * * @param freq timer frequency diff --git a/lib/subghz/protocols/subghz_protocol_came_atomo.c b/lib/subghz/protocols/subghz_protocol_came_atomo.c index fbf9ca38..ff4dff67 100644 --- a/lib/subghz/protocols/subghz_protocol_came_atomo.c +++ b/lib/subghz/protocols/subghz_protocol_came_atomo.c @@ -26,7 +26,7 @@ SubGhzProtocolCameAtomo* subghz_protocol_came_atomo_alloc() { instance->common.te_short = 600; instance->common.te_long = 1200; instance->common.te_delta = 250; - instance->common.type_protocol = SubGhzProtocolCommonTypeStatic; + instance->common.type_protocol = SubGhzProtocolCommonTypeDynamic; instance->common.to_string = (SubGhzProtocolCommonToStr)subghz_protocol_came_atomo_to_str; instance->common.to_load_protocol = (SubGhzProtocolCommonLoadFromRAW)subghz_decoder_came_atomo_to_load_protocol;