/* Gibt ein paar Töne der Tonleiter aus. Ein Rechtecksignal der Frequenz des Tons wird mit dem Systicktimer erzeugt. Der Timer startet mit der Frequenz 2*Frequenz_des_Tons und pro Schwingung 2 Mal aufgerufen. Beim ersten Mal wird das Rechtecksignal ein- und beim zweiten Mal wieder ausgeschatlet. Die Tonausgabe liegt an am Pin PA4. Es wird eine einfache Tonleiter, pro Ton 1/2 Sekunde, ausgegeben. Schaltung: Ausgabe-Pin --> 2K -> Kopfhörer -> GND Am Ausgabepin muss ein etwa 1K bis 2K grosser Vorwiderstand vor dem Kopfhörer angeschlossen sein. Danach der Kopfhörer und dann 0V (-, Erde, GND). Grösse des Wiederstandes: Sei Impedanz des Kopfhörers 240 Ohm Rk: Die Leistung P sollte kleiner 1mW betragen. P = I * V = V/(Rk+Rv) * (I*Rk) = (V/(Rk+Rv))**2 * Rk V = 3.3V, Rk = 240 Ohm, und Vorwiederstand Rv = 2K ==> P = 0.5mW Am besten wird der Kopfhörer über einen "Audio jack" / Klinkenbuchse 3.5mm angeschlossen. */ int main(void) { enable_gpio_clockcntrl(GPIO_PORTA_BIT/*switch+audio out*/|GPIO_PORTE_BIT/*led*/); config_input_gpio(GPIO_PORTA, GPIO_PIN0, GPIO_PULL_OFF); config_output_gpio(GPIO_PORTA, GPIO_PIN4); config_output_gpio(GPIO_PORTE, GPIO_PINS(15,8)); config_systick(8000000/*dummy*/, systickcfg_CORECLK|systickcfg_INTERRUPT); write1_gpio(GPIO_PORTE, GPIO_PIN8); while (1) { if (read_gpio(GPIO_PORTA, GPIO_PIN0) == 1) { setperiod_systick(note_period[C1]); counter = 0; isON = 1; start_systick(); for (unsigned tone = C1+1; tone <= C2; ++tone) { unsigned led = 8 + (tone & 7); setpins_gpio(GPIO_PORTE, GPIO_PINS(led,led), GPIO_PINS(15,8)&~led); while (4000000 > counter) ; while (! isON) ; while (isON) ; counter = 0; setperiod_systick(note_period[tone]); } stop_systick(); while (read_gpio(GPIO_PORTA, GPIO_PIN0) == 1) ; } } }
void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { {REC_SW, ACTIVE_LOW, read_gpio(REC_SW), "recovery"}, {WP_SW, ACTIVE_LOW, read_gpio(WP_SW), "write protect"}, {-1, ACTIVE_LOW, 1, "power"}, {-1, ACTIVE_LOW, 0, "lid"}, }; lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios)); }
static enum switch_state get_switch_state(void) { struct stopwatch sw; int sampled_value; uint8_t rec_sw; static enum switch_state saved_state = not_probed; if (saved_state != not_probed) return saved_state; rec_sw = get_rec_sw_gpio_pin(); sampled_value = read_gpio(rec_sw) ^ !REC_POL; if (!sampled_value) { saved_state = no_req; display_pattern(WWR_NORMAL_BOOT); return saved_state; } display_pattern(WWR_RECOVERY_PUSHED); printk(BIOS_INFO, "recovery button pressed\n"); stopwatch_init_msecs_expire(&sw, WIPEOUT_MODE_DELAY_MS); do { sampled_value = read_gpio(rec_sw) ^ !REC_POL; if (!sampled_value) break; } while (!stopwatch_expired(&sw)); if (sampled_value) { display_pattern(WWR_WIPEOUT_REQUEST); printk(BIOS_INFO, "wipeout requested, checking recovery\n"); stopwatch_init_msecs_expire(&sw, RECOVERY_MODE_EXTRA_DELAY_MS); do { sampled_value = read_gpio(rec_sw) ^ !REC_POL; if (!sampled_value) break; } while (!stopwatch_expired(&sw)); if (sampled_value) { saved_state = recovery_req; display_pattern(WWR_RECOVERY_REQUEST); printk(BIOS_INFO, "recovery requested\n"); } else { saved_state = wipeout_req; } } else { saved_state = no_req; display_pattern(WWR_NORMAL_BOOT); } return saved_state; }
void fill_lb_gpios(struct lb_gpios *gpios) { struct lb_gpio chromeos_gpios[] = { {DEV_SW, DEV_POL, read_gpio(DEV_SW), "developer"}, {get_rec_sw_gpio_pin(), REC_POL, read_gpio(get_rec_sw_gpio_pin()), "recovery"}, {get_wp_status_gpio_pin(), WP_POL, read_gpio(get_wp_status_gpio_pin()), "write protect"}, {-1, ACTIVE_LOW, 1, "power"}, {-1, ACTIVE_LOW, 0, "lid"}, }; lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios)); }
uint8 cs84xx_read_gpio(ice1712 *ice, uint8 reg_addr, uint8 chip_select) { uint8 tmp, data; tmp = read_gpio(ice); tmp |= ice->CommLines.cs_mask; tmp &= ~(chip_select); write_gpio(ice, tmp); snooze(GPIO_I2C_DELAY); write_gpio_byte(ice, (CS84xx_CHIP_ADDRESS & 0x7F) << 1, tmp); //For writing the MAP write_gpio_byte(ice, reg_addr & 0x7F, tmp); //Do not Increment tmp |= chip_select; //Deselect the chip write_gpio(ice, tmp); snooze(GPIO_I2C_DELAY); tmp &= ~(chip_select); //Reselect the chip write_gpio(ice, tmp); snooze(GPIO_I2C_DELAY); write_gpio_byte(ice, (CS84xx_CHIP_ADDRESS & 0x7F) << 1 | 1, tmp); //For writing the MAP data = read_gpio_byte(ice, tmp); //For reading tmp |= chip_select; //Deselect the chip write_gpio(ice, tmp); return data; }
/* reads the state from the gpios and updates their states returns the number of state changes */ static int read_gpios(int gpiocount, int states[MAX_GPIO_COUNT], char filenames[][MAX_FILENAME_LENGTH]) { int value; int i; int value_changed = 0; if (gpiocount > MAX_GPIO_COUNT) gpiocount = MAX_GPIO_COUNT; for (i = 0; i < gpiocount; i++) { if (read_gpio(filenames[i], &value)) { if (states[i] != value) value_changed++; states[i] = value; } else { if (states[i] != -1) value_changed++; states[i] = -1; } } return value_changed; }
void wait_for_quiet(int gpio_fd,int priority,pthread_mutex_t *lock){ int res; struct timespec start; struct timespec temp_time; long int duration = 10*BIT_TIME + 2*BIT_TIME * priority; int quiet = 0; pthread_mutex_lock(lock); clock_gettime(CLOCK_MONOTONIC,&start); while(!quiet){ clock_gettime(CLOCK_MONOTONIC, &temp_time); if(read_gpio()){ if(difftimenanos(diff(start,temp_time)) >= duration) quiet = 1; }else{ pthread_mutex_unlock(lock); pthread_mutex_lock(lock); start.tv_sec = temp_time.tv_sec; start.tv_nsec = temp_time.tv_nsec; } } }
static void headset_timer_callback(unsigned long arg) { struct headset_priv *headset = (struct headset_priv *)(arg); struct rk_headset_pdata *pdata = headset->pdata; int level = 0; // printk("headset_timer_callback,headset->headset_status=%d\n",headset->headset_status); if(headset->headset_status == HEADSET_OUT) { printk("Headset is out\n"); goto out; } #ifdef CONFIG_SND_SOC_WM8994 if(wm8994_set_status() != 0) { // printk("wait wm8994 set the MICB2\n"); // headset_info->headset_timer.expires = jiffies + 500; headset_info->headset_timer.expires = jiffies + 10; add_timer(&headset_info->headset_timer); goto out; } #endif level = read_gpio(pdata->hook_gpio); if(level < 0) goto out; if((level > 0 && pdata->hook_down_type == HOOK_DOWN_LOW) || (level == 0 && pdata->hook_down_type == HOOK_DOWN_HIGH)) { headset->isMic = 1;//have mic DBG("enable headset_hook irq\n"); enable_irq(headset_info->irq[HOOK]); headset->isHook_irq = enable; headset_info->hook_status = HOOK_UP; if(pdata->hook_down_type == HOOK_DOWN_HIGH) irq_set_irq_type(headset_info->irq[HOOK],IRQF_TRIGGER_RISING); else irq_set_irq_type(headset_info->irq[HOOK],IRQF_TRIGGER_FALLING); } else headset->isMic= 0;//No microphone printk("headset->isMic = %d\n",headset->isMic); headset_info->cur_headset_status = headset_info->isMic ? 1:2;//BIT_HEADSET:BIT_HEADSET_NO_MIC;// #if defined(CONFIG_SND_RK_SOC_RK2928) || defined(CONFIG_SND_RK29_SOC_RK610) rk2928_codec_set_spk(HEADSET_IN); if(headset_info->cur_headset_status == 1) gpio_set_value(pdata->Sw_mic_gpio, pdata->Hp_mic_io_value); #endif // rk28_send_wakeup_key(); switch_set_state(&headset_info->sdev, headset_info->cur_headset_status); DBG("headset_info->cur_headset_status = %d\n",headset_info->cur_headset_status); out: return; }
static void hook_work(struct work_struct *work) { int level = 0; struct rk_headset_pdata *pdata = headset_info->pdata; static unsigned int old_status = HOOK_UP; mutex_lock(&headset_info->mutex_lock[HOOK]); if(headset_info->headset_status == HEADSET_OUT){ DBG("Headset is out\n"); goto RE_ERROR; } #ifdef CONFIG_SND_SOC_WM8994 if(wm8994_set_status() != 0) { DBG("wm8994 is not set on heatset channel or suspend\n"); goto RE_ERROR; } #endif level = read_gpio(pdata->hook_gpio); if(level < 0) goto RE_ERROR; old_status = headset_info->hook_status; DBG("Hook_work -- level = %d\n",level); if(level == 0) headset_info->hook_status = pdata->hook_down_type == HOOK_DOWN_HIGH?HOOK_UP:HOOK_DOWN; else if(level > 0) headset_info->hook_status = pdata->hook_down_type == HOOK_DOWN_HIGH?HOOK_DOWN:HOOK_UP; if(old_status == headset_info->hook_status) { DBG("old_status == headset_info->hook_status\n"); goto RE_ERROR; } DBG("Hook_work -- level = %d hook status is %s\n",level,headset_info->hook_status?"key down":"key up"); if(headset_info->hook_status == HOOK_DOWN) { if(pdata->hook_down_type == HOOK_DOWN_HIGH) irq_set_irq_type(headset_info->irq[HOOK],IRQF_TRIGGER_FALLING); else irq_set_irq_type(headset_info->irq[HOOK],IRQF_TRIGGER_RISING); } else { if(pdata->hook_down_type == HOOK_DOWN_HIGH) irq_set_irq_type(headset_info->irq[HOOK],IRQF_TRIGGER_RISING); else irq_set_irq_type(headset_info->irq[HOOK],IRQF_TRIGGER_FALLING); } input_report_key(headset_info->input_dev,HOOK_KEY_CODE,headset_info->hook_status); input_sync(headset_info->input_dev); RE_ERROR: mutex_unlock(&headset_info->mutex_lock[HOOK]); }
static void read_gpios(void *arg, long period) { gpio_t *s; s = arg; while ( s != NULL ) { read_gpio(s, period); s = s->next; } }
//IRQ received from WPC, copy data into input queue void irq_recv (void) { int val; val = read_gpio(); if (verbose) fprintf (stdout, "Received %i on GPIO\n", val); queue_add (&gpio_input_q, val); //Assuming that the WPC CPU reads U29 before it tries to send data to U30 output_waiting = false; }
/* Gibt mit 11025 Hz gesampeltes Geräusch an Pin PA4 und PA5 mittels Digital-Analog-Converter aus. Eine 3.5mm Kopfhörerbuchse sollte an die Anschlüsse GND, PA4 und PA5 angeschlossen werden per Steckbrett und Jumper-Kabel. Ein Vorwiderstand zwischen GND und Buchse von mind. 100Ohm und fertig. Kopfhörer angeschlossen, nun kann der Sound akustisch wahrgenommen werden. Ein Druck auf den User-Button erzeugt ein Schussgeräusch, dann ein UFO und danach erklingt eine Explosion. Wird die Usertaste erneut gedrückt, bevor das Geräusch ausgeklungen ist, wird die Ausgabe wiederholt, beginnend mit dem Schussgeräusch. */ int main(void) { enable_gpio_clockcntrl(GPIO_PORTA_BIT/*switch+audio-out*/|GPIO_PORTE_BIT/*led*/); enable_dac_clockcntrl(); config_input_gpio(GPIO_PORTA, GPIO_PIN0, GPIO_PULL_OFF); // Wichtig: Zuerst IOPIN auf analog umschalten, damit keine parasitären Ströme fliessen config_analog_gpio(GPIO_PORTA, GPIO_PIN4); #if defined(USE_EXTI_LINE9) config_output_gpio(GPIO_PORTA, GPIO_PIN9); #endif config_output_gpio(GPIO_PORTE, GPIO_PINS(15,8)); #if defined(USE_SWTRIGGER) config_dac(DAC1, dac_channel_DUAL, daccfg_ENABLE_CHANNEL|daccfg_ENABLE_TRIGGER|daccfg_TRIGGER_SOFTWARE); #elif defined(USE_EXTI_LINE9) config_dac(DAC1, dac_channel_DUAL, daccfg_ENABLE_CHANNEL|daccfg_ENABLE_TRIGGER|daccfg_TRIGGER_EXTI_LINE9); #else config_dac(DAC1, dac_channel_DUAL, daccfg_ENABLE_CHANNEL|daccfg_DISABLE_TRIGGER); #endif if (isenabled_dac(DAC1, dac_channel_1) != 1 || isenabled_dac(DAC1, dac_channel_2) != 1 || isenabled_dac(DAC1, dac_channel_DUAL) != 1) { // error write1_gpio(GPIO_PORTE, GPIO_PINS(15,8)); } config_systick((8000000+11025/2) / 11025, systickcfg_CORECLK|systickcfg_INTERRUPT); write1_gpio(GPIO_PORTE, GPIO_PIN8); while (1) { if (read_gpio(GPIO_PORTA, GPIO_PIN0) == 1) { stop_systick(); counter = 0; soundnr = 0; start_systick(); write1_gpio(GPIO_PORTE, GPIO_PIN9); while (read_gpio(GPIO_PORTA, GPIO_PIN0) == 1) ; write0_gpio(GPIO_PORTE, GPIO_PIN9); } } }
int read_register(unsigned char mask) { unsigned char val[2]; if(read_gpio(val) < 0){ return -1; } if(val[0] & mask) return 1; else return 0; }
int main(int ac, char *av[]) { int ret=0; if(ac < 2 || ac > 4){ usage(av[0]); return -1; } if(strncmp(QUIET, av[1], strlen(QUIET)) == 0) quiet = 1; if(strncmp(INIT, av[1], strlen(INIT)) == 0){ if((ret = init_gpio(av[2])) == -1) return -1; if(!quiet) printf("%02x\n", ret); } else if(strncmp(READ, av[1], strlen(READ)) == 0){ if((ret = read_gpio()) < 0) return -1; if(!quiet) printf("%02x\n", ret); } else if(strncmp(WRITE, av[1], strlen(WRITE)) == 0){ if(write_gpio(av[2]) < 0) return -1; if((ret = read_gpio()) < 0) return -1; if(!quiet) printf("%02x\n", ret); } else{ usage(av[0]); return -1; } return ret; }
static void Hp_mic_work(struct work_struct *work) { int level = 0; struct rk_headset_pdata *pdata = headset_info->pdata; printk("hp_mic_work---------\n"); mutex_lock(&headset_info->mutex_lock[MIC]); if(headset_info->headset_status == HEADSET_OUT) { printk("Headset is out\n"); goto out; } level = read_gpio(pdata->Hook_gpio); if(level < 0) goto out; if((level > 0 && pdata->Hook_down_type == HOOK_DOWN_LOW) || (level == 0 && pdata->Hook_down_type == HOOK_DOWN_HIGH)) { headset_info->isMic = 1;//have mic DBG("enable headset_hook irq\n"); enable_irq(headset_info->irq[HOOK]); headset_info->isHook_irq = enable; headset_info->hook_status = HOOK_UP; if(pdata->Hook_down_type == HOOK_DOWN_HIGH) irq_set_irq_type(headset_info->irq[HOOK],IRQF_TRIGGER_RISING); else irq_set_irq_type(headset_info->irq[HOOK],IRQF_TRIGGER_FALLING); Switch_Mic_Mode(HP_MIC); } else headset_info->isMic= 0;//No microphone printk("headset->isMic = %d\n",headset_info->isMic); headset_info->cur_headset_status = headset_info->isMic ? BIT_HEADSET:BIT_HEADSET_NO_MIC; #if defined(CONFIG_SND_RK_SOC_RK2928) rk2928_codec_set_spk(HEADSET_IN); #endif rk28_send_wakeup_key(); switch_set_state(&headset_info->sdev, headset_info->cur_headset_status); DBG("headset_info->cur_headset_status = %d\n",headset_info->cur_headset_status); out: mutex_unlock(&headset_info->mutex_lock[MIC]); return; }
static int local_decision(void) { /* read keys and pswitch */ int val = read_lradc(0); /* if hold is on, power off * if back is pressed, boot to OF * if play is pressed, boot RB * otherwise power off */ if(read_gpio(0, 9) == 0) return BOOT_STOP; if(val >= 1050 && val < 1150) return BOOT_OF; if(val >= 1420 && val < 1520) return BOOT_ROCK; return BOOT_STOP; }
static int boot_decision(int context) { /* We are lacking buttons on the Zen X-Fi2 because on USB, the select button * enters recovery mode ! So we can only use power but power is used to power up * on normal boots and then select is free ! Thus use a non-uniform scheme: * - normal boot/RTC: * - no key: Rockbox * - select: OF * - USB boot: * - no key: Rockbox * - power: OF */ if(context == CONTEXT_USB) return read_pswitch() == 1 ? BOOT_OF : BOOT_ROCK; else return !read_gpio(0, 14) ? BOOT_OF : BOOT_ROCK; }
int synchronize(){ struct timespec start; struct timespec temp_time; int synced = 0; clock_gettime(CLOCK_MONOTONIC, &start); while(!synced){ clock_gettime(CLOCK_MONOTONIC, &temp_time); if(read_gpio()){ // printf("%d\n",difftimenanos(diff(start,temp_time))); if(difftimenanos(diff(start,temp_time)) >= TWELVEBITTIMES) synced = 1; }else{ start.tv_sec = temp_time.tv_sec; start.tv_nsec = temp_time.tv_nsec; } } }
static enum boot_t boot_decision(enum context_t context) { /* if volume down is hold, boot to OF */ if(!read_gpio(1, 30)) return BOOT_OF; /* on normal boot, make sure power button is hold long enough */ if(context == CONTEXT_NORMAL) { // monitor PSWITCH int count = 0; for(int i = 0; i < 550000; i++) if(read_pswitch() == 1) count++; if(count < 400000) return BOOT_STOP; } return BOOT_ROCK; }
int write_register(char *flag, unsigned char mask) { unsigned char val[2]; if(read_gpio(val) < 0) return -1; if(strcmp("high", flag) == 0) val[0] |= mask; else if(strcmp("low", flag) == 0) val[0] &= ~mask; else return -1; if(write_gpio(val) < 0) return -1; return read_register(mask); }
void ak45xx_write_gpio(ice1712 *ice, uint8 reg_addr, uint8 data, uint8 chip_select) { uint8 tmp; tmp = read_gpio(ice); tmp |= ice->CommLines.cs_mask; tmp &= ~(chip_select); write_gpio(ice, tmp); snooze(GPIO_I2C_DELAY); write_gpio_byte(ice, ((AK45xx_CHIP_ADDRESS & 0x03) << 6) | 0x20 | (reg_addr & 0x1F), tmp); write_gpio_byte(ice, data, tmp); tmp |= chip_select; write_gpio(ice, tmp); snooze(GPIO_I2C_DELAY); }
void cs84xx_write_gpio(ice1712 *ice, uint8 reg_addr, uint8 data, uint8 chip_select) { uint8 tmp; tmp = read_gpio(ice); tmp |= ice->CommLines.cs_mask; tmp &= ~(chip_select); write_gpio(ice, tmp); snooze(GPIO_I2C_DELAY); write_gpio_byte(ice, (CS84xx_CHIP_ADDRESS & 0x7F) << 1, tmp); write_gpio_byte(ice, reg_addr & 0x7F, tmp); //Do not Increment write_gpio_byte(ice, data, tmp); tmp |= chip_select; write_gpio(ice, tmp); snooze(GPIO_I2C_DELAY); }
/* Schaltet die Onboard LEDs ein und aus, um einen PWM-Timer mit dem systick Timer zu emulieren. Die Hälfte der LEDs leuchtet mit voller Stärke, um einen Vergleich zu haben. Mit einem Druck auf den User-Button werden die LEDs dunkler. Nach mehreren Tastendrücken werden diese wieder auf ihre Anfangsleuchtstärke zurückgesetzt. */ int main(void) { enable_gpio_clockcntrl(GPIOA_BIT/*switch*/|GPIOE_BIT/*led*/); config_input_gpio(GPIOA, GPIO_PIN0, GPIO_PULL_OFF); config_output_gpio(GPIOE, GPIO_PINS(15,8)); config_systick(8000000/10000/*0.1msec An-Zeit*/, systickcfg_CORECLOCK|systickcfg_INTERRUPT|systickcfg_START); write1_gpio(GPIOE, GPIO_PINS(11,8)); while (1) { if (read_gpio(GPIOA, GPIO_PIN0) == 1) { offmultiple += offmultiple / 2; if (offmultiple > 200) offmultiple = 2; for (volatile int i = 0; i < 100000; ++i) ; // while (read_gpio(GPIOA, GPIO_PIN0) == 1) ; } } }
uint8 read_gpio_byte(ice1712 *ice, uint8 gpio_data) { int i; uint8 data = 0; for (i = 7; i >= 0; i--) { // drop clock gpio_data &= ~(ice->CommLines.clock); write_gpio(ice, gpio_data); snooze(GPIO_I2C_DELAY); if (read_gpio(ice) & ice->CommLines.data_in) data |= 1 << i; gpio_data |= ice->CommLines.clock; write_gpio(ice, gpio_data); snooze(GPIO_I2C_DELAY); } return data; }
static void headsetobserve_work(struct work_struct *work) { int level = 0; int level2 = 0; struct rk_headset_pdata *pdata = headset_info->pdata; static unsigned int old_status = 0; DBG("---headsetobserve_work---\n"); mutex_lock(&headset_info->mutex_lock[HEADSET]); level = read_gpio(pdata->headset_gpio); if(level < 0) goto out; msleep(100); level2 = read_gpio(pdata->headset_gpio); if(level2 < 0) goto out; if(level2 != level) goto out; old_status = headset_info->headset_status; if(pdata->headset_insert_type == HEADSET_IN_HIGH) headset_info->headset_status = level?HEADSET_IN:HEADSET_OUT; else headset_info->headset_status = level?HEADSET_OUT:HEADSET_IN; if(old_status == headset_info->headset_status) { DBG("old_status == headset_info->headset_status\n"); goto out; } DBG("(headset in is %s)headset status is %s\n", pdata->headset_insert_type?"high level":"low level", headset_info->headset_status?"in":"out"); if(headset_info->headset_status == HEADSET_IN) { headset_info->cur_headset_status = BIT_HEADSET_NO_MIC; if(pdata->headset_insert_type == HEADSET_IN_HIGH) irq_set_irq_type(headset_info->irq[HEADSET],IRQF_TRIGGER_FALLING); else irq_set_irq_type(headset_info->irq[HEADSET],IRQF_TRIGGER_RISING); if (pdata->hook_gpio) { del_timer(&headset_info->headset_timer);//Start the timer, wait for switch to the headphone channel headset_info->headset_timer.expires = jiffies + 100; add_timer(&headset_info->headset_timer); goto out; } } else if(headset_info->headset_status == HEADSET_OUT) { headset_info->hook_status = HOOK_UP; if(headset_info->isHook_irq == enable) { DBG("disable headset_hook irq\n"); headset_info->isHook_irq = disable; disable_irq(headset_info->irq[HOOK]); } headset_info->cur_headset_status = 0;//~(BIT_HEADSET|BIT_HEADSET_NO_MIC); //#if defined(CONFIG_SND_RK_SOC_RK2928) || defined(CONFIG_SOC_RK3028) //rk2928_codec_set_spk(HEADSET_OUT); //#endif if(pdata->headset_insert_type == HEADSET_IN_HIGH) irq_set_irq_type(headset_info->irq[HEADSET],IRQF_TRIGGER_RISING); else irq_set_irq_type(headset_info->irq[HEADSET],IRQF_TRIGGER_FALLING); } // rk28_send_wakeup_key(); switch_set_state(&headset_info->sdev, headset_info->cur_headset_status); #if defined(CONFIG_SND_RK_SOC_RK2928) || defined(CONFIG_SND_RK29_SOC_RK610) if (headset_info->headset_status == HEADSET_OUT) { mdelay(200); rk2928_codec_set_spk(HEADSET_OUT); gpio_set_value(pdata->Sw_mic_gpio, headset_info->pdata->Main_mic_io_value); } #endif DBG("headset_info->cur_headset_status = %d\n",headset_info->cur_headset_status); out: mutex_unlock(&headset_info->mutex_lock[HEADSET]); }
status_t ice1712_buffer_exchange(ice1712 *card, multi_buffer_info *data) { int cpu_status = 0, status; /* unsigned char peak[MAX_ADC]; int i; */ // TRACE("Avant Exchange p : %d, r : %d\n", data->playback_buffer_cycle, data->record_buffer_cycle); status = acquire_sem_etc(card->buffer_ready_sem, 1, B_RELATIVE_TIMEOUT | B_CAN_INTERRUPT, 50000); switch (status) { case B_NO_ERROR: // TRACE("B_NO_ERROR\n"); cpu_status = disable_interrupts(); // Playback buffers info data->played_real_time = card->played_time; data->played_frames_count = card->frames_count; data->playback_buffer_cycle = (card->buffer - 1) % SWAPPING_BUFFERS; //Buffer played // Record buffers info data->recorded_real_time = card->played_time; data->recorded_frames_count = card->frames_count; data->record_buffer_cycle = (card->buffer - 1) % SWAPPING_BUFFERS; //Buffer filled data->flags = B_MULTI_BUFFER_PLAYBACK | B_MULTI_BUFFER_RECORD; restore_interrupts(cpu_status); break; case B_BAD_SEM_ID: TRACE("B_BAD_SEM_ID\n"); break; case B_INTERRUPTED: TRACE("B_INTERRUPTED\n"); break; case B_BAD_VALUE: TRACE("B_BAD_VALUE\n"); break; case B_WOULD_BLOCK: TRACE("B_WOULD_BLOCK\n"); break; case B_TIMED_OUT: TRACE("B_TIMED_OUT\n"); start_DMA(card); cpu_status = lock(); data->played_real_time = card->played_time; data->playback_buffer_cycle = 0; data->played_frames_count += card->buffer_size; data->recorded_real_time = card->played_time; data->record_buffer_cycle = 0; data->recorded_frames_count += card->buffer_size; data->flags = B_MULTI_BUFFER_PLAYBACK | B_MULTI_BUFFER_RECORD; unlock(cpu_status); break; default: TRACE("Default\n"); break; } if ((card->buffer % 1500) == 0) { uint8 reg8, reg8_dir; reg8 = read_gpio(card); reg8_dir = read_cci_uint8(card, CCI_GPIO_DIRECTION_CONTROL); TRACE("DEBUG === GPIO = %d (dir %d)\n", reg8, reg8_dir); reg8 = spdif_read(card, CS84xx_VERSION_AND_CHIP_ID); TRACE("DEBUG === S/PDif Version : 0x%x\n", reg8); } return B_OK; }
int get_write_protect_state(void) { return read_gpio(WP_SW) ^ !WP_POL; }
int get_write_protect_state(void) { return read_gpio(get_wp_status_gpio_pin()) ^ !WP_POL; }
int get_spd_offset(void) { u32 base_addr = find_gpio_base(); u8 spd_offset = read_gpio(base_addr, GPIO_16); return spd_offset; }
int main(int ac, char *av[]) { int ret=0; if(ac != 2 && ac != 3){ usage(av[0]); return -1; } if(strncmp(INIT, av[1], strlen(INIT)) == 0){ if(init_gpio() == -1) return -1; } else if(strncmp(POWER, av[1], strlen(POWER)) == 0){ if(ac == 2){ if((ret = read_register(M_POWER)) == -1) return -1; printf("%d\n", ret); } else{ if((ret = write_register(av[2], M_POWER)) == -1) return -1; } } else if(strncmp(RESET1, av[1], strlen(RESET1)) == 0){ if(ac == 2){ if((ret = read_register(M_RESET1)) == -1) return -1; printf("%d\n", ret); } else{ if((ret = write_register(av[2], M_RESET1)) == -1) return -1; } } else if(strncmp(RESET2, av[1], strlen(RESET2)) == 0){ if(ac == 2){ if((ret = read_register(M_RESET2)) == -1) return -1; printf("%d\n", ret); } else{ if((ret = write_register(av[2], M_RESET2)) == -1) return -1; } } else if(strncmp(USBRST, av[1], strlen(USBRST)) == 0){ if(ac == 2){ if((ret = read_register(M_USBRST)) == -1) return -1; printf("%d\n", ret); } else{ if((ret = write_register(av[2], M_USBRST)) == -1) return -1; } } else if(strncmp(UARTINI, av[1], strlen(UARTINI)) == 0){ } else if(strncmp(AREAIND, av[1], strlen(AREAIND)) == 0){ } else if(strncmp(PSHOLD, av[1], strlen(PSHOLD)) == 0){ } else if(strncmp(RSTCHK, av[1], strlen(RSTCHK)) == 0){ } else if(strncmp(RI, av[1], strlen(RI)) == 0){ } else if(strncmp(FUPSTS, av[1], strlen(FUPSTS)) == 0){ } else if(strncmp(ANT0, av[1], strlen(ANT0)) == 0){ } else if(strncmp(ANT1, av[1], strlen(ANT1)) == 0){ } else if(strncmp(MOSIND, av[1], strlen(MOSIND)) == 0){ } else if(strncmp(RAW, av[1], strlen(RAW)) == 0){ unsigned char val[2]; if(read_gpio(val) < 0) return -1; printf("input: %02x %02x\n", val[1], val[0]); if(read_config(val) < 0) return -1; printf("config: %02x %02x\n", val[1], val[0]); if(read_output(val) < 0) return -1; printf("output: %02x %02x\n", val[1], val[0]); } else{ usage(av[0]); return -1; } return ret; }