4848#ifndef I2C_BUFFER_LENGTH
4949#define I2C_BUFFER_LENGTH 128 // Default size, if none is set using Wire::setBuffersize(size_t)
5050#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 */
5551
5652class TwoWire : public HardwareI2C {
5753protected:
@@ -77,8 +73,11 @@ class TwoWire : public HardwareI2C {
7773private:
7874#if SOC_I2C_SUPPORT_SLAVE
7975 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;
8281 static void onRequestService (uint8_t , void *);
8382 static void onReceiveService (uint8_t , uint8_t *, size_t , bool , void *);
8483#endif /* SOC_I2C_SUPPORT_SLAVE */
@@ -116,8 +115,8 @@ class TwoWire : public HardwareI2C {
116115 size_t requestFrom (uint8_t address, size_t len, bool stopBit) override ;
117116 size_t requestFrom (uint8_t address, size_t len) override ;
118117
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 ;
121120
122121 // call setPins() first, so that begin() can be called without arguments from libraries
123122 bool setPins (int sda, int scl);
0 commit comments