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  * Menu Configurable Defines
515  */
516 #ifndef MAX_REGISTERED_MENUS
517 #define MAX_REGISTERED_MENUS 4
518 #endif
519 #ifndef MAX_MENU_LINE_LEN
520 #define MAX_MENU_LINE_LEN 128
521 #endif
522 
523 /*
524  * Status Line Configurable Defines
525  */
526 #ifndef MAX_STATUS_LINE_LABEL_LEN
527 #define MAX_STATUS_LINE_LABEL_LEN 32
528 #endif
529 #ifndef MAX_STATUS_LINE_VALUE_LEN
530 #define MAX_STATUS_LINE_VALUE_LEN 128
531 #endif
532 
533 /*
534  * Creates a main menu. A main menu must have a non NULL uart update function.
535  * This will be verified when registering the menu. numItems is incremented by
536  * one to allow for a common default "Back" or "Help" menu item between menus.
537  */
538 #define CUI_MAIN_MENU(_menuSymbol, _pMenuTitle, _numItems, _pMenuUpdateFn) \
539  CUI_menu_t _menuSymbol = { \
540  .uartUpdateFn=_pMenuUpdateFn, \
541  .pTitle=_pMenuTitle, \
542  .numItems=_numItems + 1, \
543  .pUpper=NULL, \
544  .menuItems = {
545 /*
546  * Creates a sub menu. This will be verified when registering the menu. numItems
547  * is incremented by one to allow for a common default "Back" or "Help" menu
548  * item between menus.
549  */
550 #define CUI_SUB_MENU(_menuSymbol, _pMenuTitle, _numItems, _pUpperMenu) \
551  extern CUI_menu_t _pUpperMenu; \
552  CUI_menu_t _menuSymbol = { \
553  .uartUpdateFn=NULL, \
554  .pTitle=_pMenuTitle, \
555  .numItems=_numItems + 1, \
556  .pUpper=&_pUpperMenu, \
557  .menuItems = {
558 
559 /*
560  * Inserts _pSubMenu into the .menuItems[] of a parent menu.
561  */
562 #define CUI_MENU_ITEM_SUBMENU(_pSubMenu) {.pDesc=NULL, .item.pSubMenu=(&_pSubMenu)},
563 
564 /*
565  * Inserts an action into the .menuItems[] of a parent menu.
566  */
567 #define CUI_MENU_ITEM_ACTION(_pItemDesc, _pFnAction) {.pDesc=(_pItemDesc), .interceptable=false, .interceptActive=false, .item.pFnAction=(_pFnAction)},
568 
569 /*
570  * Inserts an interceptable action into the .menuItems[] of a parent menu.
571  */
572 #define CUI_MENU_ITEM_INT_ACTION(_pItemDesc, _pFnIntercept) {.pDesc=(_pItemDesc), .interceptable=true, .interceptActive=false, .item.pFnIntercept=(_pFnIntercept)},
573 
574 /*
575  * Helper macros to add generic Help and Back screens to all menus
576  * The CUI will use these for you. Do not use these in an application.
577  */
578 #define CUI_MENU_ITEM_HELP CUI_MENU_ITEM_INT_ACTION(CUI_MENU_ACTION_HELP_DESC, (CUI_pFnIntercept_t) CUI_menuActionHelp)
579 #define CUI_MENU_ITEM_BACK CUI_MENU_ITEM_ACTION(CUI_MENU_ACTION_BACK_DESC, (CUI_pFnAction_t) CUI_menuActionBack)
580 #define CUI_MAIN_MENU_END CUI_MENU_ITEM_HELP }};
581 #define CUI_SUB_MENU_END CUI_MENU_ITEM_BACK }};
582 #define CUI_MENU_ACTION_BACK_DESC "< BACK >"
583 #define CUI_MENU_ACTION_HELP_DESC "< HELP >"
584 
585 
586 #define CUI_IS_INPUT_NUM(_input) ((_input >= '0') && (_input <= '9'))
587 #define CUI_IS_INPUT_ALPHA(_input) ((_input >= 'a') && (_input <= 'z'))
588 #define CUI_IS_INPUT_ALPHA_NUM(_input) ((CUI_IS_INPUT_ALPHA(_input)) && (CUI_IS_INPUT_NUM(_input)))
589 #define CUI_IS_INPUT_HEX(_input) ((CUI_IS_INPUT_NUM(_input)) || ((_input >= 'a') && (_input <= 'f')))
590 #define CUI_IS_INPUT_BINARY(_input) ((_input == '0') || (_input == '1'))
591 
592 
593 
594 /* Indication of previewing an interceptable item */
595 #define CUI_ITEM_PREVIEW 0x00
596 
597 /* Indication item is now intercepting the uart */
598 #define CUI_ITEM_INTERCEPT_START 0xFE
599 
600 /* Indication item is done intercepting the uart */
601 #define CUI_ITEM_INTERCEPT_STOP 0xFF
602 
603 /* Indication item intercept should be canceled */
604 #define CUI_ITEM_INTERCEPT_CANCEL 0xF9
605 
606 #define CUI_INPUT_UP 0xFA // Up Arrow
607 #define CUI_INPUT_DOWN 0xFB // Down Arrow
608 #define CUI_INPUT_RIGHT 0xFC // Right Arrow
609 #define CUI_INPUT_LEFT 0xFD // Left Arrow
610 #define CUI_INPUT_BACK 0x7F // Backspace Key
611 #define CUI_INPUT_EXECUTE 0x0D // Enter Key
612 #define CUI_INPUT_ESC 0x1B // ESC (escape) Key
613 
614 #define CUI_COLOR_RESET "\033[0m"
615 #define CUI_COLOR_RED "\033[31m"
616 #define CUI_COLOR_GREEN "\033[32m"
617 #define CUI_COLOR_YELLOW "\033[33m"
618 #define CUI_COLOR_BLUE "\033[34m"
619 #define CUI_COLOR_MAGENTA "\033[35m"
620 #define CUI_COLOR_CYAN "\033[36m"
621 #define CUI_COLOR_WHITE "\033[37m"
622 
623 #define CUI_DEBUG_MSG_START "\0337"
624 #define CUI_DEBUG_MSG_END "\0338\033[k"
625 
626 #define CUI_BLINK_CONTINUOUS 0xFFFF
627 
628 /******************************************************************************
629  * TYPEDEFS
630  */
631 
632 /*
633  * [Return Types]
634  */
635 typedef enum CUI_retVal
636 {
658 } CUI_retVal_t;
659 
660 /*
661  * [General CUI Types]
662  */
663 typedef uint32_t CUI_clientHandle_t;
664 
665 typedef struct {
669 } CUI_params_t;
670 
671 typedef struct {
672  char clientName[MAX_CLIENT_NAME_LEN];
673  uint8_t maxStatusLines;
675 
676 /*
677  * [Button Related Types]
678  */
680 typedef void (*CUI_btnPressCB_t)(uint32_t _index, Button_EventMask _buttonEvents);
681 
682 typedef struct {
683  uint32_t index;
686 
687 /*
688  * [LED Related Types]
689  */
690 typedef struct {
691  uint32_t index;
693 
694 /*
695  * [Display Related Types]
696  */
697 typedef struct {
698  int32_t row;
699  int32_t col;
701 
702 typedef void (*CUI_pFnClientMenuUpdate_t)(void);
703 
704 /* Type definitions for action functions types */
705 typedef void (*CUI_pFnAction_t)(const int32_t _itemEntry);
706 typedef void (*CUI_pFnIntercept_t)(const char _input, char* _lines[3], CUI_cursorInfo_t * _curInfo);
707 
708 typedef struct CUI_menu_s CUI_menu_t;
709 
710 /* Type definition for a sub menu/action item entry */
711 typedef struct {
712  char* pDesc; /* action description. NULL for sub menu */
713  bool interceptable; /* Is item interceptable */
714  bool interceptActive; /* Is item currently being intercepted */
715  union {
716  CUI_menu_t* pSubMenu; /* Sub menu */
717  CUI_pFnAction_t pFnAction; /* Function for action */
718  CUI_pFnIntercept_t pFnIntercept; /* Function for interceptable action */
719  } item;
721 
722 /* Type definition for a menu object */
723 struct CUI_menu_s {
724  CUI_pFnClientMenuUpdate_t uartUpdateFn; /* Uart Update function */
725  const char* pTitle; /* Title of this menu */
726  int32_t numItems; /* # of item entries */
727  CUI_menu_t* pUpper; /* upper menu */
728  CUI_menuItem_t menuItems[]; /* item entries */
729 };
730 
731 /******************************************************************************
732  Function Prototypes
733  *****************************************************************************/
734 
735 /******************************************************************************
736  * General CUI APIs
737  *****************************************************************************/
738 /*********************************************************************
739  * @fn CUI_init
740  *
741  * @brief Initialize the CUI module. This function must be called
742  * before any other CUI functions.
743  */
744 CUI_retVal_t CUI_init(CUI_params_t* _pParams);
745 
746 /*********************************************************************
747  * @fn CUI_paramsInit
748  *
749  * @brief Initialize a CUI_params_t struct to a known state.
750  * The known state in this case setting each resource
751  * management flag to true
752  */
753 void CUI_paramsInit(CUI_params_t* _pParams);
754 
755 /*********************************************************************
756  * @fn CUI_clientOpen
757  *
758  * @brief Open a client with the CUI module. A client is required
759  * to request/acquire resources
760  */
761 CUI_clientHandle_t CUI_clientOpen(CUI_clientParams_t* _pParams);
762 
763 /*********************************************************************
764  * @fn CUI_clientParamsInit
765  *
766  * @brief Initialize a CUI_clientParams_t struct to a known state.
767  */
768 void CUI_clientParamsInit(CUI_clientParams_t* _pClientParams);
769 
770 /*********************************************************************
771  * @fn CUI_close
772  *
773  * @brief Close the CUI module. Release all resources and memory.
774  */
775 CUI_retVal_t CUI_close();
776 
777 /******************************************************************************
778  * Button CUI APIs
779  *****************************************************************************/
780 /*********************************************************************
781  * @fn CUI_btnResourceRequest
782  *
783  * @brief Request access to a button resource
784  */
785 CUI_retVal_t CUI_btnResourceRequest(const CUI_clientHandle_t _clientHandle, const CUI_btnRequest_t* _pRequest);
786 
787 /*********************************************************************
788  * @fn CUI_btnSetCb
789  *
790  * @brief Set the CUI_btnPressCB of a button resource that is currently
791  * acquired
792  */
793 CUI_retVal_t CUI_btnSetCb(const CUI_clientHandle_t _clientHandle, const uint32_t _index, const CUI_btnPressCB_t _appCb);
794 
795 /*********************************************************************
796  * @fn CUI_btnGetValue
797  *
798  * @brief Set the CUI_btnPressCB of a button resource that is currently
799  * acquired
800  */
801 CUI_retVal_t CUI_btnGetValue(const CUI_clientHandle_t _clientHandle, const uint32_t _index, bool* _pBtnState);
802 
803 /*********************************************************************
804  * @fn CUI_btnResourceRelease
805  *
806  * @brief Release access to a button resource that is currently acquired
807  */
808 CUI_retVal_t CUI_btnResourceRelease(const CUI_clientHandle_t _clientHandle, const uint32_t _index);
809 
810 /******************************************************************************
811  * LED CUI APIs
812  *****************************************************************************/
813 /*********************************************************************
814  * @fn CUI_ledResourceRequest
815  *
816  * @brief Request access to a led resource
817  */
818 CUI_retVal_t CUI_ledResourceRequest(const CUI_clientHandle_t _clientHandle, const CUI_ledRequest_t* _pRequest);
819 
820 /*********************************************************************
821  * @fn CUI_ledResourceRelease
822  *
823  * @brief Release access to a led resource that is currently acquired
824  */
825 CUI_retVal_t CUI_ledResourceRelease(const CUI_clientHandle_t _clientHandle, const uint32_t _index);
826 
827 /*********************************************************************
828  * @fn CUI_ledOn
829  *
830  * @brief Turn a led on
831  */
832 CUI_retVal_t CUI_ledOn(const CUI_clientHandle_t _clientHandle, const uint32_t _index, const uint8_t _brightness);
833 
834 /*********************************************************************
835  * @fn CUI_ledOff
836  *
837  * @brief Turn a led off
838  */
839 CUI_retVal_t CUI_ledOff(const CUI_clientHandle_t _clientHandle, const uint32_t _index);
840 
841 /*********************************************************************
842  * @fn CUI_ledToggle
843  *
844  * @brief Toggle the state of a led [on/off]
845  */
846 CUI_retVal_t CUI_ledToggle(const CUI_clientHandle_t _clientHandle, const uint32_t _index);
847 
848 /*********************************************************************
849  * @fn CUI_ledBlink
850  *
851  * @brief Start blinking a led. Blinking will be at a rate of LED_BLINK_PERIOD ms
852  */
853 CUI_retVal_t CUI_ledBlink(const CUI_clientHandle_t _clientHandle, const uint32_t _index, const uint16_t _numBlinks);
854 
855 /******************************************************************************
856  * Menu CUI APIs
857  *****************************************************************************/
858 /*********************************************************************
859  * @fn CUI_registerMenu
860  *
861  * @brief Register a menu with the CUI module
862  */
863 CUI_retVal_t CUI_registerMenu(const CUI_clientHandle_t _clientHandle, CUI_menu_t* _pMenu);
864 
865 /*********************************************************************
866  * @fn CUI_deRegisterMenu
867  *
868  * @brief De-registers a menu with the CUI module
869  */
870 CUI_retVal_t CUI_deRegisterMenu(const CUI_clientHandle_t _clientHandle, CUI_menu_t* _pMenu);
871 
872 /*********************************************************************
873  * @fn CUI_updateMultiMenuTitle
874  *
875  * @brief Changes the default multi menu title
876  */
877 CUI_retVal_t CUI_updateMultiMenuTitle(const char* _pTitle);
878 
879 /*********************************************************************
880  * @fn CUI_menuNav
881  *
882  * @brief Navigate to a specific entry of a menu that has already been
883  * registered
884  */
885 CUI_retVal_t CUI_menuNav(const CUI_clientHandle_t _clientHandle, CUI_menu_t* _pMenu, const uint32_t _itemIndex);
886 
887 /*********************************************************************
888  * @fn CUI_processMenuUpdate
889  *
890  * @brief This function should be called whenever there is UART input
891  * to be processed.
892  */
893 CUI_retVal_t CUI_processMenuUpdate(void);
894 
895 /******************************************************************************
896  * Status Line CUI APIs
897  *****************************************************************************/
898 /*********************************************************************
899  * @fn CUI_statusLineResourceRequest
900  *
901  * @brief Request access to a new status line
902  */
903 CUI_retVal_t CUI_statusLineResourceRequest(const CUI_clientHandle_t _clientHandle, const char _pLabel[MAX_STATUS_LINE_LABEL_LEN], uint32_t* _pLineId);
904 
905 /*********************************************************************
906  * @fn CUI_statusLinePrintf
907  *
908  * @brief Update an acquired status line
909  */
910 CUI_retVal_t CUI_statusLinePrintf(const CUI_clientHandle_t _clientHandle, const uint32_t _lineId, const char *format, ...);
911 
912 
913 /*********************************************************************
914  * Assert Debug API
915  ********************************************************************/
916 /*********************************************************************
917  * @fn CUI_assert
918  *
919  * @brief Without requiring a cuiHandle_t you may print an assert
920  * string and optionally spinLock while flashing the leds.
921  *
922  * Note: If you choose to spinLock, this function will close
923  * all existing clients that have been opened and then
924  * enter an infinite loop that flashes the leds.
925  */
926 void CUI_assert(const char* _assertMsg, const bool _spinLock);
927 
928 void CUI_menuActionBack(const int32_t _itemEntry);
929 void CUI_menuActionHelp(const char _input, char* _pLines[3], CUI_cursorInfo_t* _pCurInfo);
930 #ifdef __cplusplus
931 }
932 #endif
933 
934 #endif /* CUI_H */
CUI_pFnAction_t pFnAction
Definition: cui.h:717
uint8_t maxStatusLines
Definition: cui.h:673
bool interceptActive
Definition: cui.h:714
void CUI_paramsInit(CUI_params_t *_pParams)
void(* CUI_pFnAction_t)(const int32_t _itemEntry)
Definition: cui.h:705
CUI_retVal_t CUI_deRegisterMenu(const CUI_clientHandle_t _clientHandle, CUI_menu_t *_pMenu)
Definition: cui.h:711
CUI_btnPressCB_t appCB
Definition: cui.h:684
bool interceptable
Definition: cui.h:713
CUI_retVal_t CUI_btnResourceRelease(const CUI_clientHandle_t _clientHandle, const uint32_t _index)
#define MAX_CLIENT_NAME_LEN
Definition: cui.h:510
Definition: cui.h:653
Definition: cui.h:652
void CUI_assert(const char *_assertMsg, const bool _spinLock)
Definition: cui.h:655
int32_t col
Definition: cui.h:699
CUI_pFnIntercept_t pFnIntercept
Definition: cui.h:718
int32_t row
Definition: cui.h:698
bool manageLeds
Definition: cui.h:667
CUI_retVal_t CUI_processMenuUpdate(void)
Definition: cui.h:690
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_retVal_t CUI_close()
Definition: cui.h:642
CUI_retVal_t CUI_ledToggle(const CUI_clientHandle_t _clientHandle, const uint32_t _index)
Definition: cui.h:671
uint32_t index
Definition: cui.h:691
Definition: cui.h:697
Definition: cui.h:647
bool manageUart
Definition: cui.h:668
CUI_menu_t * pUpper
Definition: cui.h:727
void CUI_menuActionHelp(const char _input, char *_pLines[3], CUI_cursorInfo_t *_pCurInfo)
CUI_retVal_t CUI_updateMultiMenuTitle(const char *_pTitle)
CUI_retVal_t CUI_ledResourceRequest(const CUI_clientHandle_t _clientHandle, const CUI_ledRequest_t *_pRequest)
int32_t numItems
Definition: cui.h:726
Definition: cui.h:723
void(* CUI_btnPressCB_t)(uint32_t _index, Button_EventMask _buttonEvents)
Definition: cui.h:680
CUI_retVal_t CUI_btnSetCb(const CUI_clientHandle_t _clientHandle, const uint32_t _index, const CUI_btnPressCB_t _appCb)
Definition: cui.h:682
CUI_retVal_t CUI_ledBlink(const CUI_clientHandle_t _clientHandle, const uint32_t _index, const uint16_t _numBlinks)
Definition: cui.h:656
CUI_retVal_t CUI_init(CUI_params_t *_pParams)
CUI_pFnClientMenuUpdate_t uartUpdateFn
Definition: cui.h:724
Definition: cui.h:657
Definition: cui.h:645
CUI_retVal_t CUI_statusLinePrintf(const CUI_clientHandle_t _clientHandle, const uint32_t _lineId, const char *format,...)
CUI_retVal_t CUI_statusLineResourceRequest(const CUI_clientHandle_t _clientHandle, const char _pLabel[MAX_STATUS_LINE_LABEL_LEN], uint32_t *_pLineId)
Definition: cui.h:639
CUI_menuItem_t menuItems[]
Definition: cui.h:728
CUI_retVal_t CUI_ledResourceRelease(const CUI_clientHandle_t _clientHandle, const uint32_t _index)
CUI_clientHandle_t CUI_clientOpen(CUI_clientParams_t *_pParams)
CUI_menu_t * pSubMenu
Definition: cui.h:716
void(* CUI_pFnIntercept_t)(const char _input, char *_lines[3], CUI_cursorInfo_t *_curInfo)
Definition: cui.h:706
Definition: cui.h:638
Definition: cui.h:637
Definition: cui.h:644
Definition: cui.h:641
CUI_retVal
Definition: cui.h:635
Definition: cui.h:649
Definition: cui.h:650
CUI_retVal_t CUI_ledOff(const CUI_clientHandle_t _clientHandle, const uint32_t _index)
void CUI_menuActionBack(const int32_t _itemEntry)
Definition: cui.h:640
const char * pTitle
Definition: cui.h:725
Definition: cui.h:651
enum CUI_retVal CUI_retVal_t
CUI_retVal_t CUI_btnResourceRequest(const CUI_clientHandle_t _clientHandle, const CUI_btnRequest_t *_pRequest)
CUI_retVal_t CUI_ledOn(const CUI_clientHandle_t _clientHandle, const uint32_t _index, const uint8_t _brightness)
uint32_t index
Definition: cui.h:683
char * pDesc
Definition: cui.h:712
Definition: cui.h:665
Definition: cui.h:643
void CUI_clientParamsInit(CUI_clientParams_t *_pClientParams)
Definition: cui.h:648
bool manageBtns
Definition: cui.h:666
Definition: cui.h:654
CUI_retVal_t CUI_btnGetValue(const CUI_clientHandle_t _clientHandle, const uint32_t _index, bool *_pBtnState)
void(* CUI_pFnClientMenuUpdate_t)(void)
Definition: cui.h:702
Definition: cui.h:646
uint32_t CUI_clientHandle_t
Definition: cui.h:663
#define MAX_STATUS_LINE_LABEL_LEN
Definition: cui.h:527
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale