i2c slave class to RaspberryPi with interrupt
Fork of i2cslave by
Diff: i2cslave.h
- Revision:
- 0:69b088a9899b
- Child:
- 2:0dff052266ca
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/i2cslave.h Sat Apr 16 04:25:19 2016 +0000 @@ -0,0 +1,55 @@ +#ifndef MBED_I2CSLAVE_H +#define MBED_I2CSLAVE_H + +#include "mbed.h" + +namespace mbed { + + /*example**************************** + + * #include "mbed.h" + * #include "i2cslave.h" + + * char Registar[0x80]; + * i2cslave i2c(dp5, dp27, Registar); + + * int main() + * { + * i2c.address(0xa0); + * while(1) + * { + * printf("%d\r\n", Registar[1]); + * } + * } + *************************************/ + +class i2cslave : public I2CSlave +{ +public: + char *Registar; + i2cslave(PinName sda, PinName scl, char *Registar); + + void getdata(); + + void attach(void (*fptr)(void)); + + template<typename T> + void attach(T* tptr, void (T::*mptr)(void)) { + fp.attach(tptr, mptr); + enable_attach(); + } + + void enable_attach(); + + void disable_attach(); + + static void func_call(uint32_t id, uint8_t addr, uint8_t state); + +protected: + FunctionPointer fp; + +}; + +} + +#endif