SDCard version

Fork of gr-peach-opencv-project-sd-card by the do

Committer:
thedo
Date:
Fri Jul 21 01:26:54 2017 +0000
Revision:
167:2ee3e82cb6f5
gr-peach-opencv-project-sd-card

Who changed what in which revision?

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