Просмотр исходного кода

Squashed 'i2ctools/' changes from 51e0d451e..e28c07ed3

e28c07ed3 move base pack here
REVERT: 51e0d451e Update changelog
REVERT: 3410a572d update app version
REVERT: bf4763311 Add infos view
REVERT: 8903390fe Update README
REVERT: 5c503c9b4 Add needed files for Flipper Application Catalog
REVERT: 08db98abc Create LICENSE
REVERT: a35ba703a change appid to new naming convention
REVERT: 3315c3279 Merge pull request #4 from Samuelrmlink/main
REVERT: 2711e8b7d Updated FlipperAppType
REVERT: 2d1d15156 Updated to use the newer Furi mutex api.
REVERT: 70ec58be2 Update readme
REVERT: a52df9e49 Rewording and fix down event type bug
REVERT: 02305cbb3 remade send view and remove unused icons
REVERT: a17f2a4a3 remade sniffer view
REVERT: 279d19e1f New main icon
REVERT: b3c662a50 Improve UI
REVERT: e12ba0046 made mistake parsing 7bit addresses
REVERT: b8a62a302 increase records limit
REVERT: 90fd1ae8e print more than 2 frames
REVERT: 167914c2e icons update
REVERT: f7c04a646 Better Menu organisation
REVERT: d34e26729 Reset GPIO pins to default state
REVERT: 6aab68d45 Share scanner with sender
REVERT: 31ba88244 Fix missing free
REVERT: 351941d8d update Todo list
REVERT: 62eceae2c Make sender a lib
REVERT: 5a99abbfb Make a lib for the scanner
REVERT: 7c3ef280b Use sniffer alloc and free
REVERT: 412a017af Remove useless "pragma once"
REVERT: 8c47c3398 make code more "furi styled"
REVERT: 2870da3b5 One tool, one file
REVERT: ce5510d50 Remove pulseview files
REVERT: 6db20acda Remove unused stuff
REVERT: 1ac288cc0 Reword for better readability
REVERT: 8baa063f7 Add Readme
REVERT: 381868475 Add sender view
REVERT: dc124f099 Fix Sniffer tool
REVERT: 3cd1fb117 Remove unused png
REVERT: 58f0763db Initial commit
REVERT: d9089be7b Initial commit

git-subtree-dir: i2ctools
git-subtree-split: e28c07ed385c8338823bc4ac6e48219415029f52
Willy-JL 2 лет назад
Родитель
Сommit
0b553db497

+ 0 - 0
.gitignore


+ 6 - 6
README.md

@@ -1,5 +1,6 @@
 # flipperzero-i2ctools
 
+[Original link](https://github.com/NaejEL/flipperzero-i2ctools)
 Set of i2c tools for Flipper Zero
 
 ![Preview](i2ctools.gif)
@@ -29,16 +30,15 @@ Spy i2c traffic
 Send command to i2c peripherals and read result 
 
 ## TODO
-- [ ] Kicad module
-- [ ] Improve UI
-- [ ] Refactor Event Management Code
-- [ ] Add Documentation
 
-## V2
 - [ ] Read more than 2 bytes in sender mode
 - [ ] Add 10-bits adresses support
 - [ ] Test with rate > 100khz
-- [ ] Save records (Sigrok compatible?)
+- [ ] Save records
 - [ ] Play from files
+- [ ] Kicad module
+- [ ] Improve UI
+- [ ] Refactor Event Management Code
+- [ ] Add Documentation
 - [ ] Remove max data size
 - [ ] Remove max frames read size

+ 2 - 3
application.fam

@@ -1,9 +1,8 @@
 App(
     appid="i2ctools",
-    name="i2c Tools",
+    name="[GPIO] i2c Tools",
     apptype=FlipperAppType.EXTERNAL,
     entry_point="i2ctools_app",
-    cdefines=["APP_I2CTOOLS"],
     requires=["gui"],
     stack_size=2 * 1024,
     order=175,
@@ -13,4 +12,4 @@ App(
     fap_author="@NaejEL",
     fap_version="1.1",
     fap_description="Set of i2c tools",
-)
+)

+ 0 - 7
docs/README.md

@@ -1,7 +0,0 @@
-## i2c Tools for Flipper Zero
-
-Set of i2c tools for Flipper Zero
-
-## Support
-
-For app feedback, bugs, and feature requests, please create an issue here: https://https://github.com/NaejEL/flipperzero-i2ctools/issues

+ 0 - 7
docs/changelog.md

@@ -1,7 +0,0 @@
-## v1.1
-
-Add infos screen
-
-## v1.0
-
-Initial release for Flipper Application Catalog

+ 138 - 131
i2ctools.c

@@ -1,10 +1,9 @@
 #include "i2ctools_i.h"
 
 void i2ctools_draw_callback(Canvas* canvas, void* ctx) {
+    furi_assert(ctx);
     i2cTools* i2ctools = ctx;
-    if(furi_mutex_acquire(i2ctools->mutex, 200) != FuriStatusOk) {
-        return;
-    }
+    furi_mutex_acquire(i2ctools->mutex, FuriWaitForever);
 
     switch(i2ctools->main_view->current_view) {
     case MAIN_VIEW:
@@ -46,6 +45,11 @@ int32_t i2ctools_app(void* p) {
     // Alloc i2ctools
     i2cTools* i2ctools = malloc(sizeof(i2cTools));
     i2ctools->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
+    if(!i2ctools->mutex) {
+        FURI_LOG_E(APP_NAME, "cannot create mutex\r\n");
+        free(i2ctools);
+        return -1;
+    }
 
     // Alloc viewport
     i2ctools->view_port = view_port_alloc();
@@ -69,143 +73,145 @@ int32_t i2ctools_app(void* p) {
     // Share scanner with sender
     i2ctools->sender->scanner = i2ctools->scanner;
 
-    while(furi_message_queue_get(event_queue, &event, FuriWaitForever) == FuriStatusOk) {
-        // Back
-        if(event.key == InputKeyBack && event.type == InputTypeRelease) {
-            if(i2ctools->main_view->current_view == MAIN_VIEW) {
-                break;
-            } else {
-                if(i2ctools->main_view->current_view == SNIFF_VIEW) {
-                    stop_interrupts();
-                    i2ctools->sniffer->started = false;
-                    i2ctools->sniffer->state = I2C_BUS_FREE;
-                }
-                i2ctools->main_view->current_view = MAIN_VIEW;
-            }
-        }
-        // Up
-        else if(event.key == InputKeyUp && event.type == InputTypeRelease) {
-            if(i2ctools->main_view->current_view == MAIN_VIEW) {
-                if((i2ctools->main_view->menu_index > SCAN_VIEW)) {
-                    i2ctools->main_view->menu_index--;
-                }
-            } else if(i2ctools->main_view->current_view == SCAN_VIEW) {
-                if(i2ctools->scanner->menu_index > 0) {
-                    i2ctools->scanner->menu_index--;
-                }
-            } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
-                if(i2ctools->sniffer->row_index > 0) {
-                    i2ctools->sniffer->row_index--;
-                }
-            } else if(i2ctools->main_view->current_view == SEND_VIEW) {
-                if(i2ctools->sender->value < 0xFF) {
-                    i2ctools->sender->value++;
-                    i2ctools->sender->sended = false;
-                }
-            }
-        }
-        // Long Up
-        else if(
-            event.key == InputKeyUp &&
-            (event.type == InputTypeLong || event.type == InputTypeRepeat)) {
-            if(i2ctools->main_view->current_view == SCAN_VIEW) {
-                if(i2ctools->scanner->menu_index > 5) {
-                    i2ctools->scanner->menu_index -= 5;
-                }
-            } else if(i2ctools->main_view->current_view == SEND_VIEW) {
-                if(i2ctools->sender->value < 0xF9) {
-                    i2ctools->sender->value += 5;
-                    i2ctools->sender->sended = false;
-                }
-            } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
-                if(i2ctools->sniffer->row_index > 5) {
-                    i2ctools->sniffer->row_index -= 5;
+    while(1) {
+        if(furi_message_queue_get(event_queue, &event, 100) == FuriStatusOk) {
+            // Back
+            if(event.key == InputKeyBack && event.type == InputTypeRelease) {
+                if(i2ctools->main_view->current_view == MAIN_VIEW) {
+                    break;
                 } else {
-                    i2ctools->sniffer->row_index = 0;
+                    if(i2ctools->main_view->current_view == SNIFF_VIEW) {
+                        stop_interrupts();
+                        i2ctools->sniffer->started = false;
+                        i2ctools->sniffer->state = I2C_BUS_FREE;
+                    }
+                    i2ctools->main_view->current_view = MAIN_VIEW;
                 }
             }
-        }
-        // Down
-        else if(event.key == InputKeyDown && event.type == InputTypeRelease) {
-            if(i2ctools->main_view->current_view == MAIN_VIEW) {
-                if(i2ctools->main_view->menu_index < MENU_SIZE - 1) {
-                    i2ctools->main_view->menu_index++;
-                }
-            } else if(i2ctools->main_view->current_view == SCAN_VIEW) {
-                if(i2ctools->scanner->menu_index < ((int)i2ctools->scanner->nb_found / 3)) {
-                    i2ctools->scanner->menu_index++;
-                }
-            } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
-                if((i2ctools->sniffer->row_index + 3) <
-                   (int)i2ctools->sniffer->frames[i2ctools->sniffer->menu_index].data_index) {
-                    i2ctools->sniffer->row_index++;
-                }
-            } else if(i2ctools->main_view->current_view == SEND_VIEW) {
-                if(i2ctools->sender->value > 0x00) {
-                    i2ctools->sender->value--;
-                    i2ctools->sender->sended = false;
+            // Up
+            else if(event.key == InputKeyUp && event.type == InputTypeRelease) {
+                if(i2ctools->main_view->current_view == MAIN_VIEW) {
+                    if((i2ctools->main_view->menu_index > SCAN_VIEW)) {
+                        i2ctools->main_view->menu_index--;
+                    }
+                } else if(i2ctools->main_view->current_view == SCAN_VIEW) {
+                    if(i2ctools->scanner->menu_index > 0) {
+                        i2ctools->scanner->menu_index--;
+                    }
+                } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
+                    if(i2ctools->sniffer->row_index > 0) {
+                        i2ctools->sniffer->row_index--;
+                    }
+                } else if(i2ctools->main_view->current_view == SEND_VIEW) {
+                    if(i2ctools->sender->value < 0xFF) {
+                        i2ctools->sender->value++;
+                        i2ctools->sender->sended = false;
+                    }
                 }
             }
-        }
-        // Long Down
-        else if(
-            event.key == InputKeyDown &&
-            (event.type == InputTypeLong || event.type == InputTypeRepeat)) {
-            if(i2ctools->main_view->current_view == SEND_VIEW) {
-                if(i2ctools->sender->value > 0x05) {
-                    i2ctools->sender->value -= 5;
-                    i2ctools->sender->sended = false;
-                } else {
-                    i2ctools->sender->value = 0;
-                    i2ctools->sender->sended = false;
-                }
-            } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
-                if((i2ctools->sniffer->row_index + 8) <
-                   (int)i2ctools->sniffer->frames[i2ctools->sniffer->menu_index].data_index) {
-                    i2ctools->sniffer->row_index += 5;
+            // Long Up
+            else if(
+                event.key == InputKeyUp &&
+                (event.type == InputTypeLong || event.type == InputTypeRepeat)) {
+                if(i2ctools->main_view->current_view == SCAN_VIEW) {
+                    if(i2ctools->scanner->menu_index > 5) {
+                        i2ctools->scanner->menu_index -= 5;
+                    }
+                } else if(i2ctools->main_view->current_view == SEND_VIEW) {
+                    if(i2ctools->sender->value < 0xF9) {
+                        i2ctools->sender->value += 5;
+                        i2ctools->sender->sended = false;
+                    }
+                } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
+                    if(i2ctools->sniffer->row_index > 5) {
+                        i2ctools->sniffer->row_index -= 5;
+                    } else {
+                        i2ctools->sniffer->row_index = 0;
+                    }
                 }
             }
-
-        } else if(event.key == InputKeyOk && event.type == InputTypeRelease) {
-            if(i2ctools->main_view->current_view == MAIN_VIEW) {
-                i2ctools->main_view->current_view = i2ctools->main_view->menu_index;
-            } else if(i2ctools->main_view->current_view == SCAN_VIEW) {
-                scan_i2c_bus(i2ctools->scanner);
-            } else if(i2ctools->main_view->current_view == SEND_VIEW) {
-                i2ctools->sender->must_send = true;
-            } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
-                if(i2ctools->sniffer->started) {
-                    stop_interrupts();
-                    i2ctools->sniffer->started = false;
-                    i2ctools->sniffer->state = I2C_BUS_FREE;
-                } else {
-                    start_interrupts(i2ctools->sniffer);
-                    i2ctools->sniffer->started = true;
-                    i2ctools->sniffer->state = I2C_BUS_FREE;
-                }
-            }
-        } else if(event.key == InputKeyRight && event.type == InputTypeRelease) {
-            if(i2ctools->main_view->current_view == SEND_VIEW) {
-                if(i2ctools->sender->address_idx < (i2ctools->scanner->nb_found - 1)) {
-                    i2ctools->sender->address_idx++;
-                    i2ctools->sender->sended = false;
-                }
-            } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
-                if(i2ctools->sniffer->menu_index < i2ctools->sniffer->frame_index) {
-                    i2ctools->sniffer->menu_index++;
-                    i2ctools->sniffer->row_index = 0;
+            // Down
+            else if(event.key == InputKeyDown && event.type == InputTypeRelease) {
+                if(i2ctools->main_view->current_view == MAIN_VIEW) {
+                    if(i2ctools->main_view->menu_index < MENU_SIZE - 1) {
+                        i2ctools->main_view->menu_index++;
+                    }
+                } else if(i2ctools->main_view->current_view == SCAN_VIEW) {
+                    if(i2ctools->scanner->menu_index < ((int)i2ctools->scanner->nb_found / 3)) {
+                        i2ctools->scanner->menu_index++;
+                    }
+                } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
+                    if((i2ctools->sniffer->row_index + 3) <
+                       (int)i2ctools->sniffer->frames[i2ctools->sniffer->menu_index].data_index) {
+                        i2ctools->sniffer->row_index++;
+                    }
+                } else if(i2ctools->main_view->current_view == SEND_VIEW) {
+                    if(i2ctools->sender->value > 0x00) {
+                        i2ctools->sender->value--;
+                        i2ctools->sender->sended = false;
+                    }
                 }
             }
-        } else if(event.key == InputKeyLeft && event.type == InputTypeRelease) {
-            if(i2ctools->main_view->current_view == SEND_VIEW) {
-                if(i2ctools->sender->address_idx > 0) {
-                    i2ctools->sender->address_idx--;
-                    i2ctools->sender->sended = false;
-                }
-            } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
-                if(i2ctools->sniffer->menu_index > 0) {
-                    i2ctools->sniffer->menu_index--;
-                    i2ctools->sniffer->row_index = 0;
+            // Long Down
+            else if(
+                event.key == InputKeyDown &&
+                (event.type == InputTypeLong || event.type == InputTypeRepeat)) {
+                if(i2ctools->main_view->current_view == SEND_VIEW) {
+                    if(i2ctools->sender->value > 0x05) {
+                        i2ctools->sender->value -= 5;
+                        i2ctools->sender->sended = false;
+                    } else {
+                        i2ctools->sender->value = 0;
+                        i2ctools->sender->sended = false;
+                    }
+                } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
+                    if((i2ctools->sniffer->row_index + 8) <
+                       (int)i2ctools->sniffer->frames[i2ctools->sniffer->menu_index].data_index) {
+                        i2ctools->sniffer->row_index += 5;
+                    }
+                }
+
+            } else if(event.key == InputKeyOk && event.type == InputTypeRelease) {
+                if(i2ctools->main_view->current_view == MAIN_VIEW) {
+                    i2ctools->main_view->current_view = i2ctools->main_view->menu_index;
+                } else if(i2ctools->main_view->current_view == SCAN_VIEW) {
+                    scan_i2c_bus(i2ctools->scanner);
+                } else if(i2ctools->main_view->current_view == SEND_VIEW) {
+                    i2ctools->sender->must_send = true;
+                } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
+                    if(i2ctools->sniffer->started) {
+                        stop_interrupts();
+                        i2ctools->sniffer->started = false;
+                        i2ctools->sniffer->state = I2C_BUS_FREE;
+                    } else {
+                        start_interrupts(i2ctools->sniffer);
+                        i2ctools->sniffer->started = true;
+                        i2ctools->sniffer->state = I2C_BUS_FREE;
+                    }
+                }
+            } else if(event.key == InputKeyRight && event.type == InputTypeRelease) {
+                if(i2ctools->main_view->current_view == SEND_VIEW) {
+                    if(i2ctools->sender->address_idx < (i2ctools->scanner->nb_found - 1)) {
+                        i2ctools->sender->address_idx++;
+                        i2ctools->sender->sended = false;
+                    }
+                } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
+                    if(i2ctools->sniffer->menu_index < i2ctools->sniffer->frame_index) {
+                        i2ctools->sniffer->menu_index++;
+                        i2ctools->sniffer->row_index = 0;
+                    }
+                }
+            } else if(event.key == InputKeyLeft && event.type == InputTypeRelease) {
+                if(i2ctools->main_view->current_view == SEND_VIEW) {
+                    if(i2ctools->sender->address_idx > 0) {
+                        i2ctools->sender->address_idx--;
+                        i2ctools->sender->sended = false;
+                    }
+                } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
+                    if(i2ctools->sniffer->menu_index > 0) {
+                        i2ctools->sniffer->menu_index--;
+                        i2ctools->sniffer->row_index = 0;
+                    }
                 }
             }
         }
@@ -218,6 +224,7 @@ int32_t i2ctools_app(void* p) {
     i2c_scanner_free(i2ctools->scanner);
     i2c_sender_free(i2ctools->sender);
     i2c_main_view_free(i2ctools->main_view);
+    furi_mutex_free(i2ctools->mutex);
     free(i2ctools);
     furi_record_close(RECORD_GUI);
     return 0;

BIN
screenshots/infos_screen.png


BIN
screenshots/main_screen.png


BIN
screenshots/scan_screen.png


BIN
screenshots/send_screen.png


BIN
screenshots/sniff_screen.png