CUI API  1.00.00.00
cui.h
Go to the documentation of this file.
1 
2 /******************************************************************************
3 
4  @file CUI.h
5 
6  @brief This file contains the interface of the Common User Interface. (CUI)
7 
8  Group: LPRF SW RND
9  $Target Device: DEVICES $
10 
11  ******************************************************************************
12  $License: BSD3 2016 $
13  ******************************************************************************
14  $Release Name: PACKAGE NAME $
15  $Release Date: PACKAGE RELEASE DATE $
16  *****************************************************************************/
17 
463 #ifndef CUI_H
464 #define CUI_H
465 
466 #include <stdlib.h>
467 #include <stdint.h>
468 #include <ti/drivers/apps/Button.h>
469 #include <ti/drivers/apps/LED.h>
470 
471 #ifdef __cplusplus
472 extern "C"
473 {
474 #endif
475 
476 /*********************************************************************
477  * MACROS
478  */
479 /*
480  * CUI Module configurable defines. These can be used by the user allow for
481  * things such as more clients to be opened or changing the maximum length of a
482  * menu line.
483  *
484  * !!!!
485  * !!!! Do not modify these values directly. Either use an .opt file or Project
486  * !!!! level defines
487  * !!!!
488  *
489  * By increasing these values the cui module will need to use more memory.
490  * You can therefore reduce the amount of memory this module will require by
491  * decreasing these values.
492  *
493  * RAM Usage per client = ~56 bytes
494  * RAM Usage per menus = ~20 bytes
495  * RAM Usage per status lines = ~76 bytes
496  *
497  * Reducing MAX_*_LEN defines will reduce the RAM usage, but the reduced memory
498  * value will not scale to the number of clients/menus/status lines. In most
499  * situations changing MAX_*_LEN defines will not produce any appreciable memory
500  * savings.
501  */
502 
503 /*
504  * Client Configurable Defines
505  */
506 #ifndef MAX_CLIENTS
507 #define MAX_CLIENTS 2
508 #endif
509 #ifndef MAX_CLIENT_NAME_LEN
510 #define MAX_CLIENT_NAME_LEN 64
511 #endif
512 
513 
514 /*
515  * Menu Configurable Defines
516  */
517 #ifndef MAX_REGISTERED_MENUS
518 #define MAX_REGISTERED_MENUS 4
519 #endif
520 #ifndef MAX_MENU_LINE_LEN
521 #define MAX_MENU_LINE_LEN 128
522 #endif
523 
524 /*
525  * Status Line Configurable Defines
526  */
527 #ifndef MAX_STATUS_LINE_LABEL_LEN
528 #define MAX_STATUS_LINE_LABEL_LEN 32
529 #endif
530 #ifndef MAX_STATUS_LINE_VALUE_LEN
531 #define MAX_STATUS_LINE_VALUE_LEN 128
532 #endif
533 
534 #ifndef CUI_MIN_FOOTPRINT
535 /*
536  * Creates a main menu. A main menu must have a non NULL uart update function.
537  * This will be verified when registering the menu. numItems is incremented by
538  * one to allow for a common default "Back" or "Help" menu item between menus.
539  */
540 #define CUI_MAIN_MENU(_menuSymbol, _pMenuTitle, _numItems, _pMenuUpdateFn) \
541  CUI_menu_t _menuSymbol = { \
542  .uartUpdateFn=_pMenuUpdateFn, \
543  .pTitle=_pMenuTitle, \
544  .numItems=_numItems + 1, \
545  .pUpper=NULL, \
546  .menuItems = {
547 /*
548  * Creates a sub menu. This will be verified when registering the menu. numItems
549  * is incremented by one to allow for a common default "Back" or "Help" menu
550  * item between menus.
551  */
552 #define CUI_SUB_MENU(_menuSymbol, _pMenuTitle, _numItems, _pUpperMenu) \
553  extern CUI_menu_t _pUpperMenu; \
554  CUI_menu_t _menuSymbol = { \
555  .uartUpdateFn=NULL, \
556  .pTitle=_pMenuTitle, \
557  .numItems=_numItems + 1, \
558  .pUpper=&_pUpperMenu, \
559  .menuItems = {
560 
561 /*
562  * Inserts _pSubMenu into the .menuItems[] of a parent menu.
563  */
564 #define CUI_MENU_ITEM_SUBMENU(_pSubMenu) { \
565  .pDesc=NULL, \
566  .itemType=CUI_MENU_ITEM_TYPE_SUBMENU, \
567  .item.pSubMenu=(&_pSubMenu)},
568 
569 /*
570  * Inserts an action into the .menuItems[] of a parent menu.
571  */
572 #define CUI_MENU_ITEM_ACTION(_pItemDesc, _pFnAction) { \
573  .pDesc=(_pItemDesc), \
574  .itemType=CUI_MENU_ITEM_TYPE_ACTION, \
575  .interceptActive=false, \
576  .item.pFnAction=(_pFnAction)},
577 
578 /*
579  * Inserts an interceptable action into the .menuItems[] of a parent menu.
580  */
581 #define CUI_MENU_ITEM_INT_ACTION(_pItemDesc, _pFnIntercept) { \
582  .pDesc=(_pItemDesc), \
583  .itemType=CUI_MENU_ITEM_TYPE_INTERCEPT, \
584  .interceptActive=false, \
585  .item.pFnIntercept=(_pFnIntercept)},
586 
587 /*
588  * Inserts a list action into the .menuItems[] of a parent menu.
589  */
590 #define CUI_MENU_ITEM_LIST_ACTION(_pItemDesc, _maxListItems, _pFnListAction) { \
591  .pDesc=(_pItemDesc), \
592  .itemType=CUI_MENU_ITEM_TYPE_LIST, \
593  .interceptActive=false, \
594  .item.pList=&((CUI_list_t){ \
595  .pFnListAction=(_pFnListAction), \
596  .maxListItems=_maxListItems, \
597  .currListIndex=0})},
598 
599 /*
600  * Helper macros to add generic Help and Back screens to all menus
601  * The CUI will use these for you. Do not use these in an application.
602  */
603 #define CUI_MENU_ITEM_HELP CUI_MENU_ITEM_INT_ACTION(CUI_MENU_ACTION_HELP_DESC, (CUI_pFnIntercept_t) CUI_menuActionHelp)
604 #define CUI_MENU_ITEM_BACK CUI_MENU_ITEM_ACTION(CUI_MENU_ACTION_BACK_DESC, (CUI_pFnAction_t) CUI_menuActionBack)
605 #define CUI_MAIN_MENU_END CUI_MENU_ITEM_HELP }};
606 #define CUI_SUB_MENU_END CUI_MENU_ITEM_BACK }};
607 #define CUI_MENU_ACTION_BACK_DESC "< BACK >"
608 #define CUI_MENU_ACTION_HELP_DESC "< HELP >"
609 #else
610 
611 #define CUI_MAIN_MENU(_menuSymbol, _pMenuTitle, _numItems, _pMenuUpdateFn) \
612  CUI_menu_t _menuSymbol;
613 
614 #define CUI_SUB_MENU(_menuSymbol, _pMenuTitle, _numItems, _pUpperMenu) \
615  CUI_menu_t _menuSymbol;
616 
617 #define CUI_MENU_ITEM_SUBMENU(_pSubMenu)
618 
619 #define CUI_MENU_ITEM_ACTION(_pItemDesc, _pFnAction)
620 
621 #define CUI_MENU_ITEM_INT_ACTION(_pItemDesc, _pFnIntercept)
622 
623 #define CUI_MENU_ITEM_LIST_ACTION(_pItemDesc, _maxListItems, _pFnListAction)
624 
625 #define CUI_MENU_ITEM_HELP
626 #define CUI_MENU_ITEM_BACK
627 #define CUI_MAIN_MENU_END
628 #define CUI_SUB_MENU_END
629 #define CUI_MENU_ACTION_BACK_DESC "< BACK >"
630 #define CUI_MENU_ACTION_HELP_DESC "< HELP >"
631 #endif
632 
633 #define CUI_IS_INPUT_NUM(_input) ((_input >= '0') && (_input <= '9'))
634 #define CUI_IS_INPUT_ALPHA(_input) ((_input >= 'a') && (_input <= 'z'))
635 #define CUI_IS_INPUT_ALPHA_NUM(_input) ((CUI_IS_INPUT_ALPHA(_input)) && (CUI_IS_INPUT_NUM(_input)))
636 #define CUI_IS_INPUT_HEX(_input) ((CUI_IS_INPUT_NUM(_input)) || ((_input >= 'a') && (_input <= 'f')))
637 #define CUI_IS_INPUT_BINARY(_input) ((_input == '0') || (_input == '1'))
638 
639 
640 
641 /* Indication of previewing an interceptable item */
642 #define CUI_ITEM_PREVIEW 0x00
643 
644 /* Indication item is now intercepting the uart */
645 #define CUI_ITEM_INTERCEPT_START 0xFE
646 
647 /* Indication item is done intercepting the uart */
648 #define CUI_ITEM_INTERCEPT_STOP 0xFF
649 
650 /* Indication item intercept should be canceled */
651 #define CUI_ITEM_INTERCEPT_CANCEL 0xF9
652 
653 #define CUI_INPUT_UP 0xFA // Up Arrow
654 #define CUI_INPUT_DOWN 0xFB // Down Arrow
655 #define CUI_INPUT_RIGHT 0xFC // Right Arrow
656 #define CUI_INPUT_LEFT 0xFD // Left Arrow
657 #define CUI_INPUT_BACK 0x7F // Backspace Key
658 #define CUI_INPUT_EXECUTE 0x0D // Enter Key
659 #define CUI_INPUT_ESC 0x1B // ESC (escape) Key
660 
661 #define CUI_COLOR_RESET "\033[0m"
662 #define CUI_COLOR_RED "\033[31m"
663 #define CUI_COLOR_GREEN "\033[32m"
664 #define CUI_COLOR_YELLOW "\033[33m"
665 #define CUI_COLOR_BLUE "\033[34m"
666 #define CUI_COLOR_MAGENTA "\033[35m"
667 #define CUI_COLOR_CYAN "\033[36m"
668 #define CUI_COLOR_WHITE "\033[37m"
669 
670 #define CUI_DEBUG_MSG_START "\0337"
671 #define CUI_DEBUG_MSG_END "\0338"
672 
673 /******************************************************************************
674  * TYPEDEFS
675  */
676 
677 /*
678  * [Return Types]
679  */
680 typedef enum CUI_retVal
681 {
699 } CUI_retVal_t;
700 
701 /*
702  * [General CUI Types]
703  */
704 typedef uint32_t CUI_clientHandle_t;
705 
706 typedef struct {
708 } CUI_params_t;
709 
710 typedef struct {
711  char clientName[MAX_CLIENT_NAME_LEN];
712  uint8_t maxStatusLines;
714 
715 /*
716  * [Menu Related Types]
717  */
718 typedef struct {
719  int16_t row;
720  int16_t col;
722 
723 typedef void (*CUI_pFnClientMenuUpdate_t)(void);
724 
725 /* Type definitions for action functions types */
726 typedef void (*CUI_pFnAction_t)(const int32_t _itemEntry);
727 typedef void (*CUI_pFnIntercept_t)(const char _input, char* _lines[3], CUI_cursorInfo_t * _curInfo);
728 typedef void (*CUI_pFnListAction_t)(const uint32_t _listIndex, char* _lines[3], bool _selected);
729 
730 typedef struct CUI_menu_s CUI_menu_t;
731 typedef struct CUI_list_s CUI_list_t;
732 
733 typedef enum CUI_menuItems{
739 
740 /* Type definition for a sub menu/action item entry */
741 typedef struct {
742  char* pDesc; /* action description. NULL for sub menu */
743  CUI_itemType_t itemType; /* What type of menu item is this */
744  bool interceptActive; /* Is item currently being intercepted */
745  union {
746  CUI_menu_t* pSubMenu; /* Sub menu */
747  CUI_pFnAction_t pFnAction; /* Function for action */
748  CUI_pFnIntercept_t pFnIntercept; /* Function for interceptable action */
749  CUI_list_t* pList; /* List */
750  } item;
752 
753 /* Type definition for a menu object */
754 struct CUI_menu_s {
755  CUI_pFnClientMenuUpdate_t uartUpdateFn; /* Uart Update function */
756  const char* pTitle; /* Title of this menu */
757  uint8_t numItems; /* # of item entries */
758  CUI_menu_t* pUpper; /* upper menu */
759  CUI_menuItem_t menuItems[]; /* item entries */
760 };
761 
762 /* Type definition for a list object */
763 struct CUI_list_s {
765  uint16_t maxListItems;
766  uint16_t currListIndex;
767 };
768 
769 /******************************************************************************
770  Function Prototypes
771  *****************************************************************************/
772 
773 /******************************************************************************
774  * General CUI APIs
775  *****************************************************************************/
776 /*********************************************************************
777  * @fn CUI_init
778  *
779  * @brief Initialize the CUI module. This function must be called
780  * before any other CUI functions.
781  */
782 CUI_retVal_t CUI_init(CUI_params_t* _pParams);
783 
784 /*********************************************************************
785  * @fn CUI_paramsInit
786  *
787  * @brief Initialize a CUI_params_t struct to a known state.
788  * The known state in this case setting each resource
789  * management flag to true
790  */
791 void CUI_paramsInit(CUI_params_t* _pParams);
792 
793 /*********************************************************************
794  * @fn CUI_clientOpen
795  *
796  * @brief Open a client with the CUI module. A client is required
797  * to request/acquire resources
798  */
799 CUI_clientHandle_t CUI_clientOpen(CUI_clientParams_t* _pParams);
800 
801 /*********************************************************************
802  * @fn CUI_clientParamsInit
803  *
804  * @brief Initialize a CUI_clientParams_t struct to a known state.
805  */
806 void CUI_clientParamsInit(CUI_clientParams_t* _pClientParams);
807 
808 /*********************************************************************
809  * @fn CUI_close
810  *
811  * @brief Close the CUI module. Release all resources and memory.
812  */
813 CUI_retVal_t CUI_close();
814 
815 /******************************************************************************
816  * Menu CUI APIs
817  *****************************************************************************/
818 /*********************************************************************
819  * @fn CUI_registerMenu
820  *
821  * @brief Register a menu with the CUI module
822  */
823 CUI_retVal_t CUI_registerMenu(const CUI_clientHandle_t _clientHandle, CUI_menu_t* _pMenu);
824 
825 /*********************************************************************
826  * @fn CUI_deRegisterMenu
827  *
828  * @brief De-registers a menu with the CUI module
829  */
830 CUI_retVal_t CUI_deRegisterMenu(const CUI_clientHandle_t _clientHandle, CUI_menu_t* _pMenu);
831 
832 /*********************************************************************
833  * @fn CUI_updateMultiMenuTitle
834  *
835  * @brief Changes the default multi menu title
836  */
837 CUI_retVal_t CUI_updateMultiMenuTitle(const char* _pTitle);
838 
839 /*********************************************************************
840  * @fn CUI_menuNav
841  *
842  * @brief Navigate to a specific entry of a menu that has already been
843  * registered
844  */
845 CUI_retVal_t CUI_menuNav(const CUI_clientHandle_t _clientHandle, CUI_menu_t* _pMenu, const uint32_t _itemIndex);
846 
847 /*********************************************************************
848  * @fn CUI_processMenuUpdate
849  *
850  * @brief This function should be called whenever there is UART input
851  * to be processed.
852  */
853 CUI_retVal_t CUI_processMenuUpdate(void);
854 
855 /******************************************************************************
856  * Status Line CUI APIs
857  *****************************************************************************/
858 /*********************************************************************
859  * @fn CUI_statusLineResourceRequest
860  *
861  * @brief Request access to a new status line
862  */
863 CUI_retVal_t CUI_statusLineResourceRequest(const CUI_clientHandle_t _clientHandle, const char _pLabel[MAX_STATUS_LINE_LABEL_LEN], const bool _refreshInd, uint32_t* _pLineId);
864 
865 /*********************************************************************
866  * @fn CUI_statusLinePrintf
867  *
868  * @brief Update an acquired status line
869  */
870 CUI_retVal_t CUI_statusLinePrintf(const CUI_clientHandle_t _clientHandle, const uint32_t _lineId, const char *format, ...);
871 
872 void CUI_wrappedIncrement(size_t* _pValue, int32_t _incAmt, size_t _maxValue);
873 /*********************************************************************
874  * Assert Debug API
875  ********************************************************************/
876 /*********************************************************************
877  * @fn CUI_assert
878  *
879  * @brief Without requiring a cuiHandle_t you may print an assert
880  * string and optionally spinLock while flashing the leds.
881  *
882  * Note: If you choose to spinLock, this function will close
883  * all existing clients that have been opened and then
884  * enter an infinite loop that flashes the leds.
885  */
886 void CUI_assert(const char* _assertMsg, const bool _spinLock);
887 #ifndef CUI_MIN_FOOTPRINT
888 void CUI_menuActionBack(const int32_t _itemEntry);
889 void CUI_menuActionHelp(const char _input, char* _pLines[3], CUI_cursorInfo_t* _pCurInfo);
890 #endif
891 #ifdef __cplusplus
892 }
893 #endif
894 
895 #endif /* CUI_H */
CUI_pFnAction_t pFnAction
Definition: cui.h:747
uint8_t maxStatusLines
Definition: cui.h:712
Definition: cui.h:736
void(* CUI_pFnListAction_t)(const uint32_t _listIndex, char *_lines[3], bool _selected)
Definition: cui.h:728
bool interceptActive
Definition: cui.h:744
CUI_retVal_t CUI_statusLineResourceRequest(const CUI_clientHandle_t _clientHandle, const char _pLabel[MAX_STATUS_LINE_LABEL_LEN], const bool _refreshInd, uint32_t *_pLineId)
void CUI_paramsInit(CUI_params_t *_pParams)
void(* CUI_pFnAction_t)(const int32_t _itemEntry)
Definition: cui.h:726
CUI_retVal_t CUI_deRegisterMenu(const CUI_clientHandle_t _clientHandle, CUI_menu_t *_pMenu)
Definition: cui.h:741
#define MAX_CLIENT_NAME_LEN
Definition: cui.h:510
Definition: cui.h:697
Definition: cui.h:735
Definition: cui.h:696
void CUI_assert(const char *_assertMsg, const bool _spinLock)
Definition: cui.h:737
uint16_t maxListItems
Definition: cui.h:765
int16_t row
Definition: cui.h:719
CUI_pFnIntercept_t pFnIntercept
Definition: cui.h:748
CUI_retVal_t CUI_processMenuUpdate(void)
CUI_retVal_t CUI_menuNav(const CUI_clientHandle_t _clientHandle, CUI_menu_t *_pMenu, const uint32_t _itemIndex)
CUI_retVal_t CUI_registerMenu(const CUI_clientHandle_t _clientHandle, CUI_menu_t *_pMenu)
CUI_itemType_t itemType
Definition: cui.h:743
CUI_retVal_t CUI_close()
Definition: cui.h:686
Definition: cui.h:710
uint8_t numItems
Definition: cui.h:757
Definition: cui.h:718
Definition: cui.h:691
bool manageUart
Definition: cui.h:707
int16_t col
Definition: cui.h:720
CUI_menu_t * pUpper
Definition: cui.h:758
void CUI_menuActionHelp(const char _input, char *_pLines[3], CUI_cursorInfo_t *_pCurInfo)
CUI_retVal_t CUI_updateMultiMenuTitle(const char *_pTitle)
CUI_menuItems
Definition: cui.h:733
Definition: cui.h:754
Definition: cui.h:734
CUI_retVal_t CUI_init(CUI_params_t *_pParams)
CUI_pFnClientMenuUpdate_t uartUpdateFn
Definition: cui.h:755
Definition: cui.h:698
Definition: cui.h:689
CUI_retVal_t CUI_statusLinePrintf(const CUI_clientHandle_t _clientHandle, const uint32_t _lineId, const char *format,...)
void CUI_wrappedIncrement(size_t *_pValue, int32_t _incAmt, size_t _maxValue)
Definition: cui.h:684
CUI_clientHandle_t CUI_clientOpen(CUI_clientParams_t *_pParams)
CUI_menu_t * pSubMenu
Definition: cui.h:746
void(* CUI_pFnIntercept_t)(const char _input, char *_lines[3], CUI_cursorInfo_t *_curInfo)
Definition: cui.h:727
Definition: cui.h:683
Definition: cui.h:682
Definition: cui.h:688
Definition: cui.h:685
CUI_retVal
Definition: cui.h:680
Definition: cui.h:693
Definition: cui.h:694
void CUI_menuActionBack(const int32_t _itemEntry)
Definition: cui.h:763
const char * pTitle
Definition: cui.h:756
Definition: cui.h:695
enum CUI_retVal CUI_retVal_t
CUI_list_t * pList
Definition: cui.h:749
uint16_t currListIndex
Definition: cui.h:766
CUI_pFnListAction_t pFnListAction
Definition: cui.h:764
char * pDesc
Definition: cui.h:742
Definition: cui.h:706
Definition: cui.h:687
void CUI_clientParamsInit(CUI_clientParams_t *_pClientParams)
Definition: cui.h:692
void(* CUI_pFnClientMenuUpdate_t)(void)
Definition: cui.h:723
Definition: cui.h:690
enum CUI_menuItems CUI_itemType_t
uint32_t CUI_clientHandle_t
Definition: cui.h:704
#define MAX_STATUS_LINE_LABEL_LEN
Definition: cui.h:528
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale