UVic Assistive Technology Lab / Mbed 2 deprecated DSLR_Camera_Gimbal

Dependencies:   mbed ros_lib_kinetic

Committer:
group-UVic-Assistive-Technolog
Date:
Wed Jan 31 05:24:12 2018 +0000
Revision:
0:3a767f41cf04
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
group-UVic-Assistive-Technolog 0:3a767f41cf04 1 /* mbed Microcontroller Library
group-UVic-Assistive-Technolog 0:3a767f41cf04 2 * Copyright (c) 2006-2015 ARM Limited
group-UVic-Assistive-Technolog 0:3a767f41cf04 3 *
group-UVic-Assistive-Technolog 0:3a767f41cf04 4 * Licensed under the Apache License, Version 2.0 (the "License");
group-UVic-Assistive-Technolog 0:3a767f41cf04 5 * you may not use this file except in compliance with the License.
group-UVic-Assistive-Technolog 0:3a767f41cf04 6 * You may obtain a copy of the License at
group-UVic-Assistive-Technolog 0:3a767f41cf04 7 *
group-UVic-Assistive-Technolog 0:3a767f41cf04 8 * http://www.apache.org/licenses/LICENSE-2.0
group-UVic-Assistive-Technolog 0:3a767f41cf04 9 *
group-UVic-Assistive-Technolog 0:3a767f41cf04 10 * Unless required by applicable law or agreed to in writing, software
group-UVic-Assistive-Technolog 0:3a767f41cf04 11 * distributed under the License is distributed on an "AS IS" BASIS,
group-UVic-Assistive-Technolog 0:3a767f41cf04 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
group-UVic-Assistive-Technolog 0:3a767f41cf04 13 * See the License for the specific language governing permissions and
group-UVic-Assistive-Technolog 0:3a767f41cf04 14 * limitations under the License.
group-UVic-Assistive-Technolog 0:3a767f41cf04 15 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 16 #ifndef MBED_I2C_API_H
group-UVic-Assistive-Technolog 0:3a767f41cf04 17 #define MBED_I2C_API_H
group-UVic-Assistive-Technolog 0:3a767f41cf04 18
group-UVic-Assistive-Technolog 0:3a767f41cf04 19 #include "device.h"
group-UVic-Assistive-Technolog 0:3a767f41cf04 20 #include "buffer.h"
group-UVic-Assistive-Technolog 0:3a767f41cf04 21 #include "dma_api.h"
group-UVic-Assistive-Technolog 0:3a767f41cf04 22
group-UVic-Assistive-Technolog 0:3a767f41cf04 23 #if DEVICE_I2C
group-UVic-Assistive-Technolog 0:3a767f41cf04 24
group-UVic-Assistive-Technolog 0:3a767f41cf04 25 /**
group-UVic-Assistive-Technolog 0:3a767f41cf04 26 * @defgroup I2CEvents I2C Events Macros
group-UVic-Assistive-Technolog 0:3a767f41cf04 27 *
group-UVic-Assistive-Technolog 0:3a767f41cf04 28 * @{
group-UVic-Assistive-Technolog 0:3a767f41cf04 29 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 30 #define I2C_EVENT_ERROR (1 << 1)
group-UVic-Assistive-Technolog 0:3a767f41cf04 31 #define I2C_EVENT_ERROR_NO_SLAVE (1 << 2)
group-UVic-Assistive-Technolog 0:3a767f41cf04 32 #define I2C_EVENT_TRANSFER_COMPLETE (1 << 3)
group-UVic-Assistive-Technolog 0:3a767f41cf04 33 #define I2C_EVENT_TRANSFER_EARLY_NACK (1 << 4)
group-UVic-Assistive-Technolog 0:3a767f41cf04 34 #define I2C_EVENT_ALL (I2C_EVENT_ERROR | I2C_EVENT_TRANSFER_COMPLETE | I2C_EVENT_ERROR_NO_SLAVE | I2C_EVENT_TRANSFER_EARLY_NACK)
group-UVic-Assistive-Technolog 0:3a767f41cf04 35
group-UVic-Assistive-Technolog 0:3a767f41cf04 36 /**@}*/
group-UVic-Assistive-Technolog 0:3a767f41cf04 37
group-UVic-Assistive-Technolog 0:3a767f41cf04 38 #if DEVICE_I2C_ASYNCH
group-UVic-Assistive-Technolog 0:3a767f41cf04 39 /** Asynch i2c hal structure
group-UVic-Assistive-Technolog 0:3a767f41cf04 40 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 41 typedef struct {
group-UVic-Assistive-Technolog 0:3a767f41cf04 42 struct i2c_s i2c; /**< Target specific i2c structure */
group-UVic-Assistive-Technolog 0:3a767f41cf04 43 struct buffer_s tx_buff; /**< Tx buffer */
group-UVic-Assistive-Technolog 0:3a767f41cf04 44 struct buffer_s rx_buff; /**< Rx buffer */
group-UVic-Assistive-Technolog 0:3a767f41cf04 45 } i2c_t;
group-UVic-Assistive-Technolog 0:3a767f41cf04 46
group-UVic-Assistive-Technolog 0:3a767f41cf04 47 #else
group-UVic-Assistive-Technolog 0:3a767f41cf04 48 /** Non-asynch i2c hal structure
group-UVic-Assistive-Technolog 0:3a767f41cf04 49 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 50 typedef struct i2c_s i2c_t;
group-UVic-Assistive-Technolog 0:3a767f41cf04 51
group-UVic-Assistive-Technolog 0:3a767f41cf04 52 #endif
group-UVic-Assistive-Technolog 0:3a767f41cf04 53
group-UVic-Assistive-Technolog 0:3a767f41cf04 54 enum {
group-UVic-Assistive-Technolog 0:3a767f41cf04 55 I2C_ERROR_NO_SLAVE = -1,
group-UVic-Assistive-Technolog 0:3a767f41cf04 56 I2C_ERROR_BUS_BUSY = -2
group-UVic-Assistive-Technolog 0:3a767f41cf04 57 };
group-UVic-Assistive-Technolog 0:3a767f41cf04 58
group-UVic-Assistive-Technolog 0:3a767f41cf04 59 #ifdef __cplusplus
group-UVic-Assistive-Technolog 0:3a767f41cf04 60 extern "C" {
group-UVic-Assistive-Technolog 0:3a767f41cf04 61 #endif
group-UVic-Assistive-Technolog 0:3a767f41cf04 62
group-UVic-Assistive-Technolog 0:3a767f41cf04 63 /**
group-UVic-Assistive-Technolog 0:3a767f41cf04 64 * \defgroup GeneralI2C I2C Configuration Functions
group-UVic-Assistive-Technolog 0:3a767f41cf04 65 * @{
group-UVic-Assistive-Technolog 0:3a767f41cf04 66 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 67
group-UVic-Assistive-Technolog 0:3a767f41cf04 68 /** Initialize the I2C peripheral. It sets the default parameters for I2C
group-UVic-Assistive-Technolog 0:3a767f41cf04 69 * peripheral, and configure its specifieds pins.
group-UVic-Assistive-Technolog 0:3a767f41cf04 70 * @param obj The i2c object
group-UVic-Assistive-Technolog 0:3a767f41cf04 71 * @param sda The sda pin
group-UVic-Assistive-Technolog 0:3a767f41cf04 72 * @param scl The scl pin
group-UVic-Assistive-Technolog 0:3a767f41cf04 73 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 74 void i2c_init(i2c_t *obj, PinName sda, PinName scl);
group-UVic-Assistive-Technolog 0:3a767f41cf04 75
group-UVic-Assistive-Technolog 0:3a767f41cf04 76 /** Configure the I2C frequency.
group-UVic-Assistive-Technolog 0:3a767f41cf04 77 * @param obj The i2c object
group-UVic-Assistive-Technolog 0:3a767f41cf04 78 * @param hz Frequency in Hz
group-UVic-Assistive-Technolog 0:3a767f41cf04 79 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 80 void i2c_frequency(i2c_t *obj, int hz);
group-UVic-Assistive-Technolog 0:3a767f41cf04 81
group-UVic-Assistive-Technolog 0:3a767f41cf04 82 /** Send START command.
group-UVic-Assistive-Technolog 0:3a767f41cf04 83 * @param obj The i2c object
group-UVic-Assistive-Technolog 0:3a767f41cf04 84 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 85 int i2c_start(i2c_t *obj);
group-UVic-Assistive-Technolog 0:3a767f41cf04 86
group-UVic-Assistive-Technolog 0:3a767f41cf04 87 /** Send STOP command.
group-UVic-Assistive-Technolog 0:3a767f41cf04 88 * @param obj The i2c object
group-UVic-Assistive-Technolog 0:3a767f41cf04 89 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 90 int i2c_stop(i2c_t *obj);
group-UVic-Assistive-Technolog 0:3a767f41cf04 91
group-UVic-Assistive-Technolog 0:3a767f41cf04 92 /** Blocking reading data.
group-UVic-Assistive-Technolog 0:3a767f41cf04 93 * @param obj The i2c object
group-UVic-Assistive-Technolog 0:3a767f41cf04 94 * @param address 7-bit address (last bit is 1)
group-UVic-Assistive-Technolog 0:3a767f41cf04 95 * @param data The buffer for receiving
group-UVic-Assistive-Technolog 0:3a767f41cf04 96 * @param length Number of bytes to read
group-UVic-Assistive-Technolog 0:3a767f41cf04 97 * @param stop Stop to be generated after the transfer is done
group-UVic-Assistive-Technolog 0:3a767f41cf04 98 * @return Number of read bytes
group-UVic-Assistive-Technolog 0:3a767f41cf04 99 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 100 int i2c_read(i2c_t *obj, int address, char *data, int length, int stop);
group-UVic-Assistive-Technolog 0:3a767f41cf04 101
group-UVic-Assistive-Technolog 0:3a767f41cf04 102 /** Blocking sending data.
group-UVic-Assistive-Technolog 0:3a767f41cf04 103 * @param obj The i2c object
group-UVic-Assistive-Technolog 0:3a767f41cf04 104 * @param address 7-bit address (last bit is 0)
group-UVic-Assistive-Technolog 0:3a767f41cf04 105 * @param data The buffer for sending
group-UVic-Assistive-Technolog 0:3a767f41cf04 106 * @param length Number of bytes to wrte
group-UVic-Assistive-Technolog 0:3a767f41cf04 107 * @param stop Stop to be generated after the transfer is done
group-UVic-Assistive-Technolog 0:3a767f41cf04 108 * @return Number of written bytes
group-UVic-Assistive-Technolog 0:3a767f41cf04 109 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 110 int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop);
group-UVic-Assistive-Technolog 0:3a767f41cf04 111
group-UVic-Assistive-Technolog 0:3a767f41cf04 112 /** Reset I2C peripheral. TODO: The action here. Most of the implementation sends stop().
group-UVic-Assistive-Technolog 0:3a767f41cf04 113 * @param obj The i2c object
group-UVic-Assistive-Technolog 0:3a767f41cf04 114 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 115 void i2c_reset(i2c_t *obj);
group-UVic-Assistive-Technolog 0:3a767f41cf04 116
group-UVic-Assistive-Technolog 0:3a767f41cf04 117 /** Read one byte.
group-UVic-Assistive-Technolog 0:3a767f41cf04 118 * @param obj The i2c object
group-UVic-Assistive-Technolog 0:3a767f41cf04 119 * @param last Acknoledge
group-UVic-Assistive-Technolog 0:3a767f41cf04 120 * @return The read byte
group-UVic-Assistive-Technolog 0:3a767f41cf04 121 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 122 int i2c_byte_read(i2c_t *obj, int last);
group-UVic-Assistive-Technolog 0:3a767f41cf04 123
group-UVic-Assistive-Technolog 0:3a767f41cf04 124 /** Write one byte.
group-UVic-Assistive-Technolog 0:3a767f41cf04 125 * @param obj The i2c object
group-UVic-Assistive-Technolog 0:3a767f41cf04 126 * @param data Byte to be written
group-UVic-Assistive-Technolog 0:3a767f41cf04 127 * @return 1 if NAK was received, 0 if ACK was received, 2 for timeout.
group-UVic-Assistive-Technolog 0:3a767f41cf04 128 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 129 int i2c_byte_write(i2c_t *obj, int data);
group-UVic-Assistive-Technolog 0:3a767f41cf04 130
group-UVic-Assistive-Technolog 0:3a767f41cf04 131 /**@}*/
group-UVic-Assistive-Technolog 0:3a767f41cf04 132
group-UVic-Assistive-Technolog 0:3a767f41cf04 133 #if DEVICE_I2CSLAVE
group-UVic-Assistive-Technolog 0:3a767f41cf04 134
group-UVic-Assistive-Technolog 0:3a767f41cf04 135 /**
group-UVic-Assistive-Technolog 0:3a767f41cf04 136 * \defgroup SynchI2C Synchronous I2C Hardware Abstraction Layer for slave
group-UVic-Assistive-Technolog 0:3a767f41cf04 137 * @{
group-UVic-Assistive-Technolog 0:3a767f41cf04 138 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 139
group-UVic-Assistive-Technolog 0:3a767f41cf04 140 /** Configure I2C as slave or master.
group-UVic-Assistive-Technolog 0:3a767f41cf04 141 * @param obj The I2C object
group-UVic-Assistive-Technolog 0:3a767f41cf04 142 * @return non-zero if a value is available
group-UVic-Assistive-Technolog 0:3a767f41cf04 143 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 144 void i2c_slave_mode(i2c_t *obj, int enable_slave);
group-UVic-Assistive-Technolog 0:3a767f41cf04 145
group-UVic-Assistive-Technolog 0:3a767f41cf04 146 /** Check to see if the I2C slave has been addressed.
group-UVic-Assistive-Technolog 0:3a767f41cf04 147 * @param obj The I2C object
group-UVic-Assistive-Technolog 0:3a767f41cf04 148 * @return The status - 1 - read addresses, 2 - write to all slaves,
group-UVic-Assistive-Technolog 0:3a767f41cf04 149 * 3 write addressed, 0 - the slave has not been addressed
group-UVic-Assistive-Technolog 0:3a767f41cf04 150 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 151 int i2c_slave_receive(i2c_t *obj);
group-UVic-Assistive-Technolog 0:3a767f41cf04 152
group-UVic-Assistive-Technolog 0:3a767f41cf04 153 /** Configure I2C as slave or master.
group-UVic-Assistive-Technolog 0:3a767f41cf04 154 * @param obj The I2C object
group-UVic-Assistive-Technolog 0:3a767f41cf04 155 * @return non-zero if a value is available
group-UVic-Assistive-Technolog 0:3a767f41cf04 156 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 157 int i2c_slave_read(i2c_t *obj, char *data, int length);
group-UVic-Assistive-Technolog 0:3a767f41cf04 158
group-UVic-Assistive-Technolog 0:3a767f41cf04 159 /** Configure I2C as slave or master.
group-UVic-Assistive-Technolog 0:3a767f41cf04 160 * @param obj The I2C object
group-UVic-Assistive-Technolog 0:3a767f41cf04 161 * @return non-zero if a value is available
group-UVic-Assistive-Technolog 0:3a767f41cf04 162 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 163 int i2c_slave_write(i2c_t *obj, const char *data, int length);
group-UVic-Assistive-Technolog 0:3a767f41cf04 164
group-UVic-Assistive-Technolog 0:3a767f41cf04 165 /** Configure I2C address.
group-UVic-Assistive-Technolog 0:3a767f41cf04 166 * @param obj The I2C object
group-UVic-Assistive-Technolog 0:3a767f41cf04 167 * @param idx Currently not used
group-UVic-Assistive-Technolog 0:3a767f41cf04 168 * @param address The address to be set
group-UVic-Assistive-Technolog 0:3a767f41cf04 169 * @param mask Currently not used
group-UVic-Assistive-Technolog 0:3a767f41cf04 170 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 171 void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask);
group-UVic-Assistive-Technolog 0:3a767f41cf04 172
group-UVic-Assistive-Technolog 0:3a767f41cf04 173 #endif
group-UVic-Assistive-Technolog 0:3a767f41cf04 174
group-UVic-Assistive-Technolog 0:3a767f41cf04 175 /**@}*/
group-UVic-Assistive-Technolog 0:3a767f41cf04 176
group-UVic-Assistive-Technolog 0:3a767f41cf04 177 #if DEVICE_I2C_ASYNCH
group-UVic-Assistive-Technolog 0:3a767f41cf04 178
group-UVic-Assistive-Technolog 0:3a767f41cf04 179 /**
group-UVic-Assistive-Technolog 0:3a767f41cf04 180 * \defgroup AsynchI2C Asynchronous I2C Hardware Abstraction Layer
group-UVic-Assistive-Technolog 0:3a767f41cf04 181 * @{
group-UVic-Assistive-Technolog 0:3a767f41cf04 182 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 183
group-UVic-Assistive-Technolog 0:3a767f41cf04 184 /** Start i2c asynchronous transfer.
group-UVic-Assistive-Technolog 0:3a767f41cf04 185 * @param obj The I2C object
group-UVic-Assistive-Technolog 0:3a767f41cf04 186 * @param tx The buffer to send
group-UVic-Assistive-Technolog 0:3a767f41cf04 187 * @param tx_length The number of words to transmit
group-UVic-Assistive-Technolog 0:3a767f41cf04 188 * @param rx The buffer to receive
group-UVic-Assistive-Technolog 0:3a767f41cf04 189 * @param rx_length The number of words to receive
group-UVic-Assistive-Technolog 0:3a767f41cf04 190 * @param address The address to be set - 7bit or 9 bit
group-UVic-Assistive-Technolog 0:3a767f41cf04 191 * @param stop If true, stop will be generated after the transfer is done
group-UVic-Assistive-Technolog 0:3a767f41cf04 192 * @param handler The I2C IRQ handler to be set
group-UVic-Assistive-Technolog 0:3a767f41cf04 193 * @param hint DMA hint usage
group-UVic-Assistive-Technolog 0:3a767f41cf04 194 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 195 void i2c_transfer_asynch(i2c_t *obj, const void *tx, size_t tx_length, void *rx, size_t rx_length, uint32_t address, uint32_t stop, uint32_t handler, uint32_t event, DMAUsage hint);
group-UVic-Assistive-Technolog 0:3a767f41cf04 196
group-UVic-Assistive-Technolog 0:3a767f41cf04 197 /** The asynchronous IRQ handler
group-UVic-Assistive-Technolog 0:3a767f41cf04 198 * @param obj The I2C object which holds the transfer information
group-UVic-Assistive-Technolog 0:3a767f41cf04 199 * @return event flags if a transfer termination condition was met or 0 otherwise.
group-UVic-Assistive-Technolog 0:3a767f41cf04 200 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 201 uint32_t i2c_irq_handler_asynch(i2c_t *obj);
group-UVic-Assistive-Technolog 0:3a767f41cf04 202
group-UVic-Assistive-Technolog 0:3a767f41cf04 203 /** Attempts to determine if I2C peripheral is already in use.
group-UVic-Assistive-Technolog 0:3a767f41cf04 204 * @param obj The I2C object
group-UVic-Assistive-Technolog 0:3a767f41cf04 205 * @return non-zero if the I2C module is active or zero if it is not
group-UVic-Assistive-Technolog 0:3a767f41cf04 206 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 207 uint8_t i2c_active(i2c_t *obj);
group-UVic-Assistive-Technolog 0:3a767f41cf04 208
group-UVic-Assistive-Technolog 0:3a767f41cf04 209 /** Abort ongoing asynchronous transaction.
group-UVic-Assistive-Technolog 0:3a767f41cf04 210 * @param obj The I2C object
group-UVic-Assistive-Technolog 0:3a767f41cf04 211 */
group-UVic-Assistive-Technolog 0:3a767f41cf04 212 void i2c_abort_asynch(i2c_t *obj);
group-UVic-Assistive-Technolog 0:3a767f41cf04 213
group-UVic-Assistive-Technolog 0:3a767f41cf04 214 #endif
group-UVic-Assistive-Technolog 0:3a767f41cf04 215
group-UVic-Assistive-Technolog 0:3a767f41cf04 216 /**@}*/
group-UVic-Assistive-Technolog 0:3a767f41cf04 217
group-UVic-Assistive-Technolog 0:3a767f41cf04 218 #ifdef __cplusplus
group-UVic-Assistive-Technolog 0:3a767f41cf04 219 }
group-UVic-Assistive-Technolog 0:3a767f41cf04 220 #endif
group-UVic-Assistive-Technolog 0:3a767f41cf04 221
group-UVic-Assistive-Technolog 0:3a767f41cf04 222 #endif
group-UVic-Assistive-Technolog 0:3a767f41cf04 223
group-UVic-Assistive-Technolog 0:3a767f41cf04 224 #endif