Add an i2c request handler

This commit is contained in:
Scott Lahteine
2016-08-11 17:57:22 -07:00
parent d29a64d4b3
commit 67f119d18b
2 changed files with 26 additions and 8 deletions

View File

@ -30,7 +30,8 @@
// Print debug messages with M111 S2 (Uses 236 bytes of PROGMEM)
//#define DEBUG_TWIBUS
typedef void (*twiSlaveFunc_t)(int bytes);
typedef void (*twiReceiveFunc_t)(int bytes);
typedef void (*twiRequestFunc_t)();
/**
* TWIBUS class
@ -143,13 +144,20 @@ class TWIBus {
inline void receive(uint8_t bytes) { relaydata(bytes); }
/**
* @brief Register a slave handler
* @details Set a handler to receive data from the bus,
* so we can act as a slave.
* @brief Register a slave receive handler
* @details Set a handler to receive data addressed to us.
*
* @param handler A function to handle receiving bytes
*/
inline void onReceive(const twiSlaveFunc_t handler) { Wire.onReceive(handler); }
inline void onReceive(const twiReceiveFunc_t handler) { Wire.onReceive(handler); }
/**
* @brief Register a slave request handler
* @details Set a handler to send data requested from us.
*
* @param handler A function to handle receiving bytes
*/
inline void onRequest(const twiRequestFunc_t handler) { Wire.onRequest(handler); }
#endif