6
6
7
7
The MIT License (MIT)
8
8
9
- Copyright (c) 2022 SparkFun Electronics
9
+ Copyright (c) 2023 SparkFun Electronics
10
+
10
11
Permission is hereby granted, free of charge, to any person obtaining a
11
12
copy of this software and associated documentation files (the "Software"),
12
13
to deal in the Software without restriction, including without limitation
@@ -21,70 +22,97 @@ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
22
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22
23
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
24
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
24
26
*/
25
27
26
28
#pragma once
27
29
28
- #include < cstdint>
30
+ #include " sfeTkError.h"
31
+
32
+
33
+ // Define our error codes for the bus. Note Errors are negative, warnings/info postive
34
+ // BUT keep the same increment on the base
35
+
36
+ const sfeTkError_t kSTkErrBusNullPtr = kSTkErrFail * (kSTkErrBaseBus + 1 );
37
+ const sfeTkError_t kSTkErrBusTimeout = kSTkErrFail * (kSTkErrBaseBus + 2 );
38
+ const sfeTkError_t kSTkErrBusNoReponse = kSTkErrFail * (kSTkErrBaseBus + 3 );
39
+ const sfeTkError_t kSTkErrBusDataTooLong = kSTkErrFail * (kSTkErrBaseBus + 4 );
40
+ const sfeTkError_t kSTkErrBusNullSettings = kSTkErrFail * (kSTkErrBaseBus + 5 );
41
+ const sfeTkError_t kSTkErrBusNullBuffer = kSTkErrFail * (kSTkErrBaseBus + 6 );
42
+ const sfeTkError_t kSTkErrBusUnderRead = kSTkErrBaseBus + 7 ;
43
+ const sfeTkError_t kSTkErrBusNotEnabled = kSTkErrBaseBus + 8 ;
44
+
45
+ // Define the bus interface.
29
46
30
47
class sfeTkIBus
31
48
{
32
49
public:
33
- // / @brief Write a single byte to the given register
34
- // /
35
- // / @param devReg The device's register's address.
36
- // / @param data Data to write.
37
- // /
38
- // / @retval bool - true on successful execution.
39
- // /
40
- virtual bool writeRegisterByte (uint8_t devReg, uint8_t data) = 0;
41
-
42
- // / @brief Write a single word (16 bit) to the given register
43
- // /
44
- // / @param devReg The device's register's address.
45
- // / @param data Data to write.
46
- // /
47
- // / @retval bool - true on successful execution.
48
- // /
49
- virtual bool writeRegisterWord (uint8_t devReg, uint16_t data) = 0;
50
-
51
- // / @brief Writes a number of bytes starting at the given register's address.
52
- // /
53
- // / @param devAddr The device's address/pin
54
- // / @param devReg The device's register's address.
55
- // / @param data Data to write.
56
- // /
57
- // / @retval int returns the number of bytes written, < 0 on error
58
- // /
59
- virtual int writeRegisterRegion (uint8_t devReg, const uint8_t *data, size_t length) = 0;
60
-
61
- // / @brief Read a single byte from the given register
62
- // /
63
- // / @param devReg The device's register's address.
64
- // / @param data Data to read.
65
- // /
66
- // / @retval bool - true on successful execution.
67
- // /
68
- virtual bool readRegisterByte (uint8_t devReg, uint8_t &data) = 0;
69
-
70
- // / @brief Read a single word (16 bit) from the given register
71
- // /
72
- // / @param devReg The device's register's address.
73
- // / @param data Data to read.
74
- // /
75
- // / @retval bool - true on successful execution.
76
- // /
77
- virtual bool readRegisterWord (uint8_t devReg, uint16_t &data) = 0;
78
-
79
- // / @brief Reads a block of data from the given register.
80
- // /
81
- // / @param devAddr The device's I2C address.
82
- // / @param devReg The device's register's address.
83
- // / @param data Data to write.
84
- // /
85
- // / @retval int returns 0 on success, or error code
86
- // /
87
- virtual int readRegisterRegion (uint8_t reg, uint8_t *data, size_t numBytes) = 0;
50
+ /* --------------------------------------------------------------------------
51
+ @brief Write a single byte to the given register
52
+
53
+ @param devReg The device's register's address.
54
+ @param data Data to write.
55
+
56
+ @retval sfeTkError_t - kSTkErrOk on successful execution.
57
+
58
+ */
59
+ virtual sfeTkError_t writeRegisterByte (uint8_t devReg, uint8_t data) = 0;
60
+
61
+ /* --------------------------------------------------------------------------
62
+ @brief Write a single word (16 bit) to the given register
63
+
64
+ @param devReg The device's register's address.
65
+ @param data Data to write.
66
+
67
+ @retval sfeTkError_t - kSTkErrOk on successful execution.
68
+
69
+ */
70
+ virtual sfeTkError_t writeRegisterWord (uint8_t devReg, uint16_t data) = 0;
71
+
72
+ /* --------------------------------------------------------------------------
73
+ @brief Writes a number of bytes starting at the given register's address.
74
+
75
+ @param devAddr The device's address/pin
76
+ param devReg The device's register's address.
77
+ @param data Data to write.
78
+
79
+ @retval int returns the number of bytes written, or kSTkErrFail on error
80
+
81
+ */
82
+ virtual int32_t writeRegisterRegion (uint8_t devReg, const uint8_t *data, size_t length) = 0;
83
+
84
+ /* --------------------------------------------------------------------------
85
+ @brief Read a single byte from the given register
86
+
87
+ @param devReg The device's register's address.
88
+ @param data Data to read.
89
+
90
+ @retval sfeTkError_t - kSTkErrOk on successful execution.
91
+
92
+ */
93
+ virtual sfeTkError_t readRegisterByte (uint8_t devReg, uint8_t &data) = 0;
94
+
95
+ /* --------------------------------------------------------------------------
96
+ @brief Read a single word (16 bit) from the given register
97
+
98
+ @param devReg The device's register's address.
99
+ @param data Data to read.
100
+
101
+ @retval sfeTkError_t - kSTkErrOk on successful execution.
102
+ */
103
+ virtual sfeTkError_t readRegisterWord (uint8_t devReg, uint16_t &data) = 0;
104
+
105
+ /* --------------------------------------------------------------------------
106
+ @brief Reads a block of data from the given register.
107
+
108
+ @param devAddr The device's I2C address.
109
+ @param devReg The device's register's address.
110
+ @param data Data to write.
111
+
112
+ @retval int returns kSTkErrOk on success, or kSTkErrFail code
113
+
114
+ */
115
+ virtual sfeTkError_t readRegisterRegion (uint8_t reg, uint8_t *data, size_t numBytes) = 0;
88
116
};
89
117
90
118
// };
0 commit comments