Shuto Naruse
/
Eurobot_2012_Secondary
Eurobot_2012_Secondary
Embed:
(wiki syntax)
Show/hide line numbers
RF12B.h
00001 #ifndef _RF12B_H 00002 #define _RF12B_H 00003 00004 #include "mbed.h" 00005 #include <queue> 00006 00007 enum rfmode_t{RX, TX}; 00008 00009 class RF12B { 00010 public: 00011 /* Constructor */ 00012 RF12B(PinName SDI, 00013 PinName SDO, 00014 PinName SCK, 00015 PinName NCS, 00016 PinName NIRQ); 00017 00018 00019 /* Reads a packet of data. Returns false if read failed. Use available() to check how much space to allocate for buffer */ 00020 bool read(unsigned char* data, unsigned int size); 00021 00022 /* Reads a byte of data from the receive buffer 00023 Returns 0xFF if there is no data */ 00024 unsigned char read(); 00025 00026 /* Transmits a packet of data */ 00027 void write(unsigned char* data, unsigned char length); 00028 void write(unsigned char data); /* 1-byte packet */ 00029 void write(std::queue<char> &data, int length = -1); /* sends a whole queue */ 00030 00031 /* Returns the packet length if data is available in the receive buffer, 0 otherwise*/ 00032 unsigned int available(); 00033 00034 protected: 00035 /* Receive FIFO buffer */ 00036 std::queue<unsigned char> fifo; 00037 std::queue<unsigned char> temp; //for storing stuff mid-packet 00038 00039 /* SPI module */ 00040 SPI spi; 00041 00042 /* Other digital pins */ 00043 DigitalOut NCS; 00044 InterruptIn NIRQ; 00045 DigitalIn NIRQ_in; 00046 //DigitalOut rfled; 00047 00048 rfmode_t mode; 00049 00050 /* Initialises the RF12B module */ 00051 void init(); 00052 00053 /* Write a command to the RF Module */ 00054 unsigned int writeCmd(unsigned int cmd); 00055 00056 /* Sends a byte of data across RF */ 00057 void send(unsigned char data); 00058 00059 /* Switch module between receive and transmit modes */ 00060 void changeMode(rfmode_t mode); 00061 00062 /* Interrupt routine for data reception */ 00063 void rxISR(); 00064 00065 /* Tell the RF Module this packet is received and wait for the next */ 00066 void resetRX(); 00067 00068 /* Return the RF Module Status word */ 00069 unsigned int status(); 00070 00071 /* Calculate CRC8 */ 00072 unsigned char crc8(unsigned char crc, unsigned char data); 00073 }; 00074 00075 #endif /* _RF12B_H */
Generated on Sat Jul 16 2022 01:26:17 by 1.7.2