Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:5c4d7b2438d3 1 /* mbed Microcontroller Library
switches 0:5c4d7b2438d3 2 * Copyright (c) 2006-2013 ARM Limited
switches 0:5c4d7b2438d3 3 *
switches 0:5c4d7b2438d3 4 * Licensed under the Apache License, Version 2.0 (the "License");
switches 0:5c4d7b2438d3 5 * you may not use this file except in compliance with the License.
switches 0:5c4d7b2438d3 6 * You may obtain a copy of the License at
switches 0:5c4d7b2438d3 7 *
switches 0:5c4d7b2438d3 8 * http://www.apache.org/licenses/LICENSE-2.0
switches 0:5c4d7b2438d3 9 *
switches 0:5c4d7b2438d3 10 * Unless required by applicable law or agreed to in writing, software
switches 0:5c4d7b2438d3 11 * distributed under the License is distributed on an "AS IS" BASIS,
switches 0:5c4d7b2438d3 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
switches 0:5c4d7b2438d3 13 * See the License for the specific language governing permissions and
switches 0:5c4d7b2438d3 14 * limitations under the License.
switches 0:5c4d7b2438d3 15 */
switches 0:5c4d7b2438d3 16 #ifndef MBED_I2C_SLAVE_H
switches 0:5c4d7b2438d3 17 #define MBED_I2C_SLAVE_H
switches 0:5c4d7b2438d3 18
switches 0:5c4d7b2438d3 19 #include "platform/platform.h"
switches 0:5c4d7b2438d3 20
switches 0:5c4d7b2438d3 21 #if DEVICE_I2CSLAVE
switches 0:5c4d7b2438d3 22
switches 0:5c4d7b2438d3 23 #include "hal/i2c_api.h"
switches 0:5c4d7b2438d3 24
switches 0:5c4d7b2438d3 25 namespace mbed {
switches 0:5c4d7b2438d3 26 /** \addtogroup drivers */
switches 0:5c4d7b2438d3 27 /** @{*/
switches 0:5c4d7b2438d3 28
switches 0:5c4d7b2438d3 29 /** An I2C Slave, used for communicating with an I2C Master device
switches 0:5c4d7b2438d3 30 *
switches 0:5c4d7b2438d3 31 * @Note Synchronization level: Not protected
switches 0:5c4d7b2438d3 32 *
switches 0:5c4d7b2438d3 33 * Example:
switches 0:5c4d7b2438d3 34 * @code
switches 0:5c4d7b2438d3 35 * // Simple I2C responder
switches 0:5c4d7b2438d3 36 * #include <mbed.h>
switches 0:5c4d7b2438d3 37 *
switches 0:5c4d7b2438d3 38 * I2CSlave slave(p9, p10);
switches 0:5c4d7b2438d3 39 *
switches 0:5c4d7b2438d3 40 * int main() {
switches 0:5c4d7b2438d3 41 * char buf[10];
switches 0:5c4d7b2438d3 42 * char msg[] = "Slave!";
switches 0:5c4d7b2438d3 43 *
switches 0:5c4d7b2438d3 44 * slave.address(0xA0);
switches 0:5c4d7b2438d3 45 * while (1) {
switches 0:5c4d7b2438d3 46 * int i = slave.receive();
switches 0:5c4d7b2438d3 47 * switch (i) {
switches 0:5c4d7b2438d3 48 * case I2CSlave::ReadAddressed:
switches 0:5c4d7b2438d3 49 * slave.write(msg, strlen(msg) + 1); // Includes null char
switches 0:5c4d7b2438d3 50 * break;
switches 0:5c4d7b2438d3 51 * case I2CSlave::WriteGeneral:
switches 0:5c4d7b2438d3 52 * slave.read(buf, 10);
switches 0:5c4d7b2438d3 53 * printf("Read G: %s\n", buf);
switches 0:5c4d7b2438d3 54 * break;
switches 0:5c4d7b2438d3 55 * case I2CSlave::WriteAddressed:
switches 0:5c4d7b2438d3 56 * slave.read(buf, 10);
switches 0:5c4d7b2438d3 57 * printf("Read A: %s\n", buf);
switches 0:5c4d7b2438d3 58 * break;
switches 0:5c4d7b2438d3 59 * }
switches 0:5c4d7b2438d3 60 * for(int i = 0; i < 10; i++) buf[i] = 0; // Clear buffer
switches 0:5c4d7b2438d3 61 * }
switches 0:5c4d7b2438d3 62 * }
switches 0:5c4d7b2438d3 63 * @endcode
switches 0:5c4d7b2438d3 64 */
switches 0:5c4d7b2438d3 65 class I2CSlave {
switches 0:5c4d7b2438d3 66
switches 0:5c4d7b2438d3 67 public:
switches 0:5c4d7b2438d3 68 enum RxStatus {
switches 0:5c4d7b2438d3 69 NoData = 0,
switches 0:5c4d7b2438d3 70 ReadAddressed = 1,
switches 0:5c4d7b2438d3 71 WriteGeneral = 2,
switches 0:5c4d7b2438d3 72 WriteAddressed = 3
switches 0:5c4d7b2438d3 73 };
switches 0:5c4d7b2438d3 74
switches 0:5c4d7b2438d3 75 /** Create an I2C Slave interface, connected to the specified pins.
switches 0:5c4d7b2438d3 76 *
switches 0:5c4d7b2438d3 77 * @param sda I2C data line pin
switches 0:5c4d7b2438d3 78 * @param scl I2C clock line pin
switches 0:5c4d7b2438d3 79 */
switches 0:5c4d7b2438d3 80 I2CSlave(PinName sda, PinName scl);
switches 0:5c4d7b2438d3 81
switches 0:5c4d7b2438d3 82 /** Set the frequency of the I2C interface
switches 0:5c4d7b2438d3 83 *
switches 0:5c4d7b2438d3 84 * @param hz The bus frequency in hertz
switches 0:5c4d7b2438d3 85 */
switches 0:5c4d7b2438d3 86 void frequency(int hz);
switches 0:5c4d7b2438d3 87
switches 0:5c4d7b2438d3 88 /** Checks to see if this I2C Slave has been addressed.
switches 0:5c4d7b2438d3 89 *
switches 0:5c4d7b2438d3 90 * @returns
switches 0:5c4d7b2438d3 91 * A status indicating if the device has been addressed, and how
switches 0:5c4d7b2438d3 92 * - NoData - the slave has not been addressed
switches 0:5c4d7b2438d3 93 * - ReadAddressed - the master has requested a read from this slave
switches 0:5c4d7b2438d3 94 * - WriteAddressed - the master is writing to this slave
switches 0:5c4d7b2438d3 95 * - WriteGeneral - the master is writing to all slave
switches 0:5c4d7b2438d3 96 */
switches 0:5c4d7b2438d3 97 int receive(void);
switches 0:5c4d7b2438d3 98
switches 0:5c4d7b2438d3 99 /** Read from an I2C master.
switches 0:5c4d7b2438d3 100 *
switches 0:5c4d7b2438d3 101 * @param data pointer to the byte array to read data in to
switches 0:5c4d7b2438d3 102 * @param length maximum number of bytes to read
switches 0:5c4d7b2438d3 103 *
switches 0:5c4d7b2438d3 104 * @returns
switches 0:5c4d7b2438d3 105 * 0 on success,
switches 0:5c4d7b2438d3 106 * non-0 otherwise
switches 0:5c4d7b2438d3 107 */
switches 0:5c4d7b2438d3 108 int read(char *data, int length);
switches 0:5c4d7b2438d3 109
switches 0:5c4d7b2438d3 110 /** Read a single byte from an I2C master.
switches 0:5c4d7b2438d3 111 *
switches 0:5c4d7b2438d3 112 * @returns
switches 0:5c4d7b2438d3 113 * the byte read
switches 0:5c4d7b2438d3 114 */
switches 0:5c4d7b2438d3 115 int read(void);
switches 0:5c4d7b2438d3 116
switches 0:5c4d7b2438d3 117 /** Write to an I2C master.
switches 0:5c4d7b2438d3 118 *
switches 0:5c4d7b2438d3 119 * @param data pointer to the byte array to be transmitted
switches 0:5c4d7b2438d3 120 * @param length the number of bytes to transmite
switches 0:5c4d7b2438d3 121 *
switches 0:5c4d7b2438d3 122 * @returns
switches 0:5c4d7b2438d3 123 * 0 on success,
switches 0:5c4d7b2438d3 124 * non-0 otherwise
switches 0:5c4d7b2438d3 125 */
switches 0:5c4d7b2438d3 126 int write(const char *data, int length);
switches 0:5c4d7b2438d3 127
switches 0:5c4d7b2438d3 128 /** Write a single byte to an I2C master.
switches 0:5c4d7b2438d3 129 *
switches 0:5c4d7b2438d3 130 * @data the byte to write
switches 0:5c4d7b2438d3 131 *
switches 0:5c4d7b2438d3 132 * @returns
switches 0:5c4d7b2438d3 133 * '1' if an ACK was received,
switches 0:5c4d7b2438d3 134 * '0' otherwise
switches 0:5c4d7b2438d3 135 */
switches 0:5c4d7b2438d3 136 int write(int data);
switches 0:5c4d7b2438d3 137
switches 0:5c4d7b2438d3 138 /** Sets the I2C slave address.
switches 0:5c4d7b2438d3 139 *
switches 0:5c4d7b2438d3 140 * @param address The address to set for the slave (ignoring the least
switches 0:5c4d7b2438d3 141 * signifcant bit). If set to 0, the slave will only respond to the
switches 0:5c4d7b2438d3 142 * general call address.
switches 0:5c4d7b2438d3 143 */
switches 0:5c4d7b2438d3 144 void address(int address);
switches 0:5c4d7b2438d3 145
switches 0:5c4d7b2438d3 146 /** Reset the I2C slave back into the known ready receiving state.
switches 0:5c4d7b2438d3 147 */
switches 0:5c4d7b2438d3 148 void stop(void);
switches 0:5c4d7b2438d3 149
switches 0:5c4d7b2438d3 150 protected:
switches 0:5c4d7b2438d3 151 i2c_t _i2c;
switches 0:5c4d7b2438d3 152 };
switches 0:5c4d7b2438d3 153
switches 0:5c4d7b2438d3 154 } // namespace mbed
switches 0:5c4d7b2438d3 155
switches 0:5c4d7b2438d3 156 #endif
switches 0:5c4d7b2438d3 157
switches 0:5c4d7b2438d3 158 #endif
switches 0:5c4d7b2438d3 159
switches 0:5c4d7b2438d3 160 /** @}*/