IoAbstraction
Loading...
Searching...
No Matches
PlatformDeterminationWire.h
1/*
2 * Copyright (c) 2018 https://www.thecoderscorner.com (Dave Cherry).
3 * This product is licensed under an Apache license, see the LICENSE file in the top-level directory.
4 */
5
6#ifndef IOA_PLATFORMDETERMINATIONWIRE_H
7#define IOA_PLATFORMDETERMINATIONWIRE_H
8
9#include "PlatformDetermination.h"
10#include <SimpleSpinLock.h>
11
12//
13// Here we work out what wire looks like on this board! Becoming non trivial these days!
14//
15#ifdef IOA_USE_MBED
16#include <i2c_api.h>
17typedef I2C* WireType;
18void ioaWireBegin(I2C* pI2cToUse);
19# define IOA_USE_MBED_WIRE
20#elif defined(IOA_USE_AVR_TWI_DIRECT) && defined(__AVR__) && defined(IOA_DEVELOPMENT_EXPERIMENTAL)
21class AvrTwiManager;
22typedef AvrTwiManager* WireType;
23extern WireType AvrTwi;
24void ioaWireBegin();
25#elif defined(BUILD_FOR_PICO_CMAKE)
26#define IOA_USE_PICOSDK_I2C
27#include "pico/i2cWrapper.h"
28class PicoI2cWrapper;
29typedef PicoI2cWrapper* WireType;
30void ioaWireBegin(i2c_inst_t* toUse);
31#elif defined(BUILD_FOR_STM32CUBE_CMAKE)
32#include "stmCube/CubeI2cWrapper.h"
33#elif defined(BUILD_FOR_NATIVE_PLATFORM)
34#include "testing/TestWire.h"
35#else
36# define IOA_USE_ARDUINO_WIRE
37#include <Wire.h>
38typedef TwoWire* WireType;
39void ioaWireBegin();
40#endif // IOA_USE_MBED
41
42extern WireType defaultWireTypePtr;
43
51bool ioaWireRead(WireType wire, int address, uint8_t* buffer, size_t len);
52
65bool ioaWireWriteWithRetry(WireType pI2c, int address, const uint8_t* buffer, size_t len, int retriesAllowed = 0, bool sendStop = true);
66
72void ioaWireSetSpeed(WireType pI2c, long frequency);
73
79bool ioaWireReady(WireType wire, int address);
80
85extern SimpleSpinLock i2cLock;
86
87#endif //IOA_PLATFORMDETERMINATIONWIRE_H