//======================================= void main(void) { uint8_t remote_id1_packet[NRFR_LENGTH_REPORT_1], remote_id2_packet[NRFR_LENGTH_REPORT_2]; uint8_t i; //======================================= CLKCTL=0; RFCE=0; RFCTL=0x10; rf_init(); // RF初始化 //======================================= hal_usb_init(true, device_req_cb, reset_cb, resume_cb, suspend_cb); hal_usb_endpoint_config(0x81, 32, ep_1_in_cb); // Configure 32 byte IN endpoint 1 EA=1; app_keep_alive_cnt=0; RX_Mode(); //进入接收模式 while(true) { if(RX_DR) { sta=0; for(i=0;i<5;i++) { remote_id1_packet[i]=rx_buf[i]; } for(i=0;i<9;i++) { remote_id2_packet[i]=rx_buf[i+5]; } app_transfer_to_usb(remote_id1_packet, remote_id2_packet); app_keep_alive_cnt=1; delay(100); } app_maintain_keep_alive(); } }
void usb_init(void) { hal_usb_init(true, device_req_cb, reset_cb, resume_cb, suspend_cb); hal_usb_endpoint_config(0x81, USB_MSG_LEN, ep_1_in_cb); //hal_usb_endpoint_config(0x91, USB_MSG_LEN, ep_1_out_cb); is_usb_writing = false; is_usb_data_ready = false; }
void usb_init(void) { hal_usb_init(true, device_req_cb, reset_cb, resume_cb, suspend_cb); hal_usb_endpoint_config(0x81, 32, ep_1_in_cb); //bulk EP IN 1 hal_usb_endpoint_config(0x01, 32, ep_1_out_cb); //bulk EP OUT 1 ep1_sent = true; ep1_receive = false; usb_state = USB_AWAKE; }
void main(void) { data app_states_t app_state = APP_INIT; CLKCTL = 0; // Reset clock control register P0DIR = (1<<3)|(1<<1)|(1<<0); // P0DIR = 0x18; // Output: P0.0 - P0.2, Input: P0.3 - P0.5 // P0ALT = 0; // All general I/O // P0 = 0; /* P0ALT = 0x0F; P0EXP = 0x02; // Slave SPI for P0 SSCONF = 0x01; //Enable slave SPI */ CE_LOW(); // Radio chip enable low RFCTL = 0x10; // Internal MCU to radio SPI enable RFCKEN = 1; // Radio clk enable RF = 1; // Radio IRQ enable // Enable global interrupt /** USB-init **/ usbpair |= 0x01; hal_usb_init(true, device_req_cb, reset_cb, resume_cb, suspend_cb); hal_usb_endpoint_config(0x82, 32, ep_1_in_cb); hal_usb_endpoint_config(0x02, 32, ep_1_out_cb); ep1_sent = true; ep2_sent = true; usb_state = USB_AWAKE; EA = 1; usb_wait_for_configuration(); // Wait until USB enumerated byteCnt = PKTLENGTH; payload[1][PKTLENGTH-1] = 0xAA; payload[0][PKTLENGTH-1] = 0xAA; for(;;) { switch(app_state) { case APP_INIT: app_state = app_init(); break; case APP_NORMAL: // Normal state app_state = app_normal(); break; case APP_SUSP_WE: // PC suspend state, remote wakeup enabled case APP_SUSP_WD: // PC suspend state, remote wakeup disabled // P0_4=1; app_state = app_susp_we(); // P0_4=0; break; default: break; } } return; }