ArPiRobot-CoreLib C++
C++ library for ArPiRobot robots
IoProvider.hpp
1 /*
2  * Copyright 2021 Marcus Behel
3  *
4  * This file is part of ArPiRobot-CoreLib.
5  *
6  * ArPiRobot-CoreLib is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * ArPiRobot-CoreLib is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with ArPiRobot-CoreLib. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 
21 #pragma once
22 
23 
24 #include <string>
25 #include <vector>
26 #include <mutex>
27 
28 namespace arpirobot {
29 
30  class IoProvider{
31  public:
32  IoProvider(const IoProvider &other) = delete;
33  IoProvider &operator=(const IoProvider &other) = delete;
34  virtual ~IoProvider() = default;
35 
36  const static unsigned int GPIO_OUT = 0;
37  const static unsigned int GPIO_IN = 1;
38  const static unsigned int GPIO_LOW = 0;
39  const static unsigned int GPIO_HIGH = 1;
40 
41  protected:
42 
43  // Protected default constructor ensures direct instantiation is not possible
44  IoProvider() = default;
45 
49  virtual void gpioMode(unsigned int pin, unsigned int mode) = 0;
50 
51  virtual void gpioWrite(unsigned int pin, unsigned int state) = 0;
52 
53  virtual unsigned int gpioRead(unsigned int pin) = 0;
54 
55  virtual void gpioSetPwmFrequency(unsigned int pin, unsigned int frequency) = 0;
56 
57  virtual unsigned int gpioGetPwmFrequency(unsigned int pin) = 0;
58 
59  virtual void gpioPwm(unsigned int pin, unsigned int value) = 0;
60 
61 
65  virtual unsigned int i2cOpen(unsigned int bus, unsigned int address) = 0;
66 
67  virtual void i2cClose(unsigned int handle) = 0;
68 
69  virtual void i2cWriteByte(unsigned int handle, uint8_t data) = 0;
70 
71  virtual uint8_t i2cReadByte(unsigned int handle) = 0;
72 
73  virtual void i2cWriteBytes(unsigned int handle, char *buf, unsigned int count) = 0;
74 
75  virtual unsigned int i2cReadBytes(unsigned int handle, char *buf, unsigned int count) = 0;
76 
77  virtual void i2cWriteReg8(unsigned int handle, uint8_t reg, uint8_t value) = 0;
78 
79  virtual uint8_t i2cReadReg8(unsigned int handle, uint8_t reg) = 0;
80 
81  virtual void i2cWriteReg16(unsigned int handle, uint8_t reg, uint16_t value) = 0;
82 
83  virtual uint16_t i2cReadReg16(unsigned int handle, uint8_t reg) = 0;
84 
85 
89 
90  // Bus = spi bus
91  // Channel = which builtin CS pin
92  // Mode = SPI Mode (0, 1, 2, 3)
93  virtual unsigned int spiOpen(unsigned int bus, unsigned int channel, unsigned int baud, unsigned int mode) = 0;
94 
95  virtual void spiClose(unsigned int handle) = 0;
96 
97  virtual void spiWrite(unsigned int handle, char *buf, unsigned int count) = 0;
98 
99  virtual unsigned int spiRead(unsigned int handle, char *buf, unsigned int count) = 0;
100 
101 
105 
106  virtual unsigned int uartOpen(char *port, unsigned int baud) = 0;
107 
108  virtual void uartClose(unsigned int handle) = 0;
109 
110  virtual unsigned int uartAvailable(unsigned int handle) = 0;
111 
112  virtual void uartWrite(unsigned int handle, char* buf, unsigned int count) = 0;
113 
114  virtual unsigned int uartRead(unsigned int handle, char *buf, unsigned int count) = 0;
115 
116  virtual void uartWriteByte(unsigned int handle, uint8_t b) = 0;
117 
118  virtual uint8_t uartReadByte(unsigned int handle) = 0;
119 
120  friend class Io;
121  };
122 
123 }
Definition: IoProvider.hpp:30
virtual unsigned int i2cOpen(unsigned int bus, unsigned int address)=0
I2C.
virtual void gpioMode(unsigned int pin, unsigned int mode)=0
GPIO & PWM.
virtual unsigned int spiOpen(unsigned int bus, unsigned int channel, unsigned int baud, unsigned int mode)=0
SPI.
virtual unsigned int uartOpen(char *port, unsigned int baud)=0
UART.
Definition: Io.hpp:32
Definition: ArduinoDevice.hpp:27