NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
serial_4way.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Ninjaflight is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Ninjaflight is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
16  * Author: 4712
17 */
18 
19 #pragma once
20 
21 #ifdef USE_SERIAL_4WAY_BLHELI_INTERFACE
22 
23 #define USE_SERIAL_4WAY_BLHELI_BOOTLOADER
24 #define USE_SERIAL_4WAY_SK_BOOTLOADER
25 
26 typedef enum {
27  imC2 = 0,
28  imSIL_BLB = 1,
29  imATM_BLB = 2,
30  imSK = 3,
31 } esc4wayInterfaceMode_e;
32 
33 typedef enum {
34 // Test Interface still present
35  cmd_InterfaceTestAlive = 0x30, // '0' alive
36 // RETURN: ACK
37 
38 // get Protocol Version Number 01..255
39  cmd_ProtocolGetVersion = 0x31, // '1' version
40 // RETURN: uint8_t VersionNumber + ACK
41 
42 // get Version String
43  cmd_InterfaceGetName = 0x32, // '2' name
44 // RETURN: String + ACK
45 
46 //get Version Number 01..255
47  cmd_InterfaceGetVersion = 0x33, // '3' version
48 // RETURN: uint16_t VersionNumber + ACK
49 
50 // Exit / Restart Interface - can be used to switch to Box Mode
51  cmd_InterfaceExit = 0x34, // '4' exit
52 // RETURN: ACK
53 
54 // Reset the Device connected to the Interface
55  cmd_DeviceReset = 0x35, // '5' reset
56 // PARAM: uint8_t escId
57 // RETURN: ACK
58 
59 // Get the Device ID connected
60 // cmd_DeviceGetID = 0x36, // '6' device id; removed since 06/106
61 // RETURN: uint8_t DeviceID + ACK
62 
63 // Initialize Flash Access for Device connected
64 // Autodetects interface protocol; retruns device signature and protocol
65  cmd_DeviceInitFlash = 0x37, // '7' init flash access
66 // PARAM: uint8_t escId
67 // RETURN: uint8_t deviceInfo[4] + ACK
68 
69 // Erase the whole Device Memory of connected Device
70  cmd_DeviceEraseAll = 0x38, // '8' erase all
71 // RETURN: ACK
72 
73 // Erase one Page of Device Memory of connected Device
74  cmd_DevicePageErase = 0x39, // '9' page erase
75 // PARAM: uint8_t PageNumber (512B pages)
76 // RETURN: APageNumber ACK
77 
78 // Read to Buffer from FLASH Memory of connected Device
79 // Buffer Len is Max 256 Bytes, 0 means 256 Bytes
80  cmd_DeviceRead = 0x3A, // ':' read Device
81 // PARAM: [ADRESS] uint8_t BuffLen
82 // RETURN: [ADRESS, len] Buffer[0..256] ACK
83 
84 // Write Buffer to FLASH Memory of connected Device
85 // Buffer Len is Max 256 Bytes, 0 means 256 Bytes
86  cmd_DeviceWrite = 0x3B, // ';' write
87 // PARAM: [ADRESS + BuffLen] Buffer[1..256]
88 // RETURN: ACK
89 
90 // Set C2CK low infinite - permanent Reset state (unimplemented)
91  cmd_DeviceC2CK_LOW = 0x3C, // '<'
92 // RETURN: ACK
93 
94 // Read to Buffer from EEPROM Memory of connected Device
95 // Buffer Len is Max 256 Bytes, 0 means 256 Bytes
96  cmd_DeviceReadEEprom = 0x3D, // '=' read Device
97 // PARAM: [ADRESS] uint8_t BuffLen
98 // RETURN: [ADRESS + BuffLen] + Buffer[1..256] ACK
99 
100 // Write Buffer to EEPROM Memory of connected Device
101 // Buffer Len is Max 256 Bytes, 0 means 256 Bytes
102  cmd_DeviceWriteEEprom = 0x3E, // '>' write
103 // PARAM: [ADRESS + BuffLen] Buffer[1..256]
104 // RETURN: ACK
105 
106 // Set Interface Mode
107  cmd_InterfaceSetMode = 0x3F, // '?'
108 // PARAM: uint8_t Mode (interfaceMode_e)
109 // RETURN: ACK
110 } esc4wayCmd_e;
111 
112 // responses
113 typedef enum {
114  esc4wayAck_OK = 0x00,
115 // esc4wayAck_I_UNKNOWN_ERROR = 0x01,
116  esc4wayAck_I_INVALID_CMD = 0x02,
117  esc4wayAck_I_INVALID_CRC = 0x03,
118  esc4wayAck_I_VERIFY_ERROR = 0x04,
119 // esc4wayAck_D_INVALID_COMMAND = 0x05,
120 // esc4wayAck_D_COMMAND_FAILED = 0x06,
121 // esc4wayAck_D_UNKNOWN_ERROR = 0x07,
122  esc4wayAck_I_INVALID_CHANNEL = 0x08,
123  esc4wayAck_I_INVALID_PARAM = 0x09,
124  esc4wayAck_D_GENERAL_ERROR = 0x0f,
125 } esc4wayAck_e;
126 
127 typedef struct escDeviceInfo_s {
128  uint16_t signature; // lower 16 bit of signature
129  uint8_t signature2; // top 8 bit of signature for SK / BootMsg last char from BL
130  uint8_t interfaceMode;
131 } escDeviceInfo_t;
132 
133 extern bool esc4wayExitRequested; // flag that exit was requested. Set by esc4wayProcessCmd, used internally by esc4wayProcess
134 
135 int esc4wayInit(void);
136 void esc4wayStart(void);
137 void esc4wayRelease(void);
138 void esc4wayProcess(serialPort_t *serial);
139 esc4wayAck_e esc4wayProcessCmd(esc4wayCmd_e command, uint16_t addr, uint8_t *data, int inLen, int *outLen);
140 
141 #endif
struct serial_config serial
Definition: config.h:116
uint16_t addr
Definition: config.c:90
uint16_t data
Definition: config.c:91
Definition: serial.h:43