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: cc13x2_26x2
10 
11  ******************************************************************************
12 
13  Copyright (c) 2016-2021, Texas Instruments Incorporated
14  All rights reserved.
15 
16  Redistribution and use in source and binary forms, with or without
17  modification, are permitted provided that the following conditions
18  are met:
19 
20  * Redistributions of source code must retain the above copyright
21  notice, this list of conditions and the following disclaimer.
22 
23  * Redistributions in binary form must reproduce the above copyright
24  notice, this list of conditions and the following disclaimer in the
25  documentation and/or other materials provided with the distribution.
26 
27  * Neither the name of Texas Instruments Incorporated nor the names of
28  its contributors may be used to endorse or promote products derived
29  from this software without specific prior written permission.
30 
31  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
38  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
41  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 
43  ******************************************************************************
44 
45 
46  *****************************************************************************/
47 
493 #ifndef CUI_H
494 #define CUI_H
495 
496 #include <stdlib.h>
497 #include <stdint.h>
498 #include <ti/drivers/apps/Button.h>
499 #include <ti/drivers/apps/LED.h>
500 
501 #ifdef __cplusplus
502 extern "C"
503 {
504 #endif
505 
506 /*********************************************************************
507  * MACROS
508  */
509 /*
510  * CUI Module configurable defines. These can be used by the user allow for
511  * things such as more clients to be opened or changing the maximum length of a
512  * menu line.
513  *
514  * !!!!
515  * !!!! Do not modify these values directly. Either use an .opt file or Project
516  * !!!! level defines
517  * !!!!
518  *
519  * By increasing these values the cui module will need to use more memory.
520  * You can therefore reduce the amount of memory this module will require by
521  * decreasing these values.
522  *
523  * RAM Usage per client = ~56 bytes
524  * RAM Usage per menus = ~20 bytes
525  * RAM Usage per status lines = ~76 bytes
526  *
527  * Reducing MAX_*_LEN defines will reduce the RAM usage, but the reduced memory
528  * value will not scale to the number of clients/menus/status lines. In most
529  * situations changing MAX_*_LEN defines will not produce any appreciable memory
530  * savings.
531  */
532 
533 /*
534  * Client Configurable Defines
535  */
536 #ifndef MAX_CLIENTS
537 #define MAX_CLIENTS 2
538 #endif
539 #ifndef MAX_CLIENT_NAME_LEN
540 #define MAX_CLIENT_NAME_LEN 64
541 #endif
542 
543 
544 /*
545  * Menu Configurable Defines
546  */
547 #ifndef MAX_REGISTERED_MENUS
548 #define MAX_REGISTERED_MENUS 4
549 #endif
550 #ifndef MAX_MENU_LINE_LEN
551 #define MAX_MENU_LINE_LEN 128
552 #endif
553 
554 /*
555  * Status Line Configurable Defines
556  */
557 #ifndef MAX_STATUS_LINE_LABEL_LEN
558 #define MAX_STATUS_LINE_LABEL_LEN 32
559 #endif
560 #ifndef MAX_STATUS_LINE_VALUE_LEN
561 #define MAX_STATUS_LINE_VALUE_LEN 128
562 #endif
563 
564 #ifndef CUI_MIN_FOOTPRINT
565 /*
566  * Creates a main menu. A main menu must have a non NULL uart update function.
567  * This will be verified when registering the menu. numItems is incremented by
568  * one to allow for a common default "Back" or "Help" menu item between menus.
569  */
570 #define CUI_MAIN_MENU(_menuSymbol, _pMenuTitle, _numItems, _pMenuUpdateFn) \
571  CUI_menu_t _menuSymbol = { \
572  .uartUpdateFn=_pMenuUpdateFn, \
573  .pTitle=_pMenuTitle, \
574  .numItems=_numItems + 1, \
575  .pUpper=NULL, \
576  .menuItems = {
577 /*
578  * Creates a sub menu. This will be verified when registering the menu. numItems
579  * is incremented by one to allow for a common default "Back" or "Help" menu
580  * item between menus.
581  */
582 #define CUI_SUB_MENU(_menuSymbol, _pMenuTitle, _numItems, _pUpperMenu) \
583  extern CUI_menu_t _pUpperMenu; \
584  CUI_menu_t _menuSymbol = { \
585  .uartUpdateFn=NULL, \
586  .pTitle=_pMenuTitle, \
587  .numItems=_numItems + 1, \
588  .pUpper=&_pUpperMenu, \
589  .menuItems = {
590 
591 /*
592  * Inserts _pSubMenu into the .menuItems[] of a parent menu.
593  */
594 #define CUI_MENU_ITEM_SUBMENU(_pSubMenu) { \
595  .pDesc=NULL, \
596  .itemType=CUI_MENU_ITEM_TYPE_SUBMENU, \
597  .item.pSubMenu=(&_pSubMenu)},
598 
599 /*
600  * Inserts an action into the .menuItems[] of a parent menu.
601  */
602 #define CUI_MENU_ITEM_ACTION(_pItemDesc, _pFnAction) { \
603  .pDesc=(_pItemDesc), \
604  .itemType=CUI_MENU_ITEM_TYPE_ACTION, \
605  .interceptActive=false, \
606  .item.pFnAction=(_pFnAction)},
607 
608 /*
609  * Inserts an interceptable action into the .menuItems[] of a parent menu.
610  */
611 #define CUI_MENU_ITEM_INT_ACTION(_pItemDesc, _pFnIntercept) { \
612  .pDesc=(_pItemDesc), \
613  .itemType=CUI_MENU_ITEM_TYPE_INTERCEPT, \
614  .interceptActive=false, \
615  .item.pFnIntercept=(_pFnIntercept)},
616 
617 /*
618  * Inserts a list action into the .menuItems[] of a parent menu.
619  */
620 #define CUI_MENU_ITEM_LIST_ACTION(_pItemDesc, _maxListItems, _pFnListAction) { \
621  .pDesc=(_pItemDesc), \
622  .itemType=CUI_MENU_ITEM_TYPE_LIST, \
623  .interceptActive=false, \
624  .item.pList=&((CUI_list_t){ \
625  .pFnListAction=(_pFnListAction), \
626  .maxListItems=_maxListItems, \
627  .currListIndex=0})},
628 
629 /*
630  * Helper macros to add generic Help and Back screens to all menus
631  * The CUI will use these for you. Do not use these in an application.
632  */
633 #define CUI_MENU_ITEM_HELP CUI_MENU_ITEM_INT_ACTION(CUI_MENU_ACTION_HELP_DESC, (CUI_pFnIntercept_t) CUI_menuActionHelp)
634 #define CUI_MENU_ITEM_BACK CUI_MENU_ITEM_ACTION(CUI_MENU_ACTION_BACK_DESC, (CUI_pFnAction_t) CUI_menuActionBack)
635 #define CUI_MAIN_MENU_END CUI_MENU_ITEM_HELP }};
636 #define CUI_SUB_MENU_END CUI_MENU_ITEM_BACK }};
637 #define CUI_MENU_ACTION_BACK_DESC "< BACK >"
638 #define CUI_MENU_ACTION_HELP_DESC "< HELP >"
639 #else
640 
641 #define CUI_MAIN_MENU(_menuSymbol, _pMenuTitle, _numItems, _pMenuUpdateFn) \
642  CUI_menu_t _menuSymbol;
643 
644 #define CUI_SUB_MENU(_menuSymbol, _pMenuTitle, _numItems, _pUpperMenu) \
645  CUI_menu_t _menuSymbol;
646 
647 #define CUI_MENU_ITEM_SUBMENU(_pSubMenu)
648 
649 #define CUI_MENU_ITEM_ACTION(_pItemDesc, _pFnAction)
650 
651 #define CUI_MENU_ITEM_INT_ACTION(_pItemDesc, _pFnIntercept)
652 
653 #define CUI_MENU_ITEM_LIST_ACTION(_pItemDesc, _maxListItems, _pFnListAction)
654 
655 #define CUI_MENU_ITEM_HELP
656 #define CUI_MENU_ITEM_BACK
657 #define CUI_MAIN_MENU_END
658 #define CUI_SUB_MENU_END
659 #define CUI_MENU_ACTION_BACK_DESC "< BACK >"
660 #define CUI_MENU_ACTION_HELP_DESC "< HELP >"
661 #endif
662 
663 #define CUI_IS_INPUT_NUM(_input) ((_input >= '0') && (_input <= '9'))
664 #define CUI_IS_INPUT_ALPHA(_input) ((_input >= 'a') && (_input <= 'z'))
665 #define CUI_IS_INPUT_ALPHA_NUM(_input) ((CUI_IS_INPUT_ALPHA(_input)) && (CUI_IS_INPUT_NUM(_input)))
666 #define CUI_IS_INPUT_HEX(_input) ((CUI_IS_INPUT_NUM(_input)) || ((_input >= 'a') && (_input <= 'f')))
667 #define CUI_IS_INPUT_BINARY(_input) ((_input == '0') || (_input == '1'))
668 
669 
670 
671 /* Indication of previewing an interceptable item */
672 #define CUI_ITEM_PREVIEW 0x00
673 
674 /* Indication item is now intercepting the uart */
675 #define CUI_ITEM_INTERCEPT_START 0xFE
676 
677 /* Indication item is done intercepting the uart */
678 #define CUI_ITEM_INTERCEPT_STOP 0xFF
679 
680 /* Indication item intercept should be canceled */
681 #define CUI_ITEM_INTERCEPT_CANCEL 0xF9
682 
683 #define CUI_INPUT_UP 0xFA // Up Arrow
684 #define CUI_INPUT_DOWN 0xFB // Down Arrow
685 #define CUI_INPUT_RIGHT 0xFC // Right Arrow
686 #define CUI_INPUT_LEFT 0xFD // Left Arrow
687 #define CUI_INPUT_BACK 0x7F // Backspace Key
688 #define CUI_INPUT_EXECUTE 0x0D // Enter Key
689 #define CUI_INPUT_ESC 0x1B // ESC (escape) Key
690 
691 #define CUI_COLOR_RESET "\033[0m"
692 #define CUI_COLOR_RED "\033[31m"
693 #define CUI_COLOR_GREEN "\033[32m"
694 #define CUI_COLOR_YELLOW "\033[33m"
695 #define CUI_COLOR_BLUE "\033[34m"
696 #define CUI_COLOR_MAGENTA "\033[35m"
697 #define CUI_COLOR_CYAN "\033[36m"
698 #define CUI_COLOR_WHITE "\033[37m"
699 
700 #define CUI_DEBUG_MSG_START "\0337"
701 #define CUI_DEBUG_MSG_END "\0338"
702 
703 /******************************************************************************
704  * TYPEDEFS
705  */
706 
707 /*
708  * [Return Types]
709  */
710 typedef enum CUI_retVal
711 {
729 } CUI_retVal_t;
730 
731 /*
732  * [General CUI Types]
733  */
734 typedef uint32_t CUI_clientHandle_t;
735 
736 typedef struct {
738 } CUI_params_t;
739 
740 typedef struct {
741  char clientName[MAX_CLIENT_NAME_LEN];
742  uint8_t maxStatusLines;
744 
745 /*
746  * [Menu Related Types]
747  */
748 typedef struct {
749  int16_t row;
750  int16_t col;
752 
753 typedef void (*CUI_pFnClientMenuUpdate_t)(void);
754 
755 /* Type definitions for action functions types */
756 typedef void (*CUI_pFnAction_t)(const int32_t _itemEntry);
757 typedef void (*CUI_pFnIntercept_t)(const char _input, char* _lines[3], CUI_cursorInfo_t * _curInfo);
758 typedef void (*CUI_pFnListAction_t)(const uint32_t _listIndex, char* _lines[3], bool _selected);
759 
760 typedef struct CUI_menu_s CUI_menu_t;
761 typedef struct CUI_list_s CUI_list_t;
762 
763 typedef enum CUI_menuItems{
769 
770 /* Type definition for a sub menu/action item entry */
771 typedef struct {
772  char* pDesc; /* action description. NULL for sub menu */
773  CUI_itemType_t itemType; /* What type of menu item is this */
774  bool interceptActive; /* Is item currently being intercepted */
775  union {
776  CUI_menu_t* pSubMenu; /* Sub menu */
777  CUI_pFnAction_t pFnAction; /* Function for action */
778  CUI_pFnIntercept_t pFnIntercept; /* Function for interceptable action */
779  CUI_list_t* pList; /* List */
780  } item;
782 
783 /* Type definition for a menu object */
784 struct CUI_menu_s {
785  CUI_pFnClientMenuUpdate_t uartUpdateFn; /* Uart Update function */
786  const char* pTitle; /* Title of this menu */
787  uint8_t numItems; /* # of item entries */
788  CUI_menu_t* pUpper; /* upper menu */
789  CUI_menuItem_t menuItems[]; /* item entries */
790 };
791 
792 /* Type definition for a list object */
793 struct CUI_list_s {
795  uint16_t maxListItems;
796  uint16_t currListIndex;
797 };
798 
799 /******************************************************************************
800  Function Prototypes
801  *****************************************************************************/
802 
803 /******************************************************************************
804  * General CUI APIs
805  *****************************************************************************/
806 /*********************************************************************
807  * @fn CUI_init
808  *
809  * @brief Initialize the CUI module. This function must be called
810  * before any other CUI functions.
811  */
812 CUI_retVal_t CUI_init(CUI_params_t* _pParams);
813 
814 /*********************************************************************
815  * @fn CUI_paramsInit
816  *
817  * @brief Initialize a CUI_params_t struct to a known state.
818  * The known state in this case setting each resource
819  * management flag to true
820  */
821 void CUI_paramsInit(CUI_params_t* _pParams);
822 
823 /*********************************************************************
824  * @fn CUI_clientOpen
825  *
826  * @brief Open a client with the CUI module. A client is required
827  * to request/acquire resources
828  */
829 CUI_clientHandle_t CUI_clientOpen(CUI_clientParams_t* _pParams);
830 
831 /*********************************************************************
832  * @fn CUI_clientParamsInit
833  *
834  * @brief Initialize a CUI_clientParams_t struct to a known state.
835  */
836 void CUI_clientParamsInit(CUI_clientParams_t* _pClientParams);
837 
838 /*********************************************************************
839  * @fn CUI_close
840  *
841  * @brief Close the CUI module. Release all resources and memory.
842  */
843 CUI_retVal_t CUI_close();
844 
845 /******************************************************************************
846  * Menu CUI APIs
847  *****************************************************************************/
848 /*********************************************************************
849  * @fn CUI_registerMenu
850  *
851  * @brief Register a menu with the CUI module
852  */
853 CUI_retVal_t CUI_registerMenu(const CUI_clientHandle_t _clientHandle, CUI_menu_t* _pMenu);
854 
855 /*********************************************************************
856  * @fn CUI_deRegisterMenu
857  *
858  * @brief De-registers a menu with the CUI module
859  */
860 CUI_retVal_t CUI_deRegisterMenu(const CUI_clientHandle_t _clientHandle, CUI_menu_t* _pMenu);
861 
862 /*********************************************************************
863  * @fn CUI_updateMultiMenuTitle
864  *
865  * @brief Changes the default multi menu title
866  */
867 CUI_retVal_t CUI_updateMultiMenuTitle(const char* _pTitle);
868 
869 /*********************************************************************
870  * @fn CUI_menuNav
871  *
872  * @brief Navigate to a specific entry of a menu that has already been
873  * registered
874  */
875 CUI_retVal_t CUI_menuNav(const CUI_clientHandle_t _clientHandle, CUI_menu_t* _pMenu, const uint32_t _itemIndex);
876 
877 /*********************************************************************
878  * @fn CUI_processMenuUpdate
879  *
880  * @brief This function should be called whenever there is UART input
881  * to be processed.
882  */
883 CUI_retVal_t CUI_processMenuUpdate(void);
884 
885 /******************************************************************************
886  * Status Line CUI APIs
887  *****************************************************************************/
888 /*********************************************************************
889  * @fn CUI_statusLineResourceRequest
890  *
891  * @brief Request access to a new status line
892  */
893 CUI_retVal_t CUI_statusLineResourceRequest(const CUI_clientHandle_t _clientHandle, const char _pLabel[MAX_STATUS_LINE_LABEL_LEN], const bool _refreshInd, uint32_t* _pLineId);
894 
895 /*********************************************************************
896  * @fn CUI_statusLinePrintf
897  *
898  * @brief Update an acquired status line
899  */
900 CUI_retVal_t CUI_statusLinePrintf(const CUI_clientHandle_t _clientHandle, const uint32_t _lineId, const char *format, ...);
901 
902 void CUI_wrappedIncrement(size_t* _pValue, int32_t _incAmt, size_t _maxValue);
903 /*********************************************************************
904  * Assert Debug API
905  ********************************************************************/
906 /*********************************************************************
907  * @fn CUI_assert
908  *
909  * @brief Without requiring a cuiHandle_t you may print an assert
910  * string and optionally spinLock while flashing the leds.
911  *
912  * Note: If you choose to spinLock, this function will close
913  * all existing clients that have been opened and then
914  * enter an infinite loop that flashes the leds.
915  */
916 void CUI_assert(const char* _assertMsg, const bool _spinLock);
917 #ifndef CUI_MIN_FOOTPRINT
918 void CUI_menuActionBack(const int32_t _itemEntry);
919 void CUI_menuActionHelp(const char _input, char* _pLines[3], CUI_cursorInfo_t* _pCurInfo);
920 #endif
921 #ifdef __cplusplus
922 }
923 #endif
924 
925 #endif /* CUI_H */
CUI_pFnAction_t pFnAction
Definition: cui.h:777
uint8_t maxStatusLines
Definition: cui.h:742
Definition: cui.h:766
void(* CUI_pFnListAction_t)(const uint32_t _listIndex, char *_lines[3], bool _selected)
Definition: cui.h:758
bool interceptActive
Definition: cui.h:774
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:756
CUI_retVal_t CUI_deRegisterMenu(const CUI_clientHandle_t _clientHandle, CUI_menu_t *_pMenu)
Definition: cui.h:771
#define MAX_CLIENT_NAME_LEN
Definition: cui.h:540
Definition: cui.h:727
Definition: cui.h:765
Definition: cui.h:726
void CUI_assert(const char *_assertMsg, const bool _spinLock)
Definition: cui.h:767
uint16_t maxListItems
Definition: cui.h:795
int16_t row
Definition: cui.h:749
CUI_pFnIntercept_t pFnIntercept
Definition: cui.h:778
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:773
CUI_retVal_t CUI_close()
Definition: cui.h:716
Definition: cui.h:740
uint8_t numItems
Definition: cui.h:787
Definition: cui.h:748
Definition: cui.h:721
bool manageUart
Definition: cui.h:737
int16_t col
Definition: cui.h:750
CUI_menu_t * pUpper
Definition: cui.h:788
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:763
Definition: cui.h:784
Definition: cui.h:764
CUI_retVal_t CUI_init(CUI_params_t *_pParams)
CUI_pFnClientMenuUpdate_t uartUpdateFn
Definition: cui.h:785
Definition: cui.h:728
Definition: cui.h:719
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:714
CUI_clientHandle_t CUI_clientOpen(CUI_clientParams_t *_pParams)
CUI_menu_t * pSubMenu
Definition: cui.h:776
void(* CUI_pFnIntercept_t)(const char _input, char *_lines[3], CUI_cursorInfo_t *_curInfo)
Definition: cui.h:757
Definition: cui.h:713
Definition: cui.h:712
Definition: cui.h:718
Definition: cui.h:715
CUI_retVal
Definition: cui.h:710
Definition: cui.h:723
Definition: cui.h:724
void CUI_menuActionBack(const int32_t _itemEntry)
Definition: cui.h:793
const char * pTitle
Definition: cui.h:786
Definition: cui.h:725
enum CUI_retVal CUI_retVal_t
CUI_list_t * pList
Definition: cui.h:779
uint16_t currListIndex
Definition: cui.h:796
CUI_pFnListAction_t pFnListAction
Definition: cui.h:794
char * pDesc
Definition: cui.h:772
Definition: cui.h:736
Definition: cui.h:717
void CUI_clientParamsInit(CUI_clientParams_t *_pClientParams)
Definition: cui.h:722
void(* CUI_pFnClientMenuUpdate_t)(void)
Definition: cui.h:753
Definition: cui.h:720
enum CUI_menuItems CUI_itemType_t
uint32_t CUI_clientHandle_t
Definition: cui.h:734
#define MAX_STATUS_LINE_LABEL_LEN
Definition: cui.h:558
© Copyright 1995-2021, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale