static int fmcomms2adv_handle_driver(struct osc_plugin *plugin, const char *attrib, const char *value)
{
	int ret = 0;

	if (MATCH_ATTRIB("calibrate")) {
		/* Set a timer for 20 seconds that calibration should succeed within. */
		struct timespec ts_current, ts_end;
		unsigned long long nsecs;
		clock_gettime(CLOCK_MONOTONIC, &ts_current);
		nsecs = ts_current.tv_nsec + (20000 * pow(10.0, 6));
		ts_end.tv_sec = ts_current.tv_sec + (nsecs / pow(10.0, 9));
		ts_end.tv_nsec = nsecs % (unsigned long long) pow(10.0, 9);

		do_calibration(NULL, NULL);
		while (!auto_calibrate && (timespeccmp(&ts_current, &ts_end, >) == 0)) {
			gtk_main_iteration();
			clock_gettime(CLOCK_MONOTONIC, &ts_current);
		}

		/* Calibration timed out or failed, probably running an old board
		 * without an ADF5355 on it.
		 */
		if (auto_calibrate < 0) {
			fprintf(stderr, "FMCOMMS5 calibration failed.\n");
			ret = -1;
		}

		/* reset calibration completion flag */
		auto_calibrate = 0;
	} else if (MATCH_ATTRIB("SYNC_RELOAD") && atoi(value)) {
Exemplo n.º 2
0
void __antenna_calibrate(struct agnx_priv *priv)
{
	void __iomem *ctl = priv->ctl;
	u32 reg;

	/* Calibrate the BaseBandFilter */
	/* base_band_filter_calibrate(priv); */
	spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1002);


	agnx_write32(ctl, AGNX_GCR_GAINSET0, 0x1d);
	agnx_write32(ctl, AGNX_GCR_GAINSET1, 0x1d);
	agnx_write32(ctl, AGNX_GCR_GAINSET2, 0x1d);

	agnx_write32(ctl, AGNX_GCR_GAINSETWRITE, 0x1);

	agnx_write32(ctl, AGNX_ACI_MODE, 0x1);
	agnx_write32(ctl, AGNX_ACI_LEN, 0x3ff);


	agnx_write32(ctl, AGNX_ACI_TIMER1, 0x27);
	agnx_write32(ctl, AGNX_ACI_TIMER2, 0x27);
	spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1400);
	spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1500);
	/* Measure Calibration */
	agnx_write32(ctl, AGNX_ACI_MEASURE, 0x1);
	calibra_delay(priv);
	do_calibration(priv);
	agnx_write32(ctl, AGNX_GCR_RXOVERIDE, 0x0);

	agnx_write32(ctl, AGNX_ACI_TIMER1, 0x21);
	agnx_write32(ctl, AGNX_ACI_TIMER2, 0x27);

	agnx_write32(ctl, AGNX_ACI_LEN, 0xf);

	reg = agnx_read32(ctl, AGNX_GCR_GAINSET0);
	reg &= 0xf;
	agnx_write32(ctl, AGNX_GCR_GAINSET0, reg);
	reg = agnx_read32(ctl, AGNX_GCR_GAINSET1);
	reg &= 0xf;
	agnx_write32(ctl, AGNX_GCR_GAINSET1, reg);
	reg = agnx_read32(ctl, AGNX_GCR_GAINSET2);
	reg &= 0xf;
	agnx_write32(ctl, AGNX_GCR_GAINSET2, reg);


	agnx_write32(ctl, AGNX_GCR_GAINSETWRITE, 0x0);

	/* Write 0x3 Gain Control Discovery Mode */
	enable_receiver(priv);
}
Exemplo n.º 3
0
static int fmcomms2adv_handle_driver(const char *attrib, const char *value)
{
	if (MATCH_ATTRIB("calibrate")) {
		do_calibration(NULL, NULL);

		while (!auto_calibrate)
			gtk_main_iteration();
	} else {
		fprintf(stderr, "Unknown token in ini file; key:'%s' value:'%s'\n",
				attrib, value);
		return -EINVAL;
	}

	return 0;
}
Exemplo n.º 4
0
static bool calibrate_from_ini(const char *ini_fn)
{
	char *value = read_token_from_ini(ini_fn, THIS_DRIVER, "calibrate");
	if (value) {
		int i = 0;

		do_calibration(NULL, NULL);
		while (i <= 20) {
			if (auto_calibrate >= 0)
				i += auto_calibrate;
			else
				return false;

			gtk_main_iteration();
		}

		free(value);
	}

	return true;
}
Exemplo n.º 5
0
int main()
{
  uint8_t i = 0;

  do_calibration();

  rtc_init();
  timer0_init();

  uart_init( UART_BAUD_SELECT(38400,F_CPU) );
  uart_putc(OSCCAL);  
  uart_putc('\n'); 

  DDRC |= (1<<PC4) | (1<<PC5);  // both pins output

  sei(); // turn on interrupt handler

  while(1)
  {
    delay_ms(100);
    // while ((ASSR & (1<<OCR2BUB)) != 0) {} 
  }
}
Exemplo n.º 6
0
void antenna_calibrate(struct agnx_priv *priv)
{
	void __iomem *ctl = priv->ctl;
	u32 reg;
	AGNX_TRACE;

	agnx_write32(ctl, AGNX_GCR_NLISTANT, 0x3);
	agnx_write32(ctl, AGNX_GCR_NMEASANT, 0x3);
	agnx_write32(ctl, AGNX_GCR_NACTIANT, 0x3);
	agnx_write32(ctl, AGNX_GCR_NCAPTANT, 0x3);

	agnx_write32(ctl, AGNX_GCR_ANTCFG, 0x1f);
	agnx_write32(ctl, AGNX_GCR_BOACT, 0x24);
	agnx_write32(ctl, AGNX_GCR_BOINACT, 0x24);
	agnx_write32(ctl, AGNX_GCR_BODYNA, 0x20);
	agnx_write32(ctl, AGNX_GCR_THD0A, 0x64);
	agnx_write32(ctl, AGNX_GCR_THD0AL, 0x64);
	agnx_write32(ctl, AGNX_GCR_THD0B, 0x46);
	agnx_write32(ctl, AGNX_GCR_THD0BTFEST, 0x3c);
	agnx_write32(ctl, AGNX_GCR_SIGHTH, 0x64);
	agnx_write32(ctl, AGNX_GCR_SIGLTH, 0x30);

	spi_rc_write(ctl, RF_CHIP0, 0x20);
	/* Fixme */
	udelay(80);
	/*    1. Should read 0x0  */
	reg = agnx_read32(ctl, AGNX_SPI_RLSW);
	if (0x0 != reg)
		printk(KERN_WARNING PFX "Unmatched rf chips result\n");
	spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1000);

	agnx_write32(ctl, AGNX_GCR_RXOVERIDE, 0x0);

	spi_rc_write(ctl, RF_CHIP0, 0x22);
	udelay(80);
	reg = agnx_read32(ctl, AGNX_SPI_RLSW);
	if (0x0 != reg)
		printk(KERN_WARNING PFX "Unmatched rf chips result\n");
	spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1005);

	agnx_write32(ctl, AGNX_GCR_RSTGCTL, 0x1);
	agnx_write32(ctl, AGNX_GCR_RSTGCTL, 0x0);

	reg = agnx_read32(ctl, AGNX_PM_SOFTRST);
	reg |= 0x1c000032;
	agnx_write32(ctl, AGNX_PM_SOFTRST, reg);
	reg = agnx_read32(ctl, AGNX_PM_PLLCTL);
	reg |= 0x0003f07;
	agnx_write32(ctl, AGNX_PM_PLLCTL, reg);

	reg = agnx_read32(ctl, 0xec50);
	reg |= 0x40;
	agnx_write32(ctl, 0xec50, reg);

	agnx_write32(ctl, AGNX_GCR_RXOVERIDE, 0xff8);
	agnx_write32(ctl, AGNX_GCR_DISCOVMOD, 0x3);

	agnx_write32(ctl, AGNX_GCR_CHAINNUM, 0x6);
	agnx_write32(ctl, 0x19874, 0x0);
	spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1700);

	/* Calibrate the BaseBandFilter */
	base_band_filter_calibrate(priv);

	spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1002);

	agnx_write32(ctl, AGNX_GCR_GAINSET0, 0x1d);
	agnx_write32(ctl, AGNX_GCR_GAINSET1, 0x1d);
	agnx_write32(ctl, AGNX_GCR_GAINSET2, 0x1d);
	agnx_write32(ctl, AGNX_GCR_GAINSETWRITE, 0x1);

	agnx_write32(ctl, AGNX_ACI_MODE, 0x1);
	agnx_write32(ctl, AGNX_ACI_LEN, 0x3ff);

	agnx_write32(ctl, AGNX_ACI_TIMER1, 0x27);
	agnx_write32(ctl, AGNX_ACI_TIMER2, 0x27);

	spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1400);
	spi_rf_write(ctl, RF_CHIP0|RF_CHIP1|RF_CHIP2, 0x1500);

	/* Measure Calibration */
	agnx_write32(ctl, AGNX_ACI_MEASURE, 0x1);
	calibra_delay(priv);

	/* do calibration */
	do_calibration(priv);

	agnx_write32(ctl, AGNX_GCR_RXOVERIDE, 0x0);
	agnx_write32(ctl, AGNX_ACI_TIMER1, 0x21);
	agnx_write32(ctl, AGNX_ACI_TIMER2, 0x27);
	agnx_write32(ctl, AGNX_ACI_LEN, 0xf);

	reg = agnx_read32(ctl, AGNX_GCR_GAINSET0);
	reg &= 0xf;
	agnx_write32(ctl, AGNX_GCR_GAINSET0, reg);
	reg = agnx_read32(ctl, AGNX_GCR_GAINSET1);
	reg &= 0xf;
	agnx_write32(ctl, AGNX_GCR_GAINSET1, reg);
	reg = agnx_read32(ctl, AGNX_GCR_GAINSET2);
	reg &= 0xf;
	agnx_write32(ctl, AGNX_GCR_GAINSET2, reg);

	agnx_write32(ctl, AGNX_GCR_GAINSETWRITE, 0x0);
	disable_receiver(priv);
} /* antenna_calibrate */
Exemplo n.º 7
0
int main()
{
  uint8_t i = 0;
  uint8_t n = 0;
  uint8_t pos;
  char strbuf[64];
  char timebuf[16];
  uint8_t seconds_last = seconds;
  uint8_t minutes_last = minutes;
  unsigned int ch;

  // FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
  // stdin = stdout = &uart_stream;

  // always calibrate the internal RC oscillator using external 32Khz crystal
  do_calibration();
  // OSCCAL = 55;

  rtc_init();
  key_init();
  extra_init();
  ht1632_setup(1); // use ram

#ifdef USE_UARTSYNC
  uart_init();
#else

  #ifdef USE_V0
  uart_init( UART_BAUD_SELECT(9600,F_CPU) );
  #else
  // uart_init( UART_BAUD_SELECT(38400,F_CPU) );
  uart_init( UART_BAUD_SELECT(9600,F_CPU) );
  #endif

#endif

  sei(); // turn on interrupt handler

  // strncpy(strbuf, "ready: ", 7);
  // sprintf(&strbuf[7], "%d", OSCCAL);
  // ht1632_scrollstr(strbuf, 10, 10);
  int start = 5;
  ht1632_putchar(start,1,'L'); 
  ht1632_putchar(start+6,1,'E'); 
  ht1632_putchar(start+12,1,'D'); 
  ht1632_putchar(start+18,1,'I'); 
  delay_ms(5000); 

  set_time(timebuf);
  disp_time(timebuf);

  // play tone to indicate we started
  play_tone(A5, 4); _delay_ms(5);
  play_tone(A5, 4); _delay_ms(10);

  while(1)
  {
    n = term_recvstr(BUF, BUFSIZE);

    if(n<0)
    {
      term_sendstr(PSTR("error occurred on uart\r\n"));
    }
    if(n>0)
    {
      MODE = term_check_mode(BUF,n);
      switch(MODE)
      {
        case MODE_TIMESET:
          mode_timeset(BUF,n);
          break;
        case MODE_DRAW:
          mode_draw();
          break;
        case MODE_INVALID:
        default:
          mode_msg(BUF,n);
          break;
      }
      // just to be paranoid
      stop_led_sync_timer();

      // hack to force time display
      minutes_last = minutes - 1;
    }

    if(last_button1state == 1)
    {
      demo_life(); 
      // if we come out of demo_life, we show time 
      set_time(timebuf);
      disp_time(timebuf);
    }

    if(seconds_last != seconds || last_buttonstate & BT_PRESS) 
    {
      seconds_last = seconds;

      if(minutes_last != minutes)
      {
        minutes_last = minutes;
        set_time(timebuf);
        disp_time(timebuf);
      }

      disp_bindots();
    }

    // fast cycle
    if(last_buttonstate & BT_HOLD)
    {
      while(!(PINC & (1<<BUTTON2)))
      {
        minutes++;
        update_datetime(1);
        set_time(timebuf);
        disp_time(timebuf);
        minutes_last = minutes;
        _delay_ms(20);
      }
      intcount = 0;
    }

    // while ((ASSR & (1<<OCR2BUB)) != 0) {} 
  }
}
Exemplo n.º 8
0
int main(int argc, char **argv)
{
	struct fb_fix_screeninfo finfo;
    struct stat s;
    int i;
    int do_calib = 1;
    char runme[PROPERTY_VALUE_MAX];
    char name[MAX_LEN] = "";
    char dev[MAX_LEN] = "";
    int found,ret;
	int fd_carstatus = 0;

    /* open log */
    log_fd = open(log, O_WRONLY | O_CREAT | O_TRUNC);

	fd_carstatus = open("/dev/carstatus", O_RDWR);
	if(fd_carstatus == -1){
	    log_write("Failed to open /dev/carstatus\n");
	} else {
        ret = ioctl(fd_carstatus, CARSTATUS_GET_TOUCHPANEL_TYPE, &touch_type);
        log_write("Calibration Touch Panel Type : 0x%x\n", touch_type);        
		if(ret >= 0) {
            if(touch_type == TOUCH_PANEL_TYPE_CAPACITIVE_GOODIX) {
                log_write("No need to do calibration for goodix capacitive\n");
				close(fd_carstatus);
				return 0;
			}
		}
		
		close(fd_carstatus);
	}
    property_get("ro.calibration", runme, "");
    if (runme[0] != '1')
	    return 0;
    
	if (check_conf()){	// if we have the calibration file, skip any following step to save time
		goto err_log;
    }
	umask(0);
	mkdir("/data/system/calibrator",0777);

    /* read framebuffer for resolution */
    fb_fd = open(fb_dev, O_RDWR);
    if (fb_fd <= 0) {
	    log_write("Failed to open %s\n", fb_dev);
	    goto err_log;
    }
    if (-1 == ioctl(fb_fd, FBIOGET_VSCREENINFO, &info)) {
	    log_write("Failed to get screen info\n");
	    goto err_fb;
    }
    log_write("Screen resolution: %dx%d\n", info.xres, info.yres);
    /* map buffer */
    if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
	    log_write("Failed to get screen info: %d\n", errno);
        goto err_fb;
    }
    scrbuf = (__u16*) mmap(0, finfo.smem_len,
			    PROT_READ | PROT_WRITE,
			    MAP_SHARED,
			    fb_fd, 0);
    if (scrbuf== MAP_FAILED) {
	    log_write("Failed to map screen\n");
	    goto err_fb;
    }
    
    /* Clear screen */
    memset(scrbuf, 0xFF, finfo.smem_len);

    /* Find touchscreen device */
    found = find_ts_device(name, dev);
    if (!found) {
        log_write("can not find ts device\n");
        goto err_map;
    }
    
	log_write("dev:%s\n", dev);
    ts_fd = open(dev, O_RDWR);
    if (ts_fd < 0) {
        log_write("Failed to open %s\n", dev);
        goto err_map;
    }
    if(touch_type == TOUCH_PANEL_TYPE_RESISTIVE_MULTIPOINT_ULTRACHIP) {
		do{
			memset(scrbuf, 0xFF, finfo.smem_len);
		}while(ret = do_calibration_uc6811());
	} else {
	    /* Special calibration function for the DA905x PMIC */
	    if (strcmp(name, DA9052_DEV_NAME) == 0) {
	        log_write("do_calibration_da9052\n");
	        do_calibration_da9052(do_calib);
	    } else {
	        log_write("do_calibration\n");
	        if (do_calib) {
				do{
	    			memset(scrbuf, 0xFF, finfo.smem_len);
				}while(ret = do_calibration());
	        }
	    }
	}

    log_write("Calibration done!!\n");
    /* Clear screen */
    memset(scrbuf, 0, finfo.smem_len);
    //test_calibration();

    close(ts_fd);
err_map:
    munmap(scrbuf, finfo.smem_len);
err_fb:
    close(fb_fd);
err_log:
    close(log_fd);

    return 0;
}
Exemplo n.º 9
0
  void key_received() {
    control->pan_valid = false;      
    control->tilt_valid = false;
    control->lens_zoom_valid = false;
    control->lens_focus_valid = false;
    control->lens_iris_valid = false;

    //    std::cout << "Got keypress: " << key->data << std::endl;

    float tmp_focus;
    if (key->state == SDL_PRESSED) {
      switch (key->sym) {
      case SDLK_UP:
	control->tilt_val = 1;
	control->tilt_rel = true;
	control->tilt_valid = true;
	break;
      case SDLK_DOWN:
	control->tilt_val = -1;
	control->tilt_rel = true;
	control->tilt_valid = true;
	break;
      case SDLK_LEFT:
	control->pan_val = -1;
	control->pan_rel = true;
	control->pan_valid = true;
	break;
      case SDLK_RIGHT:
	control->pan_val = 1;
	control->pan_rel = true;
	control->pan_valid = true;
	break;
      case 61:
	control->lens_zoom_val = 100;
	control->lens_zoom_rel = true;
	control->lens_zoom_valid = true;
	break;
      case 45:
	control->lens_zoom_val = -100;
	control->lens_zoom_rel = true;
	control->lens_zoom_valid = true;
	break;
      case SDLK_RIGHTBRACKET:
	control->lens_focus_val = 100;
	control->lens_focus_rel = true;
	control->lens_focus_valid = true;
	break;
      case SDLK_LEFTBRACKET:
	control->lens_focus_val = -100;
	control->lens_focus_rel = true;
	control->lens_focus_valid = true;
	break;
      case SDLK_SPACE:
	control->pan_val = 0;
	control->pan_rel = false;
	control->pan_valid = true;

	control->tilt_val = 0;
	control->tilt_rel = false;
	control->tilt_valid = true;

	control->lens_zoom_val = 5000;
	control->lens_zoom_rel = false;
	control->lens_zoom_valid = true;
	break;
      case SDLK_c:
	centering = !centering;
	break;
      case SDLK_d:
	undistort = !undistort;
	break;
      case SDLK_f:
	observe->lock_atom();
	tmp_focus = observe->lens_focus_val;
	observe->unlock_atom();

	if (tmp_focus > 0) {
	  control->lens_focus_val = -1;
	  control->lens_focus_rel = false;
	  control->lens_focus_valid = true;
	} else {
	  control->lens_focus_val = 0;
	  control->lens_focus_rel = true;
	  control->lens_focus_valid = true;
	}
	break;
      case SDLK_RETURN:
	take_pic = true;
	break;
      case SDLK_a:
	do_calibration();
      }

      control->publish();
      return;
    }
  }