port_microrl.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /******************************* (C) LiteMesh **********************************
  2. * @module Console
  3. * @file portConsole.c
  4. * @version 1.0.0
  5. * @date XX.XX.XXXX
  6. * $brief Port functions console lib
  7. *******************************************************************************
  8. * @history Version Author Comment
  9. * XX.XX.XXXX 1.0.0 Telenkov D.A. First release.
  10. *******************************************************************************
  11. */
  12. #include "stm32f4xx.h"
  13. #include "port_microrl.h"
  14. #include "microrl.h"
  15. #include "config.h"
  16. #include "stdio.h"
  17. #include "stdlib.h"
  18. #include "string.h"
  19. #include "dac.h"
  20. microrl_t rl;
  21. microrl_t *prl = &rl;
  22. /*
  23. AVR platform specific implementation routines (for Atmega8, rewrite for your MC)
  24. */
  25. #define _AVR_DEMO_VER "1.0"
  26. // definition commands word
  27. #define _CMD_HELP "help"
  28. #define _CMD_CLEAR "clear"
  29. #define _CMD_CLR "clear_port"
  30. #define _CMD_SET "set_port"
  31. #define _CMD_DAC_SEND_TEST_VAL "dac"
  32. // arguments for set/clear
  33. #define _SCMD_PB "port_b"
  34. #define _SCMD_PD "port_d"
  35. #define _NUM_OF_CMD 5
  36. #define _NUM_OF_SETCLEAR_SCMD 2
  37. //available commands
  38. char * keyworld [] = {
  39. _CMD_HELP,
  40. _CMD_CLEAR,
  41. _CMD_SET,
  42. _CMD_CLR,
  43. _CMD_DAC_SEND_TEST_VAL};
  44. // 'set/clear' command argements
  45. char * set_clear_key [] = {_SCMD_PB, _SCMD_PD};
  46. // array for comletion
  47. char * compl_world [_NUM_OF_CMD + 1];
  48. /**
  49. * @brief
  50. * @retval
  51. */
  52. void MICRORL_Init(void)
  53. {
  54. microrl_init(prl, print);
  55. microrl_set_execute_callback (prl, execute);
  56. }
  57. /**
  58. * @brief Print callback for microrl library
  59. * @retval
  60. */
  61. void print (const char *str)
  62. {
  63. printf(str);
  64. }
  65. /**
  66. * @brief
  67. * @retval
  68. */
  69. void MICRORL_GetChar(uint8_t ch)
  70. {
  71. microrl_insert_char(prl, ch);
  72. }
  73. //*****************************************************************************
  74. // execute callback for microrl library
  75. // do what you want here, but don't write to argv!!! read only!!
  76. int execute (int argc, const char * const * argv)
  77. {
  78. int i = 0;
  79. // just iterate through argv word and compare it with your commands
  80. while (i < argc) {
  81. if (strcmp (argv[i], _CMD_HELP) == 0)
  82. {
  83. print ("microrl library v");
  84. print (MICRORL_LIB_VER);
  85. print ("\n\r");
  86. print_help (); // print help
  87. }
  88. else if (strcmp (argv[i], _CMD_CLEAR) == 0)
  89. {
  90. print ("\033[2J"); // ESC seq for clear entire screen
  91. print ("\033[H"); // ESC seq for move cursor at left-top corner
  92. }
  93. else if (strcmp (argv[i], _CMD_DAC_SEND_TEST_VAL) == 0)
  94. {
  95. uint16_t val;
  96. if (++i < argc)
  97. {
  98. val = atoi (argv[i]);
  99. DAC_SendRawData(val);
  100. return 0;
  101. }
  102. }
  103. else
  104. {
  105. print ("command: '");
  106. print ((char*)argv[i]);
  107. print ("' Not found.\n\r");
  108. }
  109. i++;
  110. }
  111. return 0;
  112. }
  113. void print_help (void)
  114. {
  115. print ("Use TAB key for completion\n\rCommand:\n\r");
  116. print ("\tclear - clear screen\n\r");
  117. print ("\tdac - send test value\n\r");
  118. }
  119. /******************************* (C) LiteMesh *********************************/