/* Remote buttons */ void remote_int(void) { int state = 0x01 & ~GPIOD_INPUT_VAL; GPIO_CLEAR_BITWISE(GPIOD_INT_EN, 0x01); GPIO_WRITE_BITWISE(GPIOD_INT_LEV, state, 0x01); if (state != 0) { /* necessary delay 1msec */ udelay(1000); unsigned int val = adc_scan(ADC_REMOTE); if (val > 750) int_btn = BUTTON_RC_MINUS; else if (val > 375) int_btn = BUTTON_RC_PLUS; else if (val > 100) int_btn = BUTTON_RC_REW; else int_btn = BUTTON_RC_FFWD; } else int_btn = BUTTON_NONE; GPIO_SET_BITWISE(GPIOD_INT_CLR, 0x01); GPIO_SET_BITWISE(GPIOD_INT_EN, 0x01); }
bool remote_button_hold(void) { /* On my remote hold gives readout of 44 */ if (remote_detect()) return adc_scan(ADC_REMOTE)<50?true:false; else return false; }
static bool remote_detect(void) { /* When there is no remote adc readout * is exactly 0. We add some margin * for ADC readout instability */ return adc_scan(ADC_REMOTE)>10?true:false; }
/*----------------------------------------------------------------------------*/ void timer0isr(void) { static xd_u8 counter0, counter1; PSW = 0x08; DPCON = 0x0; T0CON &= ~BIT(7); //clear pending #ifdef LCD_GPIO_DRV seg_lcd_disp_scan(); #else //disp_scan(); #endif adc_scan(); counter0++; usb_polling(); #ifdef JOG_STICK_FUNC JogDetect(); #endif if ((counter0 % 5) == 0) //10ms { dec_delay_counter(); //#if SDMMC_CMD_MODE // sd_online_check(); //#if SDMMC_CLK_MODE sdmmc_online_chk(1); //#elif SDMMC_GPIO_MODE //sdmmc_detect(); //#endif keyScan(); } // if ((counter0 % 50) == 0) // { // put_msg_fifo(MSG_100MS); // } if ((counter0 % 100) == 0) { ad_mod_sel_hdlr(); put_msg_fifo(MSG_200MS); counter0 = 0; } counter1++; if ((counter1 % 250) == 0) { put_msg_fifo(MSG_HALF_SECOND); counter1 = 0; } #if 0//RTC_ENABLE if (IRTCON & BIT(7)) { alm_cnt = 1; last_work_mode = work_mode; put_msg_lifo(MSG_ALM_ON); } #endif }
/*----------------------------------------------------------------------------*/ void timer0isr(void) { static u8 counter0, counter1; PSW = 0x08; DPCON = 0x0; T0CON &= ~BIT(7); //clear pending #ifndef NO_LED_DISPLAY disp_scan(); #endif adc_scan(); counter0++; usb_polling(); disp_dled(); if ((counter0 % 5) == 0) //10ms { dec_delay_counter(); //#if SDMMC_CMD_MODE // sd_online_check(); #if SDMMC_CLK_MODE sdmmc_online_chk(1); #elif SDMMC_GPIO_MODE sdmmc_detect(); #endif keyScan(); } // if ((counter0 % 50) == 0) // { // put_msg_fifo(MSG_100MS); // } if ((counter0 % 100) == 0) { //aux_check(); //put_msg_fifo(MSG_200MS); counter0 = 0; } counter1++; if ((counter1 % 250) == 0) { put_msg_fifo(MSG_HALF_SECOND); counter1 = 0; } #if RTC_ENABLE if (IRTCON & BIT(7)) { alm_cnt = 1; last_work_mode = work_mode; put_msg_lifo(MSG_ALM_ON); } #endif }
/* Monitor remote hotswap */ static void remote_tick(void) { static bool last_status = false; static int countdown = 0; static int init_delay = 0; bool current_status; int val; int level; current_status = remote_detect(); /* Only report when the status has changed */ if (current_status != last_status) { last_status = current_status; countdown = current_status ? 20*HZ : 1; } else { /* Count down until it gets negative */ if (countdown >= 0) countdown--; if (current_status) { if (!(countdown % 8)) { /* Determine which type of remote it is */ level = disable_irq_save(); val = adc_scan(ADC_REMOTEDETECT); restore_irq(level); if (val < ADCVAL_H100_LCD_REMOTE_HOLD) { if (val < ADCVAL_H100_LCD_REMOTE) if (val < ADCVAL_H300_LCD_REMOTE) _remote_type = REMOTETYPE_H300_LCD; /* hold off */ else _remote_type = REMOTETYPE_H100_LCD; /* hold off */ else if (val < ADCVAL_H300_LCD_REMOTE_HOLD) _remote_type = REMOTETYPE_H300_LCD; /* hold on */ else _remote_type = REMOTETYPE_H100_LCD; /* hold on */ if (--init_delay <= 0) { queue_broadcast(SYS_REMOTE_PLUGGED, 0); init_delay = 6; } } else { _remote_type = REMOTETYPE_H300_NONLCD; /* hold on or off */ } } } else { if (countdown == 0) { _remote_type = REMOTETYPE_UNPLUGGED; queue_broadcast(SYS_REMOTE_UNPLUGGED, 0); } } } /* handle chip select timeout */ if (remote_cs_countdown >= 0) remote_cs_countdown--; if (remote_cs_countdown == 0) CS_HI; }
/*----------------------------------------------------------------------------*/ void timer1isr(void) { static u8 ms_cnt, counter; _push_(DPCON); _push_(DP1L); _push_(DP1H); DPCON = 0x0; T1CON &= ~(BIT(7)); disp_scan(); #ifdef USE_USB_SD_DECODE_FUNC udisk_disconnect_check(); usb_diskin_detect(); #endif #ifdef JOG_STICK_FUNC JogDetect(); #endif counter++; if (counter == 5) { counter = 0; if(dac_cnt < 21){ dac_cnt++; } adc_scan(); #ifdef USE_LINE_IN_DETECT_FUNC aux_check(); #endif keyScan(); dec_delay_counter(); #ifdef USE_USB_SD_DECODE_FUNC #ifndef NO_SD_DECODE_FUNC #if SDMMC_CMD_MODE sd_online_check(); #elif SDMMC_CLK_MODE sdmmc_online_chk(); #elif SDMMC_GPIO_MODE sdmmc_detect(); #endif #endif #endif ms_cnt++; #ifdef USE_CD_MCU_MASTER_FUNC if(ms_cnt%10==0){ mcu_master_cmd_tick=1; } if(ms_cnt%6==0){ mcu_master_tranceive_tick=1; } #endif if(ms_cnt%25==0){ if((work_mode == SYS_BLUE_TOOTH )||(work_mode == SYS_AUX)){ put_msg_fifo(INFO_250_MS); } } if (ms_cnt == 50) { ms_cnt = 0; put_msg_fifo(INFO_HALF_SECOND); LDO_IN_Volt=ldoin_voltage(); #ifdef USE_RTC_ALARM_FUNCTION check_alm(); #endif #ifdef SYS_GPIO_SEL_FUNC gpio_sel_func_mode(); #endif #ifdef ADKEY_SELECT_MODE ad_mod_sel_hdlr(); #endif } adc_start(); } _pop_(DP1H); _pop_(DP1L); _pop_(DPCON); }
int button_read_device(void) { int btn = BUTTON_NONE; bool hold_button_old; bool remote_hold_button_old; static int prev_data = 0xff; static int last_valid = 0xff; int data; /* normal buttons */ hold_button_old = hold_button; hold_button = button_hold(); #ifndef BOOTLOADER /* give BL notice if HB state chaged */ if (hold_button != hold_button_old) backlight_hold_changed(hold_button); #endif if (button_scan_on && !hold_button) { data = adc_scan(ADC_BUTTONS); /* ADC debouncing: Only accept new reading if it's * stable (+/-1). Use latest stable value otherwise. */ if ((unsigned)(data - prev_data + 1) <= 2) last_valid = data; prev_data = data; data = last_valid; if (data < 0xf0) { if(data < 0x7c) if(data < 0x42) btn = BUTTON_LEFT; else if(data < 0x62) btn = BUTTON_RIGHT; else btn = BUTTON_SELECT; else if(data < 0xb6) if(data < 0x98) btn = BUTTON_REC; else btn = BUTTON_PLAY; else if(data < 0xd3) btn = BUTTON_DOWN; else btn = BUTTON_UP; } } /* remote buttons */ data = remote_detect() ? adc_scan(ADC_REMOTE) : 0xff; remote_hold_button_old = remote_hold_button; remote_hold_button = data < 0x17; #ifndef BOOTLOADER if (remote_hold_button != remote_hold_button_old) remote_backlight_hold_changed(remote_hold_button); #endif if (!remote_hold_button) { if (data < 0xee) { if(data < 0x7a) if(data < 0x41) btn |= BUTTON_RC_FF; else if(data < 0x61) btn |= BUTTON_RC_REW; else btn |= BUTTON_RC_MODE; else if(data < 0xb4) if(data < 0x96) btn |= BUTTON_RC_REC; else btn |= BUTTON_RC_MENU; else if(data < 0xd1) btn |= BUTTON_RC_VOL_UP; else btn |= BUTTON_RC_VOL_DOWN; } } data = GPIO_READ; /* hold and power are mutually exclusive */ if (!(data & 0x04000000)) btn |= BUTTON_POWER; /* remote play button should be dead if hold */ if (!remote_hold_button && !(data & 0x02000000)) btn |= BUTTON_RC_PLAY; return btn; }
/* * Get button pressed from hardware */ int button_read_device(void) { int btn = BUTTON_NONE; int data = 0; static bool hold_button = false; bool remote_hold_button = false; bool hold_button_old; bool remote_present; /* check if we have remote connected */ remote_present = remote_detect(); /* read hold buttons status */ hold_button_old = hold_button; hold_button = button_hold(); remote_hold_button = remote_button_hold(); #ifndef BOOTLOADER /* Only main hold affects backlight */ if (hold_button != hold_button_old) backlight_hold_changed(hold_button); #endif /* Skip if main hold is active */ if (!hold_button) { data = adc_scan(ADC_BUTTONS); if (data < 2300) /* valid button */ { if (data < 900) /* middle */ { if (data < 500) { if (data > 200) /* 200 - 500 */ btn = BUTTON_REC; } else /* 900 - 500 */ btn = BUTTON_VOL_DOWN; } else /* 2250 - 900 */ { if (data < 1600) { /* 1600 - 900 */ if (data < 1200) /* 1200 - 900 */ btn = BUTTON_VOL_UP; else /* 1600 - 1200 */ btn = BUTTON_FF; } else /* 1600 - 2250 */ { if (data < 1900) /* 1900 - 1600 */ btn = BUTTON_REW; else /* 1900 - 2300 */ btn = BUTTON_FUNC; } } } } /* Skip if remote is not present or remote_hold is active */ if (remote_present && !remote_hold_button) { data = adc_scan(ADC_REMOTE); if (data < 2050) /* valid button */ { if (data < 950) /* middle */ { if (data < 650) { if (data < 400) { if (data > 250) /* 250 - 400 */ btn = BUTTON_RC_VOL_DOWN; } else /* 650 - 400 */ btn = BUTTON_RC_VOL_UP; } else /* 950 - 650 */ btn = BUTTON_RC_FF; } else /* 2050 - 950 */ { if (data < 1900) { if (data < 1350) /* 1350 - 900 */ btn = BUTTON_RC_REW; } else /* 2050 - 1900 */ btn = BUTTON_RC_FUNC; } } } /* PLAY buttons (both remote and main) are * GPIOs not ADC */ data = GPIO1_READ; /* GPIO56 active high main PLAY/PAUSE/ON */ if (!hold_button && ((data & (1<<24)))) btn |= BUTTON_PLAY; /* GPIO41 active high remote PLAY/PAUSE/ON */ if (remote_present && !remote_hold_button && ((data & (1<<9)))) btn |= BUTTON_RC_PLAY; return btn; }