mirror of
https://github.com/greatscottgadgets/hackrf.git
synced 2026-03-22 23:27:34 +01:00
Add USB vendor request to read M0 state, and host support for doing so.
This adds a `hackrf_debug [-S|--state]` option, and the necessary plumbing to libhackrf and the M4 firmware to support it. The USB API and libhackrf versions are bumped to reflect the changes.
This commit is contained in:
@@ -377,6 +377,12 @@ int write_register(hackrf_device* device, uint8_t part,
|
||||
return HACKRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
static void print_state(hackrf_m0_state *state) {
|
||||
printf("M0 state:\n");
|
||||
printf("Offset: %u bytes\n", state->offset);
|
||||
printf("TX: %u\n", state->tx);
|
||||
}
|
||||
|
||||
static void usage() {
|
||||
printf("\nUsage:\n");
|
||||
printf("\t-h, --help: this help\n");
|
||||
@@ -388,12 +394,14 @@ static void usage() {
|
||||
printf("\t-m, --max2837: target MAX2837\n");
|
||||
printf("\t-s, --si5351c: target SI5351C\n");
|
||||
printf("\t-f, --rffc5072: target RFFC5072\n");
|
||||
printf("\t-S, --state: display M0 state\n");
|
||||
printf("\t-u, --ui <1/0>: enable/disable UI\n");
|
||||
printf("\nExamples:\n");
|
||||
printf("\thackrf_debug --si5351c -n 0 -r # reads from si5351c register 0\n");
|
||||
printf("\thackrf_debug --si5351c -c # displays si5351c multisynth configuration\n");
|
||||
printf("\thackrf_debug --rffc5072 -r # reads all rffc5072 registers\n");
|
||||
printf("\thackrf_debug --max2837 -n 10 -w 22 # writes max2837 register 10 with 22 decimal\n");
|
||||
printf("\thackrf_debug --state # displays M0 state\n");
|
||||
}
|
||||
|
||||
static struct option long_options[] = {
|
||||
@@ -406,6 +414,7 @@ static struct option long_options[] = {
|
||||
{ "max2837", no_argument, 0, 'm' },
|
||||
{ "si5351c", no_argument, 0, 's' },
|
||||
{ "rffc5072", no_argument, 0, 'f' },
|
||||
{ "state", no_argument, 0, 'S' },
|
||||
{ "ui", required_argument, 0, 'u' },
|
||||
{ 0, 0, 0, 0 },
|
||||
};
|
||||
@@ -419,6 +428,7 @@ int main(int argc, char** argv) {
|
||||
bool read = false;
|
||||
bool write = false;
|
||||
bool dump_config = false;
|
||||
bool dump_state = false;
|
||||
uint8_t part = PART_NONE;
|
||||
const char* serial_number = NULL;
|
||||
bool set_ui = false;
|
||||
@@ -430,7 +440,7 @@ int main(int argc, char** argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
while( (opt = getopt_long(argc, argv, "n:rw:d:cmsfh?u:", long_options, &option_index)) != EOF ) {
|
||||
while( (opt = getopt_long(argc, argv, "n:rw:d:cmsfSh?u:", long_options, &option_index)) != EOF ) {
|
||||
switch( opt ) {
|
||||
case 'n':
|
||||
result = parse_int(optarg, ®ister_number);
|
||||
@@ -449,6 +459,10 @@ int main(int argc, char** argv) {
|
||||
dump_config = true;
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
dump_state = true;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
serial_number = optarg;
|
||||
break;
|
||||
@@ -517,13 +531,13 @@ int main(int argc, char** argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(!(write || read || dump_config || set_ui)) {
|
||||
if(!(write || read || dump_config || dump_state || set_ui)) {
|
||||
fprintf(stderr, "Specify read, write, or config option.\n");
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(part == PART_NONE && !set_ui) {
|
||||
if(part == PART_NONE && !set_ui && !dump_state) {
|
||||
fprintf(stderr, "Specify a part to read, write, or print config from.\n");
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
@@ -551,6 +565,16 @@ int main(int argc, char** argv) {
|
||||
si5351c_read_configuration(device);
|
||||
}
|
||||
|
||||
if(dump_state) {
|
||||
hackrf_m0_state state;
|
||||
result = hackrf_get_m0_state(device, &state);
|
||||
if(result != HACKRF_SUCCESS) {
|
||||
printf("hackrf_get_m0_state() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
print_state(&state);
|
||||
}
|
||||
|
||||
if(set_ui) {
|
||||
result = hackrf_set_ui_enable(device, ui_enable);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user