bool usb_init() { if(!usb_is_connected()) { return false; } send_status = 0; receive_status = 0; usb_configure_clock_48mhz(); USBDDriver_Initialize(&usbd_driver, &driver_descriptors, 0); USBD_Init(); // Check current level on VBus if(usb_is_connected()) { USBD_Connect(); } else { USBD_Disconnect(); return false; } return true; }
int main() { const Pin pins_stack[] = {PINS_STACK}; PIO_Configure(pins_stack, PIO_LISTSIZE(pins_stack)); brick_hardware_version[0] = BRICK_HARDWARE_VERSION_MAJOR; brick_hardware_version[1] = BRICK_HARDWARE_VERSION_MINOR; brick_hardware_version[2] = BRICK_HARDWARE_VERSION_REVISION; brick_init(); wdt_restart(); #ifdef PROFILING profiling_init(); #endif if(usb_is_connected()) { logi("Configure as USB device\n\r"); usb_init(); wdt_restart(); xTaskCreate(usb_message_loop, (signed char *)"usb_ml", 2000, NULL, 1, (xTaskHandle *)NULL); } else { usb_first_connection = false; logi("Configure as Stack Participant (SPI)\n\r"); spi_stack_slave_init(); wdt_restart(); xTaskCreate(spi_stack_slave_message_loop, (signed char *)"spi_ml", 2500, NULL, 1, (xTaskHandle *)NULL); } dc_init(); wdt_restart(); brick_init_start_tick_task(); wdt_restart(); vTaskStartScheduler(); }
USBSerial::operator bool() { return usb_is_connected(USBLIB) && usb_is_configured(USBLIB) && usb_cdcacm_get_dtr(); }
static void menu_renderer(int keycode) { int y = 1; unsigned i; int fh = pf2font_get_fontheight(); struct fbcon_config *config = fbcon_display(); // input handling if(!block_user) { // handle keypress if(keycode==KEY_RIGHT && menu_stack->entries[selection].execute) { menu_execute_entry(menu_stack->entries[selection].execute); return; } if(keycode==KEY_DOWN) { int first_visible = -1; int next_visible = -1; for(i=0; menu_stack->entries[i].name; i++) { if(!menu_stack->entries[i].hide || !menu_stack->entries[i].hide()) { if(first_visible==-1) first_visible = i; if(next_visible==-1 && i>selection) next_visible = i; } } if(next_visible!=-1) selection = next_visible; else selection=first_visible; } if(keycode==KEY_UP) { int last_visible = -1; int previous_visible = -1; for(i=0; menu_stack->entries[i].name; i++) { if(!menu_stack->entries[i].hide || !menu_stack->entries[i].hide()) { last_visible = i; if(i<selection) previous_visible = i; } } if(previous_visible!=-1) selection = previous_visible; else selection=last_visible; } } // clear fbcon_clear(); // title menu_set_color(NORMAL_TEXT_COLOR); pf2font_printf(0, fh*y++, "Fastboot Flash Mode (%s)", ABOOT_VERSION); // USB status if(usb_is_connected()) pf2font_printf(0, fh*y++, "Transfer Mode: USB Connected"); else pf2font_printf(0, fh*y++, "Connect USB Data Cable"); // device info char sn_buf[13]; target_serialno((unsigned char*)sn_buf); pf2font_printf(0, fh*y++, "CPU: %s Serial: %s", TARGET, sn_buf); #if WITH_DEV_PMIC_PM8921 // time unsigned long time; struct rtc_time tm; pm8xxx_rtc_read_time(&time); rtc_time_to_tm(time, &tm); pf2font_printf(0, fh*y++, "Time: %d-%02d-%02d %02d:%02d", tm.tm_year+1900, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min); #endif // divider 1 menu_set_color(DIVIDER_COLOR); menu_draw_divider(fh*y++ - pf2font_get_ascent()/2, 3); // draw interactive UI if(!block_user) { // menu header menu_set_color(NORMAL_TEXT_COLOR); pf2font_printf(0, fh*y++, "Boot Mode Selection Menu"); pf2font_printf(0, fh*y++, " Power Selects, Vol Up/Down Scrolls"); // menu entries for(i=0; menu_stack->entries[i].name; i++) { if(menu_stack->entries[i].hide && menu_stack->entries[i].hide()) continue; char* buf = NULL; if(menu_stack->entries[i].format) menu_stack->entries[i].format(&buf); else buf = strdup(menu_stack->entries[i].name); menu_draw_item(fh*y++, buf, selection==i); if(buf) free(buf); } // divider 2 menu_set_color(DIVIDER_COLOR); menu_draw_divider(fh*y++ - pf2font_get_ascent()/2, 3); } // draw log menu_set_color(LOG_COLOR_NORMAL); mutex_acquire(&logbuf_mutex); int log_top = y; int log_bottom = config->height/fh; int log_size = log_bottom-log_top; int start = (logbuf_row-log_size); for(i=(start>=0?start:0); i<=logbuf_row; i++) { pf2font_printf(0, fh*y++, logbuf[i]); } mutex_release(&logbuf_mutex); // flush fbcon_flush(); };
uint8 USBMidi::isConnected(void) { return usb_is_connected(USBLIB) && usb_is_configured(USBLIB); }