Programme d'utilisation des AX12 avec rajout de l'MX12

Fork of test_carteAToutFaire_PR by CRAC Team

Committer:
ClementBreteau
Date:
Thu May 11 11:49:50 2017 +0000
Revision:
1:f3f702086a30
test de la carte ? tout faire du petit robot

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ClementBreteau 1:f3f702086a30 1 /* mbed Microcontroller Library - SPI
ClementBreteau 1:f3f702086a30 2 * Copyright (c) 2010-2011 ARM Limited. All rights reserved.
ClementBreteau 1:f3f702086a30 3 */
ClementBreteau 1:f3f702086a30 4
ClementBreteau 1:f3f702086a30 5 #ifndef MBED_SPI_H
ClementBreteau 1:f3f702086a30 6 #define MBED_SPI_H
ClementBreteau 1:f3f702086a30 7
ClementBreteau 1:f3f702086a30 8 #include "device.h"
ClementBreteau 1:f3f702086a30 9
ClementBreteau 1:f3f702086a30 10 #if DEVICE_SPI
ClementBreteau 1:f3f702086a30 11
ClementBreteau 1:f3f702086a30 12 #include "platform.h"
ClementBreteau 1:f3f702086a30 13 #include "PinNames.h"
ClementBreteau 1:f3f702086a30 14 #include "PeripheralNames.h"
ClementBreteau 1:f3f702086a30 15 #include "Base.h"
ClementBreteau 1:f3f702086a30 16
ClementBreteau 1:f3f702086a30 17 namespace mbed {
ClementBreteau 1:f3f702086a30 18
ClementBreteau 1:f3f702086a30 19 /* Class: SPI
ClementBreteau 1:f3f702086a30 20 * A SPI Master, used for communicating with SPI slave devices
ClementBreteau 1:f3f702086a30 21 *
ClementBreteau 1:f3f702086a30 22 * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz
ClementBreteau 1:f3f702086a30 23 *
ClementBreteau 1:f3f702086a30 24 * Most SPI devices will also require Chip Select and Reset signals. These
ClementBreteau 1:f3f702086a30 25 * can be controlled using <DigitalOut> pins
ClementBreteau 1:f3f702086a30 26 *
ClementBreteau 1:f3f702086a30 27 * Example:
ClementBreteau 1:f3f702086a30 28 * > // Send a byte to a SPI slave, and record the response
ClementBreteau 1:f3f702086a30 29 * >
ClementBreteau 1:f3f702086a30 30 * > #include "mbed.h"
ClementBreteau 1:f3f702086a30 31 * >
ClementBreteau 1:f3f702086a30 32 * > SPI device(p5, p6, p7); // mosi, miso, sclk
ClementBreteau 1:f3f702086a30 33 * >
ClementBreteau 1:f3f702086a30 34 * > int main() {
ClementBreteau 1:f3f702086a30 35 * > int response = device.write(0xFF);
ClementBreteau 1:f3f702086a30 36 * > }
ClementBreteau 1:f3f702086a30 37 */
ClementBreteau 1:f3f702086a30 38 class SPI : public Base {
ClementBreteau 1:f3f702086a30 39
ClementBreteau 1:f3f702086a30 40 public:
ClementBreteau 1:f3f702086a30 41
ClementBreteau 1:f3f702086a30 42 /* Constructor: SPI
ClementBreteau 1:f3f702086a30 43 * Create a SPI master connected to the specified pins
ClementBreteau 1:f3f702086a30 44 *
ClementBreteau 1:f3f702086a30 45 * Variables:
ClementBreteau 1:f3f702086a30 46 * mosi - SPI Master Out, Slave In pin
ClementBreteau 1:f3f702086a30 47 * miso - SPI Master In, Slave Out pin
ClementBreteau 1:f3f702086a30 48 * sclk - SPI Clock pin
ClementBreteau 1:f3f702086a30 49 * name - (optional) A string to identify the object
ClementBreteau 1:f3f702086a30 50 *
ClementBreteau 1:f3f702086a30 51 * Pin Options:
ClementBreteau 1:f3f702086a30 52 * (5, 6, 7) or (11, 12, 13)
ClementBreteau 1:f3f702086a30 53 *
ClementBreteau 1:f3f702086a30 54 * mosi or miso can be specfied as NC if not used
ClementBreteau 1:f3f702086a30 55 */
ClementBreteau 1:f3f702086a30 56 SPI(PinName mosi, PinName miso, PinName sclk, const char *name = NULL);
ClementBreteau 1:f3f702086a30 57
ClementBreteau 1:f3f702086a30 58 /* Function: format
ClementBreteau 1:f3f702086a30 59 * Configure the data transmission format
ClementBreteau 1:f3f702086a30 60 *
ClementBreteau 1:f3f702086a30 61 * Variables:
ClementBreteau 1:f3f702086a30 62 * bits - Number of bits per SPI frame (4 - 16)
ClementBreteau 1:f3f702086a30 63 * mode - Clock polarity and phase mode (0 - 3)
ClementBreteau 1:f3f702086a30 64 *
ClementBreteau 1:f3f702086a30 65 * > mode | POL PHA
ClementBreteau 1:f3f702086a30 66 * > -----+--------
ClementBreteau 1:f3f702086a30 67 * > 0 | 0 0
ClementBreteau 1:f3f702086a30 68 * > 1 | 0 1
ClementBreteau 1:f3f702086a30 69 * > 2 | 1 0
ClementBreteau 1:f3f702086a30 70 * > 3 | 1 1
ClementBreteau 1:f3f702086a30 71 */
ClementBreteau 1:f3f702086a30 72 void format(int bits, int mode = 0);
ClementBreteau 1:f3f702086a30 73
ClementBreteau 1:f3f702086a30 74 /* Function: frequency
ClementBreteau 1:f3f702086a30 75 * Set the spi bus clock frequency
ClementBreteau 1:f3f702086a30 76 *
ClementBreteau 1:f3f702086a30 77 * Variables:
ClementBreteau 1:f3f702086a30 78 * hz - SCLK frequency in hz (default = 1MHz)
ClementBreteau 1:f3f702086a30 79 */
ClementBreteau 1:f3f702086a30 80 void frequency(int hz = 1000000);
ClementBreteau 1:f3f702086a30 81
ClementBreteau 1:f3f702086a30 82 /* Function: write
ClementBreteau 1:f3f702086a30 83 * Write to the SPI Slave and return the response
ClementBreteau 1:f3f702086a30 84 *
ClementBreteau 1:f3f702086a30 85 * Variables:
ClementBreteau 1:f3f702086a30 86 * value - Data to be sent to the SPI slave
ClementBreteau 1:f3f702086a30 87 * returns - Response from the SPI slave
ClementBreteau 1:f3f702086a30 88 */
ClementBreteau 1:f3f702086a30 89 virtual int write(int value);
ClementBreteau 1:f3f702086a30 90
ClementBreteau 1:f3f702086a30 91
ClementBreteau 1:f3f702086a30 92 #ifdef MBED_RPC
ClementBreteau 1:f3f702086a30 93 virtual const struct rpc_method *get_rpc_methods();
ClementBreteau 1:f3f702086a30 94 static struct rpc_class *get_rpc_class();
ClementBreteau 1:f3f702086a30 95 #endif
ClementBreteau 1:f3f702086a30 96
ClementBreteau 1:f3f702086a30 97 protected:
ClementBreteau 1:f3f702086a30 98
ClementBreteau 1:f3f702086a30 99 SPIName _spi;
ClementBreteau 1:f3f702086a30 100
ClementBreteau 1:f3f702086a30 101 void aquire(void);
ClementBreteau 1:f3f702086a30 102 static SPI *_owner;
ClementBreteau 1:f3f702086a30 103 int _bits;
ClementBreteau 1:f3f702086a30 104 int _mode;
ClementBreteau 1:f3f702086a30 105 int _hz;
ClementBreteau 1:f3f702086a30 106
ClementBreteau 1:f3f702086a30 107 };
ClementBreteau 1:f3f702086a30 108
ClementBreteau 1:f3f702086a30 109 } // namespace mbed
ClementBreteau 1:f3f702086a30 110
ClementBreteau 1:f3f702086a30 111 #endif
ClementBreteau 1:f3f702086a30 112
ClementBreteau 1:f3f702086a30 113 #endif