adding rfm12 joystick support

This commit is contained in:
tixiv 2012-03-01 23:20:05 +00:00
parent fd0c811993
commit 6a4317ca73
16 changed files with 476 additions and 4 deletions

View File

@ -37,6 +37,11 @@ source scrolltext/config.in
############################################################################### ###############################################################################
### RFM12 Menu ################################################################
source rfm12/config.in
###############################################################################
### Joystick Menu ############################################################# ### Joystick Menu #############################################################
source joystick/config.in source joystick/config.in
############################################################################### ###############################################################################

View File

@ -11,5 +11,8 @@ endif
ifeq ($(PARALLEL_JOYSTICK_SUPPORT), y) ifeq ($(PARALLEL_JOYSTICK_SUPPORT), y)
SRC = joystick.c SRC = joystick.c
endif endif
ifeq ($(RFM12_JOYSTICK_SUPPORT), y)
SRC = rfm12_joystick.c
endif
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk

View File

@ -1,7 +1,6 @@
dep_bool_menu "joystick support" JOYSTICK_SUPPORT y dep_bool_menu "joystick support" JOYSTICK_SUPPORT y
if [ "$JOYSTICK_SUPPORT" = "y" ]; then if [ "$JOYSTICK_SUPPORT" = "y" ]; then
PARALLEL_JOYSTICK_SUPPORT=y
###################### Parallel joystick menu ################################# ###################### Parallel joystick menu #################################
dep_bool_menu "parallel joystick support" PARALLEL_JOYSTICK_SUPPORT y dep_bool_menu "parallel joystick support" PARALLEL_JOYSTICK_SUPPORT y
@ -163,6 +162,12 @@ PARALLEL_JOYSTICK_SUPPORT=y
endmenu endmenu
############################################################################### ###############################################################################
###################### RFM12 joystick menu ####################################
dep_bool_menu "RFM12 Joystick support" RFM12_JOYSTICK_SUPPORT y
endmenu
fi fi
endmenu endmenu

View File

@ -4,9 +4,6 @@
#include "joystick.h" #include "joystick.h"
#include <avr/io.h> #include <avr/io.h>
unsigned char waitForFire;
inline void joy_init(){ inline void joy_init(){
PORT_FROM_PIN(JOYSTICK_PIN_UP ) |= (1<<JOYSTICK_BIT_UP ); PORT_FROM_PIN(JOYSTICK_PIN_UP ) |= (1<<JOYSTICK_BIT_UP );

View File

@ -20,6 +20,15 @@ void joy_init();
# define JOYISRIGHT (!! ((1<<7) & fakeport)) # define JOYISRIGHT (!! ((1<<7) & fakeport))
# define JOYISFIRE (!! ((1<<0) & fakeport)) # define JOYISFIRE (!! ((1<<0) & fakeport))
# elif defined(RFM12_JOYSTICK_SUPPORT)
extern volatile uint8_t rfm12_joystick_val;
# define JOYISUP (!! ((1<<0) & rfm12_joystick_val))
# define JOYISDOWN (!! ((1<<1) & rfm12_joystick_val))
# define JOYISLEFT (!! ((1<<2) & rfm12_joystick_val))
# define JOYISRIGHT (!! ((1<<3) & rfm12_joystick_val))
# define JOYISFIRE (!! ((1<<4) & rfm12_joystick_val))
# else # else

View File

@ -0,0 +1,4 @@
void joy_init(){
}

8
main.c
View File

@ -19,6 +19,10 @@
#include "can/borg_can.h" #include "can/borg_can.h"
#endif #endif
#ifdef RFM12_SUPPORT
#include "rfm12/borg_rfm12.h"
#endif
int main (void){ int main (void){
clear_screen(0); clear_screen(0);
@ -33,6 +37,10 @@ int main (void){
bcan_init(); bcan_init();
#endif #endif
#ifdef RFM12_SUPPORT
borg_rfm12_init();
#endif
#ifdef JOYSTICK_SUPPORT #ifdef JOYSTICK_SUPPORT
joy_init(); joy_init();
#endif #endif

131
profiles/borgjacke Normal file
View File

@ -0,0 +1,131 @@
#
# Automatically generated by make menuconfig: don't edit
#
#
# General Setup
#
MCU=atmega32
FREQ=16000000
#
# Borg Hardware
#
NUM_ROWS=16
NUM_COLS=16
NUMPLANE=3
BORG_HW=HW_BORG_16
#
# Borg16 port setup
#
COLPORT1=PORTC
COLPORT2=PORTA
ROWPORT=PORTD
PIN_MCLR=4
PIN_CLK=6
PIN_DATA=7
# REVERSE_COLS is not set
INVERT_ROWS=y
INTERLACED_ROWS=y
INTERLACED_COLS=y
#
# Features
#
RANDOM_SUPPORT=y
# LAP_TIME_EXTENSION is not set
SCROLLTEXT_SUPPORT=y
SCROLLTEXT_FONT=FONT_ARIAL8
SCROLLTEXT_BUFFER_SIZE=128
SCROLL_X_SPEED=20
SCROLL_Y_SPEED=20
SCROLLTEXT_TEXT="</#www.das-labor.org"
JOYSTICK_SUPPORT=y
PARALLEL_JOYSTICK_SUPPORT=y
JOYSTICK_PIN_UP=PINB
JOYSTICK_BIT_UP=0
JOYSTICK_PIN_DOWN=PINB
JOYSTICK_BIT_DOWN=1
JOYSTICK_PIN_LEFT=PINB
JOYSTICK_BIT_LEFT=2
JOYSTICK_PIN_RIGHT=PINB
JOYSTICK_BIT_RIGHT=3
JOYSTICK_PIN_FIRE=PIND
JOYSTICK_BIT_FIRE=3
# NES_PAD_SUPPORT is not set
# CAN_SUPPORT is not set
MENU_SUPPORT=y
#
# Games
#
GAME_TETRIS_CORE=y
GAME_TETRIS=y
# GAME_BASTET is not set
# GAME_TETRIS_FP is not set
GAME_SPACE_INVADERS=y
GAME_SNAKE=y
# GAME_BREAKOUT is not set
#
# Animations
#
ANIMATION_SCROLLTEXT=y
ANIMATION_SPIRAL=y
SPIRAL_DELAY=5
ANIMATION_JOERN1=y
ANIMATION_SNAKE=y
SNAKE_CYCLE_DELAY=100
SNAKE_TERMINATION_DELAY=60
SNAKE_MAX_LENGTH=64
SNAKE_MAX_APPLES=10
ANIMATION_CHECKERBOARD=y
ANIMATION_FIRE=y
FIRE_S=30
FIRE_N=5
FIRE_DIV=44
FIRE_DELAY=50
FIRE_CYCLES=800
ANIMATION_MATRIX=y
MATRIX_STREAMER_NUM=30
MATRIX_CYCLES=500
MATRIX_DELAY=60
ANIMATION_RANDOM_BRIGHT=y
# ANIMATION_STONEFLY is not set
# ANIMATION_FLYINGDOTS is not set
ANIMATION_GAMEOFLIFE=y
GOL_DELAY=100
GOL_CYCLES=360
# ANIMATION_BREAKOUT is not set
# ANIMATION_MHERWEG is not set
# ANIMATION_LTN_ANT is not set
# ANIMATION_TIME is not set
TIME_MASTER_ADDR=0x00
TIME_UPDATE_TIMEOUT=23
ANIMATION_BMSCROLLER=y
ANIMATION_LABORLOGO=y
# ANIMATION_AMPHIBIAN is not set
# ANIMATION_LOGO_OOS is not set
# ANIMATION_FAIRYDUST is not set
ANIMATION_PLASMA=y
ANIMATION_PSYCHEDELIC=y
# ANIMATION_BLACKHOLE is not set
ANIMATION_TESTS=y
ANIMATION_OFF=y
#
# small Animations
#
# SMALLANIMATION_ROWWALK is not set
SMALLANIMATION_ROWWALK_SPEED=50
SMALLANIMATION_ROWWALK_COUNT=10
# SMALLANIMATION_COLWALK is not set
SMALLANIMATION_COLWALK_SPEED=50
SMALLANIMATION_COLWALK_COUNT=10
# SMALLANIMATION_ROWBOUNCE is not set
SMALLANIMATION_ROWBOUNCE_SPEED=50
SMALLANIMATION_ROWBOUNCE_COUNT=10
# SMALLANIMATION_COLBOUNCE is not set
SMALLANIMATION_COLBOUNCE_SPEED=50
SMALLANIMATION_COLBOUNCE_COUNT=10

8
rfm12/Makefile Normal file
View File

@ -0,0 +1,8 @@
TARGET = objects
TOPDIR = ..
include $(TOPDIR)/defaults.mk
SRC = rfm12.c borg_rfm12.c
include $(TOPDIR)/rules.mk

34
rfm12/borg_rfm12.c Normal file
View File

@ -0,0 +1,34 @@
#include <avr/io.h>
#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();
}

6
rfm12/borg_rfm12.h Normal file
View File

@ -0,0 +1,6 @@
void borg_rfm12_init();
void borg_rfm12_tick();
extern volatile uint8_t rfm12_joystick_val;

80
rfm12/config.in Normal file
View File

@ -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

4
rfm12/rfm12.c Normal file
View File

@ -0,0 +1,4 @@
#include "rfm12_config.h"
#include "rfm12_lib/rfm12.c"

4
rfm12/rfm12.h Normal file
View File

@ -0,0 +1,4 @@
#include "rfm12_config.h"
#include "rfm12_lib/rfm12.h"

165
rfm12/rfm12_config.h Normal file
View File

@ -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

9
util.c
View File

@ -5,6 +5,11 @@
#ifdef JOYSTICK_SUPPORT #ifdef JOYSTICK_SUPPORT
# include "joystick/joystick.h" # include "joystick/joystick.h"
unsigned char waitForFire;
#endif
#ifdef RFM12_SUPPORT
#include "rfm12/borg_rfm12.h"
#endif #endif
//this buffer is declared in main //this buffer is declared in main
@ -41,6 +46,10 @@ void wait(int ms){
bcan_process_messages(); bcan_process_messages();
#endif #endif
#ifdef RFM12_SUPPORT
borg_rfm12_tick();
#endif
#ifdef JOYSTICK_SUPPORT #ifdef JOYSTICK_SUPPORT
if (waitForFire) { if (waitForFire) {
//PORTJOYGND &= ~(1<<BITJOY0); //PORTJOYGND &= ~(1<<BITJOY0);