change some io settings for TWR-K22F-120M

Dependents:   twr_helloworld

Committer:
Jasper_lee
Date:
Tue Dec 23 03:35:08 2014 +0000
Revision:
0:b16d94660a33
change some io setting used in TWR-K22F120M

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jasper_lee 0:b16d94660a33 1 /* mbed Microcontroller Library
Jasper_lee 0:b16d94660a33 2 * Copyright (c) 2006-2013 ARM Limited
Jasper_lee 0:b16d94660a33 3 *
Jasper_lee 0:b16d94660a33 4 * Licensed under the Apache License, Version 2.0 (the "License");
Jasper_lee 0:b16d94660a33 5 * you may not use this file except in compliance with the License.
Jasper_lee 0:b16d94660a33 6 * You may obtain a copy of the License at
Jasper_lee 0:b16d94660a33 7 *
Jasper_lee 0:b16d94660a33 8 * http://www.apache.org/licenses/LICENSE-2.0
Jasper_lee 0:b16d94660a33 9 *
Jasper_lee 0:b16d94660a33 10 * Unless required by applicable law or agreed to in writing, software
Jasper_lee 0:b16d94660a33 11 * distributed under the License is distributed on an "AS IS" BASIS,
Jasper_lee 0:b16d94660a33 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Jasper_lee 0:b16d94660a33 13 * See the License for the specific language governing permissions and
Jasper_lee 0:b16d94660a33 14 * limitations under the License.
Jasper_lee 0:b16d94660a33 15 */
Jasper_lee 0:b16d94660a33 16 #ifndef MBED_SPI_H
Jasper_lee 0:b16d94660a33 17 #define MBED_SPI_H
Jasper_lee 0:b16d94660a33 18
Jasper_lee 0:b16d94660a33 19 #include "platform.h"
Jasper_lee 0:b16d94660a33 20
Jasper_lee 0:b16d94660a33 21 #if DEVICE_SPI
Jasper_lee 0:b16d94660a33 22
Jasper_lee 0:b16d94660a33 23 #include "spi_api.h"
Jasper_lee 0:b16d94660a33 24
Jasper_lee 0:b16d94660a33 25 namespace mbed {
Jasper_lee 0:b16d94660a33 26
Jasper_lee 0:b16d94660a33 27 /** A SPI Master, used for communicating with SPI slave devices
Jasper_lee 0:b16d94660a33 28 *
Jasper_lee 0:b16d94660a33 29 * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz
Jasper_lee 0:b16d94660a33 30 *
Jasper_lee 0:b16d94660a33 31 * Most SPI devices will also require Chip Select and Reset signals. These
Jasper_lee 0:b16d94660a33 32 * can be controlled using <DigitalOut> pins
Jasper_lee 0:b16d94660a33 33 *
Jasper_lee 0:b16d94660a33 34 * Example:
Jasper_lee 0:b16d94660a33 35 * @code
Jasper_lee 0:b16d94660a33 36 * // Send a byte to a SPI slave, and record the response
Jasper_lee 0:b16d94660a33 37 *
Jasper_lee 0:b16d94660a33 38 * #include "mbed.h"
Jasper_lee 0:b16d94660a33 39 *
Jasper_lee 0:b16d94660a33 40 * SPI device(p5, p6, p7); // mosi, miso, sclk
Jasper_lee 0:b16d94660a33 41 *
Jasper_lee 0:b16d94660a33 42 * int main() {
Jasper_lee 0:b16d94660a33 43 * int response = device.write(0xFF);
Jasper_lee 0:b16d94660a33 44 * }
Jasper_lee 0:b16d94660a33 45 * @endcode
Jasper_lee 0:b16d94660a33 46 */
Jasper_lee 0:b16d94660a33 47 class SPI {
Jasper_lee 0:b16d94660a33 48
Jasper_lee 0:b16d94660a33 49 public:
Jasper_lee 0:b16d94660a33 50
Jasper_lee 0:b16d94660a33 51 /** Create a SPI master connected to the specified pins
Jasper_lee 0:b16d94660a33 52 *
Jasper_lee 0:b16d94660a33 53 * Pin Options:
Jasper_lee 0:b16d94660a33 54 * (5, 6, 7) or (11, 12, 13)
Jasper_lee 0:b16d94660a33 55 *
Jasper_lee 0:b16d94660a33 56 * mosi or miso can be specfied as NC if not used
Jasper_lee 0:b16d94660a33 57 *
Jasper_lee 0:b16d94660a33 58 * @param mosi SPI Master Out, Slave In pin
Jasper_lee 0:b16d94660a33 59 * @param miso SPI Master In, Slave Out pin
Jasper_lee 0:b16d94660a33 60 * @param sclk SPI Clock pin
Jasper_lee 0:b16d94660a33 61 */
Jasper_lee 0:b16d94660a33 62 SPI(PinName mosi, PinName miso, PinName sclk, PinName _unused=NC);
Jasper_lee 0:b16d94660a33 63
Jasper_lee 0:b16d94660a33 64 /** Configure the data transmission format
Jasper_lee 0:b16d94660a33 65 *
Jasper_lee 0:b16d94660a33 66 * @param bits Number of bits per SPI frame (4 - 16)
Jasper_lee 0:b16d94660a33 67 * @param mode Clock polarity and phase mode (0 - 3)
Jasper_lee 0:b16d94660a33 68 *
Jasper_lee 0:b16d94660a33 69 * @code
Jasper_lee 0:b16d94660a33 70 * mode | POL PHA
Jasper_lee 0:b16d94660a33 71 * -----+--------
Jasper_lee 0:b16d94660a33 72 * 0 | 0 0
Jasper_lee 0:b16d94660a33 73 * 1 | 0 1
Jasper_lee 0:b16d94660a33 74 * 2 | 1 0
Jasper_lee 0:b16d94660a33 75 * 3 | 1 1
Jasper_lee 0:b16d94660a33 76 * @endcode
Jasper_lee 0:b16d94660a33 77 */
Jasper_lee 0:b16d94660a33 78 void format(int bits, int mode = 0);
Jasper_lee 0:b16d94660a33 79
Jasper_lee 0:b16d94660a33 80 /** Set the spi bus clock frequency
Jasper_lee 0:b16d94660a33 81 *
Jasper_lee 0:b16d94660a33 82 * @param hz SCLK frequency in hz (default = 1MHz)
Jasper_lee 0:b16d94660a33 83 */
Jasper_lee 0:b16d94660a33 84 void frequency(int hz = 1000000);
Jasper_lee 0:b16d94660a33 85
Jasper_lee 0:b16d94660a33 86 /** Write to the SPI Slave and return the response
Jasper_lee 0:b16d94660a33 87 *
Jasper_lee 0:b16d94660a33 88 * @param value Data to be sent to the SPI slave
Jasper_lee 0:b16d94660a33 89 *
Jasper_lee 0:b16d94660a33 90 * @returns
Jasper_lee 0:b16d94660a33 91 * Response from the SPI slave
Jasper_lee 0:b16d94660a33 92 */
Jasper_lee 0:b16d94660a33 93 virtual int write(int value);
Jasper_lee 0:b16d94660a33 94
Jasper_lee 0:b16d94660a33 95 public:
Jasper_lee 0:b16d94660a33 96 virtual ~SPI() {
Jasper_lee 0:b16d94660a33 97 }
Jasper_lee 0:b16d94660a33 98
Jasper_lee 0:b16d94660a33 99 protected:
Jasper_lee 0:b16d94660a33 100 spi_t _spi;
Jasper_lee 0:b16d94660a33 101
Jasper_lee 0:b16d94660a33 102 void aquire(void);
Jasper_lee 0:b16d94660a33 103 static SPI *_owner;
Jasper_lee 0:b16d94660a33 104 int _bits;
Jasper_lee 0:b16d94660a33 105 int _mode;
Jasper_lee 0:b16d94660a33 106 int _hz;
Jasper_lee 0:b16d94660a33 107 };
Jasper_lee 0:b16d94660a33 108
Jasper_lee 0:b16d94660a33 109 } // namespace mbed
Jasper_lee 0:b16d94660a33 110
Jasper_lee 0:b16d94660a33 111 #endif
Jasper_lee 0:b16d94660a33 112
Jasper_lee 0:b16d94660a33 113 #endif