Skip to content

Commit 0b553db

Browse files
committed
Squashed 'i2ctools/' changes from 51e0d45..e28c07e
e28c07e move base pack here REVERT: 51e0d45 Update changelog REVERT: 3410a57 update app version REVERT: bf47633 Add infos view REVERT: 8903390 Update README REVERT: 5c503c9 Add needed files for Flipper Application Catalog REVERT: 08db98a Create LICENSE REVERT: a35ba70 change appid to new naming convention REVERT: 3315c32 Merge pull request #4 from Samuelrmlink/main REVERT: 2711e8b Updated FlipperAppType REVERT: 2d1d151 Updated to use the newer Furi mutex api. REVERT: 70ec58b Update readme REVERT: a52df9e Rewording and fix down event type bug REVERT: 02305cb remade send view and remove unused icons REVERT: a17f2a4 remade sniffer view REVERT: 279d19e New main icon REVERT: b3c662a Improve UI REVERT: e12ba00 made mistake parsing 7bit addresses REVERT: b8a62a3 increase records limit REVERT: 90fd1ae print more than 2 frames REVERT: 167914c icons update REVERT: f7c04a6 Better Menu organisation REVERT: d34e267 Reset GPIO pins to default state REVERT: 6aab68d Share scanner with sender REVERT: 31ba882 Fix missing free REVERT: 351941d update Todo list REVERT: 62eceae Make sender a lib REVERT: 5a99abb Make a lib for the scanner REVERT: 7c3ef28 Use sniffer alloc and free REVERT: 412a017 Remove useless "pragma once" REVERT: 8c47c33 make code more "furi styled" REVERT: 2870da3 One tool, one file REVERT: ce5510d Remove pulseview files REVERT: 6db20ac Remove unused stuff REVERT: 1ac288c Reword for better readability REVERT: 8baa063 Add Readme REVERT: 3818684 Add sender view REVERT: dc124f0 Fix Sniffer tool REVERT: 3cd1fb1 Remove unused png REVERT: 58f0763 Initial commit REVERT: d9089be Initial commit git-subtree-dir: i2ctools git-subtree-split: e28c07e
1 parent 51e0d45 commit 0b553db

11 files changed

+146
-154
lines changed

.gitignore

Whitespace-only changes.

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# flipperzero-i2ctools
22

3+
[Original link](https://github.com/NaejEL/flipperzero-i2ctools)
34
Set of i2c tools for Flipper Zero
45

56
![Preview](i2ctools.gif)
@@ -29,16 +30,15 @@ Spy i2c traffic
2930
Send command to i2c peripherals and read result
3031

3132
## TODO
32-
- [ ] Kicad module
33-
- [ ] Improve UI
34-
- [ ] Refactor Event Management Code
35-
- [ ] Add Documentation
3633

37-
## V2
3834
- [ ] Read more than 2 bytes in sender mode
3935
- [ ] Add 10-bits adresses support
4036
- [ ] Test with rate > 100khz
41-
- [ ] Save records (Sigrok compatible?)
37+
- [ ] Save records
4238
- [ ] Play from files
39+
- [ ] Kicad module
40+
- [ ] Improve UI
41+
- [ ] Refactor Event Management Code
42+
- [ ] Add Documentation
4343
- [ ] Remove max data size
4444
- [ ] Remove max frames read size

application.fam

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
App(
22
appid="i2ctools",
3-
name="i2c Tools",
3+
name="[GPIO] i2c Tools",
44
apptype=FlipperAppType.EXTERNAL,
55
entry_point="i2ctools_app",
6-
cdefines=["APP_I2CTOOLS"],
76
requires=["gui"],
87
stack_size=2 * 1024,
98
order=175,
@@ -13,4 +12,4 @@ App(
1312
fap_author="@NaejEL",
1413
fap_version="1.1",
1514
fap_description="Set of i2c tools",
16-
)
15+
)

docs/README.md

-7
This file was deleted.

docs/changelog.md

-7
This file was deleted.

i2ctools.c

+138-131
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#include "i2ctools_i.h"
22

33
void i2ctools_draw_callback(Canvas* canvas, void* ctx) {
4+
furi_assert(ctx);
45
i2cTools* i2ctools = ctx;
5-
if(furi_mutex_acquire(i2ctools->mutex, 200) != FuriStatusOk) {
6-
return;
7-
}
6+
furi_mutex_acquire(i2ctools->mutex, FuriWaitForever);
87

98
switch(i2ctools->main_view->current_view) {
109
case MAIN_VIEW:
@@ -46,6 +45,11 @@ int32_t i2ctools_app(void* p) {
4645
// Alloc i2ctools
4746
i2cTools* i2ctools = malloc(sizeof(i2cTools));
4847
i2ctools->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
48+
if(!i2ctools->mutex) {
49+
FURI_LOG_E(APP_NAME, "cannot create mutex\r\n");
50+
free(i2ctools);
51+
return -1;
52+
}
4953

5054
// Alloc viewport
5155
i2ctools->view_port = view_port_alloc();
@@ -69,143 +73,145 @@ int32_t i2ctools_app(void* p) {
6973
// Share scanner with sender
7074
i2ctools->sender->scanner = i2ctools->scanner;
7175

72-
while(furi_message_queue_get(event_queue, &event, FuriWaitForever) == FuriStatusOk) {
73-
// Back
74-
if(event.key == InputKeyBack && event.type == InputTypeRelease) {
75-
if(i2ctools->main_view->current_view == MAIN_VIEW) {
76-
break;
77-
} else {
78-
if(i2ctools->main_view->current_view == SNIFF_VIEW) {
79-
stop_interrupts();
80-
i2ctools->sniffer->started = false;
81-
i2ctools->sniffer->state = I2C_BUS_FREE;
82-
}
83-
i2ctools->main_view->current_view = MAIN_VIEW;
84-
}
85-
}
86-
// Up
87-
else if(event.key == InputKeyUp && event.type == InputTypeRelease) {
88-
if(i2ctools->main_view->current_view == MAIN_VIEW) {
89-
if((i2ctools->main_view->menu_index > SCAN_VIEW)) {
90-
i2ctools->main_view->menu_index--;
91-
}
92-
} else if(i2ctools->main_view->current_view == SCAN_VIEW) {
93-
if(i2ctools->scanner->menu_index > 0) {
94-
i2ctools->scanner->menu_index--;
95-
}
96-
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
97-
if(i2ctools->sniffer->row_index > 0) {
98-
i2ctools->sniffer->row_index--;
99-
}
100-
} else if(i2ctools->main_view->current_view == SEND_VIEW) {
101-
if(i2ctools->sender->value < 0xFF) {
102-
i2ctools->sender->value++;
103-
i2ctools->sender->sended = false;
104-
}
105-
}
106-
}
107-
// Long Up
108-
else if(
109-
event.key == InputKeyUp &&
110-
(event.type == InputTypeLong || event.type == InputTypeRepeat)) {
111-
if(i2ctools->main_view->current_view == SCAN_VIEW) {
112-
if(i2ctools->scanner->menu_index > 5) {
113-
i2ctools->scanner->menu_index -= 5;
114-
}
115-
} else if(i2ctools->main_view->current_view == SEND_VIEW) {
116-
if(i2ctools->sender->value < 0xF9) {
117-
i2ctools->sender->value += 5;
118-
i2ctools->sender->sended = false;
119-
}
120-
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
121-
if(i2ctools->sniffer->row_index > 5) {
122-
i2ctools->sniffer->row_index -= 5;
76+
while(1) {
77+
if(furi_message_queue_get(event_queue, &event, 100) == FuriStatusOk) {
78+
// Back
79+
if(event.key == InputKeyBack && event.type == InputTypeRelease) {
80+
if(i2ctools->main_view->current_view == MAIN_VIEW) {
81+
break;
12382
} else {
124-
i2ctools->sniffer->row_index = 0;
83+
if(i2ctools->main_view->current_view == SNIFF_VIEW) {
84+
stop_interrupts();
85+
i2ctools->sniffer->started = false;
86+
i2ctools->sniffer->state = I2C_BUS_FREE;
87+
}
88+
i2ctools->main_view->current_view = MAIN_VIEW;
12589
}
12690
}
127-
}
128-
// Down
129-
else if(event.key == InputKeyDown && event.type == InputTypeRelease) {
130-
if(i2ctools->main_view->current_view == MAIN_VIEW) {
131-
if(i2ctools->main_view->menu_index < MENU_SIZE - 1) {
132-
i2ctools->main_view->menu_index++;
133-
}
134-
} else if(i2ctools->main_view->current_view == SCAN_VIEW) {
135-
if(i2ctools->scanner->menu_index < ((int)i2ctools->scanner->nb_found / 3)) {
136-
i2ctools->scanner->menu_index++;
137-
}
138-
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
139-
if((i2ctools->sniffer->row_index + 3) <
140-
(int)i2ctools->sniffer->frames[i2ctools->sniffer->menu_index].data_index) {
141-
i2ctools->sniffer->row_index++;
142-
}
143-
} else if(i2ctools->main_view->current_view == SEND_VIEW) {
144-
if(i2ctools->sender->value > 0x00) {
145-
i2ctools->sender->value--;
146-
i2ctools->sender->sended = false;
91+
// Up
92+
else if(event.key == InputKeyUp && event.type == InputTypeRelease) {
93+
if(i2ctools->main_view->current_view == MAIN_VIEW) {
94+
if((i2ctools->main_view->menu_index > SCAN_VIEW)) {
95+
i2ctools->main_view->menu_index--;
96+
}
97+
} else if(i2ctools->main_view->current_view == SCAN_VIEW) {
98+
if(i2ctools->scanner->menu_index > 0) {
99+
i2ctools->scanner->menu_index--;
100+
}
101+
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
102+
if(i2ctools->sniffer->row_index > 0) {
103+
i2ctools->sniffer->row_index--;
104+
}
105+
} else if(i2ctools->main_view->current_view == SEND_VIEW) {
106+
if(i2ctools->sender->value < 0xFF) {
107+
i2ctools->sender->value++;
108+
i2ctools->sender->sended = false;
109+
}
147110
}
148111
}
149-
}
150-
// Long Down
151-
else if(
152-
event.key == InputKeyDown &&
153-
(event.type == InputTypeLong || event.type == InputTypeRepeat)) {
154-
if(i2ctools->main_view->current_view == SEND_VIEW) {
155-
if(i2ctools->sender->value > 0x05) {
156-
i2ctools->sender->value -= 5;
157-
i2ctools->sender->sended = false;
158-
} else {
159-
i2ctools->sender->value = 0;
160-
i2ctools->sender->sended = false;
161-
}
162-
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
163-
if((i2ctools->sniffer->row_index + 8) <
164-
(int)i2ctools->sniffer->frames[i2ctools->sniffer->menu_index].data_index) {
165-
i2ctools->sniffer->row_index += 5;
112+
// Long Up
113+
else if(
114+
event.key == InputKeyUp &&
115+
(event.type == InputTypeLong || event.type == InputTypeRepeat)) {
116+
if(i2ctools->main_view->current_view == SCAN_VIEW) {
117+
if(i2ctools->scanner->menu_index > 5) {
118+
i2ctools->scanner->menu_index -= 5;
119+
}
120+
} else if(i2ctools->main_view->current_view == SEND_VIEW) {
121+
if(i2ctools->sender->value < 0xF9) {
122+
i2ctools->sender->value += 5;
123+
i2ctools->sender->sended = false;
124+
}
125+
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
126+
if(i2ctools->sniffer->row_index > 5) {
127+
i2ctools->sniffer->row_index -= 5;
128+
} else {
129+
i2ctools->sniffer->row_index = 0;
130+
}
166131
}
167132
}
168-
169-
} else if(event.key == InputKeyOk && event.type == InputTypeRelease) {
170-
if(i2ctools->main_view->current_view == MAIN_VIEW) {
171-
i2ctools->main_view->current_view = i2ctools->main_view->menu_index;
172-
} else if(i2ctools->main_view->current_view == SCAN_VIEW) {
173-
scan_i2c_bus(i2ctools->scanner);
174-
} else if(i2ctools->main_view->current_view == SEND_VIEW) {
175-
i2ctools->sender->must_send = true;
176-
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
177-
if(i2ctools->sniffer->started) {
178-
stop_interrupts();
179-
i2ctools->sniffer->started = false;
180-
i2ctools->sniffer->state = I2C_BUS_FREE;
181-
} else {
182-
start_interrupts(i2ctools->sniffer);
183-
i2ctools->sniffer->started = true;
184-
i2ctools->sniffer->state = I2C_BUS_FREE;
185-
}
186-
}
187-
} else if(event.key == InputKeyRight && event.type == InputTypeRelease) {
188-
if(i2ctools->main_view->current_view == SEND_VIEW) {
189-
if(i2ctools->sender->address_idx < (i2ctools->scanner->nb_found - 1)) {
190-
i2ctools->sender->address_idx++;
191-
i2ctools->sender->sended = false;
192-
}
193-
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
194-
if(i2ctools->sniffer->menu_index < i2ctools->sniffer->frame_index) {
195-
i2ctools->sniffer->menu_index++;
196-
i2ctools->sniffer->row_index = 0;
133+
// Down
134+
else if(event.key == InputKeyDown && event.type == InputTypeRelease) {
135+
if(i2ctools->main_view->current_view == MAIN_VIEW) {
136+
if(i2ctools->main_view->menu_index < MENU_SIZE - 1) {
137+
i2ctools->main_view->menu_index++;
138+
}
139+
} else if(i2ctools->main_view->current_view == SCAN_VIEW) {
140+
if(i2ctools->scanner->menu_index < ((int)i2ctools->scanner->nb_found / 3)) {
141+
i2ctools->scanner->menu_index++;
142+
}
143+
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
144+
if((i2ctools->sniffer->row_index + 3) <
145+
(int)i2ctools->sniffer->frames[i2ctools->sniffer->menu_index].data_index) {
146+
i2ctools->sniffer->row_index++;
147+
}
148+
} else if(i2ctools->main_view->current_view == SEND_VIEW) {
149+
if(i2ctools->sender->value > 0x00) {
150+
i2ctools->sender->value--;
151+
i2ctools->sender->sended = false;
152+
}
197153
}
198154
}
199-
} else if(event.key == InputKeyLeft && event.type == InputTypeRelease) {
200-
if(i2ctools->main_view->current_view == SEND_VIEW) {
201-
if(i2ctools->sender->address_idx > 0) {
202-
i2ctools->sender->address_idx--;
203-
i2ctools->sender->sended = false;
204-
}
205-
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
206-
if(i2ctools->sniffer->menu_index > 0) {
207-
i2ctools->sniffer->menu_index--;
208-
i2ctools->sniffer->row_index = 0;
155+
// Long Down
156+
else if(
157+
event.key == InputKeyDown &&
158+
(event.type == InputTypeLong || event.type == InputTypeRepeat)) {
159+
if(i2ctools->main_view->current_view == SEND_VIEW) {
160+
if(i2ctools->sender->value > 0x05) {
161+
i2ctools->sender->value -= 5;
162+
i2ctools->sender->sended = false;
163+
} else {
164+
i2ctools->sender->value = 0;
165+
i2ctools->sender->sended = false;
166+
}
167+
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
168+
if((i2ctools->sniffer->row_index + 8) <
169+
(int)i2ctools->sniffer->frames[i2ctools->sniffer->menu_index].data_index) {
170+
i2ctools->sniffer->row_index += 5;
171+
}
172+
}
173+
174+
} else if(event.key == InputKeyOk && event.type == InputTypeRelease) {
175+
if(i2ctools->main_view->current_view == MAIN_VIEW) {
176+
i2ctools->main_view->current_view = i2ctools->main_view->menu_index;
177+
} else if(i2ctools->main_view->current_view == SCAN_VIEW) {
178+
scan_i2c_bus(i2ctools->scanner);
179+
} else if(i2ctools->main_view->current_view == SEND_VIEW) {
180+
i2ctools->sender->must_send = true;
181+
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
182+
if(i2ctools->sniffer->started) {
183+
stop_interrupts();
184+
i2ctools->sniffer->started = false;
185+
i2ctools->sniffer->state = I2C_BUS_FREE;
186+
} else {
187+
start_interrupts(i2ctools->sniffer);
188+
i2ctools->sniffer->started = true;
189+
i2ctools->sniffer->state = I2C_BUS_FREE;
190+
}
191+
}
192+
} else if(event.key == InputKeyRight && event.type == InputTypeRelease) {
193+
if(i2ctools->main_view->current_view == SEND_VIEW) {
194+
if(i2ctools->sender->address_idx < (i2ctools->scanner->nb_found - 1)) {
195+
i2ctools->sender->address_idx++;
196+
i2ctools->sender->sended = false;
197+
}
198+
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
199+
if(i2ctools->sniffer->menu_index < i2ctools->sniffer->frame_index) {
200+
i2ctools->sniffer->menu_index++;
201+
i2ctools->sniffer->row_index = 0;
202+
}
203+
}
204+
} else if(event.key == InputKeyLeft && event.type == InputTypeRelease) {
205+
if(i2ctools->main_view->current_view == SEND_VIEW) {
206+
if(i2ctools->sender->address_idx > 0) {
207+
i2ctools->sender->address_idx--;
208+
i2ctools->sender->sended = false;
209+
}
210+
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
211+
if(i2ctools->sniffer->menu_index > 0) {
212+
i2ctools->sniffer->menu_index--;
213+
i2ctools->sniffer->row_index = 0;
214+
}
209215
}
210216
}
211217
}
@@ -218,6 +224,7 @@ int32_t i2ctools_app(void* p) {
218224
i2c_scanner_free(i2ctools->scanner);
219225
i2c_sender_free(i2ctools->sender);
220226
i2c_main_view_free(i2ctools->main_view);
227+
furi_mutex_free(i2ctools->mutex);
221228
free(i2ctools);
222229
furi_record_close(RECORD_GUI);
223230
return 0;

screenshots/infos_screen.png

-1.76 KB
Binary file not shown.

screenshots/main_screen.png

-2.13 KB
Binary file not shown.

screenshots/scan_screen.png

-1.65 KB
Binary file not shown.

screenshots/send_screen.png

-1.87 KB
Binary file not shown.

screenshots/sniff_screen.png

-1.85 KB
Binary file not shown.

0 commit comments

Comments
 (0)