FRDM-K64F, Avnet M14A2A, Grove Shield, to create smart home system. In use with AT&Ts M2x & Flow.

Dependencies:   mbed FXOS8700CQ MODSERIAL

Committer:
jwhammel
Date:
Mon Apr 29 04:24:38 2019 +0000
Revision:
85:0cf65ceb4492
Parent:
84:fc8c9b39723a
We have added an alarm trigger that gets sent to AT&T Flow.

Who changed what in which revision?

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