예제 #1
0
static unsigned int get_hw_revision(void)
{
	int hwrev, mode0, mode1;

	adc_power_control(1);

	mode0 = get_adc_value(1);		/* HWREV_MODE0 */
	mode1 = get_adc_value(2);		/* HWREV_MODE1 */

	/*
	 * XXX Always set the default hwrev as the latest board
	 * ADC = (voltage) / 3.3 * 4096
	 */
	hwrev = 3;

#define IS_RANGE(x, min, max)	((x) > (min) && (x) < (max))
	if (IS_RANGE(mode0, 80, 200) && IS_RANGE(mode1, 80, 200))
		hwrev = 0x0;		/* 0.01V	0.01V */
	if (IS_RANGE(mode0, 750, 1000) && IS_RANGE(mode1, 80, 200))
		hwrev = 0x1;		/* 610mV	0.01V */
	if (IS_RANGE(mode0, 1300, 1700) && IS_RANGE(mode1, 80, 200))
		hwrev = 0x2;		/* 1.16V	0.01V */
	if (IS_RANGE(mode0, 2000, 2400) && IS_RANGE(mode1, 80, 200))
		hwrev = 0x3;		/* 1.79V	0.01V */
#undef IS_RANGE

	debug("mode0: %d, mode1: %d, hwrev 0x%x\n", mode0, mode1, hwrev);

	adc_power_control(0);

	return hwrev;
}
예제 #2
0
static void report_lsensor_input_event(struct al3006_info *lpi)
{

	uint8_t adc_value = 0;
	int level = 0, i, ret = 0;

	mutex_lock(&als_get_adc_mutex);

	ret = get_adc_value(&adc_value);

	if (ret == 0) {
        i = adc_value & 0x3f;
        level = i;//lux_table[i];
    }
    else
    {
        printk(KERN_ERR"lsensor read adc fail!\n");
        goto fail_out;
    }

	D("[AL3006] %s: ADC=0x%03X, Level=%d\n",__func__,i, level);

	input_report_abs(lpi->ls_input_dev, ABS_MISC, level);
	input_sync(lpi->ls_input_dev);
//	enable_als_int();

fail_out:
	mutex_unlock(&als_get_adc_mutex);

}
예제 #3
0
int sysButton3()
{
#ifdef VSIMU
	return get_button3();
#endif
#ifdef VREAL
	return 255-get_adc_value();
#endif
}
//Delay using ADC value subfunction
void delay_using_adc(unsigned char scale)
{
	if(scale>=0 && scale<=50)
	{
		unsigned int adc_delay = 0;
		adc_delay = get_adc_value();	//Obtain ADC value 
		delay(adc_delay*scale);			//Times it with a scale ranges from (0-50)
	}
}
예제 #5
0
static ssize_t ps_adc_show(struct device *dev,
            struct device_attribute *attr, char *buf)
{

    uint8_t value;
    int ret;
    struct al3006_info *lpi = lp_info;
    int value1;

    ret = get_adc_value(&value);

    ret = sprintf(buf, "ADC[0x%03X]\n ps[%d]\n als[%d]\n irq[%d]\n", \
              value, lpi->ps_enable,lpi->als_enable,lpi->ps_irq_flag);

    return ret;
}
static void report_psensor_input_event(struct ltr558_info *lpi)
{
	   uint8_t ps_data;
	   int val, ret = 0;

	   ret = get_adc_value(&ps_data);/*check i2c result*/
	   if (ret == 0) {
		     val = (ps_data & 0x80) ? 0 : 1;
		     D("[ltr558] proximity %s, ps_data=%d\n", val ? "FAR" : "NEAR", ps_data);
	   } else {/*i2c err, report far to workaround*/
		     val = 1;
		     ps_data = 0;
		     D("[ltr558] proximity i2c err, report %s, ps_data=%d, record_init_fail %d\n",
			                                             val ? "FAR" : "NEAR", ps_data, record_init_fail);
	   }
		 /* 0 is close, 1 is far */
	  input_report_abs(lpi->ps_input_dev, ABS_DISTANCE, val);
	  input_sync(lpi->ps_input_dev);

    wake_lock_timeout(&(lpi->ps_wake_lock), 2*HZ);
}
예제 #7
0
static void update_inputs(void)
{
	uint8_t i;

	io_lock();

	for (i = 0; i < 16; ++i)
	{
		adc_values.value[i] = get_adc_value(i);
	}

	for (i = 0; i < IOSLOTS_COUNT; ++i)
	{
		ioslot_values.value[i] = get_ioslot_value(i);
	}

	io_unlock();

	common_values.now = datetime_now();
	common_values.uptime = millis();
	common_values.modbus_address = config_get_address();

	controls.pause_flag = config_get_pause_flag();
}
예제 #8
0
/** 
 * The application task reading ADC values and using the LEDs.
 */
static void vAppTask( int8_t *pvParameters )
{
	uint8_t buttons = 0;
	uint16_t U1_value = 0;
	uint16_t U2_value = 0;
	uint8_t count = 0;
	
	pvParameters;
	
	led1_count = 50;
	led2_count = 100;
	
	vTaskDelay( 50 / portTICK_RATE_MS );
	
	vTaskDelay( 100 / portTICK_RATE_MS );

	debug("NanoSensor N710 Example Application.\r\n");

	/* Start an endless task loop, we must sleep most of the time allowing execution of other tasks. */
	for (;;)
	{
		/* Sleep for 500 ms or until button event */
		if (xQueueReceive(button_events, &buttons, 500 / portTICK_RATE_MS) == pdTRUE)
		{
			switch(buttons)
			{
				case 0x81:
				case 0x01:
					/* Read the LM60 illumination sensor (U1) */
					/* P0.2 */

					debug("Reading illumination (U1). ");
					if (get_adc_value(N710_LIGHT, &U1_value) == 0)
					{
							ssi_sensor_update(0, (uint32_t) U1_value);
							debug_int(U1_value);
							led1_count = 30;
					}
					else
					{
						debug("failed.");
						led1_count = 300;
					}
					debug("\r\n");
					break;

				case 0x82:
				case 0x02:
					/* Read the EL7900 temperature sensor (U2) */
					/* P0.3 */

					debug("Reading temp (U2): ");
					if (get_adc_value(N710_TEMP, &U2_value) == 0)
					{
							int32_t calc_int = (int32_t) U2_value;
							
							calc_int /= 4;      /* drop insignificant bits */
        			//calc_int *= 58608;    /* 3*160.039*1000*1000/8192 (value with         6 decimals)*/
		     calc_int *= 24420;    /* 1.25*160.039*1000*1000/8192 (value with         6 decimals)*/
        			calc_int /= 10000;   /* adjust to 2 decimals */
        			calc_int -= 6785;
							
							U2_value = (int16_t) calc_int;
							
							debug_int(U2_value/100);
							debug_put('.');
							if ((U2_value%100) >= 10)
							{
								debug_integer(2, 10, (U2_value%100));
							}
							else
							{
								debug_hex(U2_value%100);
							}
							led1_count = 30;
							led2_count = 30;
							
							ssi_sensor_update(1, (int32_t) U2_value);
					}
					else
					{
						debug("failed.");
						led1_count = 300;
						led2_count = 300;
					}
					debug("\r\n");
					break;

				default:
					debug_hex(buttons);
					break;
			}
			count = 0;
		}
		else
		{
			if (count++ >= 2)
			{
				count = 0;
				buttons = 0x01;
				xQueueSend( button_events, ( void * ) &buttons,	(portTickType) 0 );
				buttons = 0x02;
				xQueueSend( button_events, ( void * ) &buttons,	(portTickType) 0 );
			}
		}
	}
}
예제 #9
0
void *infrad_ctrl(void *ptr)
{
	int ret;
	int fd_infrad = -1;
	int fd_adc = -1;

	int adc_value = -1;

	fd_infrad = open(INFRAD_DEV_NAME, O_RDWR);
	if(fd_infrad<0){
		printf("infrad_ctrl: open device %s failed.\n", INFRAD_DEV_NAME);	
		goto exit_infrad_ctrl;
	}

	fd_adc = open(KEY_DEV_NAME, O_RDONLY|O_NONBLOCK);
	if(fd_adc<0){
		printf("infrad_ctrl: open device %s failed.\n", KEY_DEV_NAME);
		goto exit_infrad_ctrl;
	}

	printf("infrad_ctrl control start....\n");
	set_to_Color(fd_infrad);//开始强制关闭

	while(1){
		switch(getInfradStatue()){
		case 1://强制开
			set_to_Color(fd_infrad);
			break;
		case 2://强制关
			set_to_White(fd_infrad);
			break;
		case 0://自动
		default:
			adc_value = get_adc_value(fd_adc);
			if(adc_value<0){
				break;
			}
	
			if(adc_value>getImgWtoC()){
				set_to_Color(fd_infrad);
			}else if(adc_value<getImgCtoW()){
				set_to_White(fd_infrad);
			}
			break;
		}
		
		if(0==get_reset_value(fd_infrad)){
			reset_stat++;
		}else{
			reset_stat = 0;
		}
		if(reset_stat>2){
			reset_sys();
			reset_stat = 0;
		}

		sleep(2);
	}

exit_infrad_ctrl:
	if(fd_infrad>0){
		close(fd_infrad);
		fd_infrad = -1;
	}
	if(fd_adc>0){
		close(fd_adc);
		fd_adc = -1;
	}

	return;
}
예제 #10
0
/*
 * Handle commands from user-space.
 */
static int at91_adc_ioctl(struct inode *inode, struct file *file,
		unsigned int cmd, unsigned long arg)
{
	void __user *argp = (void __user *)arg;
	struct at91_adc_value tmp_adc_value;
	int tmp = 0;

	switch (cmd) {
		case ADCGETVALUE:
			get_adc_value();

			tmp_adc_value.ch0_value = adc_value.ch0_value ;
			tmp_adc_value.ch1_value = adc_value.ch1_value ;
			tmp_adc_value.ch2_value = adc_value.ch2_value ;
			tmp_adc_value.ch3_value = adc_value.ch3_value ;

			if (copy_to_user(argp, &tmp_adc_value, sizeof(tmp_adc_value)))
			{
				return -EFAULT;
			}
			return 0;

		case ADCGETMODE:
			return (ioread32(adc_channel.membase + AT91_ADC_MR));

		case ADCSETMODE:
			if(copy_from_user(&tmp, (void *) arg, sizeof(int)))
			{
				return -EFAULT;
			}
			else
			{
				tmp &= 0xFFFFFFF;
				iowrite32(tmp, (adc_channel.membase + AT91_ADC_MR));
				return 0;
			}

		case ADCGETCHANNEL:

			return (ioread32(adc_channel.membase + AT91_ADC_CHSR));

		case ADCSETCHANNEL:
			if(copy_from_user(&tmp, (void *) arg, sizeof(int)))
			{
				return -EFAULT;
			}
			else
			{
				adc_value.ch0_value = 0;
				adc_value.ch1_value = 0;
				adc_value.ch2_value = 0;
				adc_value.ch3_value = 0;
				
				tmp &= 0xf;
				adc_channel.channel_num = tmp;
				iowrite32(tmp, (adc_channel.membase + AT91_ADC_CHER));

				tmp = ~tmp & 0xf;
				iowrite32(tmp, (adc_channel.membase + AT91_ADC_CHDR));
				return 0;
			}
	}
	return -ENOTTY;
}
예제 #11
0
static ssize_t lsr_show_value(struct device *dev,
				 struct device_attribute *attr, char *buf)
{
	return sprintf(buf, "lsr value:%d\nadc value:%d\n", get_lsr_value(),get_adc_value());	
}