]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/api/SPISlave.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.
16 #ifndef MBED_SPISLAVE_H
17 #define MBED_SPISLAVE_H
27 /** A SPI slave, used for communicating with a SPI Master device
29 * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz
33 * // Reply to a SPI master as slave
37 * SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
40 * device.reply(0x00); // Prime SPI with first reply
42 * if(device.receive()) {
43 * int v = device.read(); // Read byte from master
44 * v = (v + 1) % 0x100; // Add one to it, modulo 256
45 * device.reply(v); // Make this the next reply
55 /** Create a SPI slave connected to the specified pins
58 * (5, 6, 7i, 8) or (11, 12, 13, 14)
60 * mosi or miso can be specfied as NC if not used
62 * @param mosi SPI Master Out, Slave In pin
63 * @param miso SPI Master In, Slave Out pin
64 * @param sclk SPI Clock pin
65 * @param ssel SPI chip select pin
66 * @param name (optional) A string to identify the object
68 SPISlave(PinName mosi
, PinName miso
, PinName sclk
, PinName ssel
);
70 /** Configure the data transmission format
72 * @param bits Number of bits per SPI frame (4 - 16)
73 * @param mode Clock polarity and phase mode (0 - 3)
84 void format(int bits
, int mode
= 0);
86 /** Set the spi bus clock frequency
88 * @param hz SCLK frequency in hz (default = 1MHz)
90 void frequency(int hz
= 1000000);
92 /** Polls the SPI to see if data has been received
100 /** Retrieve data from receive buffer as slave
103 * the data in the receive buffer
107 /** Fill the transmission buffer with the value to be written out
108 * as slave on the next received message from the master.
110 * @param value the data to be transmitted next
112 void reply(int value
);