[FL-3168] Add one_wire lib to f18, separate ibutton (#2509)

* Separate ibutton to its own module, add one_wire to f18
* Move onewire cli to a separate app

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
Georgii Surkov 2023-03-20 19:23:17 +03:00 committed by GitHub
parent 1d91a572cc
commit 0917494a80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 156 additions and 72 deletions

View File

@ -4,6 +4,7 @@ App(
apptype=FlipperAppType.METAPACKAGE,
provides=[
"gpio",
"onewire",
"ibutton",
"infrared",
"lfrfid",

View File

@ -4,25 +4,20 @@
#include <cli/cli.h>
#include <toolbox/args.h>
#include <one_wire/one_wire_host.h>
#include <one_wire/ibutton/ibutton_key.h>
#include <one_wire/ibutton/ibutton_worker.h>
#include <one_wire/ibutton/ibutton_protocols.h>
#include <ibutton/ibutton_key.h>
#include <ibutton/ibutton_worker.h>
#include <ibutton/ibutton_protocols.h>
static void ibutton_cli(Cli* cli, FuriString* args, void* context);
static void onewire_cli(Cli* cli, FuriString* args, void* context);
// app cli function
void ibutton_on_system_start() {
#ifdef SRV_CLI
Cli* cli = furi_record_open(RECORD_CLI);
cli_add_command(cli, "ikey", CliCommandFlagDefault, ibutton_cli, cli);
cli_add_command(cli, "onewire", CliCommandFlagDefault, onewire_cli, cli);
furi_record_close(RECORD_CLI);
#else
UNUSED(ibutton_cli);
UNUSED(onewire_cli);
#endif
}
@ -257,56 +252,3 @@ void ibutton_cli(Cli* cli, FuriString* args, void* context) {
furi_string_free(cmd);
}
static void onewire_cli_print_usage() {
printf("Usage:\r\n");
printf("onewire search\r\n");
};
static void onewire_cli_search(Cli* cli) {
UNUSED(cli);
OneWireHost* onewire = onewire_host_alloc(&ibutton_gpio);
uint8_t address[8];
bool done = false;
printf("Search started\r\n");
onewire_host_start(onewire);
furi_hal_power_enable_otg();
while(!done) {
if(onewire_host_search(onewire, address, OneWireHostSearchModeNormal) != 1) {
printf("Search finished\r\n");
onewire_host_reset_search(onewire);
done = true;
} else {
printf("Found: ");
for(uint8_t i = 0; i < 8; i++) {
printf("%02X", address[i]);
}
printf("\r\n");
}
furi_delay_ms(100);
}
furi_hal_power_disable_otg();
onewire_host_free(onewire);
}
void onewire_cli(Cli* cli, FuriString* args, void* context) {
UNUSED(context);
FuriString* cmd;
cmd = furi_string_alloc();
if(!args_read_string_and_trim(args, cmd)) {
furi_string_free(cmd);
onewire_cli_print_usage();
return;
}
if(furi_string_cmp_str(cmd, "search") == 0) {
onewire_cli_search(cli);
}
furi_string_free(cmd);
}

View File

@ -7,8 +7,8 @@
#include <gui/scene_manager.h>
#include <gui/view_dispatcher.h>
#include <one_wire/ibutton/ibutton_worker.h>
#include <one_wire/ibutton/ibutton_protocols.h>
#include <ibutton/ibutton_worker.h>
#include <ibutton/ibutton_protocols.h>
#include <rpc/rpc_app.h>
#include <storage/storage.h>

View File

@ -0,0 +1,14 @@
App(
appid="onewire",
name="1-Wire",
apptype=FlipperAppType.METAPACKAGE,
provides=["onewire_start"],
)
App(
appid="onewire_start",
apptype=FlipperAppType.STARTUP,
entry_point="onewire_on_system_start",
requires=["onewire"],
order=60,
)

View File

@ -0,0 +1,72 @@
#include <furi.h>
#include <furi_hal.h>
#include <cli/cli.h>
#include <toolbox/args.h>
#include <one_wire/one_wire_host.h>
static void onewire_cli(Cli* cli, FuriString* args, void* context);
void onewire_on_system_start() {
#ifdef SRV_CLI
Cli* cli = furi_record_open(RECORD_CLI);
cli_add_command(cli, "onewire", CliCommandFlagDefault, onewire_cli, cli);
furi_record_close(RECORD_CLI);
#else
UNUSED(onewire_cli);
#endif
}
static void onewire_cli_print_usage() {
printf("Usage:\r\n");
printf("onewire search\r\n");
};
static void onewire_cli_search(Cli* cli) {
UNUSED(cli);
OneWireHost* onewire = onewire_host_alloc(&ibutton_gpio);
uint8_t address[8];
bool done = false;
printf("Search started\r\n");
onewire_host_start(onewire);
furi_hal_power_enable_otg();
while(!done) {
if(onewire_host_search(onewire, address, OneWireHostSearchModeNormal) != 1) {
printf("Search finished\r\n");
onewire_host_reset_search(onewire);
done = true;
} else {
printf("Found: ");
for(uint8_t i = 0; i < 8; i++) {
printf("%02X", address[i]);
}
printf("\r\n");
}
furi_delay_ms(100);
}
furi_hal_power_disable_otg();
onewire_host_free(onewire);
}
void onewire_cli(Cli* cli, FuriString* args, void* context) {
UNUSED(context);
FuriString* cmd;
cmd = furi_string_alloc();
if(!args_read_string_and_trim(args, cmd)) {
furi_string_free(cmd);
onewire_cli_print_usage();
return;
}
if(furi_string_cmp_str(cmd, "search") == 0) {
onewire_cli_search(cli);
}
furi_string_free(cmd);
}

View File

@ -151,6 +151,10 @@ Header,+,lib/mlib/m-list.h,,
Header,+,lib/mlib/m-rbtree.h,,
Header,+,lib/mlib/m-tuple.h,,
Header,+,lib/mlib/m-variant.h,,
Header,+,lib/one_wire/maxim_crc.h,,
Header,+,lib/one_wire/one_wire_host.h,,
Header,+,lib/one_wire/one_wire_host_timing.h,,
Header,+,lib/one_wire/one_wire_slave.h,,
Header,+,lib/print/wrappers.h,,
Header,+,lib/toolbox/args.h,,
Header,+,lib/toolbox/crc32_calc.h,,
@ -1394,6 +1398,7 @@ Function,+,manchester_advance,_Bool,"ManchesterState, ManchesterEvent, Mancheste
Function,+,manchester_encoder_advance,_Bool,"ManchesterEncoderState*, const _Bool, ManchesterEncoderResult*"
Function,+,manchester_encoder_finish,ManchesterEncoderResult,ManchesterEncoderState*
Function,+,manchester_encoder_reset,void,ManchesterEncoderState*
Function,+,maxim_crc8,uint8_t,"const uint8_t*, const uint8_t, const uint8_t"
Function,-,mbedtls_des3_crypt_cbc,int,"mbedtls_des3_context*, int, size_t, unsigned char[8], const unsigned char*, unsigned char*"
Function,-,mbedtls_des3_crypt_ecb,int,"mbedtls_des3_context*, const unsigned char[8], unsigned char[8]"
Function,-,mbedtls_des3_free,void,mbedtls_des3_context*
@ -1472,6 +1477,32 @@ Function,+,notification_message,void,"NotificationApp*, const NotificationSequen
Function,+,notification_message_block,void,"NotificationApp*, const NotificationSequence*"
Function,-,nrand48,long,unsigned short[3]
Function,-,on_exit,int,"void (*)(int, void*), void*"
Function,+,onewire_host_alloc,OneWireHost*,const GpioPin*
Function,+,onewire_host_free,void,OneWireHost*
Function,+,onewire_host_read,uint8_t,OneWireHost*
Function,+,onewire_host_read_bit,_Bool,OneWireHost*
Function,+,onewire_host_read_bytes,void,"OneWireHost*, uint8_t*, uint16_t"
Function,+,onewire_host_reset,_Bool,OneWireHost*
Function,+,onewire_host_reset_search,void,OneWireHost*
Function,+,onewire_host_search,uint8_t,"OneWireHost*, uint8_t*, OneWireHostSearchMode"
Function,+,onewire_host_skip,void,OneWireHost*
Function,+,onewire_host_start,void,OneWireHost*
Function,+,onewire_host_stop,void,OneWireHost*
Function,+,onewire_host_target_search,void,"OneWireHost*, uint8_t"
Function,+,onewire_host_write,void,"OneWireHost*, uint8_t"
Function,+,onewire_host_write_bit,void,"OneWireHost*, _Bool"
Function,+,onewire_host_write_bytes,void,"OneWireHost*, const uint8_t*, uint16_t"
Function,+,onewire_slave_alloc,OneWireSlave*,const GpioPin*
Function,+,onewire_slave_free,void,OneWireSlave*
Function,+,onewire_slave_receive,_Bool,"OneWireSlave*, uint8_t*, size_t"
Function,+,onewire_slave_receive_bit,_Bool,OneWireSlave*
Function,+,onewire_slave_send,_Bool,"OneWireSlave*, const uint8_t*, size_t"
Function,+,onewire_slave_send_bit,_Bool,"OneWireSlave*, _Bool"
Function,+,onewire_slave_set_command_callback,void,"OneWireSlave*, OneWireSlaveCommandCallback, void*"
Function,+,onewire_slave_set_reset_callback,void,"OneWireSlave*, OneWireSlaveResetCallback, void*"
Function,+,onewire_slave_set_result_callback,void,"OneWireSlave*, OneWireSlaveResultCallback, void*"
Function,+,onewire_slave_start,void,OneWireSlave*
Function,+,onewire_slave_stop,void,OneWireSlave*
Function,-,open_memstream,FILE*,"char**, size_t*"
Function,+,path_append,void,"FuriString*, const char*"
Function,+,path_concat,void,"const char*, const char*, FuriString*"

1 entry status name type params
151 Header + lib/mlib/m-rbtree.h
152 Header + lib/mlib/m-tuple.h
153 Header + lib/mlib/m-variant.h
154 Header + lib/one_wire/maxim_crc.h
155 Header + lib/one_wire/one_wire_host.h
156 Header + lib/one_wire/one_wire_host_timing.h
157 Header + lib/one_wire/one_wire_slave.h
158 Header + lib/print/wrappers.h
159 Header + lib/toolbox/args.h
160 Header + lib/toolbox/crc32_calc.h
1398 Function + manchester_encoder_advance _Bool ManchesterEncoderState*, const _Bool, ManchesterEncoderResult*
1399 Function + manchester_encoder_finish ManchesterEncoderResult ManchesterEncoderState*
1400 Function + manchester_encoder_reset void ManchesterEncoderState*
1401 Function + maxim_crc8 uint8_t const uint8_t*, const uint8_t, const uint8_t
1402 Function - mbedtls_des3_crypt_cbc int mbedtls_des3_context*, int, size_t, unsigned char[8], const unsigned char*, unsigned char*
1403 Function - mbedtls_des3_crypt_ecb int mbedtls_des3_context*, const unsigned char[8], unsigned char[8]
1404 Function - mbedtls_des3_free void mbedtls_des3_context*
1477 Function + notification_message_block void NotificationApp*, const NotificationSequence*
1478 Function - nrand48 long unsigned short[3]
1479 Function - on_exit int void (*)(int, void*), void*
1480 Function + onewire_host_alloc OneWireHost* const GpioPin*
1481 Function + onewire_host_free void OneWireHost*
1482 Function + onewire_host_read uint8_t OneWireHost*
1483 Function + onewire_host_read_bit _Bool OneWireHost*
1484 Function + onewire_host_read_bytes void OneWireHost*, uint8_t*, uint16_t
1485 Function + onewire_host_reset _Bool OneWireHost*
1486 Function + onewire_host_reset_search void OneWireHost*
1487 Function + onewire_host_search uint8_t OneWireHost*, uint8_t*, OneWireHostSearchMode
1488 Function + onewire_host_skip void OneWireHost*
1489 Function + onewire_host_start void OneWireHost*
1490 Function + onewire_host_stop void OneWireHost*
1491 Function + onewire_host_target_search void OneWireHost*, uint8_t
1492 Function + onewire_host_write void OneWireHost*, uint8_t
1493 Function + onewire_host_write_bit void OneWireHost*, _Bool
1494 Function + onewire_host_write_bytes void OneWireHost*, const uint8_t*, uint16_t
1495 Function + onewire_slave_alloc OneWireSlave* const GpioPin*
1496 Function + onewire_slave_free void OneWireSlave*
1497 Function + onewire_slave_receive _Bool OneWireSlave*, uint8_t*, size_t
1498 Function + onewire_slave_receive_bit _Bool OneWireSlave*
1499 Function + onewire_slave_send _Bool OneWireSlave*, const uint8_t*, size_t
1500 Function + onewire_slave_send_bit _Bool OneWireSlave*, _Bool
1501 Function + onewire_slave_set_command_callback void OneWireSlave*, OneWireSlaveCommandCallback, void*
1502 Function + onewire_slave_set_reset_callback void OneWireSlave*, OneWireSlaveResetCallback, void*
1503 Function + onewire_slave_set_result_callback void OneWireSlave*, OneWireSlaveResultCallback, void*
1504 Function + onewire_slave_start void OneWireSlave*
1505 Function + onewire_slave_stop void OneWireSlave*
1506 Function - open_memstream FILE* char**, size_t*
1507 Function + path_append void FuriString*, const char*
1508 Function + path_concat void const char*, const char*, FuriString*

View File

@ -24,6 +24,7 @@
"usb_stm32",
"appframe",
"assets",
"one_wire",
"misc",
"flipper_application",
"flipperformat",
@ -45,11 +46,11 @@
"furi_hal_subghz_configs.h"
],
"excluded_modules": [
"one_wire",
"nfc",
"lfrfid",
"subghz",
"ibutton",
"infrared",
"st25rfal002"
]
}
}

View File

@ -118,6 +118,9 @@ Header,+,lib/flipper_application/plugins/composite_resolver.h,,
Header,+,lib/flipper_application/plugins/plugin_manager.h,,
Header,+,lib/flipper_format/flipper_format.h,,
Header,+,lib/flipper_format/flipper_format_i.h,,
Header,+,lib/ibutton/ibutton_key.h,,
Header,+,lib/ibutton/ibutton_protocols.h,,
Header,+,lib/ibutton/ibutton_worker.h,,
Header,+,lib/infrared/encoder_decoder/infrared.h,,
Header,+,lib/infrared/worker/infrared_transmit.h,,
Header,+,lib/infrared/worker/infrared_worker.h,,
@ -167,9 +170,6 @@ Header,+,lib/mlib/m-rbtree.h,,
Header,+,lib/mlib/m-tuple.h,,
Header,+,lib/mlib/m-variant.h,,
Header,+,lib/nfc/nfc_device.h,,
Header,+,lib/one_wire/ibutton/ibutton_key.h,,
Header,+,lib/one_wire/ibutton/ibutton_protocols.h,,
Header,+,lib/one_wire/ibutton/ibutton_worker.h,,
Header,+,lib/one_wire/maxim_crc.h,,
Header,+,lib/one_wire/one_wire_host.h,,
Header,+,lib/one_wire/one_wire_host_timing.h,,

1 entry status name type params
118 Header + lib/flipper_application/plugins/plugin_manager.h
119 Header + lib/flipper_format/flipper_format.h
120 Header + lib/flipper_format/flipper_format_i.h
121 Header + lib/ibutton/ibutton_key.h
122 Header + lib/ibutton/ibutton_protocols.h
123 Header + lib/ibutton/ibutton_worker.h
124 Header + lib/infrared/encoder_decoder/infrared.h
125 Header + lib/infrared/worker/infrared_transmit.h
126 Header + lib/infrared/worker/infrared_worker.h
170 Header + lib/mlib/m-tuple.h
171 Header + lib/mlib/m-variant.h
172 Header + lib/nfc/nfc_device.h
Header + lib/one_wire/ibutton/ibutton_key.h
Header + lib/one_wire/ibutton/ibutton_protocols.h
Header + lib/one_wire/ibutton/ibutton_worker.h
173 Header + lib/one_wire/maxim_crc.h
174 Header + lib/one_wire/one_wire_host.h
175 Header + lib/one_wire/one_wire_host_timing.h

View File

@ -35,6 +35,7 @@
"appframe",
"assets",
"one_wire",
"ibutton",
"misc",
"mbedtls",
"lfrfid",
@ -42,4 +43,4 @@
"flipperformat",
"toolbox"
]
}
}

View File

@ -87,6 +87,7 @@ libs = env.BuildModules(
"fatfs",
"flipper_format",
"one_wire",
"ibutton",
"infrared",
"littlefs",
"mbedtls",

24
lib/ibutton/SConscript Normal file
View File

@ -0,0 +1,24 @@
Import("env")
env.Append(
LINT_SOURCES=[
Dir("."),
],
CPPPATH=[
"#/lib/ibutton",
],
SDK_HEADERS=[
File("ibutton_key.h"),
File("ibutton_worker.h"),
File("ibutton_protocols.h"),
],
)
libenv = env.Clone(FW_LIB_NAME="ibutton")
libenv.ApplyLibFlags()
sources = libenv.GlobRecursive("*.c*")
lib = libenv.StaticLibrary("${FW_LIB_NAME}", sources)
libenv.Install("${LIB_DIST_DIR}", lib)
Return("lib")

View File

@ -11,9 +11,6 @@ env.Append(
File("one_wire_host_timing.h"),
File("one_wire_host.h"),
File("one_wire_slave.h"),
File("ibutton/ibutton_key.h"),
File("ibutton/ibutton_worker.h"),
File("ibutton/ibutton_protocols.h"),
File("maxim_crc.h"),
],
)