From 438965a4c7ed5352c6949b2dfc347861bd9ad688 Mon Sep 17 00:00:00 2001 From: Simone Baratta Date: Mon, 2 Dec 2019 15:00:02 +0100 Subject: [PATCH 1/4] cmake: Extract some of the common source files to avoid recompilation. --- src/CMakeLists.txt | 118 ++++++++++++++----- src/commander/commander.c | 1 + src/hww.c | 1 + src/u2f.c | 1 + src/usart/usart_hww.c | 1 - src/usb/class/usb_desc.h | 112 ------------------ src/usb/usb.c | 1 + src/usb/usb_desc_bytes.h | 114 ++++++++++++++++++ test/device-test/CMakeLists.txt | 77 +++++++----- test/device-test/src/framework/test_common.c | 1 + test/unit-test/CMakeLists.txt | 6 +- 11 files changed, 258 insertions(+), 175 deletions(-) create mode 100644 src/usb/usb_desc_bytes.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 02b917f48..2e67ef4b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -set(DBB-FIRMWARE-SOURCES - ${CMAKE_SOURCE_DIR}/src/firmware_main_loop.c +set(DBB-FIRMWARE-COMMON-SOURCES ${CMAKE_SOURCE_DIR}/src/commander/commander.c - ${CMAKE_SOURCE_DIR}/src/commander/commander_btc.c ${CMAKE_SOURCE_DIR}/src/commander/commander_states.c ${CMAKE_SOURCE_DIR}/src/keystore.c ${CMAKE_SOURCE_DIR}/src/random.c @@ -27,9 +25,6 @@ set(DBB-FIRMWARE-SOURCES ${CMAKE_SOURCE_DIR}/src/hww.c ${CMAKE_SOURCE_DIR}/src/memory/bitbox02_smarteeprom.c ${CMAKE_SOURCE_DIR}/src/memory/memory.c - ${CMAKE_SOURCE_DIR}/src/memory/mpu.c - ${CMAKE_SOURCE_DIR}/src/memory/nvmctrl.c - ${CMAKE_SOURCE_DIR}/src/memory/smarteeprom.c ${CMAKE_SOURCE_DIR}/src/salt.c ${CMAKE_SOURCE_DIR}/src/i2c_ecc.c ${CMAKE_SOURCE_DIR}/src/touch/gestures.c @@ -60,19 +55,12 @@ set(DBB-FIRMWARE-SOURCES ${CMAKE_SOURCE_DIR}/src/workflow/backup.c ${CMAKE_SOURCE_DIR}/src/workflow/reset.c ${CMAKE_SOURCE_DIR}/src/workflow/restore.c - ${CMAKE_SOURCE_DIR}/src/apps/btc/btc.c - ${CMAKE_SOURCE_DIR}/src/apps/btc/btc_common.c - ${CMAKE_SOURCE_DIR}/src/apps/btc/btc_params.c - ${CMAKE_SOURCE_DIR}/src/apps/btc/btc_sign.c - ${CMAKE_SOURCE_DIR}/src/apps/btc/btc_bip143.c ${CMAKE_SOURCE_DIR}/src/queue.c ${CMAKE_SOURCE_DIR}/src/usb/usb_processing.c ) -set(DBB-FIRMWARE-SOURCES ${DBB-FIRMWARE-SOURCES} PARENT_SCOPE) +set(DBB-FIRMWARE-COMMON-SOURCES ${DBB-FIRMWARE-COMMON-SOURCES} PARENT_SCOPE) set(DBB-FIRMWARE-USB-SOURCES - ${CMAKE_SOURCE_DIR}/src/usb/usb.c - ${CMAKE_SOURCE_DIR}/src/usb/usb_frame.c ${CMAKE_SOURCE_DIR}/src/usb/usb_packet.c ${CMAKE_SOURCE_DIR}/src/u2f/u2f_packet.c ${CMAKE_SOURCE_DIR}/src/workflow/async.c @@ -85,7 +73,6 @@ set(DBB-FIRMWARE-USART-SOURCES set(DBB-FIRMWARE-USART-SOURCES ${DBB-FIRMWARE-USART-SOURCES} PARENT_SCOPE) set(DBB-FIRMWARE-UI-SOURCES - ${CMAKE_SOURCE_DIR}/src/screen.c ${CMAKE_SOURCE_DIR}/src/ui/ugui/ugui.c ${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_9X9.c ${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_11X12.c @@ -145,30 +132,62 @@ set(DBB-BOOTLOADER-SOURCES set(DBB-BOOTLOADER-SOURCES ${DBB-BOOTLOADER-SOURCES} PARENT_SCOPE) set(DRIVER-SOURCES - ${CMAKE_SOURCE_DIR}/src/platform/platform_init.c + ${CMAKE_SOURCE_DIR}/src/memory/mpu.c + ${CMAKE_SOURCE_DIR}/src/memory/nvmctrl.c + ${CMAKE_SOURCE_DIR}/src/memory/smarteeprom.c + ${CMAKE_SOURCE_DIR}/src/screen.c ${CMAKE_SOURCE_DIR}/src/platform/driver_init.c + ${CMAKE_SOURCE_DIR}/src/platform/platform_init.c ${CMAKE_SOURCE_DIR}/src/qtouch/qtouch.c ${CMAKE_SOURCE_DIR}/src/ui/oled/oled.c ) set(DRIVER-SOURCES ${DRIVER-SOURCES} PARENT_SCOPE) +set(APP-BTC-SOURCES + ${CMAKE_SOURCE_DIR}/src/commander/commander_btc.c + ${CMAKE_SOURCE_DIR}/src/apps/btc/btc.c + ${CMAKE_SOURCE_DIR}/src/apps/btc/btc_common.c + ${CMAKE_SOURCE_DIR}/src/apps/btc/btc_params.c + ${CMAKE_SOURCE_DIR}/src/apps/btc/btc_sign.c + ${CMAKE_SOURCE_DIR}/src/apps/btc/btc_bip143.c + ) +set(APP-BTC-SOURCES ${APP-BTC-SOURCES} PARENT_SCOPE) + +# Modules that provide HW support for the BitBox02, +# and don't depend on any PRODUCT_* macro definition. set(PLATFORM-BITBOX02-SOURCES - ${CMAKE_SOURCE_DIR}/src/sd_mmc/sd_mmc_start.c ${CMAKE_SOURCE_DIR}/src/usb/class/hid/hid.c ${CMAKE_SOURCE_DIR}/src/usb/class/hid/hww/hid_hww.c ${DBB-FIRMWARE-USB-SOURCES} ) set(PLATFORM-BITBOX02-SOURCES ${PLATFORM-BITBOX02-SOURCES} PARENT_SCOPE) +# Modules that provide HW support for the BitBoxBase, +# and don't depend on any PRODUCT_* macro definition. set(PLATFORM-BITBOXBASE-SOURCES ${CMAKE_SOURCE_DIR}/src/platform/bitboxbase/leds.c - ${CMAKE_SOURCE_DIR}/src/usart/usart.c ${CMAKE_SOURCE_DIR}/src/usart/usart_hww.c ${DBB-FIRMWARE-USART-SOURCES} ) set(PLATFORM-BITBOXBASE-SOURCES ${PLATFORM-BITBOXBASE-SOURCES} PARENT_SCOPE) +# Modules specific to the BitBoxBase platform, +# that depend on the PRODUCT_* macros. +set(BITBOXBASE-ONLY-SOURCES + ${CMAKE_SOURCE_DIR}/src/usart/usart.c + ) + +# Modules specific to the BitBox02 platform, +# that depend on the PRODUCT_* macros. +set(BITBOX02-ONLY-SOURCES + ${CMAKE_SOURCE_DIR}/src/usb/usb.c + ${CMAKE_SOURCE_DIR}/src/usb/usb_frame.c + ${CMAKE_SOURCE_DIR}/src/sd_mmc/sd_mmc_start.c + ) + set(BITBOXBASE-FIRMWARE-SOURCES + ${DBB-FIRMWARE-COMMON-SOURCES} + ${BITBOXBASE-ONLY-SOURCES} ${CMAKE_SOURCE_DIR}/src/bitboxbase/bitboxbase_background.c ${CMAKE_SOURCE_DIR}/src/bitboxbase/bitboxbase_watchdog.c ${CMAKE_SOURCE_DIR}/src/bitboxbase/bitboxbase_screensaver.c @@ -176,6 +195,14 @@ set(BITBOXBASE-FIRMWARE-SOURCES ) set(BITBOXBASE-FIRMWARE-SOURCES ${BITBOXBASE-FIRMWARE-SOURCES} PARENT_SCOPE) +set(BITBOX02-FIRMWARE-SOURCES + ${DBB-FIRMWARE-COMMON-SOURCES} + ${BITBOX02-ONLY-SOURCES} + ${APP-BTC-SOURCES} + ${CMAKE_SOURCE_DIR}/src/firmware_main_loop.c +) +set(BITBOX02-FIRMWARE-SOURCES ${BITBOX02-FIRMWARE-SOURCES} PARENT_SCOPE) + set(CRYPTOAUTHLIB-SOURCES ${CMAKE_SOURCE_DIR}/src/securechip/securechip.c ) @@ -234,7 +261,6 @@ find_package(Nanopb REQUIRED) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(FIRMWARE-SOURCES - ${DBB-FIRMWARE-SOURCES} ${DBB-FIRMWARE-UI-SOURCES} ${FIRMWARE-DRIVER-SOURCES} ${DRIVER-SOURCES} @@ -368,6 +394,27 @@ if(CMAKE_CROSSCOMPILING) set(HEAP_SIZE "0x18000" CACHE STRING "Specify heap size for bootloader/firmware") set(HEAP_SIZE ${HEAP_SIZE} PARENT_SCOPE) + add_library(bitbox02-platform ${PLATFORM-BITBOX02-SOURCES}) + target_link_libraries(bitbox02-platform asf4-drivers-min) + target_include_directories(bitbox02-platform PRIVATE ${INCLUDES}) + target_include_directories(bitbox02-platform SYSTEM PUBLIC ${SYSTEMINCLUDES}) + target_include_directories(bitbox02-platform SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) + target_include_directories(bitbox02-platform SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/src) + + #if (CMAKE_CROSSCOMPILING) + # # The USB stack uses some of the usb includes, which in turn forcefully + # # includes stuff from the drivers... Better separation could be helpful here. + # get_target_property(asf4-includes asf4-drivers-min INCLUDE_DIRECTORIES) + # target_include_directories(bitbox02-platform SYSTEM PUBLIC ${asf4-includes}) + #endif() + + add_library(bitboxbase-platform ${PLATFORM-BITBOXBASE-SOURCES}) + target_link_libraries(bitboxbase-platform asf4-drivers) + target_include_directories(bitboxbase-platform PRIVATE ${INCLUDES}) + target_include_directories(bitboxbase-platform SYSTEM PUBLIC ${SYSTEMINCLUDES}) + target_include_directories(bitboxbase-platform SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) + target_include_directories(bitboxbase-platform SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/src) + # If a bootloader that locks the bootloader is flashed the bootloader area is permanently read-only. set(BOOTLOADERS-BITBOX02 bootloader # Runs signed firmware @@ -419,11 +466,13 @@ if(CMAKE_CROSSCOMPILING) endforeach(bootloader) foreach(bootloader ${BOOTLOADERS-BITBOX02}) - target_sources(${bootloader}.elf PRIVATE ${PLATFORM-BITBOX02-SOURCES}) + target_link_libraries(${bootloader}.elf PRIVATE bitbox02-platform) + target_sources(${bootloader}.elf PRIVATE ${BITBOX02-ONLY-SOURCES}) endforeach(bootloader) foreach(bootloader ${BOOTLOADERS-BITBOXBASE}) - target_sources(${bootloader}.elf PRIVATE ${PLATFORM-BITBOXBASE-SOURCES}) + target_link_libraries(${bootloader}.elf PRIVATE bitboxbase-platform) + target_sources(${bootloader}.elf PRIVATE ${BITBOXBASE-ONLY-SOURCES}) endforeach(bootloader) target_compile_definitions(bootloader.elf PRIVATE PRODUCT_BITBOX_MULTI) @@ -497,7 +546,7 @@ if(CMAKE_CROSSCOMPILING) # Select the smaller version of libc called nano. target_compile_options(${elf} PRIVATE --specs=nano.specs) target_link_libraries(${elf} PRIVATE --specs=nano.specs) - string(FIND ${firmware} semihosting SEMIHOSTING_FOUND) + string(FIND ${elf} semihosting SEMIHOSTING_FOUND) if(SEMIHOSTING_FOUND EQUAL -1) target_compile_options(${elf} PRIVATE --specs=nosys.specs) target_link_libraries(${elf} PRIVATE --specs=nosys.specs) @@ -506,40 +555,51 @@ if(CMAKE_CROSSCOMPILING) target_compile_options(${elf} PRIVATE --specs=rdimon.specs) target_link_libraries(${elf} PRIVATE --specs=rdimon.specs) endif() + string(FIND ${elf} bitboxbase BITBOXBASE_FOUND) + if(BITBOXBASE_FOUND EQUAL -1) + target_sources(${elf} PRIVATE ${BITBOX02-FIRMWARE-SOURCES}) + else() + target_sources(${elf} PRIVATE ${BITBOXBASE-FIRMWARE-SOURCES}) + endif() endforeach(firmware) target_sources(firmware.elf PRIVATE firmware.c) target_compile_definitions(firmware.elf PRIVATE PRODUCT_BITBOX_MULTI "APP_BTC=1" "APP_LTC=1" "APP_ETH=1" "APP_U2F=1") - target_sources(firmware.elf PRIVATE ${FIRMWARE-U2F-SOURCES} ${PLATFORM-BITBOX02-SOURCES}) + target_sources(firmware.elf PRIVATE ${FIRMWARE-U2F-SOURCES}) + target_link_libraries(firmware.elf PRIVATE bitbox02-platform) target_sources(firmware-semihosting.elf PRIVATE firmware.c) - target_sources(firmware-semihosting.elf PRIVATE ${FIRMWARE-U2F-SOURCES} ${PLATFORM-BITBOX02-SOURCES}) + target_sources(firmware-semihosting.elf PRIVATE ${FIRMWARE-U2F-SOURCES}) + target_link_libraries(firmware-semihosting.elf PRIVATE bitbox02-platform) + # Select an implementation of the system calls that can communicate with the debugger target_compile_definitions(firmware-semihosting.elf PRIVATE PRODUCT_BITBOX_MULTI "APP_BTC=1" "APP_LTC=1" "APP_ETH=1" "APP_U2F=1") target_compile_definitions(firmware-semihosting.elf PRIVATE SEMIHOSTING) target_sources(firmware-btc.elf PRIVATE firmware.c) target_compile_definitions(firmware-btc.elf PRIVATE PRODUCT_BITBOX_BTCONLY "APP_BTC=1" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") - target_sources(firmware-btc.elf PRIVATE ${PLATFORM-BITBOX02-SOURCES}) + target_link_libraries(firmware-btc.elf PRIVATE bitbox02-platform) target_sources(firmware-bitboxbase.elf PRIVATE bitboxbase/bitboxbase.c) target_compile_definitions(firmware-bitboxbase.elf PRIVATE PRODUCT_BITBOX_BASE "APP_BTC=0" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") - target_sources(firmware-bitboxbase.elf PRIVATE ${PLATFORM-BITBOXBASE-SOURCES} ${BITBOXBASE-FIRMWARE-SOURCES}) + target_sources(firmware-bitboxbase.elf PRIVATE ${BITBOXBASE-FIRMWARE-SOURCES}) + target_link_libraries(firmware-bitboxbase.elf PRIVATE bitboxbase-platform) target_sources(firmware-bitboxbase-semihosting.elf PRIVATE bitboxbase/bitboxbase.c) target_compile_definitions(firmware-bitboxbase-semihosting.elf PRIVATE PRODUCT_BITBOX_BASE SEMIHOSTING "APP_BTC=0" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") - target_sources(firmware-bitboxbase-semihosting.elf PRIVATE ${PLATFORM-BITBOXBASE-SOURCES} ${BITBOXBASE-FIRMWARE-SOURCES}) + target_sources(firmware-bitboxbase-semihosting.elf PRIVATE ${BITBOXBASE-FIRMWARE-SOURCES}) + target_link_libraries(firmware-bitboxbase-semihosting.elf PRIVATE bitboxbase-platform) target_link_libraries(firmware-bitboxbase.elf PRIVATE bitbox02_rust) add_dependencies(firmware-bitboxbase.elf rust rust-cbindgen) target_sources(factory-setup.elf PRIVATE factorysetup.c) target_compile_definitions(factory-setup.elf PRIVATE PRODUCT_BITBOX02_FACTORYSETUP "APP_BTC=0" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") - target_sources(factory-setup.elf PRIVATE ${PLATFORM-BITBOX02-SOURCES}) + target_link_libraries(factory-setup.elf PRIVATE bitbox02-platform) target_sources(factory-setup-bitboxbase.elf PRIVATE factorysetup.c) target_compile_definitions(factory-setup-bitboxbase.elf PRIVATE PRODUCT_BITBOXBASE_FACTORYSETUP "APP_BTC=0" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") - target_sources(factory-setup-bitboxbase.elf PRIVATE ${PLATFORM-BITBOXBASE-SOURCES}) + target_link_libraries(factory-setup-bitboxbase.elf PRIVATE bitboxbase-platform) foreach(name ${BOOTLOADERS} ${FIRMWARES}) add_custom_command( diff --git a/src/commander/commander.c b/src/commander/commander.c index 18d1def10..339588955 100644 --- a/src/commander/commander.c +++ b/src/commander/commander.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include diff --git a/src/hww.c b/src/hww.c index 62e1fa3ae..891cb7d66 100644 --- a/src/hww.c +++ b/src/hww.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include diff --git a/src/u2f.c b/src/u2f.c index 1b3895a6c..af7ae5053 100644 --- a/src/u2f.c +++ b/src/u2f.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include diff --git a/src/usart/usart_hww.c b/src/usart/usart_hww.c index faa0618b0..008b1c29b 100644 --- a/src/usart/usart_hww.c +++ b/src/usart/usart_hww.c @@ -18,7 +18,6 @@ #include "usart_frame.h" #include "usb/usb_processing.h" -#include #include #include #include diff --git a/src/usb/class/usb_desc.h b/src/usb/class/usb_desc.h index 6b1f1c93e..c879bbe57 100644 --- a/src/usb/class/usb_desc.h +++ b/src/usb/class/usb_desc.h @@ -16,7 +16,6 @@ #define _USB_DESC_H_ #include -#include #ifndef TESTING #include "usb_protocol.h" #include "usb_protocol_hid.h" @@ -28,14 +27,6 @@ #define USB_DESC_IDPRODUCT 0x2403 #define USB_DESC_HWW_EP_IN (1 | USB_EP_DIR_IN) #define USB_DESC_HWW_EP_OUT (2 | USB_EP_DIR_OUT) -#if APP_U2F == 1 -#define USB_DESC_U2F_EP_IN (3 | USB_EP_DIR_IN) -#define USB_DESC_U2F_EP_OUT (4 | USB_EP_DIR_OUT) -#define USB_DESC_IFACE_NUM_U2F 1 -#define USB_DESC_NUM_IFACES 2 -#else -#define USB_DESC_NUM_IFACES 1 -#endif #define USB_DESC_IFACE_NUM_HWW 0 #define USB_DESC_IFACE_LEN 32 #define USB_DESC_CONFIG_LEN 9 @@ -66,69 +57,9 @@ '.', 0, 'c', 0, 'h', 0, #define USB_DESC_IPRODUCT 2 -#if defined(BOOTLOADER) -#if PRODUCT_BITBOX_BTCONLY == 1 -#define USB_DESC_IPRODUCT_STR_DESC \ - 38, /* bLength */ \ - 0x03, /* bDescriptorType */ \ - 'b', 0, 'b', 0, '0', 0, '2', 0, 'b', 0, 't', 0, 'c', 0, '-', 0, 'b', 0, 'o', 0, 'o', 0, \ - 't', 0, 'l', 0, 'o', 0, 'a', 0, 'd', 0, 'e', 0, 'r', 0, -#else -#define USB_DESC_IPRODUCT_STR_DESC \ - 32, /* bLength */ \ - 0x03, /* bDescriptorType */ \ - 'b', 0, 'b', 0, '0', 0, '2', 0, '-', 0, 'b', 0, 'o', 0, 'o', 0, 't', 0, 'l', 0, 'o', 0, \ - 'a', 0, 'd', 0, 'e', 0, 'r', 0, -#endif -#elif FACTORYSETUP == 1 -#define USB_DESC_IPRODUCT_STR_DESC \ - 26, /* bLength */ \ - 0x03, /* bDescriptorType */ \ - 'b', 0, 'b', 0, '0', 0, '2', 0, '-', 0, 'f', 0, 'a', 0, 'c', 0, 't', 0, 'o', 0, 'r', 0, \ - 'y', 0, -#elif PRODUCT_BITBOX_BTCONLY == 1 -#define USB_DESC_IPRODUCT_STR_DESC \ - 24, /* bLength */ \ - 0x03, /* bDescriptorType */ \ - 'B', 0, 'i', 0, 't', 0, 'B', 0, 'o', 0, 'x', 0, '0', 0, '2', 0, 'B', 0, 'T', 0, 'C', 0, -#else -#define USB_DESC_IPRODUCT_STR_DESC \ - 18, /* bLength */ \ - 0x03, /* bDescriptorType */ \ - 'B', 0, 'i', 0, 't', 0, 'B', 0, 'o', 0, 'x', 0, '0', 0, '2', 0, -#endif #define USB_DESC_ISERIALNUM 3 -#if defined(BOOTLOADER_DEVDEVICE) && defined(BOOTLOADER_VERSION_HAS_METADATA) -#define BOOTLOADER_VERSION_APPEND_LEN 4 -#define BOOTLOADER_VERSION_APPEND_W16 '.', 0, 'd', 0, 'e', 0, 'v', 0, -#elif defined(BOOTLOADER_DEVDEVICE) -#define BOOTLOADER_VERSION_APPEND_LEN 4 -#define BOOTLOADER_VERSION_APPEND_W16 '+', 0, 'd', 0, 'e', 0, 'v', 0, -#else -#define BOOTLOADER_VERSION_APPEND_LEN 0 -#define BOOTLOADER_VERSION_APPEND_W16 -#endif - -#ifdef BOOTLOADER -#define USB_DESC_ISERIALNUM_STR_DESC \ - (2 + BOOTLOADER_VERSION_LEN * 2 + BOOTLOADER_VERSION_APPEND_LEN * 2), /* bLength */ \ - 0x03, /* bDescriptorType */ \ - BOOTLOADER_VERSION_W16 BOOTLOADER_VERSION_APPEND_W16 -#else -#define USB_DESC_ISERIALNUM_STR_DESC \ - (2 + DIGITAL_BITBOX_VERSION_LEN * 2), /* bLength */ \ - 0x03, /* bDescriptorType */ \ - DIGITAL_BITBOX_VERSION_W16 -#endif - -#define USB_STR_DESC \ - USB_DESC_LANGID_DESC \ - USB_DESC_IMANUFACT_STR_DESC \ - USB_DESC_IPRODUCT_STR_DESC \ - USB_DESC_ISERIALNUM_STR_DESC - #define USB_DESC_HWW_REPORT_LEN 34 #define USB_DESC_HWW_REPORT \ 0x06, 0xff, 0xff, /* USAGE_PAGE (Vendor Defined) */ \ @@ -199,38 +130,6 @@ USB_DESC_LE16(USB_DESC_HID_EP_SIZE), /* ep_out.wMaxPacketSize */ \ 4 /* ep_out.bInterval */ -#if APP_U2F == 1 -#define USB_DESC_IFACE_U2F \ - 9, /* iface.bLength */ \ - 0x04, /* iface.bDescriptorType: INTERFACE */ \ - USB_DESC_IFACE_NUM_U2F, /* iface.bInterfaceNumber */ \ - 0x00, /* iface.bAlternateSetting */ \ - 0x02, /* iface.bNumEndpoints */ \ - HID_CLASS, /* iface.bInterfaceClass */ \ - USB_SUBCLASS_NO, /* iface.bInterfaceSubClass */ \ - USB_PROTOCOL_NO, /* iface.bInterfaceProtocol */ \ - 0x00, /* iface.iInterface */ \ - 9, /* hid.bLength */ \ - USB_DT_HID, /* hid.bDescriptorType: HID */ \ - USB_DESC_LE16(USB_HID_BDC_V1_11), /* hid.bcdHID */ \ - 0x00, /* hid.bCountryCode */ \ - 0x01, /* hid.bNumDescriptors */ \ - 0x22, /* hid.bRDescriptorType */ \ - USB_DESC_LE16(USB_DESC_U2F_REPORT_LEN), /* hid.wDescriptorLength */ \ - 7, /* ep_in.bLength */ \ - 0x05, /* ep_in.bDescriptorType: ENDPOINT */ \ - USB_DESC_U2F_EP_IN, /* ep_in.bEndpointAddress */ \ - 0x03, /* ep_in.bmAttributes */ \ - USB_DESC_LE16(USB_DESC_HID_EP_SIZE), /* ep_in.wMaxPacketSize */ \ - 4, /* ep_in.bInterval */ \ - 7, /* ep_out.bLength */ \ - 0x05, /* ep_out.bDescriptorType: ENDPOINT */ \ - USB_DESC_U2F_EP_OUT, /* ep_out.bEndpointAddress */ \ - 0x03, /* ep_out.bmAttributes */ \ - USB_DESC_LE16(USB_DESC_HID_EP_SIZE), /* ep_out.wMaxPacketSize */ \ - 4 /* ep_out.bInterval */ -#endif - #define USB_DESC_CONFIG \ USB_DESC_CONFIG_LEN, /* bLength */ \ 0x02, /* bDescriptorType: CONFIGURATION */ \ @@ -257,15 +156,4 @@ USB_DESC_ISERIALNUM, /* iSerialNumber */ \ USB_DESC_BNUMCONFIG /* bNumConfigurations */ -// ** If add an interface, adjust USB_DESC_WTOTALLEN ** -// TODO: USB_DESC_D_MAX_EP_N doesn't exist, but there is CONF_USB_D_NUM_EP_SP -// (= supported endpoints) - is that the one that needs to change? -// ** If add more endpoints, adjust USB_DESC_D_MAX_EP_N ** -#if APP_U2F == 0 -#define USB_DESC_FS USB_DEV_DESC, USB_DESC_CONFIG, USB_DESC_IFACE_HWW, USB_STR_DESC -#else -#define USB_DESC_FS \ - USB_DEV_DESC, USB_DESC_CONFIG, USB_DESC_IFACE_HWW, USB_DESC_IFACE_U2F, USB_STR_DESC -#endif - #endif diff --git a/src/usb/usb.c b/src/usb/usb.c index 6b0af560d..e285294bd 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -16,6 +16,7 @@ #ifndef TESTING #include "hid_hww.h" #include "usb_desc.h" +#include "usb_desc_bytes.h" #include "usbdc.h" #if APP_U2F == 1 #include "u2f.h" diff --git a/src/usb/usb_desc_bytes.h b/src/usb/usb_desc_bytes.h new file mode 100644 index 000000000..d6e7e02f0 --- /dev/null +++ b/src/usb/usb_desc_bytes.h @@ -0,0 +1,114 @@ +#include + +#if APP_U2F == 1 +#define USB_DESC_U2F_EP_IN (3 | USB_EP_DIR_IN) +#define USB_DESC_U2F_EP_OUT (4 | USB_EP_DIR_OUT) +#define USB_DESC_IFACE_NUM_U2F 1 +#define USB_DESC_NUM_IFACES 2 +#else +#define USB_DESC_NUM_IFACES 1 +#endif + +#if APP_U2F == 1 +#define USB_DESC_IFACE_U2F \ + 9, /* iface.bLength */ \ + 0x04, /* iface.bDescriptorType: INTERFACE */ \ + USB_DESC_IFACE_NUM_U2F, /* iface.bInterfaceNumber */ \ + 0x00, /* iface.bAlternateSetting */ \ + 0x02, /* iface.bNumEndpoints */ \ + HID_CLASS, /* iface.bInterfaceClass */ \ + USB_SUBCLASS_NO, /* iface.bInterfaceSubClass */ \ + USB_PROTOCOL_NO, /* iface.bInterfaceProtocol */ \ + 0x00, /* iface.iInterface */ \ + 9, /* hid.bLength */ \ + USB_DT_HID, /* hid.bDescriptorType: HID */ \ + USB_DESC_LE16(USB_HID_BDC_V1_11), /* hid.bcdHID */ \ + 0x00, /* hid.bCountryCode */ \ + 0x01, /* hid.bNumDescriptors */ \ + 0x22, /* hid.bRDescriptorType */ \ + USB_DESC_LE16(USB_DESC_U2F_REPORT_LEN), /* hid.wDescriptorLength */ \ + 7, /* ep_in.bLength */ \ + 0x05, /* ep_in.bDescriptorType: ENDPOINT */ \ + USB_DESC_U2F_EP_IN, /* ep_in.bEndpointAddress */ \ + 0x03, /* ep_in.bmAttributes */ \ + USB_DESC_LE16(USB_DESC_HID_EP_SIZE), /* ep_in.wMaxPacketSize */ \ + 4, /* ep_in.bInterval */ \ + 7, /* ep_out.bLength */ \ + 0x05, /* ep_out.bDescriptorType: ENDPOINT */ \ + USB_DESC_U2F_EP_OUT, /* ep_out.bEndpointAddress */ \ + 0x03, /* ep_out.bmAttributes */ \ + USB_DESC_LE16(USB_DESC_HID_EP_SIZE), /* ep_out.wMaxPacketSize */ \ + 4 /* ep_out.bInterval */ +#endif + +#if defined(BOOTLOADER) +#if PRODUCT_BITBOX_BTCONLY == 1 +#define USB_DESC_IPRODUCT_STR_DESC \ + 38, /* bLength */ \ + 0x03, /* bDescriptorType */ \ + 'b', 0, 'b', 0, '0', 0, '2', 0, 'b', 0, 't', 0, 'c', 0, '-', 0, 'b', 0, 'o', 0, 'o', 0, \ + 't', 0, 'l', 0, 'o', 0, 'a', 0, 'd', 0, 'e', 0, 'r', 0, +#else +#define USB_DESC_IPRODUCT_STR_DESC \ + 32, /* bLength */ \ + 0x03, /* bDescriptorType */ \ + 'b', 0, 'b', 0, '0', 0, '2', 0, '-', 0, 'b', 0, 'o', 0, 'o', 0, 't', 0, 'l', 0, 'o', 0, \ + 'a', 0, 'd', 0, 'e', 0, 'r', 0, +#endif +#elif FACTORYSETUP == 1 +#define USB_DESC_IPRODUCT_STR_DESC \ + 26, /* bLength */ \ + 0x03, /* bDescriptorType */ \ + 'b', 0, 'b', 0, '0', 0, '2', 0, '-', 0, 'f', 0, 'a', 0, 'c', 0, 't', 0, 'o', 0, 'r', 0, \ + 'y', 0, +#elif PRODUCT_BITBOX_BTCONLY == 1 +#define USB_DESC_IPRODUCT_STR_DESC \ + 24, /* bLength */ \ + 0x03, /* bDescriptorType */ \ + 'B', 0, 'i', 0, 't', 0, 'B', 0, 'o', 0, 'x', 0, '0', 0, '2', 0, 'B', 0, 'T', 0, 'C', 0, +#else +#define USB_DESC_IPRODUCT_STR_DESC \ + 18, /* bLength */ \ + 0x03, /* bDescriptorType */ \ + 'B', 0, 'i', 0, 't', 0, 'B', 0, 'o', 0, 'x', 0, '0', 0, '2', 0, +#endif + +#if defined(BOOTLOADER_DEVDEVICE) && defined(BOOTLOADER_VERSION_HAS_METADATA) +#define BOOTLOADER_VERSION_APPEND_LEN 4 +#define BOOTLOADER_VERSION_APPEND_W16 '.', 0, 'd', 0, 'e', 0, 'v', 0, +#elif defined(BOOTLOADER_DEVDEVICE) +#define BOOTLOADER_VERSION_APPEND_LEN 4 +#define BOOTLOADER_VERSION_APPEND_W16 '+', 0, 'd', 0, 'e', 0, 'v', 0, +#else +#define BOOTLOADER_VERSION_APPEND_LEN 0 +#define BOOTLOADER_VERSION_APPEND_W16 +#endif + +#ifdef BOOTLOADER +#define USB_DESC_ISERIALNUM_STR_DESC \ + (2 + BOOTLOADER_VERSION_LEN * 2 + BOOTLOADER_VERSION_APPEND_LEN * 2), /* bLength */ \ + 0x03, /* bDescriptorType */ \ + BOOTLOADER_VERSION_W16 BOOTLOADER_VERSION_APPEND_W16 +#else +#define USB_DESC_ISERIALNUM_STR_DESC \ + (2 + DIGITAL_BITBOX_VERSION_LEN * 2), /* bLength */ \ + 0x03, /* bDescriptorType */ \ + DIGITAL_BITBOX_VERSION_W16 +#endif + +#define USB_STR_DESC \ + USB_DESC_LANGID_DESC \ + USB_DESC_IMANUFACT_STR_DESC \ + USB_DESC_IPRODUCT_STR_DESC \ + USB_DESC_ISERIALNUM_STR_DESC + +// ** If add an interface, adjust USB_DESC_WTOTALLEN ** +// TODO: USB_DESC_D_MAX_EP_N doesn't exist, but there is CONF_USB_D_NUM_EP_SP +// (= supported endpoints) - is that the one that needs to change? +// ** If add more endpoints, adjust USB_DESC_D_MAX_EP_N ** +#if APP_U2F == 0 +#define USB_DESC_FS USB_DEV_DESC, USB_DESC_CONFIG, USB_DESC_IFACE_HWW, USB_STR_DESC +#else +#define USB_DESC_FS \ + USB_DEV_DESC, USB_DESC_CONFIG, USB_DESC_IFACE_HWW, USB_DESC_IFACE_U2F, USB_STR_DESC +#endif diff --git a/test/device-test/CMakeLists.txt b/test/device-test/CMakeLists.txt index e320965e0..74d94e1d5 100644 --- a/test/device-test/CMakeLists.txt +++ b/test/device-test/CMakeLists.txt @@ -18,8 +18,20 @@ include_directories(${NANOPB_INCLUDE_DIRS}) -set(SOURCES - ${DBB-FIRMWARE-SOURCES} +set(BBBASE-SOURCES + ${BITBOXBASE-FIRMWARE-SOURCES} + ${DBB-FIRMWARE-UI-SOURCES} + ${DRIVER-SOURCES} + ${DBB-FIRMWARE-PROTOBUF-SOURCES} + ${CRYPTOAUTHLIB-SOURCES} + ${ETHEREUM-SOURCES} + ${FIRMWARE-U2F-SOURCES} + ${CMAKE_SOURCE_DIR}/src/common_main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/framework/test_common.c +) + +set(BB02-SOURCES + ${BITBOX02-FIRMWARE-SOURCES} ${DBB-FIRMWARE-UI-SOURCES} ${FIRMWARE-DRIVER-SOURCES} ${DRIVER-SOURCES} @@ -44,21 +56,21 @@ set(INCLUDES ${CMAKE_BINARY_DIR}/src ) -add_library(bitbox02-platform +add_library(bitbox02-test-platform STATIC - ${SOURCES} - ${PLATFORM-BITBOX02-SOURCES} + ${BB02-SOURCES} ) -target_include_directories(bitbox02-platform PUBLIC ${INCLUDES}) -target_include_directories(bitbox02-platform SYSTEM PUBLIC ${SYSTEMINCLUDES}) -target_include_directories(bitbox02-platform SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) -target_compile_definitions(bitbox02-platform PUBLIC "PB_NO_PACKED_STRUCTS=1" "PB_FIELD_16BIT=1") -target_compile_definitions(bitbox02-platform PUBLIC "APP_BTC=1" "APP_LTC=1" "APP_U2F=1" "APP_ETH=1") -add_dependencies(bitbox02-platform generate-protobufs) +target_link_libraries(bitbox02-test-platform PUBLIC bitbox02-platform) +target_include_directories(bitbox02-test-platform PUBLIC ${INCLUDES}) +target_include_directories(bitbox02-test-platform SYSTEM PUBLIC ${SYSTEMINCLUDES}) +target_include_directories(bitbox02-test-platform SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) +target_compile_definitions(bitbox02-test-platform PUBLIC "PB_NO_PACKED_STRUCTS=1" "PB_FIELD_16BIT=1") +target_compile_definitions(bitbox02-test-platform PUBLIC "APP_BTC=1" "APP_LTC=1" "APP_U2F=1" "APP_ETH=1") +add_dependencies(bitbox02-test-platform generate-protobufs) # needed to find version.h -target_include_directories(bitbox02-platform SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/src) -target_link_libraries(bitbox02-platform +target_include_directories(bitbox02-test-platform SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/src) +target_link_libraries(bitbox02-test-platform PUBLIC wallycore secp256k1 @@ -74,9 +86,9 @@ target_link_libraries(bitbox02-platform ) # Always enable semihosting for the test firmwares -target_compile_definitions(bitbox02-platform PUBLIC PRODUCT_BITBOX_MULTI SEMIHOSTING) -target_link_libraries(bitbox02-platform PUBLIC --specs=nano.specs --specs=rdimon.specs) -target_compile_options(bitbox02-platform PUBLIC --specs=nano.specs --specs=rdimon.specs) +target_compile_definitions(bitbox02-test-platform PUBLIC PRODUCT_BITBOX_MULTI SEMIHOSTING) +target_link_libraries(bitbox02-test-platform PUBLIC --specs=nano.specs --specs=rdimon.specs) +target_compile_options(bitbox02-test-platform PUBLIC --specs=nano.specs --specs=rdimon.specs) set(BB02_TEST_LIST all_variants_menu @@ -123,7 +135,7 @@ foreach(name ${BB02_TEST_LIST}) target_link_libraries(${elf} PRIVATE c - bitbox02-platform + bitbox02-test-platform asf4-drivers-min ${QTOUCHLIB_A} ${QTOUCHLIB_B} @@ -147,21 +159,21 @@ foreach(name ${BB02_TEST_LIST}) endforeach() -add_library(bitboxbase-platform +add_library(bitboxbase-test-platform STATIC - ${SOURCES} - ${PLATFORM-BITBOXBASE-SOURCES} + ${BBBASE-SOURCES} ) -target_include_directories(bitboxbase-platform PUBLIC ${INCLUDES}) -target_include_directories(bitboxbase-platform SYSTEM PUBLIC ${SYSTEMINCLUDES}) -target_include_directories(bitboxbase-platform SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) -target_compile_definitions(bitboxbase-platform PUBLIC "PB_NO_PACKED_STRUCTS=1" "PB_FIELD_16BIT=1") -target_compile_definitions(bitboxbase-platform PUBLIC "APP_BTC=1" "APP_LTC=1" "APP_U2F=1" "APP_ETH=1") -add_dependencies(bitboxbase-platform generate-protobufs) +target_link_libraries(bitboxbase-test-platform PUBLIC bitboxbase-platform) +target_include_directories(bitboxbase-test-platform PUBLIC ${INCLUDES}) +target_include_directories(bitboxbase-test-platform SYSTEM PUBLIC ${SYSTEMINCLUDES}) +target_include_directories(bitboxbase-test-platform SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) +target_compile_definitions(bitboxbase-test-platform PUBLIC "PB_NO_PACKED_STRUCTS=1" "PB_FIELD_16BIT=1") +target_compile_definitions(bitboxbase-test-platform PUBLIC "APP_BTC=1" "APP_LTC=1" "APP_U2F=1" "APP_ETH=1") +add_dependencies(bitboxbase-test-platform generate-protobufs) # needed to find version.h -target_include_directories(bitboxbase-platform SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/src) -target_link_libraries(bitboxbase-platform +target_include_directories(bitboxbase-test-platform SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/src) +target_link_libraries(bitboxbase-test-platform PUBLIC wallycore secp256k1 @@ -175,11 +187,12 @@ target_link_libraries(bitboxbase-platform ctaes -Wl,-u,exception_table ) +add_dependencies(bitboxbase-test-platform rust-cbindgen) # Always enable semihosting for the test firmwares -target_compile_definitions(bitboxbase-platform PUBLIC PRODUCT_BITBOX_BASE SEMIHOSTING) -target_link_libraries(bitboxbase-platform PUBLIC --specs=nano.specs --specs=rdimon.specs) -target_compile_options(bitboxbase-platform PUBLIC --specs=nano.specs --specs=rdimon.specs) +target_compile_definitions(bitboxbase-test-platform PUBLIC PRODUCT_BITBOX_BASE SEMIHOSTING) +target_link_libraries(bitboxbase-test-platform PUBLIC --specs=nano.specs --specs=rdimon.specs) +target_compile_options(bitboxbase-test-platform PUBLIC --specs=nano.specs --specs=rdimon.specs) set(BBB_TEST_LIST bitboxbase_touch_demo @@ -201,7 +214,7 @@ foreach(name ${BBB_TEST_LIST}) PRIVATE asf4-drivers-min asf4-drivers - bitboxbase-platform + bitboxbase-test-platform c ${QTOUCHLIB_A} ${QTOUCHLIB_B} diff --git a/test/device-test/src/framework/test_common.c b/test/device-test/src/framework/test_common.c index 7223e4dbf..313527c99 100644 --- a/test/device-test/src/framework/test_common.c +++ b/test/device-test/src/framework/test_common.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "screen.h" #include "util.h" diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index 9fdc7badb..4755282b4 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt @@ -19,7 +19,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter -Wno-missing-prototypes -Wno-missing-declarations -Wno-implicit-function-declaration -Wno-bad-function-cast") set(DBB-FILTERED-SOURCES - ${DBB-FIRMWARE-SOURCES} + ${DBB-FIRMWARE-COMMON-SOURCES} ${DBB-FIRMWARE-UI-SOURCES} ${DBB-FIRMWARE-PROTOBUF-SOURCES} ${FIRMWARE-U2F-SOURCES} @@ -46,9 +46,13 @@ find_package(Nanopb REQUIRED) add_library(bitbox STATIC + ${APP-BTC-SOURCES} ${DBB-FILTERED-SOURCES} ${CTAES-SOURCES} ${ETHEREUM-SOURCES} + # The usb.c file mixes together hardware and testing code... This should be split. + ${CMAKE_SOURCE_DIR}/src/usb/usb.c + ${CMAKE_SOURCE_DIR}/src/usb/usb_frame.c framework/mock_blocking.c framework/mock_screen.c framework/mock_screen_stack.c From 505517241a7237a0b7b229ce0151bff64dd39bed Mon Sep 17 00:00:00 2001 From: Simone Baratta Date: Tue, 3 Dec 2019 12:03:06 +0100 Subject: [PATCH 2/4] cmake: Split app sources into separate libraries. As the files related to APP_BTC don't depend on any PRODUCT* macro, but only on the APP_* macros, move those to a separate CMake unit (app_btc-multi, app_btc-btc), to avoid multiple unnecessary compilations. --- src/CMakeLists.txt | 64 ++++++++++++++------- src/apps/btc/btc_sign.c | 15 ++--- src/apps/btc/btc_sign.h | 4 +- src/screen.h | 1 - src/touch/gestures.h | 1 + src/usb/class/hid/hid.c | 2 +- src/usb/class/usb_desc.h | 32 +---------- src/usb/usb_desc_bytes.h | 77 +++++++++++++++++++++++++- src/usb/usb_frame.h | 2 +- src/workflow/reboot.c | 1 + test/device-test/CMakeLists.txt | 6 +- test/device-test/include/test_common.h | 1 + test/unit-test/CMakeLists.txt | 1 + test/unit-test/test_btc_sign.c | 14 ++--- 14 files changed, 144 insertions(+), 77 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2e67ef4b0..105c2e0d4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,7 +20,6 @@ set(DBB-FIRMWARE-COMMON-SOURCES ${CMAKE_SOURCE_DIR}/src/random.c ${CMAKE_SOURCE_DIR}/src/attestation.c ${CMAKE_SOURCE_DIR}/src/hardfault.c - ${CMAKE_SOURCE_DIR}/src/util.c ${CMAKE_SOURCE_DIR}/src/sd.c ${CMAKE_SOURCE_DIR}/src/hww.c ${CMAKE_SOURCE_DIR}/src/memory/bitbox02_smarteeprom.c @@ -113,7 +112,6 @@ set(DBB-FIRMWARE-UI-SOURCES set(DBB-FIRMWARE-UI-SOURCES ${DBB-FIRMWARE-UI-SOURCES} PARENT_SCOPE) set(DBB-BOOTLOADER-SOURCES - ${CMAKE_SOURCE_DIR}/src/util.c ${CMAKE_SOURCE_DIR}/src/pukcc/curve_p256.c ${CMAKE_SOURCE_DIR}/src/pukcc/pukcc.c ${CMAKE_SOURCE_DIR}/src/bootloader/bootloader.c @@ -143,16 +141,6 @@ set(DRIVER-SOURCES ) set(DRIVER-SOURCES ${DRIVER-SOURCES} PARENT_SCOPE) -set(APP-BTC-SOURCES - ${CMAKE_SOURCE_DIR}/src/commander/commander_btc.c - ${CMAKE_SOURCE_DIR}/src/apps/btc/btc.c - ${CMAKE_SOURCE_DIR}/src/apps/btc/btc_common.c - ${CMAKE_SOURCE_DIR}/src/apps/btc/btc_params.c - ${CMAKE_SOURCE_DIR}/src/apps/btc/btc_sign.c - ${CMAKE_SOURCE_DIR}/src/apps/btc/btc_bip143.c - ) -set(APP-BTC-SOURCES ${APP-BTC-SOURCES} PARENT_SCOPE) - # Modules that provide HW support for the BitBox02, # and don't depend on any PRODUCT_* macro definition. set(PLATFORM-BITBOX02-SOURCES @@ -180,6 +168,7 @@ set(BITBOXBASE-ONLY-SOURCES # Modules specific to the BitBox02 platform, # that depend on the PRODUCT_* macros. set(BITBOX02-ONLY-SOURCES + ${CMAKE_SOURCE_DIR}/src/usb/usb_frame.c ${CMAKE_SOURCE_DIR}/src/usb/usb.c ${CMAKE_SOURCE_DIR}/src/usb/usb_frame.c ${CMAKE_SOURCE_DIR}/src/sd_mmc/sd_mmc_start.c @@ -198,7 +187,6 @@ set(BITBOXBASE-FIRMWARE-SOURCES ${BITBOXBASE-FIRMWARE-SOURCES} PARENT_SCOPE) set(BITBOX02-FIRMWARE-SOURCES ${DBB-FIRMWARE-COMMON-SOURCES} ${BITBOX02-ONLY-SOURCES} - ${APP-BTC-SOURCES} ${CMAKE_SOURCE_DIR}/src/firmware_main_loop.c ) set(BITBOX02-FIRMWARE-SOURCES ${BITBOX02-FIRMWARE-SOURCES} PARENT_SCOPE) @@ -253,13 +241,47 @@ set(SYSTEMINCLUDES ${SYSTEMINCLUDES} PARENT_SCOPE) #----------------------------------------------------------------------------- # Build embedded firmware - # TODO: Not needed when building bootlaoder.. # Since the nanopb is included in the source tree and not in the sysroot (/usr/local/arm-none-eabi) we have to disable searching in the sysroot. set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) find_package(Nanopb REQUIRED) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(APP-BTC-SOURCES + ${CMAKE_SOURCE_DIR}/src/commander/commander_btc.c + ${CMAKE_SOURCE_DIR}/src/apps/btc/btc.c + ${CMAKE_SOURCE_DIR}/src/apps/btc/btc_common.c + ${CMAKE_SOURCE_DIR}/src/apps/btc/btc_params.c + ${CMAKE_SOURCE_DIR}/src/apps/btc/btc_sign.c + ${CMAKE_SOURCE_DIR}/src/apps/btc/btc_bip143.c + ) +set(APP-BTC-SOURCES ${APP-BTC-SOURCES} PARENT_SCOPE) + +get_property(WALLY_INCLUDES TARGET wallycore PROPERTY INTERFACE_INCLUDE_DIRECTORIES) + +add_library(util ${CMAKE_SOURCE_DIR}/src/util.c) +target_include_directories(util PRIVATE ${INCLUDES}) +target_include_directories(util SYSTEM PUBLIC ${SYSTEMINCLUDES}) +target_include_directories(util SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) +target_include_directories(util SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/src) + +add_library(app_btc-btc ${APP-BTC-SOURCES}) +target_compile_definitions(app_btc-btc PUBLIC "APP_BTC=1" "APP_LTC=0") +target_include_directories(app_btc-btc PRIVATE ${INCLUDES}) +target_include_directories(app_btc-btc SYSTEM PUBLIC ${SYSTEMINCLUDES}) +target_include_directories(app_btc-btc SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) +target_include_directories(app_btc-btc SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/src) +target_link_libraries(app_btc-btc noiseprotocol wallycore secp256k1 util) + +add_library(app_btc-multi ${APP-BTC-SOURCES}) +target_compile_definitions(app_btc-multi PUBLIC "APP_BTC=1" "APP_LTC=1") +target_compile_definitions(app_btc-multi PRIVATE "NO_PLATFORM_CONFIGURED") +target_include_directories(app_btc-multi PRIVATE ${INCLUDES}) +target_include_directories(app_btc-multi SYSTEM PUBLIC ${SYSTEMINCLUDES}) +target_include_directories(app_btc-multi SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) +target_include_directories(app_btc-multi SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/src) +target_link_libraries(app_btc-multi noiseprotocol wallycore secp256k1 util) + set(FIRMWARE-SOURCES ${DBB-FIRMWARE-UI-SOURCES} ${FIRMWARE-DRIVER-SOURCES} @@ -395,7 +417,7 @@ if(CMAKE_CROSSCOMPILING) set(HEAP_SIZE ${HEAP_SIZE} PARENT_SCOPE) add_library(bitbox02-platform ${PLATFORM-BITBOX02-SOURCES}) - target_link_libraries(bitbox02-platform asf4-drivers-min) + target_link_libraries(bitbox02-platform asf4-drivers-min util) target_include_directories(bitbox02-platform PRIVATE ${INCLUDES}) target_include_directories(bitbox02-platform SYSTEM PUBLIC ${SYSTEMINCLUDES}) target_include_directories(bitbox02-platform SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) @@ -409,7 +431,7 @@ if(CMAKE_CROSSCOMPILING) #endif() add_library(bitboxbase-platform ${PLATFORM-BITBOXBASE-SOURCES}) - target_link_libraries(bitboxbase-platform asf4-drivers) + target_link_libraries(bitboxbase-platform asf4-drivers util) target_include_directories(bitboxbase-platform PRIVATE ${INCLUDES}) target_include_directories(bitboxbase-platform SYSTEM PUBLIC ${SYSTEMINCLUDES}) target_include_directories(bitboxbase-platform SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) @@ -455,6 +477,7 @@ if(CMAKE_CROSSCOMPILING) target_compile_options(${elf} PRIVATE --specs=nano.specs) target_link_libraries(${elf} PRIVATE --specs=nano.specs) string(FIND ${bootloader} semihosting SEMIHOSTING_FOUND) + target_compile_definitions(${elf} PRIVATE "APP_U2F=0" "APP_BTC=0" "APP_ETH=0" "APP_LTC=0") if(SEMIHOSTING_FOUND EQUAL -1) target_compile_options(${elf} PRIVATE --specs=nosys.specs) target_link_libraries(${elf} PRIVATE --specs=nosys.specs) @@ -564,21 +587,24 @@ if(CMAKE_CROSSCOMPILING) endforeach(firmware) target_sources(firmware.elf PRIVATE firmware.c) - target_compile_definitions(firmware.elf PRIVATE PRODUCT_BITBOX_MULTI "APP_BTC=1" "APP_LTC=1" "APP_ETH=1" "APP_U2F=1") + target_compile_definitions(firmware.elf PRIVATE PRODUCT_BITBOX_MULTI "APP_ETH=1" "APP_U2F=1") target_sources(firmware.elf PRIVATE ${FIRMWARE-U2F-SOURCES}) target_link_libraries(firmware.elf PRIVATE bitbox02-platform) + target_link_libraries(firmware.elf PRIVATE app_btc-multi) target_sources(firmware-semihosting.elf PRIVATE firmware.c) target_sources(firmware-semihosting.elf PRIVATE ${FIRMWARE-U2F-SOURCES}) target_link_libraries(firmware-semihosting.elf PRIVATE bitbox02-platform) + target_link_libraries(firmware-semihosting.elf PRIVATE app_btc-multi) # Select an implementation of the system calls that can communicate with the debugger - target_compile_definitions(firmware-semihosting.elf PRIVATE PRODUCT_BITBOX_MULTI "APP_BTC=1" "APP_LTC=1" "APP_ETH=1" "APP_U2F=1") + target_compile_definitions(firmware-semihosting.elf PRIVATE PRODUCT_BITBOX_MULTI "APP_ETH=1" "APP_U2F=1") target_compile_definitions(firmware-semihosting.elf PRIVATE SEMIHOSTING) target_sources(firmware-btc.elf PRIVATE firmware.c) - target_compile_definitions(firmware-btc.elf PRIVATE PRODUCT_BITBOX_BTCONLY "APP_BTC=1" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") + target_compile_definitions(firmware-btc.elf PRIVATE PRODUCT_BITBOX_BTCONLY "APP_ETH=0" "APP_U2F=0") target_link_libraries(firmware-btc.elf PRIVATE bitbox02-platform) + target_link_libraries(firmware-btc.elf PRIVATE app_btc-btc) target_sources(firmware-bitboxbase.elf PRIVATE bitboxbase/bitboxbase.c) target_compile_definitions(firmware-bitboxbase.elf PRIVATE PRODUCT_BITBOX_BASE "APP_BTC=0" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") diff --git a/src/apps/btc/btc_sign.c b/src/apps/btc/btc_sign.c index 0d368d7d2..dc2ff8416 100644 --- a/src/apps/btc/btc_sign.c +++ b/src/apps/btc/btc_sign.c @@ -81,7 +81,7 @@ static void _sha256(const uint8_t* bytes, size_t bytes_len, uint8_t* out) sha256_finish(&ctx, out); } -static void _reset(void) +void btc_sign_reset(void) { _state = STATE_INIT; _coin_params = NULL; @@ -103,7 +103,7 @@ static void _reset(void) static app_btc_sign_error_t _error(app_btc_sign_error_t err) { - _reset(); + btc_sign_reset(); return err; } @@ -134,7 +134,7 @@ app_btc_sign_error_t app_btc_sign_init( // legacy not supported return _error(APP_BTC_SIGN_ERR_INVALID_INPUT); } - _reset(); + btc_sign_reset(); _coin_params = coin_params; _script_type = request->script_type; _bip44_account = request->bip44_account; @@ -292,7 +292,7 @@ static app_btc_sign_error_t _sign_input_pass2( next_out->index = _index; } else { // Done with inputs pass2 -> done completely. - _reset(); + btc_sign_reset(); next_out->type = BTCSignNextResponse_Type_DONE; } return APP_BTC_SIGN_OK; @@ -472,10 +472,3 @@ app_btc_sign_error_t app_btc_sign_output( } return APP_BTC_SIGN_OK; } - -#ifdef TESTING -void tst_app_btc_reset(void) -{ - _reset(); -} -#endif diff --git a/src/apps/btc/btc_sign.h b/src/apps/btc/btc_sign.h index 6999ea4f9..b76d76f9a 100644 --- a/src/apps/btc/btc_sign.h +++ b/src/apps/btc/btc_sign.h @@ -39,8 +39,6 @@ app_btc_sign_input(const BTCSignInputRequest* request, BTCSignNextResponse* next USE_RESULT app_btc_sign_error_t app_btc_sign_output(const BTCSignOutputRequest* request, BTCSignNextResponse* next_out); -#ifdef TESTING -void tst_app_btc_reset(void); -#endif +void btc_sign_reset(void); #endif diff --git a/src/screen.h b/src/screen.h index 836e16058..1537a77f7 100644 --- a/src/screen.h +++ b/src/screen.h @@ -19,7 +19,6 @@ #include #include -#include #include // TODO: allow updating diff --git a/src/touch/gestures.h b/src/touch/gestures.h index 8165561d1..75baad6bd 100644 --- a/src/touch/gestures.h +++ b/src/touch/gestures.h @@ -17,6 +17,7 @@ #include +#include #include #include diff --git a/src/usb/class/hid/hid.c b/src/usb/class/hid/hid.c index f6773ab3b..8a886041a 100644 --- a/src/usb/class/hid/hid.c +++ b/src/usb/class/hid/hid.c @@ -13,7 +13,7 @@ // limitations under the License. #include "hid.h" -#include "usb_desc.h" +//#include "usb_desc.h" #if !defined(TESTING) #include "usb_protocol.h" #endif diff --git a/src/usb/class/usb_desc.h b/src/usb/class/usb_desc.h index c879bbe57..8897a804a 100644 --- a/src/usb/class/usb_desc.h +++ b/src/usb/class/usb_desc.h @@ -27,10 +27,8 @@ #define USB_DESC_IDPRODUCT 0x2403 #define USB_DESC_HWW_EP_IN (1 | USB_EP_DIR_IN) #define USB_DESC_HWW_EP_OUT (2 | USB_EP_DIR_OUT) -#define USB_DESC_IFACE_NUM_HWW 0 -#define USB_DESC_IFACE_LEN 32 -#define USB_DESC_CONFIG_LEN 9 -#define USB_DESC_WTOTALLEN (USB_DESC_CONFIG_LEN + USB_DESC_IFACE_LEN * USB_DESC_NUM_IFACES) +#define USB_DESC_U2F_EP_IN (3 | USB_EP_DIR_IN) +#define USB_DESC_U2F_EP_OUT (4 | USB_EP_DIR_OUT) #define USB_DESC_BMAXPKSZ0 0x40 #define USB_DESC_BCDUSB 0x200 // 0x0200 => USB 2.0 version; 0x0210 => USB 2.1 version #define USB_DESC_BCDDEVICE 0x100 @@ -130,30 +128,4 @@ USB_DESC_LE16(USB_DESC_HID_EP_SIZE), /* ep_out.wMaxPacketSize */ \ 4 /* ep_out.bInterval */ -#define USB_DESC_CONFIG \ - USB_DESC_CONFIG_LEN, /* bLength */ \ - 0x02, /* bDescriptorType: CONFIGURATION */ \ - USB_DESC_LE16(USB_DESC_WTOTALLEN), /* wTotalLength */ \ - USB_DESC_NUM_IFACES, /* bNumInterfaces */ \ - USB_DESC_BCONFIGVAL, /* bConfigurationValue */ \ - 0x00, /* iConfiguration */ \ - USB_DESC_BMATTRI, /* bmAttributes */ \ - USB_DESC_BMAXPOWER /* bMaxPower */ - -#define USB_DEV_DESC \ - 18, /* bLength */ \ - 0x01, /* bDescriptorType: DEVICE */ \ - USB_DESC_LE16(USB_DESC_BCDUSB), /* bcdUSB */ \ - USB_CLASS_NO, /* bDeviceClass */ \ - USB_SUBCLASS_NO, /* bDeviceSubClass */ \ - USB_PROTOCOL_NO, /* bDeviceProtocol */ \ - USB_DESC_BMAXPKSZ0, /* bMaxPacketSize0 */ \ - USB_DESC_LE16(USB_DESC_IDVENDER), /* idVendor */ \ - USB_DESC_LE16(USB_DESC_IDPRODUCT), /* idProduct */ \ - USB_DESC_LE16(USB_DESC_BCDDEVICE), /* bcdDevice */ \ - USB_DESC_IMANUFACT, /* iManufacturer */ \ - USB_DESC_IPRODUCT, /* iProduct */ \ - USB_DESC_ISERIALNUM, /* iSerialNumber */ \ - USB_DESC_BNUMCONFIG /* bNumConfigurations */ - #endif diff --git a/src/usb/usb_desc_bytes.h b/src/usb/usb_desc_bytes.h index d6e7e02f0..620119ef5 100644 --- a/src/usb/usb_desc_bytes.h +++ b/src/usb/usb_desc_bytes.h @@ -1,3 +1,6 @@ +#ifndef __USB_DESC_BYTES_H +#define __USB_DESC_BYTES_H + #include #if APP_U2F == 1 @@ -102,6 +105,76 @@ USB_DESC_IPRODUCT_STR_DESC \ USB_DESC_ISERIALNUM_STR_DESC +#if APP_U2F == 1 +#define USB_DESC_IFACE_NUM_U2F 1 +#define USB_DESC_NUM_IFACES 2 +#else +#define USB_DESC_NUM_IFACES 1 +#endif + +#define USB_DESC_IFACE_NUM_HWW 0 +#define USB_DESC_IFACE_LEN 32 +#define USB_DESC_CONFIG_LEN 9 +#define USB_DESC_WTOTALLEN (USB_DESC_CONFIG_LEN + USB_DESC_IFACE_LEN * USB_DESC_NUM_IFACES) + +#define USB_DESC_CONFIG \ + USB_DESC_CONFIG_LEN, /* bLength */ \ + 0x02, /* bDescriptorType: CONFIGURATION */ \ + USB_DESC_LE16(USB_DESC_WTOTALLEN), /* wTotalLength */ \ + USB_DESC_NUM_IFACES, /* bNumInterfaces */ \ + USB_DESC_BCONFIGVAL, /* bConfigurationValue */ \ + 0x00, /* iConfiguration */ \ + USB_DESC_BMATTRI, /* bmAttributes */ \ + USB_DESC_BMAXPOWER /* bMaxPower */ + +#if APP_U2F == 1 +#define USB_DESC_IFACE_U2F \ + 9, /* iface.bLength */ \ + 0x04, /* iface.bDescriptorType: INTERFACE */ \ + USB_DESC_IFACE_NUM_U2F, /* iface.bInterfaceNumber */ \ + 0x00, /* iface.bAlternateSetting */ \ + 0x02, /* iface.bNumEndpoints */ \ + HID_CLASS, /* iface.bInterfaceClass */ \ + USB_SUBCLASS_NO, /* iface.bInterfaceSubClass */ \ + USB_PROTOCOL_NO, /* iface.bInterfaceProtocol */ \ + 0x00, /* iface.iInterface */ \ + 9, /* hid.bLength */ \ + USB_DT_HID, /* hid.bDescriptorType: HID */ \ + USB_DESC_LE16(USB_HID_BDC_V1_11), /* hid.bcdHID */ \ + 0x00, /* hid.bCountryCode */ \ + 0x01, /* hid.bNumDescriptors */ \ + 0x22, /* hid.bRDescriptorType */ \ + USB_DESC_LE16(USB_DESC_U2F_REPORT_LEN), /* hid.wDescriptorLength */ \ + 7, /* ep_in.bLength */ \ + 0x05, /* ep_in.bDescriptorType: ENDPOINT */ \ + USB_DESC_U2F_EP_IN, /* ep_in.bEndpointAddress */ \ + 0x03, /* ep_in.bmAttributes */ \ + USB_DESC_LE16(USB_DESC_HID_EP_SIZE), /* ep_in.wMaxPacketSize */ \ + 4, /* ep_in.bInterval */ \ + 7, /* ep_out.bLength */ \ + 0x05, /* ep_out.bDescriptorType: ENDPOINT */ \ + USB_DESC_U2F_EP_OUT, /* ep_out.bEndpointAddress */ \ + 0x03, /* ep_out.bmAttributes */ \ + USB_DESC_LE16(USB_DESC_HID_EP_SIZE), /* ep_out.wMaxPacketSize */ \ + 4 /* ep_out.bInterval */ +#endif + +#define USB_DEV_DESC \ + 18, /* bLength */ \ + 0x01, /* bDescriptorType: DEVICE */ \ + USB_DESC_LE16(USB_DESC_BCDUSB), /* bcdUSB */ \ + USB_CLASS_NO, /* bDeviceClass */ \ + USB_SUBCLASS_NO, /* bDeviceSubClass */ \ + USB_PROTOCOL_NO, /* bDeviceProtocol */ \ + USB_DESC_BMAXPKSZ0, /* bMaxPacketSize0 */ \ + USB_DESC_LE16(USB_DESC_IDVENDER), /* idVendor */ \ + USB_DESC_LE16(USB_DESC_IDPRODUCT), /* idProduct */ \ + USB_DESC_LE16(USB_DESC_BCDDEVICE), /* bcdDevice */ \ + USB_DESC_IMANUFACT, /* iManufacturer */ \ + USB_DESC_IPRODUCT, /* iProduct */ \ + USB_DESC_ISERIALNUM, /* iSerialNumber */ \ + USB_DESC_BNUMCONFIG /* bNumConfigurations */ + // ** If add an interface, adjust USB_DESC_WTOTALLEN ** // TODO: USB_DESC_D_MAX_EP_N doesn't exist, but there is CONF_USB_D_NUM_EP_SP // (= supported endpoints) - is that the one that needs to change? @@ -111,4 +184,6 @@ #else #define USB_DESC_FS \ USB_DEV_DESC, USB_DESC_CONFIG, USB_DESC_IFACE_HWW, USB_DESC_IFACE_U2F, USB_STR_DESC -#endif +#endif // APP_U2F + +#endif // __USB_DESC_BYTES_H diff --git a/src/usb/usb_frame.h b/src/usb/usb_frame.h index 7d16bd612..938a2746c 100644 --- a/src/usb/usb_frame.h +++ b/src/usb/usb_frame.h @@ -18,7 +18,7 @@ #include #include "queue.h" -#include +#include "usb_desc.h" #define FRAME_TYPE_MASK 0x80 // Frame type mask #define FRAME_TYPE_INIT 0x80 // Initial frame identifier diff --git a/src/workflow/reboot.c b/src/workflow/reboot.c index c48ebabbf..018ae8cb9 100644 --- a/src/workflow/reboot.c +++ b/src/workflow/reboot.c @@ -15,6 +15,7 @@ #include "reboot.h" #include "confirm.h" #include +#include #include #ifndef TESTING #include diff --git a/test/device-test/CMakeLists.txt b/test/device-test/CMakeLists.txt index 74d94e1d5..5b35da53e 100644 --- a/test/device-test/CMakeLists.txt +++ b/test/device-test/CMakeLists.txt @@ -25,7 +25,6 @@ set(BBBASE-SOURCES ${DBB-FIRMWARE-PROTOBUF-SOURCES} ${CRYPTOAUTHLIB-SOURCES} ${ETHEREUM-SOURCES} - ${FIRMWARE-U2F-SOURCES} ${CMAKE_SOURCE_DIR}/src/common_main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/framework/test_common.c ) @@ -66,7 +65,7 @@ target_include_directories(bitbox02-test-platform PUBLIC ${INCLUDES}) target_include_directories(bitbox02-test-platform SYSTEM PUBLIC ${SYSTEMINCLUDES}) target_include_directories(bitbox02-test-platform SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) target_compile_definitions(bitbox02-test-platform PUBLIC "PB_NO_PACKED_STRUCTS=1" "PB_FIELD_16BIT=1") -target_compile_definitions(bitbox02-test-platform PUBLIC "APP_BTC=1" "APP_LTC=1" "APP_U2F=1" "APP_ETH=1") +target_compile_definitions(bitbox02-test-platform PUBLIC "APP_U2F=1" "APP_ETH=1") add_dependencies(bitbox02-test-platform generate-protobufs) # needed to find version.h target_include_directories(bitbox02-test-platform SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/src) @@ -82,6 +81,7 @@ target_link_libraries(bitbox02-test-platform bignum # TODO: only eth sha3 # TODO: Only eth ctaes + app_btc-multi -Wl,-u,exception_table ) @@ -169,7 +169,7 @@ target_include_directories(bitboxbase-test-platform PUBLIC ${INCLUDES}) target_include_directories(bitboxbase-test-platform SYSTEM PUBLIC ${SYSTEMINCLUDES}) target_include_directories(bitboxbase-test-platform SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) target_compile_definitions(bitboxbase-test-platform PUBLIC "PB_NO_PACKED_STRUCTS=1" "PB_FIELD_16BIT=1") -target_compile_definitions(bitboxbase-test-platform PUBLIC "APP_BTC=1" "APP_LTC=1" "APP_U2F=1" "APP_ETH=1") +target_compile_definitions(bitboxbase-test-platform PUBLIC "APP_BTC=0" "APP_LTC=0" "APP_U2F=0" "APP_ETH=0") add_dependencies(bitboxbase-test-platform generate-protobufs) # needed to find version.h target_include_directories(bitboxbase-test-platform SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/src) diff --git a/test/device-test/include/test_common.h b/test/device-test/include/test_common.h index 55720e8ae..9b361260d 100644 --- a/test/device-test/include/test_common.h +++ b/test/device-test/include/test_common.h @@ -16,6 +16,7 @@ #define _TEST_COMMON_H_ #include +#include #include #include diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index 4755282b4..263d1bed9 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt @@ -106,6 +106,7 @@ target_link_libraries(bitbox wallycore secp256k1 bignum + util PRIVATE base32 ctaes diff --git a/test/unit-test/test_btc_sign.c b/test/unit-test/test_btc_sign.c index 208573f25..02d0839d4 100644 --- a/test/unit-test/test_btc_sign.c +++ b/test/unit-test/test_btc_sign.c @@ -97,7 +97,7 @@ static void _test_btc_sign_init(void** state) assert_int_equal(next.index, 0); } { // test invalid version - tst_app_btc_reset(); + btc_sign_reset(); BTCSignInitRequest invalid = init_req_valid; for (invalid.version = 0; invalid.version < 10; invalid.version++) { if (invalid.version == 1 || invalid.version == 2) { @@ -107,25 +107,25 @@ static void _test_btc_sign_init(void** state) } } { // test invalid inputs - tst_app_btc_reset(); + btc_sign_reset(); BTCSignInitRequest invalid = init_req_valid; invalid.num_inputs = 0; assert_int_equal(APP_BTC_SIGN_ERR_INVALID_INPUT, app_btc_sign_init(&invalid, &next)); } { // test invalid outputs - tst_app_btc_reset(); + btc_sign_reset(); BTCSignInitRequest invalid = init_req_valid; invalid.num_outputs = 0; assert_int_equal(APP_BTC_SIGN_ERR_INVALID_INPUT, app_btc_sign_init(&invalid, &next)); } { // test invalid locktime - tst_app_btc_reset(); + btc_sign_reset(); BTCSignInitRequest invalid = init_req_valid; invalid.locktime = 1; assert_int_equal(APP_BTC_SIGN_ERR_INVALID_INPUT, app_btc_sign_init(&invalid, &next)); } { // test invalid coin - tst_app_btc_reset(); + btc_sign_reset(); BTCSignInitRequest invalid = init_req_valid; invalid.coin = _BTCCoin_MIN - 1; assert_int_equal(APP_BTC_SIGN_ERR_INVALID_INPUT, app_btc_sign_init(&invalid, &next)); @@ -133,7 +133,7 @@ static void _test_btc_sign_init(void** state) assert_int_equal(APP_BTC_SIGN_ERR_INVALID_INPUT, app_btc_sign_init(&invalid, &next)); } { // test unsupported p2pkh - tst_app_btc_reset(); + btc_sign_reset(); BTCSignInitRequest invalid = init_req_valid; invalid.script_type = BTCScriptType_SCRIPT_P2PKH; assert_int_equal(APP_BTC_SIGN_ERR_INVALID_INPUT, app_btc_sign_init(&invalid, &next)); @@ -711,9 +711,9 @@ static void _test_overflow_output_ours(void** state) int main(void) { const struct CMUnitTest tests[] = { + cmocka_unit_test(_test_btc_sign), cmocka_unit_test(_test_btc_sign_init), - cmocka_unit_test(_test_btc_sign), cmocka_unit_test(_test_seeded), cmocka_unit_test(_test_wrong_coin_input), cmocka_unit_test(_test_wrong_coin_change), From 80d1276f361c3a38e70e281f10f007b82018493a Mon Sep 17 00:00:00 2001 From: Simone Baratta Date: Tue, 3 Dec 2019 17:04:18 +0100 Subject: [PATCH 3/4] cmake: Separate the platform-independent UI components. Most of the workflow, components, and UI code doesn't depend on the platform it will be run on. Compile it only once to save many CMake build entries. The gestures code is a dependency of most components, but it has a slight dependency on the hardware platform. Split it into an API and an implementation file to let including the header possible without having to define the platform the code will run on. --- src/CMakeLists.txt | 125 +++--- src/bitboxbase/bitboxbase_background.c | 1 + src/bootloader/bootloader.c | 1 + src/qtouch/qtouch.c | 6 + src/qtouch/qtouch.h | 216 ---------- src/qtouch/qtouch_bitbox02.h | 123 ++++++ src/qtouch/qtouch_bitboxbase.h | 122 ++++++ src/screen.c | 1 + src/touch/gestures.c | 4 + src/touch/gestures.h | 19 +- src/touch/gestures_bitboxbase.c | 385 ++++++++++++++++++ src/touch/gestures_bitboxbase.h | 25 ++ src/touch/gestures_impl.h | 39 ++ src/ui/components/confirm_gesture.c | 1 - src/ui/components/show_logo.c | 1 + src/ui/components/trinary_input_string.c | 4 - src/ui/components/ui_images.c | 1 - src/ui/components/ui_images.h | 70 ---- src/ui/components/ui_logos.h | 90 ++++ src/ui/components/waiting.c | 1 + test/device-test/CMakeLists.txt | 3 + .../src/test_bitboxbase_touch_demo.c | 1 + test/unit-test/CMakeLists.txt | 3 + test/unit-test/framework/mock_gestures.c | 2 + 24 files changed, 884 insertions(+), 360 deletions(-) create mode 100644 src/qtouch/qtouch_bitbox02.h create mode 100644 src/qtouch/qtouch_bitboxbase.h create mode 100644 src/touch/gestures_bitboxbase.c create mode 100644 src/touch/gestures_bitboxbase.h create mode 100644 src/touch/gestures_impl.h create mode 100644 src/ui/components/ui_logos.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 105c2e0d4..54c5773d1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,36 +26,17 @@ set(DBB-FIRMWARE-COMMON-SOURCES ${CMAKE_SOURCE_DIR}/src/memory/memory.c ${CMAKE_SOURCE_DIR}/src/salt.c ${CMAKE_SOURCE_DIR}/src/i2c_ecc.c - ${CMAKE_SOURCE_DIR}/src/touch/gestures.c ${CMAKE_SOURCE_DIR}/src/usb/noise.c ${CMAKE_SOURCE_DIR}/src/backup.c ${CMAKE_SOURCE_DIR}/src/restore.c ${CMAKE_SOURCE_DIR}/src/reset.c ${CMAKE_SOURCE_DIR}/src/cipher/cipher.c - ${CMAKE_SOURCE_DIR}/src/workflow/blocking.c - ${CMAKE_SOURCE_DIR}/src/workflow/cancel.c - ${CMAKE_SOURCE_DIR}/src/workflow/workflow.c - ${CMAKE_SOURCE_DIR}/src/workflow/trinary_input.c - ${CMAKE_SOURCE_DIR}/src/workflow/confirm.c - ${CMAKE_SOURCE_DIR}/src/workflow/confirm_time.c - ${CMAKE_SOURCE_DIR}/src/workflow/status.c - ${CMAKE_SOURCE_DIR}/src/workflow/password.c - ${CMAKE_SOURCE_DIR}/src/workflow/password_enter.c - ${CMAKE_SOURCE_DIR}/src/workflow/create_seed.c - ${CMAKE_SOURCE_DIR}/src/workflow/unlock.c - ${CMAKE_SOURCE_DIR}/src/workflow/show_mnemonic.c - ${CMAKE_SOURCE_DIR}/src/workflow/restore_from_mnemonic.c - ${CMAKE_SOURCE_DIR}/src/workflow/pairing.c - ${CMAKE_SOURCE_DIR}/src/workflow/verify_pub.c - ${CMAKE_SOURCE_DIR}/src/workflow/verify_recipient.c - ${CMAKE_SOURCE_DIR}/src/workflow/verify_total.c - ${CMAKE_SOURCE_DIR}/src/workflow/reboot.c - ${CMAKE_SOURCE_DIR}/src/workflow/sdcard.c - ${CMAKE_SOURCE_DIR}/src/workflow/backup.c - ${CMAKE_SOURCE_DIR}/src/workflow/reset.c - ${CMAKE_SOURCE_DIR}/src/workflow/restore.c ${CMAKE_SOURCE_DIR}/src/queue.c ${CMAKE_SOURCE_DIR}/src/usb/usb_processing.c + ${CMAKE_SOURCE_DIR}/src/workflow/reboot.c + ${CMAKE_SOURCE_DIR}/src/workflow/restore.c + ${CMAKE_SOURCE_DIR}/src/workflow/restore_from_mnemonic.c + ${CMAKE_SOURCE_DIR}/src/workflow/workflow.c ) set(DBB-FIRMWARE-COMMON-SOURCES ${DBB-FIRMWARE-COMMON-SOURCES} PARENT_SCOPE) @@ -71,22 +52,33 @@ set(DBB-FIRMWARE-USART-SOURCES ) set(DBB-FIRMWARE-USART-SOURCES ${DBB-FIRMWARE-USART-SOURCES} PARENT_SCOPE) -set(DBB-FIRMWARE-UI-SOURCES - ${CMAKE_SOURCE_DIR}/src/ui/ugui/ugui.c +set(DBB-FIRMWARE-UI-COMMON-SOURCES ${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_9X9.c ${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_11X12.c ${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_13X14.c ${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_15X16.c ${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_17X18.c ${CMAKE_SOURCE_DIR}/src/ui/screen_stack.c - ${CMAKE_SOURCE_DIR}/src/ui/screen_process.c ${CMAKE_SOURCE_DIR}/src/ui/event_handler.c ${CMAKE_SOURCE_DIR}/src/ui/ui_util.c +) +set(DBB-FIRMWARE-UI-COMMON-SOURCES ${DBB-FIRMWARE-UI-COMMON-SOURCES} PARENT_SCOPE) + +# UI items that are tied to their platform. +set(DBB-FIRMWARE-UI-SOURCES + ${CMAKE_SOURCE_DIR}/src/ui/components/show_logo.c + ${CMAKE_SOURCE_DIR}/src/ui/components/waiting.c + ${CMAKE_SOURCE_DIR}/src/ui/screen_process.c + ${CMAKE_SOURCE_DIR}/src/ui/ugui/ugui.c + ${CMAKE_SOURCE_DIR}/src/touch/gestures.c +) +set(DBB-FIRMWARE-UI-SOURCES ${DBB-FIRMWARE-UI-SOURCES} PARENT_SCOPE) + +# Component files that are not tied to a particular platform. +set(DBB-FIRMWARE-COMPONENT-SOURCES ${CMAKE_SOURCE_DIR}/src/ui/components/trinary_choice.c ${CMAKE_SOURCE_DIR}/src/ui/components/trinary_input_char.c ${CMAKE_SOURCE_DIR}/src/ui/components/trinary_input_string.c - ${CMAKE_SOURCE_DIR}/src/ui/components/show_logo.c - ${CMAKE_SOURCE_DIR}/src/ui/components/waiting.c ${CMAKE_SOURCE_DIR}/src/ui/components/entry_screen.c ${CMAKE_SOURCE_DIR}/src/ui/components/knight_rider.c ${CMAKE_SOURCE_DIR}/src/ui/components/right_arrow.c @@ -109,7 +101,30 @@ set(DBB-FIRMWARE-UI-SOURCES ${CMAKE_SOURCE_DIR}/src/ui/components/ui_images.c ${CMAKE_SOURCE_DIR}/src/ui/components/confirm_transaction.c ) -set(DBB-FIRMWARE-UI-SOURCES ${DBB-FIRMWARE-UI-SOURCES} PARENT_SCOPE) +set(DBB-FIRMWARE-COMPONENT-SOURCES ${DBB-FIRMWARE-COMPONENT-SOURCES} PARENT_SCOPE) + +# All workflows that don't depend on a particular platform. +set(DBB-FIRMWARE-WORKFLOW-SOURCES + ${CMAKE_SOURCE_DIR}/src/workflow/blocking.c + ${CMAKE_SOURCE_DIR}/src/workflow/cancel.c + ${CMAKE_SOURCE_DIR}/src/workflow/trinary_input.c + ${CMAKE_SOURCE_DIR}/src/workflow/confirm.c + ${CMAKE_SOURCE_DIR}/src/workflow/confirm_time.c + ${CMAKE_SOURCE_DIR}/src/workflow/status.c + ${CMAKE_SOURCE_DIR}/src/workflow/password.c + ${CMAKE_SOURCE_DIR}/src/workflow/password_enter.c + ${CMAKE_SOURCE_DIR}/src/workflow/create_seed.c + ${CMAKE_SOURCE_DIR}/src/workflow/unlock.c + ${CMAKE_SOURCE_DIR}/src/workflow/show_mnemonic.c + ${CMAKE_SOURCE_DIR}/src/workflow/pairing.c + ${CMAKE_SOURCE_DIR}/src/workflow/verify_pub.c + ${CMAKE_SOURCE_DIR}/src/workflow/verify_recipient.c + ${CMAKE_SOURCE_DIR}/src/workflow/verify_total.c + ${CMAKE_SOURCE_DIR}/src/workflow/sdcard.c + ${CMAKE_SOURCE_DIR}/src/workflow/backup.c + ${CMAKE_SOURCE_DIR}/src/workflow/reset.c +) +set(DBB-FIRMWARE-WORKFLOW-SOURCES ${DBB-FIRMWARE-WORKFLOW-SOURCES} PARENT_SCOPE) set(DBB-BOOTLOADER-SOURCES ${CMAKE_SOURCE_DIR}/src/pukcc/curve_p256.c @@ -117,13 +132,10 @@ set(DBB-BOOTLOADER-SOURCES ${CMAKE_SOURCE_DIR}/src/bootloader/bootloader.c ${CMAKE_SOURCE_DIR}/src/bootloader/startup.c ${CMAKE_SOURCE_DIR}/src/bootloader/mpu_regions.c - ${CMAKE_SOURCE_DIR}/src/memory/mpu.c - ${CMAKE_SOURCE_DIR}/src/memory/nvmctrl.c ${CMAKE_SOURCE_DIR}/src/queue.c ${CMAKE_SOURCE_DIR}/src/usb/usb_processing.c ${CMAKE_SOURCE_DIR}/src/ui/ugui/ugui.c ${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_9X9.c - ${CMAKE_SOURCE_DIR}/src/screen.c ${CMAKE_SOURCE_DIR}/src/hardfault.c ${CMAKE_SOURCE_DIR}/src/ui/components/ui_images.c ) @@ -265,23 +277,6 @@ target_include_directories(util SYSTEM PUBLIC ${SYSTEMINCLUDES}) target_include_directories(util SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) target_include_directories(util SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/src) -add_library(app_btc-btc ${APP-BTC-SOURCES}) -target_compile_definitions(app_btc-btc PUBLIC "APP_BTC=1" "APP_LTC=0") -target_include_directories(app_btc-btc PRIVATE ${INCLUDES}) -target_include_directories(app_btc-btc SYSTEM PUBLIC ${SYSTEMINCLUDES}) -target_include_directories(app_btc-btc SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) -target_include_directories(app_btc-btc SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/src) -target_link_libraries(app_btc-btc noiseprotocol wallycore secp256k1 util) - -add_library(app_btc-multi ${APP-BTC-SOURCES}) -target_compile_definitions(app_btc-multi PUBLIC "APP_BTC=1" "APP_LTC=1") -target_compile_definitions(app_btc-multi PRIVATE "NO_PLATFORM_CONFIGURED") -target_include_directories(app_btc-multi PRIVATE ${INCLUDES}) -target_include_directories(app_btc-multi SYSTEM PUBLIC ${SYSTEMINCLUDES}) -target_include_directories(app_btc-multi SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) -target_include_directories(app_btc-multi SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/src) -target_link_libraries(app_btc-multi noiseprotocol wallycore secp256k1 util) - set(FIRMWARE-SOURCES ${DBB-FIRMWARE-UI-SOURCES} ${FIRMWARE-DRIVER-SOURCES} @@ -294,6 +289,7 @@ set(FIRMWARE-SOURCES set(BOOTLOADER-SOURCES ${DBB-BOOTLOADER-SOURCES} + ${DBB-FIRMWARE-UI-SOURCES} ${DRIVER-SOURCES} ) @@ -309,8 +305,33 @@ if(CMAKE_CROSSCOMPILING) get_property(CMSIS_INCLUDES TARGET CMSIS PROPERTY INTERFACE_INCLUDE_DIRECTORIES) get_property(WALLY_INCLUDES TARGET wallycore PROPERTY INTERFACE_INCLUDE_DIRECTORIES) + set(helper_libraries app_btc-btc app_btc-multi ui_common components workflows) + add_library(app_btc-btc ${APP-BTC-SOURCES}) + target_compile_definitions(app_btc-btc PUBLIC "APP_BTC=1" "APP_LTC=0") + + add_library(app_btc-multi ${APP-BTC-SOURCES}) + target_compile_definitions(app_btc-multi PUBLIC "APP_BTC=1" "APP_LTC=1") + target_link_libraries(app_btc-multi noiseprotocol wallycore secp256k1 util) + + add_library(ui_common ${DBB-FIRMWARE-UI-COMMON-SOURCES}) + + add_library(components ${DBB-FIRMWARE-COMPONENT-SOURCES}) + target_link_libraries(components ui_common) + + add_library(workflows ${DBB-FIRMWARE-WORKFLOW-SOURCES}) + target_link_libraries(workflows components) + foreach(include ${INCLUDES} ${SYSTEMINCLUDES} ${SAMD51A_INCLUDES} ${ASF4_INCLUDES} ${ASF4_MIN_INCLUDES} ${CMSIS_INCLUDES} ${NANOPB_INCLUDE_DIRS} ${WALLY_INCLUDES}) list(APPEND RUST_INCLUDES -I${include}) + target_include_directories(components SYSTEM PRIVATE ${include}) + target_include_directories(workflows SYSTEM PRIVATE ${include}) + foreach (library ${helper_libraries}) + target_include_directories(${library} PRIVATE ${INCLUDES}) + target_include_directories(${library} SYSTEM PUBLIC ${SYSTEMINCLUDES}) + target_include_directories(${library} SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) + target_include_directories(${library} SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/src) + target_link_libraries(${library} base32 noiseprotocol wallycore secp256k1 util) + endforeach() endforeach() if(CMAKE_BUILD_TYPE STREQUAL "DEBUG") @@ -321,6 +342,8 @@ if(CMAKE_CROSSCOMPILING) set(RUSTFLAGS --remap-path-prefix=${CMAKE_CURRENT_SOURCE_DIR}/rust=src) endif() + add_dependencies(workflows generate-protobufs) + set(LIBBITBOX02_RUST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/rust/bitbox02-rust) set(LIBBITBOX02_RUST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/rust/bitbox02-rust/target) set(LIBBITBOX02_RUST ${CMAKE_CURRENT_BINARY_DIR}/rust/bitbox02-rust/target/thumbv7em-none-eabi/${RUST_PROFILE}/libbitbox02_rust.a) @@ -417,7 +440,7 @@ if(CMAKE_CROSSCOMPILING) set(HEAP_SIZE ${HEAP_SIZE} PARENT_SCOPE) add_library(bitbox02-platform ${PLATFORM-BITBOX02-SOURCES}) - target_link_libraries(bitbox02-platform asf4-drivers-min util) + target_link_libraries(bitbox02-platform asf4-drivers-min util workflows) target_include_directories(bitbox02-platform PRIVATE ${INCLUDES}) target_include_directories(bitbox02-platform SYSTEM PUBLIC ${SYSTEMINCLUDES}) target_include_directories(bitbox02-platform SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) @@ -431,7 +454,7 @@ if(CMAKE_CROSSCOMPILING) #endif() add_library(bitboxbase-platform ${PLATFORM-BITBOXBASE-SOURCES}) - target_link_libraries(bitboxbase-platform asf4-drivers util) + target_link_libraries(bitboxbase-platform asf4-drivers util workflows) target_include_directories(bitboxbase-platform PRIVATE ${INCLUDES}) target_include_directories(bitboxbase-platform SYSTEM PUBLIC ${SYSTEMINCLUDES}) target_include_directories(bitboxbase-platform SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) diff --git a/src/bitboxbase/bitboxbase_background.c b/src/bitboxbase/bitboxbase_background.c index 8b1cdd622..6f9f1a53c 100644 --- a/src/bitboxbase/bitboxbase_background.c +++ b/src/bitboxbase/bitboxbase_background.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include diff --git a/src/bootloader/bootloader.c b/src/bootloader/bootloader.c index f5f89a748..03a417572 100644 --- a/src/bootloader/bootloader.c +++ b/src/bootloader/bootloader.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #if PLATFORM_BITBOXBASE == 1 diff --git a/src/qtouch/qtouch.c b/src/qtouch/qtouch.c index 43c977582..4e8e523d6 100644 --- a/src/qtouch/qtouch.c +++ b/src/qtouch/qtouch.c @@ -33,6 +33,12 @@ Copyright (c) 2017 Microchip. All rights reserved. #include #include +#if PLATFORM_BITBOXBASE == 1 +#include "qtouch_bitboxbase.h" +#else +#include "qtouch_bitbox02.h" +#endif + /*---------------------------------------------------------------------------- * prototypes *----------------------------------------------------------------------------*/ diff --git a/src/qtouch/qtouch.h b/src/qtouch/qtouch.h index 3e2042cb0..45f7897ad 100644 --- a/src/qtouch/qtouch.h +++ b/src/qtouch/qtouch.h @@ -29,11 +29,6 @@ extern "C" { *----------------------------------------------------------------------------*/ #include "touch_api_ptc.h" -#include - -#if PLATFORM_BITBOXBASE == 1 -bool qtouch_get_button_state(size_t idx); -#endif /**********************************************************/ /******************* Acquisition controls *****************/ @@ -76,206 +71,6 @@ bool qtouch_get_button_state(size_t idx); * defines *----------------------------------------------------------------------------*/ -#if PLATFORM_BITBOX02 == 1 -/**********************************************************/ -/***************** Node Params ******************/ -/**********************************************************/ -/* Acquisition Set 1 */ -/* Defines the number of sensor nodes in the acquisition set - * Range: 1 to 65535. - * Default value: 1 - */ -#define DEF_NUM_CHANNELS (8) - -/* Defines node parameter setting - * {X-line, Y-line, Charge Share Delay, NODE_RSEL_PRSC(series resistor, prescaler), NODE_G(Analog - * Gain , Digital Gain), filter level} - */ -// Slider 1 buttons -#define NODE_0_PARAMS \ - { \ - X_NONE, Y_LINE(26), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \ - NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \ - } -#define NODE_1_PARAMS \ - { \ - X_NONE, Y_LINE(27), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \ - NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \ - } -#define NODE_2_PARAMS \ - { \ - X_NONE, Y_LINE(28), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \ - NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \ - } -#define NODE_3_PARAMS \ - { \ - X_NONE, Y_LINE(29), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \ - NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \ - } -// Slider 0 buttons -#define NODE_4_PARAMS \ - { \ - X_NONE, Y_LINE(30), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \ - NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \ - } -#define NODE_5_PARAMS \ - { \ - X_NONE, Y_LINE(31), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \ - NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \ - } -#define NODE_6_PARAMS \ - { \ - X_NONE, Y_LINE(20), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \ - NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \ - } -#define NODE_7_PARAMS \ - { \ - X_NONE, Y_LINE(21), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \ - NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \ - } - -/**********************************************************/ -/***************** Key Params ******************/ -/**********************************************************/ -/* Defines the number of key sensors - * Range: 1 to 65535. - * Default value: 1 - */ -#define DEF_NUM_SENSORS (DEF_NUM_CHANNELS) - -/* Defines Key Sensor setting - * {Sensor Threshold, Sensor Hysterisis, Sensor AKS} - */ -// 0..3 higher Slider left to right 4..7 lower Slider right to left -#define KEY_0_PARAMS \ - { \ - 16, HYST_50, NO_AKS_GROUP \ - } -#define KEY_1_PARAMS \ - { \ - 16, HYST_50, NO_AKS_GROUP \ - } -#define KEY_2_PARAMS \ - { \ - 16, HYST_50, NO_AKS_GROUP \ - } -#define KEY_3_PARAMS \ - { \ - 16, HYST_50, NO_AKS_GROUP \ - } -#define KEY_4_PARAMS \ - { \ - 16, HYST_50, NO_AKS_GROUP \ - } -#define KEY_5_PARAMS \ - { \ - 16, HYST_50, NO_AKS_GROUP \ - } -#define KEY_6_PARAMS \ - { \ - 16, HYST_50, NO_AKS_GROUP \ - } -#define KEY_7_PARAMS \ - { \ - 16, HYST_50, NO_AKS_GROUP \ - } - -#elif PLATFORM_BITBOXBASE == 1 -/**********************************************************/ -/***************** Node Params ******************/ -/**********************************************************/ -/* Acquisition Set 1 */ -/* Defines the number of sensor nodes in the acquisition set - * Range: 1 to 65535. - * Default value: 1 - */ -#define DEF_NUM_CHANNELS (6) - -/* Defines node parameter setting - * {X-line, Y-line, Charge Share Delay, NODE_RSEL_PRSC(series resistor, prescaler), NODE_G(Analog - * Gain , Digital Gain), filter level} - */ -// Slider buttons -#define NODE_0_PARAMS \ - { \ - X_NONE, Y_LINE(23), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_2), \ - NODE_GAIN(GAIN_8, GAIN_1), FILTER_LEVEL_32 \ - } -#define NODE_1_PARAMS \ - { \ - X_NONE, Y_LINE(22), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_2), \ - NODE_GAIN(GAIN_8, GAIN_1), FILTER_LEVEL_32 \ - } -#define NODE_2_PARAMS \ - { \ - X_NONE, Y_LINE(21), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_2), \ - NODE_GAIN(GAIN_8, GAIN_1), FILTER_LEVEL_32 \ - } -#define NODE_3_PARAMS \ - { \ - X_NONE, Y_LINE(20), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_2), \ - NODE_GAIN(GAIN_8, GAIN_1), FILTER_LEVEL_32 \ - } -// Top buttons -#define NODE_4_PARAMS \ - { \ - X_NONE, Y_LINE(30), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_4), \ - NODE_GAIN(GAIN_16, GAIN_2), FILTER_LEVEL_256 \ - } -#define NODE_5_PARAMS \ - { \ - X_NONE, Y_LINE(31), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_4), \ - NODE_GAIN(GAIN_16, GAIN_2), FILTER_LEVEL_256 \ - } - -/**********************************************************/ -/***************** Key Params ******************/ -/**********************************************************/ -/* Defines the number of key sensors - * Range: 1 to 65535. - * Default value: 1 - */ -#define DEF_NUM_SENSORS (DEF_NUM_CHANNELS) - -/* Defines Key Sensor setting - * {Sensor Threshold, Sensor Hysterisis, Sensor AKS} - */ -// 0..3 higher Slider left to right 4..7 lower Slider right to left -#define KEY_0_PARAMS \ - { \ - 16, HYST_50, NO_AKS_GROUP \ - } -#define KEY_1_PARAMS \ - { \ - 16, HYST_50, NO_AKS_GROUP \ - } -#define KEY_2_PARAMS \ - { \ - 16, HYST_50, NO_AKS_GROUP \ - } -#define KEY_3_PARAMS \ - { \ - 16, HYST_50, NO_AKS_GROUP \ - } -#define KEY_4_PARAMS \ - { \ - 16, HYST_50, NO_AKS_GROUP \ - } -#define KEY_5_PARAMS \ - { \ - 16, HYST_50, NO_AKS_GROUP \ - } - -/* - * Defines number of buttson - */ -#define DEF_NUM_BUTTONS 2 -/* - * Defines the offset to the first button in the node list - */ -#define DEF_BUTTON_OFFSET 4 -#endif - /* De-bounce counter for additional measurements to confirm touch detection * Range: 0 to 255. * Default value: 4. @@ -347,17 +142,6 @@ bool qtouch_get_button_state(size_t idx); * This allows low noise button readings while keeping * fast responsiveness. */ -#if PLATFORM_BITBOX02 == 1 -#define DEF_NUM_SCROLLERS 2 // Number of scrollers (sliders or wheels) -#define DEF_SCROLLER_NUM_CHANNELS 4 // Number of channels per scroller -#define DEF_SCROLLER_OFFSET_0 4 // Index of first button in scroller -#define DEF_SCROLLER_OFFSET_1 0 // Index of first button in scroller -#elif PLATFORM_BITBOXBASE == 1 -#define DEF_NUM_SCROLLERS 1 // Number of scrollers (sliders or wheels) -#define DEF_SCROLLER_NUM_CHANNELS 4 // Number of channels per scroller -#define DEF_SCROLLER_OFFSET_0 0 // Index of first button in scroller -#define DEF_SCROLLER_OFFSET_1 0 // Index of first button in scroller -#endif #define DEF_SCROLLER_RESOLUTION 256 // Scroller resolution in bits #define DEF_SCROLLER_DET_THRESHOLD 25 // Scroller detect threshold #define DEF_SCROLLER_TOUCH_THRESHOLD 25 // Scroller active threshold diff --git a/src/qtouch/qtouch_bitbox02.h b/src/qtouch/qtouch_bitbox02.h new file mode 100644 index 000000000..81160f4cf --- /dev/null +++ b/src/qtouch/qtouch_bitbox02.h @@ -0,0 +1,123 @@ +// Copyright 2019 Shift Cryptosecurity AG +// +// 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. + +/** QTouch parameters for the BitBox02 platform. */ + +/**********************************************************/ +/***************** Node Params ******************/ +/**********************************************************/ +/* Acquisition Set 1 */ +/* Defines the number of sensor nodes in the acquisition set + * Range: 1 to 65535. + * Default value: 1 + */ +#define DEF_NUM_CHANNELS (8) + +/* Defines node parameter setting + * {X-line, Y-line, Charge Share Delay, NODE_RSEL_PRSC(series resistor, prescaler), NODE_G(Analog + * Gain , Digital Gain), filter level} + */ +// Slider 1 buttons +#define NODE_0_PARAMS \ + { \ + X_NONE, Y_LINE(26), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \ + NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \ + } +#define NODE_1_PARAMS \ + { \ + X_NONE, Y_LINE(27), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \ + NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \ + } +#define NODE_2_PARAMS \ + { \ + X_NONE, Y_LINE(28), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \ + NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \ + } +#define NODE_3_PARAMS \ + { \ + X_NONE, Y_LINE(29), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \ + NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \ + } +// Slider 0 buttons +#define NODE_4_PARAMS \ + { \ + X_NONE, Y_LINE(30), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \ + NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \ + } +#define NODE_5_PARAMS \ + { \ + X_NONE, Y_LINE(31), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \ + NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \ + } +#define NODE_6_PARAMS \ + { \ + X_NONE, Y_LINE(20), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \ + NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \ + } +#define NODE_7_PARAMS \ + { \ + X_NONE, Y_LINE(21), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_1), \ + NODE_GAIN(GAIN_4, GAIN_4), FILTER_LEVEL_512 \ + } + +/**********************************************************/ +/***************** Key Params ******************/ +/**********************************************************/ +/* Defines the number of key sensors + * Range: 1 to 65535. + * Default value: 1 + */ +#define DEF_NUM_SENSORS (DEF_NUM_CHANNELS) + +/* Defines Key Sensor setting + * {Sensor Threshold, Sensor Hysterisis, Sensor AKS} + */ +// 0..3 higher Slider left to right 4..7 lower Slider right to left +#define KEY_0_PARAMS \ + { \ + 16, HYST_50, NO_AKS_GROUP \ + } +#define KEY_1_PARAMS \ + { \ + 16, HYST_50, NO_AKS_GROUP \ + } +#define KEY_2_PARAMS \ + { \ + 16, HYST_50, NO_AKS_GROUP \ + } +#define KEY_3_PARAMS \ + { \ + 16, HYST_50, NO_AKS_GROUP \ + } +#define KEY_4_PARAMS \ + { \ + 16, HYST_50, NO_AKS_GROUP \ + } +#define KEY_5_PARAMS \ + { \ + 16, HYST_50, NO_AKS_GROUP \ + } +#define KEY_6_PARAMS \ + { \ + 16, HYST_50, NO_AKS_GROUP \ + } +#define KEY_7_PARAMS \ + { \ + 16, HYST_50, NO_AKS_GROUP \ + } + +#define DEF_NUM_SCROLLERS 2 // Number of scrollers (sliders or wheels) +#define DEF_SCROLLER_NUM_CHANNELS 4 // Number of channels per scroller +#define DEF_SCROLLER_OFFSET_0 4 // Index of first button in scroller +#define DEF_SCROLLER_OFFSET_1 0 // Index of first button in scroller diff --git a/src/qtouch/qtouch_bitboxbase.h b/src/qtouch/qtouch_bitboxbase.h new file mode 100644 index 000000000..b7697d28a --- /dev/null +++ b/src/qtouch/qtouch_bitboxbase.h @@ -0,0 +1,122 @@ +// Copyright 2019 Shift Cryptosecurity AG +// +// 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. + +#ifndef __QTOUCH_BITBOXBASE_H +#define __QTOUCH_BITBOXBASE_H + +/** QTouch parameters for the BitBoxBase HSM platform. */ + +/**********************************************************/ +/***************** Node Params ******************/ +/**********************************************************/ +/* Acquisition Set 1 */ +/* Defines the number of sensor nodes in the acquisition set + * Range: 1 to 65535. + * Default value: 1 + */ +#define DEF_NUM_CHANNELS (6) + +/* Defines node parameter setting + * {X-line, Y-line, Charge Share Delay, NODE_RSEL_PRSC(series resistor, prescaler), NODE_G(Analog + * Gain , Digital Gain), filter level} + */ +// Slider buttons +#define NODE_0_PARAMS \ + { \ + X_NONE, Y_LINE(23), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_2), \ + NODE_GAIN(GAIN_8, GAIN_1), FILTER_LEVEL_32 \ + } +#define NODE_1_PARAMS \ + { \ + X_NONE, Y_LINE(22), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_2), \ + NODE_GAIN(GAIN_8, GAIN_1), FILTER_LEVEL_32 \ + } +#define NODE_2_PARAMS \ + { \ + X_NONE, Y_LINE(21), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_2), \ + NODE_GAIN(GAIN_8, GAIN_1), FILTER_LEVEL_32 \ + } +#define NODE_3_PARAMS \ + { \ + X_NONE, Y_LINE(20), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_2), \ + NODE_GAIN(GAIN_8, GAIN_1), FILTER_LEVEL_32 \ + } +// Top buttons +#define NODE_4_PARAMS \ + { \ + X_NONE, Y_LINE(30), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_4), \ + NODE_GAIN(GAIN_16, GAIN_2), FILTER_LEVEL_256 \ + } +#define NODE_5_PARAMS \ + { \ + X_NONE, Y_LINE(31), 0, NODE_RSEL_PRSC(RSEL_VAL_20, PRSC_DIV_SEL_4), \ + NODE_GAIN(GAIN_16, GAIN_2), FILTER_LEVEL_256 \ + } + +/**********************************************************/ +/***************** Key Params ******************/ +/**********************************************************/ +/* Defines the number of key sensors + * Range: 1 to 65535. + * Default value: 1 + */ +#define DEF_NUM_SENSORS (DEF_NUM_CHANNELS) + +/* Defines Key Sensor setting + * {Sensor Threshold, Sensor Hysterisis, Sensor AKS} + */ +// 0..3 higher Slider left to right 4..7 lower Slider right to left +#define KEY_0_PARAMS \ + { \ + 16, HYST_50, NO_AKS_GROUP \ + } +#define KEY_1_PARAMS \ + { \ + 16, HYST_50, NO_AKS_GROUP \ + } +#define KEY_2_PARAMS \ + { \ + 16, HYST_50, NO_AKS_GROUP \ + } +#define KEY_3_PARAMS \ + { \ + 16, HYST_50, NO_AKS_GROUP \ + } +#define KEY_4_PARAMS \ + { \ + 16, HYST_50, NO_AKS_GROUP \ + } +#define KEY_5_PARAMS \ + { \ + 16, HYST_50, NO_AKS_GROUP \ + } + +/* + * Defines number of buttons + */ +#define DEF_NUM_BUTTONS 2 + +/* + * Defines the offset to the first button in the node list + */ +#define DEF_BUTTON_OFFSET 4 + +#define DEF_NUM_SCROLLERS 1 // Number of scrollers (sliders or wheels) +#define DEF_SCROLLER_NUM_CHANNELS 4 // Number of channels per scroller +#define DEF_SCROLLER_OFFSET_0 0 // Index of first button in scroller +#define DEF_SCROLLER_OFFSET_1 0 // Index of first button in scroller + +bool qtouch_get_button_state(size_t idx); + +#endif // __QTOUCH_BITBOXBASE_H diff --git a/src/screen.c b/src/screen.c index 560bb873c..8f33142c2 100644 --- a/src/screen.c +++ b/src/screen.c @@ -15,6 +15,7 @@ #include "screen.h" #include +#include #include #include #include diff --git a/src/touch/gestures.c b/src/touch/gestures.c index 9bafc93b3..645fec143 100644 --- a/src/touch/gestures.c +++ b/src/touch/gestures.c @@ -25,6 +25,10 @@ #endif #include "gestures.h" +#include "gestures_impl.h" +#if PLATFORM_BITBOXBASE == 1 +#include "gestures_bitboxbase.h" +#endif #include "ui/event.h" #include "ui/event_handler.h" #include "util.h" diff --git a/src/touch/gestures.h b/src/touch/gestures.h index 75baad6bd..05a6cff76 100644 --- a/src/touch/gestures.h +++ b/src/touch/gestures.h @@ -17,20 +17,16 @@ #include -#include #include #include #ifndef TESTING -#include "qtouch.h" -#define TOUCH_NUM_BUTTONS DEF_NUM_CHANNELS -#define TOUCH_NUM_SLIDERS DEF_NUM_SCROLLERS +#include #define MAX_SLIDER_POS (DEF_SCROLLER_RESOLUTION - 1) #else -#define TOUCH_NUM_BUTTONS (8) -#define TOUCH_NUM_SLIDERS (2) #define MAX_SLIDER_POS (255) #endif + #define SLIDER_POSITION_ONE_THIRD (MAX_SLIDER_POS / 3) #define SLIDER_POSITION_TWO_THIRD (MAX_SLIDER_POS / 3 * 2) @@ -40,13 +36,6 @@ typedef struct { int32_t velocity; } gestures_slider_data_t; -#if PLATFORM_BITBOXBASE == 1 -enum bitboxbase_button_id_t { - BITBOXBASE_BUTTON_LEFT, - BITBOXBASE_BUTTON_RIGHT, -}; -#endif - /** * Detects a gestures and calls the respective callback. * @param[in] reset The flag indicates whether the gesture history should be @@ -57,8 +46,4 @@ enum bitboxbase_button_id_t { */ void gestures_detect(bool reset, bool emit_without_release); -#if PLATFORM_BITBOXBASE == 1 -enum bitboxbase_button_id_t gestures_button_which(const event_t* event); -#endif - #endif diff --git a/src/touch/gestures_bitboxbase.c b/src/touch/gestures_bitboxbase.c new file mode 100644 index 000000000..6a456d349 --- /dev/null +++ b/src/touch/gestures_bitboxbase.c @@ -0,0 +1,385 @@ +// Copyright 2019 Shift Cryptosecurity AG +// +// 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 +#include +#include +#include + +#ifndef TESTING +#include "qtouch.h" +#include +#else +#include "mock_qtouch.h" +#endif + +#include "gestures.h" +#if PLATFORM_BITBOXBASE == 1 +#include "gestures_bitboxbase.h" +#endif + +#include "ui/event.h" +#include "ui/event_handler.h" +#include "util.h" +#include +#include + +#define MAX_REGISTRATIONS 7 +#define MAX_HISTORY 30 + +/** The minimum amount of sliding difference required, so that the gesture is detected as slide. */ +static const uint8_t SLIDE_DETECTION_DIFF = MAX_SLIDER_POS * 0.04; // Percent of slider range +/** + * The maximum amount of sliding that the user's finger is allowed to move + * for its gesture to be still considered a tap. + */ +static const uint8_t TAP_SLIDE_TOLERANCE = MAX_SLIDER_POS * 0.1; // Percent of slider range + +extern volatile uint8_t measurement_done_touch; + +/********************************** STATE **********************************/ + +#if PLATFORM_BITBOX02 == 1 +static const uint16_t LONG_TOUCH = 500; +#elif PLATFORM_BITBOXBASE == 1 +static const uint16_t LONG_TOUCH = 1000; +#endif + +enum slider_status_t { INACTIVE, ACTIVE, RELEASED }; + +enum gesture_type_t { NONE, SLIDE, TAP }; + +// Stores whether or not sliders were released since a new screen reset the state. +bool _released_since_new_screen = false; + +/** + * The state of the gesture detection while the slider is not released. + */ +typedef struct { + // Incremented by 1 for every update. + uint32_t duration; + // The start of the position. + uint16_t position_start; + // The last measured position. + uint16_t position_current; + /* + * The maximum distance the finger has travelled + * since starting the gesture. + */ + uint16_t max_slide_travel; + int32_t velocity_sum; + uint16_t velocity_index; + // Stores the velocities. + int16_t velocity_values[MAX_HISTORY]; + // The gesture type (tap, slide). FUTURE: remove this? + enum gesture_type_t gesture_type; + // The status of the slider. + enum slider_status_t slider_status; +} gestures_detection_state_t; + +/** + * The current state. A gesture is detected over multiple function calls to + * gestures_measure_and_emit(). Thus, we need to store the information continuously in a file-local + * state. + */ +static gestures_detection_state_t _state[TOUCH_NUM_SLIDERS] = {0}; + +#if PLATFORM_BITBOXBASE == 1 +struct button_detection_state_t { + enum bitboxbase_button_id_t button_id; + uint32_t duration; + enum slider_status_t button_status; +}; + +struct button_detection_state_t _bitboxbase_button_state[] = { + {BITBOXBASE_BUTTON_LEFT, 0, INACTIVE}, + {BITBOXBASE_BUTTON_RIGHT, 0, INACTIVE}, +}; + +enum bitboxbase_button_id_t gestures_button_which(const event_t* event) +{ + return ((const struct button_detection_state_t*)event->data)->button_id; +} +#endif + +/********************************** STATE UPDATE **********************************/ + +/** + * Updates the state of a slider. + */ +static void _slider_state_update(gestures_detection_state_t* state, uint16_t position) +{ + if (state->duration == 0) { + state->position_start = position; + state->position_current = position; + state->max_slide_travel = 0; + state->gesture_type = TAP; + } + int16_t velocity_current = position - state->position_current; + state->position_current = position; + int16_t velocity_removed = state->velocity_values[state->velocity_index]; + state->velocity_sum = state->velocity_sum - velocity_removed + velocity_current; + state->velocity_values[state->velocity_index] = velocity_current; + state->velocity_index = (state->velocity_index + 1) % MAX_HISTORY; + uint16_t distance_from_start = abs((int)position - (int)state->position_start); + state->max_slide_travel = MAX(distance_from_start, state->max_slide_travel); + + state->slider_status = ACTIVE; + if (abs(state->position_current - state->position_start) > SLIDE_DETECTION_DIFF) { + state->gesture_type = SLIDE; + } + state->duration++; +} + +/** + * Reads the status of the touch sliders and updates the state. + */ +static void _slider_state_read_and_update(const uint8_t location) +{ + if (qtouch_is_scroller_active(location)) { + uint16_t current_pos = qtouch_get_scroller_position(location); + if (location == bottom_slider) { + current_pos = MAX_SLIDER_POS - current_pos; + } + _slider_state_update(&_state[location], current_pos); + } else if (_state[location].duration > 0 && _state[location].slider_status != RELEASED) { + _state[location].slider_status = RELEASED; + } else { + _state[location].slider_status = INACTIVE; + _state[location].duration = 0; + } +} + +/** + * Resets the state. + */ +static void _reset_state(void) +{ + memset(_state, 0, sizeof(_state)); +} + +/** + * Prepares the gestures data to be sent with an emitted event + */ +static void _collect_gestures_data( + gestures_detection_state_t* state, + gestures_slider_data_t* slider_data) +{ + slider_data->position = state->position_current; + slider_data->diff = state->position_current - state->position_start; + slider_data->velocity = state->velocity_sum; +} + +/********************************** GESTURE DETECTION **********************************/ + +static bool _is_continuous_tap(uint8_t location) +{ + return _state[location].max_slide_travel < TAP_SLIDE_TOLERANCE && + _state[location].slider_status == ACTIVE; +} + +static bool _is_tap_release(uint8_t location) +{ + return _state[location].max_slide_travel < TAP_SLIDE_TOLERANCE && + _state[location].slider_status == RELEASED; +} + +static bool _is_long_tap_release(uint8_t location) +{ + return _is_tap_release(location) && _state[location].duration > LONG_TOUCH; +} + +static bool _is_continuous_slide(uint8_t location) +{ + return _state[location].gesture_type == SLIDE && _state[location].slider_status == ACTIVE; +} + +static bool _is_slide_released(uint8_t location) +{ + return _state[location].gesture_type == SLIDE && _state[location].slider_status == RELEASED; +} + +/********************************** EVENT HANDLER **********************************/ + +static void _gesture_emit_event(uint8_t id, slider_location_t location) +{ + // If a slider is being touched on a new screen, + // wait until released before emitting events. + if (!_released_since_new_screen) { + return; + } + gestures_slider_data_t slider_data; + _collect_gestures_data(&_state[location], &slider_data); + event_t event = {.data = &slider_data, .id = id}; + emit_event(&event); +} + +static void _emit_continuous_slide_event(void) +{ + if (_is_continuous_slide(top_slider)) { + _gesture_emit_event(EVENT_TOP_SLIDE, top_slider); + } + if (_is_continuous_slide(bottom_slider)) { + _gesture_emit_event(EVENT_BOTTOM_SLIDE, bottom_slider); + } +} + +static void _emit_slide_release_event(void) +{ + if (_is_slide_released(top_slider)) { + _gesture_emit_event(EVENT_TOP_SLIDE_RELEASED, top_slider); + } + if (_is_slide_released(bottom_slider)) { + _gesture_emit_event(EVENT_BOTTOM_SLIDE_RELEASED, bottom_slider); + } +} + +static void _emit_long_tap_event(void) +{ + if (_is_long_tap_release(top_slider)) { + _gesture_emit_event(EVENT_TOP_LONG_TAP, top_slider); + } + if (_is_long_tap_release(bottom_slider)) { + _gesture_emit_event(EVENT_BOTTOM_LONG_TAP, bottom_slider); + } +} + +static void _emit_short_tap_event(void) +{ + if (_is_tap_release(top_slider)) { + _gesture_emit_event(EVENT_TOP_SHORT_TAP, top_slider); + } + if (_is_tap_release(bottom_slider)) { + _gesture_emit_event(EVENT_BOTTOM_SHORT_TAP, bottom_slider); + } +} + +static void _emit_continuous_tap_event(void) +{ + if (_is_continuous_tap(top_slider)) { + _gesture_emit_event(EVENT_TOP_CONTINUOUS_TAP, top_slider); + } + if (_is_continuous_tap(bottom_slider)) { + _gesture_emit_event(EVENT_BOTTOM_CONTINUOUS_TAP, bottom_slider); + } +} + +#if PLATFORM_BITBOXBASE == 1 +static void _emit_button_short_tap(size_t idx) +{ + event_t event = {.data = &_bitboxbase_button_state[idx], .id = EVENT_BUTTON_SHORT_TAP}; + emit_event(&event); +} + +static void _emit_button_long_tap(size_t idx) +{ + event_t event = {.data = &_bitboxbase_button_state[idx], .id = EVENT_BUTTON_LONG_TAP}; + emit_event(&event); +} + +static void _emit_button_continouos_tap(size_t idx) +{ + event_t event = {.data = &_bitboxbase_button_state[idx], .id = EVENT_BUTTON_CONTINUOUS_TAP}; + emit_event(&event); +} + +static void _button_state_update_and_emit(size_t idx) +{ + bool active = qtouch_get_button_state(idx); + struct button_detection_state_t* current = &_bitboxbase_button_state[idx]; + switch (current->button_status) { + case INACTIVE: + if (active) { + current->button_status = ACTIVE; + } + break; + case ACTIVE: + current->duration++; + if (current->duration > LONG_TOUCH) { + _emit_button_continouos_tap(idx); + } + if (!active) { + current->button_status = RELEASED; + } + break; + case RELEASED: + if (current->duration > LONG_TOUCH) { + _emit_button_long_tap(idx); + } else { + _emit_button_short_tap(idx); + } + current->button_status = INACTIVE; + current->duration = 0; + break; + default:; + // Do nothing + } +} +#endif + +/********************************** MEASURE, DETECT and CALLBACK **********************************/ + +/** + * Measures the slider usage and calls registered callbacks to inform a client + * about a detected gesture. + */ +static void _measure_and_emit(void) +{ + qtouch_process(); // Non blocking + if (measurement_done_touch != 1) { + return; + } + + bool gesture_detected = false; + + for (int location = 0; location < TOUCH_NUM_SLIDERS; location++) { + _slider_state_read_and_update(location); + gesture_detected = gesture_detected || _state[location].gesture_type != NONE; + } + +#if PLATFORM_BITBOXBASE == 1 + for (size_t button = 0; button < DEF_NUM_BUTTONS; button++) { + _button_state_update_and_emit(button); + } +#endif + + if (gesture_detected) { + _emit_continuous_slide_event(); + _emit_slide_release_event(); + _emit_long_tap_event(); + _emit_short_tap_event(); + _emit_continuous_tap_event(); + } + + bool both_sliders_released_or_inactive = true; + for (int location = 0; location < TOUCH_NUM_SLIDERS; location++) { + if (_state[location].slider_status != RELEASED && + _state[location].slider_status != INACTIVE) { + both_sliders_released_or_inactive = false; + } + } + if (both_sliders_released_or_inactive) { + _reset_state(); + _released_since_new_screen = true; + } +} + +void gestures_detect(bool reset, bool emit_without_release) +{ + if (reset) { + _reset_state(); + _released_since_new_screen = emit_without_release; + } + _measure_and_emit(); +} diff --git a/src/touch/gestures_bitboxbase.h b/src/touch/gestures_bitboxbase.h new file mode 100644 index 000000000..0761ba598 --- /dev/null +++ b/src/touch/gestures_bitboxbase.h @@ -0,0 +1,25 @@ +// Copyright 2019 Shift Cryptosecurity AG +// +// 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. + +#ifndef __GESTURES_BITBOXBASE_H +#define __GESTURES_BITBOXBASE_H + +enum bitboxbase_button_id_t { + BITBOXBASE_BUTTON_LEFT, + BITBOXBASE_BUTTON_RIGHT, +}; + +enum bitboxbase_button_id_t gestures_button_which(const event_t* event); + +#endif // __GESTURES_BITBOXBASE_H diff --git a/src/touch/gestures_impl.h b/src/touch/gestures_impl.h new file mode 100644 index 000000000..8c771ecd4 --- /dev/null +++ b/src/touch/gestures_impl.h @@ -0,0 +1,39 @@ +// Copyright 2019 Shift Cryptosecurity AG +// +// 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. + +#ifndef __GESTURES_IMPL_H +#define __GESTURES_IMPL_H + +/** Implementation-specific values for the gestures module. */ + +#ifndef TESTING + +#include +#if PLATFORM_BITBOX02 == 1 +#include +#else +#include +#endif + +#define TOUCH_NUM_BUTTONS DEF_NUM_CHANNELS +#define TOUCH_NUM_SLIDERS DEF_NUM_SCROLLERS + +#else + +#define TOUCH_NUM_BUTTONS (8) +#define TOUCH_NUM_SLIDERS (2) + +#endif + +#endif // __GESTURES_IMPL_H diff --git a/src/ui/components/confirm_gesture.c b/src/ui/components/confirm_gesture.c index 3e9a53b35..17d88c3e8 100644 --- a/src/ui/components/confirm_gesture.c +++ b/src/ui/components/confirm_gesture.c @@ -18,7 +18,6 @@ #include "ui_images.h" #include -#include #include #include #include diff --git a/src/ui/components/show_logo.c b/src/ui/components/show_logo.c index 819250a03..25abe70d6 100644 --- a/src/ui/components/show_logo.c +++ b/src/ui/components/show_logo.c @@ -15,6 +15,7 @@ #include "show_logo.h" #include "image.h" #include "ui_images.h" +#include "ui_logos.h" #include #include diff --git a/src/ui/components/trinary_input_string.c b/src/ui/components/trinary_input_string.c index 3896a213a..7eb9cc83b 100644 --- a/src/ui/components/trinary_input_string.c +++ b/src/ui/components/trinary_input_string.c @@ -34,10 +34,6 @@ #include #include -#ifndef TESTING -#include -#endif - #define EMPTY_CHAR '_' #define MASK_CHAR_WIDTH 6 #define BLINK_RATE 200 diff --git a/src/ui/components/ui_images.c b/src/ui/components/ui_images.c index 361720675..d435fd4ba 100644 --- a/src/ui/components/ui_images.c +++ b/src/ui/components/ui_images.c @@ -14,7 +14,6 @@ #include "ui_images.h" -#include #include void image_arrow(int x, int y, int height, arrow_orientation_t orientation) diff --git a/src/ui/components/ui_images.h b/src/ui/components/ui_images.h index e1d8cee5f..6dc10276c 100644 --- a/src/ui/components/ui_images.h +++ b/src/ui/components/ui_images.h @@ -15,79 +15,9 @@ #ifndef _UI_IMAGES_H_ #define _UI_IMAGES_H_ -#include - #include #include -#if PRODUCT_BITBOX_BTCONLY == 1 - -#define IMAGE_BB2_LOGO_W 79 -#define IMAGE_BB2_LOGO_H 25 - -static const uint8_t IMAGE_BB2_LOGO[] = { - 0xfe, 0x0c, 0x30, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xfe, 0x18, 0x60, 0xff, 0x00, 0x00, - 0x00, 0x07, 0x80, 0xf3, 0x06, 0x00, 0xc1, 0x83, 0x00, 0x00, 0x00, 0x10, 0x82, 0x16, 0x0c, 0x67, - 0xe3, 0x06, 0x0f, 0x87, 0x1c, 0x21, 0x08, 0x1c, 0x18, 0xcf, 0xc6, 0x0c, 0x3f, 0x86, 0x30, 0x81, - 0x00, 0x3f, 0xe1, 0x86, 0x0f, 0xf0, 0x63, 0x06, 0xc1, 0x02, 0x00, 0x7f, 0xc3, 0x0c, 0x1f, 0xe1, - 0x83, 0x0f, 0x82, 0x04, 0x01, 0x60, 0xc6, 0x18, 0x30, 0x63, 0x06, 0x0e, 0x04, 0x08, 0x0c, 0xc1, - 0x8c, 0x30, 0x60, 0xc6, 0x0c, 0x1c, 0x08, 0x10, 0x61, 0x83, 0x18, 0x60, 0xc1, 0x8c, 0x18, 0x7c, - 0x10, 0x21, 0x03, 0x06, 0x30, 0xc1, 0x83, 0x0c, 0x60, 0xd8, 0x10, 0x84, 0x07, 0xf8, 0x61, 0xe3, - 0xfc, 0x1f, 0xc3, 0x18, 0x21, 0x08, 0x0f, 0xe0, 0xc1, 0xc7, 0xf0, 0x1f, 0x0e, 0x38, 0x3c, 0x1f, - 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe4, 0x00, - 0x04, 0x00, 0x00, 0x20, 0x00, 0x0a, 0x08, 0x01, 0x21, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x10, - 0x80, 0x02, 0x57, 0x31, 0x97, 0x01, 0x9c, 0xa2, 0x18, 0xeb, 0xa6, 0x77, 0xa4, 0x94, 0xa9, 0x04, - 0xa5, 0x44, 0x4a, 0x52, 0x52, 0x99, 0x49, 0x09, 0x52, 0xe9, 0x4a, 0x50, 0xf4, 0xa4, 0xa5, 0x32, - 0x92, 0x52, 0xa4, 0x12, 0x94, 0xa1, 0x09, 0x49, 0x4a, 0x79, 0x23, 0x19, 0x48, 0x19, 0x28, 0x81, - 0xce, 0x92, 0x64, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}; - -#elif PRODUCT_BITBOX_BASE == 1 || PRODUCT_BITBOXBASE_FACTORYSETUP == 1 - -#define IMAGE_BB2_LOGO_W 96 -#define IMAGE_BB2_LOGO_H 13 - -static const uint8_t IMAGE_BB2_LOGO[] = { - 0xfe, 0x0c, 0x30, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x0c, 0x30, 0x7f, - 0x80, 0x00, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0xc1, 0x80, 0x30, 0x60, 0xc0, 0x00, 0x00, 0x08, - 0x20, 0x00, 0x00, 0x00, 0xc1, 0x8c, 0xfc, 0x60, 0xc1, 0xf0, 0xe3, 0x88, 0x10, 0x00, 0x00, 0x00, - 0xc1, 0x8c, 0xfc, 0x60, 0xc3, 0xf8, 0x63, 0x08, 0x10, 0x70, 0x78, 0x3c, 0xff, 0x0c, 0x30, 0x7f, - 0x83, 0x18, 0x36, 0x08, 0x10, 0x88, 0x84, 0x42, 0xff, 0x0c, 0x30, 0x7f, 0x86, 0x0c, 0x3e, 0x0f, - 0xe1, 0x04, 0x80, 0x81, 0xc1, 0x8c, 0x30, 0x60, 0xc6, 0x0c, 0x1c, 0x08, 0x10, 0x04, 0x80, 0x81, - 0xc1, 0x8c, 0x30, 0x60, 0xc6, 0x0c, 0x1c, 0x08, 0x08, 0xfc, 0x78, 0xff, 0xc1, 0x8c, 0x30, 0x60, - 0xc6, 0x0c, 0x3e, 0x08, 0x09, 0x04, 0x04, 0x80, 0xc1, 0x8c, 0x30, 0x60, 0xc3, 0x18, 0x36, 0x08, - 0x09, 0x04, 0x04, 0x80, 0xff, 0x0c, 0x3c, 0x7f, 0x83, 0xf8, 0x63, 0x08, 0x11, 0x0c, 0x84, 0x41, - 0xfe, 0x0c, 0x1c, 0x7f, 0x01, 0xf0, 0xe3, 0x8f, 0xe0, 0xf4, 0x78, 0x3e}; - -#elif (PRODUCT_BITBOX_MULTI == 1) || PRODUCT_BITBOX02_FACTORYSETUP == 1 - -#define IMAGE_BB2_LOGO_W 79 -#define IMAGE_BB2_LOGO_H 23 - -static const uint8_t IMAGE_BB2_LOGO[] = { - 0xfe, 0x0c, 0x30, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xfe, 0x18, 0x60, 0xff, 0x00, 0x00, - 0x00, 0x07, 0x80, 0xf3, 0x06, 0x00, 0xc1, 0x83, 0x00, 0x00, 0x00, 0x10, 0x82, 0x16, 0x0c, 0x67, - 0xe3, 0x06, 0x0f, 0x87, 0x1c, 0x21, 0x08, 0x1c, 0x18, 0xcf, 0xc6, 0x0c, 0x3f, 0x86, 0x30, 0x81, - 0x00, 0x3f, 0xe1, 0x86, 0x0f, 0xf0, 0x63, 0x06, 0xc1, 0x02, 0x00, 0x7f, 0xc3, 0x0c, 0x1f, 0xe1, - 0x83, 0x0f, 0x82, 0x04, 0x01, 0x60, 0xc6, 0x18, 0x30, 0x63, 0x06, 0x0e, 0x04, 0x08, 0x0c, 0xc1, - 0x8c, 0x30, 0x60, 0xc6, 0x0c, 0x1c, 0x08, 0x10, 0x61, 0x83, 0x18, 0x60, 0xc1, 0x8c, 0x18, 0x7c, - 0x10, 0x21, 0x03, 0x06, 0x30, 0xc1, 0x83, 0x0c, 0x60, 0xd8, 0x10, 0x84, 0x07, 0xf8, 0x61, 0xe3, - 0xfc, 0x1f, 0xc3, 0x18, 0x21, 0x08, 0x0f, 0xe0, 0xc1, 0xc7, 0xf0, 0x1f, 0x0e, 0x38, 0x3c, 0x1f, - 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x04, - 0x10, 0x00, 0xa0, 0x80, 0x00, 0x00, 0x00, 0x01, 0x8c, 0x09, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00, - 0x00, 0x02, 0xaa, 0x57, 0x41, 0x8e, 0xba, 0x67, 0x00, 0x00, 0x00, 0x05, 0x54, 0xa4, 0x84, 0xa5, - 0x25, 0x29, 0x00, 0x00, 0x00, 0x09, 0x29, 0x49, 0x0f, 0x4a, 0x4a, 0x52, 0x00, 0x00, 0x00, 0x12, - 0x52, 0x92, 0x10, 0x94, 0x94, 0xa4, 0x00, 0x00, 0x00, 0x20, 0x99, 0x24, 0x1c, 0xe9, 0x26, 0x48, - 0x00, 0x00, 0x00, 0x00}; - -#else - -#error "Invalid product" - -#endif - #define IMAGE_ROTATE_W 22 #define IMAGE_ROTATE_H 14 diff --git a/src/ui/components/ui_logos.h b/src/ui/components/ui_logos.h new file mode 100644 index 000000000..8ba54d96b --- /dev/null +++ b/src/ui/components/ui_logos.h @@ -0,0 +1,90 @@ +// Copyright 2019 Shift Cryptosecurity AG +// +// 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. + +#ifndef __UI_LOGOS_H +#define __UI_LOGOS_H + +#include + +#include + +#if PRODUCT_BITBOX_BTCONLY == 1 + +#define IMAGE_BB2_LOGO_W 79 +#define IMAGE_BB2_LOGO_H 25 + +static const uint8_t IMAGE_BB2_LOGO[] = { + 0xfe, 0x0c, 0x30, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xfe, 0x18, 0x60, 0xff, 0x00, 0x00, + 0x00, 0x07, 0x80, 0xf3, 0x06, 0x00, 0xc1, 0x83, 0x00, 0x00, 0x00, 0x10, 0x82, 0x16, 0x0c, 0x67, + 0xe3, 0x06, 0x0f, 0x87, 0x1c, 0x21, 0x08, 0x1c, 0x18, 0xcf, 0xc6, 0x0c, 0x3f, 0x86, 0x30, 0x81, + 0x00, 0x3f, 0xe1, 0x86, 0x0f, 0xf0, 0x63, 0x06, 0xc1, 0x02, 0x00, 0x7f, 0xc3, 0x0c, 0x1f, 0xe1, + 0x83, 0x0f, 0x82, 0x04, 0x01, 0x60, 0xc6, 0x18, 0x30, 0x63, 0x06, 0x0e, 0x04, 0x08, 0x0c, 0xc1, + 0x8c, 0x30, 0x60, 0xc6, 0x0c, 0x1c, 0x08, 0x10, 0x61, 0x83, 0x18, 0x60, 0xc1, 0x8c, 0x18, 0x7c, + 0x10, 0x21, 0x03, 0x06, 0x30, 0xc1, 0x83, 0x0c, 0x60, 0xd8, 0x10, 0x84, 0x07, 0xf8, 0x61, 0xe3, + 0xfc, 0x1f, 0xc3, 0x18, 0x21, 0x08, 0x0f, 0xe0, 0xc1, 0xc7, 0xf0, 0x1f, 0x0e, 0x38, 0x3c, 0x1f, + 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe4, 0x00, + 0x04, 0x00, 0x00, 0x20, 0x00, 0x0a, 0x08, 0x01, 0x21, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x10, + 0x80, 0x02, 0x57, 0x31, 0x97, 0x01, 0x9c, 0xa2, 0x18, 0xeb, 0xa6, 0x77, 0xa4, 0x94, 0xa9, 0x04, + 0xa5, 0x44, 0x4a, 0x52, 0x52, 0x99, 0x49, 0x09, 0x52, 0xe9, 0x4a, 0x50, 0xf4, 0xa4, 0xa5, 0x32, + 0x92, 0x52, 0xa4, 0x12, 0x94, 0xa1, 0x09, 0x49, 0x4a, 0x79, 0x23, 0x19, 0x48, 0x19, 0x28, 0x81, + 0xce, 0x92, 0x64, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}; + +#elif PRODUCT_BITBOX_BASE == 1 || PRODUCT_BITBOXBASE_FACTORYSETUP == 1 + +#define IMAGE_BB2_LOGO_W 96 +#define IMAGE_BB2_LOGO_H 13 + +static const uint8_t IMAGE_BB2_LOGO[] = { + 0xfe, 0x0c, 0x30, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x0c, 0x30, 0x7f, + 0x80, 0x00, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0xc1, 0x80, 0x30, 0x60, 0xc0, 0x00, 0x00, 0x08, + 0x20, 0x00, 0x00, 0x00, 0xc1, 0x8c, 0xfc, 0x60, 0xc1, 0xf0, 0xe3, 0x88, 0x10, 0x00, 0x00, 0x00, + 0xc1, 0x8c, 0xfc, 0x60, 0xc3, 0xf8, 0x63, 0x08, 0x10, 0x70, 0x78, 0x3c, 0xff, 0x0c, 0x30, 0x7f, + 0x83, 0x18, 0x36, 0x08, 0x10, 0x88, 0x84, 0x42, 0xff, 0x0c, 0x30, 0x7f, 0x86, 0x0c, 0x3e, 0x0f, + 0xe1, 0x04, 0x80, 0x81, 0xc1, 0x8c, 0x30, 0x60, 0xc6, 0x0c, 0x1c, 0x08, 0x10, 0x04, 0x80, 0x81, + 0xc1, 0x8c, 0x30, 0x60, 0xc6, 0x0c, 0x1c, 0x08, 0x08, 0xfc, 0x78, 0xff, 0xc1, 0x8c, 0x30, 0x60, + 0xc6, 0x0c, 0x3e, 0x08, 0x09, 0x04, 0x04, 0x80, 0xc1, 0x8c, 0x30, 0x60, 0xc3, 0x18, 0x36, 0x08, + 0x09, 0x04, 0x04, 0x80, 0xff, 0x0c, 0x3c, 0x7f, 0x83, 0xf8, 0x63, 0x08, 0x11, 0x0c, 0x84, 0x41, + 0xfe, 0x0c, 0x1c, 0x7f, 0x01, 0xf0, 0xe3, 0x8f, 0xe0, 0xf4, 0x78, 0x3e}; + +#elif (PRODUCT_BITBOX_MULTI == 1) || PRODUCT_BITBOX02_FACTORYSETUP == 1 + +#define IMAGE_BB2_LOGO_W 79 +#define IMAGE_BB2_LOGO_H 23 + +static const uint8_t IMAGE_BB2_LOGO[] = { + 0xfe, 0x0c, 0x30, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xfe, 0x18, 0x60, 0xff, 0x00, 0x00, + 0x00, 0x07, 0x80, 0xf3, 0x06, 0x00, 0xc1, 0x83, 0x00, 0x00, 0x00, 0x10, 0x82, 0x16, 0x0c, 0x67, + 0xe3, 0x06, 0x0f, 0x87, 0x1c, 0x21, 0x08, 0x1c, 0x18, 0xcf, 0xc6, 0x0c, 0x3f, 0x86, 0x30, 0x81, + 0x00, 0x3f, 0xe1, 0x86, 0x0f, 0xf0, 0x63, 0x06, 0xc1, 0x02, 0x00, 0x7f, 0xc3, 0x0c, 0x1f, 0xe1, + 0x83, 0x0f, 0x82, 0x04, 0x01, 0x60, 0xc6, 0x18, 0x30, 0x63, 0x06, 0x0e, 0x04, 0x08, 0x0c, 0xc1, + 0x8c, 0x30, 0x60, 0xc6, 0x0c, 0x1c, 0x08, 0x10, 0x61, 0x83, 0x18, 0x60, 0xc1, 0x8c, 0x18, 0x7c, + 0x10, 0x21, 0x03, 0x06, 0x30, 0xc1, 0x83, 0x0c, 0x60, 0xd8, 0x10, 0x84, 0x07, 0xf8, 0x61, 0xe3, + 0xfc, 0x1f, 0xc3, 0x18, 0x21, 0x08, 0x0f, 0xe0, 0xc1, 0xc7, 0xf0, 0x1f, 0x0e, 0x38, 0x3c, 0x1f, + 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x04, + 0x10, 0x00, 0xa0, 0x80, 0x00, 0x00, 0x00, 0x01, 0x8c, 0x09, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x02, 0xaa, 0x57, 0x41, 0x8e, 0xba, 0x67, 0x00, 0x00, 0x00, 0x05, 0x54, 0xa4, 0x84, 0xa5, + 0x25, 0x29, 0x00, 0x00, 0x00, 0x09, 0x29, 0x49, 0x0f, 0x4a, 0x4a, 0x52, 0x00, 0x00, 0x00, 0x12, + 0x52, 0x92, 0x10, 0x94, 0x94, 0xa4, 0x00, 0x00, 0x00, 0x20, 0x99, 0x24, 0x1c, 0xe9, 0x26, 0x48, + 0x00, 0x00, 0x00, 0x00}; + +#else + +#error "Invalid product" + +#endif + +#endif // __UI_LOGOS_H diff --git a/src/ui/components/waiting.c b/src/ui/components/waiting.c index e9fa3bc8f..6b849439e 100644 --- a/src/ui/components/waiting.c +++ b/src/ui/components/waiting.c @@ -16,6 +16,7 @@ #include "image.h" #include "ui_images.h" +#include "ui_logos.h" #include #include diff --git a/test/device-test/CMakeLists.txt b/test/device-test/CMakeLists.txt index 5b35da53e..f76d08a98 100644 --- a/test/device-test/CMakeLists.txt +++ b/test/device-test/CMakeLists.txt @@ -135,7 +135,10 @@ foreach(name ${BB02_TEST_LIST}) target_link_libraries(${elf} PRIVATE c + "-Wl,--start-group" + workflows bitbox02-test-platform + "-Wl,--end-group" asf4-drivers-min ${QTOUCHLIB_A} ${QTOUCHLIB_B} diff --git a/test/device-test/src/test_bitboxbase_touch_demo.c b/test/device-test/src/test_bitboxbase_touch_demo.c index e84707746..bb4251443 100644 --- a/test/device-test/src/test_bitboxbase_touch_demo.c +++ b/test/device-test/src/test_bitboxbase_touch_demo.c @@ -25,6 +25,7 @@ #include "qtouch.h" #include "screen.h" #include "touch/gestures.h" +#include "touch/gestures_bitboxbase.h" #include "ui/component.h" #include "ui/components/label.h" #include "ui/oled/oled.h" diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index 263d1bed9..42244d6fd 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt @@ -20,6 +20,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter -Wno-missing-prototype set(DBB-FILTERED-SOURCES ${DBB-FIRMWARE-COMMON-SOURCES} + ${DBB-FIRMWARE-UI-COMMON-SOURCES} ${DBB-FIRMWARE-UI-SOURCES} ${DBB-FIRMWARE-PROTOBUF-SOURCES} ${FIRMWARE-U2F-SOURCES} @@ -46,6 +47,8 @@ find_package(Nanopb REQUIRED) add_library(bitbox STATIC + ${DBB-FIRMWARE-COMPONENT-SOURCES} + ${DBB-FIRMWARE-WORKFLOW-SOURCES} ${APP-BTC-SOURCES} ${DBB-FILTERED-SOURCES} ${CTAES-SOURCES} diff --git a/test/unit-test/framework/mock_gestures.c b/test/unit-test/framework/mock_gestures.c index 47c25e555..46a3ea79a 100644 --- a/test/unit-test/framework/mock_gestures.c +++ b/test/unit-test/framework/mock_gestures.c @@ -20,6 +20,8 @@ #include "mock_gestures.h" #include "mock_qtouch.h" + +#include #include #define MEASUREMENT_PERIOD 125 From e65d80869970f74beb6fc8bf4d92cafb248374bf Mon Sep 17 00:00:00 2001 From: Simone Baratta Date: Wed, 4 Dec 2019 11:51:55 +0100 Subject: [PATCH 4/4] cmake: Deduce PRODUCT_ macros from PLATFORM_ and EDITION_. Instead of #defininig all the possible PRODUCT_ macros, it makes more sense to enforce the definition of the (limited) PLATFORM_ and EDITION_ macros, and extract the relevant definitions of PRODUCT_* from there. This makes it easier to enforce that the macros are defined consistently, and allows further separation of code that is dependent on the platform it will run on, but not on the edition (e.g. the touch code depends on the PLATFORM_*, but it doesn't matter whether it will run on a -multi or on a -btconly device). --- src/CMakeLists.txt | 39 +++++++++-------- src/platform/platform_config.h | 75 +++++++++++++++++++++++++-------- test/device-test/CMakeLists.txt | 4 +- test/unit-test/CMakeLists.txt | 12 ++++-- 4 files changed, 88 insertions(+), 42 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 54c5773d1..3edb25d0d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -69,7 +69,6 @@ set(DBB-FIRMWARE-UI-SOURCES ${CMAKE_SOURCE_DIR}/src/ui/components/show_logo.c ${CMAKE_SOURCE_DIR}/src/ui/components/waiting.c ${CMAKE_SOURCE_DIR}/src/ui/screen_process.c - ${CMAKE_SOURCE_DIR}/src/ui/ugui/ugui.c ${CMAKE_SOURCE_DIR}/src/touch/gestures.c ) set(DBB-FIRMWARE-UI-SOURCES ${DBB-FIRMWARE-UI-SOURCES} PARENT_SCOPE) @@ -134,7 +133,6 @@ set(DBB-BOOTLOADER-SOURCES ${CMAKE_SOURCE_DIR}/src/bootloader/mpu_regions.c ${CMAKE_SOURCE_DIR}/src/queue.c ${CMAKE_SOURCE_DIR}/src/usb/usb_processing.c - ${CMAKE_SOURCE_DIR}/src/ui/ugui/ugui.c ${CMAKE_SOURCE_DIR}/src/ui/fonts/font_a_9X9.c ${CMAKE_SOURCE_DIR}/src/hardfault.c ${CMAKE_SOURCE_DIR}/src/ui/components/ui_images.c @@ -150,6 +148,7 @@ set(DRIVER-SOURCES ${CMAKE_SOURCE_DIR}/src/platform/platform_init.c ${CMAKE_SOURCE_DIR}/src/qtouch/qtouch.c ${CMAKE_SOURCE_DIR}/src/ui/oled/oled.c + ${CMAKE_SOURCE_DIR}/src/ui/ugui/ugui.c ) set(DRIVER-SOURCES ${DRIVER-SOURCES} PARENT_SCOPE) @@ -521,25 +520,25 @@ if(CMAKE_CROSSCOMPILING) target_sources(${bootloader}.elf PRIVATE ${BITBOXBASE-ONLY-SOURCES}) endforeach(bootloader) - target_compile_definitions(bootloader.elf PRIVATE PRODUCT_BITBOX_MULTI) - target_compile_definitions(bootloader-development.elf PRIVATE PRODUCT_BITBOX_MULTI BOOTLOADER_DEVDEVICE) - target_compile_definitions(bootloader-semihosting.elf PRIVATE PRODUCT_BITBOX_MULTI BOOTLOADER_DEVDEVICE SEMIHOSTING) - target_compile_definitions(bootloader-development-locked.elf PRIVATE PRODUCT_BITBOX_MULTI BOOTLOADER_DEVDEVICE BOOTLOADER_PRODUCTION) + target_compile_definitions(bootloader.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1") + target_compile_definitions(bootloader-development.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" BOOTLOADER_DEVDEVICE) + target_compile_definitions(bootloader-semihosting.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" BOOTLOADER_DEVDEVICE SEMIHOSTING) + target_compile_definitions(bootloader-development-locked.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" BOOTLOADER_DEVDEVICE BOOTLOADER_PRODUCTION) set_property(TARGET bootloader-development-locked.elf PROPERTY EXCLUDE_FROM_ALL ON) - target_compile_definitions(bootloader-production.elf PRIVATE PRODUCT_BITBOX_MULTI BOOTLOADER_PRODUCTION) + target_compile_definitions(bootloader-production.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" BOOTLOADER_PRODUCTION) set_property(TARGET bootloader-production.elf PROPERTY EXCLUDE_FROM_ALL ON) - target_compile_definitions(bootloader-btc.elf PRIVATE PRODUCT_BITBOX_BTCONLY) - target_compile_definitions(bootloader-btc-development.elf PRIVATE PRODUCT_BITBOX_BTCONLY BOOTLOADER_DEVDEVICE) - target_compile_definitions(bootloader-btc-production.elf PRIVATE PRODUCT_BITBOX_BTCONLY BOOTLOADER_PRODUCTION) + target_compile_definitions(bootloader-btc.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_BTCONLY=1") + target_compile_definitions(bootloader-btc-development.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_BTCONLY=1" BOOTLOADER_DEVDEVICE) + target_compile_definitions(bootloader-btc-production.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_BTCONLY=1" BOOTLOADER_PRODUCTION) set_property(TARGET bootloader-btc-production.elf PROPERTY EXCLUDE_FROM_ALL ON) - target_compile_definitions(bootloader-bitboxbase.elf PRIVATE PRODUCT_BITBOX_BASE) - target_compile_definitions(bootloader-bitboxbase-development.elf PRIVATE BOOTLOADER_DEVDEVICE PRODUCT_BITBOX_BASE) - target_compile_definitions(bootloader-bitboxbase-semihosting.elf PRIVATE BOOTLOADER_DEVDEVICE PRODUCT_BITBOX_BASE SEMIHOSTING) - target_compile_definitions(bootloader-bitboxbase-production.elf PRIVATE BOOTLOADER_PRODUCTION PRODUCT_BITBOX_BASE) + target_compile_definitions(bootloader-bitboxbase.elf PRIVATE "PLATFORM_BITBOXBASE=1" "EDITION_STANDARD=1") + target_compile_definitions(bootloader-bitboxbase-development.elf PRIVATE BOOTLOADER_DEVDEVICE "PLATFORM_BITBOXBASE=1" "EDITION_STANDARD=1") + target_compile_definitions(bootloader-bitboxbase-semihosting.elf PRIVATE BOOTLOADER_DEVDEVICE "PLATFORM_BITBOXBASE=1" "EDITION_STANDARD=1" SEMIHOSTING) + target_compile_definitions(bootloader-bitboxbase-production.elf PRIVATE BOOTLOADER_PRODUCTION "PLATFORM_BITBOXBASE=1" "EDITION_STANDARD=1") set_property(TARGET bootloader-bitboxbase-production.elf PROPERTY EXCLUDE_FROM_ALL ON) set(FIRMWARES @@ -610,7 +609,7 @@ if(CMAKE_CROSSCOMPILING) endforeach(firmware) target_sources(firmware.elf PRIVATE firmware.c) - target_compile_definitions(firmware.elf PRIVATE PRODUCT_BITBOX_MULTI "APP_ETH=1" "APP_U2F=1") + target_compile_definitions(firmware.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" "APP_ETH=1" "APP_U2F=1") target_sources(firmware.elf PRIVATE ${FIRMWARE-U2F-SOURCES}) target_link_libraries(firmware.elf PRIVATE bitbox02-platform) target_link_libraries(firmware.elf PRIVATE app_btc-multi) @@ -621,21 +620,21 @@ if(CMAKE_CROSSCOMPILING) target_link_libraries(firmware-semihosting.elf PRIVATE app_btc-multi) # Select an implementation of the system calls that can communicate with the debugger - target_compile_definitions(firmware-semihosting.elf PRIVATE PRODUCT_BITBOX_MULTI "APP_ETH=1" "APP_U2F=1") + target_compile_definitions(firmware-semihosting.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" "APP_ETH=1" "APP_U2F=1") target_compile_definitions(firmware-semihosting.elf PRIVATE SEMIHOSTING) target_sources(firmware-btc.elf PRIVATE firmware.c) - target_compile_definitions(firmware-btc.elf PRIVATE PRODUCT_BITBOX_BTCONLY "APP_ETH=0" "APP_U2F=0") + target_compile_definitions(firmware-btc.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_BTCONLY=1" "APP_ETH=0" "APP_U2F=0") target_link_libraries(firmware-btc.elf PRIVATE bitbox02-platform) target_link_libraries(firmware-btc.elf PRIVATE app_btc-btc) target_sources(firmware-bitboxbase.elf PRIVATE bitboxbase/bitboxbase.c) - target_compile_definitions(firmware-bitboxbase.elf PRIVATE PRODUCT_BITBOX_BASE "APP_BTC=0" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") + target_compile_definitions(firmware-bitboxbase.elf PRIVATE "PLATFORM_BITBOXBASE=1" "EDITION_STANDARD=1" "APP_BTC=0" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") target_sources(firmware-bitboxbase.elf PRIVATE ${BITBOXBASE-FIRMWARE-SOURCES}) target_link_libraries(firmware-bitboxbase.elf PRIVATE bitboxbase-platform) target_sources(firmware-bitboxbase-semihosting.elf PRIVATE bitboxbase/bitboxbase.c) - target_compile_definitions(firmware-bitboxbase-semihosting.elf PRIVATE PRODUCT_BITBOX_BASE SEMIHOSTING "APP_BTC=0" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") + target_compile_definitions(firmware-bitboxbase-semihosting.elf PRIVATE "PLATFORM_BITBOXBASE=1" "EDITION_STANDARD=1" SEMIHOSTING "APP_BTC=0" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") target_sources(firmware-bitboxbase-semihosting.elf PRIVATE ${BITBOXBASE-FIRMWARE-SOURCES}) target_link_libraries(firmware-bitboxbase-semihosting.elf PRIVATE bitboxbase-platform) @@ -647,7 +646,7 @@ if(CMAKE_CROSSCOMPILING) target_link_libraries(factory-setup.elf PRIVATE bitbox02-platform) target_sources(factory-setup-bitboxbase.elf PRIVATE factorysetup.c) - target_compile_definitions(factory-setup-bitboxbase.elf PRIVATE PRODUCT_BITBOXBASE_FACTORYSETUP "APP_BTC=0" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") + target_compile_definitions(factory-setup-bitboxbase.elf PRIVATE "PLATFORM_BITBOXBASE=1" "EDITION_FACTORYSETUP=1" "APP_BTC=0" "APP_LTC=0" "APP_ETH=0" "APP_U2F=0") target_link_libraries(factory-setup-bitboxbase.elf PRIVATE bitboxbase-platform) foreach(name ${BOOTLOADERS} ${FIRMWARES}) diff --git a/src/platform/platform_config.h b/src/platform/platform_config.h index ba97cbbe2..763bc8d1f 100644 --- a/src/platform/platform_config.h +++ b/src/platform/platform_config.h @@ -15,67 +15,108 @@ #ifndef _PLATFORM_CONFIG_H #define _PLATFORM_CONFIG_H -// Force the PRODUCT_ defines to be 0 or 1, so they can be used safely without risk of typos. +#if !defined(PLATFORM_BITBOX02) +#define PLATFORM_BITBOX02 0 +#elif PLATFORM_BITBOX02 != 0 && PLATFORM_BITBOX02 != 1 +#error "Invalid value for PLATFORM_BITBOX02." +#endif + +#if !defined(PLATFORM_BITBOXBASE) +#define PLATFORM_BITBOXBASE 0 +#elif PLATFORM_BITBOXBASE != 0 && PLATFORM_BITBOXBASE != 1 +#error "Invalid value for PLATFORM_BITBOXBASE." +#endif + +#if !defined(EDITION_STANDARD) +#define EDITION_STANDARD 0 +#elif EDITION_STANDARD != 0 && EDITION_STANDARD != 1 +#error "Invalid value for EDITION_STANDARD." +#endif +#if !defined(EDITION_BTCONLY) +#define EDITION_BTCONLY 0 +#elif EDITION_BTCONLY != 0 && EDITION_BTCONLY != 1 +#error "Invalid value for EDITION_BTCONLY." +#endif +#if !defined(EDITION_FACTORYSETUP) +#define EDITION_FACTORYSETUP 0 +#elif EDITION_FACTORYSETUP != 0 && EDITION_FACTORYSETUP != 1 +#error "Invalid value for EDITION_FACTORYSETUP." +#endif + +#if PLATFORM_BITBOX02 == 1 + +#if EDITION_STANDARD == 1 +#define PRODUCT_BITBOX_MULTI 1 +#elif EDITION_BTCONLY == 1 +#define PRODUCT_BITBOX_BTCONLY 1 +#elif EDITION_FACTORYSETUP == 1 +#define PRODUCT_BITBOX02_FACTORYSETUP 1 +#else +#error "Invalid EDITION value." +#endif + +#elif PLATFORM_BITBOXBASE == 1 + +#if EDITION_STANDARD == 1 +#define PRODUCT_BITBOX_BASE 1 +#elif EDITION_FACTORYSETUP == 1 +#define PRODUCT_BITBOXBASE_FACTORYSETUP 1 +#else +#error "Invalid EDITION value." +#endif + +#else +#error "Invalid PRODUCT value." +#endif #if !defined(PRODUCT_BITBOX_MULTI) #define PRODUCT_BITBOX_MULTI 0 #elif PRODUCT_BITBOX_MULTI != 1 -#error "invalid product value" +#error "invalid PRODUCT_BITBOX_MULTI value" #endif #if !defined(PRODUCT_BITBOX_BTCONLY) #define PRODUCT_BITBOX_BTCONLY 0 #elif PRODUCT_BITBOX_BTCONLY != 1 -#error "invalid product value" +#error "invalid PRODUCT_BITBOX_BTCONLY value" #endif #if !defined(PRODUCT_BITBOX_BASE) #define PRODUCT_BITBOX_BASE 0 #elif PRODUCT_BITBOX_BASE != 1 -#error "invalid product value" +#error "invalid PRODUCT_BITBOX_BASE value" #endif #if !defined(PRODUCT_BITBOX02_FACTORYSETUP) #define PRODUCT_BITBOX02_FACTORYSETUP 0 #elif PRODUCT_BITBOX02_FACTORYSETUP != 1 -#error "invald product value" +#error "invald PRODUCT_BITBOX02_FACTORYSETUP value" #endif - #if !defined(PRODUCT_BITBOXBASE_FACTORYSETUP) #define PRODUCT_BITBOXBASE_FACTORYSETUP 0 #elif PRODUCT_BITBOXBASE_FACTORYSETUP != 1 -#error "invald product value" +#error "invald PRODUCT_BITBOXBASE_FACTORYSETUP value" #endif // Derive other useful definitions from the product. #if PRODUCT_BITBOX_MULTI == 1 -#define PLATFORM_BITBOX02 1 -#define PLATFORM_BITBOXBASE 0 #define FACTORYSETUP 0 #endif #if PRODUCT_BITBOX_BTCONLY == 1 -#define PLATFORM_BITBOX02 1 -#define PLATFORM_BITBOXBASE 0 #define FACTORYSETUP 0 #endif #if PRODUCT_BITBOX_BASE == 1 -#define PLATFORM_BITBOX02 0 -#define PLATFORM_BITBOXBASE 1 #define FACTORYSETUP 0 #endif #if PRODUCT_BITBOX02_FACTORYSETUP == 1 -#define PLATFORM_BITBOX02 1 -#define PLATFORM_BITBOXBASE 0 #define FACTORYSETUP 1 #endif #if PRODUCT_BITBOXBASE_FACTORYSETUP == 1 -#define PLATFORM_BITBOX02 0 -#define PLATFORM_BITBOXBASE 1 #define FACTORYSETUP 1 #endif diff --git a/test/device-test/CMakeLists.txt b/test/device-test/CMakeLists.txt index f76d08a98..d75b3db6e 100644 --- a/test/device-test/CMakeLists.txt +++ b/test/device-test/CMakeLists.txt @@ -86,7 +86,7 @@ target_link_libraries(bitbox02-test-platform ) # Always enable semihosting for the test firmwares -target_compile_definitions(bitbox02-test-platform PUBLIC PRODUCT_BITBOX_MULTI SEMIHOSTING) +target_compile_definitions(bitbox02-test-platform PUBLIC "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" SEMIHOSTING) target_link_libraries(bitbox02-test-platform PUBLIC --specs=nano.specs --specs=rdimon.specs) target_compile_options(bitbox02-test-platform PUBLIC --specs=nano.specs --specs=rdimon.specs) @@ -193,7 +193,7 @@ target_link_libraries(bitboxbase-test-platform add_dependencies(bitboxbase-test-platform rust-cbindgen) # Always enable semihosting for the test firmwares -target_compile_definitions(bitboxbase-test-platform PUBLIC PRODUCT_BITBOX_BASE SEMIHOSTING) +target_compile_definitions(bitboxbase-test-platform PUBLIC "PLATFORM_BITBOXBASE=1" "EDITION_STANDARD=1" SEMIHOSTING) target_link_libraries(bitboxbase-test-platform PUBLIC --specs=nano.specs --specs=rdimon.specs) target_compile_options(bitboxbase-test-platform PUBLIC --specs=nano.specs --specs=rdimon.specs) diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index 42244d6fd..a4b248351 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt @@ -47,12 +47,18 @@ find_package(Nanopb REQUIRED) add_library(bitbox STATIC + ${DBB-FIRMWARE-COMMON-SOURCES} ${DBB-FIRMWARE-COMPONENT-SOURCES} ${DBB-FIRMWARE-WORKFLOW-SOURCES} ${APP-BTC-SOURCES} - ${DBB-FILTERED-SOURCES} + ${DBB-FIRMWARE-UI-COMMON-SOURCES} + ${DBB-FIRMWARE-UI-SOURCES} + ${DBB-FIRMWARE-PROTOBUF-SOURCES} + ${DBB-FIRMWARE-USB-SOURCES} + ${DBB-FIRMWARE-USART-SOURCES} ${CTAES-SOURCES} ${ETHEREUM-SOURCES} + ${FIRMWARE-U2F-SOURCES} # The usb.c file mixes together hardware and testing code... This should be split. ${CMAKE_SOURCE_DIR}/src/usb/usb.c ${CMAKE_SOURCE_DIR}/src/usb/usb_frame.c @@ -94,7 +100,7 @@ set_source_files_properties( target_include_directories(bitbox SYSTEM PUBLIC ${NANOPB_INCLUDE_DIRS}) target_include_directories(bitbox PRIVATE ${CMAKE_SOURCE_DIR}/external/FatFs/source) target_compile_definitions(bitbox PUBLIC "PB_NO_PACKED_STRUCTS=1" "PB_FIELD_16BIT=1") -target_compile_definitions(bitbox PUBLIC "PRODUCT_BITBOX_MULTI=1" "APP_BTC=1" "APP_LTC=1" "APP_U2F=1" "APP_ETH=1") +target_compile_definitions(bitbox PUBLIC "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" "APP_BTC=1" "APP_LTC=1" "APP_U2F=1" "APP_ETH=1") add_dependencies(bitbox generate-protobufs) # Since noiseprotocol and wallycore are external projects we need to specify the dependency @@ -146,7 +152,7 @@ target_include_directories( ${INCLUDES} ${CMAKE_BINARY_DIR}/src ) -target_compile_definitions(u2f-util PUBLIC "TESTING" PRODUCT_BITBOX_MULTI "APP_U2F=1" "APP_BTC=1" "APP_LTC=1" "APP_ETH=1") +target_compile_definitions(u2f-util PUBLIC "TESTING" "PLATFORM_BITBOX02=1" "EDITION_STANDARD=1" "APP_U2F=1" "APP_BTC=1" "APP_LTC=1" "APP_ETH=1") target_compile_definitions(u2f-util PUBLIC "USE_KECCAK")