-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBusDevice.h
94 lines (67 loc) · 3.53 KB
/
BusDevice.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* This file is part of the Arduino_ThreadsafeIO library.
* Copyright (c) 2021 Arduino SA.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef BUS_DEVICE_H_
#define BUS_DEVICE_H_
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include "IoTransaction.h"
#include "spi/SpiBusDeviceConfig.h"
/**************************************************************************************
* FORWARD DECLARATION
**************************************************************************************/
namespace arduino
{
class HardwareSPI;
class HardwareI2C;
}
class BusDevice;
class SpiBusDevice;
class WireBusDevice;
/**************************************************************************************
* CLASS DECLARATION
**************************************************************************************/
class BusDeviceBase
{
public:
virtual ~BusDeviceBase() { }
virtual IoResponse transfer(IoRequest & req) = 0;
static BusDevice create(arduino::HardwareSPI & spi, int const cs_pin, SPISettings const & spi_settings, byte const fill_symbol = 0xFF);
static BusDevice create(arduino::HardwareSPI & spi, int const cs_pin, uint32_t const spi_clock, BitOrder const spi_bit_order, SPIMode const spi_bit_mode, byte const fill_symbol = 0xFF);
static BusDevice create(arduino::HardwareSPI & spi, SpiBusDeviceConfig::SpiSelectFunc spi_select, SpiBusDeviceConfig::SpiDeselectFunc spi_deselect, SPISettings const & spi_settings, byte const fill_symbol = 0xFF);
static BusDevice create(arduino::HardwareI2C & wire, byte const slave_addr);
static BusDevice create(arduino::HardwareI2C & wire, byte const slave_addr, bool const restart);
static BusDevice create(arduino::HardwareI2C & wire, byte const slave_addr, bool const restart, bool const stop);
};
class BusDevice
{
public:
BusDevice(BusDeviceBase * dev);
BusDevice(arduino::HardwareSPI & spi, int const cs_pin, SPISettings const & spi_settings, byte const fill_symbol = 0xFF);
BusDevice(arduino::HardwareSPI & spi, int const cs_pin, uint32_t const spi_clock, BitOrder const spi_bit_order, SPIMode const spi_bit_mode, byte const fill_symbol = 0xFF);
BusDevice(arduino::HardwareSPI & spi, SpiBusDeviceConfig::SpiSelectFunc spi_select, SpiBusDeviceConfig::SpiDeselectFunc spi_deselect, SPISettings const & spi_settings, byte const fill_symbol = 0xFF);
BusDevice(arduino::HardwareI2C & wire, byte const slave_addr);
BusDevice(arduino::HardwareI2C & wire, byte const slave_addr, bool const restart);
BusDevice(arduino::HardwareI2C & wire, byte const slave_addr, bool const restart, bool const stop);
IoResponse transfer(IoRequest & req);
SpiBusDevice & spi();
WireBusDevice & wire();
private:
mbed::SharedPtr<BusDeviceBase> _dev;
};
#endif /* BUS_DEVICE_H_ */