working version with calibration done

Fork of Eurobot2013 by Oskar Weigl

Committer:
xiaxia686
Date:
Tue Apr 09 15:32:47 2013 +0000
Revision:
11:5ba926692210
Parent:
10:2bd9f4e02b74
woking version (calibrated)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sv 1:6799c07fe510 1 #ifndef _RF12B_H
sv 1:6799c07fe510 2 #define _RF12B_H
sv 1:6799c07fe510 3
sv 1:6799c07fe510 4 #include "mbed.h"
sv 1:6799c07fe510 5 //#include <queue>
sv 1:6799c07fe510 6
sv 1:6799c07fe510 7 enum rfmode_t{RX, TX};
sv 1:6799c07fe510 8
sv 1:6799c07fe510 9 class DummyCT;
sv 1:6799c07fe510 10
sv 1:6799c07fe510 11 class RF12B {
sv 1:6799c07fe510 12 public:
sv 1:6799c07fe510 13 /* Constructor */
sv 1:6799c07fe510 14 RF12B(PinName SDI,
sv 1:6799c07fe510 15 PinName SDO,
sv 1:6799c07fe510 16 PinName SCK,
sv 1:6799c07fe510 17 PinName NCS,
sv 1:6799c07fe510 18 PinName NIRQ);
sv 1:6799c07fe510 19
sv 1:6799c07fe510 20
sv 1:6799c07fe510 21
sv 1:6799c07fe510 22 /* Reads a packet of data. Returns false if read failed. Use available() to check how much space to allocate for buffer */
sv 1:6799c07fe510 23 bool read(unsigned char* data, unsigned int size);
sv 1:6799c07fe510 24
sv 1:6799c07fe510 25 /* Reads a byte of data from the receive buffer
sv 1:6799c07fe510 26 Returns 0xFF if there is no data */
sv 1:6799c07fe510 27 unsigned char read();
sv 1:6799c07fe510 28
sv 1:6799c07fe510 29 /* Transmits a packet of data */
sv 1:6799c07fe510 30 void write(unsigned char* data, unsigned char length);
sv 1:6799c07fe510 31 void write(unsigned char data); /* 1-byte packet */
sv 1:6799c07fe510 32 // void write(std::queue<char> &data, int length = -1); /* sends a whole queue */
sv 1:6799c07fe510 33
sv 1:6799c07fe510 34 /* Returns the packet length if data is available in the receive buffer, 0 otherwise*/
sv 1:6799c07fe510 35 unsigned int available();
sv 1:6799c07fe510 36
sv 1:6799c07fe510 37 /** A assigns a callback function when a new reading is available **/
sv 1:6799c07fe510 38 void (*callbackfunc)(unsigned char rx_code);
sv 1:6799c07fe510 39 DummyCT* callbackobj;
sv 1:6799c07fe510 40 void (DummyCT::*mcallbackfunc)(unsigned char rx_code);
sv 1:6799c07fe510 41
sv 1:6799c07fe510 42 protected:
sv 1:6799c07fe510 43 /* Receive FIFO buffer */
sv 1:6799c07fe510 44 // std::queue<unsigned char> fifo;
sv 1:6799c07fe510 45 // std::queue<unsigned char> temp; //for storing stuff mid-packet
sv 1:6799c07fe510 46
sv 1:6799c07fe510 47 /* SPI module */
sv 1:6799c07fe510 48 SPI spi;
sv 1:6799c07fe510 49
sv 1:6799c07fe510 50 /* Other digital pins */
sv 1:6799c07fe510 51 DigitalOut NCS;
sv 1:6799c07fe510 52 InterruptIn NIRQ;
sv 1:6799c07fe510 53 DigitalIn NIRQ_in;
sv 1:6799c07fe510 54 //DigitalOut rfled;
sv 1:6799c07fe510 55
sv 1:6799c07fe510 56 rfmode_t mode;
sv 1:6799c07fe510 57
sv 1:6799c07fe510 58 /* Initialises the RF12B module */
sv 1:6799c07fe510 59 void init();
sv 1:6799c07fe510 60
sv 1:6799c07fe510 61 /* Write a command to the RF Module */
sv 1:6799c07fe510 62 unsigned int writeCmd(unsigned int cmd);
sv 1:6799c07fe510 63
sv 1:6799c07fe510 64 /* Sends a byte of data across RF */
sv 1:6799c07fe510 65 void send(unsigned char data);
sv 1:6799c07fe510 66
sv 1:6799c07fe510 67 /* Switch module between receive and transmit modes */
sv 1:6799c07fe510 68 void changeMode(rfmode_t mode);
sv 1:6799c07fe510 69
sv 1:6799c07fe510 70 /* Interrupt routine for data reception */
sv 1:6799c07fe510 71 void rxISR();
sv 1:6799c07fe510 72
sv 1:6799c07fe510 73 /* Tell the RF Module this packet is received and wait for the next */
sv 1:6799c07fe510 74 void resetRX();
sv 1:6799c07fe510 75
sv 1:6799c07fe510 76 /* Return the RF Module Status word */
sv 1:6799c07fe510 77 unsigned int status();
sv 1:6799c07fe510 78
sv 1:6799c07fe510 79 /* Calculate CRC8 */
sv 1:6799c07fe510 80 unsigned char crc8(unsigned char crc, unsigned char data);
sv 1:6799c07fe510 81 };
sv 1:6799c07fe510 82
sv 1:6799c07fe510 83 #endif /* _RF12B_H */