Opencv 3.1 project on GR-PEACH board
Fork of gr-peach-opencv-project by
drivers/SPISlave.h@170:54ff26da7eb6, 2017-07-04 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
thedo | 167:1657b442184c | 1 | /* mbed Microcontroller Library |
thedo | 167:1657b442184c | 2 | * Copyright (c) 2006-2013 ARM Limited |
thedo | 167:1657b442184c | 3 | * |
thedo | 167:1657b442184c | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
thedo | 167:1657b442184c | 5 | * you may not use this file except in compliance with the License. |
thedo | 167:1657b442184c | 6 | * You may obtain a copy of the License at |
thedo | 167:1657b442184c | 7 | * |
thedo | 167:1657b442184c | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
thedo | 167:1657b442184c | 9 | * |
thedo | 167:1657b442184c | 10 | * Unless required by applicable law or agreed to in writing, software |
thedo | 167:1657b442184c | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
thedo | 167:1657b442184c | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
thedo | 167:1657b442184c | 13 | * See the License for the specific language governing permissions and |
thedo | 167:1657b442184c | 14 | * limitations under the License. |
thedo | 167:1657b442184c | 15 | */ |
thedo | 167:1657b442184c | 16 | #ifndef MBED_SPISLAVE_H |
thedo | 167:1657b442184c | 17 | #define MBED_SPISLAVE_H |
thedo | 167:1657b442184c | 18 | |
thedo | 167:1657b442184c | 19 | #include "platform/platform.h" |
thedo | 167:1657b442184c | 20 | |
thedo | 167:1657b442184c | 21 | #if defined (DEVICE_SPISLAVE) || defined(DOXYGEN_ONLY) |
thedo | 167:1657b442184c | 22 | |
thedo | 167:1657b442184c | 23 | #include "hal/spi_api.h" |
thedo | 167:1657b442184c | 24 | |
thedo | 167:1657b442184c | 25 | namespace mbed { |
thedo | 167:1657b442184c | 26 | /** \addtogroup drivers */ |
thedo | 167:1657b442184c | 27 | |
thedo | 167:1657b442184c | 28 | /** A SPI slave, used for communicating with a SPI Master device |
thedo | 167:1657b442184c | 29 | * |
thedo | 167:1657b442184c | 30 | * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz |
thedo | 167:1657b442184c | 31 | * |
thedo | 167:1657b442184c | 32 | * @note Synchronization level: Not protected |
thedo | 167:1657b442184c | 33 | * |
thedo | 167:1657b442184c | 34 | * Example: |
thedo | 167:1657b442184c | 35 | * @code |
thedo | 167:1657b442184c | 36 | * // Reply to a SPI master as slave |
thedo | 167:1657b442184c | 37 | * |
thedo | 167:1657b442184c | 38 | * #include "mbed.h" |
thedo | 167:1657b442184c | 39 | * |
thedo | 167:1657b442184c | 40 | * SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel |
thedo | 167:1657b442184c | 41 | * |
thedo | 167:1657b442184c | 42 | * int main() { |
thedo | 167:1657b442184c | 43 | * device.reply(0x00); // Prime SPI with first reply |
thedo | 167:1657b442184c | 44 | * while(1) { |
thedo | 167:1657b442184c | 45 | * if(device.receive()) { |
thedo | 167:1657b442184c | 46 | * int v = device.read(); // Read byte from master |
thedo | 167:1657b442184c | 47 | * v = (v + 1) % 0x100; // Add one to it, modulo 256 |
thedo | 167:1657b442184c | 48 | * device.reply(v); // Make this the next reply |
thedo | 167:1657b442184c | 49 | * } |
thedo | 167:1657b442184c | 50 | * } |
thedo | 167:1657b442184c | 51 | * } |
thedo | 167:1657b442184c | 52 | * @endcode |
thedo | 167:1657b442184c | 53 | * @ingroup drivers |
thedo | 167:1657b442184c | 54 | */ |
thedo | 167:1657b442184c | 55 | class SPISlave { |
thedo | 167:1657b442184c | 56 | |
thedo | 167:1657b442184c | 57 | public: |
thedo | 167:1657b442184c | 58 | |
thedo | 167:1657b442184c | 59 | /** Create a SPI slave connected to the specified pins |
thedo | 167:1657b442184c | 60 | * |
thedo | 167:1657b442184c | 61 | * mosi or miso can be specfied as NC if not used |
thedo | 167:1657b442184c | 62 | * |
thedo | 167:1657b442184c | 63 | * @param mosi SPI Master Out, Slave In pin |
thedo | 167:1657b442184c | 64 | * @param miso SPI Master In, Slave Out pin |
thedo | 167:1657b442184c | 65 | * @param sclk SPI Clock pin |
thedo | 167:1657b442184c | 66 | * @param ssel SPI chip select pin |
thedo | 167:1657b442184c | 67 | */ |
thedo | 167:1657b442184c | 68 | SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel); |
thedo | 167:1657b442184c | 69 | |
thedo | 167:1657b442184c | 70 | /** Configure the data transmission format |
thedo | 167:1657b442184c | 71 | * |
thedo | 167:1657b442184c | 72 | * @param bits Number of bits per SPI frame (4 - 16) |
thedo | 167:1657b442184c | 73 | * @param mode Clock polarity and phase mode (0 - 3) |
thedo | 167:1657b442184c | 74 | * |
thedo | 167:1657b442184c | 75 | * @code |
thedo | 167:1657b442184c | 76 | * mode | POL PHA |
thedo | 167:1657b442184c | 77 | * -----+-------- |
thedo | 167:1657b442184c | 78 | * 0 | 0 0 |
thedo | 167:1657b442184c | 79 | * 1 | 0 1 |
thedo | 167:1657b442184c | 80 | * 2 | 1 0 |
thedo | 167:1657b442184c | 81 | * 3 | 1 1 |
thedo | 167:1657b442184c | 82 | * @endcode |
thedo | 167:1657b442184c | 83 | */ |
thedo | 167:1657b442184c | 84 | void format(int bits, int mode = 0); |
thedo | 167:1657b442184c | 85 | |
thedo | 167:1657b442184c | 86 | /** Set the spi bus clock frequency |
thedo | 167:1657b442184c | 87 | * |
thedo | 167:1657b442184c | 88 | * @param hz SCLK frequency in hz (default = 1MHz) |
thedo | 167:1657b442184c | 89 | */ |
thedo | 167:1657b442184c | 90 | void frequency(int hz = 1000000); |
thedo | 167:1657b442184c | 91 | |
thedo | 167:1657b442184c | 92 | /** Polls the SPI to see if data has been received |
thedo | 167:1657b442184c | 93 | * |
thedo | 167:1657b442184c | 94 | * @returns |
thedo | 167:1657b442184c | 95 | * 0 if no data, |
thedo | 167:1657b442184c | 96 | * 1 otherwise |
thedo | 167:1657b442184c | 97 | */ |
thedo | 167:1657b442184c | 98 | int receive(void); |
thedo | 167:1657b442184c | 99 | |
thedo | 167:1657b442184c | 100 | /** Retrieve data from receive buffer as slave |
thedo | 167:1657b442184c | 101 | * |
thedo | 167:1657b442184c | 102 | * @returns |
thedo | 167:1657b442184c | 103 | * the data in the receive buffer |
thedo | 167:1657b442184c | 104 | */ |
thedo | 167:1657b442184c | 105 | int read(void); |
thedo | 167:1657b442184c | 106 | |
thedo | 167:1657b442184c | 107 | /** Fill the transmission buffer with the value to be written out |
thedo | 167:1657b442184c | 108 | * as slave on the next received message from the master. |
thedo | 167:1657b442184c | 109 | * |
thedo | 167:1657b442184c | 110 | * @param value the data to be transmitted next |
thedo | 167:1657b442184c | 111 | */ |
thedo | 167:1657b442184c | 112 | void reply(int value); |
thedo | 167:1657b442184c | 113 | |
thedo | 167:1657b442184c | 114 | protected: |
thedo | 167:1657b442184c | 115 | spi_t _spi; |
thedo | 167:1657b442184c | 116 | |
thedo | 167:1657b442184c | 117 | int _bits; |
thedo | 167:1657b442184c | 118 | int _mode; |
thedo | 167:1657b442184c | 119 | int _hz; |
thedo | 167:1657b442184c | 120 | }; |
thedo | 167:1657b442184c | 121 | |
thedo | 167:1657b442184c | 122 | } // namespace mbed |
thedo | 167:1657b442184c | 123 | |
thedo | 167:1657b442184c | 124 | #endif |
thedo | 167:1657b442184c | 125 | |
thedo | 167:1657b442184c | 126 | #endif |
thedo | 167:1657b442184c | 127 |