Integrating the ublox LISA C200 modem
Fork of SprintUSBModemHTTPClientTest by
mbed-src/common/I2C.cpp@5:3f93dd1d4cb3, 2013-09-26 (annotated)
- Committer:
- sam_grove
- Date:
- Thu Sep 26 00:44:20 2013 -0500
- Revision:
- 5:3f93dd1d4cb3
Exported program and replaced contents of the repo with the source
to build and debug using keil mdk. Libs NOT upto date are lwip, lwip-sys
and socket. these have newer versions under mbed_official but were starting
from a know working point
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove | 5:3f93dd1d4cb3 | 1 | /* mbed Microcontroller Library |
sam_grove | 5:3f93dd1d4cb3 | 2 | * Copyright (c) 2006-2013 ARM Limited |
sam_grove | 5:3f93dd1d4cb3 | 3 | * |
sam_grove | 5:3f93dd1d4cb3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sam_grove | 5:3f93dd1d4cb3 | 5 | * you may not use this file except in compliance with the License. |
sam_grove | 5:3f93dd1d4cb3 | 6 | * You may obtain a copy of the License at |
sam_grove | 5:3f93dd1d4cb3 | 7 | * |
sam_grove | 5:3f93dd1d4cb3 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
sam_grove | 5:3f93dd1d4cb3 | 9 | * |
sam_grove | 5:3f93dd1d4cb3 | 10 | * Unless required by applicable law or agreed to in writing, software |
sam_grove | 5:3f93dd1d4cb3 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
sam_grove | 5:3f93dd1d4cb3 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sam_grove | 5:3f93dd1d4cb3 | 13 | * See the License for the specific language governing permissions and |
sam_grove | 5:3f93dd1d4cb3 | 14 | * limitations under the License. |
sam_grove | 5:3f93dd1d4cb3 | 15 | */ |
sam_grove | 5:3f93dd1d4cb3 | 16 | #include "I2C.h" |
sam_grove | 5:3f93dd1d4cb3 | 17 | |
sam_grove | 5:3f93dd1d4cb3 | 18 | #if DEVICE_I2C |
sam_grove | 5:3f93dd1d4cb3 | 19 | |
sam_grove | 5:3f93dd1d4cb3 | 20 | namespace mbed { |
sam_grove | 5:3f93dd1d4cb3 | 21 | |
sam_grove | 5:3f93dd1d4cb3 | 22 | I2C *I2C::_owner = NULL; |
sam_grove | 5:3f93dd1d4cb3 | 23 | |
sam_grove | 5:3f93dd1d4cb3 | 24 | I2C::I2C(PinName sda, PinName scl) { |
sam_grove | 5:3f93dd1d4cb3 | 25 | // The init function also set the frequency to 100000 |
sam_grove | 5:3f93dd1d4cb3 | 26 | i2c_init(&_i2c, sda, scl); |
sam_grove | 5:3f93dd1d4cb3 | 27 | _hz = 100000; |
sam_grove | 5:3f93dd1d4cb3 | 28 | |
sam_grove | 5:3f93dd1d4cb3 | 29 | // Used to avoid unnecessary frequency updates |
sam_grove | 5:3f93dd1d4cb3 | 30 | _owner = this; |
sam_grove | 5:3f93dd1d4cb3 | 31 | } |
sam_grove | 5:3f93dd1d4cb3 | 32 | |
sam_grove | 5:3f93dd1d4cb3 | 33 | void I2C::frequency(int hz) { |
sam_grove | 5:3f93dd1d4cb3 | 34 | _hz = hz; |
sam_grove | 5:3f93dd1d4cb3 | 35 | |
sam_grove | 5:3f93dd1d4cb3 | 36 | // We want to update the frequency even if we are already the bus owners |
sam_grove | 5:3f93dd1d4cb3 | 37 | i2c_frequency(&_i2c, _hz); |
sam_grove | 5:3f93dd1d4cb3 | 38 | |
sam_grove | 5:3f93dd1d4cb3 | 39 | // Updating the frequency of the bus we become the owners of it |
sam_grove | 5:3f93dd1d4cb3 | 40 | _owner = this; |
sam_grove | 5:3f93dd1d4cb3 | 41 | } |
sam_grove | 5:3f93dd1d4cb3 | 42 | |
sam_grove | 5:3f93dd1d4cb3 | 43 | void I2C::aquire() { |
sam_grove | 5:3f93dd1d4cb3 | 44 | if (_owner != this) { |
sam_grove | 5:3f93dd1d4cb3 | 45 | i2c_frequency(&_i2c, _hz); |
sam_grove | 5:3f93dd1d4cb3 | 46 | _owner = this; |
sam_grove | 5:3f93dd1d4cb3 | 47 | } |
sam_grove | 5:3f93dd1d4cb3 | 48 | } |
sam_grove | 5:3f93dd1d4cb3 | 49 | |
sam_grove | 5:3f93dd1d4cb3 | 50 | // write - Master Transmitter Mode |
sam_grove | 5:3f93dd1d4cb3 | 51 | int I2C::write(int address, const char* data, int length, bool repeated) { |
sam_grove | 5:3f93dd1d4cb3 | 52 | aquire(); |
sam_grove | 5:3f93dd1d4cb3 | 53 | |
sam_grove | 5:3f93dd1d4cb3 | 54 | int stop = (repeated) ? 0 : 1; |
sam_grove | 5:3f93dd1d4cb3 | 55 | int written = i2c_write(&_i2c, address, data, length, stop); |
sam_grove | 5:3f93dd1d4cb3 | 56 | |
sam_grove | 5:3f93dd1d4cb3 | 57 | return length != written; |
sam_grove | 5:3f93dd1d4cb3 | 58 | } |
sam_grove | 5:3f93dd1d4cb3 | 59 | |
sam_grove | 5:3f93dd1d4cb3 | 60 | int I2C::write(int data) { |
sam_grove | 5:3f93dd1d4cb3 | 61 | return i2c_byte_write(&_i2c, data); |
sam_grove | 5:3f93dd1d4cb3 | 62 | } |
sam_grove | 5:3f93dd1d4cb3 | 63 | |
sam_grove | 5:3f93dd1d4cb3 | 64 | // read - Master Reciever Mode |
sam_grove | 5:3f93dd1d4cb3 | 65 | int I2C::read(int address, char* data, int length, bool repeated) { |
sam_grove | 5:3f93dd1d4cb3 | 66 | aquire(); |
sam_grove | 5:3f93dd1d4cb3 | 67 | |
sam_grove | 5:3f93dd1d4cb3 | 68 | int stop = (repeated) ? 0 : 1; |
sam_grove | 5:3f93dd1d4cb3 | 69 | int read = i2c_read(&_i2c, address, data, length, stop); |
sam_grove | 5:3f93dd1d4cb3 | 70 | |
sam_grove | 5:3f93dd1d4cb3 | 71 | return length != read; |
sam_grove | 5:3f93dd1d4cb3 | 72 | } |
sam_grove | 5:3f93dd1d4cb3 | 73 | |
sam_grove | 5:3f93dd1d4cb3 | 74 | int I2C::read(int ack) { |
sam_grove | 5:3f93dd1d4cb3 | 75 | if (ack) { |
sam_grove | 5:3f93dd1d4cb3 | 76 | return i2c_byte_read(&_i2c, 0); |
sam_grove | 5:3f93dd1d4cb3 | 77 | } else { |
sam_grove | 5:3f93dd1d4cb3 | 78 | return i2c_byte_read(&_i2c, 1); |
sam_grove | 5:3f93dd1d4cb3 | 79 | } |
sam_grove | 5:3f93dd1d4cb3 | 80 | } |
sam_grove | 5:3f93dd1d4cb3 | 81 | |
sam_grove | 5:3f93dd1d4cb3 | 82 | void I2C::start(void) { |
sam_grove | 5:3f93dd1d4cb3 | 83 | i2c_start(&_i2c); |
sam_grove | 5:3f93dd1d4cb3 | 84 | } |
sam_grove | 5:3f93dd1d4cb3 | 85 | |
sam_grove | 5:3f93dd1d4cb3 | 86 | void I2C::stop(void) { |
sam_grove | 5:3f93dd1d4cb3 | 87 | i2c_stop(&_i2c); |
sam_grove | 5:3f93dd1d4cb3 | 88 | } |
sam_grove | 5:3f93dd1d4cb3 | 89 | |
sam_grove | 5:3f93dd1d4cb3 | 90 | } // namespace mbed |
sam_grove | 5:3f93dd1d4cb3 | 91 | |
sam_grove | 5:3f93dd1d4cb3 | 92 | #endif |