stmpe811_state_t stmpe811_init(void) { stmpe811_i2c_init(); msleep(50); stmpe811_reset(); /* start of the documented initialization sequence */ stmpe811_disable_ts(); stmpe811_disable_gpio(); stmpe811_enable_fifo_of(); stmpe811_enable_fifo_th(); stmpe811_enable_fifo_touch_det(); stmpe811_set_adc_sample(0x40); /* set to 80 cycles */ stmpe811_set_adc_resolution(0x08); /* set adc resolution to 12 bit */ stmpe811_set_adc_freq(0x01); /* set adc clock speed to 3.25 MHz */ stmpe811_set_gpio_af(0x00); /* set GPIO AF to function as ts/adc */ /* * tsc cfg set to avg control = 4 samples * touch detection delay = 500 microseconds * panel driver settling time = 500 microcseconds */ stmpe811_set_tsc(0x9A); stmpe811_set_fifo_th(0x01); /* set fifo threshold */ stmpe811_reset_fifo(); /* reset fifo */ /* set fractional part to 7, whole part to 1 */ stmpe811_set_tsc_fraction_z(0x07); /* set current limit value to 50 mA */ stmpe811_set_tsc_i_drive(0x01); stmpe811_enable_tsc(); /* enable tsc (touchscreen clock) */ stmpe811_set_int_sta(0xFF); /* clear interrupt status */ stmpe811_enable_interrupts(); /* end of the documented initialization sequence */ msleep(2); return stmpe811_state_ok; }
STMPE811_HANDLE stmpe811_instantiate(FAR struct i2c_dev_s *dev, FAR struct stmpe811_config_s *config) #endif { FAR struct stmpe811_dev_s *priv; uint8_t regval; int ret; /* Allocate the device state structure */ #ifdef CONFIG_STMPE811_MULTIPLE priv = (FAR struct stmpe811_dev_s *)kmm_zalloc(sizeof(struct stmpe811_dev_s)); if (!priv) { return NULL; } /* And save the device structure in the list of STMPE811 so that we can find it later */ priv->flink = g_stmpe811list; g_stmpe811list = priv; #else /* Use the one-and-only STMPE811 driver instance */ priv = &g_stmpe811; #endif /* Initialize the device state structure */ sem_init(&priv->exclsem, 0, 1); priv->config = config; #ifdef CONFIG_STMPE811_SPI priv->spi = dev; #else priv->i2c = dev; /* Set the I2C address and frequency. REVISIT: This logic would be * insufficient if we share the I2C bus with any other devices that also * modify the address and frequency. */ I2C_SETADDRESS(dev, config->address, 7); I2C_SETFREQUENCY(dev, config->frequency); #endif /* Read and verify the STMPE811 chip ID */ ret = stmpe811_checkid(priv); if (ret < 0) { #ifdef CONFIG_STMPE811_MULTIPLE g_stmpe811list = priv->flink; kmm_free(priv); #endif return NULL; } /* Generate STMPE811 Software reset */ stmpe811_reset(priv); /* Configure the interrupt output pin to generate interrupts on high or low level. */ regval = stmpe811_getreg8(priv, STMPE811_INT_CTRL); #ifdef CONFIG_STMPE811_ACTIVELOW regval &= ~INT_CTRL_INT_POLARITY; /* Pin polarity: Active low / falling edge */ #else regval |= INT_CTRL_INT_POLARITY; /* Pin polarity: Active high / rising edge */ #endif #ifdef CONFIG_STMPE811_EDGE regval |= INT_CTRL_INT_TYPE; /* Edge interrupt */ #else regval &= ~INT_CTRL_INT_TYPE; /* Level interrupt */ #endif stmpe811_putreg8(priv, STMPE811_INT_CTRL, regval); /* Attach the STMPE811 interrupt handler. */ config->attach(config, stmpe811_interrupt); /* Clear any pending interrupts */ stmpe811_putreg8(priv, STMPE811_INT_STA, INT_ALL); config->clear(config); config->enable(config, true); /* Enable global interrupts */ regval = stmpe811_getreg8(priv, STMPE811_INT_CTRL); regval |= INT_CTRL_GLOBAL_INT; stmpe811_putreg8(priv, STMPE811_INT_CTRL, regval); /* Return our private data structure as an opaque handle */ return (STMPE811_HANDLE)priv; }