diff --git a/libraries/AP_HAL/AP_HAL_Namespace.h b/libraries/AP_HAL/AP_HAL_Namespace.h index f78b5aabea..74753303ce 100644 --- a/libraries/AP_HAL/AP_HAL_Namespace.h +++ b/libraries/AP_HAL/AP_HAL_Namespace.h @@ -17,6 +17,7 @@ namespace AP_HAL { class I2CDriver; class Device; + class SPIDevice; class SPIDeviceDriver; class SPIDeviceManager; diff --git a/libraries/AP_HAL/SPIDevice.h b/libraries/AP_HAL/SPIDevice.h new file mode 100644 index 0000000000..7a158985c4 --- /dev/null +++ b/libraries/AP_HAL/SPIDevice.h @@ -0,0 +1,52 @@ +/// -*- 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 "AP_HAL_Namespace.h" +#include "Device.h" +#include "utility/OwnPtr.h" + +namespace AP_HAL { + +class SPIDevice : public Device { +public: + virtual ~SPIDevice() { } + /* Device implementation */ + + /* See Device::set_speed() */ + virtual bool set_speed(Device::Speed speed) override = 0; + + /* See Device::transfer() */ + virtual bool transfer(const uint8_t *send, uint32_t send_len, + uint8_t *recv, uint32_t recv_len) override = 0; + + /* See Device::get_semaphore() */ + virtual Semaphore *get_semaphore() override = 0; + + /* See Device::register_periodic_callback() */ + virtual Device::PeriodicHandle *register_periodic_callback( + uint32_t period_usec, MemberProc) override = 0; + + virtual int get_fd() override = 0; +}; + +/* SPIDeviceManager is temporarily provided by SPIDriver.h */ + +} diff --git a/libraries/AP_HAL/SPIDriver.h b/libraries/AP_HAL/SPIDriver.h index 92256ad310..f9182ad896 100644 --- a/libraries/AP_HAL/SPIDriver.h +++ b/libraries/AP_HAL/SPIDriver.h @@ -1,14 +1,39 @@ +/// -*- 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 -#ifndef __AP_HAL_SPI_DRIVER_H__ -#define __AP_HAL_SPI_DRIVER_H__ +#include #include "AP_HAL_Namespace.h" +#include "SPIDevice.h" +#include "utility/OwnPtr.h" +namespace AP_HAL { -class AP_HAL::SPIDeviceManager { +class SPIDeviceManager { public: virtual void init() = 0; - virtual AP_HAL::SPIDeviceDriver* device(enum AP_HAL::SPIDeviceType, uint8_t index = 0) = 0; + virtual SPIDeviceDriver* device(enum SPIDeviceType, uint8_t index = 0) = 0; + virtual OwnPtr get_device(const char *name) + { + return nullptr; + } }; /** @@ -16,10 +41,10 @@ public: * transfers to be portable to other platforms. */ -class AP_HAL::SPIDeviceDriver { +class SPIDeviceDriver { public: virtual void init() = 0; - virtual AP_HAL::Semaphore* get_semaphore() = 0; + virtual Semaphore* get_semaphore() = 0; virtual bool transaction(const uint8_t *tx, uint8_t *rx, uint16_t len) = 0; virtual void cs_assert() = 0; @@ -41,5 +66,4 @@ public: virtual void set_bus_speed(enum bus_speed speed) {} }; -#endif // __AP_HAL_SPI_DRIVER_H__ - +}