Skip to content

Commit 32e3756

Browse files
brooksprumoMaureenHelm
authored andcommitted
include: Fixes #1205, C++ usage of sensor.h
I ran into issue #1205 earlier today and realized the fix was to simply provide the proper casts. The issue is that C++ is less permissive than C here, erroring when trying to implicitly convert from `void *` to `struct gpio_driver_api *`. The same cast is done in include/drivers/gpio.h, which is why I did that here as well. This fix was validated by compiling my C++ application successfully and also successfully running my app on my board, interacting with sensors. Signed-off-by: Brooks Prumo <[email protected]>
1 parent 788d6eb commit 32e3756

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

include/drivers/sensor.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ static inline int z_impl_sensor_attr_set(struct device *dev,
345345
enum sensor_attribute attr,
346346
const struct sensor_value *val)
347347
{
348-
const struct sensor_driver_api *api = dev->driver_api;
348+
const struct sensor_driver_api *api =
349+
(const struct sensor_driver_api *)dev->driver_api;
349350

350351
if (api->attr_set == NULL) {
351352
return -ENOTSUP;
@@ -375,7 +376,8 @@ static inline int sensor_trigger_set(struct device *dev,
375376
struct sensor_trigger *trig,
376377
sensor_trigger_handler_t handler)
377378
{
378-
const struct sensor_driver_api *api = dev->driver_api;
379+
const struct sensor_driver_api *api =
380+
(const struct sensor_driver_api *)dev->driver_api;
379381

380382
if (api->trigger_set == NULL) {
381383
return -ENOTSUP;
@@ -404,7 +406,8 @@ __syscall int sensor_sample_fetch(struct device *dev);
404406

405407
static inline int z_impl_sensor_sample_fetch(struct device *dev)
406408
{
407-
const struct sensor_driver_api *api = dev->driver_api;
409+
const struct sensor_driver_api *api =
410+
(const struct sensor_driver_api *)dev->driver_api;
408411

409412
return api->sample_fetch(dev, SENSOR_CHAN_ALL);
410413
}
@@ -434,7 +437,8 @@ __syscall int sensor_sample_fetch_chan(struct device *dev,
434437
static inline int z_impl_sensor_sample_fetch_chan(struct device *dev,
435438
enum sensor_channel type)
436439
{
437-
const struct sensor_driver_api *api = dev->driver_api;
440+
const struct sensor_driver_api *api =
441+
(const struct sensor_driver_api *)dev->driver_api;
438442

439443
return api->sample_fetch(dev, type);
440444
}
@@ -468,7 +472,8 @@ static inline int z_impl_sensor_channel_get(struct device *dev,
468472
enum sensor_channel chan,
469473
struct sensor_value *val)
470474
{
471-
const struct sensor_driver_api *api = dev->driver_api;
475+
const struct sensor_driver_api *api =
476+
(const struct sensor_driver_api *)dev->driver_api;
472477

473478
return api->channel_get(dev, chan, val);
474479
}

0 commit comments

Comments
 (0)