Describes predefine macros for mbed online compiler (armcc)

Committer:
MACRUM
Date:
Thu Mar 16 21:58:09 2017 +0900
Revision:
6:40e873bbc5f7
Add licence header info

Who changed what in which revision?

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