Ejemplo n.º 1
0
Archivo: ui.c Proyecto: Mazetti/asf
void ui_device_sof_action(void)
{
	uint16_t framenumber;
	static uint8_t cpt_sof = 0;

	if (!ui_device_b_mouse_enable) {
		return;
	}

	framenumber = udd_get_frame_number();
	if ((framenumber % 1000) == 0) {
		LED_On(LED0);
	}

	if ((framenumber % 1000) == 500) {
		LED_Off(LED0);
	}

	/* Scan process running each 2ms */
	cpt_sof++;
	if (2 > cpt_sof) {
		return;
	}

	cpt_sof = 0;

	/* Look touch sensor activity for the X and Y events */
	if (!gpio_pin_is_high(GPIO_PUSH_BUTTON_1)) {
		udi_hid_mouse_moveX(-MOUSE_MOVE_RANGE);
	}
}
/**
 * \brief Handle start of frame
 *
 * Called by USB stack when a start of frame is received, i.e., every
 * millisecond during normal operation. This function triggers processing
 * of the user interface if the HID interface has been enabled.
 */
void main_sof_action(void)
{
	if (!main_b_mouse_enable) {
		return;
	}
	ui_process(udd_get_frame_number());
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: marekr/asf
void main_sof_action(void)
{
	if ((!main_b_msc_enable) ||
		(!main_b_cdc_enable))
		return;
	ui_process(udd_get_frame_number());
}
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;

}
Ejemplo n.º 5
0
Archivo: ui.c Proyecto: scarecrowli/asf
void ui_device_sof_action(void)
{
	uint16_t framenumber;
	static uint8_t cpt_sof = 0;
	static int32_t move_count = MOUSE_MOVE_COUNT;
	static uint8_t move_dir = MOVE_UP;

	if (!ui_device_b_mouse_enable) {
		return;
	}

	framenumber = udd_get_frame_number();
	if ((framenumber % 1000) == 0) {
		LED_On();
	}

	if ((framenumber % 1000) == 500) {
		LED_Off();
	}

	/* Scan process running each 2ms */
	cpt_sof++;
	if (2 > cpt_sof) {
		return;
	}

	cpt_sof = 0;

	/* Uses buttons to move mouse */
	if (!port_pin_get_input_level(BUTTON_0_PIN)) {
		move_count--;
		switch (move_dir) {
		case MOVE_UP:
			udi_hid_mouse_moveY(-MOUSE_MOVE_RANGE);
			if (move_count < 0) {
				move_dir = MOVE_RIGHT;
				move_count = MOUSE_MOVE_COUNT;
			}

			break;

		case MOVE_RIGHT:
			udi_hid_mouse_moveX(+MOUSE_MOVE_RANGE);
			if (move_count < 0) {
				move_dir = MOVE_DOWN;
				move_count = MOUSE_MOVE_COUNT;
			}

			break;

		case MOVE_DOWN:
			udi_hid_mouse_moveY(+MOUSE_MOVE_RANGE);
			if (move_count < 0) {
				move_dir = MOVE_LEFT;
				move_count = MOUSE_MOVE_COUNT;
			}

			break;

		case MOVE_LEFT:
			udi_hid_mouse_moveX(-MOUSE_MOVE_RANGE);
			if (move_count < 0) {
				move_dir = MOVE_UP;
				move_count = MOUSE_MOVE_COUNT;
			}

			break;
		}
	}
}
static void udi_cdc_tx_send(uint8_t port)
{
	irqflags_t flags;
	uint8_t buf_sel_trans;
	bool b_short_packet;
	udd_ep_id_t ep;
	static uint16_t sof_zlp_counter = 0;

#if UDI_CDC_PORT_NB == 1 // To optimize code
	port = 0;
#endif

	if (udi_cdc_tx_trans_ongoing[port]) {
		return; // Already on going or wait next SOF to send next data
	}
	if (udd_is_high_speed()) {
		if (udi_cdc_tx_sof_num[port] == udd_get_micro_frame_number()) {
			return; // Wait next SOF to send next data
		}
	}else{
		if (udi_cdc_tx_sof_num[port] == udd_get_frame_number()) {
			return; // Wait next SOF to send next data
		}
	}

	flags = cpu_irq_save(); // to protect udi_cdc_tx_buf_sel
	buf_sel_trans = udi_cdc_tx_buf_sel[port];
	if (udi_cdc_tx_buf_nb[port][buf_sel_trans] == 0) {
		sof_zlp_counter++;
		if (((!udd_is_high_speed()) && (sof_zlp_counter < 100))
				|| (udd_is_high_speed() && (sof_zlp_counter < 800))) {
			cpu_irq_restore(flags);
			return;
		}
	}
	sof_zlp_counter = 0;

	if (!udi_cdc_tx_both_buf_to_send[port]) {
		// Send current Buffer
		// and switch the current buffer
		udi_cdc_tx_buf_sel[port] = (buf_sel_trans==0)?1:0;
	}else{
		// Send the other Buffer
		// and no switch the current buffer
		buf_sel_trans = (buf_sel_trans==0)?1:0;
	}
	udi_cdc_tx_trans_ongoing[port] = true;
	cpu_irq_restore(flags);

	b_short_packet = (udi_cdc_tx_buf_nb[port][buf_sel_trans] != UDI_CDC_TX_BUFFERS);
	if (b_short_packet) {
		if (udd_is_high_speed()) {
			udi_cdc_tx_sof_num[port] = udd_get_micro_frame_number();
		}else{
			udi_cdc_tx_sof_num[port] = udd_get_frame_number();
		}
	}else{
		udi_cdc_tx_sof_num[port] = 0; // Force next transfer without wait SOF
	}

	// Send the buffer with enable of short packet
	switch (port) {
#define UDI_CDC_PORT_TO_DATA_EP_IN(index, unused) \
	case index: \
		ep = UDI_CDC_DATA_EP_IN_##index; \
		break;
	MREPEAT(UDI_CDC_PORT_NB, UDI_CDC_PORT_TO_DATA_EP_IN, ~)
#undef UDI_CDC_PORT_TO_DATA_EP_IN
	default:
		ep = UDI_CDC_DATA_EP_IN_0;
		break;
	}
	udd_ep_run( ep,
			b_short_packet,
			udi_cdc_tx_buf[port][buf_sel_trans],
			udi_cdc_tx_buf_nb[port][buf_sel_trans],
			udi_cdc_data_sent);
}
Ejemplo n.º 7
0
/*! \brief Main function. Execution starts here.
 */
int main(void)
{

    uint8_t write_data[PATTERN_TEST_LENGTH];
    uint8_t read_data[PATTERN_TEST_LENGTH];
    uint32_t file_size = 0,remaining_len = 0;;

    struct i2c_master_packet tx_buf = {
        .address     = SLAVE_ADDRESS,
        .data_length = PATTERN_TEST_LENGTH,
        .data        = write_data,
        .ten_bit_address = false,
        .high_speed      = false,
        .hs_master_code  = 0x0,
    };
    struct i2c_master_packet rx_buf = {
        .address     = SLAVE_ADDRESS,
        .data_length = 1,
        .data        = read_data,
        .ten_bit_address = false,
        .high_speed      = false,
        .hs_master_code  = 0x0,
    };
    uint8_t nb_twi_packets_sent;
    uint16_t cdc_rx_size;

    irq_initialize_vectors();
    cpu_irq_enable();

    sleepmgr_init();
    system_init();
    configure_usart();

    ui_init();
    ui_powerdown();

    udc_start();
    printf("Start application\r\n");
    while (true) {

        if (!b_com_port_opened) {
            continue;
        }
        if (b_cdc_data_rx == true) {
            b_cdc_data_rx = false;
            cdc_rx_size = udi_cdc_get_nb_received_data();
            udi_cdc_read_buf((void *)cdc_data, cdc_rx_size);
            if (file_size == 0 && cdc_rx_size == 4) {
                MSB0W(file_size) = cdc_data[0];
                MSB1W(file_size) = cdc_data[1];
                MSB2W(file_size) = cdc_data[2];
                MSB3W(file_size) = cdc_data[3];
                printf("File size :%ld\r\n",file_size);
            }
            remaining_len += cdc_rx_size;

            if (cdc_rx_size == TARGET_PAGE_SIZE/2) {
                if (!b_wait) {
                    memcpy((void *)(write_data), (const void *)cdc_data, cdc_rx_size);
                    b_wait = true;
                    if (file_size + 4 == remaining_len) {
                        tx_buf.data_length = TARGET_PAGE_SIZE/2;
                        while (i2c_master_write_packet_wait(&i2c_master_instance, &tx_buf) != STATUS_OK) ;
                    }
                }
                else {
                    memcpy((void *)(write_data + (TARGET_PAGE_SIZE/2)), (const void *)cdc_data, cdc_rx_size);
                    tx_buf.data_length = TARGET_PAGE_SIZE;
                    while (i2c_master_write_packet_wait(&i2c_master_instance, &tx_buf) != STATUS_OK) ;
                    b_wait = false;
                }

            } else {
                if ((cdc_rx_size) <= PATTERN_TEST_LENGTH) {
                    tx_buf.data_length = cdc_rx_size;
                    memcpy((void *)(write_data), (const void *)cdc_data, cdc_rx_size);
                    while (i2c_master_write_packet_wait(&i2c_master_instance, &tx_buf) != STATUS_OK) ;
                } else {
                    nb_twi_packets_sent = 0;
                    while(cdc_rx_size / PATTERN_TEST_LENGTH) {
                        tx_buf.data_length = PATTERN_TEST_LENGTH;
                        memcpy((void *)(write_data), (const void *)(&cdc_data[(nb_twi_packets_sent++) * (PATTERN_TEST_LENGTH)]), PATTERN_TEST_LENGTH);
                        while (i2c_master_write_packet_wait(&i2c_master_instance, &tx_buf) != STATUS_OK) ;
                        cdc_rx_size -= (PATTERN_TEST_LENGTH);
                    }
                    if(cdc_rx_size) {
                        tx_buf.data_length = cdc_rx_size;
                        memcpy((void *)(write_data), (const void *)(&cdc_data[(nb_twi_packets_sent) * (PATTERN_TEST_LENGTH)]), cdc_rx_size);
                        while (i2c_master_write_packet_wait(&i2c_master_instance, &tx_buf) != STATUS_OK) ;
                        cdc_rx_size = 0;
                    }
                }
            }
        }
        if (i2c_master_read_packet_wait(&i2c_master_instance, &rx_buf) == STATUS_OK) {
            udi_cdc_write_buf((const void *)(rx_buf.data),(iram_size_t)read_data[0]);
            if (file_size + 4 == remaining_len) {
                printf("File transfer successfully, file size:%ld, transefer size :%ld\r\n",file_size,remaining_len-4);
            }
        }

    }
}

void main_suspend_action(void)
{
    ui_powerdown();
}

void main_resume_action(void)
{
    ui_wakeup();
}

void main_sof_action(void)
{
    if (!main_b_cdc_enable)
        return;
    ui_process(udd_get_frame_number());
}

#ifdef USB_DEVICE_LPM_SUPPORT
void main_suspend_lpm_action(void)
{
    ui_powerdown();
}

void main_remotewakeup_lpm_disable(void)
{
    ui_wakeup_disable();
}

void main_remotewakeup_lpm_enable(void)
{
    ui_wakeup_enable();
}
#endif

bool main_cdc_enable(uint8_t port)
{
    main_b_cdc_enable = true;
    configure_i2c_master();
    return true;
}

void main_cdc_disable(uint8_t port)
{
    main_b_cdc_enable = false;
    b_com_port_opened = false;
    i2c_master_disable(&i2c_master_instance);
}
Ejemplo n.º 8
0
void main_sof_action(void)
{
	if (!main_b_kbd_enable)
		return;
	ui_process(udd_get_frame_number());
}
Ejemplo n.º 9
0
void main_sof_action(void)
{
	// LCD strings for on-board sensors
	static uint8_t lcd_txt_light[LCD_TEXT_STRING_SIZE + 2 * LCD_TEST_DISPLAY_SIZE]
			= "LIGHT SENSOR     ";
	static uint8_t lcd_txt_ntc[LCD_TEXT_STRING_SIZE + 2 * LCD_TEST_DISPLAY_SIZE]
			= "TEMPERATURE SENSOR     ";
	static uint8_t lcd_txt_pot[LCD_TEXT_STRING_SIZE + 2 * LCD_TEST_DISPLAY_SIZE]
			= "POTENTIOMETER INPUT     ";
	static uint8_t lcd_txt_ext_v[LCD_TEXT_STRING_SIZE + 2 * LCD_TEST_DISPLAY_SIZE]
			= "EXTERNAL VOLTAGE    ";

	static uint8_t old_button;

	if (main_timeout_user_message) {
		// Currently LCD is busy displaying user message from USB
		// Wait end of timeout to display again sensor message
		if (--main_timeout_user_message == 0) {
			switch (main_sensor_selected) {
			case LIGHT_SENSOR:
				ui_display_text(lcd_txt_light,
					sizeof(lcd_txt_light));
				break;
			case TEMPERATURE_SENSOR:
				ui_display_text(lcd_txt_ntc,
					sizeof(lcd_txt_ntc));
				break;
			case POTENTIOMETER_SENSOR:
				ui_display_text(lcd_txt_pot,
					sizeof(lcd_txt_pot));
				break;
			case EXT_VOLTAGE_INPUT:
				ui_display_text(lcd_txt_ext_v,
					sizeof(lcd_txt_ext_v));
			default:
				break;
			}
		}
	}

	// Change LOCAL text display when a button is pressed...
	if (old_button!=ui_button()) {
		old_button=ui_button();
		if (ui_pusb_button_0()) {
			ui_display_text(lcd_txt_light, sizeof(lcd_txt_light));
			main_sensor_selected = LIGHT_SENSOR;
		}
		if (ui_pusb_button_1()) {
			ui_display_text(lcd_txt_ntc, sizeof(lcd_txt_ntc));
			main_sensor_selected = TEMPERATURE_SENSOR;
		}
		if (ui_pusb_button_2()) {
			ui_display_text(lcd_txt_pot, sizeof(lcd_txt_pot));
			main_sensor_selected = POTENTIOMETER_SENSOR;
		}
		if (ui_pusb_button_3()) {
			ui_display_text(lcd_txt_ext_v, sizeof(lcd_txt_ext_v));
			main_sensor_selected = EXT_VOLTAGE_INPUT;
		}
		// If hid generic interface is not up and running, do nothing
		if (!main_b_generic_enable) {
			return;
		}
	}

	// Prepare new report each HID_SEND_REPORT_MS ms
	if ((udd_get_frame_number() % HID_SEND_REPORT_MS) == 0) {
		usb_hid_com_send_report_in();
	}

	// Prepare new ADC samples each ADC_NEW_SAMPLE_MS ms
	if ((udd_get_frame_number() % ADC_NEW_SAMPLE_MS) == 0) {
		adc_sensors_start_conversions();
	}

	// Each LCD_SCROLLING_MS ms Performs LCD scrolling
	if ((udd_get_frame_number() % LCD_SCROLLING_MS) == 0) {
		ui_scroll_text();
	}

	// Refresh on-board sensors LCD display
	// each LCD_SENSOR_MS and if no user message is displayed
	if (((udd_get_frame_number() % LCD_SENSOR_MS) == 0)
		&& (main_timeout_user_message == 0)) {
		switch (main_sensor_selected) {
		case LIGHT_SENSOR:
			ui_display_sensor(adc_sensor_get_light(),
					UI_UNIT_NONE);
			break;
		case TEMPERATURE_SENSOR:
			ui_display_sensor(adc_sensor_get_temperature(),
					UI_UNIT_DEGREE_C);
			break;
		case POTENTIOMETER_SENSOR:
			ui_display_sensor(adc_sensor_get_potentiometer(),
					UI_UNIT_MILIVOLT);
			break;
		case EXT_VOLTAGE_INPUT:
			ui_display_sensor(adc_sensor_get_ext_voltage(),
					UI_UNIT_MILIVOLT);
		default:
			break;
		}
	}
}