libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
i2c.h
Go to the documentation of this file.
1#pragma once
2#include "util/hal_map.h"
3#include "daisy_core.h"
4
5namespace daisy
6{
26{
27 public:
29 struct Config
30 {
32 enum class Mode
33 {
36 };
37
39 enum class Peripheral
40 {
41 I2C_1 = 0,
42 I2C_2,
43 I2C_3,
44 I2C_4,
45 };
46
50 enum class Speed
51 {
54 I2C_1MHZ,
55 };
56
58 struct
59 {
66 // 0x10 is chosen as a default to avoid conflicts with reserved addresses
68 };
69
71 enum class Result
72 {
73 OK,
74 ERR
75 };
76
77 enum class Direction
78 {
79 TRANSMIT,
80 RECEIVE,
81 };
82
83 I2CHandle() : pimpl_(nullptr) {}
84 I2CHandle(const I2CHandle& other) = default;
85 I2CHandle& operator=(const I2CHandle& other) = default;
86
89
91 const Config& GetConfig() const;
92
102 uint8_t* data,
104 uint32_t timeout);
105
115 uint8_t* data,
117 uint32_t timeout);
118
120 typedef void (*CallbackFunctionPtr)(void* context, Result result);
121
142 uint8_t* data,
145 void* callback_context);
146
167 uint8_t* data,
170 void* callback_context);
171
185 uint8_t* data,
187 uint32_t timeout);
188
202 uint8_t* data,
204 uint32_t timeout);
205
206
207 class Impl;
209 private:
210 Impl* pimpl_;
211};
212
213extern "C"
214{
217};
218
219} // namespace daisy
Definition i2c.h:26
I2CHandle(const I2CHandle &other)=default
const Config & GetConfig() const
Result ReadDataAtAddress(uint16_t address, uint16_t mem_address, uint16_t mem_address_size, uint8_t *data, uint16_t data_size, uint32_t timeout)
Result TransmitDma(uint16_t address, uint8_t *data, uint16_t size, CallbackFunctionPtr callback, void *callback_context)
Result Init(const Config &config)
I2CHandle()
Definition i2c.h:83
Result
Definition i2c.h:72
Result ReceiveBlocking(uint16_t address, uint8_t *data, uint16_t size, uint32_t timeout)
void(* CallbackFunctionPtr)(void *context, Result result)
Definition i2c.h:120
I2CHandle & operator=(const I2CHandle &other)=default
Direction
Definition i2c.h:78
Result TransmitBlocking(uint16_t address, uint8_t *data, uint16_t size, uint32_t timeout)
Result ReceiveDma(uint16_t address, uint8_t *data, uint16_t size, CallbackFunctionPtr callback, void *callback_context)
Result WriteDataAtAddress(uint16_t address, uint16_t mem_address, uint16_t mem_address_size, uint8_t *data, uint16_t data_size, uint32_t timeout)
Definition leddriver.h:33
Hardware defines and helpers for daisy field platform.
Definition index.h:2
void dsy_i2c_global_init()
Definition i2c.h:30
Mode
Definition i2c.h:33
struct daisy::I2CHandle::Config::@15 pin_config
Mode mode
Definition i2c.h:65
Pin scl
Definition i2c.h:60
Speed
Definition i2c.h:51
Speed speed
Definition i2c.h:64
uint8_t address
Definition i2c.h:67
Peripheral periph
Definition i2c.h:57
Peripheral
Definition i2c.h:40
Pin sda
Definition i2c.h:61
representation of hardware port/pin combination
Definition daisy_core.h:193