Ejemplo n.º 1
0
static int hs_1wire_init(void)
{
	char all_zero = 0;
	char send_data = 0xF5;

	HS_LOG("[1-wire]hs_1wire_init");
	fp = openFile(hi->pdata.onewire_tty_dev,O_CREAT|O_RDWR|O_NONBLOCK,0666);
	HS_LOG("Open %s", hi->pdata.onewire_tty_dev);
	if (!fp->private_data) {
		HS_LOG("No private data");
		if (hi->pdata.tx_level_shift_en)
			gpio_set_value_cansleep(hi->pdata.tx_level_shift_en, 1);
		if (hi->pdata.uart_sw)
			gpio_set_value_cansleep(hi->pdata.uart_sw, 0);
		hi->aid = 0;
		closeFile(fp);
		return -1;
	}
	setup_hs_tty(fp);
	HS_LOG("Setup HS tty");
	if (hi->pdata.tx_level_shift_en) {
		gpio_set_value_cansleep(hi->pdata.tx_level_shift_en, 0); /*Level shift low enable*/
		HS_LOG("[HS]set tx_level_shift_en to 0");
	}
	if (hi->pdata.uart_sw) {
		gpio_set_value_cansleep(hi->pdata.uart_sw, 1); /* 1: UART I/O to Audio Jack, 0: UART I/O to others */
		HS_LOG("[HS]Set uart sw = 1");
	}
	hi->aid = 0;
	hr_msleep(20);
	writeFile(fp,&all_zero,1);
	hr_msleep(5);
	writeFile(fp,&send_data,1);
//	if (hi->pdata.remote_press) {
//		while(gpio_get_value(hi->pdata.remote_press) == 1) {
//			HS_LOG("[HS]Polling remote_press low");
//		}
//	}
	HS_LOG("Send 0x00 0x35");
	usleep(300);
	if (hi->pdata.tx_level_shift_en)
		gpio_set_value_cansleep(hi->pdata.tx_level_shift_en, 1);
	HS_LOG("[HS]Disable level shift");
	hr_msleep(22);
	if (hs_read_aid() == 0) {
		HS_LOG("[1-wire]Valid AID received, enter 1-wire mode");
		if (hi->pdata.tx_level_shift_en)
			gpio_set_value_cansleep(hi->pdata.tx_level_shift_en, 1);
		closeFile(fp);
		return 0;
	} else {
		if (hi->pdata.tx_level_shift_en)
			gpio_set_value_cansleep(hi->pdata.tx_level_shift_en, 1);
		if (hi->pdata.uart_sw)
			gpio_set_value_cansleep(hi->pdata.uart_sw, 0);
		hi->aid = 0;
		closeFile(fp);
		return -1;
	}
}
static int hs_1wire_init(void)
{
    char all_zero = 0;
    char send_data = 0xF5;

    HS_LOG("[1-wire]hs_1wire_init");
    fp = openFile(hi->pdata.onewire_tty_dev,O_RDWR|O_SYNC|O_NONBLOCK,0660);
    HS_LOG("Open %s", hi->pdata.onewire_tty_dev);
    if (fp != NULL) {
        if (!fp->private_data) {
            HS_LOG("No private data");
            if (hi->pdata.tx_level_shift_en)
                gpio_set_value_cansleep(hi->pdata.tx_level_shift_en, 1);
            if (hi->pdata.uart_sw)
                gpio_set_value_cansleep(hi->pdata.uart_sw, 0);
            hi->aid = 0;
            closeFile(fp);
            return -1;
        }
    } else {
        HS_LOG("%s, openFile is NULL pointer\n", __func__);
        return -1;
    }
    setup_hs_tty(fp);
    HS_LOG("Setup HS tty");
    if (hi->pdata.tx_level_shift_en) {
        gpio_set_value_cansleep(hi->pdata.tx_level_shift_en, 0);
        HS_LOG("[HS]set tx_level_shift_en to 0");
    }
    if (hi->pdata.uart_sw) {
        gpio_set_value_cansleep(hi->pdata.uart_sw, 1);
        HS_LOG("[HS]Set uart sw = 1");
    }
    hi->aid = 0;
    hr_msleep(20);
    writeFile(fp,&all_zero,1);
    hr_msleep(5);
    writeFile(fp,&send_data,1);
    HS_LOG("Send 0x00 0xF5");
    usleep(300);
    if (hi->pdata.tx_level_shift_en)
        gpio_set_value_cansleep(hi->pdata.tx_level_shift_en, 1);
    HS_LOG("[HS]Disable level shift");
    hr_msleep(22);
    if (hs_read_aid() == 0) {
        HS_LOG("[1-wire]Valid AID received, enter 1-wire mode");
        if (hi->pdata.tx_level_shift_en)
            gpio_set_value_cansleep(hi->pdata.tx_level_shift_en, 1);
        closeFile(fp);
        return 0;
    } else {
        if (hi->pdata.tx_level_shift_en)
            gpio_set_value_cansleep(hi->pdata.tx_level_shift_en, 1);
        if (hi->pdata.uart_sw)
            gpio_set_value_cansleep(hi->pdata.uart_sw, 0);
        hi->aid = 0;
        closeFile(fp);
        return -1;
    }
}
Ejemplo n.º 3
0
static int hs_1wire_init(void)
{
	char all_zero = 0;
	char send_data = 0x35;

	HS_LOG("[1-wire]hs_1wire_init");
	fp = openFile(hi->pdata.onewire_tty_dev,O_CREAT|O_RDWR|O_SYNC,0666);
	HS_LOG("Open %s", hi->pdata.onewire_tty_dev);
	if (!(fp->private_data)) {
		HS_LOG("No private data");
		return -1;
	}
	setup_hs_tty(fp);
	HS_LOG("Setup HS tty");
	if (hi->pdata.tx_level_shift_en) {
		gpio_set_value_cansleep(hi->pdata.tx_level_shift_en, 0); 
		HS_LOG("[HS]set tx_level_shift_en to 0");
	}
	if (hi->pdata.uart_sw)
		gpio_set_value_cansleep(hi->pdata.uart_sw, 1); 
	hi->aid = 0;
	hr_msleep(20);
	writeFile(fp,&all_zero,1);
	hr_msleep(5);
	writeFile(fp,&send_data,1);
	if (hi->pdata.remote_press) {
		while(gpio_get_value(hi->pdata.remote_press) == 1) {
			HS_LOG("[HS]Polling remote_press low");
		}
	}
	hr_msleep(1);
	if (hi->pdata.tx_level_shift_en)
		gpio_set_value(hi->pdata.tx_level_shift_en, 1);
	HS_LOG("[HS]Disable level shift");
	hr_msleep(22);
	if (hs_read_aid() == 0) {
		HS_LOG("[1-wire]Valid AID received, enter 1-wire mode");
		return 0;
	} else {
		if (hi->pdata.tx_level_shift_en)
			gpio_set_value_cansleep(hi->pdata.tx_level_shift_en, 1);
		if (hi->pdata.uart_sw)
			gpio_set_value_cansleep(hi->pdata.uart_sw, 0);
		hi->aid = 0;
		closeFile(fp);
		return -1;
	}
}