FLYSKY RC receiver compatible with TH9X transmitter. Uses an A7105-CL or A7105-SY 2.4Ghz module.
Dependents: A7105_FLYSKY_RX_WITH_PPM
A7105_FLYSKY_RX.h
- Committer:
- pebayle
- Date:
- 2015-11-13
- Revision:
- 3:19d3601a7744
- Parent:
- 0:01963ae1d0c4
File content as of revision 3:19d3601a7744:
#ifndef A7105_FLYSKY_RX_H #define A7105_FLYSKY_RX_H #define NO_ERROR 0 #define TIME_OUT_ERROR 1 #define VALIDITY_ERROR 2 #define TX_ID_ERROR 3 //flysky protocol id = 0x2AC57554 static const unsigned char flysky_id[4] = { 0x54, 0x75, 0xC5, 0x2A }; //low byte first //default tx id static const unsigned char default_tx_id[4] = { 0x06, 0x00, 0x00, 0x30 }; //low byte first (small quadcopter) //static const unsigned char default_tx_id[4] = { 0xB2, 0xA1, 0x00, 0x00 }; //low byte first (TH9X module) //A7105 register values (0xFF = don't modify register value) static const unsigned char A7105_regs_val[] = { 0xFF, 0x42, 0x00, 0x14, 0x00, 0xFF, 0xFF ,0x00, 0x00, 0x00, 0x00, 0x19, 0x01, 0x05, 0x00, 0x50, //GIO1 Pin Control Register @0x0B = 0x19 - 4 wire dialog spi, miso on pin GIO1 0x9e, 0x4b, 0x00, 0x02, 0x16, 0x2b, 0x12, 0x00, 0x62, 0x80, 0x80, 0x00, 0x0a, 0x32, 0xc3, 0x0f, 0x13, 0xc3, 0x00, 0xFF, 0x00, 0x00, 0x3b, 0x00, 0x17, 0x47, 0x80, 0x03, 0x01, 0x45, 0x18, 0x00, 0x01, 0x0f, 0xFF, }; //A7105 TX channel number table (for RX substract 1) static const unsigned char A7105_tx_channels[16][16] = { {0x0a, 0x5a, 0x14, 0x64, 0x1e, 0x6e, 0x28, 0x78, 0x32, 0x82, 0x3c, 0x8c, 0x46, 0x96, 0x50, 0xa0}, {0xa0, 0x50, 0x96, 0x46, 0x8c, 0x3c, 0x82, 0x32, 0x78, 0x28, 0x6e, 0x1e, 0x64, 0x14, 0x5a, 0x0a}, {0x0a, 0x5a, 0x50, 0xa0, 0x14, 0x64, 0x46, 0x96, 0x1e, 0x6e, 0x3c, 0x8c, 0x28, 0x78, 0x32, 0x82}, {0x82, 0x32, 0x78, 0x28, 0x8c, 0x3c, 0x6e, 0x1e, 0x96, 0x46, 0x64, 0x14, 0xa0, 0x50, 0x5a, 0x0a}, {0x28, 0x78, 0x0a, 0x5a, 0x50, 0xa0, 0x14, 0x64, 0x1e, 0x6e, 0x3c, 0x8c, 0x32, 0x82, 0x46, 0x96}, {0x96, 0x46, 0x82, 0x32, 0x8c, 0x3c, 0x6e, 0x1e, 0x64, 0x14, 0xa0, 0x50, 0x5a, 0x0a, 0x78, 0x28}, {0x50, 0xa0, 0x28, 0x78, 0x0a, 0x5a, 0x1e, 0x6e, 0x3c, 0x8c, 0x32, 0x82, 0x46, 0x96, 0x14, 0x64}, {0x64, 0x14, 0x96, 0x46, 0x82, 0x32, 0x8c, 0x3c, 0x6e, 0x1e, 0x5a, 0x0a, 0x78, 0x28, 0xa0, 0x50}, {0x50, 0xa0, 0x46, 0x96, 0x3c, 0x8c, 0x28, 0x78, 0x0a, 0x5a, 0x32, 0x82, 0x1e, 0x6e, 0x14, 0x64}, {0x64, 0x14, 0x6e, 0x1e, 0x82, 0x32, 0x5a, 0x0a, 0x78, 0x28, 0x8c, 0x3c, 0x96, 0x46, 0xa0, 0x50}, {0x46, 0x96, 0x3c, 0x8c, 0x50, 0xa0, 0x28, 0x78, 0x0a, 0x5a, 0x1e, 0x6e, 0x32, 0x82, 0x14, 0x64}, {0x64, 0x14, 0x82, 0x32, 0x6e, 0x1e, 0x5a, 0x0a, 0x78, 0x28, 0xa0, 0x50, 0x8c, 0x3c, 0x96, 0x46}, {0x46, 0x96, 0x0a, 0x5a, 0x3c, 0x8c, 0x14, 0x64, 0x50, 0xa0, 0x28, 0x78, 0x1e, 0x6e, 0x32, 0x82}, {0x82, 0x32, 0x6e, 0x1e, 0x78, 0x28, 0xa0, 0x50, 0x64, 0x14, 0x8c, 0x3c, 0x5a, 0x0a, 0x96, 0x46}, {0x46, 0x96, 0x0a, 0x5a, 0x50, 0xa0, 0x3c, 0x8c, 0x28, 0x78, 0x1e, 0x6e, 0x32, 0x82, 0x14, 0x64}, {0x64, 0x14, 0x82, 0x32, 0x6e, 0x1e, 0x78, 0x28, 0x8c, 0x3c, 0xa0, 0x50, 0x5a, 0x0a, 0x96, 0x46}, }; class A7105_flysky_RX { public: //constructor, uses SPI, DigitalIn, DigitalOut class A7105_flysky_RX(PinName SDIO, PinName GIO1, PinName SCK, PinName CS, PinName GIO2, PinName LED); //var unsigned short int servoPulseDur[8]; // servo pulse duration (1000->2000), 8x2 bytes unsigned char txId[4]; // expected tx id, 4x1bytes, low byte first unsigned char packetTxId[4]; //tx id in current packet //function bool init(); //init A7105 chip bool bind(); //bind TX and update txId with TX id if succeed, or default txid if failed unsigned char waitPacket(); //wait next packet (1.46ms) or timeOut (1.5ms) private: //A7105 dialog SPI _spi; //spi(mosi, miso, sck) DigitalOut _cs; //CS A7105 DigitalIn _waitRx; //Wait Rx A7105 DigitalOut _statusLed; //status led: FLASH = bind process, ON = rx ok, OFF = no rx //var Timer timer; //"wait packet" timeout timer 1.5ms unsigned short int packetServoPulseDur[8]; //servo pulse duration in current packet (1000->2000) unsigned char channelCnt; //A7105 channel counter (0->15) unsigned char channelOffset; //channel offset //function void writeCmd(unsigned char cmd); void writeRegVal(unsigned char regAddr, unsigned char regVal); unsigned char readReg(unsigned char regAddr); void readPacket(void); }; #endif