Skip to content

Commit

Permalink
[clean] Decoupling BAGL / NBGL code
Browse files Browse the repository at this point in the history
  • Loading branch information
lpascal-ledger committed Jul 24, 2024
1 parent 3180f11 commit 7795ade
Show file tree
Hide file tree
Showing 12 changed files with 374 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_tests_and_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Install cmocka
run: |
sudo apt update
sudo apt install libcmocka-dev lcov
sudo apt install libcmocka-dev lcov libsodium-dev
- name: Compile the tests
run: |
cd tests/unit/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
with:
builtin: clear,rare
check_filenames: true
ignore_words_list: ontop
ignore_words_list: ontop,onl
1 change: 1 addition & 0 deletions src/bagl/nanox_enter_phrase.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <lcx_rng.h>
#include <ledger_assert.h>

#include "ux_nano.h"
#include "../constants.h"
#include "../ui.h"

Expand Down
16 changes: 14 additions & 2 deletions src/bagl/ux_nano.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,21 @@

#pragma once

#include <ux.h>
#include "ux_common/common.h"

#if (defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2))
#if defined(HAVE_BAGL)

typedef const bagl_element_t* (*keyboard_callback_t)(unsigned int event, unsigned int value);

void bolos_ux_hslider3_init(unsigned int total_count);
void bolos_ux_hslider3_set_current(unsigned int current);
void bolos_ux_hslider3_next(void);
void bolos_ux_hslider3_previous(void);

// all screens
void screen_onboarding_3_restore_init(void);
void screen_onboarding_4_restore_word_init(unsigned int action);

// bolos ux context (not mandatory if redesigning a bolos ux)
typedef struct bolos_ux_context {
Expand Down Expand Up @@ -81,4 +93,4 @@ void compare_recovery_phrase(void);
extern const ux_flow_step_t ux_ob_goto_dashboard_step;
#endif // defined(TARGET_NANOS)

#endif // (TARGET_NANOS || TARGET_NANOX || TARGET_NANOS2)
#endif // defined(HAVE_BAGL)
4 changes: 2 additions & 2 deletions src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

#include <os.h>

#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2)
#if defined(HAVE_BAGL)

#include "bagl/ux_nano.h"

#endif

// NanoS, S+, X and Stax
// All devices
void ui_idle_init(void);
21 changes: 0 additions & 21 deletions src/ux_common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,7 @@

#pragma once

#include <ux.h>

#ifdef OS_IO_SEPROXYHAL

#ifndef SPRINTF
// avoid typing the size each time
#define SPRINTF(strbuf, ...) snprintf((char*) (strbuf), sizeof(strbuf), __VA_ARGS__)
#endif

#if defined(HAVE_NBGL)
typedef const nbgl_obj_t* (*keyboard_callback_t)(unsigned int event, unsigned int value);
#else
typedef const bagl_element_t* (*keyboard_callback_t)(unsigned int event, unsigned int value);
#endif

void bolos_ux_hslider3_init(unsigned int total_count);
void bolos_ux_hslider3_set_current(unsigned int current);
void bolos_ux_hslider3_next(void);
void bolos_ux_hslider3_previous(void);

// all screens
void screen_onboarding_3_restore_init(void);
void screen_onboarding_4_restore_word_init(unsigned int action);

#endif // OS_IO_SEPROXYHAL
14 changes: 11 additions & 3 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ set(GCC_COVERAGE_LINK_FLAGS "--coverage -lgcov")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")

# adding cmake module directory
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# guard against in-source builds
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build \
Expand All @@ -39,12 +42,17 @@ add_compile_definitions(TEST)
add_compile_definitions(SCREEN_SIZE_WALLET)
add_compile_definitions(OS_IO_SEPROXYHAL)

include_directories(../../src ./mocks/)
find_package(Sodium REQUIRED)

include_directories(../../src ./mocks/ libsodium/)

add_executable(test_nbgl_mnemonic test_nbgl_mnemonic.c)

add_library(nbgl SHARED ../../src/ux_common/onboarding_seed_rom_variables.c ../../src/nbgl/mnemonic.c)
add_library(nbgl SHARED
../../src/ux_common/onboarding_seed_rom_variables.c
../../src/ux_common/onboarding_seed_bip39.c
../../src/nbgl/mnemonic.c)

target_link_libraries(test_nbgl_mnemonic PUBLIC cmocka gcov nbgl)
target_link_libraries(test_nbgl_mnemonic PUBLIC cmocka gcov nbgl sodium)

add_test(test_nbgl_mnemonic test_nbgl_mnemonic)
Loading

0 comments on commit 7795ade

Please sign in to comment.