Plese use this class with my "i2cmaster" class.
Dependents: 2016_slave_rorikon_2 2016_slave_cylinder 2016_slave_MD 2016_slave_MD_rorikon ... more
i2cslave.h@0:69b088a9899b, 2016-04-16 (annotated)
- Committer:
- sgrsn
- Date:
- Sat Apr 16 04:25:19 2016 +0000
- Revision:
- 0:69b088a9899b
- Child:
- 2:0dff052266ca
I2C_Slave class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sgrsn | 0:69b088a9899b | 1 | #ifndef MBED_I2CSLAVE_H |
sgrsn | 0:69b088a9899b | 2 | #define MBED_I2CSLAVE_H |
sgrsn | 0:69b088a9899b | 3 | |
sgrsn | 0:69b088a9899b | 4 | #include "mbed.h" |
sgrsn | 0:69b088a9899b | 5 | |
sgrsn | 0:69b088a9899b | 6 | namespace mbed { |
sgrsn | 0:69b088a9899b | 7 | |
sgrsn | 0:69b088a9899b | 8 | /*example**************************** |
sgrsn | 0:69b088a9899b | 9 | |
sgrsn | 0:69b088a9899b | 10 | * #include "mbed.h" |
sgrsn | 0:69b088a9899b | 11 | * #include "i2cslave.h" |
sgrsn | 0:69b088a9899b | 12 | |
sgrsn | 0:69b088a9899b | 13 | * char Registar[0x80]; |
sgrsn | 0:69b088a9899b | 14 | * i2cslave i2c(dp5, dp27, Registar); |
sgrsn | 0:69b088a9899b | 15 | |
sgrsn | 0:69b088a9899b | 16 | * int main() |
sgrsn | 0:69b088a9899b | 17 | * { |
sgrsn | 0:69b088a9899b | 18 | * i2c.address(0xa0); |
sgrsn | 0:69b088a9899b | 19 | * while(1) |
sgrsn | 0:69b088a9899b | 20 | * { |
sgrsn | 0:69b088a9899b | 21 | * printf("%d\r\n", Registar[1]); |
sgrsn | 0:69b088a9899b | 22 | * } |
sgrsn | 0:69b088a9899b | 23 | * } |
sgrsn | 0:69b088a9899b | 24 | *************************************/ |
sgrsn | 0:69b088a9899b | 25 | |
sgrsn | 0:69b088a9899b | 26 | class i2cslave : public I2CSlave |
sgrsn | 0:69b088a9899b | 27 | { |
sgrsn | 0:69b088a9899b | 28 | public: |
sgrsn | 0:69b088a9899b | 29 | char *Registar; |
sgrsn | 0:69b088a9899b | 30 | i2cslave(PinName sda, PinName scl, char *Registar); |
sgrsn | 0:69b088a9899b | 31 | |
sgrsn | 0:69b088a9899b | 32 | void getdata(); |
sgrsn | 0:69b088a9899b | 33 | |
sgrsn | 0:69b088a9899b | 34 | void attach(void (*fptr)(void)); |
sgrsn | 0:69b088a9899b | 35 | |
sgrsn | 0:69b088a9899b | 36 | template<typename T> |
sgrsn | 0:69b088a9899b | 37 | void attach(T* tptr, void (T::*mptr)(void)) { |
sgrsn | 0:69b088a9899b | 38 | fp.attach(tptr, mptr); |
sgrsn | 0:69b088a9899b | 39 | enable_attach(); |
sgrsn | 0:69b088a9899b | 40 | } |
sgrsn | 0:69b088a9899b | 41 | |
sgrsn | 0:69b088a9899b | 42 | void enable_attach(); |
sgrsn | 0:69b088a9899b | 43 | |
sgrsn | 0:69b088a9899b | 44 | void disable_attach(); |
sgrsn | 0:69b088a9899b | 45 | |
sgrsn | 0:69b088a9899b | 46 | static void func_call(uint32_t id, uint8_t addr, uint8_t state); |
sgrsn | 0:69b088a9899b | 47 | |
sgrsn | 0:69b088a9899b | 48 | protected: |
sgrsn | 0:69b088a9899b | 49 | FunctionPointer fp; |
sgrsn | 0:69b088a9899b | 50 | |
sgrsn | 0:69b088a9899b | 51 | }; |
sgrsn | 0:69b088a9899b | 52 | |
sgrsn | 0:69b088a9899b | 53 | } |
sgrsn | 0:69b088a9899b | 54 | |
sgrsn | 0:69b088a9899b | 55 | #endif |