for_gamma
Dependencies: Gamma Beta Alpha
Dependents: 2017_Bteam_I2CTransporter BETA_A ALPHA_A GAMMA_A
I2CTransporter.cpp@10:702dfdfc914f, 2017-08-30 (annotated)
- Committer:
- Komazawa_sun
- Date:
- Wed Aug 30 05:15:25 2017 +0000
- Revision:
- 10:702dfdfc914f
- Parent:
- 2:da463477713b
data_pools; ;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Komazawa_sun | 2:da463477713b | 1 | #include "I2CTransporter.h" |
Komazawa_sun | 2:da463477713b | 2 | |
Komazawa_sun | 2:da463477713b | 3 | I2CTransporter::I2CTransporter(PinName sda, PinName scl) |
Komazawa_sun | 2:da463477713b | 4 | : _master(sda,scl) |
Komazawa_sun | 2:da463477713b | 5 | { |
Komazawa_sun | 2:da463477713b | 6 | address = 0; |
Komazawa_sun | 2:da463477713b | 7 | target_array = NULL; |
Komazawa_sun | 2:da463477713b | 8 | Transport_Began = false; |
Komazawa_sun | 2:da463477713b | 9 | } |
Komazawa_sun | 2:da463477713b | 10 | |
Komazawa_sun | 2:da463477713b | 11 | void I2CTransporter::transport_begin(int addr_, char *target_array_, int data_size_) |
Komazawa_sun | 2:da463477713b | 12 | { |
Komazawa_sun | 2:da463477713b | 13 | address = addr_ ; |
Komazawa_sun | 2:da463477713b | 14 | target_array = target_array_; |
Komazawa_sun | 2:da463477713b | 15 | data_size = data_size_; |
Komazawa_sun | 2:da463477713b | 16 | Transport_Began = true; |
Komazawa_sun | 2:da463477713b | 17 | } |
Komazawa_sun | 2:da463477713b | 18 | |
Komazawa_sun | 2:da463477713b | 19 | bool I2CTransporter::read() |
Komazawa_sun | 2:da463477713b | 20 | { |
Komazawa_sun | 2:da463477713b | 21 | if(Transport_Began == true) |
Komazawa_sun | 2:da463477713b | 22 | { |
Komazawa_sun | 2:da463477713b | 23 | return _master.read(address, target_array, data_size) == 0 |
Komazawa_sun | 2:da463477713b | 24 | ? true |
Komazawa_sun | 2:da463477713b | 25 | : false; |
Komazawa_sun | 2:da463477713b | 26 | } |
Komazawa_sun | 2:da463477713b | 27 | else |
Komazawa_sun | 2:da463477713b | 28 | { |
Komazawa_sun | 2:da463477713b | 29 | return false; |
Komazawa_sun | 2:da463477713b | 30 | } |
Komazawa_sun | 2:da463477713b | 31 | } |
Komazawa_sun | 2:da463477713b | 32 | |
Komazawa_sun | 2:da463477713b | 33 | bool I2CTransporter::write() |
Komazawa_sun | 2:da463477713b | 34 | { |
Komazawa_sun | 2:da463477713b | 35 | if(Transport_Began == true) |
Komazawa_sun | 2:da463477713b | 36 | { |
Komazawa_sun | 2:da463477713b | 37 | return _master.write(address, target_array, data_size) == 0 |
Komazawa_sun | 2:da463477713b | 38 | ? true |
Komazawa_sun | 2:da463477713b | 39 | : false; |
Komazawa_sun | 2:da463477713b | 40 | } |
Komazawa_sun | 2:da463477713b | 41 | else |
Komazawa_sun | 2:da463477713b | 42 | { |
Komazawa_sun | 2:da463477713b | 43 | return false; |
Komazawa_sun | 2:da463477713b | 44 | } |
Komazawa_sun | 2:da463477713b | 45 | } |
Komazawa_sun | 2:da463477713b | 46 | |
Komazawa_sun | 2:da463477713b | 47 | void I2CTransporter::transport_end() |
Komazawa_sun | 2:da463477713b | 48 | { |
Komazawa_sun | 2:da463477713b | 49 | if(Transport_Began == true) |
Komazawa_sun | 2:da463477713b | 50 | { |
Komazawa_sun | 2:da463477713b | 51 | address = 0; |
Komazawa_sun | 2:da463477713b | 52 | target_array = NULL; |
Komazawa_sun | 2:da463477713b | 53 | data_size = 0; |
Komazawa_sun | 2:da463477713b | 54 | Transport_Began = false; |
Komazawa_sun | 2:da463477713b | 55 | } |
Komazawa_sun | 2:da463477713b | 56 | else |
Komazawa_sun | 2:da463477713b | 57 | { |
Komazawa_sun | 2:da463477713b | 58 | } |
Komazawa_sun | 2:da463477713b | 59 | } |