Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: sensor: Fix CXD5605 Reinit #181

Open
wants to merge 1 commit into
base: tmo-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 16 additions & 34 deletions drivers/sensor/cxd5605/cxd5605.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ static int init(const struct device *dev)

result = gpio_pin_configure_dt(&cfg->rst_gpio, GPIO_OUTPUT_HIGH);

cxd5605_setup_interrupts(dev);
/* setup shim callbacks */
cxd5605_lib_init(dev);
cxd5605_register_resp_callback(dev, driver_cxd5605_resp_cb);
cxd5605_register_nmea_callback(dev, driver_cxd5605_nmea_cb);

return result;
}

Expand Down Expand Up @@ -429,11 +435,6 @@ static int cxd5605_attr_set(const struct device *dev,
uint8_t min = 0;
uint8_t sec = 0;


const struct cxd5605_config *config = dev->config;
const struct gpio_dt_spec *pwr_gpio = &config->pwr_gpio;
const struct gpio_dt_spec *rst_gpio = &config->rst_gpio;

if (chan != SENSOR_CHAN_AMBIENT_TEMP && chan != SENSOR_CHAN_ALL) {
return -ENOTSUP;
}
Expand All @@ -459,6 +460,9 @@ static int cxd5605_attr_set(const struct device *dev,
__FILE__, __LINE__, result);
return result;
}
drv_data->op_mode = val[0].val1;
drv_data->pos_cycle = val[0].val2;
drv_data->sleep_time = val[1].val1;
break;

case SENSOR_ATTR_CXD5605_PULSE:
Expand Down Expand Up @@ -508,6 +512,7 @@ static int cxd5605_attr_set(const struct device *dev,
__FILE__, __LINE__, result);
return result;
}
drv_data->selected_sentences = val->val1;
break;

case SENSOR_ATTR_CXD5605_HOT_START:
Expand Down Expand Up @@ -580,39 +585,10 @@ static int cxd5605_attr_set(const struct device *dev,
}
break;

case SENSOR_ATTR_CXD5605_PWR_CTRL:
if (val->val1 == 0) {
result = gpio_pin_configure_dt(pwr_gpio, GPIO_OUTPUT_LOW);
result = gpio_pin_configure_dt(rst_gpio, GPIO_OUTPUT_LOW);
} else {
result = gpio_pin_configure_dt(pwr_gpio, GPIO_OUTPUT_HIGH);
result = gpio_pin_configure_dt(rst_gpio, GPIO_OUTPUT_HIGH);
}
break;

case SENSOR_ATTR_CXD5605_CALLBACK:
init(dev);
LOG_DBG("Got CXD5605_ALERT_INTERRUPTS\n");
cxd5605_setup_interrupts(dev);
/* setup shim callbacks */
#ifdef DEBUG
printf("[driver] register driver callback\n");
#endif
cxd5605_lib_init(dev);
cxd5605_register_resp_callback(dev, driver_cxd5605_resp_cb);
cxd5605_register_nmea_callback(dev, driver_cxd5605_nmea_cb);
return 0;

default:
return -ENOTSUP;
}

if (drv_data->cxd5605_cmd != SENSOR_ATTR_CXD5605_PWR_CTRL) {
result = cxd5605_wait_fetch(dev);
if (result < 0) {
return result;
}
}

return 0;
}
Expand Down Expand Up @@ -684,6 +660,7 @@ static int cxd5605_driver_pm_action(const struct device *dev,
{
const struct cxd5605_config *config = dev->config;
const struct gpio_dt_spec *rst_gpio = &config->rst_gpio;
struct cxd5605_data *drv_data = dev->data;

int result = 0;

Expand All @@ -699,6 +676,11 @@ static int cxd5605_driver_pm_action(const struct device *dev,
if (result < 0) {
printk("ERROR: I2C interface not working (CXD5605 driver)\n");
}
if (drv_data->pps_cb) {
cxd5605_pulse(dev, 1);
}
cxd5605_operating_mode(dev, drv_data->op_mode, drv_data->pos_cycle, drv_data->sleep_time);
cxd5605_sentence_select(dev, drv_data->selected_sentences);

case PM_DEVICE_ACTION_SUSPEND:
cxd5605_sleep(dev, 0);
Expand Down
6 changes: 5 additions & 1 deletion include/zephyr/drivers/sensor/cxd5605.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ enum sensor_attribute_cxd5605 {
SENSOR_ATTR_CXD5605_SLEEP,
SENSOR_ATTR_CXD5605_VERSION,
SENSOR_ATTR_CXD5605_ASSIST_GEN_FUNCTION_CONTROL,
SENSOR_ATTR_CXD5605_PWR_CTRL,
};

enum gga_nmea_fieldpos_t {
Expand Down Expand Up @@ -167,6 +166,11 @@ struct cxd5605_data {
bool got_data;
bool lib_got_data;
int command;

uint32_t op_mode;
uint32_t pos_cycle;
uint32_t sleep_time;
uint32_t selected_sentences;
};

/** a mask for the under temp alert bit in the status word*/
Expand Down