展讯平台如何使用adc来兼容多LCD

兼容LCD有两种方式,一般使用读ID的方式来兼容,但是不能兼容IC一样的LCD,另外一种是使用ADC来兼容,可以用来兼容IC一样的LCD。
如何使用ADC来兼容IC一样的LCD了?
1、 硬件上需要有ADC引脚,连上芯片端ADC脚。
2、 IC相同,模组厂不同的LCD,主要差别主要是在初始化代码上(各模组厂使用的材质不一样导致),故可以在一个LCD驱动代码中实现使用不同的初始化代码。
具体如下:
目前做法是在先通过读ID来区别IC不同的LCD,再在LCD驱动中初始化代码中使用adc来判断。
1、 向硬件咨询屏ADC引脚电平多少。总会有一个高一个地电平、

2、 在代码uboot和kernel中添加判断条件走不同的初始化代码。


代码如下:
Uboot中:
#if 1
int adc_value[2];


ADC_Init();


for(i=0;i<2;i++){
adc_value[i] = ADC_GetValue(3, false);
printf("ADC read = %d\n", adc_value[i]);
if(adc_value < 0){
printf("ADC read error\n");
udelay(10);
}
}

printk("uboot lcd_init   adc_value[0]=%d,adc_value[1]=%d\n",adc_value[0],adc_value[1]);

if(adc_value[0]<1200 || adc_value[1]<1200){
init = init_data_tongxingda;
array_size = ARRAY_SIZE(init_data_tongxingda);
} else {
init = init_data;
array_size = ARRAY_SIZE(init_data);
}


#endif 

Kernel中:


#if 1
struct adc_sample_data adc_data = {
.channel_id = ADC_CHANNEL_3,
.channel_type = 0,
.hw_channel_delay = 0,
.scale = true,
.pbuf = &val[0],
.sample_num = 3,
.sample_bits = 1,
.sample_speed = 0,
.signal_mode = 0,
};


ret = sci_adc_get_values(&adc_data);
if (0 != ret)
printk("get adc value error!!");


for(i=0;i<3;i++)
printk(" ADC kernel _mipi_init value=%d\n", val[i]);


if((val[0]<1200 ) || (val[1]<1200 )){
init = init_data_tongxingda;
array_size = ARRAY_SIZE(init_data_tongxingda);
} else {
init = init_data;
array_size = ARRAY_SIZE(init_data);
}
#endif



MARVELL平台ADC

int get_gpadc_value(unsigned int gpadc_id)
{
u32 val = 0;


/*
* gp_id_en: GPADC enable bit in gpadc page 0x02 register;
* gp_bias:  the register of GPADC_ID bias current in gpade page;
* bias_curr: value of GPADC_ID bias current we need to set, by default, we set 6uA here;
* bias_curr_en: enable bit of GPADC bias current in pgade page 0x14 register;
* gp_meas_reg1/reg2: GPADC measure register;
*/
u32 gp_id_en, gp_bias, bias_curr, bias_curr_en, gp_meas_reg1, gp_meas_reg2;
i2c_set_bus_num(2);
int pmic_gpadc_page = 0x32;
u8 data, buf0, buf1;



switch(gpadc_id){
      case 0:
gp_id_en = (0x1 << 1 ) | (0x1 << 2);
gp_bias = 0x0b;
bias_curr = 0xf1;
bias_curr_en = (0x1 << 0) | (0x1 << 4);
gp_meas_reg1 = 0x54;
gp_meas_reg2 = 0x55;
break;
case 1:
gp_id_en = (0x1 << 1) | (0x1 << 3);
gp_bias = 0x0c;
bias_curr = 0xf1;
bias_curr_en = (0x1 << 1) | (0x1 << 5);
gp_meas_reg1 = 0x56;
gp_meas_reg2 = 0x57;
break;
case 2:
gp_id_en = (0x1 << 1) | (0x1 << 4);
gp_bias = 0x0d;
bias_curr = 0xf1;
bias_curr_en = (0x1 << 2) | (0x1 << 6);
gp_meas_reg1 = 0x58;
gp_meas_reg2 = 0x59;
break;
case 3:
gp_id_en = (0x1 << 1) | (0x1 << 5);
gp_bias = 0x0e;
bias_curr = 0xf1;
bias_curr_en = (0x1 << 3) | (0x1 << 7);
gp_meas_reg1 = 0xa6;
gp_meas_reg2 = 0xa7;
break;
default:
printf("=======please set the currect gpadc no.\n");
}
/* enable GPADC */

   i2c_read(pmic_gpadc_page, 0x01, 1, &data, 1);
    data |= 0x12;
    i2c_write(pmic_gpadc_page, 0x01, 1, &data, 1);
    
i2c_read(pmic_gpadc_page, 0x02, 1, &data, 1);
data |= gp_id_en;
i2c_write(pmic_gpadc_page, 0x02, 1, &data, 1);


i2c_read(pmic_gpadc_page, 0x06, 1, &data, 1);
data |= 0x03;
i2c_write(pmic_gpadc_page, 0x06, 1, &data, 1);


i2c_read(pmic_gpadc_page, gp_bias, 1, &data, 1);
data &= 0xf0;
data |= bias_curr;
i2c_write(pmic_gpadc_page, gp_bias, 1, &data, 1);


/* enable GPADC bias current */
i2c_read(pmic_gpadc_page, 0x14, 1, &data, 1);
data |= bias_curr_en;
i2c_write(pmic_gpadc_page, 0x14, 1, &data, 1);


i2c_read(pmic_gpadc_page, gp_meas_reg1, 1, &buf0, 1);
i2c_read(pmic_gpadc_page, gp_meas_reg2, 1, &buf1, 1);
val = (buf0 << 4) | (buf1 & 0xf);
val = ((val & 0xfff) * 7 * 100) >> 11;
printf("=======GPADC %d voltage value = %d\n",gpadc_id, val);
return val;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值