Tried to initialize the buttons and slider but couldn't get it to work.

Dependencies:   mbed

Committer:
mturner5
Date:
Mon Sep 19 03:28:41 2016 +0000
Revision:
0:0d6b77c9ae01
basic v2;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mturner5 0:0d6b77c9ae01 1 /* mbed Microcontroller Library
mturner5 0:0d6b77c9ae01 2 * Copyright (c) 2006-2013 ARM Limited
mturner5 0:0d6b77c9ae01 3 *
mturner5 0:0d6b77c9ae01 4 * Licensed under the Apache License, Version 2.0 (the "License");
mturner5 0:0d6b77c9ae01 5 * you may not use this file except in compliance with the License.
mturner5 0:0d6b77c9ae01 6 * You may obtain a copy of the License at
mturner5 0:0d6b77c9ae01 7 *
mturner5 0:0d6b77c9ae01 8 * http://www.apache.org/licenses/LICENSE-2.0
mturner5 0:0d6b77c9ae01 9 *
mturner5 0:0d6b77c9ae01 10 * Unless required by applicable law or agreed to in writing, software
mturner5 0:0d6b77c9ae01 11 * distributed under the License is distributed on an "AS IS" BASIS,
mturner5 0:0d6b77c9ae01 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mturner5 0:0d6b77c9ae01 13 * See the License for the specific language governing permissions and
mturner5 0:0d6b77c9ae01 14 * limitations under the License.
mturner5 0:0d6b77c9ae01 15 */
mturner5 0:0d6b77c9ae01 16 #ifndef MBED_I2C_H
mturner5 0:0d6b77c9ae01 17 #define MBED_I2C_H
mturner5 0:0d6b77c9ae01 18
mturner5 0:0d6b77c9ae01 19 #include "platform.h"
mturner5 0:0d6b77c9ae01 20
mturner5 0:0d6b77c9ae01 21 #if DEVICE_I2C
mturner5 0:0d6b77c9ae01 22
mturner5 0:0d6b77c9ae01 23 #include "i2c_api.h"
mturner5 0:0d6b77c9ae01 24
mturner5 0:0d6b77c9ae01 25 namespace mbed {
mturner5 0:0d6b77c9ae01 26
mturner5 0:0d6b77c9ae01 27 /** An I2C Master, used for communicating with I2C slave devices
mturner5 0:0d6b77c9ae01 28 *
mturner5 0:0d6b77c9ae01 29 * Example:
mturner5 0:0d6b77c9ae01 30 * @code
mturner5 0:0d6b77c9ae01 31 * // Read from I2C slave at address 0x62
mturner5 0:0d6b77c9ae01 32 *
mturner5 0:0d6b77c9ae01 33 * #include "mbed.h"
mturner5 0:0d6b77c9ae01 34 *
mturner5 0:0d6b77c9ae01 35 * I2C i2c(p28, p27);
mturner5 0:0d6b77c9ae01 36 *
mturner5 0:0d6b77c9ae01 37 * int main() {
mturner5 0:0d6b77c9ae01 38 * int address = 0x62;
mturner5 0:0d6b77c9ae01 39 * char data[2];
mturner5 0:0d6b77c9ae01 40 * i2c.read(address, data, 2);
mturner5 0:0d6b77c9ae01 41 * }
mturner5 0:0d6b77c9ae01 42 * @endcode
mturner5 0:0d6b77c9ae01 43 */
mturner5 0:0d6b77c9ae01 44 class I2C {
mturner5 0:0d6b77c9ae01 45
mturner5 0:0d6b77c9ae01 46 public:
mturner5 0:0d6b77c9ae01 47 enum RxStatus {
mturner5 0:0d6b77c9ae01 48 NoData,
mturner5 0:0d6b77c9ae01 49 MasterGeneralCall,
mturner5 0:0d6b77c9ae01 50 MasterWrite,
mturner5 0:0d6b77c9ae01 51 MasterRead
mturner5 0:0d6b77c9ae01 52 };
mturner5 0:0d6b77c9ae01 53
mturner5 0:0d6b77c9ae01 54 enum Acknowledge {
mturner5 0:0d6b77c9ae01 55 NoACK = 0,
mturner5 0:0d6b77c9ae01 56 ACK = 1
mturner5 0:0d6b77c9ae01 57 };
mturner5 0:0d6b77c9ae01 58
mturner5 0:0d6b77c9ae01 59 /** Create an I2C Master interface, connected to the specified pins
mturner5 0:0d6b77c9ae01 60 *
mturner5 0:0d6b77c9ae01 61 * @param sda I2C data line pin
mturner5 0:0d6b77c9ae01 62 * @param scl I2C clock line pin
mturner5 0:0d6b77c9ae01 63 */
mturner5 0:0d6b77c9ae01 64 I2C(PinName sda, PinName scl);
mturner5 0:0d6b77c9ae01 65
mturner5 0:0d6b77c9ae01 66 /** Set the frequency of the I2C interface
mturner5 0:0d6b77c9ae01 67 *
mturner5 0:0d6b77c9ae01 68 * @param hz The bus frequency in hertz
mturner5 0:0d6b77c9ae01 69 */
mturner5 0:0d6b77c9ae01 70 void frequency(int hz);
mturner5 0:0d6b77c9ae01 71
mturner5 0:0d6b77c9ae01 72 /** Read from an I2C slave
mturner5 0:0d6b77c9ae01 73 *
mturner5 0:0d6b77c9ae01 74 * Performs a complete read transaction. The bottom bit of
mturner5 0:0d6b77c9ae01 75 * the address is forced to 1 to indicate a read.
mturner5 0:0d6b77c9ae01 76 *
mturner5 0:0d6b77c9ae01 77 * @param address 8-bit I2C slave address [ addr | 1 ]
mturner5 0:0d6b77c9ae01 78 * @param data Pointer to the byte-array to read data in to
mturner5 0:0d6b77c9ae01 79 * @param length Number of bytes to read
mturner5 0:0d6b77c9ae01 80 * @param repeated Repeated start, true - don't send stop at end
mturner5 0:0d6b77c9ae01 81 *
mturner5 0:0d6b77c9ae01 82 * @returns
mturner5 0:0d6b77c9ae01 83 * 0 on success (ack),
mturner5 0:0d6b77c9ae01 84 * non-0 on failure (nack)
mturner5 0:0d6b77c9ae01 85 */
mturner5 0:0d6b77c9ae01 86 int read(int address, char *data, int length, bool repeated = false);
mturner5 0:0d6b77c9ae01 87
mturner5 0:0d6b77c9ae01 88 /** Read a single byte from the I2C bus
mturner5 0:0d6b77c9ae01 89 *
mturner5 0:0d6b77c9ae01 90 * @param ack indicates if the byte is to be acknowledged (1 = acknowledge)
mturner5 0:0d6b77c9ae01 91 *
mturner5 0:0d6b77c9ae01 92 * @returns
mturner5 0:0d6b77c9ae01 93 * the byte read
mturner5 0:0d6b77c9ae01 94 */
mturner5 0:0d6b77c9ae01 95 int read(int ack);
mturner5 0:0d6b77c9ae01 96
mturner5 0:0d6b77c9ae01 97 /** Write to an I2C slave
mturner5 0:0d6b77c9ae01 98 *
mturner5 0:0d6b77c9ae01 99 * Performs a complete write transaction. The bottom bit of
mturner5 0:0d6b77c9ae01 100 * the address is forced to 0 to indicate a write.
mturner5 0:0d6b77c9ae01 101 *
mturner5 0:0d6b77c9ae01 102 * @param address 8-bit I2C slave address [ addr | 0 ]
mturner5 0:0d6b77c9ae01 103 * @param data Pointer to the byte-array data to send
mturner5 0:0d6b77c9ae01 104 * @param length Number of bytes to send
mturner5 0:0d6b77c9ae01 105 * @param repeated Repeated start, true - do not send stop at end
mturner5 0:0d6b77c9ae01 106 *
mturner5 0:0d6b77c9ae01 107 * @returns
mturner5 0:0d6b77c9ae01 108 * 0 on success (ack),
mturner5 0:0d6b77c9ae01 109 * non-0 on failure (nack)
mturner5 0:0d6b77c9ae01 110 */
mturner5 0:0d6b77c9ae01 111 int write(int address, const char *data, int length, bool repeated = false);
mturner5 0:0d6b77c9ae01 112
mturner5 0:0d6b77c9ae01 113 /** Write single byte out on the I2C bus
mturner5 0:0d6b77c9ae01 114 *
mturner5 0:0d6b77c9ae01 115 * @param data data to write out on bus
mturner5 0:0d6b77c9ae01 116 *
mturner5 0:0d6b77c9ae01 117 * @returns
mturner5 0:0d6b77c9ae01 118 * '1' if an ACK was received,
mturner5 0:0d6b77c9ae01 119 * '0' otherwise
mturner5 0:0d6b77c9ae01 120 */
mturner5 0:0d6b77c9ae01 121 int write(int data);
mturner5 0:0d6b77c9ae01 122
mturner5 0:0d6b77c9ae01 123 /** Creates a start condition on the I2C bus
mturner5 0:0d6b77c9ae01 124 */
mturner5 0:0d6b77c9ae01 125
mturner5 0:0d6b77c9ae01 126 void start(void);
mturner5 0:0d6b77c9ae01 127
mturner5 0:0d6b77c9ae01 128 /** Creates a stop condition on the I2C bus
mturner5 0:0d6b77c9ae01 129 */
mturner5 0:0d6b77c9ae01 130 void stop(void);
mturner5 0:0d6b77c9ae01 131
mturner5 0:0d6b77c9ae01 132 protected:
mturner5 0:0d6b77c9ae01 133 void aquire();
mturner5 0:0d6b77c9ae01 134
mturner5 0:0d6b77c9ae01 135 i2c_t _i2c;
mturner5 0:0d6b77c9ae01 136 static I2C *_owner;
mturner5 0:0d6b77c9ae01 137 int _hz;
mturner5 0:0d6b77c9ae01 138 };
mturner5 0:0d6b77c9ae01 139
mturner5 0:0d6b77c9ae01 140 } // namespace mbed
mturner5 0:0d6b77c9ae01 141
mturner5 0:0d6b77c9ae01 142 #endif
mturner5 0:0d6b77c9ae01 143
mturner5 0:0d6b77c9ae01 144 #endif