1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef __ESP_SSC_H__ 16 #define __ESP_SSC_H__ 17 18 #include <stdint.h> 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 #define CMD_T_ASYNC 0x01 25 #define CMD_T_SYNC 0x02 26 27 typedef struct cmd_s { 28 char *cmd_str; 29 uint8_t flag; 30 uint8_t id; 31 void (* cmd_func)(void); 32 void (* cmd_callback)(void *arg); 33 } ssc_cmd_t; 34 35 #define MAX_LINE_N 127 36 37 typedef enum { 38 SSC_BR_9600 = 9600, 39 SSC_BR_19200 = 19200, 40 SSC_BR_38400 = 38400, 41 SSC_BR_57600 = 57600, 42 SSC_BR_74880 = 74880, 43 SSC_BR_115200 = 115200, 44 SSC_BR_230400 = 230400, 45 SSC_BR_460800 = 460800, 46 SSC_BR_921600 = 921600 47 } SscBaudRate; 48 49 /** \defgroup SSC_APIs SSC APIs 50 * @brief SSC APIs 51 * 52 * SSC means simple serial command. 53 * SSC APIs allows users to define their own command, users can refer to spiffs_test/test_main.c. 54 * 55 */ 56 57 /** @addtogroup SSC_APIs 58 * @{ 59 */ 60 61 /** 62 * @brief Initial the ssc function. 63 * 64 * @attention param is no use, just compatible with ESP8266, default bandrate is 115200 65 * 66 * @param SscBaudRate bandrate : baud rate 67 * 68 * @return null 69 */ 70 void ssc_attach(SscBaudRate bandrate); 71 72 /** 73 * @brief Get the length of the simple serial command. 74 * 75 * @param null 76 * 77 * @return length of the command. 78 */ 79 int ssc_param_len(void); 80 81 /** 82 * @brief Get the simple serial command string. 83 * 84 * @param null 85 * 86 * @return the command. 87 */ 88 char *ssc_param_str(void); 89 90 /** 91 * @brief Parse the simple serial command (ssc). 92 * 93 * @param char *pLine : [input] the ssc string 94 * @param char *argv[] : [output] parameters of the ssc 95 * 96 * @return the number of parameters. 97 */ 98 int ssc_parse_param(char *pLine, char *argv[]); 99 100 /** 101 * @brief Register the user-defined simple serial command (ssc) set. 102 * 103 * @param ssc_cmd_t *cmdset : the ssc set 104 * @param uint8 cmdnum : number of commands 105 * @param void (* help)(void) : callback of user-guide 106 * 107 * @return null 108 */ 109 void ssc_register(ssc_cmd_t *cmdset, uint8_t cmdnum, void (* help)(void)); 110 111 /** 112 * @} 113 */ 114 115 #ifdef __cplusplus 116 } 117 #endif 118 119 #endif /* __ESP_SSC_H__ */ 120