Exemplo n.º 1
0
/**
 * 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);
		}
	}
}
Exemplo n.º 2
0
/**
 * 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);
		}
	}
}