void telemetry_init(void) { debug("telemetry: init\n"); debug_flush(); // mark as invalid telemetry_expected_id = 0; // setup buffer telemetry_buffer.write = 0; telemetry_buffer.read = 0; telemetry_buffer.read_ok = 0; #ifdef HUB_TELEMETRY_ON_SBUS_UART // re-use sbus uart, no init necessary debug("telemetry: using sbus uart\n"); debug_flush(); // attach callback uart_set_rx_callback(&telemetry_rx_callback); #else // init software serial port soft_serial_init(); // attach callback soft_serial_set_rx_callback(&telemetry_rx_callback); #endif #if TELEMETRY_DO_TEST telemetry_rx_echo_test(); #endif }
int main(void) { pin_init(); uart_init(); uart_set_rx_callback(&my_rx_callback); uart_enable(); sei(); while(1) { uart_send_data(ch_cycles, 4*CH_NUM); uart_send_data(ch_rpm, 2*CH_NUM); measure_rpm(); _delay_ms(1000); } }
int main(void) { uart_t *u0; /* Delay for one second to avoid multiple resets during programming. */ _delay_ms(1000); /* Initialize USART0 and set up stdout to write to it. */ u0 = uart_init("0", UART_BAUD_SELECT(38400, F_CPU)); uart_init_stdout(u0); uart_set_rx_callback(u0, notice_uart_input); i2c_init(); /* * Test if pullup is required on the I2C pins, and enable if the pins are * reading low. This allows external pullups to optionally be used, so that * for example the I2C bus can be pulled up to 3.3V to allow communication * between 3.3V and 5V devices at 3.3V. */ if((PINC & (_BV(PC0) | _BV(PC1))) == 0) { DDRC = _BV(PC0) | _BV(PC1); PORTC = _BV(PC0) | _BV(PC1); } sei(); printf_P(PSTR("\n\nBooted!\n")); printf_P(PSTR("Reading saved configuration...\n\n")); configuration_restore(); printf_P(PSTR( "Configuration:\n" " tz_offset: %2i\n" " dst_offset: %2i\n" "\n" ), configuration.tz_offset, configuration.dst_offset); printf_P(PSTR( "Commands:\n" " Get the current time:\n" " G\n" " Set the current time:\n" " S YYYY-MM-DD hh:mm:ss\n" " Set the timezone offset from UTC:\n" " O <tz_offset> <dst_offset>\n" " Set the time from GPS (if available):" " s\n" "\n" )); rtc_init(rtc); rtc_sqw_enable(rtc); rtc_sqw_rate(rtc, 1); /* Enable pullup and interrupt for PC6/PCINT22, DS1307 SQW pin. */ PORTC |= _BV(PC6); PCMSK2 |= _BV(PCINT22); PCICR |= _BV(PCIE2); /* Initialize the sequencer with 1000Hz tick rate. */ led_sequencer_init(1000); /* Initialize and load the LED Analog Clock LED display. */ led_charlieplex_init(&LED_DISPLAY); led_sequencer_push_front_matrix("c", &LED_DISPLAY); /* * Add empty sequences for hour, minute, second, hourly show, and minutely * show. */ led_sequencer_push_back_sequence("h"); led_sequencer_push_back_sequence("m"); led_sequencer_push_back_sequence("s"); led_sequencer_push_back_sequence("H"); led_sequencer_push_back_sequence("M"); /* * Initially read the time, set last_* for use later, and push a sequencer * step into the second, minute, and hour sequences. The steps pushed * below are never removed, as they are modified in place in update_hms() * with each time change. */ rtc_read(rtc, ¤t_time); last_hour = current_time.hour; last_minute = current_time.minute; last_second = current_time.second; step_hour = led_sequencer_sequence_push_back_step("h", LED_SEQUENCER_STEP_SHOW, "c", led_mapping_qhour[((current_time.hour % 12) * 4) + (current_time.minute / 15)], 255); step_minute = led_sequencer_sequence_push_back_step("m", LED_SEQUENCER_STEP_SHOW, "c", led_mapping_minute[current_time.minute], 255); step_second = led_sequencer_sequence_push_back_step("s", LED_SEQUENCER_STEP_SHOW, "c", led_mapping_minute[current_time.second], 255); enqueue_hourly_show(); led_sequencer_run(); srand(current_time.hour * current_time.minute * current_time.second); /* * Main infinite loop. */ while(1) { /* Handle UART input when ready. */ if(ready_flags & READY_UART_DATA) { ready_flags &= ~READY_UART_DATA; handle_uart_input(u0); } /* A time change has occurred, update the clock display. */ if(ready_flags & READY_UPDATE_HMS) { ready_flags &= ~READY_UPDATE_HMS; update_hms(); } /* * Run one loop through the current sequence, with interrupts disabled. */ cli(); led_sequencer_display(); sei(); } /* Never reached. */ return(0); }