From 949faf1f0f3d3aa99113cfd055c5cda827d2a1fc Mon Sep 17 00:00:00 2001 From: Richard Li Date: Tue, 14 Feb 2023 13:49:58 +0800 Subject: [PATCH 1/2] Added Microzone protocol support. --- Multiprotocol/Microzone_a7105.ino | 201 ++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 Multiprotocol/Microzone_a7105.ino diff --git a/Multiprotocol/Microzone_a7105.ino b/Multiprotocol/Microzone_a7105.ino new file mode 100644 index 000000000..523ab1930 --- /dev/null +++ b/Multiprotocol/Microzone_a7105.ino @@ -0,0 +1,201 @@ +/* + 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(MICROZONE_A7105_INO) + +#include "iface_a7105.h" + +//#define MICROZONE_FORCE_ID_FHSS +//#define MICROZONE_FORCE_ID_HYPE + +//MICROZONE constants & variables +#define MICROZONE_BIND_COUNT 2500 + +static void __attribute__((unused)) MICROZONE_send_packet() +{ + //ID + packet[1] = rx_tx_addr[0]; + packet[2] = rx_tx_addr[1]; + packet[3] = rx_tx_addr[2]; + packet[4] = rx_tx_addr[3]; + //unknown may be RX ID on some other remotes + memset(packet+5,0xFF,4); + + if(IS_BIND_IN_PROGRESS) + { + packet[ 0] = 0xBC; // bind indicator + packet[ 9] &= 0x01; + packet[ 9] ^= 0x01; // high/ low part of the RF table + packet[10] = 0x00; + //RF table + for(uint8_t i=0; i<16;i++) + packet[i+11]=hopping_frequency[i+(packet[9]<<4)]; + //unknwon + packet[27] = 0x05; + packet[28] = 0x00; + memset(packet+29,0xFF,8); + //frequency hop during bind + if(packet[9]) + rf_ch_num=0x8C; + else + rf_ch_num=0x0D; + } + else + { + packet[ 0] = 0x58; // normal packet + //14 channels: steering, throttle, ... + for(uint8_t i = 0; i < 14; i++) + { + uint16_t temp=convert_channel_ppm(i); + packet[9 + i*2]=temp&0xFF; // low byte of servo timing(1000-2000us) + packet[10 + i*2]=(temp>>8)&0xFF; // high byte of servo timing(1000-2000us) + } + rf_ch_num=hopping_frequency[hopping_frequency_no]; + hopping_frequency_no++; + packet[34] |= (hopping_frequency_no&0x0F)<<4; + packet[36] |= (hopping_frequency_no&0xF0); // last byte is ending with F on the dumps so let's see + hopping_frequency_no &= 0x1F; + } + #if 0 + debug("ch=%02X P=",rf_ch_num); + for(uint8_t i=0; i<37; i++) + debug("%02X ", packet[i]); + debugln(""); + #endif + A7105_WriteData(37, rf_ch_num); +} + +static void __attribute__((unused)) MICROZONE_hype_send_packet() +{ + if(IS_BIND_IN_PROGRESS) + { + if(packet_sent==0) + {//build the packet and send it + packet[0] = rx_tx_addr[1]; + packet[1] = rx_tx_addr[3]; + //RF table + for(uint8_t i=0; i<15;i++) + packet[i+2]=hopping_frequency[i]; + A7105_WriteData(17, 0x01); + packet_sent++; + packet_period=1421; + #if 0 + debug("ch=01 P="); + for(uint8_t i=0; i<17; i++) + debug("%02X ", packet[i]); + debugln(""); + #endif + } + else + A7105_Strobe(A7105_TX); //only send + } + else + { + //original TX is only refreshing the packet every 20ms and keep repeating the same packet in between (STROBE_TX) + //build packet=6 channels with order AETR + for(uint8_t i=0;i<6;i++) + packet[i] = convert_channel_8b(CH_AETR[i]); + //set RF channel + rf_ch_num=hopping_frequency[hopping_frequency_no]; + hopping_frequency_no++; + if(hopping_frequency_no>14) + hopping_frequency_no = 0; + //send it + A7105_WriteData(6, rf_ch_num); + packet_period=931; //packet period fluctuates a lot on the original TX from one packet to the other but stable if looking over a period of 40ms + #if 0 + debug("ch=%02X P=",rf_ch_num); + for(uint8_t i=0; i<6; i++) + debug("%02X ", packet[i]); + debugln(""); + #endif + } +} + +uint16_t MICROZONE_callback() +{ + #ifndef FORCE_MICROZONE_TUNING + A7105_AdjustLOBaseFreq(1); + #endif + if(IS_BIND_IN_PROGRESS) + { + bind_counter--; + if (bind_counter==0) + { + BIND_DONE; + if(sub_protocol==MICROZONE_HYPE) + { + A7105_WriteID(MProtocol_id); + A7105_WriteReg(A7105_03_FIFOI,0x05); + } + } + } + else + { + if(hopping_frequency_no==0) + A7105_SetPower(); + #ifdef MULTI_SYNC + telemetry_set_input_sync(packet_period); + #endif + } + if(sub_protocol==MICROZONE_FHSS) + MICROZONE_send_packet(); + else//HYPE + MICROZONE_hype_send_packet(); + return packet_period; +} + +void MICROZONE_init() +{ + A7105_Init(); + + // compute channels from ID + calc_fh_channels(sub_protocol==MICROZONE_FHSS?32:15); + hopping_frequency_no=0; + + #ifdef MICROZONE_FORCE_ID_FHSS + if(sub_protocol==MICROZONE_FHSS) + { + memcpy(rx_tx_addr,"\x3A\x39\x37\x00",4); + memcpy(hopping_frequency,"\x29\x4C\x67\x92\x31\x1C\x77\x18\x23\x6E\x81\x5C\x8F\x5A\x51\x94\x7A\x12\x45\x6C\x7F\x1E\x0D\x88\x63\x8C\x4F\x37\x26\x61\x2C\x8A",32); + } + #endif + if(sub_protocol==MICROZONE_HYPE) + { + MProtocol_id &= 0x00FF00FF; + rx_tx_addr[0] = 0xAF - (rx_tx_addr[1]&0x0F); + rx_tx_addr[2] = 0xFF - rx_tx_addr[3]; + MProtocol_id |= (rx_tx_addr[0]<<24) + (rx_tx_addr[2]<<8); + #ifdef MICROZONE_FORCE_ID_HYPE + MProtocol_id=0xAF90738C; + set_rx_tx_addr(MProtocol_id); + memcpy(hopping_frequency,"\x27\x1B\x63\x75\x03\x39\x57\x69\x87\x0F\x7B\x3F\x33\x51\x6F",15); + #endif + if(IS_BIND_IN_PROGRESS) + A7105_WriteID(0xAF00FF00); + else + { + A7105_WriteID(MProtocol_id); + A7105_WriteReg(A7105_03_FIFOI,0x05); + } + } + + if(IS_BIND_IN_PROGRESS) + bind_counter = MICROZONE_BIND_COUNT; + + packet_sent=0; + packet_period=3852; //FHSS +} +#endif From fab58c1df4b36e0fe359942acefe57cf5ef2d57f Mon Sep 17 00:00:00 2001 From: Richard Li Date: Fri, 24 Feb 2023 13:35:56 +0800 Subject: [PATCH 2/2] Compilable for M1. --- Multiprotocol/Microzone_a7105.ino | 21 +++++++-------------- Multiprotocol/Multi_Protos.ino | 5 +++++ Multiprotocol/Multiprotocol.h | 6 ++++++ Multiprotocol/_Config.h | 1 + 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Multiprotocol/Microzone_a7105.ino b/Multiprotocol/Microzone_a7105.ino index 523ab1930..445414446 100644 --- a/Multiprotocol/Microzone_a7105.ino +++ b/Multiprotocol/Microzone_a7105.ino @@ -135,7 +135,7 @@ uint16_t MICROZONE_callback() if (bind_counter==0) { BIND_DONE; - if(sub_protocol==MICROZONE_HYPE) + if(sub_protocol==MICROZONE_M1) { A7105_WriteID(MProtocol_id); A7105_WriteReg(A7105_03_FIFOI,0x05); @@ -150,9 +150,9 @@ uint16_t MICROZONE_callback() telemetry_set_input_sync(packet_period); #endif } - if(sub_protocol==MICROZONE_FHSS) - MICROZONE_send_packet(); - else//HYPE +// if(sub_protocol==MICROZONE_FHSS) +// MICROZONE_send_packet(); +// else//HYPE MICROZONE_hype_send_packet(); return packet_period; } @@ -162,23 +162,16 @@ void MICROZONE_init() A7105_Init(); // compute channels from ID - calc_fh_channels(sub_protocol==MICROZONE_FHSS?32:15); + calc_fh_channels(15); hopping_frequency_no=0; - #ifdef MICROZONE_FORCE_ID_FHSS - if(sub_protocol==MICROZONE_FHSS) - { - memcpy(rx_tx_addr,"\x3A\x39\x37\x00",4); - memcpy(hopping_frequency,"\x29\x4C\x67\x92\x31\x1C\x77\x18\x23\x6E\x81\x5C\x8F\x5A\x51\x94\x7A\x12\x45\x6C\x7F\x1E\x0D\x88\x63\x8C\x4F\x37\x26\x61\x2C\x8A",32); - } - #endif - if(sub_protocol==MICROZONE_HYPE) + if(sub_protocol==MICROZONE_M1) { MProtocol_id &= 0x00FF00FF; rx_tx_addr[0] = 0xAF - (rx_tx_addr[1]&0x0F); rx_tx_addr[2] = 0xFF - rx_tx_addr[3]; MProtocol_id |= (rx_tx_addr[0]<<24) + (rx_tx_addr[2]<<8); - #ifdef MICROZONE_FORCE_ID_HYPE + #ifdef MICROZONE_FORCE_ID MProtocol_id=0xAF90738C; set_rx_tx_addr(MProtocol_id); memcpy(hopping_frequency,"\x27\x1B\x63\x75\x03\x39\x57\x69\x87\x0F\x7B\x3F\x33\x51\x6F",15); diff --git a/Multiprotocol/Multi_Protos.ino b/Multiprotocol/Multi_Protos.ino index daa3c8743..5138d0e12 100644 --- a/Multiprotocol/Multi_Protos.ino +++ b/Multiprotocol/Multi_Protos.ino @@ -105,6 +105,7 @@ const char STR_CONFIG[] ="Config"; const char STR_LOSI[] ="Losi"; const char STR_MOULDKG[] ="MouldKg"; const char STR_XERALL[] ="Xerall"; +const char STR_MICROZONE[] ="Microzone"; const char STR_SUBTYPE_FLYSKY[] = "\x04""Std\0""V9x9""V6x6""V912""CX20"; const char STR_SUBTYPE_HUBSAN[] = "\x04""H107""H301""H501"; @@ -174,6 +175,7 @@ const char STR_SUBTYPE_MOULKG[] = "\x06""Analog""Digit\0"; const char STR_SUBTYPE_KF606[] = "\x06""KF606\0""MIG320""ZCZ50\0"; const char STR_SUBTYPE_E129[] = "\x04""E129""C186"; const char STR_SUBTYPE_FX[] = "\x04""816\0""620\0""9630"; +const char STR_SUBTYPE_MICROZONE[] = "\x02""M1""M2"; #define NO_SUBTYPE nullptr #ifdef SEND_CPPM @@ -377,6 +379,9 @@ const mm_protocol_definition multi_protocols[] = { #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(MICROZONE_A7105_INO) + {PROTO_MICROZONE, STR_MICROZONE, STR_SUBTYPE_MICROZONE, 2, OPTION_NONE, 0, 1, SW_A7105, MICROZONE_init, MICROZONE_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 939e7b4b5..a6bdd349c 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -121,6 +121,7 @@ enum PROTOCOLS PROTO_XERALL = 91, // =>NRF24L01 PROTO_MT99XX2 = 92, // =>NRF24L01, extension of MT99XX protocol PROTO_KYOSHO2 = 93, // =>NRF24L01 + PROTO_MICROZONE = 94, // =>A7105 PROTO_NANORF = 126, // =>NRF24L01 PROTO_TEST = 127, // =>CC2500 @@ -463,6 +464,11 @@ enum FX FX620 = 1, FX9630 = 2, }; +enum MICROZONE +{ + MICROZONE_M1 = 0, + MICROZONE_M2 = 1, +}; #define NONE 0 #define P_HIGH 1 diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 60e5d978f..6aa5b5735 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -182,6 +182,7 @@ #define KYOSHO_A7105_INO #define PELIKAN_A7105_INO #define WFLY2_A7105_INO +#define MICROZONE_A7105_INO //The protocols below need a CYRF6936 to be installed #define DEVO_CYRF6936_INO