Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jleni committed Jun 18, 2020
2 parents ee7e1fa + 3c1cc48 commit 9e1a77e
Show file tree
Hide file tree
Showing 21 changed files with 422 additions and 49 deletions.
10 changes: 5 additions & 5 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,14 @@ DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX

DEFINES += HAVE_UX_FLOW

#SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
SDK_SOURCE_PATH += lib_ux
DEFINES += HAVE_BLE
DEFINES += HAVE_BLE_APDU BLE_COMMAND_TIMEOUT_MS=2000

SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
else
# Assume Nano S
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
DEFINES += HAVE_BOLOS_UX COMPLIANCE_UX_160 HAVE_UX_LEGACY HAVE_UX_FLOW
DEFINES += COMPLIANCE_UX_160 HAVE_UX_LEGACY HAVE_UX_FLOW
endif

# X specific
Expand Down Expand Up @@ -164,8 +166,6 @@ APP_SOURCE_PATH += $(MY_DIR)/../deps/ledger-zxlib/src
APP_SOURCE_PATH += $(MY_DIR)/../deps/ledger-zxlib/app/common

SDK_SOURCE_PATH += lib_stusb lib_stusb_impl

#SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
SDK_SOURCE_PATH += lib_ux

rust:
Expand Down
12 changes: 12 additions & 0 deletions app/src/common/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,21 @@ void handle_generic_apdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32

void app_init() {
io_seproxyhal_init();

#ifdef TARGET_NANOX
// grab the current plane mode setting
G_io_app.plane_mode = os_setting_get(OS_SETTING_PLANEMODE, NULL, 0);
#endif // TARGET_NANOX

USB_power(0);
USB_power(1);
view_idle_show(0);

#ifdef HAVE_BLE
// Enable Bluetooth
BLE_power(0, NULL);
BLE_power(1, "Nano X");
#endif // HAVE_BLE
}

#pragma clang diagnostic push
Expand Down
77 changes: 77 additions & 0 deletions deps/ledger-zxlib/app/common/app_mode.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*******************************************************************************
* (c) 2020 Zondax GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/

#include "app_mode.h"

typedef struct {
uint32_t expert;
} app_mode_t;

#if defined(TARGET_NANOS) || defined(TARGET_NANOX)
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////

//NV_CONST app_mode_t N_appmode NV_ALIGN;
//#define N_APPMODE_PTR ((NV_VOL app_mode_t *)PIC(&N_appmode))
app_mode_t app_mode;

void app_mode_reset(){
app_mode.expert = 0;
}

bool app_mode_expert() {
// TODO: read from NVRAM
// app_mode_t *p = N_APPMODE_PTR;
// uint8_t expert = p->expert;
// return expert;
// app_mode_t* p =(NV_VOL app_mode_t *)PIC(&N_appmode_impl);
// return p->expert;
return app_mode.expert;
}

void app_mode_set_expert(uint8_t val) {
// TODO: write to NVRAM
app_mode.expert = val;
}

#else
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////

app_mode_t app_mode;

void app_mode_reset() {
app_mode.expert = 0;
}

bool app_mode_expert() {
return app_mode.expert;
}

void app_mode_set_expert(uint8_t val) {
app_mode.expert = val;
}

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////

#endif
33 changes: 33 additions & 0 deletions deps/ledger-zxlib/app/common/app_mode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* (c) 2016 Ledger
* (c) 2018 Zondax GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
#pragma once
#include "zxmacros.h"
#include "stdbool.h"

#ifdef __cplusplus
extern "C" {
#endif

void app_mode_reset();

bool app_mode_expert();

void app_mode_set_expert(uint8_t val);

#ifdef __cplusplus
}
#endif
48 changes: 40 additions & 8 deletions deps/ledger-zxlib/app/common/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "zxmacros.h"
#include "view_templates.h"
#include "tx.h"
#include "app_mode.h"

#include <string.h>
#include <stdio.h>
Expand Down Expand Up @@ -69,6 +70,18 @@ void h_paging_init() {
viewdata.pageCount = 1;
}

uint8_t h_paging_can_increase() {
if (viewdata.pageIdx + 1 < viewdata.pageCount) {
return 1;
} else {
// passed page count, go to next index
if (viewdata.itemIdx + 1 < viewdata.itemCount) {
return 1;
}
}
return 0;
}

void h_paging_increase() {
if (viewdata.pageIdx + 1 < viewdata.pageCount) {
// increase page
Expand All @@ -82,6 +95,17 @@ void h_paging_increase() {
}
}

uint8_t h_paging_can_decrease() {
if (viewdata.pageIdx != 0) {
return 1;
} else {
if (viewdata.itemIdx > 0) {
return 1;
}
}
return 0;
}

void h_paging_decrease() {
if (viewdata.pageIdx != 0) {
viewdata.pageIdx--;
Expand Down Expand Up @@ -141,12 +165,15 @@ view_error_t h_review_update_data() {
view_error_t h_addr_update_item(uint8_t idx) {
MEMZERO(viewdata.value, MAX_CHARS_PER_VALUE1_LINE);

switch (idx) {
case 0: return view_printAddr();
case 1: return view_printPath();
default:
return view_error_detected;
if (idx == 0) {
return view_printAddr();
}

if (idx == 1 && app_mode_expert()) {
return view_printPath();
}

return view_error_detected;
}

void io_seproxyhal_display(const bagl_element_t *element) {
Expand All @@ -157,13 +184,18 @@ void view_init(void) {
UX_INIT();
}

void view_idle_show(unsigned int ignored) {
view_idle_show_impl();
void view_idle_show(uint8_t item_idx) {
view_idle_show_impl(item_idx);
}

void view_address_show(address_kind_e addressKind) {
viewdata.addrKind = addressKind;
viewdata.itemCount = VIEW_ADDRESS_ITEM_COUNT; // Address, path, etc.

viewdata.itemCount = 1;
if (app_mode_expert()) {
viewdata.itemCount = 2;
}

view_address_show_impl();
}

Expand Down
2 changes: 1 addition & 1 deletion deps/ledger-zxlib/app/common/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
void view_init();

/// view_idle_show (idle view - main menu + status)
void view_idle_show(unsigned int ignored);
void view_idle_show(uint8_t item_idx);

/// view_error (error view)
void view_error_show();
Expand Down
6 changes: 5 additions & 1 deletion deps/ledger-zxlib/app/common/view_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void splitValueField();
///////////////////////////////////////////////
///////////////////////////////////////////////

void view_idle_show_impl();
void view_idle_show_impl(uint8_t item_idx);

void view_address_show_impl();

Expand All @@ -101,8 +101,12 @@ void h_sign_reject(unsigned int _);

void h_paging_init();

uint8_t h_paging_can_increase();

void h_paging_increase();

uint8_t h_paging_can_decrease();

void h_paging_decrease();

void h_paging_set_page_count(uint8_t pageCount);
Expand Down
Loading

0 comments on commit 9e1a77e

Please sign in to comment.