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