fix interrupt handling
This commit is contained in:
parent
ab7673f268
commit
218c5b0572
4 changed files with 60 additions and 32 deletions
|
@ -52,7 +52,11 @@ static int pmw33xx_access(const struct device *dev, const uint8_t reg, uint8_t *
|
|||
},
|
||||
.count = 1,
|
||||
};
|
||||
uint8_t result[1] = {*value};
|
||||
|
||||
uint8_t result[1];
|
||||
if (value != NULL) {
|
||||
result[0] = *value;
|
||||
}
|
||||
struct spi_buf_set rx = {
|
||||
.buffers =
|
||||
&(struct spi_buf){
|
||||
|
@ -77,7 +81,7 @@ static int pmw33xx_access(const struct device *dev, const uint8_t reg, uint8_t *
|
|||
err = spi_read(data->bus, spi_cfg, &rx);
|
||||
pmw33xx_cs_select(cs_gpio_cfg, 1);
|
||||
k_sleep(K_USEC(160));
|
||||
if ((reg & PMW33XX_WR_MASK) == 0)
|
||||
if ((reg & PMW33XX_WR_MASK) == 0 && value != NULL)
|
||||
*value = result[0];
|
||||
return err;
|
||||
}
|
||||
|
@ -88,6 +92,7 @@ static int pmw33xx_write_reg(const struct device *dev, const uint8_t reg, const
|
|||
uint8_t v = value;
|
||||
return pmw33xx_access(dev, reg | PMW33XX_WR_MASK, &v);
|
||||
}
|
||||
|
||||
static int pmw33xx_write_srom(const struct device *dev) {
|
||||
struct pmw33xx_data *data = dev->data;
|
||||
const struct pmw33xx_config *cfg = dev->config;
|
||||
|
@ -166,9 +171,19 @@ static int pmw33xx_read_motion_burst(const struct device *dev, struct pmw33xx_mo
|
|||
}
|
||||
err = spi_read(data->bus, spi_cfg, &rx);
|
||||
pmw33xx_cs_select(cs_gpio_cfg, 1);
|
||||
#ifdef CONFIG_PMW33XX_TRIGGER
|
||||
pmw33xx_reset_motion(dev);
|
||||
#endif
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PMW33XX_TRIGGER
|
||||
void pmw33xx_reset_motion(const struct device *dev) {
|
||||
// reset motswk interrupt
|
||||
pmw33xx_read_reg(dev, PMW33XX_REG_MOTION, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
int pmw33xx_spi_init(const struct device *dev) {
|
||||
const struct pmw33xx_config *cfg = dev->config;
|
||||
const struct pmw33xx_gpio_dt_spec *cs_gpio_cfg = &cfg->bus_cfg.spi_cfg->cs_spec;
|
||||
|
@ -269,7 +284,8 @@ static int pmw33xx_init_chip(const struct device *dev) {
|
|||
LOG_ERR("pid does not match expected: got (%x), expected(%x)", pid, PMW33XX_PID);
|
||||
return -EIO;
|
||||
}
|
||||
pmw33xx_write_reg(dev, PMW33XX_REG_CONFIG2, 0x00); // clear rest enable
|
||||
pmw33xx_write_reg(dev, PMW33XX_REG_CONFIG2,
|
||||
config->disable_rest ? 0x00 : PMW33XX_RESTEN); // set rest enable
|
||||
|
||||
err = pmw33xx_write_srom(dev);
|
||||
if (err) {
|
||||
|
@ -361,9 +377,10 @@ static int pmw33xx_init(const struct device *dev) {
|
|||
{ \
|
||||
.bus_name = DT_INST_BUS_LABEL(n), .bus_init = pmw33xx_spi_init, \
|
||||
.bus_cfg = {.spi_cfg = PMW33XX_SPI_CFG(n)}, \
|
||||
.disable_rest = DT_INST_NODE_HAS_PROP(n, disable_rest), \
|
||||
COND_CODE_0(DT_INST_NODE_HAS_PROP(n, cpi), (0), (DT_INST_PROP(n, cpi))) \
|
||||
COND_CODE_1(CONFIG_PMW33XX_TRIGGER, \
|
||||
(PMW33XX_GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(n), motswk_gpios, 0)), ()) \
|
||||
(, PMW33XX_GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(n), motswk_gpios, 0)), ()) \
|
||||
}
|
||||
|
||||
#define PMW33XX_INST(n) \
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
/* power up reset cmd */
|
||||
#define PMW33XX_RESET_CMD 0x5A
|
||||
|
||||
/* cpi max and min values */
|
||||
#define PMW33XX_3389_CPI_MIN 50
|
||||
#define PMW33XX_3389_CPI_MAX 16000
|
||||
#define PMW33XX_3360_CPI_MIN 100
|
||||
|
@ -89,6 +90,7 @@ struct pmw33xx_config {
|
|||
char *bus_name;
|
||||
int (*bus_init)(const struct device *dev);
|
||||
const union pmw33xx_bus_cfg bus_cfg;
|
||||
bool disable_rest;
|
||||
int cpi;
|
||||
#if CONFIG_PMW33XX_TRIGGER
|
||||
struct pmw33xx_gpio_dt_spec motswk_spec;
|
||||
|
@ -98,7 +100,7 @@ struct pmw33xx_config {
|
|||
struct pmw33xx_data;
|
||||
|
||||
struct pmw33xx_transfer_function {
|
||||
int (*read_data)(const struct device *dev, uint16_t *value);
|
||||
int (*read_data)(const struct device *dev, int16_t *value);
|
||||
};
|
||||
|
||||
struct pmw33xx_data {
|
||||
|
@ -136,6 +138,8 @@ int pmw33xx_trigger_set(const struct device *dev, const struct sensor_trigger *t
|
|||
sensor_trigger_handler_t handler);
|
||||
|
||||
int pmw33xx_init_interrupt(const struct device *dev);
|
||||
|
||||
void pmw33xx_reset_motion(const struct device *dev);
|
||||
#endif
|
||||
|
||||
#endif /* ZEPHYR_DRIVERS_SENSOR_PIXART_PMW33XX_H_ */
|
||||
|
|
|
@ -23,6 +23,7 @@ static inline void setup_int(const struct device *dev, bool enable) {
|
|||
struct pmw33xx_data *data = dev->data;
|
||||
const struct pmw33xx_config *cfg = dev->config;
|
||||
|
||||
gpio_pin_configure(cfg->motswk_spec.port, cfg->motswk_spec.pin, cfg->motswk_spec.dt_flags);
|
||||
if (gpio_pin_interrupt_configure(cfg->motswk_spec.port, cfg->motswk_spec.pin,
|
||||
enable ? GPIO_INT_EDGE_TO_ACTIVE : GPIO_INT_DISABLE)) {
|
||||
LOG_WRN("Unable to set MOTSWK GPIO interrupt");
|
||||
|
@ -72,7 +73,7 @@ static void pmw33xx_thread(int dev_ptr, int unused) {
|
|||
static void pmw33xx_work_cb(struct k_work *work) {
|
||||
struct pmw33xx_data *drv_data = CONTAINER_OF(work, struct pmw33xx_data, work);
|
||||
|
||||
LOG_DBG("");
|
||||
LOG_DBG(" ");
|
||||
|
||||
pmw33xx_thread_cb(drv_data->dev);
|
||||
}
|
||||
|
@ -91,6 +92,8 @@ int pmw33xx_trigger_set(const struct device *dev, const struct sensor_trigger *t
|
|||
|
||||
setup_int(dev, true);
|
||||
|
||||
// reset motion on int setup
|
||||
pmw33xx_reset_motion(dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,3 +20,7 @@ properties:
|
|||
type: int
|
||||
description: mouse cpi
|
||||
required: false
|
||||
disable-rest:
|
||||
type: boolean
|
||||
description: disables mouse rest mode, will decrease battery life
|
||||
required: false
|
||||
|
|
Loading…
Add table
Reference in a new issue