Mbed SDK for XRange SX1272 LoRa module
Dependents: XRangePingPong XRange-LoRaWAN-lmic-app lora-transceiver
SX1272 LoRa RF module
https://www.netblocks.eu/xrange-sx1272-lora-datasheet/
common/I2CSlave.cpp@336:1e18a06a987b, 2015-01-15 (annotated)
- Committer:
- dudmuck
- Date:
- Thu Jan 15 02:25:40 2015 +0000
- Revision:
- 336:1e18a06a987b
updated to rev443 of official mbed-src
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dudmuck | 336:1e18a06a987b | 1 | /* mbed Microcontroller Library |
dudmuck | 336:1e18a06a987b | 2 | * Copyright (c) 2006-2013 ARM Limited |
dudmuck | 336:1e18a06a987b | 3 | * |
dudmuck | 336:1e18a06a987b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
dudmuck | 336:1e18a06a987b | 5 | * you may not use this file except in compliance with the License. |
dudmuck | 336:1e18a06a987b | 6 | * You may obtain a copy of the License at |
dudmuck | 336:1e18a06a987b | 7 | * |
dudmuck | 336:1e18a06a987b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
dudmuck | 336:1e18a06a987b | 9 | * |
dudmuck | 336:1e18a06a987b | 10 | * Unless required by applicable law or agreed to in writing, software |
dudmuck | 336:1e18a06a987b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
dudmuck | 336:1e18a06a987b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
dudmuck | 336:1e18a06a987b | 13 | * See the License for the specific language governing permissions and |
dudmuck | 336:1e18a06a987b | 14 | * limitations under the License. |
dudmuck | 336:1e18a06a987b | 15 | */ |
dudmuck | 336:1e18a06a987b | 16 | #include "I2CSlave.h" |
dudmuck | 336:1e18a06a987b | 17 | |
dudmuck | 336:1e18a06a987b | 18 | #if DEVICE_I2CSLAVE |
dudmuck | 336:1e18a06a987b | 19 | |
dudmuck | 336:1e18a06a987b | 20 | namespace mbed { |
dudmuck | 336:1e18a06a987b | 21 | |
dudmuck | 336:1e18a06a987b | 22 | I2CSlave::I2CSlave(PinName sda, PinName scl) : _i2c() { |
dudmuck | 336:1e18a06a987b | 23 | i2c_init(&_i2c, sda, scl); |
dudmuck | 336:1e18a06a987b | 24 | i2c_frequency(&_i2c, 100000); |
dudmuck | 336:1e18a06a987b | 25 | i2c_slave_mode(&_i2c, 1); |
dudmuck | 336:1e18a06a987b | 26 | } |
dudmuck | 336:1e18a06a987b | 27 | |
dudmuck | 336:1e18a06a987b | 28 | void I2CSlave::frequency(int hz) { |
dudmuck | 336:1e18a06a987b | 29 | i2c_frequency(&_i2c, hz); |
dudmuck | 336:1e18a06a987b | 30 | } |
dudmuck | 336:1e18a06a987b | 31 | |
dudmuck | 336:1e18a06a987b | 32 | void I2CSlave::address(int address) { |
dudmuck | 336:1e18a06a987b | 33 | int addr = (address & 0xFF) | 1; |
dudmuck | 336:1e18a06a987b | 34 | i2c_slave_address(&_i2c, 0, addr, 0); |
dudmuck | 336:1e18a06a987b | 35 | } |
dudmuck | 336:1e18a06a987b | 36 | |
dudmuck | 336:1e18a06a987b | 37 | int I2CSlave::receive(void) { |
dudmuck | 336:1e18a06a987b | 38 | return i2c_slave_receive(&_i2c); |
dudmuck | 336:1e18a06a987b | 39 | } |
dudmuck | 336:1e18a06a987b | 40 | |
dudmuck | 336:1e18a06a987b | 41 | int I2CSlave::read(char *data, int length) { |
dudmuck | 336:1e18a06a987b | 42 | return i2c_slave_read(&_i2c, data, length) != length; |
dudmuck | 336:1e18a06a987b | 43 | } |
dudmuck | 336:1e18a06a987b | 44 | |
dudmuck | 336:1e18a06a987b | 45 | int I2CSlave::read(void) { |
dudmuck | 336:1e18a06a987b | 46 | return i2c_byte_read(&_i2c, 0); |
dudmuck | 336:1e18a06a987b | 47 | } |
dudmuck | 336:1e18a06a987b | 48 | |
dudmuck | 336:1e18a06a987b | 49 | int I2CSlave::write(const char *data, int length) { |
dudmuck | 336:1e18a06a987b | 50 | return i2c_slave_write(&_i2c, data, length) != length; |
dudmuck | 336:1e18a06a987b | 51 | } |
dudmuck | 336:1e18a06a987b | 52 | |
dudmuck | 336:1e18a06a987b | 53 | int I2CSlave::write(int data) { |
dudmuck | 336:1e18a06a987b | 54 | return i2c_byte_write(&_i2c, data); |
dudmuck | 336:1e18a06a987b | 55 | } |
dudmuck | 336:1e18a06a987b | 56 | |
dudmuck | 336:1e18a06a987b | 57 | void I2CSlave::stop(void) { |
dudmuck | 336:1e18a06a987b | 58 | i2c_stop(&_i2c); |
dudmuck | 336:1e18a06a987b | 59 | } |
dudmuck | 336:1e18a06a987b | 60 | |
dudmuck | 336:1e18a06a987b | 61 | } |
dudmuck | 336:1e18a06a987b | 62 | |
dudmuck | 336:1e18a06a987b | 63 | #endif |