2 This project is free software: you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation, either version 3 of the License, or
5 (at your option) any later version.
7 Multiprotocol is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
16 #if defined(MULTI_CONFIG_INO)
18 #ifdef CYRF6936_INSTALLED
19 #include "iface_cyrf6936.h"
22 void CONFIG_write_GID(uint32_t id)
24 for(uint8_t i=0;i<4;i++)
25 eeprom_write_byte((EE_ADDR)EEPROM_ID_OFFSET+i,id >> (i*8));
26 //eeprom_write_byte((EE_ADDR)(EEPROM_ID_OFFSET+10),0xf0);
29 void CONFIG_write_CID(uint8_t *data)
31 for(uint8_t i=0;i<6;i++)
32 eeprom_write_byte((EE_ADDR)EEPROM_CID_OFFSET+i, data[i]);
33 //eeprom_write_byte((EE_ADDR)EEPROM_CID_INIT_OFFSET, 0xf0);
35 uint16_t CONFIG_callback()
37 static uint8_t line=0, page=0;
39 // [0] = page<<4|line number
40 // [1..6] = max 6 bytes
44 for(uint8_t i=0; i<7; i++)
45 debug("%02X ",CONFIG_SerialRX_val[i]);
47 CONFIG_SerialRX = false;
48 switch(CONFIG_SerialRX_val[0]&0x0F)
54 for(uint8_t i=0; i<4; i++)
57 id |= CONFIG_SerialRX_val[i+1];
59 debugln("Update ID to %lx", id);
63 if(CONFIG_SerialRX_val[1]==0xAA)
65 #define STM32_UUID ((uint32_t *)0x1FFFF7E8)
66 id = STM32_UUID[0] ^ STM32_UUID[1] ^ STM32_UUID[2];
67 debugln("Reset GID to %lx", id);
71 #ifdef CYRF6936_INSTALLED
73 debug("Update CID to ");
74 for(uint8_t i=0; i<6; i++)
75 debug("%02X ",CONFIG_SerialRX_val[i+1]);
77 CONFIG_write_CID(&CONFIG_SerialRX_val[1]);
79 if(CONFIG_SerialRX_val[1]==0xAA)
82 CYRF_WriteRegister(CYRF_25_MFG_ID, 0xFF); /* Fuses power on */
83 CYRF_ReadRegisterMulti(CYRF_25_MFG_ID, data, 6);
84 CYRF_WriteRegister(CYRF_25_MFG_ID, 0x00); /* Fuses power off */
85 debug("Reset CID to ");
86 for(uint8_t i=0; i<6; i++)
87 debug("%02X ",data[i]);
89 CONFIG_write_CID(data);
94 if(CONFIG_SerialRX_val[1]==0xAA)
97 #if defined(STM32_BOARD)
100 for (uint16_t i = 0; i < 512; i++)
101 eeprom_write_byte((EE_ADDR)i, 0xFF);
110 // [0] = page<<4|line number
111 // line=0: VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION, VERSION_PATCH_LEVEL, Channel order:RUDDER<<6|THROTTLE<<4|ELEVATOR<<2|AILERON
112 // [1..21] = max 20 characters, any displayable chars followed by:
113 // 0x00 : end of line
114 // 0x80+len: selectable text to follow
115 // 0x90+len: selectable text to follow with "Are you sure?"
116 // 0xA0+len: not editable dec value
117 // 0xB0+len: editable dec value
118 // 0xC0+len: not editable hex value
119 // 0xD0+len: editable hex value
120 memset(&packet_in[1],0,20);
123 packet_in[0] = (page<<4) | line;
127 packet_in[1]=VERSION_MAJOR;
128 packet_in[2]=VERSION_MINOR;
129 packet_in[3]=VERSION_REVISION;
130 packet_in[4]=VERSION_PATCH_LEVEL;
131 packet_in[5]=RUDDER<<6|THROTTLE<<4|ELEVATOR<<2|AILERON;
135 #ifndef FORCE_GLOBAL_ID
136 memcpy(&packet_in[1],"Global ID",9);
137 packet_in[10] = 0xD0 + 4;
139 memcpy(&packet_in[1],"Fixed ID ",9);
140 packet_in[10] = 0xC0 + 4;
142 MProtocol_id_master = random_id(EEPROM_ID_OFFSET,false);
143 set_rx_tx_addr(MProtocol_id_master);
144 for(uint8_t i=0; i<4; i++)
145 packet_in[11+i]=rx_tx_addr[i];
147 #if defined(STM32_BOARD) && not defined(FORCE_GLOBAL_ID)
150 packet_in[1] = 0x90+9;
151 memcpy(&packet_in[2],"Reset GID",9);
154 #ifdef CYRF6936_INSTALLED
157 #ifndef FORCE_CYRF_ID
158 memcpy(&packet_in[1],"Cyrf ID",7);
159 packet_in[8] = 0xD0 + 6;
160 CYRF_GetMfgData(&packet_in[9]);
162 memcpy(&packet_in[1],"Fixed CID",9);
163 packet_in[10] = 0xC0 + 6;
164 CYRF_GetMfgData(&packet_in[11]);
167 #ifndef FORCE_CYRF_ID
170 packet_in[1] = 0x90+9;
171 memcpy(&packet_in[2],"Reset CID",9);
176 packet_in[1] = 0x90+13;
177 memcpy(&packet_in[2],"Format EEPROM",13);
183 while(packet_in[1]==0); // next line if empty