aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h')
-rw-r--r--drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h73
1 files changed, 50 insertions, 23 deletions
diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h
index fa43f4ac..490b8dca 100644
--- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h
+++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h
@@ -30,7 +30,7 @@
#ifndef _GINPUT_LLD_MOUSE_BOARD_H
#define _GINPUT_LLD_MOUSE_BOARD_H
-static const I2CConfig i2ccfg2 = {
+static const I2CConfig i2ccfg = {
OPMODE_I2C,
400000,
FAST_DUTY_CYCLE_2,
@@ -41,12 +41,12 @@ static const I2CConfig i2ccfg2 = {
*
* @notapi
*/
-static inline void init_board(void) {
- palSetPadMode(GPIOC, 13, PAL_MODE_INPUT); /* TP IRQ */
- palSetPadMode(GPIOB, 10, PAL_MODE_ALTERNATE(4)); /* I2C2 SCL */
- palSetPadMode(GPIOB, 11, PAL_MODE_ALTERNATE(4)); /* I2C2 SDA */
+static void init_board(void) {
+ palSetPadMode(GPIOC, 13, PAL_MODE_INPUT | PAL_STM32_PUDR_FLOATING); /* TP IRQ */
+ palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SCL */
+ palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SDA */
- i2cStart(&I2CD2, &i2ccfg2);
+ i2cStart(&I2CD1, &i2ccfg);
}
/**
@@ -60,34 +60,61 @@ static inline bool_t getpin_pressed(void) {
}
/**
- * @brief Aquire the bus ready for readings
+ * @brief Write a value into a certain register
*
- * @notapi
- */
-static inline void aquire_bus(void) {
- i2cAcquireBus(&I2CD2);
-}
-
-/**
- * @brief Release the bus after readings
+ * @param[in] reg The register address
+ * @param[in] n The amount of bytes (one or two)
+ * @param[in] val The value
*
* @notapi
*/
-static inline void release_bus(void) {
- i2cReleaseBus(&I2CD2);
-}
+static void write_reg(uint8_t reg, uint8_t n, uint16_t val) {
+ uint8_t txbuf[1];
+
+ i2cAcquireBus(&I2CD1);
+
+ txbuf[0] = reg;
+ i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 1, NULL, 0, MS2ST(STMPE811_TIMEOUT));
+ if(n == 1) {
+ txbuf[0] = val;
+ i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 1, NULL, 0, MS2ST(STMPE811_TIMEOUT));
+ } else if(n == 3) {
+ txbuf[0] = ((val & 0xFF00) >> 8);
+ txbuf[1] = (val & 0x00FF);
+ i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 2, NULL, 0, MS2ST(STMPE811_TIMEOUT));
+ }
+
+ i2cReleaseBus(&I2CD1);
+}
+
/**
- * @brief Read a value from touch controller
- * @return The value read from the controller
+ * @brief Read the value of a certain register
*
- * params[in] port The controller port to read.
+ * @param[in] reg The register address
+ * @param[in] n The amount of bytes (one or two)
*
* @notapi
*/
-static inline uint16_t read_value(uint16_t port) {
- #error "STMPE811: Implement this driver first!"
+static uint16_t read_reg(uint8_t reg, uint8_t n) {
+ uint8_t txbuf[1], rxbuf[2];
+ uint16_t ret;
+
+ i2cAcquireBus(&I2CD1);
+
+ txbuf[0] = reg;
+ i2cMasterTransmitTimeout(&I2CD1, 0x82 >> 1, txbuf, 1, rxbuf, 2, MS2ST(STMPE811_TIMEOUT));
+
+ i2cReleaseBus(&I2CD1);
+
+ if(n == 1)
+ ret = rxbuf[0];
+ else if (n == 2)
+ ret = ((rxbuf[0] << 8) | (rxbuf[1] & 0xFF));
+
+ return ret;
}
#endif /* _GINPUT_LLD_MOUSE_BOARD_H */
/** @} */
+