前面测试了最基本的IO、串口、SPI等等,测多了开发板你就知道了,工程模板给你已经开了很多很多功能了,无外乎就是开关个配置复制复制修改修改代码。
所以直接一步到位测一下USB,用的是host-hid demo,可以识别USB鼠标和键盘设备
首先加上之前的OLED驱动
- nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
- system_clock_config();
- at32_board_init();
-
- /* get system clock */
- crm_clocks_freq_get(&crm_clocks_freq_struct);
-
- OLED_Init();
- OLED_SetDir(3);
- OLED_Clear(0);
- OLED_DrawRectangle(5,5,122,59,1);
- OLED_DrawRectangle(15,15,112,49,1);
- OLED_DrawRectangle(25,25,102,39,1);
- OLED_Refresh_Gram();
接着打开一个多少钱用来做定时刷新,因为host需要一直轮询,所以不能占用太多的刷新影响,而工程也没有开启滴答定时器做系统计数,因此不能获取到准确的时基,同于也不能通过循环次数做计时,因为每次循环时间并不一致
- /* enable tmr1 clock */
- crm_periph_clock_enable(CRM_TMR1_PERIPH_CLOCK, TRUE);
- /* tmr1 configuration */
- /* time base configuration */
- tmr_base_init(TMR1, 10-1, (crm_clocks_freq_struct.apb2_freq / 10000) - 1);
- tmr_cnt_dir_set(TMR1, TMR_COUNT_UP);
- /* overflow interrupt enable */
- tmr_interrupt_enable(TMR1, TMR_OVF_INT, TRUE);
- /* tmr1 hall interrupt nvic init */
- nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
- nvic_irq_enable(TMR1_OVF_TMR10_IRQn, 1, 0);
- /* enable tmr1 */
- tmr_counter_enable(TMR1, TRUE);
定时器中断中对变量进行计数,当作时基
- uint32_t tmr_cnt = 0;
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] this function handles timer1 overflow handler.
- * @param none
- * @retval none
- */
- void TMR1_OVF_TMR10_IRQHandler(void)
- {
- if(tmr_interrupt_flag_get(TMR1, TMR_OVF_FLAG) == SET)
- {
- tmr_flag_clear(TMR1, TMR_OVF_FLAG);
- tmr_cnt += 10;
- }
- }
没100毫秒进行一次刷屏,尽量不占用USB轮询
|