48
48
#ifndef I2C_BUFFER_LENGTH
49
49
#define I2C_BUFFER_LENGTH 128 // Default size, if none is set using Wire::setBuffersize(size_t)
50
50
#endif
51
- #if SOC_I2C_SUPPORT_SLAVE
52
- typedef void (*user_onRequest)(void );
53
- typedef void (*user_onReceive)(uint8_t *, int );
54
- #endif /* SOC_I2C_SUPPORT_SLAVE */
55
51
56
52
class TwoWire : public HardwareI2C {
57
53
protected:
@@ -77,8 +73,11 @@ class TwoWire : public HardwareI2C {
77
73
private:
78
74
#if SOC_I2C_SUPPORT_SLAVE
79
75
bool is_slave;
80
- void (*user_onRequest)(void );
81
- void (*user_onReceive)(int );
76
+ // functional pointers for user callbacks
77
+ using user_onRequest_t = void (*)(void );
78
+ using user_onReceive_t = void (*)(int );
79
+ user_onRequest_t user_onRequest;
80
+ user_onReceive_t user_onReceive;
82
81
static void onRequestService (uint8_t , void *);
83
82
static void onReceiveService (uint8_t , uint8_t *, size_t , bool , void *);
84
83
#endif /* SOC_I2C_SUPPORT_SLAVE */
@@ -116,8 +115,8 @@ class TwoWire : public HardwareI2C {
116
115
size_t requestFrom (uint8_t address, size_t len, bool stopBit) override ;
117
116
size_t requestFrom (uint8_t address, size_t len) override ;
118
117
119
- void onReceive (void (*)( int ) ) override ;
120
- void onRequest (void (*)( void ) ) override ;
118
+ void onReceive (user_onReceive_t ) override ;
119
+ void onRequest (user_onRequest_t ) override ;
121
120
122
121
// call setPins() first, so that begin() can be called without arguments from libraries
123
122
bool setPins (int sda, int scl);
0 commit comments