Programm for decoding radio-signals sent by a ETH-Window-Shutter-Contact, received with a RFM12B-module

Dependencies:   TextLCD mbed

Committer:
charly
Date:
Thu Apr 07 19:54:09 2011 +0000
Revision:
1:fc72e0bdb693
Parent:
0:96794c9fc5a3
Reorganized and created classes for RFM12B and ETH-Comfort

Who changed what in which revision?

UserRevisionLine numberNew contents of line
charly 0:96794c9fc5a3 1 #ifndef rfm12B_H
charly 0:96794c9fc5a3 2 #define rfm12B_H
charly 0:96794c9fc5a3 3
charly 0:96794c9fc5a3 4 #include <mbed.h>
charly 0:96794c9fc5a3 5
charly 1:fc72e0bdb693 6 /*!
charly 1:fc72e0bdb693 7 * \file rfm12b.h
charly 1:fc72e0bdb693 8 * \brief class for rfm2b in rawmode - only receive part implemented
charly 1:fc72e0bdb693 9 * \author Karl Zweimüller based on code from WED 6.9.2009
charly 1:fc72e0bdb693 10 */
charly 1:fc72e0bdb693 11
charly 0:96794c9fc5a3 12 typedef unsigned char Byte; // used to be uint8_t : something a byte wide, whatever ....
charly 0:96794c9fc5a3 13
charly 0:96794c9fc5a3 14 /** This Class handles a rfm12b transceiver
charly 0:96794c9fc5a3 15 * see http://www.hoperf.com/rf_fsk/rfm12b.htm
charly 1:fc72e0bdb693 16 *
charly 0:96794c9fc5a3 17 */
charly 1:fc72e0bdb693 18 class rfm12b {
charly 0:96794c9fc5a3 19 public:
charly 0:96794c9fc5a3 20 /** Create a rfm12b object
charly 0:96794c9fc5a3 21 *
charly 0:96794c9fc5a3 22 * @param mosi SPI-Interface. One of the 2 PSI-Interfaces of mbed. Pin p5 or p11
charly 0:96794c9fc5a3 23 * @param miso SPI-Interface. One of the 2 PSI-Interfaces of mbed. Pin p6 or p12
charly 0:96794c9fc5a3 24 * @param sclk SPI-Interface. One of the 2 PSI-Interfaces of mbed. Pin p7 or p13
charly 0:96794c9fc5a3 25 * @param nsel Chip-Select. A Digial Output of mbed
charly 0:96794c9fc5a3 26 * @param rxdata Data-Pin for received data. A DigitalIn of mbed
charly 0:96794c9fc5a3 27 */
charly 0:96794c9fc5a3 28 rfm12b(PinName mosi, PinName miso, PinName sclk, PinName nsel, PinName rxdata);
charly 1:fc72e0bdb693 29
charly 0:96794c9fc5a3 30 /** init the spi-interface
charly 0:96794c9fc5a3 31 */
charly 0:96794c9fc5a3 32 void init_spi();
charly 1:fc72e0bdb693 33
charly 0:96794c9fc5a3 34 /** initialize the device
charly 0:96794c9fc5a3 35 */
charly 0:96794c9fc5a3 36 void RFM_init(void);
charly 1:fc72e0bdb693 37
charly 0:96794c9fc5a3 38 /** write and read 16 bit
charly 0:96794c9fc5a3 39 */
charly 0:96794c9fc5a3 40 uint16_t rfm_spi16(uint16_t outval);
charly 0:96794c9fc5a3 41
charly 0:96794c9fc5a3 42 /** attach a function to be called when the data-pin changes from 0->1 and from 1->0
charly 0:96794c9fc5a3 43 * this function has to do all the decoding
charly 0:96794c9fc5a3 44 * keep this function short, as no interrrupts can occour within
charly 0:96794c9fc5a3 45 *
charly 0:96794c9fc5a3 46 * @param fptr Pointer to callback-function
charly 0:96794c9fc5a3 47 */
charly 0:96794c9fc5a3 48 void attachISR(void (*fptr)(void)) {
charly 0:96794c9fc5a3 49 m_pinRXData->fall(fptr);
charly 0:96794c9fc5a3 50 m_pinRXData->rise(fptr);
charly 0:96794c9fc5a3 51 }
charly 0:96794c9fc5a3 52
charly 1:fc72e0bdb693 53 template<typename T>
charly 1:fc72e0bdb693 54 /** attach an object member function to be called when the data-pin changes from 0->1 and from 1->0
charly 1:fc72e0bdb693 55 *
charly 1:fc72e0bdb693 56 * @param tptr pointer to object
charly 1:fc72e0bdb693 57 * @param mprt pointer ro member function
charly 1:fc72e0bdb693 58 *
charly 1:fc72e0bdb693 59 */
charly 1:fc72e0bdb693 60 void attachISR(T* tptr, void (T::*mptr)(void)) {
charly 1:fc72e0bdb693 61 if ((mptr != NULL) && (tptr != NULL)) {
charly 1:fc72e0bdb693 62 m_pinRXData->fall(tptr, mptr);
charly 1:fc72e0bdb693 63 m_pinRXData->rise(tptr, mptr);
charly 1:fc72e0bdb693 64 }
charly 1:fc72e0bdb693 65 }
charly 1:fc72e0bdb693 66
charly 1:fc72e0bdb693 67
charly 0:96794c9fc5a3 68
charly 0:96794c9fc5a3 69 private:
charly 0:96794c9fc5a3 70
charly 1:fc72e0bdb693 71
charly 0:96794c9fc5a3 72 DigitalOut *cs; //chipselect
charly 0:96794c9fc5a3 73 InterruptIn *m_pinRXData; //rx data pin
charly 0:96794c9fc5a3 74 SPI *rfm12b_spi; //spi-interface
charly 1:fc72e0bdb693 75
charly 0:96794c9fc5a3 76
charly 0:96794c9fc5a3 77 };
charly 0:96794c9fc5a3 78
charly 0:96794c9fc5a3 79 #endif