Opencv 3.1 project on GR-PEACH board

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

Committer:
thedo
Date:
Tue Jul 04 06:23:13 2017 +0000
Revision:
170:54ff26da7eb6
Parent:
167:1657b442184c
project opencv 3.1 on GR PEACH board, no use SD card.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thedo 167:1657b442184c 1
thedo 167:1657b442184c 2 /** \addtogroup hal */
thedo 167:1657b442184c 3 /** @{*/
thedo 167:1657b442184c 4 /* mbed Microcontroller Library
thedo 167:1657b442184c 5 * Copyright (c) 2006-2013 ARM Limited
thedo 167:1657b442184c 6 *
thedo 167:1657b442184c 7 * Licensed under the Apache License, Version 2.0 (the "License");
thedo 167:1657b442184c 8 * you may not use this file except in compliance with the License.
thedo 167:1657b442184c 9 * You may obtain a copy of the License at
thedo 167:1657b442184c 10 *
thedo 167:1657b442184c 11 * http://www.apache.org/licenses/LICENSE-2.0
thedo 167:1657b442184c 12 *
thedo 167:1657b442184c 13 * Unless required by applicable law or agreed to in writing, software
thedo 167:1657b442184c 14 * distributed under the License is distributed on an "AS IS" BASIS,
thedo 167:1657b442184c 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
thedo 167:1657b442184c 16 * See the License for the specific language governing permissions and
thedo 167:1657b442184c 17 * limitations under the License.
thedo 167:1657b442184c 18 */
thedo 167:1657b442184c 19 #ifndef MBED_SPI_API_H
thedo 167:1657b442184c 20 #define MBED_SPI_API_H
thedo 167:1657b442184c 21
thedo 167:1657b442184c 22 #include "device.h"
thedo 167:1657b442184c 23 #include "hal/dma_api.h"
thedo 167:1657b442184c 24 #include "hal/buffer.h"
thedo 167:1657b442184c 25
thedo 167:1657b442184c 26 #if DEVICE_SPI
thedo 167:1657b442184c 27
thedo 167:1657b442184c 28 #define SPI_EVENT_ERROR (1 << 1)
thedo 167:1657b442184c 29 #define SPI_EVENT_COMPLETE (1 << 2)
thedo 167:1657b442184c 30 #define SPI_EVENT_RX_OVERFLOW (1 << 3)
thedo 167:1657b442184c 31 #define SPI_EVENT_ALL (SPI_EVENT_ERROR | SPI_EVENT_COMPLETE | SPI_EVENT_RX_OVERFLOW)
thedo 167:1657b442184c 32
thedo 167:1657b442184c 33 #define SPI_EVENT_INTERNAL_TRANSFER_COMPLETE (1 << 30) // Internal flag to report that an event occurred
thedo 167:1657b442184c 34
thedo 167:1657b442184c 35 #define SPI_FILL_WORD (0xFFFF)
thedo 167:1657b442184c 36
thedo 167:1657b442184c 37 #if DEVICE_SPI_ASYNCH
thedo 167:1657b442184c 38 /** Asynch SPI HAL structure
thedo 167:1657b442184c 39 */
thedo 167:1657b442184c 40 typedef struct {
thedo 167:1657b442184c 41 struct spi_s spi; /**< Target specific SPI structure */
thedo 167:1657b442184c 42 struct buffer_s tx_buff; /**< Tx buffer */
thedo 167:1657b442184c 43 struct buffer_s rx_buff; /**< Rx buffer */
thedo 167:1657b442184c 44 } spi_t;
thedo 167:1657b442184c 45
thedo 167:1657b442184c 46 #else
thedo 167:1657b442184c 47 /** Non-asynch SPI HAL structure
thedo 167:1657b442184c 48 */
thedo 167:1657b442184c 49 typedef struct spi_s spi_t;
thedo 167:1657b442184c 50
thedo 167:1657b442184c 51 #endif
thedo 167:1657b442184c 52
thedo 167:1657b442184c 53 #ifdef __cplusplus
thedo 167:1657b442184c 54 extern "C" {
thedo 167:1657b442184c 55 #endif
thedo 167:1657b442184c 56
thedo 167:1657b442184c 57 /**
thedo 167:1657b442184c 58 * \defgroup hal_GeneralSPI SPI Configuration Functions
thedo 167:1657b442184c 59 * @{
thedo 167:1657b442184c 60 */
thedo 167:1657b442184c 61
thedo 167:1657b442184c 62 /** Initialize the SPI peripheral
thedo 167:1657b442184c 63 *
thedo 167:1657b442184c 64 * Configures the pins used by SPI, sets a default format and frequency, and enables the peripheral
thedo 167:1657b442184c 65 * @param[out] obj The SPI object to initialize
thedo 167:1657b442184c 66 * @param[in] mosi The pin to use for MOSI
thedo 167:1657b442184c 67 * @param[in] miso The pin to use for MISO
thedo 167:1657b442184c 68 * @param[in] sclk The pin to use for SCLK
thedo 167:1657b442184c 69 * @param[in] ssel The pin to use for SSEL
thedo 167:1657b442184c 70 */
thedo 167:1657b442184c 71 void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel);
thedo 167:1657b442184c 72
thedo 167:1657b442184c 73 /** Release a SPI object
thedo 167:1657b442184c 74 *
thedo 167:1657b442184c 75 * TODO: spi_free is currently unimplemented
thedo 167:1657b442184c 76 * This will require reference counting at the C++ level to be safe
thedo 167:1657b442184c 77 *
thedo 167:1657b442184c 78 * Return the pins owned by the SPI object to their reset state
thedo 167:1657b442184c 79 * Disable the SPI peripheral
thedo 167:1657b442184c 80 * Disable the SPI clock
thedo 167:1657b442184c 81 * @param[in] obj The SPI object to deinitialize
thedo 167:1657b442184c 82 */
thedo 167:1657b442184c 83 void spi_free(spi_t *obj);
thedo 167:1657b442184c 84
thedo 167:1657b442184c 85 /** Configure the SPI format
thedo 167:1657b442184c 86 *
thedo 167:1657b442184c 87 * Set the number of bits per frame, configure clock polarity and phase, shift order and master/slave mode.
thedo 167:1657b442184c 88 * The default bit order is MSB.
thedo 167:1657b442184c 89 * @param[in,out] obj The SPI object to configure
thedo 167:1657b442184c 90 * @param[in] bits The number of bits per frame
thedo 167:1657b442184c 91 * @param[in] mode The SPI mode (clock polarity, phase, and shift direction)
thedo 167:1657b442184c 92 * @param[in] slave Zero for master mode or non-zero for slave mode
thedo 167:1657b442184c 93 */
thedo 167:1657b442184c 94 void spi_format(spi_t *obj, int bits, int mode, int slave);
thedo 167:1657b442184c 95
thedo 167:1657b442184c 96 /** Set the SPI baud rate
thedo 167:1657b442184c 97 *
thedo 167:1657b442184c 98 * Actual frequency may differ from the desired frequency due to available dividers and bus clock
thedo 167:1657b442184c 99 * Configures the SPI peripheral's baud rate
thedo 167:1657b442184c 100 * @param[in,out] obj The SPI object to configure
thedo 167:1657b442184c 101 * @param[in] hz The baud rate in Hz
thedo 167:1657b442184c 102 */
thedo 167:1657b442184c 103 void spi_frequency(spi_t *obj, int hz);
thedo 167:1657b442184c 104
thedo 167:1657b442184c 105 /**@}*/
thedo 167:1657b442184c 106 /**
thedo 167:1657b442184c 107 * \defgroup SynchSPI Synchronous SPI Hardware Abstraction Layer
thedo 167:1657b442184c 108 * @{
thedo 167:1657b442184c 109 */
thedo 167:1657b442184c 110
thedo 167:1657b442184c 111 /** Write a byte out in master mode and receive a value
thedo 167:1657b442184c 112 *
thedo 167:1657b442184c 113 * @param[in] obj The SPI peripheral to use for sending
thedo 167:1657b442184c 114 * @param[in] value The value to send
thedo 167:1657b442184c 115 * @return Returns the value received during send
thedo 167:1657b442184c 116 */
thedo 167:1657b442184c 117 int spi_master_write(spi_t *obj, int value);
thedo 167:1657b442184c 118
thedo 167:1657b442184c 119 /** Write a block out in master mode and receive a value
thedo 167:1657b442184c 120 *
thedo 167:1657b442184c 121 * The total number of bytes sent and recieved will be the maximum of
thedo 167:1657b442184c 122 * tx_length and rx_length. The bytes written will be padded with the
thedo 167:1657b442184c 123 * value 0xff.
thedo 167:1657b442184c 124 *
thedo 167:1657b442184c 125 * @param[in] obj The SPI peripheral to use for sending
thedo 167:1657b442184c 126 * @param[in] tx_buffer Pointer to the byte-array of data to write to the device
thedo 167:1657b442184c 127 * @param[in] tx_length Number of bytes to write, may be zero
thedo 167:1657b442184c 128 * @param[in] rx_buffer Pointer to the byte-array of data to read from the device
thedo 167:1657b442184c 129 * @param[in] rx_length Number of bytes to read, may be zero
thedo 167:1657b442184c 130 * @returns
thedo 167:1657b442184c 131 * The number of bytes written and read from the device. This is
thedo 167:1657b442184c 132 * maximum of tx_length and rx_length.
thedo 167:1657b442184c 133 */
thedo 167:1657b442184c 134 int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length);
thedo 167:1657b442184c 135
thedo 167:1657b442184c 136 /** Check if a value is available to read
thedo 167:1657b442184c 137 *
thedo 167:1657b442184c 138 * @param[in] obj The SPI peripheral to check
thedo 167:1657b442184c 139 * @return non-zero if a value is available
thedo 167:1657b442184c 140 */
thedo 167:1657b442184c 141 int spi_slave_receive(spi_t *obj);
thedo 167:1657b442184c 142
thedo 167:1657b442184c 143 /** Get a received value out of the SPI receive buffer in slave mode
thedo 167:1657b442184c 144 *
thedo 167:1657b442184c 145 * Blocks until a value is available
thedo 167:1657b442184c 146 * @param[in] obj The SPI peripheral to read
thedo 167:1657b442184c 147 * @return The value received
thedo 167:1657b442184c 148 */
thedo 167:1657b442184c 149 int spi_slave_read(spi_t *obj);
thedo 167:1657b442184c 150
thedo 167:1657b442184c 151 /** Write a value to the SPI peripheral in slave mode
thedo 167:1657b442184c 152 *
thedo 167:1657b442184c 153 * Blocks until the SPI peripheral can be written to
thedo 167:1657b442184c 154 * @param[in] obj The SPI peripheral to write
thedo 167:1657b442184c 155 * @param[in] value The value to write
thedo 167:1657b442184c 156 */
thedo 167:1657b442184c 157 void spi_slave_write(spi_t *obj, int value);
thedo 167:1657b442184c 158
thedo 167:1657b442184c 159 /** Checks if the specified SPI peripheral is in use
thedo 167:1657b442184c 160 *
thedo 167:1657b442184c 161 * @param[in] obj The SPI peripheral to check
thedo 167:1657b442184c 162 * @return non-zero if the peripheral is currently transmitting
thedo 167:1657b442184c 163 */
thedo 167:1657b442184c 164 int spi_busy(spi_t *obj);
thedo 167:1657b442184c 165
thedo 167:1657b442184c 166 /** Get the module number
thedo 167:1657b442184c 167 *
thedo 167:1657b442184c 168 * @param[in] obj The SPI peripheral to check
thedo 167:1657b442184c 169 * @return The module number
thedo 167:1657b442184c 170 */
thedo 167:1657b442184c 171 uint8_t spi_get_module(spi_t *obj);
thedo 167:1657b442184c 172
thedo 167:1657b442184c 173 /**@}*/
thedo 167:1657b442184c 174
thedo 167:1657b442184c 175 #if DEVICE_SPI_ASYNCH
thedo 167:1657b442184c 176 /**
thedo 167:1657b442184c 177 * \defgroup AsynchSPI Asynchronous SPI Hardware Abstraction Layer
thedo 167:1657b442184c 178 * @{
thedo 167:1657b442184c 179 */
thedo 167:1657b442184c 180
thedo 167:1657b442184c 181 /** Begin the SPI transfer. Buffer pointers and lengths are specified in tx_buff and rx_buff
thedo 167:1657b442184c 182 *
thedo 167:1657b442184c 183 * @param[in] obj The SPI object that holds the transfer information
thedo 167:1657b442184c 184 * @param[in] tx The transmit buffer
thedo 167:1657b442184c 185 * @param[in] tx_length The number of bytes to transmit
thedo 167:1657b442184c 186 * @param[in] rx The receive buffer
thedo 167:1657b442184c 187 * @param[in] rx_length The number of bytes to receive
thedo 167:1657b442184c 188 * @param[in] bit_width The bit width of buffer words
thedo 167:1657b442184c 189 * @param[in] event The logical OR of events to be registered
thedo 167:1657b442184c 190 * @param[in] handler SPI interrupt handler
thedo 167:1657b442184c 191 * @param[in] hint A suggestion for how to use DMA with this transfer
thedo 167:1657b442184c 192 */
thedo 167:1657b442184c 193 void spi_master_transfer(spi_t *obj, const void *tx, size_t tx_length, void *rx, size_t rx_length, uint8_t bit_width, uint32_t handler, uint32_t event, DMAUsage hint);
thedo 167:1657b442184c 194
thedo 167:1657b442184c 195 /** The asynchronous IRQ handler
thedo 167:1657b442184c 196 *
thedo 167:1657b442184c 197 * Reads the received values out of the RX FIFO, writes values into the TX FIFO and checks for transfer termination
thedo 167:1657b442184c 198 * conditions, such as buffer overflows or transfer complete.
thedo 167:1657b442184c 199 * @param[in] obj The SPI object that holds the transfer information
thedo 167:1657b442184c 200 * @return Event flags if a transfer termination condition was met; otherwise 0.
thedo 167:1657b442184c 201 */
thedo 167:1657b442184c 202 uint32_t spi_irq_handler_asynch(spi_t *obj);
thedo 167:1657b442184c 203
thedo 167:1657b442184c 204 /** Attempts to determine if the SPI peripheral is already in use
thedo 167:1657b442184c 205 *
thedo 167:1657b442184c 206 * If a temporary DMA channel has been allocated, peripheral is in use.
thedo 167:1657b442184c 207 * If a permanent DMA channel has been allocated, check if the DMA channel is in use. If not, proceed as though no DMA
thedo 167:1657b442184c 208 * channel were allocated.
thedo 167:1657b442184c 209 * If no DMA channel is allocated, check whether tx and rx buffers have been assigned. For each assigned buffer, check
thedo 167:1657b442184c 210 * if the corresponding buffer position is less than the buffer length. If buffers do not indicate activity, check if
thedo 167:1657b442184c 211 * there are any bytes in the FIFOs.
thedo 167:1657b442184c 212 * @param[in] obj The SPI object to check for activity
thedo 167:1657b442184c 213 * @return Non-zero if the SPI port is active or zero if it is not.
thedo 167:1657b442184c 214 */
thedo 167:1657b442184c 215 uint8_t spi_active(spi_t *obj);
thedo 167:1657b442184c 216
thedo 167:1657b442184c 217 /** Abort an SPI transfer
thedo 167:1657b442184c 218 *
thedo 167:1657b442184c 219 * @param obj The SPI peripheral to stop
thedo 167:1657b442184c 220 */
thedo 167:1657b442184c 221 void spi_abort_asynch(spi_t *obj);
thedo 167:1657b442184c 222
thedo 167:1657b442184c 223
thedo 167:1657b442184c 224 #endif
thedo 167:1657b442184c 225
thedo 167:1657b442184c 226 /**@}*/
thedo 167:1657b442184c 227
thedo 167:1657b442184c 228 #ifdef __cplusplus
thedo 167:1657b442184c 229 }
thedo 167:1657b442184c 230 #endif // __cplusplus
thedo 167:1657b442184c 231
thedo 167:1657b442184c 232 #endif // SPI_DEVICE
thedo 167:1657b442184c 233
thedo 167:1657b442184c 234 #endif // MBED_SPI_API_H
thedo 167:1657b442184c 235
thedo 167:1657b442184c 236 /** @}*/
thedo 167:1657b442184c 237