Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/lvgl btnmatrix disable #81

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions external/lvgl/src/widgets/lv_btnmatrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,14 @@ static void lv_btnmatrix_event(const lv_obj_class_t * class_p, lv_event_t * e)
/*Search the pressed area*/
lv_indev_get_point(param, &p);
btn_pr = get_button_from_point(obj, &p);
if (btn_pr != LV_BTNMATRIX_BTN_NONE) {
if (button_is_inactive(btnm->ctrl_bits[btn_pr]) == true) {
btnm->btn_id_sel = btn_pr;
invalidate_button_area(obj, btnm->btn_id_sel); /*Invalidate the new area*/
return;
}
}

/*Handle the case where there is no button there*/
if (btn_pr != LV_BTNMATRIX_BTN_NONE) {
if (button_is_inactive(btnm->ctrl_bits[btn_pr]) == false &&
Expand Down
109 changes: 55 additions & 54 deletions rust/rust_c/src/interfaces/ethereum/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use alloc::boxed::Box;
use alloc::string::ToString;
use alloc::string::{String, ToString};
use alloc::{format, slice};

use app_ethereum::errors::EthereumError;
use app_ethereum::{
parse_fee_market_tx, parse_legacy_tx, parse_personal_message, parse_typed_data_message,
};
use keystore::algorithms::secp256k1::derive_public_key;
use third_party::hex;
use third_party::ur_registry::ethereum::eth_sign_request::EthSignRequest;
use third_party::ur_registry::ethereum::eth_signature::EthSignature;
use third_party::ur_registry::traits::RegistryItem;
Expand Down Expand Up @@ -64,30 +63,46 @@ pub extern "C" fn eth_check(
}
}

fn parse_eth_sub_path(path: String) -> Option<String> {
let root_path = "44'/60'/";
match path.strip_prefix(root_path) {
Some(path) => {
if let Some(index) = path.find("/") {
Some(path[index + 1..].to_string())
} else {
None
}
}
None => None,
}
}

fn try_get_eth_public_key(
xpub: String,
eth_sign_request: EthSignRequest,
) -> Result<third_party::secp256k1::PublicKey, RustCError> {
match eth_sign_request.get_derivation_path().get_path() {
None => Err(RustCError::InvalidHDPath),
Some(path) => {
let _path = path.clone();
if let Some(sub_path) = parse_eth_sub_path(_path) {
derive_public_key(&xpub, &format!("m/{}", sub_path))
.map_err(|e| RustCError::UnexpectedError(format!("unable to derive pubkey")))
} else {
Err(RustCError::InvalidHDPath)
}
}
}
}

#[no_mangle]
pub extern "C" fn eth_parse(
ptr: PtrUR,
xpub: PtrString,
) -> PtrT<TransactionParseResult<DisplayETH>> {
let crypto_eth = extract_ptr_with_type!(ptr, EthSignRequest);
let pubkey = match crypto_eth.get_derivation_path().get_path() {
None => {
return TransactionParseResult::from(RustCError::InvalidHDPath).c_ptr();
}
Some(path) => {
let xpub = recover_c_char(xpub);
let mut _path = path.clone();
let root_path = "44'/60'/0'/";
let sub_path = match _path.strip_prefix(root_path) {
Some(path) => path,
None => {
return TransactionParseResult::from(RustCError::InvalidHDPath).c_ptr();
}
};
derive_public_key(&xpub, &format!("m/{}", sub_path))
}
};

let xpub = recover_c_char(xpub);
let pubkey = try_get_eth_public_key(xpub, crypto_eth.clone());
let transaction_type = TransactionType::from(crypto_eth.get_data_type());

match (pubkey, transaction_type) {
Expand Down Expand Up @@ -142,23 +157,8 @@ pub extern "C" fn eth_parse_personal_message(
xpub: PtrString,
) -> PtrT<TransactionParseResult<DisplayETHPersonalMessage>> {
let crypto_eth = extract_ptr_with_type!(ptr, EthSignRequest);
let pubkey = match crypto_eth.get_derivation_path().get_path() {
None => {
return TransactionParseResult::from(RustCError::InvalidHDPath).c_ptr();
}
Some(path) => {
let xpub = recover_c_char(xpub);
let mut _path = path.clone();
let root_path = "44'/60'/0'/";
let sub_path = match _path.strip_prefix(root_path) {
Some(path) => path,
None => {
return TransactionParseResult::from(RustCError::InvalidHDPath).c_ptr();
}
};
derive_public_key(&xpub, &format!("m/{}", sub_path))
}
};
let xpub = recover_c_char(xpub);
let pubkey = try_get_eth_public_key(xpub, crypto_eth.clone());

let transaction_type = TransactionType::from(crypto_eth.get_data_type());

Expand Down Expand Up @@ -189,23 +189,8 @@ pub extern "C" fn eth_parse_typed_data(
xpub: PtrString,
) -> PtrT<TransactionParseResult<DisplayETHTypedData>> {
let crypto_eth = extract_ptr_with_type!(ptr, EthSignRequest);
let pubkey = match crypto_eth.get_derivation_path().get_path() {
None => {
return TransactionParseResult::from(RustCError::InvalidHDPath).c_ptr();
}
Some(path) => {
let xpub = recover_c_char(xpub);
let mut _path = path.clone();
let root_path = "44'/60'/0'/";
let sub_path = match _path.strip_prefix(root_path) {
Some(path) => path,
None => {
return TransactionParseResult::from(RustCError::InvalidHDPath).c_ptr();
}
};
derive_public_key(&xpub, &format!("m/{}", sub_path))
}
};
let xpub = recover_c_char(xpub);
let pubkey = try_get_eth_public_key(xpub, crypto_eth.clone());

let transaction_type = TransactionType::from(crypto_eth.get_data_type());

Expand Down Expand Up @@ -290,11 +275,27 @@ pub extern "C" fn eth_sign_tx(ptr: PtrUR, seed: PtrBytes, seed_len: u32) -> PtrT
#[cfg(test)]
mod tests {
extern crate std;

use std::println;

#[test]
fn test() {
let p = "m/44'/60'/0'/0/0";
let prefix = "m/44'/60'/0'/";
println!("{:?}", p.strip_prefix(prefix))
}

#[test]
fn test_test() {
let _path = "44'/60'/1'/0/0";
let root_path = "44'/60'/";
let sub_path = match _path.strip_prefix(root_path) {
Some(path) => {
if let Some(index) = path.find("/") {
println!("{}", &path[index..]);
}
}
None => {}
};
}
}
2 changes: 2 additions & 0 deletions rust/third_party/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/config/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef _VERSION_H
#define _VERSION_H

#define SOFTWARE_VERSION_MAJOR 0
#define SOFTWARE_VERSION_MINOR 9
#define SOFTWARE_VERSION_MAJOR 1
#define SOFTWARE_VERSION_MINOR 0
#define SOFTWARE_VERSION_BUILD 0
#define SOFTWARE_VERSION (SOFTWARE_VERSION_MAJOR * 10000 + SOFTWARE_VERSION_MINOR * 100 + SOFTWARE_VERSION_BUILD)

Expand Down
1 change: 1 addition & 0 deletions src/managers/keystore.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ int32_t KeystoreInit(void)
ASSERT(sizeof(AccountInfo_t) == 32);
ASSERT(sizeof(PublicInfo_t) == 32);
ret = SE_HmacEncryptRead((uint8_t *)&g_publicInfo, PAGE_PUBLIC_INFO);
assert(g_publicInfo.loginPasswordErrorCount <= 10);
return ret;
}

Expand Down
40 changes: 21 additions & 19 deletions src/tasks/touchpad_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ osSemaphoreId_t g_touchPadSem = NULL;
TouchStatus_t g_touchStatus[TOUCH_RING_BUFFER_SIZE];
volatile bool g_touchPress;
static uint8_t g_touchWriteIndex, g_touchReadIndex;
TouchStatus_t g_touchStatusG;

void CreateTouchPadTask(void)
{
Expand Down Expand Up @@ -62,11 +63,12 @@ static void TouchPadTask(void *argument)
LcdDraw(touchStatus.x, touchStatus.y, touchStatus.x, touchStatus.y, &testColor);
#else
if (lastTouch) {
g_touchWriteIndex++;
if (g_touchWriteIndex >= TOUCH_RING_BUFFER_SIZE) {
g_touchWriteIndex = 0;
}
memcpy(&g_touchStatus[g_touchWriteIndex], &touchStatus, sizeof(TouchStatus_t));
// g_touchWriteIndex++;
// if (g_touchWriteIndex >= TOUCH_RING_BUFFER_SIZE) {
// g_touchWriteIndex = 0;
// }
// memcpy(&g_touchStatus[g_touchWriteIndex], &touchStatus, sizeof(TouchStatus_t));
memcpy(&g_touchStatusG, &touchStatus, sizeof(TouchStatus_t));
}
lastTouch = touchStatus.touch;
#endif
Expand All @@ -83,20 +85,20 @@ static void TouchPadTask(void *argument)

TouchStatus_t *GetTouchStatus(void)
{
uint8_t index;

index = g_touchReadIndex;
//printf("index=%d\r\n", index);
if (g_touchReadIndex != g_touchWriteIndex) {
g_touchReadIndex++;
if (g_touchReadIndex >= TOUCH_RING_BUFFER_SIZE) {
g_touchReadIndex = 0;
}
g_touchStatus[index].continueReading = true;
} else {
g_touchStatus[index].continueReading = false;
}
return &g_touchStatus[index];
// uint8_t index;

// index = g_touchReadIndex;
// //printf("index=%d\r\n", index);
// if (g_touchReadIndex != g_touchWriteIndex) {
// g_touchReadIndex++;
// if (g_touchReadIndex >= TOUCH_RING_BUFFER_SIZE) {
// g_touchReadIndex = 0;
// }
// g_touchStatus[index].continueReading = true;
// } else {
// g_touchStatus[index].continueReading = false;
// }
return &g_touchStatusG;
}


Expand Down
1 change: 1 addition & 0 deletions src/tasks/ui_display_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ static void UiDisplayTask(void *argument)
case UI_MSG_CLOSE_CURRENT_VIEW: {
GuiCLoseCurrentWorkingView();
}
break;
case UI_MSG_SCREEN_SHOT: {
#ifndef BUILD_PRODUCTION
#ifdef ENABLE_SCREEN_SHOT
Expand Down
8 changes: 4 additions & 4 deletions src/ui/gui_components/gui_keyboard_hintbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ void GuiClearKeyboardInput(KeyboardWidget_t *keyboardWidget)

void GuiSetErrorLabel(KeyboardWidget_t *keyboardWidget, char *errorMessage)
{
assert(keyboardWidget);
assert(keyboardWidget->errLabel);
lv_label_set_text(keyboardWidget->errLabel, errorMessage);
lv_obj_clear_flag(keyboardWidget->errLabel, LV_OBJ_FLAG_HIDDEN);
if (keyboardWidget != NULL && keyboardWidget->errLabel != NULL) {
lv_label_set_text(keyboardWidget->errLabel, errorMessage);
lv_obj_clear_flag(keyboardWidget->errLabel, LV_OBJ_FLAG_HIDDEN);
}
}

void GuiShowErrorLabel(KeyboardWidget_t *keyboardWidget)
Expand Down
2 changes: 1 addition & 1 deletion src/ui/gui_components/gui_status_bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ void SetNavBarLeftBtn(NavBarWidget_t *navBarWidget, NVS_LEFT_BUTTON_ENUM button,
if (button != NVS_BAR_MANAGE) {
lv_obj_add_event_cb(navBarWidget->leftBtn, leftButtonCb, LV_EVENT_CLICKED, param);
} else {
lv_obj_add_event_cb(navBarWidget->leftBtn, leftButtonCb, LV_EVENT_SHORT_CLICKED, param);
lv_obj_add_event_cb(navBarWidget->leftBtn, leftButtonCb, LV_EVENT_CLICKED, param);
}
}
}
Expand Down
12 changes: 0 additions & 12 deletions src/ui/gui_widgets/gui_about_terms_widgets.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,6 @@ void GuiAboutTermsEntranceWidget(lv_obj_t *parent)
lv_obj_align(itemObj, LV_ALIGN_DEFAULT, 22, dy);
dy += (height + 24);

tittle = "No Retrieval of Sensitive Information";
text = "We do not store your sensitive information like passwords or seed phrases. Keep your credentials safe.";
itemObj = GuiGetTermsItemContainer(g_cont, tittle, text, &height);
lv_obj_align(itemObj, LV_ALIGN_DEFAULT, 22, dy);
dy += (height + 24);

tittle = "Risks";
text = "Be aware of the risks associated with cryptocurrencies and technology vulnerabilities.";
itemObj = GuiGetTermsItemContainer(g_cont, tittle, text, &height);
Expand All @@ -178,12 +172,6 @@ void GuiAboutTermsEntranceWidget(lv_obj_t *parent)
lv_obj_align(itemObj, LV_ALIGN_DEFAULT, 22, dy);
dy += (height + 24);

tittle = "Indemnity";
text = "You must be 18 years old or above to access and use our Products or Services.";
itemObj = GuiGetTermsItemContainer(g_cont, tittle, text, &height);
lv_obj_align(itemObj, LV_ALIGN_DEFAULT, 22, dy);
dy += (height + 24);

tittle = "Discontinuance of Services";
text = "We may modify or discontinue our services. Remember to back up your seed phrase to access your cryptocurrencies.";
itemObj = GuiGetTermsItemContainer(g_cont, tittle, text, &height);
Expand Down
Loading
Loading