From a117c22c34ed80c656214f8354c2f17abc86959c Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Tue, 1 Dec 2015 01:07:59 -0200 Subject: [PATCH] AP_HAL_Empty: add I2CDevice --- .../AP_HAL_Empty/AP_HAL_Empty_Namespace.h | 2 + libraries/AP_HAL_Empty/AP_HAL_Empty_Private.h | 1 + libraries/AP_HAL_Empty/I2CDevice.h | 89 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 libraries/AP_HAL_Empty/I2CDevice.h diff --git a/libraries/AP_HAL_Empty/AP_HAL_Empty_Namespace.h b/libraries/AP_HAL_Empty/AP_HAL_Empty_Namespace.h index 2c77b9c4f8..840450bbd3 100644 --- a/libraries/AP_HAL_Empty/AP_HAL_Empty_Namespace.h +++ b/libraries/AP_HAL_Empty/AP_HAL_Empty_Namespace.h @@ -5,6 +5,8 @@ namespace Empty { class AnalogSource; class DigitalSource; class GPIO; + class I2CDevice; + class I2CDeviceManager; class I2CDriver; class OpticalFlow; class PrivateMember; diff --git a/libraries/AP_HAL_Empty/AP_HAL_Empty_Private.h b/libraries/AP_HAL_Empty/AP_HAL_Empty_Private.h index e38731a4be..90eaa84b58 100644 --- a/libraries/AP_HAL_Empty/AP_HAL_Empty_Private.h +++ b/libraries/AP_HAL_Empty/AP_HAL_Empty_Private.h @@ -8,6 +8,7 @@ #include "AnalogIn.h" #include "GPIO.h" +#include "I2CDevice.h" #include "I2CDriver.h" #include "OpticalFlow.h" #include "PrivateMember.h" diff --git a/libraries/AP_HAL_Empty/I2CDevice.h b/libraries/AP_HAL_Empty/I2CDevice.h new file mode 100644 index 0000000000..d7836b4b47 --- /dev/null +++ b/libraries/AP_HAL_Empty/I2CDevice.h @@ -0,0 +1,89 @@ +/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- +/* + * Copyright (C) 2015-2016 Intel Corporation. All rights reserved. + * + * This file is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +#pragma once + +#include + +#include +#include +#include + +namespace Empty { + +class I2CDevice : public AP_HAL::I2CDevice { +public: + I2CDevice() + { + } + + virtual ~I2CDevice() { } + + /* AP_HAL::I2CDevice implementation */ + + /* See AP_HAL::I2CDevice::set_address() */ + void set_address(uint8_t address) override { } + + /* See AP_HAL::I2CDevice::set_retries() */ + void set_retries(uint8_t retries) override { } + + + /* AP_HAL::Device implementation */ + + /* See AP_HAL::Device::transfer() */ + bool transfer(const uint8_t *send, uint32_t send_len, + uint8_t *recv, uint32_t recv_len) override + { + return true; + } + + bool read_registers_multiple(uint8_t first_reg, uint8_t *recv, + uint32_t recv_len, uint8_t times) + { + return true; + } + + + /* See AP_HAL::Device::set_speed() */ + bool set_speed(enum AP_HAL::Device::Speed speed) override { return true; } + + /* See AP_HAL::Device::get_semaphore() */ + AP_HAL::Semaphore *get_semaphore() { return nullptr; } + + /* See AP_HAL::Device::register_periodic_callback() */ + AP_HAL::Device::PeriodicHandle *register_periodic_callback( + uint32_t period_usec, AP_HAL::MemberProc) override + { + return nullptr; + }; + + /* See AP_HAL::Device::get_fd() */ + int get_fd() { return -1; } +}; + +class I2CDeviceManager : public AP_HAL::I2CDeviceManager { +public: + I2CDeviceManager() { } + + /* AP_HAL::I2CDeviceManager implementation */ + AP_HAL::OwnPtr get_device(uint8_t bus, uint8_t address) + { + return AP_HAL::OwnPtr(new I2CDevice()); + } +}; + +}