Skip to content

Commit

Permalink
Latest Release RM0416-0359-0.100.4-22e2176 on PATREON & GitHub - MAIN…
Browse files Browse the repository at this point in the history
… APP TWEAKS
  • Loading branch information
RogueMaster committed Apr 17, 2024
1 parent ae27678 commit f9b0b54
Show file tree
Hide file tree
Showing 26 changed files with 888 additions and 27 deletions.
14 changes: 14 additions & 0 deletions applications/main/gpio/gpio_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ GpioApp* gpio_app_alloc(void) {
view_dispatcher_add_view(
app->view_dispatcher, GpioAppViewGpioTest, gpio_test_get_view(app->gpio_test));

app->gpio_i2c_scanner = gpio_i2c_scanner_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
GpioAppViewI2CScanner,
gpio_i2c_scanner_get_view(app->gpio_i2c_scanner));

app->gpio_i2c_sfp = gpio_i2c_sfp_alloc();
view_dispatcher_add_view(
app->view_dispatcher, GpioAppViewI2CSfp, gpio_i2c_sfp_get_view(app->gpio_i2c_sfp));

app->widget = widget_alloc();
view_dispatcher_add_view(
app->view_dispatcher, GpioAppViewUsbUartCloseRpc, widget_get_view(app->widget));
Expand All @@ -84,6 +94,8 @@ void gpio_app_free(GpioApp* app) {
// Views
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewVarItemList);
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewGpioTest);
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewI2CScanner);
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewI2CSfp);
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewUsbUart);
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewUsbUartCfg);
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewUsbUartCloseRpc);
Expand All @@ -93,6 +105,8 @@ void gpio_app_free(GpioApp* app) {
gpio_test_free(app->gpio_test);
gpio_usb_uart_free(app->gpio_usb_uart);
dialog_ex_free(app->dialog);
gpio_i2c_scanner_free(app->gpio_i2c_scanner);
gpio_i2c_sfp_free(app->gpio_i2c_sfp);

// View dispatcher
view_dispatcher_free(app->view_dispatcher);
Expand Down
6 changes: 6 additions & 0 deletions applications/main/gpio/gpio_app_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <gui/modules/dialog_ex.h>
#include "views/gpio_test.h"
#include "views/gpio_usb_uart.h"
#include "views/gpio_i2c_scanner.h"
#include "views/gpio_i2c_sfp.h"
#include "gpio_icons.h"
#include <expansion/expansion.h>

Expand All @@ -34,6 +36,8 @@ struct GpioApp {
GpioUsbUart* gpio_usb_uart;
GPIOItems* gpio_items;
UsbUartBridge* usb_uart_bridge;
GpioI2CScanner* gpio_i2c_scanner;
GpioI2CSfp* gpio_i2c_sfp;
UsbUartConfig* usb_uart_cfg;
};

Expand All @@ -44,4 +48,6 @@ typedef enum {
GpioAppViewUsbUartCfg,
GpioAppViewUsbUartCloseRpc,
GpioAppViewExitConfirm,
GpioAppViewI2CScanner,
GpioAppViewI2CSfp
} GpioAppView;
2 changes: 2 additions & 0 deletions applications/main/gpio/gpio_custom_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ typedef enum {
GpioStartEventOtgOn,
GpioStartEventManualControl,
GpioStartEventUsbUart,
GpioStartEventI2CScanner,
GpioStartEventI2CSfp,

GpioCustomEventErrorBack,

Expand Down
23 changes: 23 additions & 0 deletions applications/main/gpio/gpio_i2c_scanner_control.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "gpio_i2c_scanner_control.h"
#include <furi.h>

void gpio_i2c_scanner_run_once(I2CScannerState* i2c_scanner_state) {
//Reset the number of items for rewriting the array
i2c_scanner_state->items = 0;
furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);

uint32_t response_timeout_ticks = furi_ms_to_ticks(5.f);

//Addresses 0 to 7 are reserved and won't be scanned
for(int i = FIRST_NON_RESERVED_I2C_ADDRESS; i <= HIGHEST_I2C_ADDRESS; i++) {
if(furi_hal_i2c_is_device_ready(
&furi_hal_i2c_handle_external,
i << 1,
response_timeout_ticks)) { //Bitshift of 1 bit to convert 7-Bit Address into 8-Bit Address
i2c_scanner_state->responding_address[i2c_scanner_state->items] = i;
i2c_scanner_state->items++;
}
}

furi_hal_i2c_release(&furi_hal_i2c_handle_external);
}
21 changes: 21 additions & 0 deletions applications/main/gpio/gpio_i2c_scanner_control.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <stdint.h>
#include <stdbool.h>

#include <furi_hal_i2c.h>

#define FIRST_NON_RESERVED_I2C_ADDRESS 8
#define HIGHEST_I2C_ADDRESS 127
#define AVAILABLE_NONRESVERED_I2C_ADDRESSES 120

typedef struct {
uint8_t items;
uint8_t responding_address[AVAILABLE_NONRESVERED_I2C_ADDRESSES];
} I2CScannerState;

/** Scans the I2C-Bus (SDA: Pin 15, SCL: Pin 16) for available 7-Bit slave addresses. Saves the number of detected slaves and their addresses.
*
* @param i2c_scanner_state State including the detected addresses and the number of addresses saved.
*/
void gpio_i2c_scanner_run_once(I2CScannerState* st);
Loading

0 comments on commit f9b0b54

Please sign in to comment.