IoAbstraction
All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
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#else
32# define IOA_USE_ARDUINO_WIRE
33#include <Wire.h>
34typedef TwoWire* WireType;
35void ioaWireBegin();
36#endif // IOA_USE_MBED
37
38extern WireType defaultWireTypePtr;
39
47bool ioaWireRead(WireType wire, int address, uint8_t* buffer, size_t len);
48
61bool ioaWireWriteWithRetry(WireType pI2c, int address, const uint8_t* buffer, size_t len, int retriesAllowed = 0, bool sendStop = true);
62
68void ioaWireSetSpeed(WireType pI2c, long frequency);
69
75bool ioaWireReady(WireType wire, int address);
76
81extern SimpleSpinLock i2cLock;
82
83#endif //IOA_PLATFORMDETERMINATIONWIRE_H