diff --git a/Multiprotocol/CYRF6936_SPI.ino b/Multiprotocol/CYRF6936_SPI.ino index a1733f9..aaf04b6 100644 --- a/Multiprotocol/CYRF6936_SPI.ino +++ b/Multiprotocol/CYRF6936_SPI.ino @@ -258,7 +258,7 @@ void CYRF_FindBestChannels(uint8_t *channels, uint8_t len, uint8_t minspace, uin delayMilliseconds(1); for(i = 0; i < NUM_FREQ; i++) { - CYRF_ConfigRFChannel(i); + CYRF_ConfigRFChannel(protocol==PROTO_LOSI?i|1:i); delayMicroseconds(270); //slow channel require 270usec for synthesizer to settle if( !(CYRF_ReadRegister(CYRF_05_RX_CTRL) & 0x80)) { CYRF_WriteRegister(CYRF_05_RX_CTRL, 0x80); //Prepare to receive diff --git a/Multiprotocol/Losi_cyrf6936.ino b/Multiprotocol/Losi_cyrf6936.ino new file mode 100644 index 0000000..fc17b60 --- /dev/null +++ b/Multiprotocol/Losi_cyrf6936.ino @@ -0,0 +1,147 @@ +/* + This project is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Multiprotocol is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Multiprotocol. If not, see . + */ + +#if defined(LOSI_CYRF6936_INO) + +#include "iface_cyrf6936.h" + +#define LOSI_FORCE_ID + +const uint8_t PROGMEM LOSI_bind_sop_code[] = {0x62, 0xdf, 0xc1, 0x49, 0xdf, 0xb1, 0xc0, 0x49}; +const uint8_t LOSI_data_code[][16] = { + { 0xD7, 0xA1, 0x54, 0xB1, 0x5E, 0x89, 0xAE, 0x86, 0xC9, 0x2C, 0x06, 0x93, 0x86, 0xB9, 0x9E, 0xD7 }, //bind + { 0xE1, 0xD6, 0x31, 0x26, 0x5F, 0xBD, 0x40, 0x93, 0xDC, 0x68, 0x08, 0x99, 0x97, 0xAE, 0xAF, 0x8C }, + { 0xDC, 0x68, 0x08, 0x99, 0x97, 0xAE, 0xAF, 0x8C, 0xC3, 0x0E, 0x01, 0x16, 0x0E, 0x32, 0x06, 0xBA }, + { 0xC3, 0x0E, 0x01, 0x16, 0x0E, 0x32, 0x06, 0xBA, 0xE0, 0x83, 0x01, 0xFA, 0xAB, 0x3E, 0x8F, 0xAC }, + { 0xE0, 0x83, 0x01, 0xFA, 0xAB, 0x3E, 0x8F, 0xAC, 0x5C, 0xD5, 0x9C, 0xB8, 0x46, 0x9C, 0x7D, 0x84 }, + { 0x5C, 0xD5, 0x9C, 0xB8, 0x46, 0x9C, 0x7D, 0x84, 0xF1, 0xC6, 0xFE, 0x5C, 0x9D, 0xA5, 0x4F, 0xB7 }, + { 0xF1, 0xC6, 0xFE, 0x5C, 0x9D, 0xA5, 0x4F, 0xB7, 0x58, 0xB5, 0xB3, 0xDD, 0x0E, 0x28, 0xF1, 0xB0 }, + { 0x58, 0xB5, 0xB3, 0xDD, 0x0E, 0x28, 0xF1, 0xB0, 0x5F, 0x30, 0x3B, 0x56, 0x96, 0x45, 0xF4, 0xA1 }, + { 0x5F, 0x30, 0x3B, 0x56, 0x96, 0x45, 0xF4, 0xA1, 0x03, 0xBC, 0x6E, 0x8A, 0xEF, 0xBD, 0xFE, 0xF8 } +}; + +static uint16_t __attribute__((unused)) LOSI_check(uint16_t val) +{ + const uint8_t PROGMEM tab[] = { 0xF1, 0xDA, 0xB6, 0xC8 }; + uint8_t res = 0x0B, tmp; + uint16_t calc = val>>2; // don't care about the 2 first bits + for(uint8_t i=0; i<5; i++) + { + tmp=pgm_read_byte_near(&tab[i&0x03]); + if(calc&0x0001) + res ^= tmp>>4; + calc >>= 1; + if(calc&0x0001) + res ^= tmp; + calc >>= 1; + } + return val ^ (res<<12); +} + +static void __attribute__((unused)) LOSI_send_packet() +{ + memcpy(packet, rx_tx_addr, 4); + if(IS_BIND_IN_PROGRESS) + { + memcpy(&packet[4], rx_tx_addr, 4); + packet[8] = 0x05; // CRC? + packet[9] = 0x52; // CRC? + } + else + { + for(uint8_t i=0; i<3; i++) + { + uint16_t val = LOSI_check(Channel_data[i]<<1); + packet[4+i*2] = val >> 8; + packet[5+i*2] = val; + } + } + + CYRF_SetPower(0x38); + CYRF_WriteDataPacketLen(packet, 0x0A); + #if 0 + for(uint8_t i=0; i < 0x0A; i++) + debug("%02X ", packet[i]); + debugln(); + #endif +} + +static void __attribute__((unused)) LOSI_cyrf_init() +{ + /* Initialise CYRF chip */ + CYRF_WriteRegister(CYRF_28_CLK_EN, 0x02); + CYRF_WriteRegister(CYRF_32_AUTO_CAL_TIME, 0x3C); + CYRF_WriteRegister(CYRF_35_AUTOCAL_OFFSET, 0x14); + CYRF_WriteRegister(CYRF_06_RX_CFG, 0x48); + CYRF_WriteRegister(CYRF_1B_TX_OFFSET_LSB, 0x55); + CYRF_WriteRegister(CYRF_1C_TX_OFFSET_MSB, 0x05); + //CYRF_WriteRegister(CYRF_0F_XACT_CFG, 0x24); + CYRF_SetPower(0x38); + CYRF_WriteRegister(CYRF_12_DATA64_THOLD, 0x0A); + CYRF_WriteRegister(CYRF_39_ANALOG_CTRL, 0x01); + CYRF_WritePreamble(0x333304); + //CYRF_WriteRegister(CYRF_27_CLK_OVERRIDE, 0x00); + CYRF_WriteRegister(CYRF_10_FRAMING_CFG, 0x4A); + CYRF_WriteRegister(CYRF_1F_TX_OVERRIDE, 0x04); // No CRC + //CYRF_WriteRegister(CYRF_1E_RX_OVERRIDE, 0x14); + //CYRF_WriteRegister(CYRF_14_EOP_CTRL, 0x02); +} + +uint16_t LOSI_callback() +{ + #ifdef MULTI_SYNC + telemetry_set_input_sync(19738); + #endif + LOSI_send_packet(); + if(bind_counter) + { + bind_counter--; + if(bind_counter==0) + { + BIND_DONE; + CYRF_ConfigDataCode(LOSI_data_code[num_ch], 16); // Load normal data code + } + return 8763; + } + return 19738; +} + +void LOSI_init() +{ + LOSI_cyrf_init(); + CYRF_FindBestChannels(hopping_frequency, 1, 0, 0x13, 75); // 75 is unknown since dump stops at 0x27, this routine resets the CRC Seed to 0 + CYRF_ConfigRFChannel(hopping_frequency[0] | 1); // Only odd channels + + #ifdef LOSI_FORCE_ID + rx_tx_addr[0] = 0x47; + rx_tx_addr[1] = 0x52; + rx_tx_addr[2] = 0xAE; + rx_tx_addr[3] = 0xAA; + num_ch = 8; // It looks that you could choose what you want based on channel business + #endif + + if(IS_BIND_IN_PROGRESS) + { + bind_counter = 300; + CYRF_ConfigDataCode(LOSI_data_code[0], 16); // Load bind data code + } + else + { + CYRF_ConfigDataCode(LOSI_data_code[num_ch], 16); // Load normal data code + bind_counter = 0; + } +} + +#endif diff --git a/Multiprotocol/Multi.txt b/Multiprotocol/Multi.txt index 517328e..e4d5b7b 100644 --- a/Multiprotocol/Multi.txt +++ b/Multiprotocol/Multi.txt @@ -82,4 +82,6 @@ 82,LOLI 83,E129 84,JOYSWAY -85,E016H \ No newline at end of file +85,E016H +87,IKEA +89,LOSI \ No newline at end of file diff --git a/Multiprotocol/Multi_Protos.ino b/Multiprotocol/Multi_Protos.ino index 05de614..34b38a7 100644 --- a/Multiprotocol/Multi_Protos.ino +++ b/Multiprotocol/Multi_Protos.ino @@ -100,6 +100,7 @@ const char STR_E129[] ="E129"; const char STR_E016H[] ="E016H"; const char STR_IKEAANSLUTA[]="Ansluta"; const char STR_CONFIG[] ="Config"; +const char STR_LOSI[] ="Losi"; const char STR_SUBTYPE_FLYSKY[] = "\x04""Std\0""V9x9""V6x6""V912""CX20"; const char STR_SUBTYPE_HUBSAN[] = "\x04""H107""H301""H501"; @@ -355,6 +356,9 @@ const mm_protocol_definition multi_protocols[] = { #if defined(LOLI_NRF24L01_INO) {PROTO_LOLI, STR_LOLI, NO_SUBTYPE, 0, OPTION_NONE, 1, 0, SW_NRF, LOLI_init, LOLI_callback }, #endif + #if defined(LOSI_CYRF6936_INO) + {PROTO_LOSI, STR_LOSI, NO_SUBTYPE, 0, OPTION_NONE, 0, 0, SW_CYRF, LOSI_init, LOSI_callback }, + #endif #if defined(MJXQ_CCNRF_INO) {PROTO_MJXQ, STR_MJXQ, STR_SUBTYPE_MJXQ, 7, OPTION_NONE, 0, 0, SW_NRF, MJXQ_init, MJXQ_callback }, #endif diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index 23aa1db..e14d4cb 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -19,7 +19,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 #define VERSION_REVISION 2 -#define VERSION_PATCH_LEVEL 79 +#define VERSION_PATCH_LEVEL 80 #define MODE_SERIAL 0 @@ -116,6 +116,7 @@ enum PROTOCOLS PROTO_CONFIG = 86, // Module config PROTO_IKEAANSLUTA = 87, // =>CC2500 PROTO_WILLIFM = 88, // 27/35ab/40/41/72 MHz module external project + PROTO_LOSI = 89, // =>CYRF6936 PROTO_NANORF = 126, // =>NRF24L01 PROTO_TEST = 127, // =>CC2500 diff --git a/Multiprotocol/Validate.h b/Multiprotocol/Validate.h index 468f7b3..3c2b8c4 100644 --- a/Multiprotocol/Validate.h +++ b/Multiprotocol/Validate.h @@ -260,6 +260,7 @@ #undef E010R5_CYRF6936_INO #undef E129_CYRF6936_INO #undef J6PRO_CYRF6936_INO + #undef LOSI_CYRF6936_INO #undef MLINK_CYRF6936_INO #undef TRAXXAS_CYRF6936_INO #undef WFLY_CYRF6936_INO diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index e98a3ac..766f316 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -187,6 +187,7 @@ #define E010R5_CYRF6936_INO #define E129_CYRF6936_INO #define J6PRO_CYRF6936_INO +#define LOSI_CYRF6936_INO #define MLINK_CYRF6936_INO #define TRAXXAS_CYRF6936_INO #define WFLY_CYRF6936_INO @@ -695,6 +696,7 @@ const PPM_Parameters PPM_prot[14*NBR_BANKS]= { H301 H501 PROTO_IKEAANSLUTA + NONE PROTO_J6PRO NONE PROTO_JJRC345 @@ -712,6 +714,8 @@ const PPM_Parameters PPM_prot[14*NBR_BANKS]= { KYOSHO_HYPE PROTO_LOLI NONE + PROTO_LOSI + NONE PROTO_MJXQ WLH08 X600 diff --git a/Protocols_Details.md b/Protocols_Details.md index 41cf3f3..d042926 100644 --- a/Protocols_Details.md +++ b/Protocols_Details.md @@ -595,6 +595,15 @@ CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8|CH9|CH10|CH11|CH12 ---|---|---|---|---|---|---|---|---|----|----|---- A|E|T|R|CH5|CH6|CH7|CH8|CH9|CH10|CH11|CH12 +## Losi - *89* +TX: LSR-3000 + +Extended limits supported + +CH1|CH2|CH3 +---|---|--- +ST|THR|CH3 + ## MLINK - *78* Extended limits supported