/** * \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()); }
int main (int argc, char **argv) { /* Disable watchdog if enabled by bootloader/fuses */ MCUSR &= ~(1 << WDRF); wdt_disable(); // Assert pshold to stay powered on OUTPUT(pshold); HIGH(pshold); // En fast batt charging OUTPUT(usb_i_sel); LOW(usb_i_sel); // Init UI ui_setup(); // do nothing while(1) { // Usb processing //ser.process(); done on timer // Update ui ui_process(); } }
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; }
/*! \brief Main function. Execution starts here. */ int main(void) { irq_initialize_vectors(); cpu_irq_enable(); // Initialize the sleep manager sleepmgr_init(); #if !SAMD21 && !SAMR21 && !SAMD11 && !SAML21 sysclk_init(); board_init(); #else system_init(); #endif ui_init(); ui_powerdown(); // Start USB stack to authorize VBus monitoring udc_start(); // The main loop manages only the power mode // because the USB management is done by interrupt while (true) { #ifdef USB_DEVICE_LOW_SPEED // No USB "Keep a live" interrupt available in low speed // to scan generic interface then use main loop if (main_b_generic_enable) { static volatile uint16_t virtual_sof_sub = 0; static uint16_t virtual_sof = 0; if (sysclk_get_cpu_hz()/50000 == virtual_sof_sub++) { virtual_sof_sub = 0; static uint16_t virtual_sof = 0; ui_process(virtual_sof++); } } #else sleepmgr_enter_sleep(); #endif } }
/*! \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); }
void main_sof_action(void) { if (!main_b_kbd_enable) return; ui_process(udd_get_frame_number()); }
/** * \brief Main application function * * This function ensures that the hardware and drivers are initialized before * entering an infinite work loop. * * In the work loop, the maXTouch device is polled for new touch events and any * new event is passed on to the user interface implementation for processing. * The loop then attempts to enter sleep. * * The user interface processing itself is not started by the work loop, but by * the USB callback function for start of frame. */ int main(void) { #ifdef USB_DEVICE_LOW_SPEED uint16_t virtual_sof_sub; uint16_t virtual_sof; #endif /* maXTouch data structure */ static struct mxt_device device; /* Initialize system clocks */ sysclk_init(); /* Initialize interrupt vectors */ irq_initialize_vectors(); /* Enable interrupts */ cpu_irq_enable(); /* Initialize the sleep manager */ sleepmgr_init(); /* Initialize the board */ board_init(); /* Initialize the mXT touch device */ mxt_init(&device); /* Initialize the graphical library */ gfx_init(); /* Set correct landscape orientation */ gfx_set_orientation(GFX_SWITCH_XY | GFX_FLIP_Y); /* Set background color */ gfx_draw_filled_rect(0, 0, gfx_get_width(), gfx_get_height(), COLOR_BACKGROUND); /* Draw the help text */ gfx_draw_string_aligned( "Middle finger to move cursor\n" "Index finger to left click\n" "Ring finger to right click", gfx_get_width() / 2, gfx_get_height() / 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_CENTER, TEXT_ALIGN_CENTER); /* Initialize the user interface */ ui_init(); ui_powerdown(); /* Start USB stack to authorize VBus monitoring */ udc_start(); /* Check if there are any new touch data pending */ while (true) { if (mxt_is_message_pending(&device)) { if (mxt_read_touch_event(&device, &ui_touch_event) == STATUS_OK) { ui_flag_new_touch_event(); } } /* Try to sleep */ sleepmgr_enter_sleep(); #ifdef USB_DEVICE_LOW_SPEED /* No USB "Keep alive" interrupt available in low speed * to scan mouse interface then use main loop */ if (main_b_mouse_enable) { virtual_sof_sub = 0; virtual_sof = 0; if (virtual_sof_sub++ == 700) { virtual_sof_sub = 0; ui_process(virtual_sof++); } } #endif } }