Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: cc3000_ping_demo_try_2
Fork of mbed by
Revision 20:029aa53d7323, committed 2010-06-03
- Comitter:
- simon
- Date:
- Thu Jun 03 11:17:50 2010 +0000
- Parent:
- 19:e6be4cd80aad
- Child:
- 21:3944f1e2fa4f
- Commit message:
- * Add SPISlave, SPIHalfDuplex, SerialHalfDuplex
* Add I2C repeated start
* Add ethernet set_link()
* Add documentation for wait()
Changed in this revision
--- a/Ethernet.h Tue May 18 16:04:21 2010 +0000
+++ b/Ethernet.h Thu Jun 03 11:17:50 2010 +0000
@@ -52,6 +52,14 @@
*/
virtual ~Ethernet();
+ enum Mode {
+ AutoNegotiate
+ , HalfDuplex10
+ , FullDuplex10
+ , HalfDuplex100
+ , FullDuplex100
+ };
+
/* Function: write
* Writes into an outgoing ethernet packet.
*
@@ -139,6 +147,20 @@
*/
int link();
+ /* Function: set_link
+ * Sets the speed and duplex parameters of an ethernet link
+ *
+ * Variables:
+ * mode - the speed and duplex mode to set the link to:
+ *
+ * > AutoNegotiate Auto negotiate speed and duplex
+ * > HalfDuplex10 10 Mbit, half duplex
+ * > FullDuplex10 10 Mbit, full duplex
+ * > HalfDuplex100 100 Mbit, half duplex
+ * > FullDuplex100 100 Mbit, full duplex
+ */
+ void set_link(Mode mode);
+
};
} // namespace mbed
--- a/I2C.h Tue May 18 16:04:21 2010 +0000
+++ b/I2C.h Thu Jun 03 11:17:50 2010 +0000
@@ -17,7 +17,7 @@
* An I2C Master, used for communicating with I2C slave devices
*
* Example:
- * > // Read from I2C slave at address 0x1234
+ * > // Read from I2C slave at address 0x62
* >
* > #include "mbed.h"
* >
@@ -33,6 +33,13 @@
public:
+ enum RxStatus {
+ NoData
+ , MasterGeneralCall
+ , MasterWrite
+ , MasterRead
+ };
+
/* Constructor: I2C
* Create an I2C Master interface, connected to the specified pins
*
@@ -60,9 +67,10 @@
* address - 8-bit I2C slave address [ addr | 1 ]
* data - Pointer to the byte-array to read data in to
* length - Number of bytes to read
+ * repeated - Repeated start, true - don't send stop at end
* returns - 0 on success (ack), or non-0 on failure (nack)
*/
- int read(int address, char *data, int length);
+ int read(int address, char *data, int length, bool repeated = false);
/* Function: write
* Write to an I2C slave
@@ -74,17 +82,18 @@
* address - 8-bit I2C slave address [ addr | 0 ]
* data - Pointer to the byte-array data to send
* length - Number of bytes to send
+ * repeated - Repeated start, true - do not send stop at end
* returns - 0 on success (ack), or non-0 on failure (nack)
*/
- int write(int address, const char *data, int length);
+ int write(int address, const char *data, int length, bool repeated = false);
protected:
- I2CName _i2c;
-
void aquire();
- static I2C *_owner;
- int _hz;
+
+ I2CName _i2c;
+ static I2C *_owner;
+ int _hz;
};
Binary file LPC1768/capi.ar has changed
Binary file LPC1768/core_cm3.o has changed
Binary file LPC1768/mbed.ar has changed
Binary file LPC2368/capi.ar has changed
Binary file LPC2368/mbed.ar has changed
--- a/SPI.h Tue May 18 16:04:21 2010 +0000
+++ b/SPI.h Thu Jun 03 11:17:50 2010 +0000
@@ -1,5 +1,5 @@
/* mbed Microcontroller Library - SPI
- * Copyright (c) 2006-2009 ARM Limited. All rights reserved.
+ * Copyright (c) 2010 ARM Limited. All rights reserved.
* sford
*/
@@ -48,7 +48,7 @@
* Pin Options:
* (5, 6, 7) or (11, 12, 13)
*
- * mosi or miso can be specfied as NOT_CONNECTED if not used
+ * mosi or miso can be specfied as NC if not used
*/
SPI(PinName mosi, PinName miso, PinName sclk, const char *name = NULL);
@@ -83,7 +83,8 @@
* value - Data to be sent to the SPI slave
* returns - Response from the SPI slave
*/
- int write(int value);
+ virtual int write(int value);
+
#ifdef MBED_RPC
virtual const struct rpc_method *get_rpc_methods();
@@ -94,7 +95,7 @@
SPIName _spi;
- void aquire();
+ void aquire(void);
static SPI *_owner;
int _bits;
int _mode;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SPIHalfDuplex.h Thu Jun 03 11:17:50 2010 +0000
@@ -0,0 +1,113 @@
+/* mbed Microcontroller Library - SPI
+ * Copyright (c) 2010 ARM Limited. All rights reserved.
+ * jward
+ */
+
+#ifndef MBED_SPIHALFDUPLEX_H
+#define MBED_SPIHALFDUPLEX_H
+
+#include "SPI.h"
+
+namespace mbed {
+
+/* Class: SPIHalfDuplex
+ * A SPI half-duplex master, used for communicating with SPI slave devices
+ * over a shared data line.
+ *
+ * The default format is set to 8-bits for both master and slave, and a
+ * clock frequency of 1MHz
+ *
+ * Most SPI devies will also require Chip Select and Reset signals. These
+ * can be controlled using <DigitalOut> pins.
+ *
+ * Although this is for a shared data line, both MISO and MOSI are defined,
+ * and should be tied together externally to the mbed. This class handles
+ * the tri-stating of the MOSI pin.
+ *
+ * Example:
+ * > // Send a byte to a SPI half-duplex slave, and record the response
+ * >
+ * > #include "mbed.h"
+ * >
+ * > SPIHalfDuplex device(p5, p6, p7) // mosi, miso, sclk
+ * >
+ * > int main() {
+ * > int respone = device.write(0xAA);
+ * > }
+ */
+
+class SPIHalfDuplex : public SPI {
+
+public:
+
+ /* Constructor: SPIHalfDuplex
+ * Create a SPI half-duplex master connected to the specified pins
+ *
+ * Variables:
+ * mosi - SPI Master Out, Slave In pin
+ * miso - SPI Master In, Slave Out pin
+ * sclk - SPI Clock pin
+ * name - (optional) A string to identify the object
+ *
+ * Pin Options:
+ * (5, 6, 7) or (11, 12, 13)
+ *
+ * mosi or miso can be specfied as NC if not used
+ */
+ SPIHalfDuplex(PinName mosi, PinName miso, PinName sclk,
+ const char *name = NULL);
+
+#if 0 // Inherited from SPI - documentation only
+ /* Function: format
+ * Configure the data transmission format
+ *
+ * Variables:
+ * bits - Number of bits per SPI frame (4 - 16)
+ * mode - Clock polarity and phase mode (0 - 3)
+ *
+ * > mode | POL PHA
+ * > -----+--------
+ * > 0 | 0 0
+ * > 1 | 0 1
+ * > 2 | 1 0
+ * > 3 | 1 1
+ */
+ void format(int bits, int mode = 0);
+
+ /* Function: frequency
+ * Set the spi bus clock frequency
+ *
+ * Variables:
+ * hz - SCLK frequency in hz (default = 1MHz)
+ */
+ void frequency(int hz = 1000000);
+#endif
+
+ /* Function: write
+ * Write to the SPI Slave and return the response
+ *
+ * Variables:
+ * value - Data to be sent to the SPI slave
+ * returns - Response from the SPI slave
+ */
+ virtual int write(int value);
+
+ /* Function: slave_format
+ * Set the number of databits expected from the slave, from 4-16
+ *
+ * Variables:
+ * sbits - Number of expected bits in the slave response
+ */
+ void slave_format(int sbits);
+
+protected:
+
+ PinName _mosi;
+ PinName _miso;
+ int _sbits;
+
+}; // End of class
+
+} // End of namespace mbed
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SPISlave.h Thu Jun 03 11:17:50 2010 +0000
@@ -0,0 +1,122 @@
+/* mbed Microcontroller Library - SPI
+ * Copyright (c) 2010 ARM Limited. All rights reserved.
+ * sford
+ */
+
+#ifndef MBED_SPISLAVE_H
+#define MBED_SPISLAVE_H
+
+#include "platform.h"
+#include "PinNames.h"
+#include "PeripheralNames.h"
+#include "Base.h"
+
+namespace mbed {
+
+/* Class: SPISlave
+ * A SPI slave, used for communicating with a SPI Master device
+ *
+ * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz
+ *
+ * Example:
+ * > // Reply to a SPI master as slave
+ * >
+ * > #include "mbed.h"
+ * >
+ * > SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
+ * >
+ * > int main() {
+ * > device.reply(0x00); // Prime SPI with first reply
+ * > while(1) {
+ * > if(device.receive()) {
+ * > int v = device.read(); // Read byte from master
+ * > v = (v + 1) % 0x100; // Add one to it, modulo 256
+ * > device.reply(v); // Make this the next reply
+ * > }
+ * > }
+ * > }
+ */
+class SPISlave : public Base {
+
+public:
+
+ /* Constructor: SPI
+ * Create a SPI slave connected to the specified pins
+ *
+ * Variables:
+ * mosi - SPI Master Out, Slave In pin
+ * miso - SPI Master In, Slave Out pin
+ * sclk - SPI Clock pin
+ * ssel - SPI chip select pin
+ * name - (optional) A string to identify the object
+ *
+ * Pin Options:
+ * (5, 6, 7i, 8) or (11, 12, 13, 14)
+ *
+ * mosi or miso can be specfied as NC if not used
+ */
+ SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel,
+ const char *name = NULL);
+
+ /* Function: format
+ * Configure the data transmission format
+ *
+ * Variables:
+ * bits - Number of bits per SPI frame (4 - 16)
+ * mode - Clock polarity and phase mode (0 - 3)
+ *
+ * > mode | POL PHA
+ * > -----+--------
+ * > 0 | 0 0
+ * > 1 | 0 1
+ * > 2 | 1 0
+ * > 3 | 1 1
+ */
+ void format(int bits, int mode = 0);
+
+ /* Function: frequency
+ * Set the spi bus clock frequency
+ *
+ * Variables:
+ * hz - SCLK frequency in hz (default = 1MHz)
+ */
+ void frequency(int hz = 1000000);
+
+ /* Function: receive
+ * Polls the SPI to see if data has been received
+ *
+ * Variables:
+ * returns - zero if no data, 1 otherwise
+ */
+ int receive(void);
+
+ /* Function: read
+ * Retrieve data from receive buffer as slave
+ *
+ * Variables:
+ * returns - the data in the receive buffer
+ */
+ int read(void);
+
+ /* Function: reply
+ * Fill the transmission buffer with the value to be written out
+ * as slave on the next received message from the master.
+ *
+ * Variables:
+ * value - the data to be transmitted next
+ */
+ void reply(int value);
+
+protected:
+
+ SPIName _spi;
+
+ int _bits;
+ int _mode;
+ int _hz;
+
+};
+
+} // namespace mbed
+
+#endif
--- a/Serial.h Tue May 18 16:04:21 2010 +0000
+++ b/Serial.h Thu Jun 03 11:17:50 2010 +0000
@@ -39,7 +39,7 @@
* tx - Transmit pin
* rx - Receive pin
*
- * Note: Either tx or rx may be specified as NOT_CONNECTED if unused
+ * Note: Either tx or rx may be specified as NC if unused
*/
Serial(PinName tx, PinName rx, const char *name = NULL);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SerialHalfDuplex.h Thu Jun 03 11:17:50 2010 +0000
@@ -0,0 +1,161 @@
+/* mbed Microcontroller Library - SerialHalfDuplex
+ * Copyright (c) 2010 ARM Limited. All rights reserved.
+ * jward
+ */
+
+#ifndef MBED_SERIALHALFDUPLEX_H
+#define MBED_SERIALHALFDUPLEX_H
+
+#include "Serial.h"
+#include "PinNames.h"
+#include "PeripheralNames.h"
+
+namespace mbed {
+
+/* Class: SerialHalfDuplex
+ * A serial port (UART) for communication with other devices, with a single
+ * shared transmit and receive line.
+ *
+ * If the device both transmits and receives, then both (separate) pins need
+ * to be defined, and tied together externally.
+ *
+ * Example:
+ * > // Send a byte as a master, and receive a byte as a slave
+ * >
+ * > #include "mbed.h"
+ * >
+ * > SerialHalfDuplex master(p9, p10);
+ * >
+ * > int main() {
+ * > int outbyte = master.putc(0x55);
+ * > int retbyte = master.getc();
+ * > printf("Wrote: %02X Read: %02X\n", outbyte, retbyte);
+ * > }
+ */
+class SerialHalfDuplex : public Serial {
+
+public:
+ /* Constructor: SerialHalfDuplex
+ * Create a half-duplex serial port, connected to the specified transmit
+ * and receive pins.
+ *
+ * Variables:
+ * tx - Transmit pin
+ * rx - Receive pin
+ *
+ * Note: Either tx or rx may be specified as NC if unused
+ */
+
+ SerialHalfDuplex(PinName tx, PinName rx, const char *name = NULL);
+
+#if 0 // Inherited from Serial class, for documentation
+ /* Function: baud
+ * Set the baud rate of the serial port
+ *
+ * Variables:
+ * baudrate - The baudrate of the serial port (default = 9600).
+ */
+ void baud(int baudrate);
+
+ enum Parity {
+ None = 0
+ , Odd
+ , Even
+ , Forced1
+ , Forced0
+ };
+
+ /* Function: format
+ * Set the transmission format used by the Serial port
+ *
+ * Variables:
+ * bits - The number of bits in a word (5-8; default = 8)
+ * parity - The parity used (Serial::None, Serial::Odd,
+Serial::Even, Serial::Forced1, Serial::Forced0; default = Serial::None)
+ * stop - The number of stop bits (1 or 2; default = 1)
+ */
+ void format(int bits = 8, Parity parity = Serial::None, int stop_bits
+= 1);
+
+ /* Function: putc
+ * Write a character
+ *
+ * Variables:
+ * c - The character to write to the serial port
+ */
+ int putc(int c);
+
+ /* Function: getc
+ * Read a character
+ *
+ * Variables:
+ * returns - The character read from the serial port
+ */
+ int getc();
+
+ /* Function: printf
+ * Write a formated string
+ *
+ * Variables:
+ * format - A printf-style format string, followed by the
+ * variables to use in formating the string.
+ */
+ int printf(const char* format, ...);
+
+ /* Function: scanf
+ * Read a formated string
+ *
+ * Variables:
+ * format - A scanf-style format string,
+ * followed by the pointers to variables to store the results.
+ */
+ int scanf(const char* format, ...);
+
+ /* Function: readable
+ * Determine if there is a character available to read
+ *
+ * Variables:
+ * returns - 1 if there is a character available to read, else 0
+ */
+ int readable();
+
+ /* Function: writeable
+ * Determine if there is space available to write a character
+ *
+ * Variables:
+ * returns - 1 if there is space to write a character, else 0
+ */
+ int writeable();
+
+ /* Function: attach
+ * Attach a function to call whenever a serial interrupt is generated
+ *
+ * Variables:
+ * fptr - A pointer to a void function, or 0 to set as none
+ */
+ void attach(void (*fptr)(void));
+
+ /* Function: attach
+ * Attach a member function to call whenever a serial interrupt is generated
+ *
+ * Variables:
+ * tptr - pointer to the object to call the member function on
+ * mptr - pointer to the member function to be called
+ */
+ template<typename T>
+ void attach(T* tptr, void (T::*mptr)(void));
+
+#endif
+
+protected:
+ PinName _txpin;
+ int _pinfunc;
+
+ virtual int _putc(int c);
+ virtual int _getc(void);
+
+}; // End class SerialHalfDuplex
+
+} // End namespace
+
+#endif
--- a/mbed.h Tue May 18 16:04:21 2010 +0000 +++ b/mbed.h Thu Jun 03 11:17:50 2010 +0000 @@ -6,7 +6,7 @@ #ifndef MBED_H #define MBED_H -#define MBED_LIBRARY_VERSION 21 +#define MBED_LIBRARY_VERSION 22 // Useful C libraries #include <stdio.h> @@ -32,7 +32,10 @@ #include "AnalogOut.h" #include "PwmOut.h" #include "Serial.h" +#include "SerialHalfDuplex.h" #include "SPI.h" +#include "SPISlave.h" +#include "SPIHalfDuplex.h" #include "I2C.h" #include "Ethernet.h" #include "CAN.h"
--- a/wait_api.h Tue May 18 16:04:21 2010 +0000
+++ b/wait_api.h Thu Jun 03 11:17:50 2010 +0000
@@ -1,3 +1,23 @@
+/* Title: wait
+ * Generic wait functions.
+ *
+ * These provide simple NOP type wait capabilities.
+ *
+ * Example:
+ * > #include "mbed.h"
+ * >
+ * > DigitalOut heartbeat(LED1);
+ * >
+ * > int main() {
+ * > while (1) {
+ * > heartbeat = 1;
+ * > wait(0.5);
+ * > heartbeat = 0;
+ * > wait(0.5);
+ * > }
+ * > }
+ */
+
/* mbed Microcontroller Library - wait_api
* Copyright (c) 2009 ARM Limited. All rights reserved.
* sford
@@ -12,8 +32,29 @@
extern "C" {
#endif
+/* Function: wait
+ * Waits for a number of seconds, with microsecond resolution (within
+ * the accuracy of single precision floating point).
+ *
+ * Variables:
+ * s - number of seconds to wait
+ */
void wait(float s);
+
+/* Function: wait_ms
+ * Waits a number of milliseconds.
+ *
+ * Variables:
+ * ms - the whole number of milliseconds to wait
+ */
void wait_ms(int ms);
+
+/* Function: wait_us
+ * Waits a number of microseconds.
+ *
+ * Variables:
+ * us - the whole number of microseconds to wait
+ */
void wait_us(int us);
#ifdef __cplusplus
