-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMC5983MA_IO.hpp
60 lines (51 loc) · 2.55 KB
/
MMC5983MA_IO.hpp
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
/// MMC5983MA_IO.hpp - MMC5983MA_IO_Base_C class - IO for MEMSIC MMC5983MA
/// 3-axis magnetometer driver template class.
// DRNadler 26-June-2023
/*
MIT License
Copyright (c) 2023 Dave Nadler
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef MMC5983A_IO_HPP_INCLUDED
#define MMC5983A_IO_HPP_INCLUDED
/// You must provide a class TDEVICE implementing platform-specific device IO
/// to the MMC5983MA_C template. Either:
/// a) Implement MMC5983MA_IO_base_C members directly, or
/// b) Implement a derived class, adding any required instance data (ie chip select used, error details).
/// Note: Using a template avoids all indirect call overhead (from virtual functions or C function pointers).
class MMC5983MA_IO_base_C {
public:
typedef enum { SPI, I2C } InterfaceType_T;
const InterfaceType_T interfaceType;
// ToDo: MMC5983MA_IO_base_C init()
/// Platform-specific bus read
void read(uint8_t reg_addr, uint8_t (&read_data)[], uint32_t len);
/// Platform-specific bus write
void write(uint8_t reg_addr, const uint8_t (&write_data)[], uint32_t len);
/// Platform-specific delay before return
void delay_us(uint32_t uSecs);
/// Did last IO operation succeed?
bool IO_OK();
/// Application must implement printf-analog if MMC5983MA_PRINT_DETAILED_LOG is defined in MMC5983MA_C
#ifdef __GNUG__
int DiagPrintf(const char* format, ...); __attribute__((format(printf, 2, 3)));
#else
int DiagPrintf(const char* format, ...); // __attribute__((format(printf, 2, 3)));
#endif
MMC5983MA_IO_base_C(InterfaceType_T interfaceType_) : interfaceType(interfaceType_) {};
};
#endif // MMC5983A_IO_HPP_INCLUDED