mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-01 12:24:07 +08:00
124 lines
3.3 KiB
C++
124 lines
3.3 KiB
C++
/****************************************************************************
|
|
*
|
|
* Copyright (c) 2012-2016 PX4 Development Team. All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in
|
|
* the documentation and/or other materials provided with the
|
|
* distribution.
|
|
* 3. Neither the name PX4 nor the names of its contributors may be
|
|
* used to endorse or promote products derived from this software
|
|
* without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
****************************************************************************/
|
|
|
|
/**
|
|
* @file gyro.cpp
|
|
*
|
|
* Driver for the Invensense mpu9250 connected via SPI.
|
|
*
|
|
* @author Andrew Tridgell
|
|
*
|
|
* based on the mpu6000 driver
|
|
*/
|
|
|
|
#include <drivers/device/spi.h>
|
|
|
|
#include "accel.h"
|
|
#include "icm20948.h"
|
|
|
|
ICM20948_accel::ICM20948_accel(ICM20948 *parent, const char *path) :
|
|
CDev("ICM20948_accel", path),
|
|
_parent(parent)
|
|
{
|
|
}
|
|
|
|
ICM20948_accel::~ICM20948_accel()
|
|
{
|
|
if (_accel_class_instance != -1) {
|
|
unregister_class_devname(ACCEL_BASE_DEVICE_PATH, _accel_class_instance);
|
|
}
|
|
}
|
|
|
|
int
|
|
ICM20948_accel::init()
|
|
{
|
|
// do base class init
|
|
int ret = CDev::init();
|
|
|
|
/* if probe/setup failed, bail now */
|
|
if (ret != OK) {
|
|
DEVICE_DEBUG("accel init failed");
|
|
return ret;
|
|
}
|
|
|
|
_accel_class_instance = register_class_devname(ACCEL_BASE_DEVICE_PATH);
|
|
|
|
return ret;
|
|
}
|
|
|
|
void
|
|
ICM20948_accel::parent_poll_notify()
|
|
{
|
|
poll_notify(POLLIN);
|
|
}
|
|
|
|
int
|
|
ICM20948_accel::ioctl(struct file *filp, int cmd, unsigned long arg)
|
|
{
|
|
/*
|
|
* Repeated in ICM20948_mag::ioctl
|
|
* Both accel and mag CDev could be unused in case of magnetometer only mode or MPU6500
|
|
*/
|
|
|
|
switch (cmd) {
|
|
case SENSORIOCRESET: {
|
|
return _parent->reset();
|
|
}
|
|
|
|
case SENSORIOCSPOLLRATE: {
|
|
switch (arg) {
|
|
|
|
/* zero would be bad */
|
|
case 0:
|
|
return -EINVAL;
|
|
|
|
case SENSOR_POLLRATE_DEFAULT:
|
|
return ioctl(filp, SENSORIOCSPOLLRATE, MPU9250_ACCEL_DEFAULT_RATE);
|
|
|
|
/* adjust to a legal polling interval in Hz */
|
|
default:
|
|
return _parent->_set_pollrate(arg);
|
|
}
|
|
}
|
|
|
|
case ACCELIOCSSCALE: {
|
|
struct accel_calibration_s *s = (struct accel_calibration_s *) arg;
|
|
memcpy(&_parent->_accel_scale, s, sizeof(_parent->_accel_scale));
|
|
return OK;
|
|
}
|
|
|
|
default:
|
|
return CDev::ioctl(filp, cmd, arg);
|
|
}
|
|
}
|