Skip to content

Commit

Permalink
wip: Enforce PRODUCT_* macros throughout the code (not working)
Browse files Browse the repository at this point in the history
  • Loading branch information
conte91 committed Dec 4, 2019
1 parent fc9cea4 commit 85e65cf
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 56 deletions.
36 changes: 18 additions & 18 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -515,25 +515,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_BTC=1")
target_compile_definitions(bootloader-btc-development.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_BTC=1" BOOTLOADER_DEVDEVICE)
target_compile_definitions(bootloader-btc-production.elf PRIVATE "PLATFORM_BITBOX02=1" "EDITION_BTC=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
Expand Down Expand Up @@ -604,7 +604,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)
Expand All @@ -615,21 +615,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_BTC=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_ETH=0" "APP_LTC=0" "APP_U2F=0")
target_compile_definitions(firmware-bitboxbase.elf PRIVATE "PLATFORM_BITBOXBASE=1" "EDITION_STANDARD=1" "APP_BTC=0" "APP_ETH=0" "APP_LTC=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)
target_compile_definitions(firmware-bitboxbase-semihosting.elf PRIVATE "PLATFORM_BITBOXBASE=1" "EDITION_STANDARD=1" SEMIHOSTING)
target_sources(firmware-bitboxbase-semihosting.elf PRIVATE ${BITBOXBASE-FIRMWARE-SOURCES})
target_link_libraries(firmware-bitboxbase-semihosting.elf PRIVATE bitboxbase-platform)

Expand All @@ -641,7 +641,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)
target_compile_definitions(factory-setup-bitboxbase.elf PRIVATE "PLATFORM_BITBOXBASE=1" "EDITION_FACTORYSETUP=1")
target_link_libraries(factory-setup-bitboxbase.elf PRIVATE bitboxbase-platform)

foreach(name ${BOOTLOADERS} ${FIRMWARES})
Expand Down
76 changes: 59 additions & 17 deletions src/platform/platform_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,67 +15,109 @@
#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_BTC == 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

Expand Down
4 changes: 4 additions & 0 deletions src/qtouch/qtouch.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Copyright (c) 2017 Microchip. All rights reserved.
#include <driver_init.h>
#include <platform_config.h>

#if PLATFORM_BITBOXBASE == 1
#include "qtouch_bitboxbase.h"
#endif

/*----------------------------------------------------------------------------
* prototypes
*----------------------------------------------------------------------------*/
Expand Down
4 changes: 0 additions & 4 deletions src/qtouch/qtouch.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ extern "C" {
#include "touch_api_ptc.h"
#include <platform_config.h>

#if PLATFORM_BITBOXBASE == 1
bool qtouch_get_button_state(size_t idx);
#endif

/**********************************************************/
/******************* Acquisition controls *****************/
/**********************************************************/
Expand Down
1 change: 1 addition & 0 deletions src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "screen.h"

#include <hal_delay.h>
#include <platform/platform_config.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
Expand Down
12 changes: 0 additions & 12 deletions src/touch/gestures.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include <stdbool.h>

#include <platform/platform_config.h>
#include <screen.h>
#include <ui/component.h>

Expand All @@ -40,13 +39,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
Expand All @@ -57,8 +49,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
2 changes: 1 addition & 1 deletion src/ui/components/confirm_gesture.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "ui_images.h"

#include <hardfault.h>
#include <platform/platform_config.h>
#include <qtouch.h>
#include <screen.h>
#include <touch/gestures.h>
#include <ui/ui_util.h>
Expand Down
1 change: 1 addition & 0 deletions src/ui/components/icon_button.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "ui_images.h"

#include <hardfault.h>
#include <qtouch.h>
#include <screen.h>
#include <touch/gestures.h>
#include <ui/ui_util.h>
Expand Down
1 change: 1 addition & 0 deletions src/ui/components/label.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "knight_rider.h"

#include <hardfault.h>
#include <qtouch.h>
#include <screen.h>
#include <string.h>
#include <touch/gestures.h>
Expand Down
1 change: 1 addition & 0 deletions src/ui/components/left_arrow.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <hardfault.h>
#include <screen.h>
#include <touch/gestures.h>
#include <qtouch.h>
#include <ui/ui_util.h>
#include <util.h>

Expand Down
1 change: 1 addition & 0 deletions src/ui/components/right_arrow.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "right_arrow.h"

#include <hardfault.h>
#include <qtouch.h>
#include <screen.h>
#include <touch/gestures.h>
#include <ui/ui_util.h>
Expand Down
1 change: 1 addition & 0 deletions src/ui/components/trinary_input_char.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "trinary_input_char.h"

#include "button.h"
#include "qtouch.h"

#include <hardfault.h>
#include <touch/gestures.h>
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/trinary_input_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <string.h>

#ifndef TESTING
#include <driver_init.h>
//#include <driver_init.h>
#endif

#define EMPTY_CHAR '_'
Expand Down
1 change: 0 additions & 1 deletion src/ui/components/ui_images.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include "ui_images.h"

#include <platform/platform_config.h>
#include <ui/ugui/ugui.h>

void image_arrow(int x, int y, int height, arrow_orientation_t orientation)
Expand Down
2 changes: 0 additions & 2 deletions src/ui/components/ui_images.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#ifndef _UI_IMAGES_H_
#define _UI_IMAGES_H_

#include <platform/platform_config.h>

#include <stdbool.h>
#include <stdint.h>

Expand Down
3 changes: 3 additions & 0 deletions src/ui/components/ui_logos.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#define __UI_LOGOS_H

#include <stdint.h>

#include <platform/platform_config.h>

#if PRODUCT_BITBOX_BTCONLY == 1

#define IMAGE_BB2_LOGO_W 79
Expand Down

0 comments on commit 85e65cf

Please sign in to comment.