APM:Libraries
SPIDevice.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2016 Intel Corporation. All rights reserved.
3  *
4  * This file is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This file is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  * See the GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #pragma once
18 
19 #include <inttypes.h>
20 
21 #include "AP_HAL_Namespace.h"
22 #include "Device.h"
23 #include "utility/OwnPtr.h"
24 
25 namespace AP_HAL {
26 
27 class SPIDevice : public Device {
28 public:
30 
31  virtual ~SPIDevice() { }
32  /* Device implementation */
33 
34  /* See Device::set_speed() */
35  virtual bool set_speed(Device::Speed speed) override = 0;
36 
37  /* See Device::transfer() */
38  virtual bool transfer(const uint8_t *send, uint32_t send_len,
39  uint8_t *recv, uint32_t recv_len) override = 0;
40 
41  /*
42  * Like #transfer(), but both @send and @recv buffers are transmitted at
43  * the same time: because of this they need to be of the same size.
44  */
45  virtual bool transfer_fullduplex(const uint8_t *send, uint8_t *recv,
46  uint32_t len) = 0;
47 
48  /*
49  * send N bytes of clock pulses without taking CS. This is used
50  * when initialising microSD interfaces over SPI
51  */
52  virtual bool clock_pulse(uint32_t len) { return false; }
53 
54  /* See Device::get_semaphore() */
55  virtual Semaphore *get_semaphore() override = 0;
56 
57  /* See Device::register_periodic_callback() */
59  uint32_t period_usec, Device::PeriodicCb) override = 0;
60 
61  /* See Device::adjust_periodic_callback() */
63  PeriodicHandle h, uint32_t period_usec) override { return false; }
64 };
65 
67 public:
68  virtual OwnPtr<SPIDevice> get_device(const char *name)
69  {
70  return nullptr;
71  }
72 
73  /* Return the number of SPI devices currently registered. */
74  virtual uint8_t get_count() { return 0; }
75 
76  /* Get spi device name at @idx */
77  virtual const char *get_device_name(uint8_t idx) { return nullptr; }
78 };
79 
80 }
virtual Device::PeriodicHandle register_periodic_callback(uint32_t period_usec, Device::PeriodicCb) override=0
virtual bool clock_pulse(uint32_t len)
Definition: SPIDevice.h:52
virtual uint8_t get_count()
Definition: SPIDevice.h:74
const char * name
Definition: BusTest.cpp:11
virtual bool adjust_periodic_callback(PeriodicHandle h, uint32_t period_usec) override
Definition: SPIDevice.h:62
virtual OwnPtr< SPIDevice > get_device(const char *name)
Definition: SPIDevice.h:68
virtual Semaphore * get_semaphore() override=0
void * PeriodicHandle
Definition: Device.h:42
virtual bool transfer_fullduplex(const uint8_t *send, uint8_t *recv, uint32_t len)=0
virtual bool set_speed(Device::Speed speed) override=0
virtual ~SPIDevice()
Definition: SPIDevice.h:31
virtual bool transfer(const uint8_t *send, uint32_t send_len, uint8_t *recv, uint32_t recv_len) override=0
virtual const char * get_device_name(uint8_t idx)
Definition: SPIDevice.h:77