Skip to content

Commit

Permalink
Consistency with OFW and UL api for region, version, otp
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Mar 19, 2024
1 parent a9fa995 commit 3d317f7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 37 deletions.
2 changes: 1 addition & 1 deletion applications/settings/about/about.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static DialogMessageButton about_screen_hw_version(DialogsApp* dialogs, DialogMe
furi_hal_version_get_hw_target(),
furi_hal_version_get_hw_body(),
furi_hal_version_get_hw_connect(),
furi_hal_version_get_hw_region_name_otp(),
furi_hal_version_get_hw_region_name(),
furi_hal_region_get_name(),
my_name ? my_name : "Unknown");

Expand Down
2 changes: 1 addition & 1 deletion targets/f7/furi_hal/furi_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void furi_hal_init() {
furi_hal_flash_init();
furi_hal_resources_init();
furi_hal_version_init();
furi_hal_region_init();
furi_hal_spi_config_init();
furi_hal_spi_dma_init();
furi_hal_ibutton_init();
Expand All @@ -59,7 +60,6 @@ void furi_hal_init() {
furi_hal_light_init();
furi_hal_bt_init();
furi_hal_memory_init();
furi_hal_region_init();

#ifndef FURI_RAM_EXEC
furi_hal_usb_init();
Expand Down
41 changes: 20 additions & 21 deletions targets/f7/furi_hal/furi_hal_region.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <furi_hal_region.h>
#include <furi_hal_version.h>
#include <furi.h>

const FuriHalRegion furi_hal_region_zero = {
.country_code = "00",
Expand Down Expand Up @@ -74,7 +73,7 @@ const FuriHalRegion furi_hal_region_jp = {
static const FuriHalRegion* furi_hal_region = NULL;

void furi_hal_region_init() {
FuriHalVersionRegion region = furi_hal_version_get_hw_region_otp();
FuriHalVersionRegion region = furi_hal_version_get_hw_region();

if(region == FuriHalVersionRegionUnknown) {
furi_hal_region = &furi_hal_region_zero;
Expand All @@ -95,19 +94,16 @@ void furi_hal_region_set(FuriHalRegion* region) {
furi_hal_region = region;
}

const FuriHalRegionBand* furi_hal_region_get_band(uint32_t frequency) {
if(!furi_hal_region) {
return NULL;
}
bool furi_hal_region_is_provisioned() {
return furi_hal_region != NULL;
}

for(size_t i = 0; i < furi_hal_region->bands_count; i++) {
if(furi_hal_region->bands[i].start <= frequency &&
furi_hal_region->bands[i].end >= frequency) {
return &furi_hal_region->bands[i];
}
const char* furi_hal_region_get_name() {
if(furi_hal_region) {
return furi_hal_region->country_code;
} else {
return "--";
}

return NULL;
}

bool furi_hal_region_is_frequency_allowed(uint32_t frequency) {
Expand All @@ -123,14 +119,17 @@ bool furi_hal_region_is_frequency_allowed(uint32_t frequency) {
return true;
}

bool furi_hal_region_is_provisioned() {
return furi_hal_region != NULL;
}
const FuriHalRegionBand* furi_hal_region_get_band(uint32_t frequency) {
if(!furi_hal_region) {
return NULL;
}

const char* furi_hal_region_get_name() {
if(furi_hal_region) {
return furi_hal_region->country_code;
} else {
return "--";
for(size_t i = 0; i < furi_hal_region->bands_count; i++) {
if(furi_hal_region->bands[i].start <= frequency &&
furi_hal_region->bands[i].end >= frequency) {
return &furi_hal_region->bands[i];
}
}

return NULL;
}
16 changes: 8 additions & 8 deletions targets/f7/furi_hal/furi_hal_version.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,15 @@ uint8_t furi_hal_version_get_hw_connect() {
}

FuriHalVersionRegion furi_hal_version_get_hw_region() {
return FuriHalVersionRegionUnknown;
return furi_hal_version.board_region;
}

FuriHalVersionRegion furi_hal_version_get_hw_region_otp() {
return furi_hal_version.board_region;
return furi_hal_version_get_hw_region();
}

const char* furi_hal_version_get_hw_region_name() {
return "R00";
}

const char* furi_hal_version_get_hw_region_name_otp() {
switch(furi_hal_version_get_hw_region_otp()) {
switch(furi_hal_version_get_hw_region()) {
case FuriHalVersionRegionUnknown:
return "R00";
case FuriHalVersionRegionEuRu:
Expand All @@ -276,6 +272,10 @@ const char* furi_hal_version_get_hw_region_name_otp() {
return "R??";
}

const char* furi_hal_version_get_hw_region_name_otp() {
return furi_hal_version_get_hw_region_name();
}

FuriHalVersionDisplay furi_hal_version_get_hw_display() {
return furi_hal_version.board_display;
}
Expand Down Expand Up @@ -316,5 +316,5 @@ const uint8_t* furi_hal_version_uid() {
if(version_get_custom_name(NULL) != NULL) {
return (const uint8_t*)&(*((uint32_t*)version_get_custom_name(NULL)));
}
return (const uint8_t*)UID64_BASE;
return furi_hal_version_uid_default();
}
12 changes: 6 additions & 6 deletions targets/furi_hal_include/furi_hal_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,25 @@ FuriHalVersionColor furi_hal_version_get_hw_color();
*/
uint8_t furi_hal_version_get_hw_connect();

/** Get hardware region (fake) = 0
/** Get hardware region
*
* @return Hardware Region (fake)
* @return Hardware Region
*/
FuriHalVersionRegion furi_hal_version_get_hw_region();

/** Get hardware region name (fake) = R00
/** Get hardware region name
*
* @return Hardware Region name (fake)
* @return Hardware Region name
*/
const char* furi_hal_version_get_hw_region_name();

/** Get hardware region (OTP)
/** Get hardware region (compatibility with Unleashed API)
*
* @return Hardware Region
*/
FuriHalVersionRegion furi_hal_version_get_hw_region_otp();

/** Get hardware region name (OTP)
/** Get hardware region name (compatibility with Unleashed API)
*
* @return Hardware Region name
*/
Expand Down

0 comments on commit 3d317f7

Please sign in to comment.