/** * @brief Blocks until a button is pressed and then released. * * @param[in] num Which button to wait for. Either 0 or 1. */ void button_wait(int num) { // wait for button to be pushed down while (!button_get(num)) chThdSleepMilliseconds(1); // delay 30 ms for button debouncing chThdSleepMilliseconds(30); // wait for button to be released, if it is still down while (button_get(num)) chThdSleepMilliseconds(1); // delay 30 ms for button debouncing chThdSleepMilliseconds(30); }
static void usb_mode(void) { int button; /* Init USB */ usb_init(); usb_start_monitoring(); /* Wait for threads to connect */ show_splash(HZ/2, "Waiting for USB"); while (1) { button = button_get_w_tmo(HZ/2); if (button == SYS_USB_CONNECTED) break; /* Hit */ } if (button == SYS_USB_CONNECTED) { /* Got the message - wait for disconnect */ show_splash(0, "Bootloader USB mode"); usb_acknowledge(SYS_USB_CONNECTED_ACK); while (1) { button = button_get(true); if (button == SYS_USB_DISCONNECTED) break; } } }
/* * Task of polling buttons. */ void poll_buttons (void *data) { unsigned char pagenum = 0; unsigned char up_pressed = 0, left_pressed = 0; unsigned char center_pressed = 0, right_pressed = 0; unsigned char down_pressed = 0; printf (&line1, "Testing LCD."); printf (&line2, "Use buttons."); for (;;) { timer_delay (&timer, 10); int key = button_get(); if (key != BUTTON_UP) up_pressed = 0; else if (! up_pressed) { up_pressed = 1; /* Up button: clear screen. */ lcd_clear_all (&line1, &line2); printf (&line1, "Cleared."); } if (key != BUTTON_LEFT) left_pressed = 0; else if (! left_pressed) { left_pressed = 1; /* Left button: show previous page of symbols. */ display_page (--pagenum); } if (key != BUTTON_SELECT) center_pressed = 0; else if (! center_pressed) { center_pressed = 1; /* Center button: show current page of symbols. */ display_page (pagenum); } if (key != BUTTON_RIGHT) right_pressed = 0; else if (! right_pressed) { right_pressed = 1; /* Right button: show next page of symbols. */ display_page (++pagenum); } if (key != BUTTON_DOWN) down_pressed = 0; else if (! down_pressed) { down_pressed = 1; /* Down button: scroll long message. */ printf (&line2, message1); } } }
OCEntityHandlerResult ButtonOCEntityHandlerCb(OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void *callbackParam) { OCEntityHandlerResult ehRet = OC_EH_OK; OCEntityHandlerResponse response = {0}; OCRepPayload* payload = OCRepPayloadCreate(); if(!payload) { OC_LOG(ERROR, TAG, ("Failed to allocate Payload")); return OC_EH_ERROR; } if(entityHandlerRequest && (flag & OC_REQUEST_FLAG)) { OC_LOG (INFO, TAG, ("Flag includes OC_REQUEST_FLAG")); if(OC_REST_GET == entityHandlerRequest->method) { button_get(); OCRepPayloadSetUri(payload, "/grove/button"); OCRepPayloadSetPropInt(payload, "button", button.button); OCRepPayloadSetPropInt(payload, "touch", button.touch); } else if(OC_REST_PUT == entityHandlerRequest->method) { OC_LOG(ERROR, TAG, ("Un-supported request for Sensor: PUT")); } if (ehRet == OC_EH_OK) { // Format the response. Note this requires some info about the request response.requestHandle = entityHandlerRequest->requestHandle; response.resourceHandle = entityHandlerRequest->resource; response.ehResult = ehRet; response.payload = (OCPayload*) payload; response.numSendVendorSpecificHeaderOptions = 0; memset(response.sendVendorSpecificHeaderOptions, 0, sizeof response.sendVendorSpecificHeaderOptions); memset(response.resourceUri, 0, sizeof response.resourceUri); // Indicate that response is NOT in a persistent buffer response.persistentBufferFlag = 0; // Send the response if (OCDoResponse(&response) != OC_STACK_OK) { OC_LOG(ERROR, TAG, "Error sending response"); ehRet = OC_EH_ERROR; } } } if (entityHandlerRequest && (flag & OC_OBSERVE_FLAG)) { if (OC_OBSERVE_REGISTER == entityHandlerRequest->obsInfo.action) { OC_LOG (INFO, TAG, ("Received OC_OBSERVE_REGISTER from client")); button.observer = 1; } else if (OC_OBSERVE_DEREGISTER == entityHandlerRequest->obsInfo.action) { OC_LOG (INFO, TAG, ("Received OC_OBSERVE_DEREGISTER from client")); button.observer = 0; } } OCRepPayloadDestroy(payload); return ehRet; }
static bool reset_settings(void) { bool done=false; int line; int button; lcd_clear_display(); #ifdef HAVE_LCD_CHARCELLS line = 0; #else line = 1; lcd_puts(0,0,str(LANG_RESET_ASK_RECORDER)); #endif lcd_puts(0,line,str(LANG_RESET_CONFIRM)); lcd_puts(0,line+1,str(LANG_RESET_CANCEL)); lcd_update(); while(!done) { button = button_get(true); switch(button) { case SETTINGS_OK: settings_reset(); settings_apply(); lcd_clear_display(); lcd_puts(0,1,str(LANG_RESET_DONE_CLEAR)); done = true; break; case SETTINGS_CANCEL: lcd_clear_display(); lcd_puts(0,1,str(LANG_RESET_DONE_CANCEL)); done = true; break; default: if(default_event_handler(button) == SYS_USB_CONNECTED) return true; } } lcd_puts(0,0,str(LANG_RESET_DONE_SETTING)); lcd_update(); sleep(HZ); return false; }
bool __dbg_hw_info(void) { int line = 0, i, button, oldline; bool done=false; char buf[100]; lcd_setfont(FONT_SYSFIXED); lcd_clear_display(); /* Put all the static text before the while loop */ lcd_puts(0, line++, "[Hardware info]"); line++; oldline=line; while(!done) { line = oldline; button = button_get(false); button &= ~BUTTON_REPEAT; #ifdef BUTTON_SELECT if (button == BUTTON_SELECT) #else if (button == BUTTON_STOP) #endif done=true; snprintf(buf, sizeof(buf), "current tick: %08x Seconds running: %08d", (unsigned int)current_tick, (unsigned int)current_tick/100); lcd_puts(0, line++, buf); snprintf(buf, sizeof(buf), "GPIOA: 0x%08x GPIOB: 0x%08x", (unsigned int)GPIOA, (unsigned int)GPIOB); lcd_puts(0, line++, buf); snprintf(buf, sizeof(buf), "GPIOC: 0x%08x GPIOD: 0x%08x", (unsigned int)GPIOC, (unsigned int)GPIOD); lcd_puts(0, line++, buf); snprintf(buf, sizeof(buf), "GPIOE: 0x%08x", (unsigned int)GPIOE); lcd_puts(0, line++, buf); for (i = 0; i<4; i++) { snprintf(buf, sizeof(buf), "ADC%d: 0x%04x", i, adc_read(i)); lcd_puts(0, line++, buf); } lcd_update(); } return false; }
void button_observer() { OCStackResult result = OC_STACK_ERROR; if(button.observer) { button_get(); if(button.button != button.button_old || button.touch != button.touch_old) { result = OCNotifyAllObservers(button.handle, OC_NA_QOS); button.button_old = button.button; button.touch_old = button.touch; if(result == OC_STACK_NO_OBSERVERS) button.observer = 0; } } }
long button_get_w_tmo(int ticks) { struct queue_event ev; #ifdef HAVE_ADJUSTABLE_CPU_FREQ /* Be sure to keep boosted state. */ if (!queue_empty(&button_queue)) return button_get(true); button_boost(false); #endif queue_wait_w_tmo(&button_queue, &ev, ticks); if (ev.id == SYS_TIMEOUT) ev.id = BUTTON_NONE; else button_data = ev.data; return ev.id; }
bool dbg_hw_info(void) { int line = 0, i, button, oldline; bool done=false; lcd_setfont(FONT_SYSFIXED); lcd_clear_display(); /* Put all the static text before the while loop */ lcd_puts(0, line++, "[Hardware info]"); line++; oldline=line; while(!done) { line = oldline; button = button_get(false); button &= ~BUTTON_REPEAT; #ifdef BUTTON_SELECT if (button == BUTTON_SELECT) #else if (button == BUTTON_STOP) #endif done=true; lcd_putsf(0, line++, "current tick: %08lx Seconds running: %08ld", current_tick, current_tick/HZ); lcd_putsf(0, line++, "GPIOA: 0x%08lx GPIOB: 0x%08lx", GPIOA, GPIOB); lcd_putsf(0, line++, "GPIOC: 0x%08lx GPIOD: 0x%08lx", GPIOC, GPIOD); lcd_putsf(0, line++, "GPIOE: 0x%08lx", GPIOE); for (i = 0; i<4; i++) lcd_putsf(0, line++, "ADC%d: 0x%04x", i, adc_read(i)); lcd_update(); } return false; }
/* prompt user to plug USB and fix a problem */ static void prompt_usb(const char* msg1, const char* msg2) { int button; lcd_clear_display(); lcd_puts(0, 0, msg1); lcd_puts(0, 1, msg2); #ifdef HAVE_LCD_BITMAP lcd_puts(0, 2, "Insert USB cable"); lcd_puts(0, 3, "and fix it."); #endif lcd_update(); do { button = button_get(true); if (button == SYS_POWEROFF) { power_off(); } } while (button != SYS_USB_CONNECTED); usb_screen(); system_reboot(); }
void display_logf(void) /* Doesn't return! */ { int i, index, button, user_index=0; #ifdef HAVE_TOUCHSCREEN int touch, prev_y=0; #endif char buffer[COLUMNS+1]; while(1) { index = logfindex + user_index; lcd_clear_display(); for(i = LINES-1; i>=0; i--) { if(--index < 0) { if(logfwrap) index = MAX_LOGF_LINES-1; else break; /* done */ } memcpy(buffer, logfbuffer[index], COLUMNS); if (logfbuffer[index][MAX_LOGF_ENTRY] == LOGF_TERMINATE_CONTINUE_LINE) buffer[MAX_LOGF_ENTRY-1] = '>'; else if (logfbuffer[index][MAX_LOGF_ENTRY] == LOGF_TERMINATE_MULTI_LINE) buffer[MAX_LOGF_ENTRY-1] = '\0'; buffer[COLUMNS] = '\0'; lcd_puts(0, i, buffer); } button = button_get(false); if(button == SYS_USB_CONNECTED) usb_acknowledge(SYS_USB_CONNECTED_ACK); else if(button == SYS_USB_DISCONNECTED) ; else if(button & LOGF_UP) user_index++; else if(button & LOGF_DOWN) user_index--; else if(button & LOGF_CLEAR) user_index = 0; #ifdef HAVE_TOUCHSCREEN else if(button & BUTTON_TOUCHSCREEN) { touch = button_get_data(); if(button & BUTTON_REL) prev_y = 0; if(prev_y != 0) user_index += (prev_y - (touch & 0xFFFF)) / SYSFONT_HEIGHT; prev_y = touch & 0xFFFF; } #endif lcd_update(); sleep(HZ/16); } }
/* The following function is just test/development code */ void show_debug_screen(void) { int button; int power_count = 0; int count = 0; bool do_power_off = false; lcd_puts_scroll(0,0,"+++ this is a very very long line to test scrolling. ---"); while (!do_power_off) { line = 1; button = button_get(false); /* Power-off if POWER button has been held for a time This loop is currently running at about 100 iterations/second */ if (button & POWEROFF_BUTTON) { power_count++; if (power_count > 100) do_power_off = true; } else { power_count = 0; } #if 0 if (button & BUTTON_SELECT){ _backlight_off(); } else{ _backlight_on(); } #endif printf("Btn: 0x%08x",button); #if 0 printf("Tick: %d",current_tick); printf("GPIOA: 0x%08x",GPIOA); printf("GPIOB: 0x%08x",GPIOB); printf("GPIOC: 0x%08x",GPIOC); printf("GPIOD: 0x%08x",GPIOD); printf("GPIOE: 0x%08x",GPIOE); #endif #if 0 int i; for (i = 0; i<4; i++) { printf("ADC%d: 0x%04x",i,adc_read(i)); } #endif count++; printf("Count: %d",count); lcd_update(); sleep(HZ/10); } lcd_clear_display(); line = 0; printf("POWER-OFF"); /* Power-off */ power_off(); printf("(NOT) POWERED OFF"); while (true); }
/* * int get_action_worker(int context, struct button_mapping *user_mappings, int timeout) This function searches the button list for the given context for the just pressed button. If there is a match it returns the value from the list. If there is no match.. the last item in the list "points" to the next context in a chain so the "chain" is followed until the button is found. putting ACTION_NONE will get CONTEXT_STD which is always the last list checked. Timeout can be TIMEOUT_NOBLOCK to return immediatly TIMEOUT_BLOCK to wait for a button press Any number >0 to wait that many ticks for a press */ static int get_action_worker(int context, int timeout, const struct button_mapping* (*get_context_map)(int) ) { const struct button_mapping *items = NULL; int button; int i=0; int ret = ACTION_UNKNOWN; static int last_context = CONTEXT_STD; send_event(GUI_EVENT_ACTIONUPDATE, NULL); if (timeout == TIMEOUT_NOBLOCK) button = button_get(false); else if (timeout == TIMEOUT_BLOCK) button = button_get(true); else button = button_get_w_tmo(timeout); #if defined(HAVE_GUI_BOOST) && defined(HAVE_ADJUSTABLE_CPU_FREQ) static struct timeout gui_unboost; /* Boost the CPU in case of wheel scrolling activity in the defined contexts. * Call unboost with a timeout of GUI_BOOST_TIMEOUT. */ if ((button&(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD)) && (context == CONTEXT_STD || context == CONTEXT_LIST || context == CONTEXT_MAINMENU || context == CONTEXT_TREE)) { gui_boost(true); timeout_register(&gui_unboost, gui_unboost_callback, GUI_BOOST_TIMEOUT, 0); } #endif /* Data from sys events can be pulled with button_get_data * multimedia button presses don't go through the action system */ if (button == BUTTON_NONE || button & (SYS_EVENT|BUTTON_MULTIMEDIA)) { /* no button pressed so no point in waiting for release */ if (button == BUTTON_NONE) wait_for_release = false; return button; } /* the special redraw button should result in a screen refresh */ if (button == BUTTON_REDRAW) return ACTION_REDRAW; /* if action_wait_for_release() was called without a button being pressed * then actually waiting for release would do the wrong thing, i.e. * the next key press is entirely ignored. So, if here comes a normal * button press (neither release nor repeat) the press is a fresh one and * no point in waiting for release * * This logic doesn't work for touchscreen which can send normal * button events repeatedly before the first repeat (as in BUTTON_REPEAT). * These cannot be distinguished from the very first touch * but there's nothing we can do about it here */ if ((button & (BUTTON_REPEAT|BUTTON_REL)) == 0) wait_for_release = false; /* Don't send any buttons through untill we see the release event */ if (wait_for_release) { if (button&BUTTON_REL) { /* remember the button for the below button eating on context * change */ last_button = button; wait_for_release = false; } return ACTION_NONE; } if ((context != last_context) && ((last_button & BUTTON_REL) == 0) #ifdef HAVE_SCROLLWHEEL /* Scrollwheel doesn't generate release events */ && !(last_button & (BUTTON_SCROLL_BACK | BUTTON_SCROLL_FWD)) #endif ) { if (button & BUTTON_REL) { last_button = button; last_action = ACTION_NONE; } /* eat all buttons until the previous button was |BUTTON_REL (also eat the |BUTTON_REL button) */ return ACTION_NONE; /* "safest" return value */ } last_context = context; #ifndef HAS_BUTTON_HOLD screen_has_lock = ((context & ALLOW_SOFTLOCK) == ALLOW_SOFTLOCK); if (is_keys_locked()) { if (button == unlock_combo) { last_button = BUTTON_NONE; keys_locked = false; #if defined(HAVE_TOUCHPAD) || defined(HAVE_TOUCHSCREEN) /* enable back touch device */ button_enable_touch(true); #endif splash(HZ/2, str(LANG_KEYLOCK_OFF)); return ACTION_REDRAW; } else #if (BUTTON_REMOTE != 0) if ((button & BUTTON_REMOTE) == 0) #endif { if ((button & BUTTON_REL)) splash(HZ/2, str(LANG_KEYLOCK_ON)); return ACTION_REDRAW; } } #if defined(HAVE_TOUCHPAD) || defined(HAVE_TOUCHSCREEN) else { /* make sure touchpad get reactivated if we quit the screen */ button_enable_touch(true); } #endif context &= ~ALLOW_SOFTLOCK; #endif /* HAS_BUTTON_HOLD */ #ifdef HAVE_TOUCHSCREEN if (button & BUTTON_TOUCHSCREEN) { repeated = false; short_press = false; if (last_button & BUTTON_TOUCHSCREEN) { if ((button & BUTTON_REL) && ((last_button & BUTTON_REPEAT)==0)) { short_press = true; } else if (button & BUTTON_REPEAT) repeated = true; } last_button = button; return ACTION_TOUCHSCREEN; } #endif #if defined(HAVE_LCD_BITMAP) && !defined(BOOTLOADER) button = button_flip_horizontally(context, button); #endif /* logf("%x,%x",last_button,button); */ while (1) { /* logf("context = %x",context); */ #if (BUTTON_REMOTE != 0) if (button & BUTTON_REMOTE) context |= CONTEXT_REMOTE; #endif if ((context & CONTEXT_PLUGIN) && get_context_map) items = get_context_map(context); else items = get_context_mapping(context); if (items == NULL) break; ret = do_button_check(items,button,last_button,&i); if (ret == ACTION_UNKNOWN) { context = get_next_context(items,i); if (context != (int)CONTEXT_STOPSEARCHING) { i = 0; continue; } } /* Action was found or STOPSEARCHING was specified */ break; } /* DEBUGF("ret = %x\n",ret); */ #ifndef HAS_BUTTON_HOLD if (screen_has_lock && (ret == ACTION_STD_KEYLOCK)) { unlock_combo = button; keys_locked = true; splash(HZ/2, str(LANG_KEYLOCK_ON)); #if defined(HAVE_TOUCHPAD) || defined(HAVE_TOUCHSCREEN) /* disable touch device on keylock */ button_enable_touch(false); #endif button_clear_queue(); return ACTION_REDRAW; } #endif if ((current_tick - last_action_tick < REPEAT_WINDOW_TICKS) && (ret == last_action)) repeated = true; else repeated = false; last_button = button; last_action = ret; last_data = button_get_data(); last_action_tick = current_tick; #if CONFIG_CODEC == SWCODEC /* Produce keyclick */ keyclick_click(false, ret); #endif return ret; }
static void init(void) { int rc; bool mounted = false; #if CONFIG_CHARGING && (CONFIG_CPU == SH7034) /* if nobody initialized ATA before, I consider this a cold start */ bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */ #endif system_init(); kernel_init(); #ifdef HAVE_ADJUSTABLE_CPU_FREQ set_cpu_frequency(CPUFREQ_NORMAL); #ifdef CPU_COLDFIRE coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS); #endif cpu_boost(true); #endif buffer_init(); settings_reset(); i2c_init(); power_init(); enable_irq(); #ifdef CPU_ARM enable_fiq(); #endif /* current_tick should be ticking by now */ CHART("ticking"); lcd_init(); #ifdef HAVE_REMOTE_LCD lcd_remote_init(); #endif font_init(); CHART(">show_logo"); show_logo(); CHART("<show_logo"); lang_init(core_language_builtin, language_strings, LANG_LAST_INDEX_IN_ARRAY); #ifdef DEBUG debug_init(); #else #ifdef HAVE_SERIAL serial_setup(); #endif #endif #if CONFIG_RTC rtc_init(); #endif #ifdef HAVE_RTC_RAM CHART(">settings_load(RTC)"); settings_load(SETTINGS_RTC); /* early load parts of global_settings */ CHART("<settings_load(RTC)"); #endif adc_init(); usb_init(); #if CONFIG_USBOTG == USBOTG_ISP1362 isp1362_init(); #elif CONFIG_USBOTG == USBOTG_M5636 m5636_init(); #endif backlight_init(); button_init(); powermgmt_init(); #if CONFIG_TUNER radio_init(); #endif /* Keep the order of this 3 (viewportmanager handles statusbars) * Must be done before any code uses the multi-screen API */ CHART(">gui_syncstatusbar_init"); gui_syncstatusbar_init(&statusbars); CHART("<gui_syncstatusbar_init"); CHART(">sb_skin_init"); sb_skin_init(); CHART("<sb_skin_init"); CHART(">gui_sync_wps_init"); gui_sync_wps_init(); CHART("<gui_sync_wps_init"); CHART(">viewportmanager_init"); viewportmanager_init(); CHART("<viewportmanager_init"); #if CONFIG_CHARGING && (CONFIG_CPU == SH7034) /* charger_inserted() can't be used here because power_thread() hasn't checked power_input_status() yet */ if (coldstart && (power_input_status() & POWER_INPUT_MAIN_CHARGER) && !global_settings.car_adapter_mode #ifdef ATA_POWER_PLAYERSTYLE && !ide_powered() /* relies on probing result from bootloader */ #endif ) { rc = charging_screen(); /* display a "charging" screen */ if (rc == 1) /* charger removed */ power_off(); /* "On" pressed or USB connected: proceed */ show_logo(); /* again, to provide better visual feedback */ } #endif CHART(">storage_init"); rc = storage_init(); CHART("<storage_init"); if(rc) { #ifdef HAVE_LCD_BITMAP lcd_clear_display(); lcd_putsf(0, 1, "ATA error: %d", rc); lcd_puts(0, 3, "Press ON to debug"); lcd_update(); while(!(button_get(true) & BUTTON_REL)); /*DO NOT CHANGE TO ACTION SYSTEM */ dbg_ports(); #endif panicf("ata: %d", rc); } #ifdef HAVE_EEPROM_SETTINGS CHART(">eeprom_settings_init"); eeprom_settings_init(); CHART("<eeprom_settings_init"); #endif #ifndef HAVE_USBSTACK usb_start_monitoring(); while (usb_detect() == USB_INSERTED) { #ifdef HAVE_EEPROM_SETTINGS firmware_settings.disk_clean = false; #endif /* enter USB mode early, before trying to mount */ if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED) #if (CONFIG_STORAGE & STORAGE_MMC) if (!mmc_touched() || (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED)) #endif { gui_usb_screen_run(); mounted = true; /* mounting done @ end of USB mode */ } #ifdef HAVE_USB_POWER if (usb_powered()) /* avoid deadlock */ break; #endif } #endif if (!mounted) { CHART(">disk_mount_all"); rc = disk_mount_all(); CHART("<disk_mount_all"); if (rc<=0) { lcd_clear_display(); lcd_puts(0, 0, "No partition"); lcd_puts(0, 1, "found."); #ifdef HAVE_LCD_BITMAP lcd_puts(0, 2, "Insert USB cable"); lcd_puts(0, 3, "and fix it."); #endif lcd_update(); while(button_get(true) != SYS_USB_CONNECTED) {}; gui_usb_screen_run(); system_reboot(); } } #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \ (CONFIG_KEYPAD == IRIVER_H10_PAD) #ifdef SETTINGS_RESET /* Reset settings if holding the reset button. (Rec on Archos, A on Gigabeat) */ if ((button_status() & SETTINGS_RESET) == SETTINGS_RESET) #else /* Reset settings if the hold button is turned on */ if (button_hold()) #endif { splash(HZ*2, str(LANG_RESET_DONE_CLEAR)); settings_reset(); } else #endif { CHART(">settings_load(ALL)"); settings_load(SETTINGS_ALL); CHART("<settings_load(ALL)"); } CHART(">init_dircache(true)"); rc = init_dircache(true); CHART("<init_dircache(true)"); if (rc < 0) { #ifdef HAVE_TAGCACHE remove(TAGCACHE_STATEFILE); #endif } CHART(">settings_apply(true)"); settings_apply(true); CHART("<settings_apply(true)"); CHART(">init_dircache(false)"); init_dircache(false); CHART("<init_dircache(false)"); #ifdef HAVE_TAGCACHE CHART(">init_tagcache"); init_tagcache(); CHART("<init_tagcache"); #endif #ifdef HAVE_EEPROM_SETTINGS if (firmware_settings.initialized) { /* In case we crash. */ firmware_settings.disk_clean = false; CHART(">eeprom_settings_store"); eeprom_settings_store(); CHART("<eeprom_settings_store"); } #endif playlist_init(); tree_mem_init(); filetype_init(); scrobbler_init(); #if CONFIG_CODEC == SWCODEC tdspeed_init(); #endif /* CONFIG_CODEC == SWCODEC */ #if CONFIG_CODEC != SWCODEC /* No buffer allocation (see buffer.c) may take place after the call to audio_init() since the mpeg thread takes the rest of the buffer space */ mp3_init( global_settings.volume, global_settings.bass, global_settings.treble, global_settings.balance, global_settings.loudness, global_settings.avc, global_settings.channel_config, global_settings.stereo_width, global_settings.mdb_strength, global_settings.mdb_harmonics, global_settings.mdb_center, global_settings.mdb_shape, global_settings.mdb_enable, global_settings.superbass); /* audio_init must to know the size of voice buffer so init voice first */ talk_init(); #endif /* CONFIG_CODEC != SWCODEC */ CHART(">audio_init"); audio_init(); CHART("<audio_init"); #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR) pcm_rec_init(); #endif /* runtime database has to be initialized after audio_init() */ cpu_boost(false); #if CONFIG_CHARGING car_adapter_mode_init(); #endif #ifdef IPOD_ACCESSORY_PROTOCOL iap_setup(global_settings.serial_bitrate); #endif #ifdef HAVE_ACCESSORY_SUPPLY accessory_supply_set(global_settings.accessory_supply); #endif #ifdef HAVE_LINEOUT_POWEROFF lineout_set(global_settings.lineout_active); #endif #ifdef HAVE_HOTSWAP_STORAGE_AS_MAIN CHART("<check_bootfile(false)"); check_bootfile(false); /* remember write time and filesize */ CHART(">check_bootfile(false)"); #endif CHART("<settings_apply_skins"); settings_apply_skins(); CHART(">settings_apply_skins"); }
void main(void) { int rc; power_init(); system_init(); kernel_init(); lcd_init(); show_logo(); enable_irq(); adc_init(); usb_init(); button_init(); powermgmt_init(); #if CONFIG_CHARGING && (CONFIG_CPU == SH7034) if (charger_inserted() #ifdef ATA_POWER_PLAYERSTYLE && !ide_powered() /* relies on probing result from bootloader */ #endif ) { charging_screen(); /* display a "charging" screen */ show_logo(); /* again, to provide better visual feedback */ } #endif rc = storage_init(); if(rc) { #ifdef HAVE_LCD_BITMAP char str[32]; lcd_clear_display(); snprintf(str, 31, "ATA error: %d", rc); lcd_puts(0, 1, str); lcd_update(); while(!(button_get(true) & BUTTON_REL)); #endif panicf("storage: %d", rc); } usb_start_monitoring(); while (usb_detect() == USB_INSERTED) { /* enter USB mode early, before trying to mount */ if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED) { usb_screen(); } } rc = disk_mount_all(); if (rc<=0) { prompt_usb("No partition", "found."); } { // rolo the firmware static const char filename[] = "/" BOOTFILE; rolo_load((char*)filename); /* won't return if started */ prompt_usb("No firmware", filename); } }
/* * int get_action_worker(int context, struct button_mapping *user_mappings, int timeout) This function searches the button list for the given context for the just pressed button. If there is a match it returns the value from the list. If there is no match.. the last item in the list "points" to the next context in a chain so the "chain" is followed until the button is found. putting ACTION_NONE will get CONTEXT_STD which is always the last list checked. Timeout can be TIMEOUT_NOBLOCK to return immediatly TIMEOUT_BLOCK to wait for a button press Any number >0 to wait that many ticks for a press */ static int get_action_worker(int context, int timeout, const struct button_mapping* (*get_context_map)(int) ) { const struct button_mapping *items = NULL; int button; int i=0; int ret = ACTION_UNKNOWN; static int last_context = CONTEXT_STD; send_event(GUI_EVENT_ACTIONUPDATE, NULL); if (timeout == TIMEOUT_NOBLOCK) button = button_get(false); else if (timeout == TIMEOUT_BLOCK) button = button_get(true); else button = button_get_w_tmo(timeout); #if defined(HAVE_GUI_BOOST) && defined(HAVE_ADJUSTABLE_CPU_FREQ) static struct timeout gui_unboost; /* Boost the CPU in case of wheel scrolling activity in the defined contexts. * Call unboost with a timeout of GUI_BOOST_TIMEOUT. */ if ((button&(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD)) && (context == CONTEXT_STD || context == CONTEXT_LIST || context == CONTEXT_MAINMENU || context == CONTEXT_TREE)) { gui_boost(true); timeout_register(&gui_unboost, gui_unboost_callback, GUI_BOOST_TIMEOUT, 0); } #endif /* Data from sys events can be pulled with button_get_data * multimedia button presses don't go through the action system */ if (button == BUTTON_NONE || button & (SYS_EVENT|BUTTON_MULTIMEDIA)) return button; /* Don't send any buttons through untill we see the release event */ if (wait_for_release) { if (button&BUTTON_REL) { /* remember the button for the below button eating on context * change */ last_button = button; wait_for_release = false; } return ACTION_NONE; } #if CONFIG_CODEC == SWCODEC /* Produce keyclick */ keyclick_click(button); #endif if ((context != last_context) && ((last_button & BUTTON_REL) == 0) #ifdef HAVE_SCROLLWHEEL /* Scrollwheel doesn't generate release events */ && !(last_button & (BUTTON_SCROLL_BACK | BUTTON_SCROLL_FWD)) #endif ) { if (button & BUTTON_REL) { last_button = button; last_action = ACTION_NONE; } /* eat all buttons until the previous button was |BUTTON_REL (also eat the |BUTTON_REL button) */ return ACTION_NONE; /* "safest" return value */ } last_context = context; #ifndef HAS_BUTTON_HOLD screen_has_lock = ((context & ALLOW_SOFTLOCK) == ALLOW_SOFTLOCK); if (screen_has_lock && keys_locked) { if (button == unlock_combo) { last_button = BUTTON_NONE; keys_locked = false; splash(HZ/2, str(LANG_KEYLOCK_OFF)); return ACTION_REDRAW; } else #if (BUTTON_REMOTE != 0) if ((button & BUTTON_REMOTE) == 0) #endif { if ((button & BUTTON_REL)) splash(HZ/2, str(LANG_KEYLOCK_ON)); return ACTION_REDRAW; } } context &= ~ALLOW_SOFTLOCK; #endif /* HAS_BUTTON_HOLD */ #ifdef HAVE_TOUCHSCREEN if (button & BUTTON_TOUCHSCREEN) { repeated = false; short_press = false; if (last_button & BUTTON_TOUCHSCREEN) { if ((button & BUTTON_REL) && ((last_button & BUTTON_REPEAT)==0)) { short_press = true; } else if (button & BUTTON_REPEAT) repeated = true; } last_button = button; return ACTION_TOUCHSCREEN; } #endif #if defined(HAVE_LCD_BITMAP) && !defined(BOOTLOADER) button = button_flip_horizontally(context, button); #endif /* logf("%x,%x",last_button,button); */ while (1) { /* logf("context = %x",context); */ #if (BUTTON_REMOTE != 0) if (button & BUTTON_REMOTE) context |= CONTEXT_REMOTE; #endif if ((context & CONTEXT_PLUGIN) && get_context_map) items = get_context_map(context); else items = get_context_mapping(context); if (items == NULL) break; ret = do_button_check(items,button,last_button,&i); if (ret == ACTION_UNKNOWN) { context = get_next_context(items,i); if (context != (int)CONTEXT_STOPSEARCHING) { i = 0; continue; } } /* Action was found or STOPSEARCHING was specified */ break; } /* DEBUGF("ret = %x\n",ret); */ #ifndef HAS_BUTTON_HOLD if (screen_has_lock && (ret == ACTION_STD_KEYLOCK)) { unlock_combo = button; keys_locked = true; splash(HZ/2, str(LANG_KEYLOCK_ON)); button_clear_queue(); return ACTION_REDRAW; } #endif if ((current_tick - last_action_tick < REPEAT_WINDOW_TICKS) && (ret == last_action)) repeated = true; else repeated = false; last_button = button; last_action = ret; last_data = button_get_data(); last_action_tick = current_tick; return ret; }
bool __dbg_hw_info(void) { int line = 0, oldline; int button; #if defined(MROBE_500) int *address=0x0; #endif bool done=false; lcd_setfont(FONT_SYSFIXED); lcd_clear_display(); /* Put all the static text befor the while loop */ lcd_puts(0, line++, "[Hardware info]"); lcd_puts(0, line++, "Clock info:"); #if LCD_WIDTH > 320 lcd_putsf(0, line++, "IO_CLK_PLLA: 0x%04x IO_CLK_PLLB: 0x%04x " "IO_CLK_SEL0: 0x%04x IO_CLK_SEL1: 0x%04x", IO_CLK_PLLA, IO_CLK_PLLB, IO_CLK_SEL0, IO_CLK_SEL1); lcd_putsf(0, line++, "IO_CLK_SEL2: 0x%04x IO_CLK_DIV0: 0x%04x " "IO_CLK_DIV1: 0x%04x IO_CLK_DIV2: 0x%04x", IO_CLK_SEL2, IO_CLK_DIV0, IO_CLK_DIV1, IO_CLK_DIV2); lcd_putsf(0, line++, "IO_CLK_DIV3: 0x%04x IO_CLK_DIV4: 0x%04x " "IO_CLK_BYP : 0x%04x IO_CLK_INV : 0x%04x", IO_CLK_DIV3, IO_CLK_DIV4, IO_CLK_BYP, IO_CLK_INV); lcd_putsf(0, line++, "IO_CLK_MOD0: 0x%04x IO_CLK_MOD1: 0x%04x " "IO_CLK_MOD2: 0x%04x IO_CLK_LPCTL0: 0x%04x", IO_CLK_MOD0, IO_CLK_MOD1, IO_CLK_MOD2, IO_CLK_LPCTL0); #else lcd_putsf(0, line++, " IO_CLK_PLLA: 0x%04x IO_CLK_PLLB: 0x%04x", IO_CLK_PLLA, IO_CLK_PLLB); lcd_putsf(0, line++, " IO_CLK_SEL0: 0x%04x IO_CLK_SEL1: 0x%04x", IO_CLK_SEL0, IO_CLK_SEL1); lcd_putsf(0, line++, " IO_CLK_SEL2: 0x%04x IO_CLK_DIV0: 0x%04x", IO_CLK_SEL2, IO_CLK_DIV0); lcd_putsf(0, line++, " IO_CLK_DIV1: 0x%04x IO_CLK_DIV2: 0x%04x", IO_CLK_DIV1, IO_CLK_DIV2); lcd_putsf(0, line++, " IO_CLK_DIV3: 0x%04x IO_CLK_DIV4: 0x%04x", IO_CLK_DIV3, IO_CLK_DIV4); lcd_putsf(0, line++, " IO_CLK_BYP : 0x%04x IO_CLK_INV : 0x%04x", IO_CLK_BYP, IO_CLK_INV); lcd_putsf(0, line++, " IO_CLK_MOD0: 0x%04x IO_CLK_MOD1: 0x%04x ", IO_CLK_MOD0, IO_CLK_MOD1); lcd_putsf(0, line++, " IO_CLK_MOD2: 0x%04x IO_CLK_LPCTL0: 0x%04x ", IO_CLK_MOD2, IO_CLK_LPCTL0); #endif lcd_puts(0, line++, "Interrupt info:"); lcd_putsf(0, line++, " IO_INTC_EINT0: 0x%04x IO_INTC_EINT1: 0x%04x ", IO_INTC_EINT0, IO_INTC_EINT1); lcd_putsf(0, line++, " IO_INTC_EINT2: 0x%04x IO_INTC_IRQ0: 0x%04x ", IO_INTC_EINT2, IO_INTC_IRQ0); lcd_putsf(0, line++, " IO_INTC_IRQ1: 0x%04x IO_INTC_IRQ2: 0x%04x ", IO_INTC_IRQ1, IO_INTC_IRQ2); lcd_puts(0, line++, "Board revision:"); switch (IO_BUSC_REVR) { case 0x0010: lcd_puts(0, line++, " DM320 Rev. A"); break; case 0x0011: lcd_puts(0, line++, " DM320 Rev. B/C"); break; default: lcd_puts(0, line++, " Unknown DM320 Chip ID"); } #if defined(MROBE_500) line++; #endif oldline=line; while(!done) { line = oldline; #if defined(MROBE_500) button = button_get(false); button&=~BUTTON_REPEAT; if (button == BUTTON_POWER) done=true; if(button==BUTTON_RC_PLAY) address+=0x01; else if (button==BUTTON_RC_DOWN) address-=0x01; else if (button==BUTTON_RC_FF) address+=0x800; else if (button==BUTTON_RC_REW) address-=0x800; #else button = button_get(false); if(button & BUTTON_POWER) done = true; else if(button & BUTTON_LEFT) lcd_set_direct_fb(false); else if(button & BUTTON_RIGHT) lcd_set_direct_fb(true); lcd_puts(0, line++, "LCD info:"); lcd_putsf(0, line++, " LCD direct FB access? %s", (lcd_get_direct_fb() ? "yes" : "no")); line++; #endif lcd_puts(0, line++, "[Rockbox info]"); lcd_putsf(0, line++, "current tick: %08x Seconds running: %08d", (unsigned int)current_tick, (unsigned int)current_tick/100); #if defined(MROBE_500) lcd_putsf(0, line++, "Address: 0x%08x Data: 0x%08x", (unsigned int)address, *address); lcd_putsf(0, line++, "Address: 0x%08x Data: 0x%08x", (unsigned int)(address+1), *(address+1)); lcd_putsf(0, line++, "Address: 0x%08x Data: 0x%08x", (unsigned int)(address+2), *(address+2)); #endif lcd_update(); } return false; }
bool __dbg_ports(void) { #if defined(MROBE_500) int line = 0; int i; int button; bool done=false; lcd_setfont(FONT_SYSFIXED); lcd_clear_display(); while(!done) { line = 0; button = button_get(false); button&=~BUTTON_REPEAT; if (button == BUTTON_POWER) done=true; lcd_puts(0, line++, "[USB Information]"); lcd_putsf(0, line++, "TRN_CTRL: 0x%04x TRN_LNSTAT: 0x%04x", M66591_TRN_CTRL, M66591_TRN_LNSTAT); lcd_putsf(0, line++, "HSFS: 0x%04x TESTMODE: 0x%04x", M66591_HSFS, M66591_TESTMODE); lcd_putsf(0, line++, "PIN_CFG0: 0x%04x PIN_CFG1: 0x%04x", M66591_PIN_CFG0, M66591_PIN_CFG1); lcd_putsf(0, line++, "PIN_CFG2: 0x%04x", M66591_PIN_CFG2); lcd_putsf(0, line++, "DCP_CTRLEN: 0x%04x", M66591_DCP_CTRLEN); lcd_putsf(0, line++, "CPORT_CTRL0: 0x%04x CPORT_CTRL1: 0x%04x", M66591_CPORT_CTRL0, M66591_CPORT_CTRL1); lcd_putsf(0, line++, "CPORT_CTRL2: 0x%04x DPORT_CTRL0: 0x%04x", M66591_CPORT_CTRL2, M66591_DPORT_CTRL0); lcd_putsf(0, line++, "DPORT_CTRL1: 0x%04x DPORT_CTRL2: 0x%04x", M66591_DPORT_CTRL1, M66591_DPORT_CTRL2); lcd_putsf(0, line++, "INTCFG_MAIN: 0x%04x INTCFG_OUT: 0x%04x", M66591_INTCFG_MAIN, M66591_INTCFG_OUT); lcd_putsf(0, line++, "INTCFG_RDY: 0x%04x INTCFG_NRDY: 0x%04x", M66591_INTCFG_RDY, M66591_INTCFG_NRDY); lcd_putsf(0, line++, "INTCFG_EMP: 0x%04x INTSTAT_MAIN: 0x%04x", M66591_INTCFG_EMP, M66591_INTSTAT_MAIN); lcd_putsf(0, line++, "INTSTAT_RDY: 0x%04x INTSTAT_NRDY: 0x%04x", M66591_INTSTAT_RDY, M66591_INTSTAT_NRDY); lcd_putsf(0, line++, "INTSTAT_EMP: 0x%04x USB_ADDRESS: 0x%04x", M66591_INTSTAT_EMP, M66591_USB_ADDRESS); lcd_putsf(0, line++, "USB_REQ0: 0x%04x USB_REQ1: 0x%04x", M66591_USB_REQ0, M66591_USB_REQ1); lcd_putsf(0, line++, "USB_REQ2: 0x%04x USB_REQ3: 0x%04x", M66591_USB_REQ2, M66591_USB_REQ3); lcd_putsf(0, line++, "DCP_CNTMD: 0x%04x DCP_MXPKSZ: 0x%04x", M66591_DCP_CNTMD, M66591_DCP_MXPKSZ); lcd_putsf(0, line++, "DCPCTRL: 0x%04x", M66591_DCPCTRL); line++; for(i=1; i<6; i++) { M66591_PIPE_CFGWND=i; lcd_putsf(0, line++, "PIPE_CFGSEL:0x%04x PIPE_CFGWND: 0x%04x", M66591_PIPE_CFGSEL, M66591_PIPE_CFGWND); } line++; lcd_putsf(0, line++, "PIPECTRL1: 0x%04x PIPECTRL2: 0x%04x", M66591_PIPECTRL1, M66591_PIPECTRL2); lcd_putsf(0, line++, "PIPECTRL3: 0x%04x PIPECTRL4: 0x%04x", M66591_PIPECTRL3, M66591_PIPECTRL4); lcd_putsf(0, line++, "PIPECTRL5: 0x%04x PIPECTRL6: 0x%04x", M66591_PIPECTRL5, M66591_PIPECTRL6); lcd_putsf(0, line++, "GIO_BITSET0: 0x%04x GIO_BITSET1: 0x%04x", IO_GIO_BITSET0, IO_GIO_BITSET1); lcd_putsf(0, line++, "GIO_BITSET2: 0x%04x", IO_GIO_BITSET2); lcd_putsf(0, line++, "SDRAM_SDMODE: 0x%04x SDRAM_REFCTL: 0x%04x", IO_SDRAM_SDMODE, IO_SDRAM_REFCTL); lcd_putsf(0, line++, "EMIF_CS4CTRL1:0x%04x EMIF_CS4CTRL2:0x%04x", IO_EMIF_CS4CTRL1, IO_EMIF_CS4CTRL2); lcd_update(); } #endif return false; }
int main(void) { bool_t isUserRun = FALSE; bool_t displayCountdown = TRUE; uint16_t bootByte; _ee_getReserved(_AI_EE_RES_ADDR_BOOT, &bootByte); if (button_get(0) && button_get(1)) { // Both buttons are pressed so the user // wants to run the bootloader. isUserRun = TRUE; } else if (bootByte != _AI_EE_RES_VAL_BOOT_RUN) { startProgram(); } _ee_putReserved(_AI_EE_RES_ADDR_BOOT, _AI_EE_RES_VAL_DEFAULT); led_on(0); led_on(1); int i, j; for (i = 0; i < BOOT_TIMEOUT; i++) { if (isUserRun) { // flash LED1 if (i % 100 == 0) led_toggle(1); // update the countdown if (i % 1000 == 0) { lcd_clear(); lcd_printf("Aithon Board\n%d", (BOOT_TIMEOUT-i)/1000); displayCountdown = TRUE; } // show the bootloader build date if button 0 pressed if (button_get(0) && displayCountdown) { if (i > (.1 * BOOT_TIMEOUT)) { lcd_clear(); lcd_printf(DATE); displayCountdown = FALSE; } } } // check all the interfaces for a SYNC for (j = 0; j < NUM_INTERFACES; j++) { if (sdGetTimeout(_interfaces[j], TIME_IMMEDIATE) == SYNC) { _interface = _interfaces[j]; updateProgram(); // We should never get here... while(1); } } chThdSleepMilliseconds(1); } startProgram(); return 0; }
/* scale */ return output >> scalebits; } #define INPUT_BUFFER_SIZE (5*8192) #define OUTPUT_BUFFER_SIZE 8192 /* Must be an integer multiple of 4. */ void real_mpeg_play(char* fname) { unsigned char InputBuffer[INPUT_BUFFER_SIZE], OutputBuffer[OUTPUT_BUFFER_SIZE], *OutputPtr=OutputBuffer; const unsigned char *OutputBufferEnd=OutputBuffer+OUTPUT_BUFFER_SIZE; int Status=0, i, fd; unsigned long FrameCount=0; sound_t sound; struct mp3entry mp3; static struct dither d0, d1; int key=0; mp3info(&mp3, fname, false); /* FIXME: honor the v1first setting */ init_sound(&sound); /* Configure sound device for this file - always select Stereo because some sound cards don't support mono */ config_sound(&sound,mp3.frequency,2); if ((fd=open(fname,O_RDONLY)) < 0) { fprintf(stderr,"could not open %s\n",fname); return; } /* First the structures used by libmad must be initialized. */ mad_stream_init(&Stream); mad_frame_init(&Frame); mad_synth_init(&Synth); mad_timer_reset(&Timer); do { if (Stream.buffer==NULL || Stream.error==MAD_ERROR_BUFLEN) { size_t ReadSize,Remaining; unsigned char *ReadStart; if(Stream.next_frame!=NULL) { Remaining=Stream.bufend-Stream.next_frame; memmove(InputBuffer,Stream.next_frame,Remaining); ReadStart=InputBuffer+Remaining; ReadSize=INPUT_BUFFER_SIZE-Remaining; } else { ReadSize=INPUT_BUFFER_SIZE, ReadStart=InputBuffer, Remaining=0; } if ((int)(ReadSize=read(fd,ReadStart,ReadSize)) < 0) { fprintf(stderr,"end of input stream\n"); break; } mad_stream_buffer(&Stream,InputBuffer,ReadSize+Remaining); Stream.error=0; } if(mad_frame_decode(&Frame,&Stream)) { if(MAD_RECOVERABLE(Stream.error)) { fprintf(stderr,"recoverable frame level error\n"); fflush(stderr); continue; } else { if(Stream.error==MAD_ERROR_BUFLEN) { continue; } else { fprintf(stderr,"unrecoverable frame level error\n"); Status=1; break; } } } FrameCount++; mad_timer_add(&Timer,Frame.header.duration); mad_synth_frame(&Synth,&Frame); for(i=0;i<Synth.pcm.length;i++) { unsigned short Sample; /* Left channel */ Sample=scale(Synth.pcm.samples[0][i],&d0); *(OutputPtr++)=Sample&0xff; *(OutputPtr++)=Sample>>8; /* Right channel. If the decoded stream is monophonic then * the right output channel is the same as the left one. */ if(MAD_NCHANNELS(&Frame.header)==2) { Sample=scale(Synth.pcm.samples[1][i],&d1); } *(OutputPtr++)=Sample&0xff; *(OutputPtr++)=Sample>>8; /* Flush the buffer if it is full. */ if (OutputPtr==OutputBufferEnd) { if (output_sound(&sound, OutputBuffer, OUTPUT_BUFFER_SIZE)!=OUTPUT_BUFFER_SIZE) { fprintf(stderr,"PCM write error.\n"); Status=2; break; } OutputPtr=OutputBuffer; } } if ((key=button_get(0))==BUTTON_STOP) { break; } }while(1); /* Mad is no longer used, the structures that were initialized must * now be cleared. */ mad_synth_finish(&Synth); mad_frame_finish(&Frame); mad_stream_finish(&Stream); /* If the output buffer is not empty and no error occured during * the last write, then flush it. */ if(OutputPtr!=OutputBuffer && Status!=2) { size_t BufferSize=OutputPtr-OutputBuffer; if (output_sound(&sound, OutputPtr, BufferSize)!=(int)BufferSize) { fprintf(stderr,"PCM write error\n"); Status=2; } } /* Accounting report if no error occured. */ if(!Status) { char Buffer[80]; mad_timer_string(Timer,Buffer,"%lu:%02lu.%03u", MAD_UNITS_MINUTES,MAD_UNITS_MILLISECONDS,0); fprintf(stderr,"%lu frames decoded (%s).\n",FrameCount,Buffer); } close_sound(&sound); /* That's the end of the world (in the H. G. Wells way). */ return; }