Tried to initialize the buttons and slider but couldn't get it to work.

Dependencies:   mbed

Committer:
mturner5
Date:
Mon Sep 19 03:28:41 2016 +0000
Revision:
0:0d6b77c9ae01
basic v2;

Who changed what in which revision?

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