Information
This code is old.
Version 2.0 is available.
Latest version has improved usability.
Please find following page.
- Demo program with same functions of TextLCD_SB1602E.
- Component page.
- Library page
Information
このコードは古いバージョンです
バージョン2.0 が公開されています.
新しいバージョンでは使い勝手が改善されています.
以下のページを御覧ください.
- 新ライブラリ対応のデモ・プログラム(機能はこれまでのものと同じです)
- コンポーネント・ページ
I2cBusDevice.h@0:694061176edf, 2010-01-23 (annotated)
- Committer:
- okano
- Date:
- Sat Jan 23 13:45:18 2010 +0000
- Revision:
- 0:694061176edf
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 0:694061176edf | 1 | /* |
okano | 0:694061176edf | 2 | * I2C device base class |
okano | 0:694061176edf | 3 | * |
okano | 0:694061176edf | 4 | * A base class for all I2C devices. |
okano | 0:694061176edf | 5 | * This manages the device address and transfers |
okano | 0:694061176edf | 6 | * |
okano | 0:694061176edf | 7 | * Copyright (c) 2010 Tedd OKANO |
okano | 0:694061176edf | 8 | * Released under the MIT License: http://mbed.org/license/mit |
okano | 0:694061176edf | 9 | * |
okano | 0:694061176edf | 10 | * revision 1.0 15-Jan-2010 a. 1st release |
okano | 0:694061176edf | 11 | * revision 1.1 23-Jan-2010 a. The word "MBED_I2cBusDevice" is used instead of _I2cBusDevice_ to avoid symbol conflict |
okano | 0:694061176edf | 12 | * b. copyright notice added |
okano | 0:694061176edf | 13 | */ |
okano | 0:694061176edf | 14 | |
okano | 0:694061176edf | 15 | #ifndef MBED_I2cBusDevice |
okano | 0:694061176edf | 16 | #define MBED_I2cBusDevice |
okano | 0:694061176edf | 17 | |
okano | 0:694061176edf | 18 | #include "mbed.h" |
okano | 0:694061176edf | 19 | |
okano | 0:694061176edf | 20 | class I2cBusDevice { |
okano | 0:694061176edf | 21 | public: |
okano | 0:694061176edf | 22 | |
okano | 0:694061176edf | 23 | I2cBusDevice( I2C *i2c, char dev_address ) { |
okano | 0:694061176edf | 24 | bus = i2c; |
okano | 0:694061176edf | 25 | device = dev_address; |
okano | 0:694061176edf | 26 | } |
okano | 0:694061176edf | 27 | |
okano | 0:694061176edf | 28 | ~I2cBusDevice() { |
okano | 0:694061176edf | 29 | } |
okano | 0:694061176edf | 30 | |
okano | 0:694061176edf | 31 | int write( char *data, int length ) { |
okano | 0:694061176edf | 32 | return ( bus->write( device, data, length) ); |
okano | 0:694061176edf | 33 | } |
okano | 0:694061176edf | 34 | |
okano | 0:694061176edf | 35 | int read( char *data, int length ) { |
okano | 0:694061176edf | 36 | return ( bus->read( device, data, length) ); |
okano | 0:694061176edf | 37 | } |
okano | 0:694061176edf | 38 | |
okano | 0:694061176edf | 39 | int read( char reg_ptr, char *data, int length ) { |
okano | 0:694061176edf | 40 | if ( bus->write( device, ®_ptr, 1 ) ) |
okano | 0:694061176edf | 41 | return ( 1 ); |
okano | 0:694061176edf | 42 | |
okano | 0:694061176edf | 43 | if ( bus->read( device, data, length ) ) |
okano | 0:694061176edf | 44 | return ( 1 ); |
okano | 0:694061176edf | 45 | |
okano | 0:694061176edf | 46 | return ( 0 ); |
okano | 0:694061176edf | 47 | } |
okano | 0:694061176edf | 48 | |
okano | 0:694061176edf | 49 | protected: |
okano | 0:694061176edf | 50 | I2C *bus; |
okano | 0:694061176edf | 51 | char device; |
okano | 0:694061176edf | 52 | |
okano | 0:694061176edf | 53 | private: |
okano | 0:694061176edf | 54 | static char i2c_error; |
okano | 0:694061176edf | 55 | } |
okano | 0:694061176edf | 56 | ; |
okano | 0:694061176edf | 57 | |
okano | 0:694061176edf | 58 | #endif |