/** * This method is called periodically to check for new messages on the USB bus and process them. */ void hid_poll(void) { hid_bootReport message; // Poll the USB layer. usb_poll(); // If no USB device, there's no work for us to be done, so just return. if (hidDevice==NULL) return; // If not connected just return. if (!connected) return; // Check for an incoming HID message. don't wait for incoming packet so set "true" if ( !hid_pollMessage(&message, true) ) {return;} #ifdef DEBUG else { xSerialPrint_P(PSTR("\r\nIN >> ")); hid_printMessage(&message);} #endif // Handle messages if (*theConnection == HID_OPEN ) hid_handleMessage( &message ); else hid_handleOkay( &message ); // we got a character, so set the Connection to OPEN. }
bool PDC_check_key(void) { #ifdef CONFIG_USB_HID usb_poll(); if ((curses_flags & F_ENABLE_CONSOLE) && usbhid_havechar()) { return TRUE; } #endif #ifdef CONFIG_PC_KEYBOARD if ((curses_flags & F_ENABLE_CONSOLE) && keyboard_havechar()) { return TRUE; } #endif #ifdef CONFIG_SERIAL_CONSOLE if ((curses_flags & F_ENABLE_SERIAL) && serial_havechar()) { return TRUE; } #endif return FALSE; }
extern int main ( void ) { usb_init(); for ( ;; ) { usb_poll(); } }
/* * exec() - Main loop * * INPUT * none * OUTPUT * none */ static void exec(void) { usb_poll(); /* Attempt to animate should a screensaver be present */ animate(); display_refresh(); }
static void usb_net_poller(struct NetPoller *poller) { static int usb_initted; if (!usb_initted) dc_usb_initialize(); usb_poll(); }
void main(void) { debug_init(); debug("\r\n\r\nlibci20 firmware\r\n"); while (1) { usb_poll(); } }
void main() { usb_init(); usb_set_idle_handler(idler); while (1) { idler(); usb_poll(); } }
/** * Poll for completed and received packets * * @v netdev Network device */ static void dm96xx_poll ( struct net_device *netdev ) { struct dm96xx_device *dm96xx = netdev->priv; int rc; /* Poll USB bus */ usb_poll ( dm96xx->bus ); /* Refill endpoints */ if ( ( rc = usbnet_refill ( &dm96xx->usbnet ) ) != 0 ) netdev_rx_err ( netdev, NULL, rc ); }
int havekey(void) { #if IS_ENABLED(CONFIG_LP_USB) usb_poll(); #endif struct console_input_driver *in; for (in = console_in; in != 0; in = in->next) if (in->havekey()) return 1; return 0; }
/** * This returns an ASCII value - the two getchar functions * cook the respective input from the device. */ int getchar(void) { while (1) { #ifdef CONFIG_USB usb_poll(); #endif struct console_input_driver *in; for (in = console_in; in != 0; in = in->next) if (in->havechar()) return in->getchar(); } }
void main(void) { init_io(); setup_counter(); usb_init(); ep0_init(); while (1) { read_counter(); usb_poll(); } }
/** * This returns an ASCII value - the two getchar functions * cook the respective input from the device. */ int getchar(void) { while (1) { #if IS_ENABLED(CONFIG_LP_USB) usb_poll(); #endif struct console_input_driver *in; for (in = console_in; in != 0; in = in->next) if (in->havechar()) { last_getchar_input_type = in->input_type; return in->getchar(); } } }
bool cmd_receive(UsbCommand* cmd) { // Check if there is a usb packet available if (!usb_poll()) return false; // Try to retrieve the available command frame size_t rxlen = usb_read((byte_t*)cmd,sizeof(UsbCommand)); // Check if the transfer was complete if (rxlen != sizeof(UsbCommand)) return false; // Received command successfully return true; }
void main(void) { flash_prepare_flashing(); usb_init(&dfu_device); #ifdef SHORT_ISR for (;;) { usb_poll(); } #else sys_yield_for_frogs(); #endif }
static int usbhub_detach(usbdev_t *dev) { usbhub_softc_t *hub; usbdev_t *deldev; int idx; if (!IS_HUB(dev)) return 0; /* should not happen */ hub = dev->ud_private; for (idx = 0; idx < UHUB_MAX_DEVICES; idx++) { deldev = hub->uhub_devices[idx]; if (deldev) { if (usb_noisy > 0) console_log("USB: Removing device attached to bus %d hub %d port %d", dev->ud_bus->ub_num, dev->ud_address,idx+1); if (deldev->ud_drv) { /* close open pipes, cancel reqs */ usb_destroy_all_pipes(deldev); /* * Try to process the done queue. This will complete any * requests that made it out of the pipes while we were * doing the stuff above. */ usb_poll(deldev->ud_bus); /* Call detach method, clean up device softc */ (*(deldev->ud_drv->udrv_detach))(deldev); } else { if (usb_noisy > 0) { console_log("USB: Detached device on bus %d hub %d port %d " "has no methods", dev->ud_bus->ub_num, dev->ud_address,idx+1); } } if (deldev->ud_cfgdescr) usb_dma_free(deldev->ud_cfgdescr); usb_destroy_device(deldev); } } if (hub->uhub_imsg != NULL) { usb_dma_free(hub->uhub_imsg); } KFREE(hub); /* remove softc */ return 0; }
void main() { // Enabling LED to indicate we are in the bootloader GPIOA_PDDR |= (1<<19); // Setup pin - A19 - See Lib/pin_map.mchck for more details on pins PORTA_PCR19 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); GPIOA_PSOR |= (1<<19); flash_prepare_flashing(); usb_init( &dfu_device ); for (;;) { usb_poll(); } }
int main() { usb_init(); hw_init(); // init the class driver here dfu_init(); // register the rx handler function with the dfu //dfu_reg_rx_handler(rx); // and off we go... while (1) { usb_poll(); } }
static int curses_getchar(int _delay) { #if CONFIG(LP_USB_HID) || CONFIG(LP_PC_KEYBOARD) || \ CONFIG(LP_SERIAL_CONSOLE) unsigned short c; #endif do { #if CONFIG(LP_USB_HID) usb_poll(); if ((curses_flags & F_ENABLE_CONSOLE) && usbhid_havechar()) { c = usbhid_getchar(); if (c != 0) return c; } #endif #if CONFIG(LP_PC_KEYBOARD) if ((curses_flags & F_ENABLE_CONSOLE) && keyboard_havechar()) { c = keyboard_getchar(); if (c != 0) return c; } #endif #if CONFIG(LP_SERIAL_CONSOLE) if ((curses_flags & F_ENABLE_SERIAL) && serial_havechar()) { c = serial_getchar(); return cook_serial(c); } #endif if (_delay == 0) { break; } else if (_delay >= 10) { mdelay(10); _delay -= 10; } else if (_delay > 0) { mdelay(_delay); _delay = 0; } } while (1); return ERR; }
static int curses_getchar(int _delay) { #if defined(CONFIG_USB_HID) || defined(CONFIG_PC_KEYBOARD) || defined(CONFIG_SERIAL_CONSOLE) unsigned short c; #endif do { #ifdef CONFIG_USB_HID usb_poll(); if ((curses_flags & F_ENABLE_CONSOLE) && usbhid_havechar()) { c = usbhid_getchar(); if (c != 0) return c; } #endif #ifdef CONFIG_PC_KEYBOARD if ((curses_flags & F_ENABLE_CONSOLE) && keyboard_havechar()) { c = keyboard_getchar(); if (c != 0) return c; } #endif #ifdef CONFIG_SERIAL_CONSOLE if ((curses_flags & F_ENABLE_SERIAL) && serial_havechar()) { c = serial_getchar(); return cook_serial(c); } #endif if (_delay == 0) break; if (_delay > 0) { mdelay(1); _delay--; } } while (1); return ERR; }
/** * Poll for completed and received packets * * @v netdev Network device */ static void smsc95xx_poll ( struct net_device *netdev ) { struct smsc95xx_device *smsc95xx = netdev->priv; uint32_t int_sts; int rc; /* Poll USB bus */ usb_poll ( smsc95xx->bus ); /* Refill endpoints */ if ( ( rc = usbnet_refill ( &smsc95xx->usbnet ) ) != 0 ) netdev_rx_err ( netdev, NULL, rc ); /* Do nothing more unless there are interrupts to handle */ int_sts = smsc95xx->int_sts; if ( ! int_sts ) return; /* Check link status if applicable */ if ( int_sts & SMSC95XX_INT_STS_PHY_INT ) { smsc95xx_check_link ( smsc95xx ); int_sts &= ~SMSC95XX_INT_STS_PHY_INT; } /* Record RX FIFO overflow if applicable */ if ( int_sts & SMSC95XX_INT_STS_RXDF_INT ) { DBGC2 ( smsc95xx, "SMSC95XX %p RX FIFO overflowed\n", smsc95xx ); netdev_rx_err ( netdev, NULL, -ENOBUFS ); int_sts &= ~SMSC95XX_INT_STS_RXDF_INT; } /* Check for unexpected interrupts */ if ( int_sts ) { DBGC ( smsc95xx, "SMSC95XX %p unexpected interrupt %#08x\n", smsc95xx, int_sts ); netdev_rx_err ( netdev, NULL, -ENOTTY ); } /* Clear interrupts */ if ( ( rc = smsc95xx_writel ( smsc95xx, SMSC95XX_INT_STS, smsc95xx->int_sts ) ) != 0 ) netdev_rx_err ( netdev, NULL, rc ); smsc95xx->int_sts = 0; }
void main(void) { rcc_clock_setup_in_hse_8mhz_out_72mhz(); init_systick(); init_usb(); power_init(); lock_init(); // configure status LED rcc_periph_clock_enable(RCC_GPIOC); gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13); // configure buzzer input rcc_periph_clock_enable(RCC_GPIOB); gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO9); gpio_set(GPIOB, GPIO9); // pull up set_state(CLOSED); uint32_t button_start = 0; while(1) { usb_poll(); if(get_state() == CLOSED) gpio_set(GPIOC, GPIO13); else gpio_clear(GPIOC, GPIO13); if(gpio_get(GPIOB, GPIO9) == 0) { if(button_start == 0) button_start = ticks; } else button_start = 0; if(button_start && time_after(ticks, button_start + (HZ/10)) && get_state() == CLOSED) lock(); if(button_start && time_after(ticks, button_start + HZ * 15)) lock(); } }
/** * Poll for completed and received packets * * @v rndis RNDIS device */ static void acm_poll ( struct rndis_device *rndis ) { struct acm_device *acm = rndis->priv; int rc; /* Poll USB bus */ usb_poll ( acm->bus ); /* Refill rings */ if ( ( rc = usbnet_refill ( &acm->usbnet ) ) != 0 ) rndis_rx_err ( rndis, NULL, rc ); /* Retrieve encapsulated response, if applicable */ if ( acm->responded ) { /* Clear flag */ acm->responded = 0; /* Get encapsulated response */ if ( ( rc = acm_control_receive ( acm ) ) != 0 ) rndis_rx_err ( rndis, NULL, rc ); } }
int main(void) { // TIMER 0 Fast PWM, clear OC0A on match TCCR0A = (1 << COM0A1) | (1 << WGM01) | (1 << WGM00); // TIMER 0 Prescaler ck/8 TCCR0B = (1 << CS02); // TIMER 1 Fast PWM 8-bit, clear OC1A, OC1B on match TCCR1A = (1 << COM1A1) | (1 << COM1B1) | (1 << WGM10); // TIMER 1 Prescaler ck/8 TCCR1B = (1 << CS12) | (1 << WGM12); //PWM kanalen als uitgang DDRB = (1 << PB2) | (1 << PB3) | (1 << PB4); //0C0A, 0C1A, OC1B PWM_RED = 0; PWM_GREEN = 0; PWM_BLUE = 0; usb_init(); for (;;) { usb_poll(); } return 0; }
int PDC_get_key(void) { int c = 0; #ifdef CONFIG_USB_HID usb_poll(); if ((curses_flags & F_ENABLE_CONSOLE) && usbhid_havechar()) { c = usbhid_getchar(); } #endif #ifdef CONFIG_PC_KEYBOARD if ((curses_flags & F_ENABLE_CONSOLE) && keyboard_havechar() && (c==0)) { c = keyboard_getchar(); } #endif #ifdef CONFIG_SERIAL_CONSOLE if ((curses_flags & F_ENABLE_SERIAL) && serial_havechar() && (c==0)) { c = cook_serial(serial_getchar()); } #endif SP->key_code = FALSE; if (c == 0) { c = ERR; } if (c >= KEY_MIN) { SP->key_code = TRUE; } return c; }
static int rtek_data_rx( void *ctx ) { rtek_softc_t *softc = (rtek_softc_t *) ctx; usb_poll(softc->dev->ud_bus); return( !softc->rx_ur->ur_inprogress ); }
int _main(unsigned zero, unsigned type, unsigned tags) { const char *cmdline = 0; int n; arm11_clock_init(); /* must do this before board_init() so that we ** use the partition table in the tags if it ** already exists */ if((zero == 0) && (type != 0) && tags_okay(tags)) { linux_type = type; linux_tags = tags; cmdline = tags_get_cmdline((void*) linux_tags); tags_import_partitions((void*) linux_tags); revision = tags_get_revision((void*) linux_tags); if(revision == 1) { console_set_colors(0x03E0, 0xFFFF); } if(revision == 2) { console_set_colors(0x49B2, 0xFFFF); } /* we're running as a second-stage, so wait for interrupt */ boot_from_flash = 0; } else { linux_type = board_machtype(); linux_tags = 0; } board_init(); keypad_init(); console_init(); dprintf_set_putc(uart_putc); if(linux_tags == 0) { /* generate atags containing partitions * from the bootloader, etc */ linux_tags = ADDR_TAGS; create_atags(linux_tags, 0, 0, 0); } if (cmdline) { char *sn = strstr(cmdline, SERIALNO_STR); if (sn) { char *s = serialno; sn += SERIALNO_LEN; while (*sn && (*sn != ' ') && ((s - serialno) < 31)) { *s++ = *sn++; } *s++ = 0; } } cprintf("\n\nUSB FastBoot: V%s\n", get_fastboot_version()); cprintf("Machine ID: %d v%d\n", linux_type, revision); cprintf("Build Date: "__DATE__", "__TIME__"\n\n"); cprintf("Serial Number: %s\n\n", serialno[0] ? serialno : "UNKNOWN"); flash_dump_ptn(); flash_init(); /* scan the keyboard a bit */ for(n = 0; n < 50; n++) { boot_poll(); } if (boot_from_flash) { cprintf("\n ** BOOTING LINUX FROM FLASH **\n"); boot_linux_from_flash(); } usbloader_init(); for(;;) { usb_poll(); } return 0; }
static void usbhub_scan_ports(usbdev_t *dev,void *arg) { uint16_t current; uint16_t changed; usbhub_softc_t *softc; int idx; int res; int len; uint8_t *buf; usbdev_t *newdev; usb_driver_t *newdrv; int addr; usb_port_status_t *portstatus; usb_config_descr_t cfgdescr; unsigned int powerondelay; if (!IS_HUB(dev)) return; /* should not happen. */ portstatus = usb_dma_alloc(sizeof(usb_port_status_t)); if (portstatus == NULL) return; /* * We know this is a hub. Get the softc back. */ softc = (usbhub_softc_t *) dev->ud_private; powerondelay = ((unsigned int) softc->uhub_descr.bPowerOnToPowerGood)*2 + 20; /* * Turn on the power to the ports whose power is not yet on. */ for (idx = 0; idx < softc->uhub_nports; idx++) { usbhub_get_port_status(dev,idx+1,portstatus); current = GETUSBFIELD(portstatus,wPortStatus); changed = GETUSBFIELD(portstatus,wPortChange); if (usb_noisy > 1) { printf("BeforePowerup: port %d status %04X changed %04X\n",idx+1,current,changed); } if (!(current & USB_PORT_STATUS_POWER)) { if (usb_noisy > 1) console_log("USB: Powering up bus %d port %d", dev->ud_bus->ub_num,idx+1); usbhub_set_port_feature(dev,idx+1,USB_PORT_FEATURE_POWER); usb_delay_ms(dev->ud_bus,powerondelay); } } /* * Begin exploration at this level. */ for (idx = 0; idx < softc->uhub_nports; idx++) { usbhub_get_port_status(dev,idx+1,portstatus); current = GETUSBFIELD(portstatus,wPortStatus); changed = GETUSBFIELD(portstatus,wPortChange); if (usb_noisy > 0) { printf("USB: Explore: Bus %d Hub %d port %d status %04X changed %04X\n", dev->ud_bus->ub_num, dev->ud_address,idx+1,current,changed); usb_dbg_dumpportstatus(idx+1,portstatus,1); } // if (changed & USB_PORT_STATUS_RESET) { // usbhub_clear_port_feature(dev,idx+1,USB_PORT_FEATURE_C_PORT_RESET); // } if (changed & USB_PORT_STATUS_ENABLED) { usbhub_clear_port_feature(dev,idx+1,USB_PORT_FEATURE_C_PORT_ENABLE); } if (changed & USB_PORT_STATUS_CONNECT) { /* * A device was either connected or disconnected. * Clear the status change first. */ usbhub_clear_port_feature(dev,idx+1,USB_PORT_FEATURE_C_PORT_CONNECTION); if (current & USB_PORT_STATUS_CONNECT) { /* * The device has been CONNECTED. */ console_log("USB: New device connected to bus %d hub %d port %d", dev->ud_bus->ub_num, dev->ud_address,idx+1); /* * Reset the device. Reuse our old port status structure * so we get the latest status. Some devices do not report * lowspeed until they are reset. */ usbhub_reset_device(dev,idx+1,portstatus); current = GETUSBFIELD(portstatus,wPortStatus); changed = GETUSBFIELD(portstatus,wPortChange); /* * Create a device for this port. */ newdev = usb_create_device(dev->ud_bus,(current & USB_PORT_STATUS_LOWSPD) ? 1 : 0); /* * Get the device descriptor. */ res = usb_get_device_descriptor(newdev,&newdev->ud_devdescr,TRUE); if (usb_noisy > 1) usb_dbg_dumpdescriptors(newdev,(uint8_t *) &(newdev->ud_devdescr),8); /* * Set up the max packet size for the control endpoint, * then get the rest of the descriptor. */ usb_set_ep0mps(newdev,newdev->ud_devdescr.bMaxPacketSize0); res = usb_get_device_descriptor(newdev,&newdev->ud_devdescr,FALSE); /* * Obtain a new address and set the address of the * root hub to this address. */ addr = usb_new_address(newdev->ud_bus); res = usb_set_address(newdev,addr); /* * Get the configuration descriptor and all the * associated interface and endpoint descriptors. */ res = usb_get_config_descriptor(newdev,&cfgdescr,0, sizeof(usb_config_descr_t)); if (res != sizeof(usb_config_descr_t)) { printf("[a] usb_get_config_descriptor returns %d\n",res); } len = GETUSBFIELD(&cfgdescr,wTotalLength); buf = usb_dma_alloc(len); res = usb_get_config_descriptor(newdev,(usb_config_descr_t *)buf,0,len); if (res != len) { printf("[b] usb_get_config_descriptor returns %d\n",res); } newdev->ud_cfgdescr = (usb_config_descr_t *) buf; if (usb_noisy > 1) usb_dbg_dumpdescriptors(newdev,buf,len); /* * Point the hub at the devices it owns */ softc->uhub_devices[idx] = newdev; /* * Find the driver for this. It had better be the hub * driver. */ newdrv = usb_find_driver(newdev); /* * Call the attach method. */ if (newdrv) { newdev->ud_drv = newdrv; /* remember driver dispatch in device */ (*(newdrv->udrv_attach))(newdev,newdrv); } } else { /* * The device has been DISCONNECTED. */ console_log("USB: Device disconnected from bus %d hub %d port %d", dev->ud_bus->ub_num, dev->ud_address,idx+1); /* * Recover pointer to device below hub and clear * this pointer. */ newdev = softc->uhub_devices[idx]; /* Get device pointer */ usbhub_markdetached(newdev); /* mark device and all subordinate devices as "removing" */ softc->uhub_devices[idx] = NULL; /* remove device from hub */ /* * Deassign the USB device's address and then * call detach method to free resources. Devices that * do not have drivers will not have any methods. */ if (newdev) { if (newdev->ud_drv) { /* close open pipes, cancel reqs */ usb_destroy_all_pipes(newdev); /* * Try to process the done queue. This will complete any * requests that made it out of the pipes while we were * doing the stuff above. */ usb_poll(newdev->ud_bus); /* Call detach method, clean up device softc */ (*(newdev->ud_drv->udrv_detach))(newdev); } else { if (usb_noisy > 0) { console_log("USB: Detached device on bus %d hub %d port %d " "has no methods", dev->ud_bus->ub_num, dev->ud_address,idx+1); } } if (newdev->ud_cfgdescr) usb_dma_free(newdev->ud_cfgdescr); usb_destroy_device(newdev); } } } } usb_dma_free(portstatus); /* * Queue up a request for the interrupt pipe. This will catch further * changes at this port. */ usbhub_queue_intreq(dev,softc); }
/** The MAIN loop. */ int main(void) { // Turn off the CPU prescale. CLKPR = 0x80; CLKPR = 0x00; // PORTA are general purpose inputs. DDRA = 0x00; PORTA = 0xff; // pull-ups all enabled PORTD = 0xff; DDRD = 0x00; // pull-ups all enabled DDRF = 0x00; // These are ADC lines. PORTF = 0x00; usb_init(); // Set up Timer 0 to match compare every 1ms. OCR0A = 250; TCCR0A = 0x02; // CTC TCCR0B = 0x03; // CK/64 (64 * 250 == 16000) sei(); char line_buf[128] = {}; uint8_t line_len = 0; uint8_t usb_ready = 0; while (1) { wdt_reset(); g_main_loop_count++; if (usb_configured() && (usb_serial_get_control() & USB_SERIAL_DTR)) { if (!usb_ready) { usb_ready = 1; strcpy_P(line_buf, PSTR("!GNR WELCOME " DEV_VERSION EOL)); usb_serial_write((uint8_t*)line_buf, strlen(line_buf)); line_len = 0; } } else { stream_stop_all(); usb_serial_flush_input(); usb_ready = 0; line_len = 0; g_arm_code = 0; } if (usb_serial_available()) { int16_t c = usb_serial_getchar(); if (c == '\r' || c == '\n') { line_buf[line_len] = 0; handle_line(line_buf); if (g_arm_code) { g_arm_timer = ARM_TIMEOUT_MS; } line_len = 0; } else { line_buf[line_len++] = c & 0xff; if ((line_len + 1) >= sizeof(line_buf)) { /* Clobber the first byte so that this line will be reported as an error. */ line_buf[0] = MAGIC_OVERRUN_CODE; line_len--; } } } if (TIFR0 & (1 << OCF0A)) { TIFR0 |= (1 << OCF0A); g_timer++; stream_timer_update(); hit_timer_update(); g_main_loop_count = (uint16_t) (((uint32_t) g_main_loop_count) * 7 / 8); } stream_poll(); usb_poll(); hit_poll(); } }
static void usb_input_init(void) { dc_usb_initialize(); usb_poll(); }
static void freakusb_pollhandler(void) { usb_poll(); process_poll(&freakusb_process); }