Library for communicating with a Hubsan X4 quad

Dependencies:   A7105TxRx

Committer:
d34d
Date:
Thu Jan 01 19:31:19 2015 +0000
Revision:
1:3dec63fe89f4
Parent:
0:85bb69ce74b4
Update A7105 library head

Who changed what in which revision?

UserRevisionLine numberNew contents of line
d34d 0:85bb69ce74b4 1 #ifndef _HUBSAN_X4_TX
d34d 0:85bb69ce74b4 2 #define _HUBSAN_X4_TX
d34d 0:85bb69ce74b4 3
d34d 0:85bb69ce74b4 4 #include "A7105.h"
d34d 0:85bb69ce74b4 5
d34d 0:85bb69ce74b4 6 enum{
d34d 0:85bb69ce74b4 7 FLAG_VIDEO= 0x01, // record video
d34d 0:85bb69ce74b4 8 FLAG_FLIP = 0x08, // enable flips
d34d 0:85bb69ce74b4 9 FLAG_LED = 0x04 // enable LEDs
d34d 0:85bb69ce74b4 10 };
d34d 0:85bb69ce74b4 11
d34d 0:85bb69ce74b4 12 static const uint8_t kAllowedChannels[] =
d34d 0:85bb69ce74b4 13 {0x14, 0x1E, 0x28, 0x32, 0x3C, 0x46, 0x50, 0x5A, 0x64, 0x6E, 0x78, 0x82};
d34d 0:85bb69ce74b4 14 static const uint32_t kTxId = 0xDB042679;
d34d 0:85bb69ce74b4 15
d34d 0:85bb69ce74b4 16 /**
d34d 0:85bb69ce74b4 17 * Class for communicating with a Hubsan X4 using the A7105TxRx library
d34d 0:85bb69ce74b4 18 *
d34d 0:85bb69ce74b4 19 * Example:
d34d 0:85bb69ce74b4 20 * @code
d34d 0:85bb69ce74b4 21 * #include "mbed.h"
d34d 0:85bb69ce74b4 22 * #include "HubsanTx.h"
d34d 0:85bb69ce74b4 23 *
d34d 0:85bb69ce74b4 24 * #define A7105_SPI_FREQUENCY 10000000 // 10MHz
d34d 0:85bb69ce74b4 25 *
d34d 0:85bb69ce74b4 26 * HubsanTx hubsan(D4, D5, D3, D6, A7105_SPI_FREQUENCY);
d34d 0:85bb69ce74b4 27 *
d34d 0:85bb69ce74b4 28 * int main() {
d34d 0:85bb69ce74b4 29 * // init
d34d 0:85bb69ce74b4 30 * hubsan.init();
d34d 0:85bb69ce74b4 31 * }
d34d 0:85bb69ce74b4 32 * @endcode
d34d 0:85bb69ce74b4 33 */
d34d 0:85bb69ce74b4 34 class HubsanTx : public A7105 {
d34d 0:85bb69ce74b4 35 public:
d34d 0:85bb69ce74b4 36 /**
d34d 0:85bb69ce74b4 37 * @param mosi Pin used to transmit data to the slave
d34d 0:85bb69ce74b4 38 * @param miso Pin used to receive data from the slave
d34d 0:85bb69ce74b4 39 * @param clk Pin used for the clock
d34d 0:85bb69ce74b4 40 * @param cs Pin used for the chip select
d34d 0:85bb69ce74b4 41 * @param freqHz Frequency used to clock data in and out
d34d 0:85bb69ce74b4 42 */
d34d 0:85bb69ce74b4 43 HubsanTx(PinName mosi, PinName miso, PinName clk, PinName cs, uint32_t freqHz);
d34d 0:85bb69ce74b4 44
d34d 0:85bb69ce74b4 45 /**
d34d 0:85bb69ce74b4 46 * Initialize the A7105 to communicate with a Hubsan X4
d34d 0:85bb69ce74b4 47 */
d34d 0:85bb69ce74b4 48 int8_t init();
d34d 0:85bb69ce74b4 49
d34d 0:85bb69ce74b4 50 private:
d34d 0:85bb69ce74b4 51 uint8_t _packet[16];
d34d 0:85bb69ce74b4 52 uint8_t _channel;
d34d 0:85bb69ce74b4 53 uint32_t _sessionId;
d34d 0:85bb69ce74b4 54 uint8_t _state;
d34d 0:85bb69ce74b4 55 uint8_t _packetCount;
d34d 0:85bb69ce74b4 56 };
d34d 0:85bb69ce74b4 57
d34d 0:85bb69ce74b4 58 #endif // _HUBSAN_X4_TX