コード例 #1
0
void ui_process(uint16_t framenumber)
{
	bool b_btn_state;
	static bool btn0_last_state = false;
	static bool btn1_last_state = false;
	static uint8_t cpt_sof = 0;

	if ((framenumber % 1000) == 0) {
		LED_On(LED1);
	}
	if ((framenumber % 1000) == 500) {
		LED_Off(LED1);
	}
	/* Scan process running each 40ms */
	cpt_sof++;
	if (cpt_sof < 40) {
		return;
	}
	cpt_sof = 0;

	/* Scan push buttons 1 and 2 */
	b_btn_state = !ioport_get_pin_level(GPIO_PUSH_BUTTON_1);
	if (b_btn_state != btn0_last_state) {
		ui_hid_report[0]=b_btn_state;
		udi_hid_generic_send_report_in(ui_hid_report);
		btn0_last_state = b_btn_state;
	}
	b_btn_state = !ioport_get_pin_level(GPIO_PUSH_BUTTON_2);
	if (b_btn_state != btn1_last_state) {
		ui_hid_report[0]=b_btn_state;
		udi_hid_generic_send_report_in(ui_hid_report);
		btn1_last_state = b_btn_state;
	}
}
コード例 #2
0
void ui_process(uint16_t framenumber)
{
	bool b_btn_state;
	static bool btn0_last_state = false;
	static bool btn1_last_state = false;
	static uint8_t cpt_sof = 0;

	if ((framenumber % 1000) == 0) {
		LED_On(LED0_GPIO);
	}
	if ((framenumber % 1000) == 500) {
		LED_Off(LED0_GPIO);
	}
	// Scan process running each 40ms
	cpt_sof++;
	if (cpt_sof < 40) {
		return;
	}
	cpt_sof = 0;

	// Scan buttons on switch 0 and 1
	b_btn_state = (!gpio_pin_is_high(GPIO_PUSH_BUTTON_1)) ? true : false;
	if (b_btn_state != btn0_last_state) {
		ui_hid_report[0]=b_btn_state;
		udi_hid_generic_send_report_in(ui_hid_report);
		btn0_last_state = b_btn_state;
	}
	b_btn_state = (!gpio_pin_is_high(GPIO_PUSH_BUTTON_2)) ? true : false;
	if (b_btn_state != btn1_last_state) {
		ui_hid_report[0]=b_btn_state;
		udi_hid_generic_send_report_in(ui_hid_report);
		btn1_last_state = b_btn_state;
	}
}
コード例 #3
0
ファイル: ui.c プロジェクト: InSoonPark/asf
void ui_process(uint16_t framenumber)
{
	bool b_btn_state;
	static bool btn0_last_state = false;
	static bool btn1_last_state = false;
	static bool btn2_last_state = false;
	static bool btnq_last_state = false;
	static uint8_t cpt_sof = 0;

	if ((framenumber % 1000) == 0) {
		LED_On(LED1_GPIO);
	}
	if ((framenumber % 1000) == 500) {
		LED_Off(LED1_GPIO);
	}
	// Scan process running each 40ms
	cpt_sof++;
	if (40 > cpt_sof)
		return;
	cpt_sof = 0;

	// Scan buttons on switch 0, 1 and 2
	b_btn_state = (gpio_pin_is_low(GPIO_PUSH_BUTTON_0)) ? true : false;
	if (b_btn_state != btn0_last_state) {
		ui_hid_report[0]=b_btn_state;
		udi_hid_generic_send_report_in(ui_hid_report);
		btn0_last_state = b_btn_state;
	}

	b_btn_state = (gpio_pin_is_low(GPIO_PUSH_BUTTON_1)) ? true : false;
	if (b_btn_state != btn1_last_state) {
		ui_hid_report[0]=b_btn_state;
		udi_hid_generic_send_report_in(ui_hid_report);
		btn1_last_state = b_btn_state;
	}

	b_btn_state = (gpio_pin_is_low(GPIO_PUSH_BUTTON_2)) ? true : false;
	if (b_btn_state != btn2_last_state) {
		ui_hid_report[0]=b_btn_state;
		udi_hid_generic_send_report_in(ui_hid_report);
		btn2_last_state = b_btn_state;
	}

	// Scan QTouch button
	b_btn_state = (!check_touch_key_pressed()) ? true : false;
	if (b_btn_state != btnq_last_state) {
		ui_hid_report[0]=b_btn_state;
		udi_hid_generic_send_report_in(ui_hid_report);
		btnq_last_state = b_btn_state;
	}
}
コード例 #4
0
ファイル: ui.c プロジェクト: Timvrakas/samd21_gcc
void ui_process(uint16_t framenumber)
{
	bool b_btn_state;
	static bool btn0_last_state = false;
	static uint8_t cpt_sof = 0;

	// Blink LED
	if (ui_b_led_blink) {
		if ((framenumber % 1000) == 0) {
			LED_On(LED_0_PIN);
		}
		if ((framenumber % 1000) == 500) {
			LED_Off(LED_0_PIN);
		}
	}

	// Scan process running each 40ms
	cpt_sof++;
	if (cpt_sof < 40) {
		return;
	}
	cpt_sof = 0;

	// Scan buttons
	b_btn_state = !port_pin_get_input_level(BUTTON_0_PIN);
	if (b_btn_state != btn0_last_state) {
		ui_hid_report[0] = b_btn_state;
		udi_hid_generic_send_report_in(ui_hid_report);
		btn0_last_state = b_btn_state;
	}
}
コード例 #5
0
void usb_hid_com_send_report_in(void)
{
	// Fill HID report fields
	report_to_send.light = adc_sensor_get_light();
	report_to_send.temperature = adc_sensor_get_temperature();
	report_to_send.ext_voltage = adc_sensor_get_ext_voltage();
	report_to_send.potentiometer = adc_sensor_get_potentiometer();
	report_to_send.buttons = ui_button();
	report_to_send.sensor_selected = main_get_sensor_selected();
	// Send HID report in background
	udi_hid_generic_send_report_in((uint8_t*)&report_to_send);
}
コード例 #6
0
void main_sof_action(void)
{
	static bool btn_last_state = 0;
	bool btn_state = ui_button();
	
	if (!main_b_generic_enable)
		return;
	ui_process(udd_get_frame_number());
	if(btn_state!=btn_last_state) {
		report_to_send[0]=btn_state;
		udi_hid_generic_send_report_in(report_to_send);
	}
	btn_last_state=btn_state;

}
コード例 #7
0
/**************************************************************************************************
* Handle received HID set feature reports
*/
void HID_set_feature_report_out(uint8_t *report)
{
	uint8_t		response[UDI_HID_REPORT_OUT_SIZE];
	response[0] = report[0] | 0x80;
	response[1] = report[1];
	response[2] = report[2];
	
	uint16_t	addr;
	addr = *(uint16_t *)(report+1);

	switch(report[0])
	{
		// no-op
		case CMD_NOP:
			break;
		
		// write to RAM page buffer
		case CMD_RESET_POINTER:
			page_ptr = 0;
			return;

		// read from RAM page buffer
		case CMD_READ_BUFFER:
			memcpy(response, &page_buffer[page_ptr], UDI_HID_REPORT_OUT_SIZE);
			page_ptr += UDI_HID_REPORT_OUT_SIZE;
			page_ptr &= APP_SECTION_PAGE_SIZE-1;
			break;

		// erase entire application section
		case CMD_ERASE_APP_SECTION:
			SP_WaitForSPM();
			SP_EraseApplicationSection();
			return;

		// calculate application and bootloader section CRCs
		case CMD_READ_FLASH_CRCS:
			SP_WaitForSPM();
			*(uint32_t *)&response[3] = SP_ApplicationCRC();
			*(uint32_t *)&response[7] = SP_BootCRC();
			break;

		// read MCU IDs
		case CMD_READ_MCU_IDS:
			response[3] = MCU.DEVID0;
			response[4] = MCU.DEVID1;
			response[5] = MCU.DEVID2;
			response[6] = MCU.REVID;
			break;
		
		// read fuses
		case CMD_READ_FUSES:
			response[3] = SP_ReadFuseByte(0);
			response[4] = SP_ReadFuseByte(1);
			response[5] = SP_ReadFuseByte(2);
			response[6] = 0xFF;
			response[7] = SP_ReadFuseByte(4);
			response[8] = SP_ReadFuseByte(5);
			break;
		
		// write RAM page buffer to application section page
		case CMD_WRITE_PAGE:
			if (addr > (APP_SECTION_SIZE / APP_SECTION_PAGE_SIZE))	// out of range
			{
				response[1] = 0xFF;
				response[2] = 0xFF;
				break;
			}
			SP_WaitForSPM();
			SP_LoadFlashPage(page_buffer);
			SP_WriteApplicationPage(APP_SECTION_START + ((uint32_t)addr * APP_SECTION_PAGE_SIZE));
			page_ptr = 0;
			break;

		// read application page to RAM buffer and return first 32 bytes
		case CMD_READ_PAGE:
			if (addr > (APP_SECTION_SIZE / APP_SECTION_PAGE_SIZE))	// out of range
			{
				response[1] = 0xFF;
				response[2] = 0xFF;
			}
			else
			{
				memcpy_P(page_buffer, (const void *)(APP_SECTION_START + (APP_SECTION_PAGE_SIZE * addr)), APP_SECTION_PAGE_SIZE);
				memcpy(&response[3], page_buffer, 32);
				page_ptr = 0;
			}
			break;
		
		// erase user signature row
		case CMD_ERASE_USER_SIG_ROW:
			SP_WaitForSPM();
			SP_EraseUserSignatureRow();
			break;
		
		// write RAM buffer to user signature row
		case CMD_WRITE_USER_SIG_ROW:
			SP_WaitForSPM();
			SP_LoadFlashPage(page_buffer);
			SP_WriteUserSignatureRow();
			break;

		// read user signature row to RAM buffer and return first 32 bytes
		case CMD_READ_USER_SIG_ROW:
			if (addr > (USER_SIGNATURES_PAGE_SIZE - 32))
			{
				response[1] = 0xFF;
				response[2] = 0xFF;
			}
			else
			{
				memcpy_P(page_buffer, (const void *)(USER_SIGNATURES_START + addr), USER_SIGNATURES_SIZE);
				memcpy(&response[3], page_buffer, 32);
				page_ptr = 0;
			}
			break;

		case CMD_READ_SERIAL:
			{
				uint8_t	i;
				uint8_t	j = 3;
				uint8_t b;
	
				for (i = 0; i < 6; i++)
				{
					b = SP_ReadCalibrationByte(offsetof(NVM_PROD_SIGNATURES_t, LOTNUM0) + i);
					response[j++] = hex_to_char(b >> 4);
					response[j++] = hex_to_char(b & 0x0F);
				}
				response[j++] = '-';
				b = SP_ReadCalibrationByte(offsetof(NVM_PROD_SIGNATURES_t, LOTNUM0) + 6);
				response[j++] = hex_to_char(b >> 4);
				response[j++] = hex_to_char(b & 0x0F);
				response[j++] = '-';

				for (i = 7; i < 11; i++)
				{
					b = SP_ReadCalibrationByte(offsetof(NVM_PROD_SIGNATURES_t, LOTNUM0) + i);
					response[j++] = hex_to_char(b >> 4);
					response[j++] = hex_to_char(b & 0x0F);
				}

				response[j] = '\0';
				break;
			}
		
		case CMD_READ_BOOTLOADER_VERSION:
			response[3] = BOOTLOADER_VERSION;
			break;
		
		case CMD_RESET_MCU:
			reset_do_soft_reset();
			response[1] = 0xFF;	// failed
			break;
		
		case CMD_READ_EEPROM:
			if (addr > (EEPROM_SIZE - 32))
			{
				response[1] = 0xFF;
				response[2] = 0xFF;
			}
			else
			{
				EEP_EnableMapping();
				memcpy_P(page_buffer, (const void *)(MAPPED_EEPROM_START + addr), APP_SECTION_PAGE_SIZE);
				EEP_DisableMapping();
				memcpy(&response[3], page_buffer, 32);
				page_ptr = 0;
			}
			break;

		case CMD_WRITE_EEPROM:
			if (addr > (EEPROM_SIZE / EEPROM_PAGE_SIZE))
			{
				response[1] = 0xFF;
				response[2] = 0xFF;
			}
			else
			{
				EEP_LoadPageBuffer(&report[3], EEPROM_PAGE_SIZE);
				EEP_AtomicWritePage(addr);
			}
			break;
		
		// unknown command
		default:
			response[0] = 0xFF;
			break;
	}

	udi_hid_generic_send_report_in(response);
}
コード例 #8
0
ファイル: hid.c プロジェクト: kuro68k/Superplay
/**************************************************************************************************
** Send a latest report over HID
*/
void HID_send_report(void)
{
	static uint8_t last_rot = 0xFF;
	static bool rot_left = false;
	static bool rot_right = false;
	static bool inhibit = false;

	HID_REPORT_t	hid_report;
	
	if (!HID_enabled)
		return;
	
	memset(&hid_report, 0, sizeof(hid_report));
	
	if (!VEN_enabled)	// only send HID reports if not using high frequency interface
	{
		hid_report.x = 0;
		hid_report.y = 0;
		if (logical_inputs[LJOY_UP])		hid_report.y = -127;
		if (logical_inputs[LJOY_DN])		hid_report.y = 127;
		if (logical_inputs[LJOY_RT])		hid_report.x = 127;
		if (logical_inputs[LJOY_LF])		hid_report.x = -127;

		if (logical_inputs[LBUTTON1])		hid_report.buttons1 |= (1<<0);
		if (logical_inputs[LBUTTON2])		hid_report.buttons1 |= (1<<1);
		if (logical_inputs[LBUTTON3])		hid_report.buttons1 |= (1<<2);
		if (logical_inputs[LBUTTON4])		hid_report.buttons1 |= (1<<3);
		if (logical_inputs[LBUTTON5])		hid_report.buttons1 |= (1<<4);
		if (logical_inputs[LBUTTON6])		hid_report.buttons1 |= (1<<5);
		if (logical_inputs[LBUTTON7])		hid_report.buttons1 |= (1<<6);
		if (logical_inputs[LBUTTON8])		hid_report.buttons1 |= (1<<7);
		if (logical_inputs[LBUTTON9])		hid_report.buttons2 |= (1<<0);
		if (logical_inputs[LBUTTON10])		hid_report.buttons2 |= (1<<1);
		if (logical_inputs[LBUTTON11])		hid_report.buttons2 |= (1<<2);
		if (logical_inputs[LBUTTON12])		hid_report.buttons2 |= (1<<3);
		if (logical_inputs[LBUTTON13])		hid_report.buttons2 |= (1<<4);
		if (logical_inputs[LBUTTON14])		hid_report.buttons2 |= (1<<5);
		if (logical_inputs[LBUTTON15])		hid_report.buttons2 |= (1<<6);
		if (logical_inputs[LBUTTON16])		hid_report.buttons2 |= (1<<7);
		
		if (logical_inputs[LSTART])			hid_report.buttons3 |= (1<<0);
		if (logical_inputs[LCOIN])			hid_report.buttons3 |= (1<<1);
		if (logical_inputs[LCONTROL])		hid_report.buttons3 |= (1<<2);
		if (logical_inputs[LUNUSED])		hid_report.buttons3 |= (1<<3);

		// rotary
		if (!rot_left && !rot_right && !inhibit)
		{
			uint8_t new_rot = hid_find_rotary_pos();
			if (new_rot != -1)
			{
				if (last_rot == 0xFF)
					last_rot = new_rot;

				// determine clockwise/anti-clockwise movement
				if ((last_rot != new_rot) && (new_rot != 0xF))
				{
					if ((last_rot > 9) && (new_rot < 3))
						rot_left = true;
					else if ((last_rot < 3) && (new_rot > 9))
						rot_right = true;
					else if (last_rot > new_rot)
						rot_right = true;
					else
						rot_left = true;

					last_rot = new_rot;
			
					// restart time
					HID_TC.CTRLA = 0;
					HID_TC.CNT = 0;
					HID_TC.INTFLAGS = TC0_OVFIF_bm;
					HID_TC.CTRLA = HID_TC_CLKSEL;
				}
			}
		}
		
		// check for end of left/right button press
		if (HID_TC.INTFLAGS & TC0_OVFIF_bm)
		{
			if (inhibit)	// end of fake button press
			{
				HID_TC.CTRLA = 0;
				HID_TC.INTFLAGS = TC0_OVFIF_bm;
				inhibit = false;
			}
			else			// start inhibit phase
			{
				HID_TC.CTRLA = 0;
				HID_TC.CNT = 0;
				HID_TC.INTFLAGS = TC0_OVFIF_bm;
				HID_TC.CTRLA = HID_TC_CLKSEL;
				rot_left = false;
				rot_right = false;
				inhibit = true;
			}
		}
		
		if (rot_left)	hid_report.buttons3 |= HID_ROTATE_LEFT_BUTTON_bm;
		if (rot_right)	hid_report.buttons3 |= HID_ROTATE_RIGHT_BUTTON_bm;
	}
	
	udi_hid_generic_send_report_in((uint8_t *)&hid_report);
}
コード例 #9
0
ファイル: hid.c プロジェクト: kuro68k/Superplay
/**************************************************************************************************
** Accept commands from host (KBUS)
*/
void HID_set_feature(uint8_t *report)
{
	KBUS_PACKET_t response;
	KBUS_process_command((KBUS_PACKET_t *)report, &response);
	udi_hid_generic_send_report_in((uint8_t *)&response);
}