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_SLAVE_H
mturner5 0:0d6b77c9ae01 17 #define MBED_I2C_SLAVE_H
mturner5 0:0d6b77c9ae01 18
mturner5 0:0d6b77c9ae01 19 #include "platform.h"
mturner5 0:0d6b77c9ae01 20
mturner5 0:0d6b77c9ae01 21 #if DEVICE_I2CSLAVE
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 Slave, used for communicating with an I2C Master device
mturner5 0:0d6b77c9ae01 28 *
mturner5 0:0d6b77c9ae01 29 * Example:
mturner5 0:0d6b77c9ae01 30 * @code
mturner5 0:0d6b77c9ae01 31 * // Simple I2C responder
mturner5 0:0d6b77c9ae01 32 * #include <mbed.h>
mturner5 0:0d6b77c9ae01 33 *
mturner5 0:0d6b77c9ae01 34 * I2CSlave slave(p9, p10);
mturner5 0:0d6b77c9ae01 35 *
mturner5 0:0d6b77c9ae01 36 * int main() {
mturner5 0:0d6b77c9ae01 37 * char buf[10];
mturner5 0:0d6b77c9ae01 38 * char msg[] = "Slave!";
mturner5 0:0d6b77c9ae01 39 *
mturner5 0:0d6b77c9ae01 40 * slave.address(0xA0);
mturner5 0:0d6b77c9ae01 41 * while (1) {
mturner5 0:0d6b77c9ae01 42 * int i = slave.receive();
mturner5 0:0d6b77c9ae01 43 * switch (i) {
mturner5 0:0d6b77c9ae01 44 * case I2CSlave::ReadAddressed:
mturner5 0:0d6b77c9ae01 45 * slave.write(msg, strlen(msg) + 1); // Includes null char
mturner5 0:0d6b77c9ae01 46 * break;
mturner5 0:0d6b77c9ae01 47 * case I2CSlave::WriteGeneral:
mturner5 0:0d6b77c9ae01 48 * slave.read(buf, 10);
mturner5 0:0d6b77c9ae01 49 * printf("Read G: %s\n", buf);
mturner5 0:0d6b77c9ae01 50 * break;
mturner5 0:0d6b77c9ae01 51 * case I2CSlave::WriteAddressed:
mturner5 0:0d6b77c9ae01 52 * slave.read(buf, 10);
mturner5 0:0d6b77c9ae01 53 * printf("Read A: %s\n", buf);
mturner5 0:0d6b77c9ae01 54 * break;
mturner5 0:0d6b77c9ae01 55 * }
mturner5 0:0d6b77c9ae01 56 * for(int i = 0; i < 10; i++) buf[i] = 0; // Clear buffer
mturner5 0:0d6b77c9ae01 57 * }
mturner5 0:0d6b77c9ae01 58 * }
mturner5 0:0d6b77c9ae01 59 * @endcode
mturner5 0:0d6b77c9ae01 60 */
mturner5 0:0d6b77c9ae01 61 class I2CSlave {
mturner5 0:0d6b77c9ae01 62
mturner5 0:0d6b77c9ae01 63 public:
mturner5 0:0d6b77c9ae01 64 enum RxStatus {
mturner5 0:0d6b77c9ae01 65 NoData = 0,
mturner5 0:0d6b77c9ae01 66 ReadAddressed = 1,
mturner5 0:0d6b77c9ae01 67 WriteGeneral = 2,
mturner5 0:0d6b77c9ae01 68 WriteAddressed = 3
mturner5 0:0d6b77c9ae01 69 };
mturner5 0:0d6b77c9ae01 70
mturner5 0:0d6b77c9ae01 71 /** Create an I2C Slave interface, connected to the specified pins.
mturner5 0:0d6b77c9ae01 72 *
mturner5 0:0d6b77c9ae01 73 * @param sda I2C data line pin
mturner5 0:0d6b77c9ae01 74 * @param scl I2C clock line pin
mturner5 0:0d6b77c9ae01 75 */
mturner5 0:0d6b77c9ae01 76 I2CSlave(PinName sda, PinName scl);
mturner5 0:0d6b77c9ae01 77
mturner5 0:0d6b77c9ae01 78 /** Set the frequency of the I2C interface
mturner5 0:0d6b77c9ae01 79 *
mturner5 0:0d6b77c9ae01 80 * @param hz The bus frequency in hertz
mturner5 0:0d6b77c9ae01 81 */
mturner5 0:0d6b77c9ae01 82 void frequency(int hz);
mturner5 0:0d6b77c9ae01 83
mturner5 0:0d6b77c9ae01 84 /** Checks to see if this I2C Slave has been addressed.
mturner5 0:0d6b77c9ae01 85 *
mturner5 0:0d6b77c9ae01 86 * @returns
mturner5 0:0d6b77c9ae01 87 * A status indicating if the device has been addressed, and how
mturner5 0:0d6b77c9ae01 88 * - NoData - the slave has not been addressed
mturner5 0:0d6b77c9ae01 89 * - ReadAddressed - the master has requested a read from this slave
mturner5 0:0d6b77c9ae01 90 * - WriteAddressed - the master is writing to this slave
mturner5 0:0d6b77c9ae01 91 * - WriteGeneral - the master is writing to all slave
mturner5 0:0d6b77c9ae01 92 */
mturner5 0:0d6b77c9ae01 93 int receive(void);
mturner5 0:0d6b77c9ae01 94
mturner5 0:0d6b77c9ae01 95 /** Read from an I2C master.
mturner5 0:0d6b77c9ae01 96 *
mturner5 0:0d6b77c9ae01 97 * @param data pointer to the byte array to read data in to
mturner5 0:0d6b77c9ae01 98 * @param length maximum number of bytes to read
mturner5 0:0d6b77c9ae01 99 *
mturner5 0:0d6b77c9ae01 100 * @returns
mturner5 0:0d6b77c9ae01 101 * 0 on success,
mturner5 0:0d6b77c9ae01 102 * non-0 otherwise
mturner5 0:0d6b77c9ae01 103 */
mturner5 0:0d6b77c9ae01 104 int read(char *data, int length);
mturner5 0:0d6b77c9ae01 105
mturner5 0:0d6b77c9ae01 106 /** Read a single byte from an I2C master.
mturner5 0:0d6b77c9ae01 107 *
mturner5 0:0d6b77c9ae01 108 * @returns
mturner5 0:0d6b77c9ae01 109 * the byte read
mturner5 0:0d6b77c9ae01 110 */
mturner5 0:0d6b77c9ae01 111 int read(void);
mturner5 0:0d6b77c9ae01 112
mturner5 0:0d6b77c9ae01 113 /** Write to an I2C master.
mturner5 0:0d6b77c9ae01 114 *
mturner5 0:0d6b77c9ae01 115 * @param data pointer to the byte array to be transmitted
mturner5 0:0d6b77c9ae01 116 * @param length the number of bytes to transmite
mturner5 0:0d6b77c9ae01 117 *
mturner5 0:0d6b77c9ae01 118 * @returns
mturner5 0:0d6b77c9ae01 119 * 0 on success,
mturner5 0:0d6b77c9ae01 120 * non-0 otherwise
mturner5 0:0d6b77c9ae01 121 */
mturner5 0:0d6b77c9ae01 122 int write(const char *data, int length);
mturner5 0:0d6b77c9ae01 123
mturner5 0:0d6b77c9ae01 124 /** Write a single byte to an I2C master.
mturner5 0:0d6b77c9ae01 125 *
mturner5 0:0d6b77c9ae01 126 * @data the byte to write
mturner5 0:0d6b77c9ae01 127 *
mturner5 0:0d6b77c9ae01 128 * @returns
mturner5 0:0d6b77c9ae01 129 * '1' if an ACK was received,
mturner5 0:0d6b77c9ae01 130 * '0' otherwise
mturner5 0:0d6b77c9ae01 131 */
mturner5 0:0d6b77c9ae01 132 int write(int data);
mturner5 0:0d6b77c9ae01 133
mturner5 0:0d6b77c9ae01 134 /** Sets the I2C slave address.
mturner5 0:0d6b77c9ae01 135 *
mturner5 0:0d6b77c9ae01 136 * @param address The address to set for the slave (ignoring the least
mturner5 0:0d6b77c9ae01 137 * signifcant bit). If set to 0, the slave will only respond to the
mturner5 0:0d6b77c9ae01 138 * general call address.
mturner5 0:0d6b77c9ae01 139 */
mturner5 0:0d6b77c9ae01 140 void address(int address);
mturner5 0:0d6b77c9ae01 141
mturner5 0:0d6b77c9ae01 142 /** Reset the I2C slave back into the known ready receiving state.
mturner5 0:0d6b77c9ae01 143 */
mturner5 0:0d6b77c9ae01 144 void stop(void);
mturner5 0:0d6b77c9ae01 145
mturner5 0:0d6b77c9ae01 146 protected:
mturner5 0:0d6b77c9ae01 147 i2c_t _i2c;
mturner5 0:0d6b77c9ae01 148 };
mturner5 0:0d6b77c9ae01 149
mturner5 0:0d6b77c9ae01 150 } // namespace mbed
mturner5 0:0d6b77c9ae01 151
mturner5 0:0d6b77c9ae01 152 #endif
mturner5 0:0d6b77c9ae01 153
mturner5 0:0d6b77c9ae01 154 #endif