From 5a26b2854f2e10c8be8ce78e18435ba7362988c0 Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 1 Jun 2012 20:02:49 +0000 Subject: [PATCH] Single lamps can be controlled. r0ketbeam is working. Input support is working. The 7 segment display control code works. --- 7seg.c | 246 ++++++++++++++++++++++++++++------------------------ 7seg.h | 13 ++- 7seg_config.h | 20 ----- Makefile | 6 +- cerebrum_firmware.c | 32 ++++--- config.c | 18 ++++ config.h | 25 +++++- foo.py | 5 ++ input.c | 36 ++++++++ inputs.h => input.h | 14 +-- input_config.h | 7 -- inputs.c | 30 ------- led.c | 117 ++++++++++--------------- led.h | 54 +++++------- pwm.c | 17 +++- pwm.h | 16 ++-- pwm_config.h | 6 -- r0ketbeam.c | 7 ++ r0ketbeam.h | 9 +- 19 files changed, 350 insertions(+), 328 deletions(-) rewrite 7seg.c (72%) delete mode 100644 7seg_config.h create mode 100644 config.c create mode 100755 foo.py create mode 100644 input.c rename inputs.h => input.h (51%) delete mode 100644 input_config.h delete mode 100644 inputs.c rewrite led.c (82%) rewrite led.h (60%) delete mode 100644 pwm_config.h diff --git a/7seg.c b/7seg.c dissimilarity index 72% index 3e8c73f..ba7dd50 100644 --- a/7seg.c +++ b/7seg.c @@ -1,115 +1,131 @@ -#include -#include -#include -#include -#include "uart.h" -#include "7seg_config.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); -} - -inline void 7seg_pulse_clk(){ - 7SEG_CLK_PORT |= _BV(7SEG_CLK_PIN); - 7SEG_CLK_PORT &= ~_BV(7SEG_CLK_PIN); -} - -inline void 7seg_data_out(uint8_t val){ - 7SEG_DATA_PORT &= ~_BV(7SEG_DATA_PIN); - if(!val){ - 7SEG_DATA_PORT |= _BV(7SEG_DATA_PIN); - } -} - -inline void 7seg_select_digit(uint8_t digit){ - 7SEG_DIGIT1_PORT &= ~_BV(7SEG_DIGIT1_PIN); - 7SEG_DIGIT2_PORT &= ~_BV(7SEG_DIGIT2_PIN); - if(digit&1){ - 7SEG_DIGIT1_PORT |= _BV(7SEG_DIGIT1_PIN); - } - if(digit&2){ - 7SEG_DIGIT2_PORT |= _BV(7SEG_DIGIT2_PIN); - } -} - -int 7seg_cycle=1; - -int 7seg_digit1[] = { - 0x56C0, - 0x6000, - 0x94C0, - 0x9640, - 0xC600, - 0xD240, - 0xD2C0, - 0x1600, - 0xD6C0, - 0xD640, - 0xD680, - 0xC2C0, - 0x50C0, - 0x86C0, - 0xD0C0, - 0xD080 -}; - -int 7seg_digit2[] = { - 0x011F, - 0x000C, - 0x081B, - 0x081E, - 0x090C, - 0x0916, - 0x0917, - 0x001C, - 0x091F, - 0x091E, - 0x091D, - 0x0907, - 0x0113, - 0x080F, - 0x0913, - 0x0911 -}; - -int 7seg_get_digit(uint8_t b, uint8_t a){ - int out = 0; - a -= '0'; - b -= '0'; - if(a > 0x20) - a-=0x20; - if(a > 0x10) - a-=7; - if(b > 0x20) - b-=0x20; - if(b > 0x10) - b-=7; - out = 7seg_digit1[a]; - return out | 7seg_digit2[b]; -} - -void 7seg_loop(){ //one frame - cycle = get_digit(7seg_buf[2],7seg_buf[3]); - for(uint8_t i = 0; i<16; i++){ - data_out(cycle&1); - cycle>>=1; - pulse_clk(); - } - data_out(0); - select_digit(1); - _delay_ms(1); - select_digit(0); - cycle = get_digit(7seg_buf[0],7seg_buf[1]); - for(uint8_t i = 0; i<16; i++){ - data_out(cycle&1); - cycle>>=1; - pulse_clk(); - } - data_out(0); - select_digit(2); - _delay_ms(1); - select_digit(0); -} +#include "config.h" +#ifdef HAS_7SEG_SUPPORT +#include +#include +#include +#include +#include "uart.h" +#include "7seg.h" + +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 l7seg_pulse_clk(void){ + L7SEG_CLK_PORT |= _BV(L7SEG_CLK_PIN); + L7SEG_CLK_PORT &= ~_BV(L7SEG_CLK_PIN); +} + +inline void l7seg_data_out(uint8_t val){ + L7SEG_DATA_PORT &= ~_BV(L7SEG_DATA_PIN); + if(!val){ + L7SEG_DATA_PORT |= _BV(L7SEG_DATA_PIN); + } +} + +inline void l7seg_select_digit(uint8_t digit){ + L7SEG_DIGIT1_PORT &= ~_BV(L7SEG_DIGIT1_PIN); + L7SEG_DIGIT2_PORT &= ~_BV(L7SEG_DIGIT2_PIN); + if(digit&1){ + L7SEG_DIGIT1_PORT |= _BV(L7SEG_DIGIT1_PIN); + } + if(digit&2){ + L7SEG_DIGIT2_PORT |= _BV(L7SEG_DIGIT2_PIN); + } +} + +int l7seg_cycle=1; + +int l7seg_digit1[] = { + 0x56C0, //0 + 0x0600, //1 + 0x94C0, //2 + 0x9640, //3 + 0xC600, //4 + 0xD240, //5 + 0xD2C0, //6 + 0x1600, //7 + 0xD6C0, //8 + 0xD640, //9 + 0xD680, //A + 0xC2C0, //B + 0x50C0, //C + 0x86C0, //D + 0xD0C0, //E + 0xD080 //F +}; + +int l7seg_digit2[] = { + 0x011F, + 0x000C, + 0x081B, + 0x081E, + 0x090C, + 0x0916, + 0x0917, + 0x001C, + 0x091F, + 0x091E, + 0x091D, + 0x0907, + 0x0113, + 0x080F, + 0x0913, + 0x0911 +}; + +int l7seg_get_digit(uint8_t b, uint8_t a){ + int out = 0; + a -= '0'; + b -= '0'; + if(a > 0x20) + a-=0x20; + if(a > 0x10) + a-=7; + if(b > 0x20) + b-=0x20; + if(b > 0x10) + b-=7; + out = l7seg_digit1[a]; + return out | l7seg_digit2[b]; +} + +void l7seg_loop(){ //one frame + uint8_t nbuf = 0; + static uint8_t pos = 0; + if(pos&1){ + l7seg_cycle = l7seg_get_digit(l7seg_buf[2],l7seg_buf[3]); + l7seg_select_digit(0); + for(uint8_t i = 0; i<16; i++){ + l7seg_data_out(l7seg_cycle&1); + l7seg_cycle>>=1; + l7seg_pulse_clk(); + } + l7seg_data_out(0); + l7seg_select_digit(1); + }else{ + l7seg_cycle = l7seg_get_digit(l7seg_buf[0],l7seg_buf[1]); + l7seg_select_digit(0); + for(uint8_t i = 0; i<16; i++){ + l7seg_data_out(l7seg_cycle&1); + l7seg_cycle>>=1; + l7seg_pulse_clk(); + } + l7seg_data_out(0); + l7seg_select_digit(2); + } + pos++; +} + +uint8_t _l7seg_buf[4] = {'1','3','3','7'}; +uint8_t* l7seg_buf = _l7seg_buf; + +#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..ee024aa 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* l7seg_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..07a249c 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 config.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..8145842 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,10 +30,11 @@ 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(); + config_setup(); sei(); } @@ -51,11 +54,11 @@ void loop(){ //one frame // \\ - backslash // \n - newline // \[x] - x - //eats [n] commands: 's' (0x73) led value sets led number [led] to [value] - // 'b' (0x62) buffer buffer buffer buffer sets the whole frame buffer - // 'a' (0x61) meter value sets analog meter number [meter] to [value] - // 'r' (0x72) read the frame buffer - // 'd' (0x64) digit digit digit digit sets the 7-segment display + //eats [n] commands: 's' (0x73) led value sets led number [led] to [value] + // 'b' (0x62) buffer buffer buffer buffer sets the whole frame buffer + // 'a' (0x61) meter value sets analog meter number [meter] to [value] + // 'r' (0x72) read the frame buffer + // 'd' (0x64) display digit digit digit digit sets the 7-segment display (CAUTION: "display" currently is ignored) //this device will utter a "'c' (0x63) num state" when switch [num] changes state to [state] //commands are terminated by \n if(!receive_state){ @@ -84,6 +87,7 @@ void loop(){ //one frame case 0: //Do not assume anything about the variables used //command char switch(c){ +#ifdef HAS_LED_SUPPORT case 's': state = 2; break; @@ -91,19 +95,22 @@ void loop(){ //one frame nbuf = 0; state = 4; break; +#endif//HAS_LED_SUPPORT #ifdef HAS_PWM_SUPPORT case 'a': state = 5; nbuf = 0; break; #endif//HAS_PWM_SUPPORT +#ifdef HAS_LED_SUPPORT case 'r': uart_putc('r'); for(uint8_t i=0; i PWM_COUNT) @@ -146,7 +155,7 @@ void loop(){ //one frame state = 8; break; case 8: - 7seg_buf[nbuf][bpos] = c; + l7seg_buf[(uint8_t)bpos] = c; bpos++; if(bpos == 4){ state = 0; @@ -158,7 +167,8 @@ void loop(){ //one frame }while(!receive_state); led_loop(); r0ketbeam_loop(); - 7seg_loop(); + l7seg_loop(); input_loop(); pwm_loop(); + _delay_ms(1); } diff --git a/config.c b/config.c new file mode 100644 index 0000000..ede5c51 --- /dev/null +++ b/config.c @@ -0,0 +1,18 @@ + +#include "config.h" +#include +#include "input.h" + +void config_setup(){ + PORTH |= 0x20; +} + +void input_scan_inputs(){ + switch_states[0] |= !!(PINH&0x20); +} + +void led_output_stuff1(uint8_t data, uint8_t dir){ + PORTK = data; + DDRK = dir; +} + diff --git a/config.h b/config.h index 864a94c..b13e76a 100644 --- a/config.h +++ b/config.h @@ -2,9 +2,32 @@ #ifndef __CONFIG_H__ #define __CONFIG_H__ -#define HAS_PWM_SUPPORT 1 +//#define HAS_PWM_SUPPORT 1 #define HAS_R0KETBEAM_SUPPORT 1 #define HAS_INPUT_SUPPORT 1 #define HAS_LED_SUPPORT 1 +#define HAS_7SEG_SUPPORT 1 + +//#define PWM_COUNT 5 +#define INPUT_COUNT 1 + + +#define L7SEG_CLK_DDR DDRG +#define L7SEG_CLK_PORT PORTG +#define L7SEG_CLK_PIN 5 + +#define L7SEG_DATA_DDR DDRE +#define L7SEG_DATA_PORT PORTE +#define L7SEG_DATA_PIN 3 + +#define L7SEG_DIGIT1_DDR DDRE +#define L7SEG_DIGIT1_PORT PORTE +#define L7SEG_DIGIT1_PIN 4 + +#define L7SEG_DIGIT2_DDR DDRE +#define L7SEG_DIGIT2_PORT PORTE +#define L7SEG_DIGIT2_PIN 5 + +void config_setup(void); #endif//__CONFIG_H__ diff --git a/foo.py b/foo.py new file mode 100755 index 0000000..303bfc4 --- /dev/null +++ b/foo.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python +import serial +ser = serial.Serial("/dev/ttyACM0", 115200) +while True: + print ser.readline() diff --git a/input.c b/input.c new file mode 100644 index 0000000..f0b04cf --- /dev/null +++ b/input.c @@ -0,0 +1,36 @@ + +#include "input.h" +#ifdef HAS_INPUT_SUPPORT + +void input_setup(void){ +} + +void input_loop(void){ + input_scan_inputs(); + for(int i=0; i>1){ + uart_putc('c'); + uart_puthex(i); + uart_puthex(switch_states[i]&1); + uart_putc('\n'); + debounce_timeouts[i] = 0x00; + switch_states[i] = (switch_states[i]<<1)&3; + } + switch_states[i] &= 0xFE; + }else{ + debounce_timeouts[i]--; + } + } +} + +uint8_t debounce_timeouts[INPUT_COUNT]; +uint8_t switch_states[INPUT_COUNT]; + +#else//HAS_INPUT_SUPPORT + +void input_setup(){} +void input_loop(){} + +#endif//HAS_INPUT_SUPPORT diff --git a/inputs.h b/input.h similarity index 51% rename from inputs.h rename to input.h index af7e75b..8f608c7 100644 --- a/inputs.h +++ b/input.h @@ -1,19 +1,19 @@ #ifndef __INPUTS_H__ #define __INPUTS_H__ -#ifdef HAS_INPUT_SUPPORT #include - -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[INPUT_COUNT]; +extern uint8_t switch_states[INPUT_COUNT]; +void input_scan_inputs(void); #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/inputs.c b/inputs.c deleted file mode 100644 index ec54842..0000000 --- a/inputs.c +++ /dev/null @@ -1,30 +0,0 @@ - -#include "input_config.h" -#include "inputs.h" - -uint8_t switch_last_state = 0; -int switch_debounce_timeout = 0; - -void input_setup(void){ - //FIXME set input DDRs -} - -void input_loop(void){ - //FIXME scan inputs - //switch_states[0] |= !!(PINH&0x02); - for(int i=0; i>3] &= ~(1<<(num&7)); - if(val) - frameBuffer[num>>3] |= 1<<(num&7); - } -} - -void led_loop(){ - for(int i=0; i<8; i++){ - uint8_t Q = 0x80>>i; //select the currently active "row" of the matrix. On the protoboards I make, this actually corresponds to physical traces. - //uint8_t DDRQ = 0xFF>>i; //This is supposed to be an optimization. It is untested and will probably not work. - 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; - else - Q |= frameBuffer[i&3] & (0xFF << (i&3)); - //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! - // Q&0x01 ==> PG5 - // 02 ==> PE3 - // 04 ==> PH3 - // 08 ==> PH4 - // 10 ==> PH5 - // 20 ==> PH6 - // 40 ==> PB4 - // 80 ==> PB5 - DDRG&=~(1<<5); - DDRG|=(DDRQ&1)<<5; - PORTG&=~(1<<5); - PORTG|=(Q&1)<<5; - DDRE&=~(1<<3); - DDRE|=(DDRQ&2)<<2; - PORTE&=~(1<<3); - PORTE|=(Q&2)<<2; - DDRH&=0xC3; - DDRH|=(DDRQ&0x3C); - PORTH&=0xC3; - PORTH|=(Q&0x3C); - DDRB&=0xCF; - DDRB|=(DDRQ&0xC0)>>2; - PORTB&=0xCF; - PORTB|=(Q&0xC0)>>2; - /* second channel skeleton - Q = 0x80>>i; - if(!(i&4)) - Q |= frameBuffer[4+(i&3)] >> i; - else - Q |= frameBuffer[4+(i&3)] & (0xFF << (i&3)); - DDRA = DDRQ; - PORTA = Q; - //PORTD &= 0x0F; - //PORTD |= Q&0xF0; - //PORTB &= 0xF0; - //PORTB |= Q&0x0F; - */ - _delay_ms(1); - } -} + +#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; + frameBuffer = secondFrameBuffer; + secondFrameBuffer = tmp; +} + +void setLED(int num, int val){ + if(num<32){ + frameBuffer[num>>3] &= ~(1<<(num&7)); + if(val) + frameBuffer[num>>3] |= 1<<(num&7); + } +} + +void led_loop(){ + uint8_t row = 2; //selects the currently active "row" of the matrix. On the protoboards I make, this actually corresponds to physical traces. + for(int i=0; i<7; i++){ + uint8_t DDRQ = frameBuffer[i]; + uint8_t Q = ~DDRQ; + Q |= row; + DDRQ |= row; + row <<= 1; + led_output_stuff1(Q, DDRQ); + _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,0,0,0}; +uint8_t _secondFrameBuffer[] = {0,0,0,0,0,0,0}; +uint8_t* frameBuffer = _frameBuffer; +uint8_t* secondFrameBuffer = _secondFrameBuffer; + +#else//HAS_LED_SUPPORT + +void led_loop(){} + +#endif//HAS_LED_SUPPORT diff --git a/led.h b/led.h dissimilarity index 60% index 958b432..61f7bca 100644 --- a/led.h +++ b/led.h @@ -1,30 +1,24 @@ - -#ifndef __LED_H__ -#define __LED_H__ - -#include - -#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; - -void swapBuffers(void); -void setLED(int num, int val); - -//CAUTION! This loop function takes more than 8ms due to delays. -void led_loop(void); - -#else//HAS_LED_SUPPORT - -void led_loop(void){} - -#endif//HAS_LED_SUPPORT - -//The DDRs of the led matrix outputs are set in the mux loop. -void led_setup(void){} - -#endif//__LED_H__ + +#ifndef __LED_H__ +#define __LED_H__ + +#include +#include "config.h" + +#ifdef HAS_LED_SUPPORT + +extern uint8_t* frameBuffer; +extern uint8_t* secondFrameBuffer; + +extern void led_output_stuff1(uint8_t data, uint8_t dir); + +void swapBuffers(void); +void setLED(int num, int val); + +#endif//HAS_LED_SUPPORT + +//CAUTION! This loop function takes more than 8ms due to delays. +void led_loop(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