mbed library sources with internal temperature sensor for nucleo f401

Committer:
elessair
Date:
Sat Jan 17 18:03:58 2015 +0000
Revision:
0:7e2bd16f80af
nucleo f401re internal temperature added

Who changed what in which revision?

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