mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 15:28:36 -07:00
Merge branch 'UNLEASHED' into 420
This commit is contained in:
@@ -209,7 +209,7 @@ void subghz_frequency_analyzer_draw(Canvas* canvas, SubGhzFrequencyAnalyzerModel
|
||||
// Buttons hint
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
elements_button_left(canvas, "T-");
|
||||
elements_button_right(canvas, "T+");
|
||||
elements_button_right(canvas, "+T");
|
||||
}
|
||||
|
||||
uint32_t subghz_frequency_find_correct(uint32_t input) {
|
||||
@@ -271,7 +271,7 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
|
||||
subghz_frequency_analyzer_worker_set_trigger_level(instance->worker, trigger_level);
|
||||
FURI_LOG_I(TAG, "trigger = %.1f", (double)trigger_level);
|
||||
need_redraw = true;
|
||||
} else if(event->type == InputTypePress && event->key == InputKeyDown) {
|
||||
} else if(event->type == InputTypePress && event->key == InputKeyUp) {
|
||||
if(instance->feedback_level == 0) {
|
||||
instance->feedback_level = 2;
|
||||
} else {
|
||||
@@ -283,7 +283,7 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
|
||||
need_redraw = true;
|
||||
} else if(
|
||||
((event->type == InputTypePress) || (event->type == InputTypeRepeat)) &&
|
||||
event->key == InputKeyUp) {
|
||||
event->key == InputKeyDown) {
|
||||
instance->show_frame = instance->max_index > 0;
|
||||
if(instance->show_frame) {
|
||||
instance->selected_index = (instance->selected_index + 1) % instance->max_index;
|
||||
|
||||
@@ -78,12 +78,6 @@ typedef struct {
|
||||
FuriString* right_file;
|
||||
FuriString* ok_file;
|
||||
|
||||
FuriString* up_l;
|
||||
FuriString* left_l;
|
||||
FuriString* right_l;
|
||||
FuriString* down_l;
|
||||
FuriString* ok_l;
|
||||
|
||||
FuriString* file_path;
|
||||
|
||||
char* up_label;
|
||||
@@ -135,34 +129,7 @@ static char* char_to_str(char* str, int i) {
|
||||
|
||||
return converted;
|
||||
}
|
||||
/*
|
||||
static const char* int_to_char(int number) {
|
||||
switch(number) {
|
||||
case 0:
|
||||
return "0";
|
||||
case 1:
|
||||
return "1";
|
||||
case 2:
|
||||
return "2";
|
||||
case 3:
|
||||
return "3";
|
||||
case 4:
|
||||
return "4";
|
||||
case 5:
|
||||
return "5";
|
||||
case 6:
|
||||
return "6";
|
||||
case 7:
|
||||
return "7";
|
||||
case 8:
|
||||
return "8";
|
||||
case 9:
|
||||
return "9";
|
||||
default:
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//get filename without path
|
||||
static char* extract_filename(const char* name, int len) {
|
||||
FuriString* tmp;
|
||||
@@ -174,6 +141,43 @@ static char* extract_filename(const char* name, int len) {
|
||||
return char_to_str((char*)furi_string_get_cstr(tmp), len);
|
||||
}
|
||||
|
||||
static void cfg_read_file_path(
|
||||
FlipperFormat* fff_file,
|
||||
FuriString* text_file_path,
|
||||
char** text_file_label,
|
||||
const char* read_key,
|
||||
int* is_enabled) {
|
||||
if(!flipper_format_read_string(fff_file, read_key, text_file_path)) {
|
||||
FURI_LOG_W(TAG, "Could not read %s string", read_key);
|
||||
*text_file_label = "N/A";
|
||||
*is_enabled = 0;
|
||||
} else {
|
||||
*text_file_label = extract_filename(furi_string_get_cstr(text_file_path), 16);
|
||||
FURI_LOG_D(TAG, "%s file: %s", read_key, furi_string_get_cstr(text_file_path));
|
||||
*is_enabled = 1;
|
||||
}
|
||||
flipper_format_rewind(fff_file);
|
||||
}
|
||||
|
||||
static void cfg_read_file_label(
|
||||
FlipperFormat* fff_file,
|
||||
char** text_file_label,
|
||||
const char* read_key,
|
||||
bool is_enabled) {
|
||||
FuriString* temp_label = furi_string_alloc();
|
||||
|
||||
if(!flipper_format_read_string(fff_file, read_key, temp_label)) {
|
||||
FURI_LOG_W(TAG, "Could not read %s string", read_key);
|
||||
} else {
|
||||
if(is_enabled == 1) {
|
||||
*text_file_label = char_to_str((char*)furi_string_get_cstr(temp_label), 16);
|
||||
}
|
||||
FURI_LOG_D(TAG, "%s label: %s", read_key, *text_file_label);
|
||||
}
|
||||
flipper_format_rewind(fff_file);
|
||||
furi_string_free(temp_label);
|
||||
}
|
||||
|
||||
/*
|
||||
* check that map file exists
|
||||
* assign variables to values within map file
|
||||
@@ -195,8 +199,6 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) {
|
||||
app->right_enabled = 0;
|
||||
app->ok_enabled = 0;
|
||||
|
||||
int label_len = 16;
|
||||
|
||||
//check that map file exists
|
||||
if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) {
|
||||
FURI_LOG_E(TAG, "Could not open MAP file %s", furi_string_get_cstr(file_name));
|
||||
@@ -205,112 +207,29 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) {
|
||||
|
||||
//assign variables to values within map file
|
||||
//set missing filenames to N/A
|
||||
if(!flipper_format_read_string(fff_data_file, "UP", app->up_file)) {
|
||||
FURI_LOG_W(TAG, "Could not read UP string");
|
||||
//set label to "N/A"
|
||||
app->up_label = "N/A";
|
||||
} else {
|
||||
//check name length for proper screen fit
|
||||
//then set filename as label. Might be replaced with defined label later on below.
|
||||
app->up_label = extract_filename(furi_string_get_cstr(app->up_file), label_len);
|
||||
FURI_LOG_I(TAG, "UP file: %s", furi_string_get_cstr(app->up_file));
|
||||
//enable processing of the signal on button press
|
||||
app->up_enabled = 1;
|
||||
}
|
||||
cfg_read_file_path(fff_data_file, app->up_file, &app->up_label, "UP", &app->up_enabled);
|
||||
|
||||
//Repeat process for Down
|
||||
if(!flipper_format_read_string(fff_data_file, "DOWN", app->down_file)) {
|
||||
FURI_LOG_W(TAG, "Could not read DOWN string");
|
||||
app->down_label = "N/A";
|
||||
} else {
|
||||
app->down_label = extract_filename(furi_string_get_cstr(app->down_file), label_len);
|
||||
FURI_LOG_I(TAG, "DOWN file: %s", furi_string_get_cstr(app->down_file));
|
||||
app->down_enabled = 1;
|
||||
}
|
||||
cfg_read_file_path(
|
||||
fff_data_file, app->down_file, &app->down_label, "DOWN", &app->down_enabled);
|
||||
|
||||
//Repeat process for Left
|
||||
if(!flipper_format_read_string(fff_data_file, "LEFT", app->left_file)) {
|
||||
FURI_LOG_W(TAG, "Could not read LEFT string");
|
||||
app->left_label = "N/A";
|
||||
} else {
|
||||
app->left_label = extract_filename(furi_string_get_cstr(app->left_file), label_len);
|
||||
FURI_LOG_I(TAG, "LEFT file: %s", furi_string_get_cstr(app->left_file));
|
||||
app->left_enabled = 1;
|
||||
}
|
||||
cfg_read_file_path(
|
||||
fff_data_file, app->left_file, &app->left_label, "LEFT", &app->left_enabled);
|
||||
|
||||
//Repeat process for Right
|
||||
if(!flipper_format_read_string(fff_data_file, "RIGHT", app->right_file)) {
|
||||
FURI_LOG_W(TAG, "Could not read RIGHT string");
|
||||
app->right_label = "N/A";
|
||||
} else {
|
||||
app->right_label = extract_filename(furi_string_get_cstr(app->right_file), label_len);
|
||||
FURI_LOG_I(TAG, "RIGHT file: %s", furi_string_get_cstr(app->right_file));
|
||||
app->right_enabled = 1;
|
||||
}
|
||||
cfg_read_file_path(
|
||||
fff_data_file, app->right_file, &app->right_label, "RIGHT", &app->right_enabled);
|
||||
|
||||
//Repeat process for Ok
|
||||
if(!flipper_format_read_string(fff_data_file, "OK", app->ok_file)) {
|
||||
FURI_LOG_W(TAG, "Could not read OK string");
|
||||
app->ok_label = "N/A";
|
||||
} else {
|
||||
app->ok_label = extract_filename(furi_string_get_cstr(app->ok_file), label_len);
|
||||
FURI_LOG_I(TAG, "OK file: %s", furi_string_get_cstr(app->ok_file));
|
||||
app->ok_enabled = 1;
|
||||
}
|
||||
cfg_read_file_path(fff_data_file, app->ok_file, &app->ok_label, "OK", &app->ok_enabled);
|
||||
|
||||
//File definitions are done.
|
||||
//File checks will follow after label assignment in order to close the universal_rf_map file without the need to reopen it again.
|
||||
|
||||
//Label Assignment/Check Start
|
||||
|
||||
//assign variables to values within map file
|
||||
if(!flipper_format_read_string(fff_data_file, "ULABEL", app->up_l)) {
|
||||
FURI_LOG_W(TAG, "Could not read ULABEL string");
|
||||
} else {
|
||||
//check if button is enabled, and set label
|
||||
if(app->up_enabled == 1) {
|
||||
//set label from map to variable and shrink to fit screen
|
||||
app->up_label = char_to_str((char*)furi_string_get_cstr(app->up_l), label_len);
|
||||
}
|
||||
FURI_LOG_I(TAG, "UP label: %s", app->up_label);
|
||||
}
|
||||
|
||||
if(!flipper_format_read_string(fff_data_file, "DLABEL", app->down_l)) {
|
||||
FURI_LOG_W(TAG, "Could not read DLABEL string");
|
||||
} else {
|
||||
if(app->down_enabled == 1) {
|
||||
app->down_label = char_to_str((char*)furi_string_get_cstr(app->down_l), label_len);
|
||||
}
|
||||
FURI_LOG_I(TAG, "DOWN label: %s", app->down_label);
|
||||
}
|
||||
|
||||
if(!flipper_format_read_string(fff_data_file, "LLABEL", app->left_l)) {
|
||||
FURI_LOG_W(TAG, "Could not read LLABEL string");
|
||||
} else {
|
||||
if(app->left_enabled == 1) {
|
||||
app->left_label = char_to_str((char*)furi_string_get_cstr(app->left_l), label_len);
|
||||
}
|
||||
FURI_LOG_I(TAG, "LEFT label: %s", app->left_label);
|
||||
}
|
||||
|
||||
if(!flipper_format_read_string(fff_data_file, "RLABEL", app->right_l)) {
|
||||
FURI_LOG_W(TAG, "Could not read RLABEL string");
|
||||
} else {
|
||||
if(app->right_enabled == 1) {
|
||||
app->right_label =
|
||||
char_to_str((char*)furi_string_get_cstr(app->right_l), label_len);
|
||||
}
|
||||
FURI_LOG_I(TAG, "RIGHT label: %s", app->right_label);
|
||||
}
|
||||
|
||||
if(!flipper_format_read_string(fff_data_file, "OKLABEL", app->ok_l)) {
|
||||
FURI_LOG_W(TAG, "Could not read OKLABEL string");
|
||||
} else {
|
||||
if(app->ok_enabled == 1) {
|
||||
app->ok_label = char_to_str((char*)furi_string_get_cstr(app->ok_l), label_len);
|
||||
}
|
||||
FURI_LOG_I(TAG, "OK label: %s", app->ok_label);
|
||||
}
|
||||
cfg_read_file_label(fff_data_file, &app->up_label, "ULABEL", app->up_enabled);
|
||||
cfg_read_file_label(fff_data_file, &app->down_label, "DLABEL", app->down_enabled);
|
||||
cfg_read_file_label(fff_data_file, &app->left_label, "LLABEL", app->left_enabled);
|
||||
cfg_read_file_label(fff_data_file, &app->right_label, "RLABEL", app->right_enabled);
|
||||
cfg_read_file_label(fff_data_file, &app->ok_label, "OKLABEL", app->ok_enabled);
|
||||
}
|
||||
|
||||
flipper_format_file_close(fff_data_file);
|
||||
@@ -567,7 +486,7 @@ void unirfremix_tx_stop(UniRFRemix* app) {
|
||||
|
||||
//Stop TX
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
FURI_LOG_I(TAG, "TX Done!");
|
||||
//FURI_LOG_I(TAG, "TX Done!");
|
||||
subghz_transmitter_stop(app->tx_transmitter);
|
||||
|
||||
FURI_LOG_D(TAG, "Checking if protocol is dynamic");
|
||||
@@ -636,7 +555,7 @@ static bool unirfremix_send_sub(UniRFRemix* app, FlipperFormat* fff_data) {
|
||||
break;
|
||||
}
|
||||
|
||||
FURI_LOG_I(TAG, "Sending...");
|
||||
//FURI_LOG_I(TAG, "Sending...");
|
||||
notification_message(app->notification, &sequence_blink_start_magenta);
|
||||
|
||||
furi_hal_subghz_start_async_tx(subghz_transmitter_yield, app->tx_transmitter);
|
||||
@@ -648,7 +567,7 @@ static bool unirfremix_send_sub(UniRFRemix* app, FlipperFormat* fff_data) {
|
||||
}
|
||||
|
||||
static void unirfremix_send_signal(UniRFRemix* app, Storage* storage, const char* path) {
|
||||
FURI_LOG_I(TAG, "Sending: %s", path);
|
||||
FURI_LOG_D(TAG, "Sending: %s", path);
|
||||
|
||||
app->tx_file_path = path;
|
||||
|
||||
@@ -688,7 +607,7 @@ static void unirfremix_send_signal(UniRFRemix* app, Storage* storage, const char
|
||||
static void unirfremix_process_signal(UniRFRemix* app, FuriString* signal) {
|
||||
view_port_update(app->view_port);
|
||||
|
||||
FURI_LOG_I(TAG, "signal = %s", furi_string_get_cstr(signal));
|
||||
FURI_LOG_D(TAG, "signal = %s", furi_string_get_cstr(signal));
|
||||
|
||||
if(strlen(furi_string_get_cstr(signal)) > 12) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
@@ -856,12 +775,6 @@ void unirfremix_free(UniRFRemix* app, bool with_subghz) {
|
||||
furi_string_free(app->right_file);
|
||||
furi_string_free(app->ok_file);
|
||||
|
||||
furi_string_free(app->up_l);
|
||||
furi_string_free(app->down_l);
|
||||
furi_string_free(app->left_l);
|
||||
furi_string_free(app->right_l);
|
||||
furi_string_free(app->ok_l);
|
||||
|
||||
furi_string_free(app->file_path);
|
||||
furi_string_free(app->signal);
|
||||
|
||||
@@ -901,12 +814,6 @@ int32_t unirfremix_app(void* p) {
|
||||
app->right_file = furi_string_alloc();
|
||||
app->ok_file = furi_string_alloc();
|
||||
|
||||
app->up_l = furi_string_alloc();
|
||||
app->down_l = furi_string_alloc();
|
||||
app->left_l = furi_string_alloc();
|
||||
app->right_l = furi_string_alloc();
|
||||
app->ok_l = furi_string_alloc();
|
||||
|
||||
app->file_result = 3;
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
@@ -13,4 +13,12 @@ App(
|
||||
fap_icon="mouse_10px.png",
|
||||
fap_category="GPIO",
|
||||
fap_icon_assets="images",
|
||||
fap_private_libs=[
|
||||
Lib(
|
||||
name="nrf24",
|
||||
sources=[
|
||||
"nrf24.c",
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -9,4 +9,12 @@ App(
|
||||
order=60,
|
||||
fap_icon="nrfsniff_10px.png",
|
||||
fap_category="GPIO",
|
||||
fap_private_libs=[
|
||||
Lib(
|
||||
name="nrf24",
|
||||
sources=[
|
||||
"nrf24.c",
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
520
applications/plugins/nrfsniff/lib/nrf24/nrf24.c
Normal file
520
applications/plugins/nrfsniff/lib/nrf24/nrf24.c
Normal file
@@ -0,0 +1,520 @@
|
||||
#include "nrf24.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <furi_hal_resources.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
void nrf24_init() {
|
||||
furi_hal_spi_bus_handle_init(nrf24_HANDLE);
|
||||
furi_hal_spi_acquire(nrf24_HANDLE);
|
||||
furi_hal_gpio_init(nrf24_CE_PIN, GpioModeOutputPushPull, GpioPullUp, GpioSpeedVeryHigh);
|
||||
furi_hal_gpio_write(nrf24_CE_PIN, false);
|
||||
}
|
||||
|
||||
void nrf24_deinit() {
|
||||
furi_hal_spi_release(nrf24_HANDLE);
|
||||
furi_hal_spi_bus_handle_deinit(nrf24_HANDLE);
|
||||
furi_hal_gpio_write(nrf24_CE_PIN, false);
|
||||
furi_hal_gpio_init(nrf24_CE_PIN, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
void nrf24_spi_trx(
|
||||
FuriHalSpiBusHandle* handle,
|
||||
uint8_t* tx,
|
||||
uint8_t* rx,
|
||||
uint8_t size,
|
||||
uint32_t timeout) {
|
||||
UNUSED(timeout);
|
||||
furi_hal_gpio_write(handle->cs, false);
|
||||
furi_hal_spi_bus_trx(handle, tx, rx, size, nrf24_TIMEOUT);
|
||||
furi_hal_gpio_write(handle->cs, true);
|
||||
}
|
||||
|
||||
uint8_t nrf24_write_reg(FuriHalSpiBusHandle* handle, uint8_t reg, uint8_t data) {
|
||||
uint8_t tx[2] = {W_REGISTER | (REGISTER_MASK & reg), data};
|
||||
uint8_t rx[2] = {0};
|
||||
nrf24_spi_trx(handle, tx, rx, 2, nrf24_TIMEOUT);
|
||||
return rx[0];
|
||||
}
|
||||
|
||||
uint8_t
|
||||
nrf24_write_buf_reg(FuriHalSpiBusHandle* handle, uint8_t reg, uint8_t* data, uint8_t size) {
|
||||
uint8_t tx[size + 1];
|
||||
uint8_t rx[size + 1];
|
||||
memset(rx, 0, size + 1);
|
||||
tx[0] = W_REGISTER | (REGISTER_MASK & reg);
|
||||
memcpy(&tx[1], data, size);
|
||||
nrf24_spi_trx(handle, tx, rx, size + 1, nrf24_TIMEOUT);
|
||||
return rx[0];
|
||||
}
|
||||
|
||||
uint8_t nrf24_read_reg(FuriHalSpiBusHandle* handle, uint8_t reg, uint8_t* data, uint8_t size) {
|
||||
uint8_t tx[size + 1];
|
||||
uint8_t rx[size + 1];
|
||||
memset(rx, 0, size + 1);
|
||||
tx[0] = R_REGISTER | (REGISTER_MASK & reg);
|
||||
memset(&tx[1], 0, size);
|
||||
nrf24_spi_trx(handle, tx, rx, size + 1, nrf24_TIMEOUT);
|
||||
memcpy(data, &rx[1], size);
|
||||
return rx[0];
|
||||
}
|
||||
|
||||
uint8_t nrf24_flush_rx(FuriHalSpiBusHandle* handle) {
|
||||
uint8_t tx[] = {FLUSH_RX};
|
||||
uint8_t rx[] = {0};
|
||||
nrf24_spi_trx(handle, tx, rx, 1, nrf24_TIMEOUT);
|
||||
return rx[0];
|
||||
}
|
||||
|
||||
uint8_t nrf24_flush_tx(FuriHalSpiBusHandle* handle) {
|
||||
uint8_t tx[] = {FLUSH_TX};
|
||||
uint8_t rx[] = {0};
|
||||
nrf24_spi_trx(handle, tx, rx, 1, nrf24_TIMEOUT);
|
||||
return rx[0];
|
||||
}
|
||||
|
||||
uint8_t nrf24_get_maclen(FuriHalSpiBusHandle* handle) {
|
||||
uint8_t maclen;
|
||||
nrf24_read_reg(handle, REG_SETUP_AW, &maclen, 1);
|
||||
maclen &= 3;
|
||||
return maclen + 2;
|
||||
}
|
||||
|
||||
uint8_t nrf24_set_maclen(FuriHalSpiBusHandle* handle, uint8_t maclen) {
|
||||
assert(maclen > 1 && maclen < 6);
|
||||
uint8_t status = 0;
|
||||
status = nrf24_write_reg(handle, REG_SETUP_AW, maclen - 2);
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t nrf24_status(FuriHalSpiBusHandle* handle) {
|
||||
uint8_t status;
|
||||
uint8_t tx[] = {R_REGISTER | (REGISTER_MASK & REG_STATUS)};
|
||||
nrf24_spi_trx(handle, tx, &status, 1, nrf24_TIMEOUT);
|
||||
return status;
|
||||
}
|
||||
|
||||
uint32_t nrf24_get_rate(FuriHalSpiBusHandle* handle) {
|
||||
uint8_t setup = 0;
|
||||
uint32_t rate = 0;
|
||||
nrf24_read_reg(handle, REG_RF_SETUP, &setup, 1);
|
||||
setup &= 0x28;
|
||||
if(setup == 0x20)
|
||||
rate = 250000; // 250kbps
|
||||
else if(setup == 0x08)
|
||||
rate = 2000000; // 2Mbps
|
||||
else if(setup == 0x00)
|
||||
rate = 1000000; // 1Mbps
|
||||
|
||||
return rate;
|
||||
}
|
||||
|
||||
uint8_t nrf24_set_rate(FuriHalSpiBusHandle* handle, uint32_t rate) {
|
||||
uint8_t r6 = 0;
|
||||
uint8_t status = 0;
|
||||
if(!rate) rate = 2000000;
|
||||
|
||||
nrf24_read_reg(handle, REG_RF_SETUP, &r6, 1); // RF_SETUP register
|
||||
r6 = r6 & (~0x28); // Clear rate fields.
|
||||
if(rate == 2000000)
|
||||
r6 = r6 | 0x08;
|
||||
else if(rate == 1000000)
|
||||
r6 = r6;
|
||||
else if(rate == 250000)
|
||||
r6 = r6 | 0x20;
|
||||
|
||||
status = nrf24_write_reg(handle, REG_RF_SETUP, r6); // Write new rate.
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t nrf24_get_chan(FuriHalSpiBusHandle* handle) {
|
||||
uint8_t channel = 0;
|
||||
nrf24_read_reg(handle, REG_RF_CH, &channel, 1);
|
||||
return channel;
|
||||
}
|
||||
|
||||
uint8_t nrf24_set_chan(FuriHalSpiBusHandle* handle, uint8_t chan) {
|
||||
uint8_t status;
|
||||
status = nrf24_write_reg(handle, REG_RF_CH, chan);
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t nrf24_get_src_mac(FuriHalSpiBusHandle* handle, uint8_t* mac) {
|
||||
uint8_t size = 0;
|
||||
uint8_t status = 0;
|
||||
size = nrf24_get_maclen(handle);
|
||||
status = nrf24_read_reg(handle, REG_RX_ADDR_P0, mac, size);
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t nrf24_set_src_mac(FuriHalSpiBusHandle* handle, uint8_t* mac, uint8_t size) {
|
||||
uint8_t status = 0;
|
||||
uint8_t clearmac[] = {0, 0, 0, 0, 0};
|
||||
nrf24_set_maclen(handle, size);
|
||||
nrf24_write_buf_reg(handle, REG_RX_ADDR_P0, clearmac, 5);
|
||||
status = nrf24_write_buf_reg(handle, REG_RX_ADDR_P0, mac, size);
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t nrf24_get_dst_mac(FuriHalSpiBusHandle* handle, uint8_t* mac) {
|
||||
uint8_t size = 0;
|
||||
uint8_t status = 0;
|
||||
size = nrf24_get_maclen(handle);
|
||||
status = nrf24_read_reg(handle, REG_TX_ADDR, mac, size);
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t nrf24_set_dst_mac(FuriHalSpiBusHandle* handle, uint8_t* mac, uint8_t size) {
|
||||
uint8_t status = 0;
|
||||
uint8_t clearmac[] = {0, 0, 0, 0, 0};
|
||||
nrf24_set_maclen(handle, size);
|
||||
nrf24_write_buf_reg(handle, REG_TX_ADDR, clearmac, 5);
|
||||
status = nrf24_write_buf_reg(handle, REG_TX_ADDR, mac, size);
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t nrf24_get_packetlen(FuriHalSpiBusHandle* handle) {
|
||||
uint8_t len = 0;
|
||||
nrf24_read_reg(handle, RX_PW_P0, &len, 1);
|
||||
return len;
|
||||
}
|
||||
|
||||
uint8_t nrf24_set_packetlen(FuriHalSpiBusHandle* handle, uint8_t len) {
|
||||
uint8_t status = 0;
|
||||
status = nrf24_write_reg(handle, RX_PW_P0, len);
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
nrf24_rxpacket(FuriHalSpiBusHandle* handle, uint8_t* packet, uint8_t* packetsize, bool full) {
|
||||
uint8_t status = 0;
|
||||
uint8_t size = 0;
|
||||
uint8_t tx_pl_wid[] = {R_RX_PL_WID, 0};
|
||||
uint8_t rx_pl_wid[] = {0, 0};
|
||||
uint8_t tx_cmd[33] = {0}; // 32 max payload size + 1 for command
|
||||
uint8_t tmp_packet[33] = {0};
|
||||
|
||||
status = nrf24_status(handle);
|
||||
|
||||
if(status & 0x40) {
|
||||
if(full)
|
||||
size = nrf24_get_packetlen(handle);
|
||||
else {
|
||||
nrf24_spi_trx(handle, tx_pl_wid, rx_pl_wid, 2, nrf24_TIMEOUT);
|
||||
size = rx_pl_wid[1];
|
||||
}
|
||||
|
||||
tx_cmd[0] = R_RX_PAYLOAD;
|
||||
nrf24_spi_trx(handle, tx_cmd, tmp_packet, size + 1, nrf24_TIMEOUT);
|
||||
nrf24_write_reg(handle, REG_STATUS, 0x40); // clear bit.
|
||||
memcpy(packet, &tmp_packet[1], size);
|
||||
} else if(status == 0) {
|
||||
nrf24_flush_rx(handle);
|
||||
nrf24_write_reg(handle, REG_STATUS, 0x40); // clear bit.
|
||||
}
|
||||
|
||||
*packetsize = size;
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t nrf24_txpacket(FuriHalSpiBusHandle* handle, uint8_t* payload, uint8_t size, bool ack) {
|
||||
uint8_t status = 0;
|
||||
uint8_t tx[size + 1];
|
||||
uint8_t rx[size + 1];
|
||||
memset(tx, 0, size + 1);
|
||||
memset(rx, 0, size + 1);
|
||||
|
||||
if(!ack)
|
||||
tx[0] = W_TX_PAYLOAD_NOACK;
|
||||
else
|
||||
tx[0] = W_TX_PAYLOAD;
|
||||
|
||||
memcpy(&tx[1], payload, size);
|
||||
nrf24_spi_trx(handle, tx, rx, size + 1, nrf24_TIMEOUT);
|
||||
nrf24_set_tx_mode(handle);
|
||||
|
||||
while(!(status & (TX_DS | MAX_RT))) status = nrf24_status(handle);
|
||||
|
||||
if(status & MAX_RT) nrf24_flush_tx(handle);
|
||||
|
||||
nrf24_set_idle(handle);
|
||||
nrf24_write_reg(handle, REG_STATUS, TX_DS | MAX_RT);
|
||||
return status & TX_DS;
|
||||
}
|
||||
|
||||
uint8_t nrf24_power_up(FuriHalSpiBusHandle* handle) {
|
||||
uint8_t status = 0;
|
||||
uint8_t cfg = 0;
|
||||
nrf24_read_reg(handle, REG_CONFIG, &cfg, 1);
|
||||
cfg = cfg | 2;
|
||||
status = nrf24_write_reg(handle, REG_CONFIG, cfg);
|
||||
furi_delay_ms(5000);
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t nrf24_set_idle(FuriHalSpiBusHandle* handle) {
|
||||
uint8_t status = 0;
|
||||
uint8_t cfg = 0;
|
||||
nrf24_read_reg(handle, REG_CONFIG, &cfg, 1);
|
||||
cfg &= 0xfc; // clear bottom two bits to power down the radio
|
||||
status = nrf24_write_reg(handle, REG_CONFIG, cfg);
|
||||
//nr204_write_reg(handle, REG_EN_RXADDR, 0x0);
|
||||
furi_hal_gpio_write(nrf24_CE_PIN, false);
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t nrf24_set_rx_mode(FuriHalSpiBusHandle* handle) {
|
||||
uint8_t status = 0;
|
||||
uint8_t cfg = 0;
|
||||
//status = nrf24_write_reg(handle, REG_CONFIG, 0x0F); // enable 2-byte CRC, PWR_UP, and PRIM_RX
|
||||
nrf24_read_reg(handle, REG_CONFIG, &cfg, 1);
|
||||
cfg |= 0x03; // PWR_UP, and PRIM_RX
|
||||
status = nrf24_write_reg(handle, REG_CONFIG, cfg);
|
||||
//nr204_write_reg(REG_EN_RXADDR, 0x03) // Set RX Pipe 0 and 1
|
||||
furi_hal_gpio_write(nrf24_CE_PIN, true);
|
||||
furi_delay_ms(2000);
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t nrf24_set_tx_mode(FuriHalSpiBusHandle* handle) {
|
||||
uint8_t status = 0;
|
||||
uint8_t cfg = 0;
|
||||
furi_hal_gpio_write(nrf24_CE_PIN, false);
|
||||
nrf24_write_reg(handle, REG_STATUS, 0x30);
|
||||
//status = nrf24_write_reg(handle, REG_CONFIG, 0x0E); // enable 2-byte CRC, PWR_UP
|
||||
nrf24_read_reg(handle, REG_CONFIG, &cfg, 1);
|
||||
cfg &= 0xfe; // disable PRIM_RX
|
||||
cfg |= 0x02; // PWR_UP
|
||||
status = nrf24_write_reg(handle, REG_CONFIG, cfg);
|
||||
furi_hal_gpio_write(nrf24_CE_PIN, true);
|
||||
furi_delay_ms(2);
|
||||
return status;
|
||||
}
|
||||
|
||||
void nrf24_configure(
|
||||
FuriHalSpiBusHandle* handle,
|
||||
uint8_t rate,
|
||||
uint8_t* srcmac,
|
||||
uint8_t* dstmac,
|
||||
uint8_t maclen,
|
||||
uint8_t channel,
|
||||
bool noack,
|
||||
bool disable_aa) {
|
||||
assert(channel <= 125);
|
||||
assert(rate == 1 || rate == 2);
|
||||
if(rate == 2)
|
||||
rate = 8; // 2Mbps
|
||||
else
|
||||
rate = 0; // 1Mbps
|
||||
|
||||
nrf24_write_reg(handle, REG_CONFIG, 0x00); // Stop nRF
|
||||
nrf24_set_idle(handle);
|
||||
nrf24_write_reg(handle, REG_STATUS, 0x1c); // clear interrupts
|
||||
if(disable_aa)
|
||||
nrf24_write_reg(handle, REG_EN_AA, 0x00); // Disable Shockburst
|
||||
else
|
||||
nrf24_write_reg(handle, REG_EN_AA, 0x1F); // Enable Shockburst
|
||||
|
||||
nrf24_write_reg(handle, REG_DYNPD, 0x3F); // enable dynamic payload length on all pipes
|
||||
if(noack)
|
||||
nrf24_write_reg(handle, REG_FEATURE, 0x05); // disable payload-with-ack, enable noack
|
||||
else {
|
||||
nrf24_write_reg(handle, REG_CONFIG, 0x0C); // 2 byte CRC
|
||||
nrf24_write_reg(handle, REG_FEATURE, 0x07); // enable dyn payload and ack
|
||||
nrf24_write_reg(
|
||||
handle, REG_SETUP_RETR, 0x1f); // 15 retries for AA, 500us auto retransmit delay
|
||||
}
|
||||
|
||||
nrf24_set_idle(handle);
|
||||
nrf24_flush_rx(handle);
|
||||
nrf24_flush_tx(handle);
|
||||
|
||||
if(maclen) nrf24_set_maclen(handle, maclen);
|
||||
if(srcmac) nrf24_set_src_mac(handle, srcmac, maclen);
|
||||
if(dstmac) nrf24_set_dst_mac(handle, dstmac, maclen);
|
||||
|
||||
nrf24_write_reg(handle, REG_RF_CH, channel);
|
||||
nrf24_write_reg(handle, REG_RF_SETUP, rate);
|
||||
furi_delay_ms(200);
|
||||
}
|
||||
|
||||
void nrf24_init_promisc_mode(FuriHalSpiBusHandle* handle, uint8_t channel, uint8_t rate) {
|
||||
//uint8_t preamble[] = {0x55, 0x00}; // little endian
|
||||
uint8_t preamble[] = {0xAA, 0x00}; // little endian
|
||||
//uint8_t preamble[] = {0x00, 0x55}; // little endian
|
||||
//uint8_t preamble[] = {0x00, 0xAA}; // little endian
|
||||
nrf24_write_reg(handle, REG_CONFIG, 0x00); // Stop nRF
|
||||
nrf24_write_reg(handle, REG_STATUS, 0x1c); // clear interrupts
|
||||
nrf24_write_reg(handle, REG_DYNPD, 0x0); // disable shockburst
|
||||
nrf24_write_reg(handle, REG_EN_AA, 0x00); // Disable Shockburst
|
||||
nrf24_write_reg(handle, REG_FEATURE, 0x05); // disable payload-with-ack, enable noack
|
||||
nrf24_set_maclen(handle, 2); // shortest address
|
||||
nrf24_set_src_mac(handle, preamble, 2); // set src mac to preamble bits to catch everything
|
||||
nrf24_set_packetlen(handle, 32); // set max packet length
|
||||
nrf24_set_idle(handle);
|
||||
nrf24_flush_rx(handle);
|
||||
nrf24_flush_tx(handle);
|
||||
nrf24_write_reg(handle, REG_RF_CH, channel);
|
||||
nrf24_write_reg(handle, REG_RF_SETUP, rate);
|
||||
|
||||
// prime for RX, no checksum
|
||||
nrf24_write_reg(handle, REG_CONFIG, 0x03); // PWR_UP and PRIM_RX, disable AA and CRC
|
||||
furi_hal_gpio_write(nrf24_CE_PIN, true);
|
||||
furi_delay_ms(100);
|
||||
}
|
||||
|
||||
void hexlify(uint8_t* in, uint8_t size, char* out) {
|
||||
memset(out, 0, size * 2);
|
||||
for(int i = 0; i < size; i++)
|
||||
snprintf(out + strlen(out), sizeof(out + strlen(out)), "%02X", in[i]);
|
||||
}
|
||||
|
||||
uint64_t bytes_to_int64(uint8_t* bytes, uint8_t size, bool bigendian) {
|
||||
uint64_t ret = 0;
|
||||
for(int i = 0; i < size; i++)
|
||||
if(bigendian)
|
||||
ret |= bytes[i] << ((size - 1 - i) * 8);
|
||||
else
|
||||
ret |= bytes[i] << (i * 8);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void int64_to_bytes(uint64_t val, uint8_t* out, bool bigendian) {
|
||||
for(int i = 0; i < 8; i++) {
|
||||
if(bigendian)
|
||||
out[i] = (val >> ((7 - i) * 8)) & 0xff;
|
||||
else
|
||||
out[i] = (val >> (i * 8)) & 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t bytes_to_int32(uint8_t* bytes, bool bigendian) {
|
||||
uint32_t ret = 0;
|
||||
for(int i = 0; i < 4; i++)
|
||||
if(bigendian)
|
||||
ret |= bytes[i] << ((3 - i) * 8);
|
||||
else
|
||||
ret |= bytes[i] << (i * 8);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void int32_to_bytes(uint32_t val, uint8_t* out, bool bigendian) {
|
||||
for(int i = 0; i < 4; i++) {
|
||||
if(bigendian)
|
||||
out[i] = (val >> ((3 - i) * 8)) & 0xff;
|
||||
else
|
||||
out[i] = (val >> (i * 8)) & 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t bytes_to_int16(uint8_t* bytes, bool bigendian) {
|
||||
uint16_t ret = 0;
|
||||
for(int i = 0; i < 2; i++)
|
||||
if(bigendian)
|
||||
ret |= bytes[i] << ((1 - i) * 8);
|
||||
else
|
||||
ret |= bytes[i] << (i * 8);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void int16_to_bytes(uint16_t val, uint8_t* out, bool bigendian) {
|
||||
for(int i = 0; i < 2; i++) {
|
||||
if(bigendian)
|
||||
out[i] = (val >> ((1 - i) * 8)) & 0xff;
|
||||
else
|
||||
out[i] = (val >> (i * 8)) & 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
// handle iffyness with preamble processing sometimes being a bit (literally) off
|
||||
void alt_address_old(uint8_t* packet, uint8_t* altaddr) {
|
||||
uint8_t macmess_hi_b[4];
|
||||
uint8_t macmess_lo_b[2];
|
||||
uint32_t macmess_hi;
|
||||
uint16_t macmess_lo;
|
||||
uint8_t preserved;
|
||||
|
||||
// get first 6 bytes into 32-bit and 16-bit variables
|
||||
memcpy(macmess_hi_b, packet, 4);
|
||||
memcpy(macmess_lo_b, packet + 4, 2);
|
||||
|
||||
macmess_hi = bytes_to_int32(macmess_hi_b, true);
|
||||
|
||||
//preserve least 7 bits from hi that will be shifted down to lo
|
||||
preserved = macmess_hi & 0x7f;
|
||||
macmess_hi >>= 7;
|
||||
|
||||
macmess_lo = bytes_to_int16(macmess_lo_b, true);
|
||||
macmess_lo >>= 7;
|
||||
macmess_lo = (preserved << 9) | macmess_lo;
|
||||
int32_to_bytes(macmess_hi, macmess_hi_b, true);
|
||||
int16_to_bytes(macmess_lo, macmess_lo_b, true);
|
||||
memcpy(altaddr, &macmess_hi_b[1], 3);
|
||||
memcpy(altaddr + 3, macmess_lo_b, 2);
|
||||
}
|
||||
|
||||
bool validate_address(uint8_t* addr) {
|
||||
uint8_t bad[][3] = {{0x55, 0x55}, {0xAA, 0xAA}, {0x00, 0x00}, {0xFF, 0xFF}};
|
||||
for(int i = 0; i < 4; i++)
|
||||
for(int j = 0; j < 2; j++)
|
||||
if(!memcmp(addr + j * 2, bad[i], 2)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool nrf24_sniff_address(FuriHalSpiBusHandle* handle, uint8_t maclen, uint8_t* address) {
|
||||
bool found = false;
|
||||
uint8_t packet[32] = {0};
|
||||
uint8_t packetsize;
|
||||
//char printit[65];
|
||||
uint8_t status = 0;
|
||||
status = nrf24_rxpacket(handle, packet, &packetsize, true);
|
||||
if(status & 0x40) {
|
||||
if(validate_address(packet)) {
|
||||
for(int i = 0; i < maclen; i++) address[i] = packet[maclen - 1 - i];
|
||||
|
||||
/*
|
||||
alt_address(packet, packet);
|
||||
|
||||
for(i = 0; i < maclen; i++)
|
||||
address[i + 5] = packet[maclen - 1 - i];
|
||||
*/
|
||||
|
||||
//memcpy(address, packet, maclen);
|
||||
//hexlify(packet, packetsize, printit);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
uint8_t nrf24_find_channel(
|
||||
FuriHalSpiBusHandle* handle,
|
||||
uint8_t* srcmac,
|
||||
uint8_t* dstmac,
|
||||
uint8_t maclen,
|
||||
uint8_t rate,
|
||||
uint8_t min_channel,
|
||||
uint8_t max_channel,
|
||||
bool autoinit) {
|
||||
uint8_t ping_packet[] = {0x0f, 0x0f, 0x0f, 0x0f}; // this can be anything, we just need an ack
|
||||
uint8_t ch = max_channel + 1; // means fail
|
||||
nrf24_configure(handle, rate, srcmac, dstmac, maclen, 2, false, false);
|
||||
for(ch = min_channel; ch <= max_channel + 1; ch++) {
|
||||
nrf24_write_reg(handle, REG_RF_CH, ch);
|
||||
if(nrf24_txpacket(handle, ping_packet, 4, true)) break;
|
||||
}
|
||||
|
||||
if(autoinit) {
|
||||
FURI_LOG_D("nrf24", "initializing radio for channel %d", ch);
|
||||
nrf24_configure(handle, rate, srcmac, dstmac, maclen, ch, false, false);
|
||||
return ch;
|
||||
}
|
||||
|
||||
return ch;
|
||||
}
|
||||
366
applications/plugins/nrfsniff/lib/nrf24/nrf24.h
Normal file
366
applications/plugins/nrfsniff/lib/nrf24/nrf24.h
Normal file
@@ -0,0 +1,366 @@
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <furi_hal_spi.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define R_REGISTER 0x00
|
||||
#define W_REGISTER 0x20
|
||||
#define REGISTER_MASK 0x1F
|
||||
#define ACTIVATE 0x50
|
||||
#define R_RX_PL_WID 0x60
|
||||
#define R_RX_PAYLOAD 0x61
|
||||
#define W_TX_PAYLOAD 0xA0
|
||||
#define W_TX_PAYLOAD_NOACK 0xB0
|
||||
#define W_ACK_PAYLOAD 0xA8
|
||||
#define FLUSH_TX 0xE1
|
||||
#define FLUSH_RX 0xE2
|
||||
#define REUSE_TX_PL 0xE3
|
||||
#define RF24_NOP 0xFF
|
||||
|
||||
#define REG_CONFIG 0x00
|
||||
#define REG_EN_AA 0x01
|
||||
#define REG_EN_RXADDR 0x02
|
||||
#define REG_SETUP_AW 0x03
|
||||
#define REG_SETUP_RETR 0x04
|
||||
#define REG_DYNPD 0x1C
|
||||
#define REG_FEATURE 0x1D
|
||||
#define REG_RF_SETUP 0x06
|
||||
#define REG_STATUS 0x07
|
||||
#define REG_RX_ADDR_P0 0x0A
|
||||
#define REG_RF_CH 0x05
|
||||
#define REG_TX_ADDR 0x10
|
||||
|
||||
#define RX_PW_P0 0x11
|
||||
#define TX_DS 0x20
|
||||
#define MAX_RT 0x10
|
||||
|
||||
#define nrf24_TIMEOUT 500
|
||||
#define nrf24_CE_PIN &gpio_ext_pb2
|
||||
#define nrf24_HANDLE &furi_hal_spi_bus_handle_external
|
||||
|
||||
/* Low level API */
|
||||
|
||||
/** Write device register
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
* @param reg - register
|
||||
* @param data - data to write
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t nrf24_write_reg(FuriHalSpiBusHandle* handle, uint8_t reg, uint8_t data);
|
||||
|
||||
/** Write buffer to device register
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
* @param reg - register
|
||||
* @param data - data to write
|
||||
* @param size - size of data to write
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t nrf24_write_buf_reg(FuriHalSpiBusHandle* handle, uint8_t reg, uint8_t* data, uint8_t size);
|
||||
|
||||
/** Read device register
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
* @param reg - register
|
||||
* @param[out] data - pointer to data
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t nrf24_read_reg(FuriHalSpiBusHandle* handle, uint8_t reg, uint8_t* data, uint8_t size);
|
||||
|
||||
/** Power up the radio for operation
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t nrf24_power_up(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Power down the radio
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t nrf24_set_idle(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Sets the radio to RX mode
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t nrf24_set_rx_mode(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Sets the radio to TX mode
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t nrf24_set_tx_mode(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/*=============================================================================================================*/
|
||||
|
||||
/* High level API */
|
||||
|
||||
/** Must call this before using any other nrf24 API
|
||||
*
|
||||
*/
|
||||
void nrf24_init();
|
||||
|
||||
/** Must call this when we end using nrf24 device
|
||||
*
|
||||
*/
|
||||
void nrf24_deinit();
|
||||
|
||||
/** Send flush rx command
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t nrf24_flush_rx(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Send flush tx command
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t nrf24_flush_tx(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Gets the RX packet length in data pipe 0
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*
|
||||
* @return packet length in data pipe 0
|
||||
*/
|
||||
uint8_t nrf24_get_packetlen(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Sets the RX packet length in data pipe 0
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
* @param len - length to set
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t nrf24_set_packetlen(FuriHalSpiBusHandle* handle, uint8_t len);
|
||||
|
||||
/** Gets configured length of MAC address
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*
|
||||
* @return MAC address length
|
||||
*/
|
||||
uint8_t nrf24_get_maclen(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Sets configured length of MAC address
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
* @param maclen - length to set MAC address to, must be greater than 1 and less than 6
|
||||
*
|
||||
* @return MAC address length
|
||||
*/
|
||||
uint8_t nrf24_set_maclen(FuriHalSpiBusHandle* handle, uint8_t maclen);
|
||||
|
||||
/** Gets the current status flags from the STATUS register
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*
|
||||
* @return status flags
|
||||
*/
|
||||
uint8_t nrf24_status(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Gets the current transfer rate
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*
|
||||
* @return transfer rate in bps
|
||||
*/
|
||||
uint32_t nrf24_get_rate(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Sets the transfer rate
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
* @param rate - the transfer rate in bps
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t nrf24_set_rate(FuriHalSpiBusHandle* handle, uint32_t rate);
|
||||
|
||||
/** Gets the current channel
|
||||
* In nrf24, the channel number is multiplied times 1MHz and added to 2400MHz to get the frequency
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*
|
||||
* @return channel
|
||||
*/
|
||||
uint8_t nrf24_get_chan(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Sets the channel
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
* @param frequency - the frequency in hertz
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t nrf24_set_chan(FuriHalSpiBusHandle* handle, uint8_t chan);
|
||||
|
||||
/** Gets the source mac address
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
* @param[out] mac - the source mac address
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t nrf24_get_src_mac(FuriHalSpiBusHandle* handle, uint8_t* mac);
|
||||
|
||||
/** Sets the source mac address
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
* @param mac - the mac address to set
|
||||
* @param size - the size of the mac address (2 to 5)
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t nrf24_set_src_mac(FuriHalSpiBusHandle* handle, uint8_t* mac, uint8_t size);
|
||||
|
||||
/** Gets the dest mac address
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
* @param[out] mac - the source mac address
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t nrf24_get_dst_mac(FuriHalSpiBusHandle* handle, uint8_t* mac);
|
||||
|
||||
/** Sets the dest mac address
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
* @param mac - the mac address to set
|
||||
* @param size - the size of the mac address (2 to 5)
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t nrf24_set_dst_mac(FuriHalSpiBusHandle* handle, uint8_t* mac, uint8_t size);
|
||||
|
||||
/** Reads RX packet
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
* @param[out] packet - the packet contents
|
||||
* @param[out] packetsize - size of the received packet
|
||||
* @param full - boolean set to true, packet length is determined by RX_PW_P0 register, false it is determined by dynamic payload length command
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t
|
||||
nrf24_rxpacket(FuriHalSpiBusHandle* handle, uint8_t* packet, uint8_t* packetsize, bool full);
|
||||
|
||||
/** Sends TX packet
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
* @param packet - the packet contents
|
||||
* @param size - packet size
|
||||
* @param ack - boolean to determine whether an ACK is required for the packet or not
|
||||
*
|
||||
* @return device status
|
||||
*/
|
||||
uint8_t nrf24_txpacket(FuriHalSpiBusHandle* handle, uint8_t* payload, uint8_t size, bool ack);
|
||||
|
||||
/** Configure the radio
|
||||
* This is not comprehensive, but covers a lot of the common configuration options that may be changed
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
* @param rate - transfer rate in Mbps (1 or 2)
|
||||
* @param srcmac - source mac address
|
||||
* @param dstmac - destination mac address
|
||||
* @param maclen - length of mac address
|
||||
* @param channel - channel to tune to
|
||||
* @param noack - if true, disable auto-acknowledge
|
||||
* @param disable_aa - if true, disable ShockBurst
|
||||
*
|
||||
*/
|
||||
void nrf24_configure(
|
||||
FuriHalSpiBusHandle* handle,
|
||||
uint8_t rate,
|
||||
uint8_t* srcmac,
|
||||
uint8_t* dstmac,
|
||||
uint8_t maclen,
|
||||
uint8_t channel,
|
||||
bool noack,
|
||||
bool disable_aa);
|
||||
|
||||
/** Configures the radio for "promiscuous mode" and primes it for rx
|
||||
* This is not an actual mode of the nrf24, but this function exploits a few bugs in the chip that allows it to act as if it were.
|
||||
* See http://travisgoodspeed.blogspot.com/2011/02/promiscuity-is-nrf24l01s-duty.html for details.
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
* @param channel - channel to tune to
|
||||
* @param rate - transfer rate in Mbps (1 or 2)
|
||||
*/
|
||||
void nrf24_init_promisc_mode(FuriHalSpiBusHandle* handle, uint8_t channel, uint8_t rate);
|
||||
|
||||
/** Listens for a packet and returns first possible address sniffed
|
||||
* Call this only after calling nrf24_init_promisc_mode
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
* @param maclen - length of target mac address
|
||||
* @param[out] addresses - sniffed address
|
||||
*
|
||||
* @return success
|
||||
*/
|
||||
bool nrf24_sniff_address(FuriHalSpiBusHandle* handle, uint8_t maclen, uint8_t* address);
|
||||
|
||||
/** Sends ping packet on each channel for designated tx mac looking for ack
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
* @param srcmac - source address
|
||||
* @param dstmac - destination address
|
||||
* @param maclen - length of address
|
||||
* @param rate - transfer rate in Mbps (1 or 2)
|
||||
* @param min_channel - channel to start with
|
||||
* @param max_channel - channel to end at
|
||||
* @param autoinit - if true, automatically configure radio for this channel
|
||||
*
|
||||
* @return channel that the address is listening on, if this value is above the max_channel param, it failed
|
||||
*/
|
||||
uint8_t nrf24_find_channel(
|
||||
FuriHalSpiBusHandle* handle,
|
||||
uint8_t* srcmac,
|
||||
uint8_t* dstmac,
|
||||
uint8_t maclen,
|
||||
uint8_t rate,
|
||||
uint8_t min_channel,
|
||||
uint8_t max_channel,
|
||||
bool autoinit);
|
||||
|
||||
/** Converts 64 bit value into uint8_t array
|
||||
* @param val - 64-bit integer
|
||||
* @param[out] out - bytes out
|
||||
* @param bigendian - if true, convert as big endian, otherwise little endian
|
||||
*/
|
||||
void int64_to_bytes(uint64_t val, uint8_t* out, bool bigendian);
|
||||
|
||||
/** Converts 32 bit value into uint8_t array
|
||||
* @param val - 32-bit integer
|
||||
* @param[out] out - bytes out
|
||||
* @param bigendian - if true, convert as big endian, otherwise little endian
|
||||
*/
|
||||
void int32_to_bytes(uint32_t val, uint8_t* out, bool bigendian);
|
||||
|
||||
/** Converts uint8_t array into 32 bit value
|
||||
* @param bytes - uint8_t array
|
||||
* @param bigendian - if true, convert as big endian, otherwise little endian
|
||||
*
|
||||
* @return 32-bit value
|
||||
*/
|
||||
uint32_t bytes_to_int32(uint8_t* bytes, bool bigendian);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -61,6 +61,6 @@ OKLABEL: Garage CLOSE
|
||||
|
||||
* ##### Universal RF Map
|
||||
- File path should not have any spaces or special characters (- and _ excluded).
|
||||
- Labels are limited to 12 characters.
|
||||
- Labels are limited to 16 characters.
|
||||
- Why? This is to prevent overlapping elements on screen.
|
||||
- For example: If you set your label or file to ```WWWWWWWWWWWWWWW``` you'll be over the screen limits.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
entry,status,name,type,params
|
||||
Version,+,8.42,,
|
||||
Version,+,7.32,,
|
||||
Header,+,applications/services/bt/bt_service/bt.h,,
|
||||
Header,+,applications/services/cli/cli.h,,
|
||||
Header,+,applications/services/cli/cli_vcp.h,,
|
||||
@@ -111,7 +111,6 @@ Header,+,lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Inc/stm32wbxx_ll_utils.h,,
|
||||
Header,+,lib/STM32CubeWB/Drivers/STM32WBxx_HAL_Driver/Inc/stm32wbxx_ll_wwdg.h,,
|
||||
Header,-,lib/STM32CubeWB/Middlewares/Third_Party/FreeRTOS/Source/include/FreeRTOS.h,,
|
||||
Header,+,lib/STM32CubeWB/Middlewares/Third_Party/FreeRTOS/Source/include/stream_buffer.h,,
|
||||
Header,+,lib/drivers/nrf24.h,,
|
||||
Header,+,lib/flipper_application/flipper_application.h,,
|
||||
Header,+,lib/flipper_format/flipper_format.h,,
|
||||
Header,+,lib/flipper_format/flipper_format_i.h,,
|
||||
@@ -596,7 +595,6 @@ Function,+,byte_input_free,void,ByteInput*
|
||||
Function,+,byte_input_get_view,View*,ByteInput*
|
||||
Function,+,byte_input_set_header_text,void,"ByteInput*, const char*"
|
||||
Function,+,byte_input_set_result_callback,void,"ByteInput*, ByteInputCallback, ByteChangedCallback, void*, uint8_t*, uint8_t"
|
||||
Function,+,bytes_to_int32,uint32_t,"uint8_t*, _Bool"
|
||||
Function,-,bzero,void,"void*, size_t"
|
||||
Function,-,calloc,void*,"size_t, size_t"
|
||||
Function,+,canvas_clear,void,Canvas*
|
||||
@@ -1653,8 +1651,6 @@ Function,+,init_mutex,_Bool,"ValueMutex*, void*, size_t"
|
||||
Function,-,initstate,char*,"unsigned, char*, size_t"
|
||||
Function,+,input_get_key_name,const char*,InputKey
|
||||
Function,+,input_get_type_name,const char*,InputType
|
||||
Function,+,int32_to_bytes,void,"uint32_t, uint8_t*, _Bool"
|
||||
Function,-,int64_to_bytes,void,"uint64_t, uint8_t*, _Bool"
|
||||
Function,-,iprintf,int,"const char*, ..."
|
||||
Function,-,isalnum,int,int
|
||||
Function,-,isalnum_l,int,"int, locale_t"
|
||||
@@ -2017,36 +2013,6 @@ Function,+,notification_internal_message_block,void,"NotificationApp*, const Not
|
||||
Function,+,notification_message,void,"NotificationApp*, const NotificationSequence*"
|
||||
Function,+,notification_message_block,void,"NotificationApp*, const NotificationSequence*"
|
||||
Function,-,nrand48,long,unsigned short[3]
|
||||
Function,-,nrf24_configure,void,"FuriHalSpiBusHandle*, uint8_t, uint8_t*, uint8_t*, uint8_t, uint8_t, _Bool, _Bool"
|
||||
Function,+,nrf24_deinit,void,
|
||||
Function,+,nrf24_find_channel,uint8_t,"FuriHalSpiBusHandle*, uint8_t*, uint8_t*, uint8_t, uint8_t, uint8_t, uint8_t, _Bool"
|
||||
Function,-,nrf24_flush_rx,uint8_t,FuriHalSpiBusHandle*
|
||||
Function,-,nrf24_flush_tx,uint8_t,FuriHalSpiBusHandle*
|
||||
Function,-,nrf24_get_chan,uint8_t,FuriHalSpiBusHandle*
|
||||
Function,-,nrf24_get_dst_mac,uint8_t,"FuriHalSpiBusHandle*, uint8_t*"
|
||||
Function,-,nrf24_get_maclen,uint8_t,FuriHalSpiBusHandle*
|
||||
Function,-,nrf24_get_packetlen,uint8_t,FuriHalSpiBusHandle*
|
||||
Function,-,nrf24_get_rate,uint32_t,FuriHalSpiBusHandle*
|
||||
Function,-,nrf24_get_src_mac,uint8_t,"FuriHalSpiBusHandle*, uint8_t*"
|
||||
Function,+,nrf24_init,void,
|
||||
Function,+,nrf24_init_promisc_mode,void,"FuriHalSpiBusHandle*, uint8_t, uint8_t"
|
||||
Function,-,nrf24_power_up,uint8_t,FuriHalSpiBusHandle*
|
||||
Function,-,nrf24_read_reg,uint8_t,"FuriHalSpiBusHandle*, uint8_t, uint8_t*, uint8_t"
|
||||
Function,-,nrf24_rxpacket,uint8_t,"FuriHalSpiBusHandle*, uint8_t*, uint8_t*, _Bool"
|
||||
Function,-,nrf24_set_chan,uint8_t,"FuriHalSpiBusHandle*, uint8_t"
|
||||
Function,-,nrf24_set_dst_mac,uint8_t,"FuriHalSpiBusHandle*, uint8_t*, uint8_t"
|
||||
Function,+,nrf24_set_idle,uint8_t,FuriHalSpiBusHandle*
|
||||
Function,-,nrf24_set_maclen,uint8_t,"FuriHalSpiBusHandle*, uint8_t"
|
||||
Function,-,nrf24_set_packetlen,uint8_t,"FuriHalSpiBusHandle*, uint8_t"
|
||||
Function,-,nrf24_set_rate,uint8_t,"FuriHalSpiBusHandle*, uint32_t"
|
||||
Function,-,nrf24_set_rx_mode,uint8_t,FuriHalSpiBusHandle*
|
||||
Function,+,nrf24_set_src_mac,uint8_t,"FuriHalSpiBusHandle*, uint8_t*, uint8_t"
|
||||
Function,-,nrf24_set_tx_mode,uint8_t,FuriHalSpiBusHandle*
|
||||
Function,+,nrf24_sniff_address,_Bool,"FuriHalSpiBusHandle*, uint8_t, uint8_t*"
|
||||
Function,-,nrf24_status,uint8_t,FuriHalSpiBusHandle*
|
||||
Function,+,nrf24_txpacket,uint8_t,"FuriHalSpiBusHandle*, uint8_t*, uint8_t, _Bool"
|
||||
Function,-,nrf24_write_buf_reg,uint8_t,"FuriHalSpiBusHandle*, uint8_t, uint8_t*, uint8_t"
|
||||
Function,-,nrf24_write_reg,uint8_t,"FuriHalSpiBusHandle*, uint8_t, uint8_t"
|
||||
Function,-,on_exit,int,"void (*)(int, void*), void*"
|
||||
Function,+,onewire_device_alloc,OneWireDevice*,"uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t"
|
||||
Function,+,onewire_device_attach,void,"OneWireDevice*, OneWireSlave*"
|
||||
@@ -2137,8 +2103,8 @@ Function,+,protocol_dict_get_manufacturer,const char*,"ProtocolDict*, size_t"
|
||||
Function,+,protocol_dict_get_max_data_size,size_t,ProtocolDict*
|
||||
Function,+,protocol_dict_get_name,const char*,"ProtocolDict*, size_t"
|
||||
Function,+,protocol_dict_get_protocol_by_name,ProtocolId,"ProtocolDict*, const char*"
|
||||
Function,-,protocol_dict_get_validate_count,uint32_t,"ProtocolDict*, size_t"
|
||||
Function,-,protocol_dict_get_write_data,_Bool,"ProtocolDict*, size_t, void*"
|
||||
Function,+,protocol_dict_get_validate_count,uint32_t,"ProtocolDict*, size_t"
|
||||
Function,+,protocol_dict_get_write_data,_Bool,"ProtocolDict*, size_t, void*"
|
||||
Function,+,protocol_dict_render_brief_data,void,"ProtocolDict*, FuriString*, size_t"
|
||||
Function,+,protocol_dict_render_data,void,"ProtocolDict*, FuriString*, size_t"
|
||||
Function,+,protocol_dict_set_data,void,"ProtocolDict*, size_t, const uint8_t*, size_t"
|
||||
|
||||
|
@@ -4,9 +4,6 @@ env.Append(
|
||||
CPPPATH=[
|
||||
"#/lib/drivers",
|
||||
],
|
||||
SDK_HEADERS=[
|
||||
File("nrf24.h"),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user