From 961fa04e15c4d10c83e6c8320e8b754b7b551b48 Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 1 Jun 2012 22:00:56 +0200 Subject: [PATCH] Ready to pull from altar. --- 7seg.c | 41 ++++++++++++++++++++++++++--------------- 7seg.h | 13 +++++-------- 7seg_config.h | 20 -------------------- Makefile | 6 +++--- cerebrum_firmware.c | 10 ++++++---- config.h | 20 ++++++++++++++++++++ inputs.c => input.c | 13 +++++++++++-- inputs.h => input.h | 13 ++++++------- input_config.h | 7 ------- led.c | 18 ++++++++++++++++-- led.h | 13 +++++-------- pwm.c | 17 +++++++++++++++-- pwm.h | 16 ++++++---------- pwm_config.h | 6 ------ r0ketbeam.c | 7 +++++++ r0ketbeam.h | 9 +-------- 16 files changed, 127 insertions(+), 102 deletions(-) delete mode 100644 7seg_config.h rename inputs.c => input.c (77%) rename inputs.h => input.h (56%) delete mode 100644 input_config.h delete mode 100644 pwm_config.h diff --git a/7seg.c b/7seg.c index 3e8c73f..322c836 100644 --- a/7seg.c +++ b/7seg.c @@ -1,37 +1,39 @@ +#include "config.h" +#ifdef HAS_7SEG_SUPPORT #include #include #include #include #include "uart.h" -#include "7seg_config.h" +#include "7seg.h" -void 7seg_setup(){ - 7SEG_CLK_DDR |= _BV(7SEG_CLK_PIN); - 7SEG_DATA_DDR |= _BV(7SEG_DATA_PIN); - 7SEG_DIGIT1_DDR |= _BV(7SEG_DIGIT1_PIN); - 7SEG_DIGIT2_DDR |= _BV(7SEG_DIGIT2_PIN); +void l7seg_setup(){ + L7SEG_CLK_DDR |= _BV(L7SEG_CLK_PIN); + L7SEG_DATA_DDR |= _BV(L7SEG_DATA_PIN); + L7SEG_DIGIT1_DDR |= _BV(L7SEG_DIGIT1_PIN); + L7SEG_DIGIT2_DDR |= _BV(L7SEG_DIGIT2_PIN); } inline void 7seg_pulse_clk(){ - 7SEG_CLK_PORT |= _BV(7SEG_CLK_PIN); - 7SEG_CLK_PORT &= ~_BV(7SEG_CLK_PIN); + L7SEG_CLK_PORT |= _BV(L7SEG_CLK_PIN); + L7SEG_CLK_PORT &= ~_BV(L7SEG_CLK_PIN); } inline void 7seg_data_out(uint8_t val){ - 7SEG_DATA_PORT &= ~_BV(7SEG_DATA_PIN); + L7SEG_DATA_PORT &= ~_BV(L7SEG_DATA_PIN); if(!val){ - 7SEG_DATA_PORT |= _BV(7SEG_DATA_PIN); + L7SEG_DATA_PORT |= _BV(L7SEG_DATA_PIN); } } inline void 7seg_select_digit(uint8_t digit){ - 7SEG_DIGIT1_PORT &= ~_BV(7SEG_DIGIT1_PIN); - 7SEG_DIGIT2_PORT &= ~_BV(7SEG_DIGIT2_PIN); + L7SEG_DIGIT1_PORT &= ~_BV(L7SEG_DIGIT1_PIN); + L7SEG_DIGIT2_PORT &= ~_BV(L7SEG_DIGIT2_PIN); if(digit&1){ - 7SEG_DIGIT1_PORT |= _BV(7SEG_DIGIT1_PIN); + L7SEG_DIGIT1_PORT |= _BV(L7SEG_DIGIT1_PIN); } if(digit&2){ - 7SEG_DIGIT2_PORT |= _BV(7SEG_DIGIT2_PIN); + L7SEG_DIGIT2_PORT |= _BV(L7SEG_DIGIT2_PIN); } } @@ -91,7 +93,7 @@ int 7seg_get_digit(uint8_t b, uint8_t a){ return out | 7seg_digit2[b]; } -void 7seg_loop(){ //one frame +void l7seg_loop(){ //one frame cycle = get_digit(7seg_buf[2],7seg_buf[3]); for(uint8_t i = 0; i<16; i++){ data_out(cycle&1); @@ -113,3 +115,12 @@ void 7seg_loop(){ //one frame _delay_ms(1); select_digit(0); } + +uint8_t 7seg_buf[1] = {char[4]}; + +#else//HAS_7SEG_SUPPORT + +void l7seg_setup(void){} +void l7seg_loop(void){} + +#endif HAS_7SEG_SUPPORT diff --git a/7seg.h b/7seg.h index 889f7b1..916d1fb 100644 --- a/7seg.h +++ b/7seg.h @@ -1,18 +1,15 @@ #ifndef __7SEG_H__ #define __7SEG_H__ -#ifdef HAS_7SEG_SUPPORT #include +#include "config.h" -void 7seg_setup(void); -void 7seg_loop(void); - -uint8_t 7seg_buf[1] = {char[4]}; +void l7seg_setup(void); +void l7seg_loop(void); -#else//HAS_7SEG_SUPPORT +#ifdef HAS_7SEG_SUPPORT -void 7seg_setup(){} -void 7seg_loop(){} +extern uint8_t 7seg_buf**; #endif//HAS_7SEG_SUPPORT #endif//__7SEG_H__ diff --git a/7seg_config.h b/7seg_config.h deleted file mode 100644 index c9f8c40..0000000 --- a/7seg_config.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __7SEG_CONFIG_H__ -#define __7SEG_CONFIG_H__ - -#define 7SEG_CLK_DDR -#define 7SEG_CLK_PORT -#define 7SEG_CLK_PIN - -#define 7SEG_DATA_DDR -#define 7SEG_DATA_PORT -#define 7SEG_DATA_PIN - -#define 7SEG_DIGIT1_DDR -#define 7SEG_DIGIT1_PORT -#define 7SEG_DIGIT1_PIN - -#define 7SEG_DIGIT2_DDR -#define 7SEG_DIGIT2_PORT -#define 7SEG_DIGIT2_PIN - -#endif//__7SEG_CONFIG_H__ diff --git a/Makefile b/Makefile index 7f870ac..333ea27 100644 --- a/Makefile +++ b/Makefile @@ -137,7 +137,7 @@ TARGET = $(PROJECTNAME) # CSRC = $(PROJECTNAME).cpp second.cpp third.cpp a.c another.c # List C and C++ files here -CSRC = $(PROJECTNAME).c uart.c util.c spi.c r0ketbeam.c RF24/RF24.c +CSRC = $(PROJECTNAME).c uart.c util.c spi.c led.c input.c 7seg.c pwm.c r0ketbeam.c RF24/RF24.c # <== @@ -386,7 +386,7 @@ AVRDUDE_PROGRAMMER = stk500v2 -b 115200 # ==> Choose the port used by the programmer -AVRDUDE_PORT = /dev/ttyACM0 +AVRDUDE_PORT = /dev/ttyACM1 # <== @@ -523,7 +523,7 @@ gccversion : # Program the device. program: $(TARGET).hex $(TARGET).eep - sh -c 'echo>/dev/ttyACM0' + sh -c 'echo>/dev/ttyACM1' $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) diff --git a/cerebrum_firmware.c b/cerebrum_firmware.c index 656d9d5..765a333 100644 --- a/cerebrum_firmware.c +++ b/cerebrum_firmware.c @@ -12,10 +12,12 @@ #include #include #include "uart.h" -#include "r0ketbeam.h" #include "util.h" +#include "r0ketbeam.h" #include "7seg.h" #include "led.h" +#include "pwm.h" +#include "input.h" void setup(void); void loop(void); @@ -28,7 +30,7 @@ int main(void){ void setup(){ uart_init(UART_BAUD_SELECT_DOUBLE_SPEED(115200, F_CPU)); pwm_setup(); - 7seg_setup(); + l7seg_setup(); r0ketbeam_setup(); input_setup(); led_setup(); @@ -100,7 +102,7 @@ void loop(){ //one frame case 'r': uart_putc('r'); for(uint8_t i=0; i - -uint8_t debounce_timeouts[INPUT_COUNT]; -uint8_t switch_states[INPUT_COUNT]; +#include "config.h" +#include "util.h" +#include "uart.h" void input_setup(void); void input_loop(void); -#else//HAS_INPUT_SUPPORT +#ifdef HAS_INPUT_SUPPORT -void input_setup(){} -void input_loop(){} +extern uint8_t debounce_timeouts[]; +extern uint8_t switch_states[]; #endif//HAS_INPUT_SUPPORT #endif//__INPUTS_H__ diff --git a/input_config.h b/input_config.h deleted file mode 100644 index a27e655..0000000 --- a/input_config.h +++ /dev/null @@ -1,7 +0,0 @@ - -#ifndef __INPUT_CONFIG_H__ -#define __INPUT_CONFIG_H__ - -#define INPUT_COUNT 1 - -#endif//__INPUT_CONFIG_H__ diff --git a/led.c b/led.c index 8989af4..a205074 100644 --- a/led.c +++ b/led.c @@ -1,5 +1,11 @@ #include "led.h" +#include + +//The DDRs of the led matrix outputs are set in the mux loop. +void led_setup(void){} + +#ifdef HAS_LED_SUPPORT void swapBuffers(void){ uint8_t* tmp = frameBuffer; @@ -22,9 +28,9 @@ void led_loop(){ uint8_t DDRQ = 0xFF; //Just for testing: reactivating the old behavioor //unpacking of frame data: data is packed like this: [11111117][22222266][33333555][4444----] if(!(i&4)) - Q |= frameBuffer[i&3] >> i; + Q |= frameBuffer[i&3] >> (i+1); else - Q |= frameBuffer[i&3] & (0xFF << (i&3)); + Q |= frameBuffer[i&3] & (0xFF << ((i&3)+1)); //FIXME this whole mapping shit should be done in h/w!!1! //FIXME this whole mapping is not even correct!!1! //FIXME IT DOES NOT WORK!!1! @@ -68,3 +74,11 @@ void led_loop(){ _delay_ms(1); } } + +//this scary construct is in place to make the compiler happy. if you know a better way, feel free to improve. +uint8_t _frameBuffer[] = {0,0,0,0}; +uint8_t _secondFrameBuffer[] = {0,0,0,0}; +uint8_t* frameBuffer = _frameBuffer; +uint8_t* secondFrameBuffer = _secondFrameBuffer; + +#endif//HAS_LED_SUPPORT diff --git a/led.h b/led.h index 958b432..6791227 100644 --- a/led.h +++ b/led.h @@ -3,14 +3,12 @@ #define __LED_H__ #include +#include "config.h" #ifdef HAS_LED_SUPPORT -//this scary construct is in place to make the compiler happy. if you know a better way, feel free to improve. -uint8_t _frameBuffer[] = {0,0,0,0}; -uint8_t _secondFrameBuffer[] = {0,0,0,0}; -uint8_t* frameBuffer = _frameBuffer; -uint8_t* secondFrameBuffer = _secondFrameBuffer; +extern uint8_t* frameBuffer; +extern uint8_t* secondFrameBuffer; void swapBuffers(void); void setLED(int num, int val); @@ -20,11 +18,10 @@ void led_loop(void); #else//HAS_LED_SUPPORT -void led_loop(void){} +void led_loop(){} #endif//HAS_LED_SUPPORT -//The DDRs of the led matrix outputs are set in the mux loop. -void led_setup(void){} +void led_setup(void); #endif//__LED_H__ diff --git a/pwm.c b/pwm.c index a9a7cac..c881f9b 100644 --- a/pwm.c +++ b/pwm.c @@ -1,8 +1,12 @@ -#include "pwm_config.h" #include "pwm.h" -void pwm_setup(void){ +//The PWM has no loop function. It runs entirely out of the ISR. +void pwm_loop(){} + +#ifdef HAS_PWM_SUPPORT + +void pwm_setup(){ //s/w "BCM"(<== "Binary Code Modulation") timer setup TCCR0A |= _BV(WGM00)|_BV(WGM01); TCCR0B |= _BV(CS02); @@ -26,3 +30,12 @@ ISR(TIMER0_OVF_vect){ pwm_cycle = 1; } } + +uint8_t pwm_cycle = 0; +uint8_t pwm_val[PWM_COUNT]; + +#else//HAS_PWM_SUPPORT + +void pwm_setup(){} + +#endif//HAS_PWM_SUPPORT diff --git a/pwm.h b/pwm.h index 81afa11..37433c4 100644 --- a/pwm.h +++ b/pwm.h @@ -5,21 +5,17 @@ #define __PWM_H__ #include +#include +#include "config.h" #ifdef HAS_PWM_SUPPORT -uint8_t pwm_cycle = 0; -uint8_t pwm_val[PWM_COUNT]; - -void pwm_setup(void); - -#else//HAS_PWM_SUPPORT - -void pwm_setup(){} +extern uint8_t pwm_cycle; +extern uint8_t pwm_val[]; #endif//HAS_PWM_SUPPORT -//The PWM has no loop function. It runs entirely out of the ISR. -void pwm_loop(){} +void pwm_setup(void); +void pwm_loop(void); #endif//__PWM_H__ diff --git a/pwm_config.h b/pwm_config.h deleted file mode 100644 index bc3ae0d..0000000 --- a/pwm_config.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __PWM_CONFIG_H__ -#define __PWM_CONFIG_H__ - -#define PWM_COUNT 5 - -#endif//__PWM_CONFIG_H__ diff --git a/r0ketbeam.c b/r0ketbeam.c index e3ba4a3..8b4c5a5 100644 --- a/r0ketbeam.c +++ b/r0ketbeam.c @@ -1,4 +1,6 @@ +#include "config.h" +#ifdef HAS_R0KETBEAM_SUPPORT #include #include "r0ketbeam.h" @@ -180,4 +182,9 @@ void r0ketbeam_loop(void) } } +#else//HAS_R0KETBEAM_SUPPORT +void r0ketbeam_loop(){} +void r0ketbeam_setup(){} + +#endif//HAS_R0KETBEAM_SUPPORT diff --git a/r0ketbeam.h b/r0ketbeam.h index e715bc8..3e02d78 100644 --- a/r0ketbeam.h +++ b/r0ketbeam.h @@ -1,15 +1,8 @@ -#include "cerebrum_module." + #ifndef __R0KETBEAM_H__ #define __R0KETBEAM_H__ -#ifdef HAS_R0KETBEAM_SUPPORT void r0ketbeam_loop(void); void r0ketbeam_setup(void); -#else//HAS_R0KETBEAM_SUPPORT - -void r0ketbeam_loop(){} -void r0ketbeam_setup(){} - -#endif//HAS_R0KETBEAM_SUPPORT #endif//__R0KETBEAM_H__ -- 2.11.4.GIT