diff --git a/config.in b/config.in index 0f7f25f..1e9ea90 100644 --- a/config.in +++ b/config.in @@ -37,6 +37,11 @@ source scrolltext/config.in ############################################################################### +### RFM12 Menu ################################################################ +source rfm12/config.in +############################################################################### + + ### Joystick Menu ############################################################# source joystick/config.in ############################################################################### diff --git a/joystick/Makefile b/joystick/Makefile index fd3ab07..2064fc8 100644 --- a/joystick/Makefile +++ b/joystick/Makefile @@ -11,5 +11,8 @@ endif ifeq ($(PARALLEL_JOYSTICK_SUPPORT), y) SRC = joystick.c endif +ifeq ($(RFM12_JOYSTICK_SUPPORT), y) + SRC = rfm12_joystick.c +endif include $(TOPDIR)/rules.mk diff --git a/joystick/config.in b/joystick/config.in index 2cc99dc..44cc585 100644 --- a/joystick/config.in +++ b/joystick/config.in @@ -1,7 +1,6 @@ dep_bool_menu "joystick support" JOYSTICK_SUPPORT y if [ "$JOYSTICK_SUPPORT" = "y" ]; then -PARALLEL_JOYSTICK_SUPPORT=y ###################### Parallel joystick menu ################################# dep_bool_menu "parallel joystick support" PARALLEL_JOYSTICK_SUPPORT y @@ -163,6 +162,12 @@ PARALLEL_JOYSTICK_SUPPORT=y endmenu ############################################################################### +###################### RFM12 joystick menu #################################### + dep_bool_menu "RFM12 Joystick support" RFM12_JOYSTICK_SUPPORT y + + endmenu + + fi endmenu diff --git a/joystick/joystick.c b/joystick/joystick.c index 82ca646..c0cec79 100644 --- a/joystick/joystick.c +++ b/joystick/joystick.c @@ -4,9 +4,6 @@ #include "joystick.h" #include -unsigned char waitForFire; - - inline void joy_init(){ PORT_FROM_PIN(JOYSTICK_PIN_UP ) |= (1< + +#include "rfm12.h" + +volatile uint8_t rfm12_joystick_val; + +void borg_rfm12_tick(){ + if (rfm12_rx_status() == STATUS_COMPLETE) + { + + //uart_putstr ("new packet:\r\n"); + + uint8_t * bufp = rfm12_rx_buffer(); + + // dump buffer contents to uart + if(rfm12_rx_len() >= 1){ + //-> F2 F1 RT LF DN UP + + rfm12_joystick_val = *bufp; + } + + // tell the implementation that the buffer + // can be reused for the next data. + rfm12_rx_clear(); + } + + rfm12_tick(); + +} + +void borg_rfm12_init(){ + rfm12_init(); +} diff --git a/rfm12/borg_rfm12.h b/rfm12/borg_rfm12.h new file mode 100644 index 0000000..b379758 --- /dev/null +++ b/rfm12/borg_rfm12.h @@ -0,0 +1,6 @@ + +void borg_rfm12_init(); +void borg_rfm12_tick(); + +extern volatile uint8_t rfm12_joystick_val; + diff --git a/rfm12/config.in b/rfm12/config.in new file mode 100644 index 0000000..80d2f90 --- /dev/null +++ b/rfm12/config.in @@ -0,0 +1,80 @@ + +dep_bool_menu "RFM12 Support" RFM12_SUPPORT y + +if [ "$RFM12_SUPPORT" = "y" ]; then + + choice 'SPI Port' \ + "PORTA PORTA \ + PORTB PORTB \ + PORTC PORTC \ + PORTD PORTD" \ + 'PORTB' PORT_SPI + + choice 'SPI SS Bit' \ + "Bit0 0 \ + Bit1 1 \ + Bit2 2 \ + Bit3 3 \ + Bit4 4 \ + Bit5 5 \ + Bit6 6 \ + Bit7 7" \ + 'Bit4' BIT_SPI_SS + + choice 'MOSI Bit' \ + "Bit0 0 \ + Bit1 1 \ + Bit2 2 \ + Bit3 3 \ + Bit4 4 \ + Bit5 5 \ + Bit6 6 \ + Bit7 7" \ + 'Bit5' BIT_MOSI + + choice 'MISO Bit' \ + "Bit0 0 \ + Bit1 1 \ + Bit2 2 \ + Bit3 3 \ + Bit4 4 \ + Bit5 5 \ + Bit6 6 \ + Bit7 7" \ + 'Bit6' BIT_MISO + + choice 'SCK Bit' \ + "Bit0 0 \ + Bit1 1 \ + Bit2 2 \ + Bit3 3 \ + Bit4 4 \ + Bit5 5 \ + Bit6 6 \ + Bit7 7" \ + 'Bit7' BIT_SCK + + choice 'RFM12 SS Port' \ + "PORTA PORTA \ + PORTB PORTB \ + PORTC PORTC \ + PORTD PORTD" \ + 'PORTB' PORT_SS + + choice 'RFM12 SS Bit' \ + "Bit0 0 \ + Bit1 1 \ + Bit2 2 \ + Bit3 3 \ + Bit4 4 \ + Bit5 5 \ + Bit6 6 \ + Bit7 7" \ + 'Bit4' BIT_SS + + + + +fi + +endmenu diff --git a/rfm12/rfm12.c b/rfm12/rfm12.c new file mode 100644 index 0000000..f75b207 --- /dev/null +++ b/rfm12/rfm12.c @@ -0,0 +1,4 @@ + +#include "rfm12_config.h" +#include "rfm12_lib/rfm12.c" + diff --git a/rfm12/rfm12.h b/rfm12/rfm12.h new file mode 100644 index 0000000..39119fb --- /dev/null +++ b/rfm12/rfm12.h @@ -0,0 +1,4 @@ + +#include "rfm12_config.h" +#include "rfm12_lib/rfm12.h" + diff --git a/rfm12/rfm12_config.h b/rfm12/rfm12_config.h new file mode 100644 index 0000000..20cae10 --- /dev/null +++ b/rfm12/rfm12_config.h @@ -0,0 +1,165 @@ +/**** RFM 12 library for Atmel AVR Microcontrollers ******* + * + * This software is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * @author Peter Fuhrmann, Hans-Gert Dahmen, Soeren Heisrath + */ + +/****************************************************** + * * + * C O N F I G U R A T I O N * + * * + ******************************************************/ + +/* + Connect the RFM12 to the AVR as follows: + + RFM12 | AVR + ----------------+------------ + SDO | MISO + nIRQ | INT0 + FSK/DATA/nFFS | VCC + DCLK/CFIL/FFIT | - + CLK | - + nRES | - + GND | GND + ANT | - + VDD | VCC + GND | GND + nINT/VDI | - + SDI | MOSI + SCK | SCK + nSEL | Slave select pin defined below +*/ + + +#include "../config.h" +#include "../makros.h" + +//Pin that the RFM12's slave select is connected to +//#define DDR_SS DDRB +//#define PORT_SS PORTB +//#define BIT_SS PB4 + +#define DDR_SS DDR(PORT_SS) + +//SPI port +//#define DDR_SPI DDRB + +#define DDR_SPI DDR(PORT_SPI) + +//#define PORT_SPI PORTB +//#define PIN_SPI PINB +//#define BIT_MOSI 5 +//#define BIT_MISO 6 +//#define BIT_SCK 7 +//#define BIT_SPI_SS 4 +//this is the hardware SS pin of the AVR - it +//needs to be set to output for the spi-interface to work +//correctly, independently of the CS pin used for the RFM12 + + +/************************ + * RFM12 CONFIGURATION OPTIONS + */ + +//baseband of the module (either RFM12_BAND_433, RFM12_BAND_868 or RFM12_BAND_912) +#define RFM12_BASEBAND RFM12_BAND_433 + +//center frequency to use (+- FSK frequency shift) +#define RFM12_FREQ 433000000UL + +//FSK frequency shift in kHz +#define FSK_SHIFT 45000 + +//Receive RSSI Threshold +#define RFM12_RSSI_THRESHOLD RFM12_RXCTRL_RSSI_79 + +//Receive Filter Bandwidth +#define RFM12_FILTER_BW RFM12_RXCTRL_BW_134 + +//Output power relative to maximum (0dB is maximum) +#define RFM12_POWER RFM12_TXCONF_POWER_0 + +//Receive LNA gain +#define RFM12_LNA_GAIN RFM12_RXCTRL_LNA_6 + +//crystal load capacitance - the frequency can be verified by measuring the +//clock output of RFM12 and comparing to 1MHz. +//11.5pF seems to be o.k. for RFM12, and 10.5pF for RFM12BP, but this may vary. +#define RFM12_XTAL_LOAD RFM12_XTAL_11_5PF + +//use this for datarates >= 2700 Baud +#define DATARATE_VALUE RFM12_DATARATE_CALC_HIGH(9600.0) + +//use this for 340 Baud < datarate < 2700 Baud +//#define DATARATE_VALUE RFM12_DATARATE_CALC_LOW(1200.0) + +//TX BUFFER SIZE +#define RFM12_TX_BUFFER_SIZE 10 + +//RX BUFFER SIZE (there are going to be 2 Buffers of this size for double_buffering) +#define RFM12_RX_BUFFER_SIZE 10 + + +/************************ + * INTERRUPT VECTOR + * set the name for the interrupt vector here + */ + +//the interrupt vector +#define RFM12_INT_VECT (INT0_vect) + +//the interrupt mask register +#define RFM12_INT_MSK GIMSK + +//the interrupt bit in the mask register +#define RFM12_INT_BIT (INT0) + +//the interrupt flag register +#define RFM12_INT_FLAG GIFR + +//the interrupt bit in the flag register +#define RFM12_FLAG_BIT (INTF0) + +//setup the interrupt to trigger on negative edge +#define RFM12_INT_SETUP() MCUCR |= (1 << ISC01) + + +/************************ + * FEATURE CONFIGURATION + */ + +#define RFM12_LOW_BATT_DETECTOR 0 +#define RFM12_USE_WAKEUP_TIMER 0 +#define RFM12_TRANSMIT_ONLY 0 +#define RFM12_SPI_SOFTWARE 0 + +//setup the low battery detector to 2.2v +//Vlb = 2.2 + (val * 0.1) +//hint: minimum measured supply voltage is 1.98V ! + +#define RFM12_LBD_VOLTAGE RFM12_LBD_VOLTAGE_2V2 + + +/**** UART DEBUGGING + * en- or disable debugging via uart. + */ +#define RFM12_UART_DEBUG 0 + + + + diff --git a/util.c b/util.c index fafffed..8f89892 100644 --- a/util.c +++ b/util.c @@ -5,6 +5,11 @@ #ifdef JOYSTICK_SUPPORT # include "joystick/joystick.h" + unsigned char waitForFire; +#endif + +#ifdef RFM12_SUPPORT + #include "rfm12/borg_rfm12.h" #endif //this buffer is declared in main @@ -41,6 +46,10 @@ void wait(int ms){ bcan_process_messages(); #endif +#ifdef RFM12_SUPPORT + borg_rfm12_tick(); +#endif + #ifdef JOYSTICK_SUPPORT if (waitForFire) { //PORTJOYGND &= ~(1<