Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/APIs/communication/ble.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Communication options
1 change: 1 addition & 0 deletions docs/APIs/communication/communication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Communication options
1 change: 1 addition & 0 deletions docs/APIs/communication/ethernet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Communication options
1 change: 1 addition & 0 deletions docs/APIs/communication/network_stack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Communication options
1 change: 1 addition & 0 deletions docs/APIs/communication/radio.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Communication options
1 change: 1 addition & 0 deletions docs/APIs/communication/wifi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Communication options
53 changes: 53 additions & 0 deletions docs/APIs/interfaces/USBDevice/USBAudio.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# USBAudio

The USBAudio class enables the mbed to be recognized as an audio device. With this interface, you can receive and send audio packets from and to a computer (play music) over USB. For instance you can connect a speaker or an I2S/I2C chip to the mbed and play the stream received from the computer.

The USB connector should be attached to

* **p31 (D+), p32 (D-) and GND** for the **LPC1768 and the LPC11U24**
* The on-board USB connector of the **FRDM-KL25Z**

<span class="warnings">**Warning:** Change the default sound board </br>To send audio packets to the mbed, you have to change the default sound board used by the Operating system.</br>
On Windows, you can do this by clicking on: **Control panel** > **Hardware and Sound** > **Manage audio device** in the Sound section > Select the mbed Audio device and press **Set default** </span>

## Hello World

[![View code](https://www.mbed.com/embed/?url=https://developer.mbed.org/users/samux/code/USBAudio_HelloWorld/)](https://developer.mbed.org/users/samux/code/USBAudio_HelloWorld/file/tip/main.cpp)

## API

[![View code](https://www.mbed.com/embed/?url=<http://mbed.org/users/mbed_official/code/USBDevice/)](http://mbed.org/users/mbed_official/code/USBDevice/file/eaa07ce86d49/main.cpp>)

## More examples

The following program is sending to a speaker all audio packets received. This means that you can play a music on your computer and listen it on your Mbed.

[![View code](https://www.mbed.com/embed/?url=<http://mbed.org/users/samux/)](http://mbed.org/users/samux/file/USBAUDIO_speaker/main.cpp>)

The USBAudio playback example sends back to the computer all audio packets received. You can then listen for incoming audio packets with [audacity](http://audacity.sourceforge.net/) for instance.

[![View code](https://www.mbed.com/embed/?url=<http://mbed.org/users/samux/)](http://mbed.org/users/samux/file/USBAudioPlayback/main.cpp>)

## In details

### Audio packet length

In this section, I will explain what kind of packets are received according to the frequency and the number of channels.

An audio packet is received each millisecond. So let's say that a frequency of 48 kHz has been chosen with 2 channels (stereo). Knowing that each sample of a packet are 16 bits long, 48 * 2 bytes will be received each millisecond for one channel. In total, for 2 channels, 48 * 2 * 2 bytes will be received.

<span class="tips">**Tip:** Compute the length packet </br>``AUDIO_LENGTH_PACKET = (FREQ / 500) * nb_channel``</span>

### How to interpret an audio packet

The read() function fills an uint8_t array. But these data has to be interpreted as 16 bits signed data (PCM). Then PCM values can be handled according to the number of channels.

### MONO: single channel

<span class="images">![](../../Images/mono.png)</span>

### STEREO: 2 channels

When there are 2 channels, values for channel 1 and values for channel 2 will alternate as explained in the following diagram:

<span class="images">![](../../Images/stereo.png)</span>
79 changes: 79 additions & 0 deletions docs/APIs/interfaces/USBDevice/USBDevice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
## USB Device

The Universal Serial Bus (USB) is the most widely used bus in today's computer. USB has particularly been designed to standardize connections between the computer and peripherals. For instance, keyboards, mice, USB audio devices, printers, scanners, disk drives or cameras can use the same bus to exchange data with a computer.

A USB device stack has been developed in order to provide all the great capabilities of USB to mbed.

# Boards supporting USB Device

LPC1768 | LPC11U24 | FRDM-KL25Z
---|---|---
![](../../Images/lpc1768_usb.png) | ![](../../Images/LPC11U24_usb.png) | ![](../../Images/FRDM_KL25Z.png) |

<span class="images">![](../../Images/mbed_usb_drawing.png)</span>

# mbed as a USB device

<span class="images">![](../../Images/capa2.png)</span>

## Mouse

The USBMouse class allows to emulate a mouse with your mbed. You can either chose a relative or absolute mouse. This class allows you to:

* Move the cursor on the screen
* Click
* Scroll

For more information, please visit [USBMouse](USBMouse.md).

## Keyboard

The USBKeyboard class allows to use mbed as a keyboard. You can:

* Send basic keys
* Send "modified keys" such as: CTRL + 'c'
* Send media keys (Mute, Volume Up, Volume Down, next track, ...)

For more information, please visit [USBKeyboard](USBKeyboard.md).

## Mouse and Keyboard

If you want to have all capabilities from a mouse and a keyboard at the same time, you can use the USBMouseKeyboard class.

For more information, please visit [USBMouseKeyboard](USBMouseKeyboard.md).

## Human Interface Device (HID)

The USBHID class is a great opportunity to send and receive raw data to a custom program. This allows you to design your own USB device without any specific drivers on the host side as all operating systems have a built-in HID driver.

For more information, please visit [USBHID](USBHID.md).

## USBSerial

The USBSerial class uses the USB interface to emulate a serial port. The mbed is recognized by the computer as a serial port. This is a great solution to communicate easily between the microcontroller and a computer.

For more information, please visit [USBSerial](USBSerial.md).

## USBMIDI

Using this library, you can do things like send MIDI messages to a computer (such as to record in a sequencer, or trigger a software synthesiser) and receive messages from a computer (such as actuate things based on MIDI events).

For more information, please visit [USBMIDI](USBMIDI.md).

## USBAudio

The USBAudio class enables the mbed to be recognized as an audio device. With this interface, you can receive audio packet from the computer (play music) and receive them over USB. For instance you connect a speaker or an I2S/I2C chip to the mbed and play the stream received from the computer.

## USBMSD

The USBMSD interface is used to emulate a mass storage device over USB. You can use this class to store or load data to and from a storage chip (SDcard, flash,...). This class implements the MSD protocol and calls pure virtual functions such as **disk_initialize**, **disk_write** or **disk_read** to interact with a storage chip.

For more information, please visit [USBMSD](USBMSD.md).

## USB HID Bindings

[USBHID bindings](http://mbed.org/cookbook/USBHID-bindings-) - Design your own USB device on top of USBHID class by developing programs in different languages and running on different platforms.

# More information

If you want information concerning the stack architecture, visit the [USBDevice stack architecture](http://mbed.org/users/samux/notebook/usbdevice-stack-architecture/).
63 changes: 63 additions & 0 deletions docs/APIs/interfaces/USBDevice/USBHID.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# USBHID

The USBHID class can be used to send and receive messages over USB. For instance, you can define your own protocol and communicate between your computer and the Mbed with all capabilities of a USB communication. To use USBHID, you need a script running on the host side (computer). For instance on a 32 bits Windows 7 machine, you can use [pywinusb](http://code.google.com/p/pywinusb/).

The USB connector should be attached to

* **p31 (D+), p32 (D-) and GND** for the **LPC1768 and the LPC11U24**
* The on-board USB connector of the **FRDM-KL25Z**

## Hello World

[![View code](https://www.mbed.com/embed/?url=https://developer.mbed.org/users/samux/code/USBHID_HelloWorld/)](https://developer.mbed.org/users/samux/code/USBHID_HelloWorld/file/tip/main.cpp)

## API

[![View code](https://www.mbed.com/embed/?url=<http://mbed.org/users/mbed_official/code/USBDevice/)](http://mbed.org/users/mbed_official/code/USBDevice/file/tip/main.cpp>)

## Details

You can choose the length of exchanged packets. In this example, mbed leds are controlled by four switches. When you press a button, there is a message sent containing buttons state. According to this message, the mbed will receive back a new message to light on leds.
We need one byte to control leds and one byte to send buttons state.

```
#include "mbed.h"
#include "USBHID.h"

//We declare a USBHID device: it can send 1 byte and receive 1 byte
USBHID hid(1, 1);

//Two reports where will be stored values to send and received
HID_REPORT recv_report;
HID_REPORT send_report;

//Bus of leds
BusOut leds(LED1,LED2,LED3,LED4);

//Bus of buttons
BusInOut buttons(p21, p22, p23, p24);

int main(void) {
uint8_t p_bus = 0;
send_report.length = 1;

while (1) {
//If a data is received, update led bus
if (hid.readNB(&recv;_report)) {
leds = recv_report.data[0];
}

//if the bus of buttons has changed, send a report
if (buttons.read() != p_bus) {
p_bus = buttons.read();
send_report.data[0] = p_bus;
hid.send(&send;_report);
}
wait(0.01);
}
}
```

## Contribute to the USBHID bindings webpage!

A great thing would be to develop in several languages running on different platforms, programs able to communicate with the mbed over USB. Visit the [USBHID bindings webpage](http://mbed.org/cookbook/USBHID-bindings-) and develop your own USBHID device!
59 changes: 59 additions & 0 deletions docs/APIs/interfaces/USBDevice/USBKeyboard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# USBKeyboard


<span class="images">[![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/NKSlkUcoOjY/0.jpg)](http://www.youtube.com/watch?v=NKSlkUcoOjY)</span>

The USBKeyboard interface is used to emulate a keyboard over the USB port. You can type strings and send keycodes, send keys with modifiers (e.g. CTRL + 's'), function keys and also the media control keys

The USB connector should be attached to

* **p31 (D+), p32 (D-) and GND** for the **LPC1768 and the LPC11U24**
* The on-board USB connector of the **FRDM-KL25Z**

## Hello World

[![View code](https://www.mbed.com/embed/?url=https://developer.mbed.org/users/samux/code/USBKeyboard_HelloWorld/)](https://developer.mbed.org/users/samux/code/USBKeyboard_HelloWorld/file/tip/main.cpp)

## API

[![View code](https://www.mbed.com/embed/?url=<http://mbed.org/users/mbed_official/code/USBDevice/)](http://mbed.org/users/mbed_official/code/USBDevice/file/6d85e04fb59f/main.cpp>)

## More examples

Program which controls sound and tracks of your playlist with switches:

```
#include "mbed.h"
#include "USBKeyboard.h"

USBKeyboard keyboard;

//Bus of buttons
BusInOut buttons(p21, p22, p23, p24, p25, p26, p29);

int main(void) {
uint8_t p_bus = 0;

while (1) {
//if the bus of buttons has changed, send a report
if (buttons.read() != p_bus) {
p_bus = buttons.read();
if(p_bus & 0x01)
keyboard.mediaControl(KEY_MUTE);
if(p_bus & 0x02)
keyboard.mediaControl(KEY_VOLUME_DOWN);
if(p_bus & 0x04)
keyboard.mediaControl(KEY_VOLUME_UP);
if(p_bus & 0x08)
keyboard.mediaControl(KEY_NEXT_TRACK);
if(p_bus & 0x10)
keyboard.mediaControl(KEY_PLAY_PAUSE);
if(p_bus & 0x20)
keyboard.mediaControl(KEY_PREVIOUS_TRACK);
if(p_bus & 0x40)
keyboard.printf("Hello World\r\n");
}
wait(0.01);
}
}
```
26 changes: 26 additions & 0 deletions docs/APIs/interfaces/USBDevice/USBMIDI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# USBMIDI

<span class="images">[![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/pRiYQ6Dv-uY/0.jpg)](http://www.youtube.com/watch?v=pRiYQ6Dv-uY)</span>

The USBMIDI interface can be used to send and receive MIDI messages over USB using the standard USB-MIDI protocol.

Using this library, you can do things like send MIDI messages to a computer (such as to record in a sequencer, or trigger a software synthesiser) and receive messages from a computer (such as actuate things based on MIDI events)

The USB connector should be attached to

* **p31 (D+), p32 (D-) and GND** for the **LPC1768 and the LPC11U24**
* The on-board USB connector of the **FRDM-KL25Z**

## Hello World

[![View code](https://www.mbed.com/embed/?url=https://developer.mbed.org/users/samux/code/USBMIDI_HelloWorld/)](https://developer.mbed.org/users/samux/code/USBMIDI_HelloWorld/file/tip/main.cpp)

## API

[![View code](https://www.mbed.com/embed/?url=<http://mbed.org/users/mbed_official/code/USBDevice/)](http://mbed.org/users/mbed_official/code/USBDevice/file/6d85e04fb59f/main.cpp>)

## More example

In this example, you can control the MIDI message sent with buttons

[![View code](https://www.mbed.com/embed/?url=https://developer.mbed.org/users/samux/code/USBMIDI_Receive/)](https://developer.mbed.org/users/samux/code/USBMIDI_Receive/file/tip/main.cpp)
48 changes: 48 additions & 0 deletions docs/APIs/interfaces/USBDevice/USBMSD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# USBMSD

The USBMSD interface is used to emulate a mass storage device over USB. You can use this class to store or load data to and from a storage chip (SDcard, flash,...). This class implements the MSD protocol and calls pure virtual functions such as ``disk_initialize``, ``disk_write`` or ``disk_read`` to interact with a storage chip. More information on how to use this class with your own chip can be found at the end of this document.

## Hardware

The USB connector should be attached to

* **p31 (D+), p32 (D-) and GND** for the **LPC1768 and the LPC11U24**
* The on-board USB connector of the **FRDM-KL25Z**

LPC1768 | LPC11U24| FRDM-KL25Z
---|---|---
![](../../Images/lpc1768_usbmsd.png) | ![](../../Images/lpc11us4_usbmsd.png) | ![](../../Images/kl25z_usbmsd.png)

## Hello World! with an SD card

The following program has been tested with a micro SD card(Transcend micro SD 1GB).

[![View code](https://www.mbed.com/embed/?url=https://developer.mbed.org/users/samux/code/USBMSD_SD_HelloWorld_Mbed/)](https://developer.mbed.org/users/samux/code/USBMSD_SD_HelloWorld_Mbed/file/tip/main.cpp)

[![View code](https://www.mbed.com/embed/?url=https://developer.mbed.org/users/samux/code/USBMSD_SD_HelloWorld_FRDM-KL25Z/)](https://developer.mbed.org/users/samux/code/USBMSD_SD_HelloWorld_FRDM-KL25Z/file/tip/main.cpp)

## API

[![View code](https://www.mbed.com/embed/?url=<http://mbed.org/users/mbed_official/code/USBDevice/)](http://mbed.org/users/mbed_official/code/USBDevice/file/eaa07ce86d49/main.cpp>)

## How to use USBMSD with your own chip ?

The USBMSD class implements the MSD protocol. It permits to access a memory chip (flash, sdcard,...) from a computer over USB. But this class doesn't work standalone, you need to subclass this class and define pure virtual functions which are called in USBMSD.

You have to inherit from USBMSD and define **ALL** the following pure virtual functions:

* virtual ``int disk_read(uint8_t * data, uint64_t block)``: function to read a block
* virtual ``int disk_write(const uint8_t * data, uint64_t block)``: function to write a block
* virtual ``int disk_initialize()``: function to initialize the memory
* virtual ``uint64_t disk_sectors()``: return the number of blocks
* virtual ``uint64_t disk_size()``: return the memory size
* virtual ``int disk_status()``: return the status of the storage chip (0: OK, 1: not initialized, 2: no medium in the drive, 4: write protection)

All functions names are compatible with the fat filesystem library. So you can imagine using your own class with USBMSD and the fat filesystem library in the same program. Just be careful because there are two different parts which will access the sd card. You can do a master/slave system using ``disk_status()``.

Once these functions defined, you can call ``connect()`` (at the end of the constructor of your class for instance) of USBMSD to connect your mass storage device. ``connect()`` will first call ``disk_status()`` to test the status of the disk. If ``disk_status()`` returns 1 (disk not initialized), then ``disk_initialize()`` is called. After this step, ``connect()`` will collect information such as the number of blocks and the memory size.

A class example which inherits from USBMSD has been developed in order to access an SD card. You can follow this example and write your own class to access your storage chip.

[![View code](https://www.mbed.com/embed/?url=<http://mbed.org/users/samux/)](http://mbed.org/users/samux/file/USBMSD_SD/main.cpp>)

Loading