]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/api/SPI.h
1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
27 /** A SPI Master, used for communicating with SPI slave devices
29 * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz
31 * Most SPI devices will also require Chip Select and Reset signals. These
32 * can be controlled using <DigitalOut> pins
36 * // Send a byte to a SPI slave, and record the response
40 * SPI device(p5, p6, p7); // mosi, miso, sclk
43 * int response = device.write(0xFF);
51 /** Create a SPI master connected to the specified pins
54 * (5, 6, 7) or (11, 12, 13)
56 * mosi or miso can be specfied as NC if not used
58 * @param mosi SPI Master Out, Slave In pin
59 * @param miso SPI Master In, Slave Out pin
60 * @param sclk SPI Clock pin
62 SPI(PinName mosi
, PinName miso
, PinName sclk
, PinName _unused
=NC
);
64 /** Configure the data transmission format
66 * @param bits Number of bits per SPI frame (4 - 16)
67 * @param mode Clock polarity and phase mode (0 - 3)
78 void format(int bits
, int mode
= 0);
80 /** Set the spi bus clock frequency
82 * @param hz SCLK frequency in hz (default = 1MHz)
84 void frequency(int hz
= 1000000);
86 /** Write to the SPI Slave and return the response
88 * @param value Data to be sent to the SPI slave
91 * Response from the SPI slave
93 virtual int write(int value
);