void WiiRemote::task(void (*pFunc)(void)) { Max.Task(); Usb.Task(); delay(1); // re-initialize if (Usb.getUsbTaskState() == USB_DETACHED_SUBSTATE_INITIALIZE) { /* TODO */ wiiremote_status_ = 0; } // wait for addressing state if (Usb.getUsbTaskState() == USB_STATE_CONFIGURING) { initBTController(); if (wiiremote_status_ & WIIREMOTE_STATE_USB_CONFIGURED) { hci_state_ = HCI_INIT_STATE; hci_counter_ = 10; l2cap_state_ = L2CAP_DOWN_STATE; Usb.setUsbTaskState(USB_STATE_RUNNING); } } if (Usb.getUsbTaskState() == USB_STATE_RUNNING) { HCI_task(); // poll the HCI event pipe L2CAP_task(); // start polling the ACL input pipe too, though discard // data until connected } //if (l2cap_state_ == L2CAP_READY_STATE) { if (wiiremote_status_ & WIIREMOTE_STATE_RUNNING) { if (pFunc) { pFunc(); } } } // task
GamepadState Gamepad::readGamepad() { GamepadState state; #if defined(__AVR_ATmega328P__) USB usb; state = usb.readJoystick(); #elif defined(__AVR_ATmega32U4__) // Read the button values. state.buttons = 0; state.buttons |= (!Esplora.readButton(SWITCH_1)) << GAMEPAD_BUTTON_1; state.buttons |= (!Esplora.readButton(SWITCH_2)) << GAMEPAD_BUTTON_2; state.buttons |= (!Esplora.readButton(SWITCH_3)) << GAMEPAD_BUTTON_3; state.buttons |= (!Esplora.readButton(SWITCH_4)) << GAMEPAD_BUTTON_4; // TODO: Create an enum for the Esplora joystick button. state.buttons |= (!Esplora.readJoystickButton()) << GAMEPAD_BUTTON_L1; // For some reason, the Esplora joystick is negative on the right and positive // on the left. It needs to be inverted. state.x = GetAdjustedEsploraJoystickValue(-Esplora.readJoystickX()); state.y = GetAdjustedEsploraJoystickValue(Esplora.readJoystickY()); return state; #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #error "Arduinos with Atmega1280 and Atmega2560 not yet supported." #endif return state; }
int App::run() { while (true) busby.puts("pharmacist\r\n"); return 0; }
void setup() { pinMode(LED_PIN, OUTPUT); if (Usb.Init() == -1) { while(1) { errorBlink(); } } }
int main(void) { dbgled(0); iprintf("start\n"); uc.attach(&u); // msc.attach(&u); ecm.setMAC(mac); ecm.attach(&u); iprintf("u.dump\n"); u.dumpDescriptors(); iprintf("u.init\n"); u.init(); sysclock.setTimeout(5 S); // because leds[0] is connected to USB_UP_LED signal and usb hardware takes it over leds[0].setup(); // dbgled(15); // int l = 0; while (1) { // u.USBHW::HwISR(); if (sysclock.poll()) { // iprintf("-------------------\n"); // iprintf("USBClkCtrl: 0x%8lX\n", LPC_USB->USBClkCtrl); // iprintf("USBClkSt: 0x%8lX\n", LPC_USB->USBClkSt); // iprintf("USBIntSt: 0x%8lX\n", LPC_SC->USBIntSt); // iprintf("USBDevIntSt: 0x%8lX\n", LPC_USB->USBDevIntSt); // iprintf("USBDevIntEn: 0x%8lX\n", LPC_USB->USBDevIntEn); // iprintf("USBDevIntPri: 0x%8lX\n", LPC_USB->USBDevIntPri); iprintf("Fr: %d\n", u.USBCTRL::lastFrame()); } w.feed(); // l++; // if ((l & ((1UL << 19) - 1UL)) == 0) // dbgled(l >> 19); } }
void loop() { Usb.Task(); if (!adk.isReady()) { return; } readMessage(); }
int main() { // Default pins to low status for (int i = 0; i < 5; i++){ leds[i].output(); leds[i] = (i & 1) ^ 1; } //bool sdok= (sd.disk_initialize() == 0); sd.disk_initialize(); Kernel* kernel = new Kernel(); kernel->streams->printf("Smoothie ( grbl port ) version 0.8.0-rc1 with new accel @%ldMHz\r\n", SystemCoreClock / 1000000); Version version; kernel->streams->printf(" Build version %s, Build date %s\r\n", version.get_build(), version.get_build_date()); // Create and add main modules kernel->add_module( new Laser() ); kernel->add_module( new Extruder() ); kernel->add_module( new SimpleShell() ); kernel->add_module( new Configurator() ); kernel->add_module( new CurrentControl() ); kernel->add_module( new TemperatureControlPool() ); kernel->add_module( new SwitchPool() ); kernel->add_module( new PauseButton() ); kernel->add_module( new PlayLed() ); kernel->add_module( new Endstops() ); kernel->add_module( new Player() ); kernel->add_module( new Panel() ); kernel->add_module( new Touchprobe() ); // Create and initialize USB stuff u.init(); //if(sdok) { // only do this if there is an sd disk // msc= new USBMSD(&u, &sd); // kernel->add_module( msc ); //} kernel->add_module( &msc ); kernel->add_module( &usbserial ); if( kernel->config->value( second_usb_serial_enable_checksum )->by_default(false)->as_bool() ){ kernel->add_module( new USBSerial(&u) ); } kernel->add_module( &dfu ); kernel->add_module( &u ); // clear up the config cache to save some memory kernel->config->config_cache_clear(); // Main loop while(1){ kernel->call_event(ON_MAIN_LOOP); kernel->call_event(ON_IDLE); } }
void setup() { Serial.begin(115200); Serial.println("Welcome to Scopduino"); pinMode(LED_PIN, OUTPUT); DDRF = 0x00; memset(g_storage_space, 0, sizeof(g_storage_space)); if (g_usb.Init() == -1) { Serial.println("OSCOKIRQ failed to assert"); } }
void processUsb() { uint8_t rcode; g_usb.Task(); if (g_adk.isReady() == false) { digitalWrite(LED_PIN, 0); return; } digitalWrite(LED_PIN, g_storage_buffer_index); rcode = g_adk.SndData(STORAGE_SIZE, g_storage_space[g_storage_index]); if (rcode) { Serial.print("USB send: "); Serial.println(rcode); } }
int main() { // Default pins to low status for (int i = 0; i < 5; i++){ leds[i].output(); leds[i] = (i & 1) ^ 1; } sd.disk_initialize(); Kernel* kernel = new Kernel(); kernel->streams->printf("Smoothie ( grbl port ) version 0.7.2 @%dMHz\r\n", SystemCoreClock / 1000000); // Create and add main modules kernel->add_module( new Laser() ); kernel->add_module( new Extruder() ); kernel->add_module( new SimpleShell() ); kernel->add_module( new Configurator() ); kernel->add_module( new CurrentControl() ); kernel->add_module( new TemperatureControlPool() ); kernel->add_module( new SwitchPool() ); kernel->add_module( new ButtonPool() ); kernel->add_module( new PauseButton() ); kernel->add_module( new PlayLed() ); kernel->add_module( new Endstops() ); kernel->add_module( new Player() ); // Create and initialize USB stuff u.init(); kernel->add_module( &msc ); kernel->add_module( &usbserial ); if( kernel->config->value( second_usb_serial_enable_checksum )->by_default(false)->as_bool() ){ kernel->add_module( new USBSerial(&u) ); } kernel->add_module( &dfu ); kernel->add_module( &u ); // Main loop while(1){ kernel->call_event(ON_MAIN_LOOP); kernel->call_event(ON_IDLE); } }
void WiiRemote::HCI_event_task(void) { uint8_t rcode = 0; // return code uint8_t buf[MAX_BUFFER_SIZE] = {0}; // check input on the event pipe (endpoint 1) rcode = Usb.inTransfer(BT_ADDR, ep_record_[ EVENT_PIPE ].epAddr, MAX_BUFFER_SIZE, (char *) buf, USB_NAK_NOWAIT); /* DEBUG_PRINT_P( PSTR("\r\nHCI_event_task: rcode = 0x") ); DEBUG_PRINT(rcode, HEX); */ if (!rcode) { /* buf[0] = Event Code */ /* buf[1] = Parameter Total Length */ /* buf[n] = Event Parameters based on each event */ DEBUG_PRINT_P( PSTR("\r\nHCI event = 0x") ); DEBUG_PRINT(buf[0], HEX); switch (buf[0]) { // switch on event type case HCI_EVENT_COMMAND_COMPLETE: hci_event_flag_ |= HCI_FLAG_COMMAND_COMPLETE; break; case HCI_EVENT_INQUIRY_RESULT: hci_event_flag_ |= HCI_FLAG_INQUIRY_RESULT; /* assume that Num_Responses is 1 */ DEBUG_PRINT_P( PSTR("\r\nFound WiiRemote BD_ADDR:\t") ); for (uint8_t i = 0; i < 6; i++) { wiiremote_bdaddr_[5-i] = (uint8_t) buf[3+i]; DEBUG_PRINT(wiiremote_bdaddr_[5-i], HEX); } break; case HCI_EVENT_INQUIRY_COMPLETE: hci_event_flag_ |= HCI_FLAG_INQUIRY_COMPLETE; break; case HCI_EVENT_COMMAND_STATUS: hci_event_flag_ |= HCI_FLAG_COMMAND_STATUS; #if WIIREMOTE_DEBUG if (buf[2]) { // show status on serial if not OK DEBUG_PRINT_P( PSTR("\r\nHCI Command Failed: ") ); DEBUG_PRINT_P( PSTR("\r\n\t Status = ") ); DEBUG_PRINT(buf[2], HEX); DEBUG_PRINT_P( PSTR("\r\n\tCommand_OpCode(OGF) = ") ); DEBUG_PRINT( ((buf[5] & 0xFC) >> 2), HEX); DEBUG_PRINT_P( PSTR("\r\n\tCommand_OpCode(OCF) = ") ); DEBUG_PRINT( (buf[5] & 0x03), HEX); DEBUG_PRINT(buf[4], HEX); } #endif break; case HCI_EVENT_CONNECT_COMPLETE: hci_event_flag_ |= HCI_FLAG_CONNECT_COMPLETE; if (!buf[2]) { // check if connected OK // store the handle for the ACL connection hci_handle_ = buf[3] | ((buf[4] & 0x0F) << 8); hci_event_flag_ |= HCI_FLAG_CONNECT_OK; } break; case HCI_EVENT_NUM_COMPLETED_PKT: #if WIIREMOTE_DEBUG DEBUG_PRINT_P( PSTR("\r\nHCI Number Of Completed Packets Event: ") ); DEBUG_PRINT_P( PSTR("\r\n\tNumber_of_Handles = 0x") ); DEBUG_PRINT(buf[2], HEX); for (uint8_t i = 0; i < buf[2]; i++) { DEBUG_PRINT_P( PSTR("\r\n\tConnection_Handle = 0x") ); DEBUG_PRINT((buf[3+i] | ((buf[4+i] & 0x0F) << 8)), HEX); } #endif break; case HCI_EVENT_QOS_SETUP_COMPLETE: break; case HCI_EVENT_DISCONN_COMPLETE: hci_event_flag_ |= HCI_FLAG_DISCONN_COMPLETE; DEBUG_PRINT_P( PSTR("\r\nHCI Disconnection Complete Event: ") ); DEBUG_PRINT_P( PSTR("\r\n\t Status = 0x") ); DEBUG_PRINT(buf[2], HEX); DEBUG_PRINT_P( PSTR("\r\n\tConnection_Handle = 0x") ); DEBUG_PRINT((buf[3] | ((buf[4] & 0x0F) << 8)), HEX); DEBUG_PRINT_P( PSTR("\r\n\t Reason = 0x") ); DEBUG_PRINT(buf[5], HEX); break; default: DEBUG_PRINT_P( PSTR("\r\nUnmanaged Event: 0x") ); DEBUG_PRINT(buf[0], HEX); break; } // switch (buf[0]) }
void WiiRemote::initBTController(void) { uint8_t rcode = 0; // return code uint8_t buf[MAX_BUFFER_SIZE] = {0}; USB_DEVICE_DESCRIPTOR *device_descriptor; /* initialize data structures for endpoints of device 1 */ // copy endpoint 0 parameters ep_record_[ CONTROL_PIPE ] = *( Usb.getDevTableEntry(0,0) ); // Bluetooth event endpoint ep_record_[ EVENT_PIPE ].epAddr = 0x01; ep_record_[ EVENT_PIPE ].Attr = EP_INTERRUPT; ep_record_[ EVENT_PIPE ].MaxPktSize = INT_MAXPKTSIZE; ep_record_[ EVENT_PIPE ].Interval = EP_POLL; ep_record_[ EVENT_PIPE ].sndToggle = bmSNDTOG0; ep_record_[ EVENT_PIPE ].rcvToggle = bmRCVTOG0; // Bluetoth data endpoint ep_record_[ DATAIN_PIPE ].epAddr = 0x02; ep_record_[ DATAIN_PIPE ].Attr = EP_BULK; ep_record_[ DATAIN_PIPE ].MaxPktSize = BULK_MAXPKTSIZE; ep_record_[ DATAIN_PIPE ].Interval = 0; ep_record_[ DATAIN_PIPE ].sndToggle = bmSNDTOG0; ep_record_[ DATAIN_PIPE ].rcvToggle = bmRCVTOG0; // Bluetooth data endpoint ep_record_[ DATAOUT_PIPE ].epAddr = 0x02; ep_record_[ DATAOUT_PIPE ].Attr = EP_BULK; ep_record_[ DATAOUT_PIPE ].MaxPktSize = BULK_MAXPKTSIZE; ep_record_[ DATAOUT_PIPE ].Interval = 0; ep_record_[ DATAOUT_PIPE ].sndToggle = bmSNDTOG0; ep_record_[ DATAOUT_PIPE ].rcvToggle = bmRCVTOG0; // plug kbd.endpoint parameters to devtable Usb.setDevTableEntry(BT_ADDR, ep_record_); // read the device descriptor and check VID and PID rcode = Usb.getDevDescr(BT_ADDR, ep_record_[ CONTROL_PIPE ].epAddr, DEV_DESCR_LEN, (char *) buf); if (rcode) { DEBUG_PRINT_P( PSTR("\r\nDevice Descriptor Error: ") ); DEBUG_PRINT(rcode, HEX); return; } device_descriptor = (USB_DEVICE_DESCRIPTOR *) &buf; if ((device_descriptor->idVendor != CSR_VID) || (device_descriptor->idProduct != CSR_PID)) { DEBUG_PRINT_P( PSTR("\r\nWrong USB Device ID: ") ); DEBUG_PRINT_P( PSTR("\r\n\t Vendor ID = ") ); DEBUG_PRINT(device_descriptor->idVendor, HEX); DEBUG_PRINT_P( PSTR("\r\n\tProduct ID = ") ); DEBUG_PRINT(device_descriptor->idProduct, HEX); return; } wiiremote_status_ |= WIIREMOTE_STATE_USB_AUTHORIZED; // configure device rcode = Usb.setConf(BT_ADDR, ep_record_[ CONTROL_PIPE ].epAddr, BT_CONFIGURATION); if (rcode) { DEBUG_PRINT_P( PSTR("\r\nDevice Configuration Error: ") ); DEBUG_PRINT(rcode, HEX); return; } wiiremote_status_ |= WIIREMOTE_STATE_USB_CONFIGURED; //LCD.clear(); DEBUG_PRINT_P( PSTR("\r\nCSR Initialized") ); //delay(200); } // initBTController
int main() { // Default pins to low status for (int i = 0; i < 5; i++){ leds[i].output(); leds[i]= 0; } Kernel* kernel = new Kernel(); kernel->streams->printf("Smoothie ( grbl port ) version 0.7.2 with new accel @%ldMHz\r\n", SystemCoreClock / 1000000); Version version; kernel->streams->printf(" Build version %s, Build date %s\r\n", version.get_build(), version.get_build_date()); //some boards don't have leds.. TOO BAD! kernel->use_leds= !kernel->config->value( disable_leds_checksum )->by_default(false)->as_bool(); // attempt to be able to disable msd in config // if(!kernel->config->value( disable_msd_checksum )->by_default(false)->as_bool()){ // msc= new USBMSD(&u, &sd); // }else{ // msc= NULL; // kernel->streams->printf("MSD is disabled\r\n"); // } bool sdok= (sd.disk_initialize() == 0); // Create and add main modules kernel->add_module( new Laser() ); kernel->add_module( new ExtruderMaker() ); kernel->add_module( new SimpleShell() ); kernel->add_module( new Configurator() ); kernel->add_module( new CurrentControl() ); kernel->add_module( new TemperatureControlPool() ); kernel->add_module( new SwitchPool() ); kernel->add_module( new PauseButton() ); kernel->add_module( new PlayLed() ); kernel->add_module( new Endstops() ); kernel->add_module( new Player() ); kernel->add_module( new Panel() ); kernel->add_module( new Touchprobe() ); // Create and initialize USB stuff u.init(); //if(sdok) { // only do this if there is an sd disk // msc= new USBMSD(&u, &sd); // kernel->add_module( msc ); //} // if(msc != NULL){ // kernel->add_module( msc ); // } kernel->add_module( &msc ); kernel->add_module( &usbserial ); if( kernel->config->value( second_usb_serial_enable_checksum )->by_default(false)->as_bool() ){ kernel->add_module( new USBSerial(&u) ); } kernel->add_module( &dfu ); kernel->add_module( &u ); // clear up the config cache to save some memory kernel->config->config_cache_clear(); if(kernel->use_leds) { // set some leds to indicate status... led0 init doe, led1 mainloop running, led2 idle loop running, led3 sdcard ok leds[0]= 1; // indicate we are done with init leds[3]= sdok?1:0; // 4th led inidicates sdcard is available (TODO maye should indicate config was found) } if(sdok) { // load config override file if present // NOTE only Mxxx commands that set values should be put in this file. The file is generated by M500 FILE *fp= fopen(kernel->config_override_filename(), "r"); if(fp != NULL) { char buf[132]; kernel->streams->printf("Loading config override file: %s...\n", kernel->config_override_filename()); while(fgets(buf, sizeof buf, fp) != NULL) { kernel->streams->printf(" %s", buf); if(buf[0] == ';') continue; // skip the comments struct SerialMessage message= {&(StreamOutput::NullStream), buf}; kernel->call_event(ON_CONSOLE_LINE_RECEIVED, &message); } kernel->streams->printf("config override file executed\n"); fclose(fp); } } uint16_t cnt= 0; // Main loop while(1){ if(kernel->use_leds) { // flash led 2 to show we are alive leds[1]= (cnt++ & 0x1000) ? 1 : 0; } kernel->call_event(ON_MAIN_LOOP); kernel->call_event(ON_IDLE); } }