123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
-
- #ifndef MBED_I2C_H
- #define MBED_I2C_H
-
- #include "platform.h"
-
- #if DEVICE_I2C
-
- #include "i2c_api.h"
-
- #if DEVICE_I2C_ASYNCH
- #include "CThunk.h"
- #include "dma_api.h"
- #include "FunctionPointer.h"
- #endif
-
- namespace mbed {
-
-
- class I2C {
-
- public:
- enum RxStatus {
- NoData,
- MasterGeneralCall,
- MasterWrite,
- MasterRead
- };
-
- enum Acknowledge {
- NoACK = 0,
- ACK = 1
- };
-
-
-
- I2C(PinName sda, PinName scl);
-
-
-
- void frequency(int hz);
-
-
-
- int read(int address, char *data, int length, bool repeated = false);
-
-
-
- int read(int ack);
-
-
-
- int write(int address, const char *data, int length, bool repeated = false);
-
-
-
- int write(int data);
-
-
-
-
- void start(void);
-
-
-
- void stop(void);
-
- #if DEVICE_I2C_ASYNCH
-
-
-
- int transfer(int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t& callback, int event = I2C_EVENT_TRANSFER_COMPLETE, bool repeated = false);
-
-
-
- void abort_transfer();
- protected:
- void irq_handler_asynch(void);
- event_callback_t _callback;
- CThunk<I2C> _irq;
- DMAUsage _usage;
- #endif
-
- protected:
- void aquire();
-
- i2c_t _i2c;
- static I2C *_owner;
- int _hz;
- };
-
- }
-
- #endif
-
- #endif
|