2015-12-30 01:41:12 +01:00
|
|
|
/*
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-10-16 19:51:42 +02:00
|
|
|
#ifdef CYRF6936_INSTALLED
|
2015-12-30 01:41:12 +01:00
|
|
|
#include "iface_cyrf6936.h"
|
|
|
|
|
|
|
|
void CYRF_WriteRegister(uint8_t address, uint8_t data)
|
|
|
|
{
|
|
|
|
CYRF_CSN_off;
|
2016-08-01 21:57:18 +02:00
|
|
|
SPI_Write(0x80 | address);
|
|
|
|
SPI_Write(data);
|
2015-12-30 01:41:12 +01:00
|
|
|
CYRF_CSN_on;
|
|
|
|
}
|
|
|
|
|
Core and all protocols have been updated
Lot of changes in this new master
ChangeLog:
- Core: LED flashing when an invalid protocol has been selected
- Core: Channels 5 to 12 available as switches for all protocols: code
and size optimization
- Documentation (readme.md): fully updated, all protocols/sub
protocols/channels described, models example, many improvements
- All protocols have been updated in some way, here are some highlights:
* Bayang: added picture, video and inverted channels
* CG023->H8_3D: added light and calibration channels
* CX10: added sub protocols Q282, JC3015_1, JC3015_2, MK33041
* ESky: added new protocol - untested
* Hubsan: added compatibility with the new Hubsan Plus protocol
* KN: fully rewritten protocol: added sub protocols WLTOYS and FEILUN,
11 channels support
New version successfully tested on all my models: Flysky RX/F939/V911
protocol Flysky, Frsky RX protocol Frsky, Hubsan X4 protocol Hubsan,
Hisky HCP100/HCP80 protocol Hisky, HK-3000/HK3100 RX protocol
Hisky/HK310, XINXUN X39 protocol YD717/XINXUN, Symax X5C-1 protocol
SymaX/SYMAX, Cheerson CX-10A protocol CX10/BLUE, Eachine 3D-X4 protocol
CG023.
To access new protocols from er9x/ersky9x, you need to build a version
from this github repository https://github.com/pascallanger/mbtx based
on the latest er9x r820 and ersky9x r218.
2016-01-20 10:50:56 +01:00
|
|
|
static void CYRF_WriteRegisterMulti(uint8_t address, const uint8_t data[], uint8_t length)
|
2015-12-30 01:41:12 +01:00
|
|
|
{
|
|
|
|
uint8_t i;
|
|
|
|
|
|
|
|
CYRF_CSN_off;
|
2016-08-01 21:57:18 +02:00
|
|
|
SPI_Write(0x80 | address);
|
2015-12-30 01:41:12 +01:00
|
|
|
for(i = 0; i < length; i++)
|
2016-08-01 21:57:18 +02:00
|
|
|
SPI_Write(data[i]);
|
2015-12-30 01:41:12 +01:00
|
|
|
CYRF_CSN_on;
|
|
|
|
}
|
|
|
|
|
Core and all protocols have been updated
Lot of changes in this new master
ChangeLog:
- Core: LED flashing when an invalid protocol has been selected
- Core: Channels 5 to 12 available as switches for all protocols: code
and size optimization
- Documentation (readme.md): fully updated, all protocols/sub
protocols/channels described, models example, many improvements
- All protocols have been updated in some way, here are some highlights:
* Bayang: added picture, video and inverted channels
* CG023->H8_3D: added light and calibration channels
* CX10: added sub protocols Q282, JC3015_1, JC3015_2, MK33041
* ESky: added new protocol - untested
* Hubsan: added compatibility with the new Hubsan Plus protocol
* KN: fully rewritten protocol: added sub protocols WLTOYS and FEILUN,
11 channels support
New version successfully tested on all my models: Flysky RX/F939/V911
protocol Flysky, Frsky RX protocol Frsky, Hubsan X4 protocol Hubsan,
Hisky HCP100/HCP80 protocol Hisky, HK-3000/HK3100 RX protocol
Hisky/HK310, XINXUN X39 protocol YD717/XINXUN, Symax X5C-1 protocol
SymaX/SYMAX, Cheerson CX-10A protocol CX10/BLUE, Eachine 3D-X4 protocol
CG023.
To access new protocols from er9x/ersky9x, you need to build a version
from this github repository https://github.com/pascallanger/mbtx based
on the latest er9x r820 and ersky9x r218.
2016-01-20 10:50:56 +01:00
|
|
|
static void CYRF_ReadRegisterMulti(uint8_t address, uint8_t data[], uint8_t length)
|
2015-12-30 01:41:12 +01:00
|
|
|
{
|
|
|
|
uint8_t i;
|
|
|
|
|
|
|
|
CYRF_CSN_off;
|
2016-08-01 21:57:18 +02:00
|
|
|
SPI_Write(address);
|
2015-12-30 01:41:12 +01:00
|
|
|
for(i = 0; i < length; i++)
|
2016-08-01 21:57:18 +02:00
|
|
|
data[i] = SPI_Read();
|
2015-12-30 01:41:12 +01:00
|
|
|
CYRF_CSN_on;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t CYRF_ReadRegister(uint8_t address)
|
|
|
|
{
|
|
|
|
uint8_t data;
|
|
|
|
CYRF_CSN_off;
|
2016-08-01 21:57:18 +02:00
|
|
|
SPI_Write(address);
|
|
|
|
data = SPI_Read();
|
2015-12-30 01:41:12 +01:00
|
|
|
CYRF_CSN_on;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
|
|
|
|
uint8_t CYRF_Reset()
|
|
|
|
{
|
2016-08-22 18:17:14 +02:00
|
|
|
#ifdef CYRF_RST_HI
|
2016-08-21 17:54:12 +02:00
|
|
|
CYRF_RST_HI; //Hardware reset
|
|
|
|
delayMicroseconds(100);
|
|
|
|
CYRF_RST_LO;
|
|
|
|
delayMicroseconds(100);
|
2016-08-22 18:17:14 +02:00
|
|
|
#endif
|
|
|
|
CYRF_WriteRegister(CYRF_1D_MODE_OVERRIDE, 0x01); //Software reset
|
2016-08-21 17:54:12 +02:00
|
|
|
delayMicroseconds(200);
|
2016-08-22 18:17:14 +02:00
|
|
|
CYRF_WriteRegister(CYRF_0C_XTAL_CTRL, 0xC0); //Enable XOUT as GPIO
|
2016-08-21 17:54:12 +02:00
|
|
|
CYRF_WriteRegister(CYRF_0D_IO_CFG, 0x04); //Enable PACTL as GPIO
|
2015-12-30 01:41:12 +01:00
|
|
|
CYRF_SetTxRxMode(TXRX_OFF);
|
2016-08-21 17:54:12 +02:00
|
|
|
//Verify the CYRF chip is responding
|
|
|
|
return (CYRF_ReadRegister(CYRF_10_FRAMING_CFG) == 0xa5);
|
2015-12-30 01:41:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void CYRF_GetMfgData(uint8_t data[])
|
|
|
|
{
|
|
|
|
/* Fuses power on */
|
|
|
|
CYRF_WriteRegister(CYRF_25_MFG_ID, 0xFF);
|
|
|
|
|
|
|
|
CYRF_ReadRegisterMulti(CYRF_25_MFG_ID, data, 6);
|
|
|
|
|
|
|
|
/* Fuses power off */
|
|
|
|
CYRF_WriteRegister(CYRF_25_MFG_ID, 0x00);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1 - Tx else Rx
|
|
|
|
*/
|
|
|
|
void CYRF_SetTxRxMode(uint8_t mode)
|
|
|
|
{
|
2016-01-10 16:10:27 +01:00
|
|
|
if(mode==TXRX_OFF)
|
|
|
|
{
|
|
|
|
CYRF_WriteRegister(CYRF_0F_XACT_CFG, 0x24); // 4=IDLE, 8=TX, C=RX
|
|
|
|
CYRF_WriteRegister(CYRF_0E_GPIO_CTRL,0x00); // XOUT=0 PACTL=0
|
|
|
|
}
|
2015-12-30 01:41:12 +01:00
|
|
|
else
|
2016-01-10 16:10:27 +01:00
|
|
|
{
|
|
|
|
//Set the post tx/rx state
|
|
|
|
CYRF_WriteRegister(CYRF_0F_XACT_CFG, mode == TX_EN ? 0x28 : 0x2C); // 4=IDLE, 8=TX, C=RX
|
|
|
|
if(mode == TX_EN)
|
2016-09-12 21:44:30 +02:00
|
|
|
#ifdef DSM_BLUE
|
|
|
|
CYRF_WriteRegister(CYRF_0E_GPIO_CTRL,0x20); // XOUT=1, PACTL=0
|
|
|
|
else
|
|
|
|
CYRF_WriteRegister(CYRF_0E_GPIO_CTRL,0x80); // XOUT=0, PACTL=1
|
|
|
|
#else
|
2016-01-10 16:10:27 +01:00
|
|
|
CYRF_WriteRegister(CYRF_0E_GPIO_CTRL,0x80); // XOUT=1, PACTL=0
|
|
|
|
else
|
|
|
|
CYRF_WriteRegister(CYRF_0E_GPIO_CTRL,0x20); // XOUT=0, PACTL=1
|
2016-09-12 21:44:30 +02:00
|
|
|
#endif
|
2016-01-10 16:10:27 +01:00
|
|
|
}
|
2015-12-30 01:41:12 +01:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void CYRF_ConfigRFChannel(uint8_t ch)
|
|
|
|
{
|
|
|
|
CYRF_WriteRegister(CYRF_00_CHANNEL,ch);
|
|
|
|
}
|
|
|
|
|
Core and all protocols have been updated
Lot of changes in this new master
ChangeLog:
- Core: LED flashing when an invalid protocol has been selected
- Core: Channels 5 to 12 available as switches for all protocols: code
and size optimization
- Documentation (readme.md): fully updated, all protocols/sub
protocols/channels described, models example, many improvements
- All protocols have been updated in some way, here are some highlights:
* Bayang: added picture, video and inverted channels
* CG023->H8_3D: added light and calibration channels
* CX10: added sub protocols Q282, JC3015_1, JC3015_2, MK33041
* ESky: added new protocol - untested
* Hubsan: added compatibility with the new Hubsan Plus protocol
* KN: fully rewritten protocol: added sub protocols WLTOYS and FEILUN,
11 channels support
New version successfully tested on all my models: Flysky RX/F939/V911
protocol Flysky, Frsky RX protocol Frsky, Hubsan X4 protocol Hubsan,
Hisky HCP100/HCP80 protocol Hisky, HK-3000/HK3100 RX protocol
Hisky/HK310, XINXUN X39 protocol YD717/XINXUN, Symax X5C-1 protocol
SymaX/SYMAX, Cheerson CX-10A protocol CX10/BLUE, Eachine 3D-X4 protocol
CG023.
To access new protocols from er9x/ersky9x, you need to build a version
from this github repository https://github.com/pascallanger/mbtx based
on the latest er9x r820 and ersky9x r218.
2016-01-20 10:50:56 +01:00
|
|
|
/*
|
|
|
|
static void CYRF_SetPower_Value(uint8_t power)
|
2015-12-30 01:41:12 +01:00
|
|
|
{
|
|
|
|
uint8_t val = CYRF_ReadRegister(CYRF_03_TX_CFG) & 0xF8;
|
|
|
|
CYRF_WriteRegister(CYRF_03_TX_CFG, val | (power & 0x07));
|
|
|
|
}
|
Core and all protocols have been updated
Lot of changes in this new master
ChangeLog:
- Core: LED flashing when an invalid protocol has been selected
- Core: Channels 5 to 12 available as switches for all protocols: code
and size optimization
- Documentation (readme.md): fully updated, all protocols/sub
protocols/channels described, models example, many improvements
- All protocols have been updated in some way, here are some highlights:
* Bayang: added picture, video and inverted channels
* CG023->H8_3D: added light and calibration channels
* CX10: added sub protocols Q282, JC3015_1, JC3015_2, MK33041
* ESky: added new protocol - untested
* Hubsan: added compatibility with the new Hubsan Plus protocol
* KN: fully rewritten protocol: added sub protocols WLTOYS and FEILUN,
11 channels support
New version successfully tested on all my models: Flysky RX/F939/V911
protocol Flysky, Frsky RX protocol Frsky, Hubsan X4 protocol Hubsan,
Hisky HCP100/HCP80 protocol Hisky, HK-3000/HK3100 RX protocol
Hisky/HK310, XINXUN X39 protocol YD717/XINXUN, Symax X5C-1 protocol
SymaX/SYMAX, Cheerson CX-10A protocol CX10/BLUE, Eachine 3D-X4 protocol
CG023.
To access new protocols from er9x/ersky9x, you need to build a version
from this github repository https://github.com/pascallanger/mbtx based
on the latest er9x r820 and ersky9x r218.
2016-01-20 10:50:56 +01:00
|
|
|
*/
|
2015-12-30 01:41:12 +01:00
|
|
|
|
|
|
|
void CYRF_SetPower(uint8_t val)
|
|
|
|
{
|
|
|
|
uint8_t power=CYRF_BIND_POWER;
|
|
|
|
if(IS_BIND_DONE_on)
|
|
|
|
power=IS_POWER_FLAG_on?CYRF_HIGH_POWER:CYRF_LOW_POWER;
|
2016-01-02 13:51:16 +01:00
|
|
|
if(IS_RANGE_FLAG_on)
|
|
|
|
power=CYRF_RANGE_POWER;
|
2016-08-17 13:44:20 +02:00
|
|
|
power|=val;
|
2016-08-15 11:52:43 +02:00
|
|
|
if(prev_power != power)
|
|
|
|
{
|
2016-08-17 13:44:20 +02:00
|
|
|
CYRF_WriteRegister(CYRF_03_TX_CFG,power);
|
2016-08-15 11:52:43 +02:00
|
|
|
prev_power=power;
|
|
|
|
}
|
2015-12-30 01:41:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void CYRF_ConfigCRCSeed(uint16_t crc)
|
|
|
|
{
|
|
|
|
CYRF_WriteRegister(CYRF_15_CRC_SEED_LSB,crc & 0xff);
|
|
|
|
CYRF_WriteRegister(CYRF_16_CRC_SEED_MSB,crc >> 8);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* these are the recommended sop codes from Cyrpress
|
|
|
|
* See "WirelessUSB LP/LPstar and PRoC LP/LPstar Technical Reference Manual"
|
|
|
|
*/
|
|
|
|
void CYRF_ConfigSOPCode(const uint8_t *sopcodes)
|
|
|
|
{
|
|
|
|
//NOTE: This can also be implemented as:
|
|
|
|
//for(i = 0; i < 8; i++) WriteRegister)0x23, sopcodes[i];
|
|
|
|
CYRF_WriteRegisterMulti(CYRF_22_SOP_CODE, sopcodes, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CYRF_ConfigDataCode(const uint8_t *datacodes, uint8_t len)
|
|
|
|
{
|
|
|
|
//NOTE: This can also be implemented as:
|
|
|
|
//for(i = 0; i < len; i++) WriteRegister)0x23, datacodes[i];
|
|
|
|
CYRF_WriteRegisterMulti(CYRF_23_DATA_CODE, datacodes, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CYRF_WritePreamble(uint32_t preamble)
|
|
|
|
{
|
|
|
|
CYRF_CSN_off;
|
2016-08-01 21:57:18 +02:00
|
|
|
SPI_Write(0x80 | 0x24);
|
|
|
|
SPI_Write(preamble & 0xff);
|
|
|
|
SPI_Write((preamble >> 8) & 0xff);
|
|
|
|
SPI_Write((preamble >> 16) & 0xff);
|
2015-12-30 01:41:12 +01:00
|
|
|
CYRF_CSN_on;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
Core and all protocols have been updated
Lot of changes in this new master
ChangeLog:
- Core: LED flashing when an invalid protocol has been selected
- Core: Channels 5 to 12 available as switches for all protocols: code
and size optimization
- Documentation (readme.md): fully updated, all protocols/sub
protocols/channels described, models example, many improvements
- All protocols have been updated in some way, here are some highlights:
* Bayang: added picture, video and inverted channels
* CG023->H8_3D: added light and calibration channels
* CX10: added sub protocols Q282, JC3015_1, JC3015_2, MK33041
* ESky: added new protocol - untested
* Hubsan: added compatibility with the new Hubsan Plus protocol
* KN: fully rewritten protocol: added sub protocols WLTOYS and FEILUN,
11 channels support
New version successfully tested on all my models: Flysky RX/F939/V911
protocol Flysky, Frsky RX protocol Frsky, Hubsan X4 protocol Hubsan,
Hisky HCP100/HCP80 protocol Hisky, HK-3000/HK3100 RX protocol
Hisky/HK310, XINXUN X39 protocol YD717/XINXUN, Symax X5C-1 protocol
SymaX/SYMAX, Cheerson CX-10A protocol CX10/BLUE, Eachine 3D-X4 protocol
CG023.
To access new protocols from er9x/ersky9x, you need to build a version
from this github repository https://github.com/pascallanger/mbtx based
on the latest er9x r820 and ersky9x r218.
2016-01-20 10:50:56 +01:00
|
|
|
/*static void CYRF_ReadDataPacket(uint8_t dpbuffer[])
|
2015-12-30 01:41:12 +01:00
|
|
|
{
|
|
|
|
CYRF_ReadRegisterMulti(CYRF_21_RX_BUFFER, dpbuffer, 0x10);
|
|
|
|
}
|
Core and all protocols have been updated
Lot of changes in this new master
ChangeLog:
- Core: LED flashing when an invalid protocol has been selected
- Core: Channels 5 to 12 available as switches for all protocols: code
and size optimization
- Documentation (readme.md): fully updated, all protocols/sub
protocols/channels described, models example, many improvements
- All protocols have been updated in some way, here are some highlights:
* Bayang: added picture, video and inverted channels
* CG023->H8_3D: added light and calibration channels
* CX10: added sub protocols Q282, JC3015_1, JC3015_2, MK33041
* ESky: added new protocol - untested
* Hubsan: added compatibility with the new Hubsan Plus protocol
* KN: fully rewritten protocol: added sub protocols WLTOYS and FEILUN,
11 channels support
New version successfully tested on all my models: Flysky RX/F939/V911
protocol Flysky, Frsky RX protocol Frsky, Hubsan X4 protocol Hubsan,
Hisky HCP100/HCP80 protocol Hisky, HK-3000/HK3100 RX protocol
Hisky/HK310, XINXUN X39 protocol YD717/XINXUN, Symax X5C-1 protocol
SymaX/SYMAX, Cheerson CX-10A protocol CX10/BLUE, Eachine 3D-X4 protocol
CG023.
To access new protocols from er9x/ersky9x, you need to build a version
from this github repository https://github.com/pascallanger/mbtx based
on the latest er9x r820 and ersky9x r218.
2016-01-20 10:50:56 +01:00
|
|
|
*/
|
2016-04-06 12:57:42 +02:00
|
|
|
void CYRF_ReadDataPacketLen(uint8_t dpbuffer[], uint8_t length)
|
2015-12-30 01:41:12 +01:00
|
|
|
{
|
2016-04-06 12:57:42 +02:00
|
|
|
CYRF_ReadRegisterMulti(CYRF_21_RX_BUFFER, dpbuffer, length);
|
2015-12-30 01:41:12 +01:00
|
|
|
}
|
2016-04-06 12:57:42 +02:00
|
|
|
|
Core and all protocols have been updated
Lot of changes in this new master
ChangeLog:
- Core: LED flashing when an invalid protocol has been selected
- Core: Channels 5 to 12 available as switches for all protocols: code
and size optimization
- Documentation (readme.md): fully updated, all protocols/sub
protocols/channels described, models example, many improvements
- All protocols have been updated in some way, here are some highlights:
* Bayang: added picture, video and inverted channels
* CG023->H8_3D: added light and calibration channels
* CX10: added sub protocols Q282, JC3015_1, JC3015_2, MK33041
* ESky: added new protocol - untested
* Hubsan: added compatibility with the new Hubsan Plus protocol
* KN: fully rewritten protocol: added sub protocols WLTOYS and FEILUN,
11 channels support
New version successfully tested on all my models: Flysky RX/F939/V911
protocol Flysky, Frsky RX protocol Frsky, Hubsan X4 protocol Hubsan,
Hisky HCP100/HCP80 protocol Hisky, HK-3000/HK3100 RX protocol
Hisky/HK310, XINXUN X39 protocol YD717/XINXUN, Symax X5C-1 protocol
SymaX/SYMAX, Cheerson CX-10A protocol CX10/BLUE, Eachine 3D-X4 protocol
CG023.
To access new protocols from er9x/ersky9x, you need to build a version
from this github repository https://github.com/pascallanger/mbtx based
on the latest er9x r820 and ersky9x r218.
2016-01-20 10:50:56 +01:00
|
|
|
static void CYRF_WriteDataPacketLen(const uint8_t dpbuffer[], uint8_t len)
|
2015-12-30 01:41:12 +01:00
|
|
|
{
|
|
|
|
CYRF_WriteRegister(CYRF_01_TX_LENGTH, len);
|
|
|
|
CYRF_WriteRegister(CYRF_02_TX_CTRL, 0x40);
|
|
|
|
CYRF_WriteRegisterMulti(CYRF_20_TX_BUFFER, dpbuffer, len);
|
|
|
|
CYRF_WriteRegister(CYRF_02_TX_CTRL, 0xBF);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CYRF_WriteDataPacket(const uint8_t dpbuffer[])
|
|
|
|
{
|
|
|
|
CYRF_WriteDataPacketLen(dpbuffer, 16);
|
|
|
|
}
|
|
|
|
|
Core and all protocols have been updated
Lot of changes in this new master
ChangeLog:
- Core: LED flashing when an invalid protocol has been selected
- Core: Channels 5 to 12 available as switches for all protocols: code
and size optimization
- Documentation (readme.md): fully updated, all protocols/sub
protocols/channels described, models example, many improvements
- All protocols have been updated in some way, here are some highlights:
* Bayang: added picture, video and inverted channels
* CG023->H8_3D: added light and calibration channels
* CX10: added sub protocols Q282, JC3015_1, JC3015_2, MK33041
* ESky: added new protocol - untested
* Hubsan: added compatibility with the new Hubsan Plus protocol
* KN: fully rewritten protocol: added sub protocols WLTOYS and FEILUN,
11 channels support
New version successfully tested on all my models: Flysky RX/F939/V911
protocol Flysky, Frsky RX protocol Frsky, Hubsan X4 protocol Hubsan,
Hisky HCP100/HCP80 protocol Hisky, HK-3000/HK3100 RX protocol
Hisky/HK310, XINXUN X39 protocol YD717/XINXUN, Symax X5C-1 protocol
SymaX/SYMAX, Cheerson CX-10A protocol CX10/BLUE, Eachine 3D-X4 protocol
CG023.
To access new protocols from er9x/ersky9x, you need to build a version
from this github repository https://github.com/pascallanger/mbtx based
on the latest er9x r820 and ersky9x r218.
2016-01-20 10:50:56 +01:00
|
|
|
/*static uint8_t CYRF_ReadRSSI(uint8_t dodummyread)
|
2015-12-30 01:41:12 +01:00
|
|
|
{
|
|
|
|
uint8_t result;
|
|
|
|
if(dodummyread)
|
|
|
|
CYRF_ReadRegister(CYRF_13_RSSI);
|
|
|
|
result = CYRF_ReadRegister(CYRF_13_RSSI);
|
|
|
|
if(result & 0x80)
|
|
|
|
result = CYRF_ReadRegister(CYRF_13_RSSI);
|
|
|
|
return (result & 0x0F);
|
|
|
|
}
|
Core and all protocols have been updated
Lot of changes in this new master
ChangeLog:
- Core: LED flashing when an invalid protocol has been selected
- Core: Channels 5 to 12 available as switches for all protocols: code
and size optimization
- Documentation (readme.md): fully updated, all protocols/sub
protocols/channels described, models example, many improvements
- All protocols have been updated in some way, here are some highlights:
* Bayang: added picture, video and inverted channels
* CG023->H8_3D: added light and calibration channels
* CX10: added sub protocols Q282, JC3015_1, JC3015_2, MK33041
* ESky: added new protocol - untested
* Hubsan: added compatibility with the new Hubsan Plus protocol
* KN: fully rewritten protocol: added sub protocols WLTOYS and FEILUN,
11 channels support
New version successfully tested on all my models: Flysky RX/F939/V911
protocol Flysky, Frsky RX protocol Frsky, Hubsan X4 protocol Hubsan,
Hisky HCP100/HCP80 protocol Hisky, HK-3000/HK3100 RX protocol
Hisky/HK310, XINXUN X39 protocol YD717/XINXUN, Symax X5C-1 protocol
SymaX/SYMAX, Cheerson CX-10A protocol CX10/BLUE, Eachine 3D-X4 protocol
CG023.
To access new protocols from er9x/ersky9x, you need to build a version
from this github repository https://github.com/pascallanger/mbtx based
on the latest er9x r820 and ersky9x r218.
2016-01-20 10:50:56 +01:00
|
|
|
*/
|
2015-12-30 01:41:12 +01:00
|
|
|
//NOTE: This routine will reset the CRC Seed
|
|
|
|
void CYRF_FindBestChannels(uint8_t *channels, uint8_t len, uint8_t minspace, uint8_t min, uint8_t max)
|
|
|
|
{
|
|
|
|
#define NUM_FREQ 80
|
|
|
|
#define FREQ_OFFSET 4
|
|
|
|
uint8_t rssi[NUM_FREQ];
|
|
|
|
|
|
|
|
if (min < FREQ_OFFSET)
|
|
|
|
min = FREQ_OFFSET;
|
|
|
|
if (max > NUM_FREQ)
|
|
|
|
max = NUM_FREQ;
|
|
|
|
|
|
|
|
uint8_t i;
|
|
|
|
int8_t j;
|
|
|
|
memset(channels, 0, sizeof(uint8_t) * len);
|
|
|
|
CYRF_ConfigCRCSeed(0x0000);
|
|
|
|
CYRF_SetTxRxMode(RX_EN);
|
|
|
|
//Wait for pre-amp to switch from send to receive
|
2016-08-22 18:17:14 +02:00
|
|
|
delayMilliseconds(1);
|
2015-12-30 01:41:12 +01:00
|
|
|
for(i = 0; i < NUM_FREQ; i++)
|
|
|
|
{
|
|
|
|
CYRF_ConfigRFChannel(i);
|
2016-10-16 19:51:42 +02:00
|
|
|
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
|
|
|
|
delayMicroseconds(15);
|
|
|
|
CYRF_ReadRegister(CYRF_13_RSSI); //dummy read
|
|
|
|
delayMicroseconds(15); //The conversion can occur as often as once every 12us
|
|
|
|
}
|
|
|
|
rssi[i] = CYRF_ReadRegister(CYRF_13_RSSI)&0x1F;
|
2015-12-30 01:41:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
channels[i] = min;
|
|
|
|
for (j = min; j < max; j++)
|
|
|
|
if (rssi[j] < rssi[channels[i]])
|
|
|
|
channels[i] = j;
|
|
|
|
for (j = channels[i] - minspace; j < channels[i] + minspace; j++) {
|
|
|
|
//Ensure we don't reuse any channels within minspace of the selected channel again
|
|
|
|
if (j < 0 || j >= NUM_FREQ)
|
|
|
|
continue;
|
|
|
|
rssi[j] = 0xff;
|
|
|
|
}
|
|
|
|
}
|
2016-10-16 19:51:42 +02:00
|
|
|
CYRF_WriteRegister(CYRF_29_RX_ABORT, 0x20); // Abort RX operation
|
2015-12-30 01:41:12 +01:00
|
|
|
CYRF_SetTxRxMode(TX_EN);
|
2016-10-16 19:51:42 +02:00
|
|
|
CYRF_WriteRegister(CYRF_29_RX_ABORT, 0x20); // Clear abort RX
|
2015-12-30 01:41:12 +01:00
|
|
|
}
|
2016-09-04 16:47:34 +02:00
|
|
|
|
|
|
|
#if defined(DEVO_CYRF6936_INO) || defined(J6PRO_CYRF6936_INO)
|
|
|
|
const uint8_t PROGMEM DEVO_j6pro_sopcodes[][8] = {
|
|
|
|
/* Note these are in order transmitted (LSB 1st) */
|
|
|
|
{0x3C, 0x37, 0xCC, 0x91, 0xE2, 0xF8, 0xCC, 0x91},
|
|
|
|
{0x9B, 0xC5, 0xA1, 0x0F, 0xAD, 0x39, 0xA2, 0x0F},
|
|
|
|
{0xEF, 0x64, 0xB0, 0x2A, 0xD2, 0x8F, 0xB1, 0x2A},
|
|
|
|
{0x66, 0xCD, 0x7C, 0x50, 0xDD, 0x26, 0x7C, 0x50},
|
|
|
|
{0x5C, 0xE1, 0xF6, 0x44, 0xAD, 0x16, 0xF6, 0x44},
|
|
|
|
{0x5A, 0xCC, 0xAE, 0x46, 0xB6, 0x31, 0xAE, 0x46},
|
|
|
|
{0xA1, 0x78, 0xDC, 0x3C, 0x9E, 0x82, 0xDC, 0x3C},
|
|
|
|
{0xB9, 0x8E, 0x19, 0x74, 0x6F, 0x65, 0x18, 0x74},
|
|
|
|
{0xDF, 0xB1, 0xC0, 0x49, 0x62, 0xDF, 0xC1, 0x49},
|
|
|
|
{0x97, 0xE5, 0x14, 0x72, 0x7F, 0x1A, 0x14, 0x72},
|
|
|
|
#if defined(J6PRO_CYRF6936_INO)
|
|
|
|
{0x82, 0xC7, 0x90, 0x36, 0x21, 0x03, 0xFF, 0x17},
|
|
|
|
{0xE2, 0xF8, 0xCC, 0x91, 0x3C, 0x37, 0xCC, 0x91}, //Note: the '03' was '9E' in the Cypress recommended table
|
|
|
|
{0xAD, 0x39, 0xA2, 0x0F, 0x9B, 0xC5, 0xA1, 0x0F}, //The following are the same as the 1st 8 above,
|
|
|
|
{0xD2, 0x8F, 0xB1, 0x2A, 0xEF, 0x64, 0xB0, 0x2A}, //but with the upper and lower word swapped
|
|
|
|
{0xDD, 0x26, 0x7C, 0x50, 0x66, 0xCD, 0x7C, 0x50},
|
|
|
|
{0xAD, 0x16, 0xF6, 0x44, 0x5C, 0xE1, 0xF6, 0x44},
|
|
|
|
{0xB6, 0x31, 0xAE, 0x46, 0x5A, 0xCC, 0xAE, 0x46},
|
|
|
|
{0x9E, 0x82, 0xDC, 0x3C, 0xA1, 0x78, 0xDC, 0x3C},
|
|
|
|
{0x6F, 0x65, 0x18, 0x74, 0xB9, 0x8E, 0x19, 0x74},
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
static void __attribute__((unused)) CYRF_PROGMEM_ConfigSOPCode(const uint8_t *data)
|
|
|
|
{
|
|
|
|
uint8_t code[8];
|
|
|
|
for(uint8_t i=0;i<8;i++)
|
|
|
|
code[i]=pgm_read_byte_near(&data[i]);
|
|
|
|
CYRF_ConfigSOPCode(code);
|
2016-10-16 19:51:42 +02:00
|
|
|
}
|
|
|
|
#endif
|