#include "config.h"
#include "conf_usb.h"
#include "cdc_task.h"
#include "lib_mcu/usb/usb_drv.h"
#include "usb_descriptors.h"
#include "modules/usb/device_chap9/usb_standard_request.h"
#include "usb_specific_request.h"
#include "lib_mcu/uart/uart_lib.h"
#include "uart_usb_lib.h"
#include "lib_mcu/util/start_boot.h"
#include <stdio.h>
Go to the source code of this file.
Functions | |
void | cdc_task_init (void) |
void | cdc_task (void) |
void | sof_action () |
__interrupt void | usart_receive_interrupt () |
Variables | |
volatile U8 | cpt_sof |
U8 | rx_counter |
U8 | tx_counter |
volatile U8 | usb_request_break_generation |
S_line_coding | line_coding |
S_line_status | line_status |
S_serial_state | serial_state |
volatile U8 | rs2usb [10] |
Definition in file cdc_task.c.
void cdc_task_init | ( | void | ) |
This function initializes the hardware ressources required for CDC demo.
none |
Definition at line 90 of file cdc_task.c.
References Hwb_button_init, Joy_init, Leds_init, Uart_enable_it_rx, uart_init(), uart_usb_getchar(), uart_usb_putchar, and Usb_enable_sof_interrupt.
00091 { 00092 uart_init(); 00093 Uart_enable_it_rx(); 00094 Leds_init(); 00095 Joy_init(); 00096 Hwb_button_init(); 00097 Usb_enable_sof_interrupt(); 00098 #ifdef __GNUC__ 00099 fdevopen((int (*)(char, FILE*))(uart_usb_putchar),(int (*)(FILE*))uart_usb_getchar); //for printf redirection 00100 #endif 00101 }
void cdc_task | ( | void | ) |
Entry point of the uart cdc management This function links the uart and the USB bus.
none |
Definition at line 112 of file cdc_task.c.
References S_serial_state::bDCD, S_serial_state::bDSR, cdc_update_serial_state(), cpt_sof, S_line_status::DTR, FALSE, Is_device_enumerated, Is_hwb, Is_joy_down, Is_joy_left, Is_joy_right, Is_joy_select, Is_joy_up, Led1_toggle, Led2_toggle, REPEAT_KEY_PRESSED, rx_counter, start_boot(), TRUE, uart_putchar(), Uart_tx_ready, uart_usb_getchar(), uart_usb_test_hit(), Usb_detach, and usb_request_break_generation.
00113 { 00114 00115 if(Is_device_enumerated() && line_status.DTR) //Enumeration processs OK and COM port openned ? 00116 { 00117 if (Uart_tx_ready()) //USART free ? 00118 { 00119 if (uart_usb_test_hit()) // Something received from the USB ? 00120 { 00121 while (rx_counter) 00122 { 00123 uart_putchar(uart_usb_getchar()); // loop back USB to USART 00124 Led1_toggle(); 00125 } 00126 } 00127 } 00128 00129 if ( cpt_sof>=REPEAT_KEY_PRESSED) //Debounce joystick events 00130 { 00131 if (Is_joy_select()) { 00132 printf ("Select Pressed !\r\n"); 00133 } 00134 if (Is_joy_right()) { 00135 printf ("Right Pressed !\r\n"); 00136 serial_state.bDCD = TRUE; 00137 } 00138 else 00139 serial_state.bDCD = FALSE; 00140 00141 if (Is_joy_left()) { 00142 printf ("Left Pressed !\r\n"); 00143 serial_state.bDSR = TRUE; 00144 } 00145 else 00146 serial_state.bDSR = FALSE; 00147 00148 if (Is_joy_down()) 00149 printf ("Down Pressed !\r\n"); 00150 00151 if (Is_joy_up()) 00152 printf ("Up Pressed !\r\n"); 00153 00154 if(Is_hwb()) 00155 printf("Hello from ATmega32U4 !\r\n"); 00156 00157 cdc_update_serial_state(); 00158 } 00159 00160 if(usb_request_break_generation==TRUE) 00161 { 00162 U32 volatile tempo; 00163 usb_request_break_generation=FALSE; 00164 Led2_toggle(); 00165 Usb_detach(); // Detach actual USB Device 00166 for(tempo=0;tempo<70000;tempo++); // Wait some time before 00167 start_boot(); // Jumping to booltoader 00168 } 00169 } 00170 }
__interrupt void usart_receive_interrupt | ( | ) |
Uart Receive interrupt subroutine
none |
Definition at line 198 of file cdc_task.c.
References FALSE, Is_device_enumerated, Is_usb_write_enabled, rs2usb, TX_EP, Uart_get_byte, Uart_rx_ready, uart_usb_send_buffer(), Usb_get_selected_endpoint, and Usb_select_endpoint.
00200 { 00201 U8 i=0; 00202 U8 save_ep; 00203 00204 if(Is_device_enumerated()) 00205 { 00206 save_ep=Usb_get_selected_endpoint(); 00207 Usb_select_endpoint(TX_EP); 00208 do 00209 { 00210 if(Uart_rx_ready()) 00211 { 00212 rs2usb[i]=Uart_get_byte(); 00213 i++; 00214 } 00215 }while(Is_usb_write_enabled()==FALSE ); 00216 uart_usb_send_buffer((U8*)&rs2usb,i); 00217 Usb_select_endpoint(save_ep); 00218 } 00219 }
Definition at line 57 of file uart_usb_lib.c.
Referenced by cdc_task(), uart_usb_getchar(), uart_usb_init(), and uart_usb_test_hit().
volatile U8 usb_request_break_generation |
Definition at line 77 of file usb_specific_request.c.
Referenced by cdc_send_break(), and cdc_task().
Definition at line 75 of file cdc_task.c.
Definition at line 76 of file cdc_task.c.
Definition at line 77 of file cdc_task.c.