-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib_nbgl: nbgl_sync_use_case: First version
- Loading branch information
Xavier Chapron
committed
Apr 10, 2024
1 parent
90d0dce
commit dfd3050
Showing
3 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "nbgl_use_case.h" | ||
|
||
typedef enum { | ||
NBGL_SYNC_RET_APPROVED, | ||
NBGL_SYNC_RET_REJECTED, | ||
NBGL_SYNC_RET_QUITTED, | ||
NBGL_SYNC_RET_APDU_RECEIVED, | ||
NBGL_SYNC_RET_ERROR | ||
} nbgl_sync_ret_t; | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseHomeAndSettings(const char *appName, | ||
const nbgl_icon_details_t *appIcon, | ||
const char *tagline, | ||
const uint8_t initSettingPage, | ||
const nbgl_genericContents_t *settingContents, | ||
const nbgl_contentInfoList_t *infosList, | ||
const nbgl_homeAction_t *action); | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseReview(nbgl_operationType_t operationType, | ||
const nbgl_layoutTagValueList_t *tagValueList, | ||
const nbgl_icon_details_t *icon, | ||
const char *reviewTitle, | ||
const char *reviewSubTitle, | ||
const char *finishTitle); | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseAddressReview( | ||
const char *address, | ||
const nbgl_layoutTagValueList_t *additionalTagValueList, | ||
const nbgl_icon_details_t *icon, | ||
const char *reviewTitle, | ||
const char *reviewSubTitle); | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseReviewStatus(nbgl_reviewStatusType_t reviewStatusType); | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseStatus(const char *message, bool isSuccess); | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseReviewStreamingStart(nbgl_operationType_t operationType, | ||
const nbgl_icon_details_t *icon, | ||
const char *reviewTitle, | ||
const char *reviewSubTitle); | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseReviewStreamingContinue( | ||
const nbgl_layoutTagValueList_t *tagValueList); | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseReviewStreamingFinish(const char *finishTitle); | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseGenericReview(const nbgl_genericContents_t *contents, | ||
const char *rejectText); | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseGenericConfiguration(const char *title, | ||
uint8_t initPage, | ||
const nbgl_genericContents_t *contents); | ||
|
||
/* | ||
* This function must be implemented by the caller. | ||
* It must wait for the next seph event and process it except for APDU events. | ||
* It must return: | ||
* - true when an APDU has been received in the processed event | ||
* - false otherwise | ||
* | ||
* Note on C apps using SDK lib_standard_app, this is already provided in io.c by the lib. | ||
*/ | ||
extern bool io_recv_and_process_event(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
#include "nbgl_sync_use_case.h" | ||
|
||
static nbgl_sync_ret_t g_ret; | ||
static bool g_ended; | ||
|
||
static void choice_callback(bool confirm) | ||
{ | ||
if (confirm) { | ||
g_ret = NBGL_SYNC_RET_APPROVED; | ||
} | ||
else { | ||
g_ret = NBGL_SYNC_RET_REJECTED; | ||
} | ||
|
||
g_ended = true; | ||
} | ||
|
||
static void quit_callback(void) | ||
{ | ||
g_ret = NBGL_SYNC_RET_QUITTED; | ||
g_ended = true; | ||
} | ||
|
||
static void rejected_callback(void) | ||
{ | ||
g_ret = NBGL_SYNC_RET_REJECTED; | ||
g_ended = true; | ||
} | ||
|
||
static void nbgl_sync_init(void) | ||
{ | ||
g_ended = false; | ||
g_ret = NBGL_SYNC_RET_ERROR; | ||
} | ||
|
||
static nbgl_sync_ret_t nbgl_sync_wait(bool exitOnApdu) | ||
{ | ||
bool apduReceived; | ||
|
||
while (!g_ended) { | ||
apduReceived = io_recv_and_process_event(); | ||
if (exitOnApdu && apduReceived) { | ||
return NBGL_SYNC_RET_APDU_RECEIVED; | ||
} | ||
} | ||
|
||
return g_ret; | ||
} | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseHomeAndSettings(const char *appName, | ||
const nbgl_icon_details_t *appIcon, | ||
const char *tagline, | ||
const uint8_t initSettingPage, | ||
const nbgl_genericContents_t *settingContents, | ||
const nbgl_contentInfoList_t *infosList, | ||
const nbgl_homeAction_t *action) | ||
{ | ||
nbgl_sync_init(); | ||
nbgl_useCaseHomeAndSettings(appName, | ||
appIcon, | ||
tagline, | ||
initSettingPage, | ||
settingContents, | ||
infosList, | ||
action, | ||
quit_callback); | ||
return nbgl_sync_wait(true); | ||
} | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseReview(nbgl_operationType_t operationType, | ||
const nbgl_layoutTagValueList_t *tagValueList, | ||
const nbgl_icon_details_t *icon, | ||
const char *reviewTitle, | ||
const char *reviewSubTitle, | ||
const char *finishTitle) | ||
{ | ||
nbgl_sync_init(); | ||
nbgl_useCaseReview(operationType, | ||
tagValueList, | ||
icon, | ||
reviewTitle, | ||
reviewSubTitle, | ||
finishTitle, | ||
choice_callback); | ||
return nbgl_sync_wait(false); | ||
} | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseAddressReview( | ||
const char *address, | ||
const nbgl_layoutTagValueList_t *additionalTagValueList, | ||
const nbgl_icon_details_t *icon, | ||
const char *reviewTitle, | ||
const char *reviewSubTitle) | ||
{ | ||
nbgl_sync_init(); | ||
nbgl_useCaseAddressReview( | ||
address, additionalTagValueList, icon, reviewTitle, reviewSubTitle, choice_callback); | ||
return nbgl_sync_wait(false); | ||
} | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseReviewStatus(nbgl_reviewStatusType_t reviewStatusType) | ||
{ | ||
nbgl_sync_init(); | ||
nbgl_useCaseReviewStatus(reviewStatusType, quit_callback); | ||
return nbgl_sync_wait(false); | ||
} | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseStatus(const char *message, bool isSuccess) | ||
{ | ||
nbgl_sync_init(); | ||
nbgl_useCaseStatus(message, isSuccess, quit_callback); | ||
return nbgl_sync_wait(false); | ||
} | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseReviewStreamingStart(nbgl_operationType_t operationType, | ||
const nbgl_icon_details_t *icon, | ||
const char *reviewTitle, | ||
const char *reviewSubTitle) | ||
|
||
{ | ||
nbgl_sync_init(); | ||
nbgl_useCaseReviewStreamingStart( | ||
operationType, icon, reviewTitle, reviewSubTitle, choice_callback); | ||
return nbgl_sync_wait(false); | ||
} | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseReviewStreamingContinue( | ||
const nbgl_layoutTagValueList_t *tagValueList) | ||
|
||
{ | ||
nbgl_sync_init(); | ||
nbgl_useCaseReviewStreamingContinue(tagValueList, choice_callback); | ||
return nbgl_sync_wait(false); | ||
} | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseReviewStreamingFinish(const char *finishTitle) | ||
|
||
{ | ||
nbgl_sync_init(); | ||
nbgl_useCaseReviewStreamingFinish(finishTitle, choice_callback); | ||
return nbgl_sync_wait(false); | ||
} | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseGenericReview(const nbgl_genericContents_t *contents, | ||
const char *rejectText) | ||
|
||
{ | ||
nbgl_sync_init(); | ||
nbgl_useCaseGenericReview(contents, rejectText, rejected_callback); | ||
return nbgl_sync_wait(false); | ||
} | ||
|
||
nbgl_sync_ret_t nbgl_sync_useCaseGenericConfiguration(const char *title, | ||
uint8_t initPage, | ||
const nbgl_genericContents_t *contents) | ||
|
||
{ | ||
nbgl_sync_init(); | ||
nbgl_useCaseGenericConfiguration(title, initPage, contents, quit_callback); | ||
return nbgl_sync_wait(false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters