/** * usb_hid_mouse application entry. * * Initializes the system and then monitors buttons, sending the * corresponding character when one is pressed. */ int main(void) { uint8_t bm_buttons = 0; int8_t dx = 0, dy = 0; uint8_t is_changed; /* Disable watchdog */ wdt_disable(); /* Configure console */ board_cfg_console(); printf("-- USB Device HID Mouse Project %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); /* If they are present, configure Vbus & Wake-up pins */ pio_reset_all_it(); /* Initialize all USB power (off) */ usb_power_configure(); #ifdef NO_PUSHBUTTON printf("-- Press I J K L to move cursor\n\r"); #else /* Initialize key statuses and configure push buttons */ pio_configure(pins_joystick, ARRAY_SIZE(pins_joystick)); #endif /* HID driver initialization */ hidd_mouse_driver_initialize(&hidd_mouse_driver_descriptors); /* connect if needed */ usb_vbus_configure(); /* Infinite loop */ while (1) { if (usbd_get_state() < USBD_STATE_CONFIGURED) continue; is_changed = _buttons_monitor(&bm_buttons, &dx, &dy); if (is_changed) { uint8_t status; do { status = hidd_mouse_driver_change_points(bm_buttons, dx, dy); } while (status != USBD_STATUS_SUCCESS); } } }
/** * usb_hid_mouse application entry. * * Initializes the system and then monitors buttons, sending the * corresponding character when one is pressed. */ int main(void) { uint8_t bm_buttons = 0; int8_t dx = 0, dy = 0; uint8_t is_changed; /* Output example information */ console_example_info("USB Device HID Mouse Example"); /* Initialize all USB power (off) */ usb_power_configure(); #ifdef NO_PUSHBUTTON printf("-- Press I J K L to move cursor\n\r"); #else /* Initialize key statuses and configure push buttons */ pio_configure(pins_joystick, ARRAY_SIZE(pins_joystick)); #endif /* HID driver initialization */ hidd_mouse_driver_initialize(&hidd_mouse_driver_descriptors); /* connect if needed */ usb_vbus_configure(); /* Infinite loop */ while (1) { if (usbd_get_state() < USBD_STATE_CONFIGURED) continue; is_changed = _buttons_monitor(&bm_buttons, &dx, &dy); if (is_changed) { uint8_t status; do { status = hidd_mouse_driver_change_points(bm_buttons, dx, dy); } while (status != USBD_STATUS_SUCCESS); } } }
/** * Initializes drivers and start the USB Dual CDC device. */ int main(void) { uint8_t usb_connected = 0; uint8_t serial0_on = 0, serial1_on = 0, usart_on = 0; uint8_t serial0_read = 1; uint8_t serial1_read = 1; /* Output example information */ console_example_info("USB Dual CDC Device Example"); /* If there is on board power, switch it off */ usb_power_configure(); /* ----- CDC Function Initialize */ /* USB DualCDC driver initialization */ dual_cdcd_driver_initialize(&dual_cdcd_driver_descriptors); /* connect if needed */ usb_vbus_configure(); /* Driver loop */ while (1) { /* Device is not configured */ if (usbd_get_state() < USBD_STATE_CONFIGURED) { if (usb_connected) { printf("-I- USB Disconnect/Suspend\n\r"); usb_connected = 0; /* Serial port closed */ is_serial_port0_on = 0; is_serial_port1_on = 0; is_usart_on = 0; } } else { is_serial_port0_on = cdcd_serial_port_get_control_line_state( dual_cdcd_driver_get_serialport(0)) & CDCControlLineState_DTR; is_serial_port1_on = cdcd_serial_port_get_control_line_state( dual_cdcd_driver_get_serialport(1)) & CDCControlLineState_DTR; if (usb_connected == 0) { printf("-I- USB Connect\n\r"); usb_connected = 1; } is_usart_on = is_serial_port0_on || is_serial_port1_on; if (!usart_on && is_usart_on) { usart_on = 1; printf("-I- USART ON\n\r"); } else if (usart_on && !is_usart_on) { usart_on = 0; printf("-I- USART OFF\n\r"); } if (is_serial_port0_on) { if(!serial0_on) { serial0_on = 1; printf("-I- SerialPort0 ON\n\r"); } /* Start receiving data on the USB */ if (serial0_read == 1) { serial0_read = 0; cdcd_serial_port_read(dual_cdcd_driver_get_serialport(0), usb_serial_buffer0, DATAPACKETSIZE, (usbd_xfer_cb_t) _usb_data_received0, &serial0_read); } } else if (serial0_on && !is_serial_port0_on) { serial0_on = 0; printf("-I- SerialPort0 OFF\n\r"); } if (is_serial_port1_on) { if(!serial1_on) { serial1_on = 1; printf("-I- SerialPort1 ON\n\r"); } /* Start receiving data on the USB */ if (serial1_read == 1) { serial1_read = 0; cdcd_serial_port_read(dual_cdcd_driver_get_serialport(1), usb_serial_buffer1, DATAPACKETSIZE, (usbd_xfer_cb_t) _usb_data_received1, &serial1_read); } } else if (serial1_on && !is_serial_port1_on) { serial1_on = 0; printf("-I- SerialPort1 OFF\n\r"); } } } }
/** * \brief usb_cdc_serial Application entry point. * * Initializes drivers and start the USB <-> Serial bridge. */ int main(void) { uint8_t is_usb_connected = 0; uint8_t usb_serial_read = 1; /* Disable watchdog */ wdt_disable(); /* Configure console */ board_cfg_console(); /* Output example information */ printf("-- USB Device CDC Serial Project %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); /* Initialize all USB power (off) */ usb_power_configure(); /* Configure USART */ _configure_usart(); /* CDC serial driver initialization */ cdcd_serial_driver_initialize(&cdcd_serial_driver_descriptors); /* Help informaiton */ _debug_help(); /* connect if needed */ usb_vbus_configure(); /* Driver loop */ while (1) { /* Device is not configured */ if (usbd_get_state() < USBD_STATE_CONFIGURED) { if (is_usb_connected) { is_usb_connected = 0; is_cdc_serial_on = 0; } } else if (is_usb_connected == 0) { is_usb_connected = 1; } /* Serial port ON/OFF */ if (cdcd_serial_driver_get_control_line_state() & CDCControlLineState_DTR) { if (!is_cdc_serial_on) { is_cdc_serial_on = 1; } if(usb_serial_read == 1) { usb_serial_read = 0; /* Start receiving data on the USB */ cdcd_serial_driver_read(usb_buffer, DATAPACKETSIZE, _usb_data_received, &usb_serial_read); } if(usart_rx_flag == true) { usart_rx_flag = false; cdcd_serial_driver_write((void *)&char_recv, 1, 0, 0); if(is_cdc_echo_on) { _usart_dma_tx((uint8_t*)&char_recv, 1); } } } else if (is_cdc_serial_on) { is_cdc_serial_on = 0; } if (console_is_rx_ready()) { uint8_t key = console_get_char(); /* ESC: CDC Echo ON/OFF */ if (key == 27) { printf("** CDC Echo %s\n\r", is_cdc_echo_on ? "OFF" : "ON"); is_cdc_echo_on = !is_cdc_echo_on; } else if (key == 't') { /* 't': Test CDC writing */ _send_text(); } else { printf("Alive\n\r"); cdcd_serial_driver_write((char*)"Alive\n\r", 8, NULL, NULL); _usart_dma_tx((uint8_t*)"Alive\n\r", 8); _debug_help(); } } } }