Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Spektrum.h
00001 /* 00002 Spektrum.h 00003 Spektrum serial receiver mbed library 00004 Dennis Evangelista, 2018 00005 */ 00006 00007 #ifndef SPEKTRUM_H 00008 #define SPEKTRUM_H 00009 #define SPEKTRUM_VERSION "1.0.1" 00010 00011 #include "mbed.h" 00012 #include "rtos.h" 00013 00014 // bind modes 00015 #define SPEKTRUM_INT_DSMX_22MS 7 00016 #define SPEKTRUM_EXT_DSMX_22MS 8 00017 #define SPEKTRUM_INT_DSMX_11MS 9 00018 #define SPEKTRUM_EXT_DSMX_11MS 10 00019 // DSM2 bind modes not recommended, not implemented 00020 // EXT(ernal) bind modes don't really work on solitary satellite receiver 00021 00022 // field definitions 00023 // #define SPEKTRUM_MASK_1024_CHANID 0xfc00 00024 // #define SPEKTRUM_MASK_1024_SXPOS 0x03ff 00025 // first two only used in DSM2 which are not implemented 00026 #define SPEKTRUM_MASK_2048_CHANID 0x7800 00027 #define SPEKTRUM_MASK_2048_CHANID_MSB 0x78 00028 #define SPEKTRUM_MASK_2048_SXPOS 0x07ff 00029 00030 // allowable system field values 00031 // #define SPEKTRUM_22MS_1024_DSM2 0x01 00032 // #define SPEKTRUM_11MS_2048_DSM2 0x12 00033 #define SPEKTRUM_22MS_2048_DSMX 0xa2 00034 #define SPEKTRUM_11MS_2048_DSMX 0xb2 00035 00036 #define SPEKTRUM_BAUD 115200 00037 // Spektrum baud is supposed to be 125000, but the LPC1768 seems not 00038 // to support nonstandard baud rates. 00039 00040 #define SPEKTRUM_SERVOS 7 00041 #define SPEKTRUM_PACKET_SIZE 16 00042 #define SPEKTRUM_CHANNELS 16 00043 #define SPEKTRUM_COUNT2US(x) (x*600/1024+900) 00044 00045 00046 00047 00048 /** Spektrum receiver object for connecting to eg SPM9745 receiver 00049 */ 00050 class Spektrum 00051 { 00052 public: 00053 /** Number of fades (failed packets) from receiver */ 00054 unsigned int fades; 00055 00056 /** Tells if system is in DSMX 11ms or 22ms for example */ 00057 unsigned int system; 00058 00059 /** Contains 0-2048 values for all channels 0-15 */ 00060 unsigned int channel[SPEKTRUM_CHANNELS]; 00061 00062 /** Contains approx 900-2100us pulsewidths corresponding to chan 0-15 */ 00063 unsigned int pulsewidth[SPEKTRUM_CHANNELS]; 00064 00065 /** If true, data is value */ 00066 bool valid; // TODO switch to EventFlags? 00067 00068 /** 11 or 22 ms */ 00069 unsigned int period_ms; 00070 00071 Spektrum(PinName tx, PinName rx); // constructor 00072 ~Spektrum(); // destructor 00073 00074 private: 00075 UARTSerial _rx; 00076 unsigned char _buf[SPEKTRUM_PACKET_SIZE]; 00077 Thread _packet_thread; 00078 void _packet_callback(void); 00079 }; 00080 00081 00082 00083 00084 00085 00086 00087 /** For binding a Spektrum receiver to transmitter */ 00088 class BindPlug 00089 { 00090 public: 00091 /** e.g. SPEKTRUM_INT_DSMX_11MS, SPEKTRUM_INT_DSMX_22MS */ 00092 int mode; 00093 00094 BindPlug(PinName tx, PinName rx, int mode = SPEKTRUM_INT_DSMX_11MS); 00095 ~BindPlug(); 00096 void bind(); 00097 00098 private: 00099 DigitalOut _3Vpin; 00100 DigitalOut _datapin; 00101 }; 00102 00103 /* LATER 00104 class SpektrumTestDevice{ 00105 public: 00106 unsigned int fades; 00107 unsigned int servo[7]; 00108 SpektrumTestDevice(PinName tx, PinName rx); 00109 ~SpektrumTestDevice(); 00110 private: 00111 Serial _receiver; 00112 }; 00113 */ 00114 00115 #endif
Generated on Thu Jul 14 2022 02:38:29 by
