X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=rf433rcv%2Fteensy%2Fexample.c;h=ebf77e2cdf86f94047b85a58e557a1d736c6e36a;hb=02293cb00639b97ca422619ee15f5981a5b3ffd0;hp=649b207b7a84a85004c5af0e3ab31076e7cf1197;hpb=1d25e73e3d6d789b52433afee4ab3a1f70019912;p=svn42.git diff --git a/rf433rcv/teensy/example.c b/rf433rcv/teensy/example.c index 649b207..ebf77e2 100644 --- a/rf433rcv/teensy/example.c +++ b/rf433rcv/teensy/example.c @@ -28,17 +28,58 @@ #include "usb_rawhid.h" #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) +#define RF_SEND_BUFFER_LEN_MAX 128 +volatile uint16_t output_count=0; +volatile uint8_t active_buffer=0; +volatile uint16_t send_buffer=0; +volatile uint8_t capture=0; +volatile uint8_t rf_send=0; //count of bits in rf_send_buffer that should be sent +volatile uint8_t rf_send_reload=0; //count of bits in rf_send_buffer that should be sent +volatile uint8_t rf_send_reload_count=0; // number of repetitions (times rf_send gets reloaded; +uint8_t read_buffer[64]; // buffer for reading usb signals +uint8_t write_buffer[2][64]; // buffer for writing usb signals +uint8_t rf_send_buffer[RF_SEND_BUFFER_LEN_MAX]; // buffer for sending rf433 signals +uint8_t rf_send_buffer_len=0; -volatile uint8_t do_output=0; -uint8_t read_buffer[64]; -uint8_t write_buffer[64]; -int main(void) +void reset() { - int8_t r; - uint8_t i; - uint16_t val, count=0; + cli(); + // disable watchdog, if enabled + // disable all peripherals + UDCON = 1; + USBCON = (1<0) - usb_rawhid_send(read_buffer, 50); - + { + if (read_buffer[0]=='r') //reset + reset(); + else if (read_buffer[0]=='b') //begin capture + capture=1; + else if (read_buffer[0]=='e') //end capture + capture=0; + else if (read_buffer[0]=='f') //fill send buffer + { + int8_t byte_rem = r-1; + while(byte_rem && rf_send_buffer_len2) + rf_send_reload=rf_send_buffer_len*8-read_buffer[2]; // substract bit offset + else + rf_send_reload=rf_send_buffer_len*8; + rf_send_reload_count=read_buffer[1]; + } + } + if (send_buffer) + { + send_buffer=0; + usb_rawhid_send(write_buffer[active_buffer?0:1], 45); + } } } @@ -72,8 +147,29 @@ int main(void) ISR(TIMER0_COMPA_vect) { PORTF^=2; - + if (rf_send) + { + if (rf_send_buffer[rf_send/8] & 0x80) + { + PORTF|=1; + } else { + PORTF&=~1; + } + rf_send_buffer[rf_send/8]<<=1; + rf_send--; + } else if (rf_send_reload_count) { + rf_send=rf_send_reload; + } else { + PORTF&=~1; + if (capture) { + write_buffer[active_buffer][output_count/8]<<=1; + write_buffer[active_buffer][output_count++/8]|=PINB&1; + if (output_count>=64*8) + { + output_count=0; + active_buffer=active_buffer?0:1; + send_buffer=1; + } + } + } } - - -