aboutsummaryrefslogtreecommitdiff
path: root/LUFA/Drivers/Peripheral
diff options
context:
space:
mode:
authorDean <Dean@d5102386-fcda-11dd-9fdb-3debd5008f28>2010-12-26 14:25:34 +0000
committerDean <Dean@d5102386-fcda-11dd-9fdb-3debd5008f28>2010-12-26 14:25:34 +0000
commitbeda2c5f54a97c4e76c648120d2212705189a906 (patch)
tree680767a0fba855e26799e392a59d4b0b6d8be4df /LUFA/Drivers/Peripheral
parent0a7816059e8606337381c8d9c70f3f0bb68da52e (diff)
Added basic driver example use code to the library documentation.
Made the USARTStream global public and documented in the SerialStream module, allowing for the serial USART stream to be accessed via its handle rather than via the implicit stdout and stdin streams. git-svn-id: http://lufa-lib.googlecode.com/svn/trunk@1615 d5102386-fcda-11dd-9fdb-3debd5008f28
Diffstat (limited to 'LUFA/Drivers/Peripheral')
-rw-r--r--LUFA/Drivers/Peripheral/ADC.h3
-rw-r--r--LUFA/Drivers/Peripheral/AVRU4U6U7/ADC.h18
-rw-r--r--LUFA/Drivers/Peripheral/AVRU4U6U7/TWI.h42
-rw-r--r--LUFA/Drivers/Peripheral/SPI.h20
-rw-r--r--LUFA/Drivers/Peripheral/Serial.h12
-rw-r--r--LUFA/Drivers/Peripheral/SerialStream.h30
-rw-r--r--LUFA/Drivers/Peripheral/TWI.h3
7 files changed, 123 insertions, 5 deletions
diff --git a/LUFA/Drivers/Peripheral/ADC.h b/LUFA/Drivers/Peripheral/ADC.h
index b0c6f373..0fba2d10 100644
--- a/LUFA/Drivers/Peripheral/ADC.h
+++ b/LUFA/Drivers/Peripheral/ADC.h
@@ -48,6 +48,9 @@
* Hardware ADC driver. This module provides an easy to use driver for the hardware
* ADC present on many AVR models, for the conversion of analogue signals into the
* digital domain.
+ *
+ * \note The exact API for this driver may vary depending on the target used - see
+ * individual target module documentation for the API specific to your target processor.
*/
#ifndef __ADC_H__
diff --git a/LUFA/Drivers/Peripheral/AVRU4U6U7/ADC.h b/LUFA/Drivers/Peripheral/AVRU4U6U7/ADC.h
index 4790668c..3e736864 100644
--- a/LUFA/Drivers/Peripheral/AVRU4U6U7/ADC.h
+++ b/LUFA/Drivers/Peripheral/AVRU4U6U7/ADC.h
@@ -47,6 +47,24 @@
* \note This file should not be included directly. It is automatically included as needed by the ADC driver
* dispatch header located in LUFA/Drivers/Peripheral/ADC.h.
*
+ * <b>Example Usage:</b>
+ * \code
+ * // Initialise the ADC driver before first use
+ * ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_32);
+ *
+ * // Must setup the ADC channel to read beforehand
+ * ADC_SetupChannel(1);
+ *
+ * // Perform a single conversion of the ADC channel 1
+ * ADC_GetChannelReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | ADC_CHANNEL1);
+ * printf("Conversion Result: %d\r\n", ADC_GetResult());
+ *
+ * // Start reading ADC channel 1 in free running (continuous conversion) mode
+ * ADC_StartReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | ADC_CHANNEL1);
+ * while (!(ADC_IsReadingComplete())) {};
+ * printf("Conversion Result: %d\r\n", ADC_GetResult());
+ * \endcode
+ *
* @{
*/
diff --git a/LUFA/Drivers/Peripheral/AVRU4U6U7/TWI.h b/LUFA/Drivers/Peripheral/AVRU4U6U7/TWI.h
index 67171b3f..c6fb4200 100644
--- a/LUFA/Drivers/Peripheral/AVRU4U6U7/TWI.h
+++ b/LUFA/Drivers/Peripheral/AVRU4U6U7/TWI.h
@@ -45,6 +45,37 @@
* \note This file should not be included directly. It is automatically included as needed by the TWI driver
* dispatch header located in LUFA/Drivers/Peripheral/TWI.h.
*
+ * <b>Example Usage:</b>
+ * \code
+ * // Initialise the TWI driver before first use
+ * TWI_Init();
+ *
+ * // Start a write session to device at address 0xA0 with a 10ms timeout
+ * if (TWI_StartTransmission(0xA0 | TWI_ADDRESS_WRITE, 10))
+ * {
+ * TWI_SendByte(0x01);
+ * TWI_SendByte(0x02);
+ * TWI_SendByte(0x03);
+ *
+ * // Must stop transmission afterwards to release the bus
+ * TWI_StopTransmission();
+ * }
+ *
+ * // Start a read session to device at address 0xA0 with a 10ms timeout
+ * if (TWI_StartTransmission(0xA0 | TWI_ADDRESS_READ, 10))
+ * {
+ * uint8_t Byte1, Byte2, Byte3;
+ *
+ * // Read three bytes, acknowledge after the third byte is received
+ * TWI_ReceiveByte(&Byte1, false);
+ * TWI_ReceiveByte(&Byte2, false);
+ * TWI_ReceiveByte(&Byte3, true);
+ *
+ * // Must stop transmission afterwards to release the bus
+ * TWI_StopTransmission();
+ * }
+ * \endcode
+ *
* @{
*/
@@ -70,6 +101,17 @@
#endif
/* Public Interface - May be used in end-application: */
+ /* Macros: */
+ /** TWI slave device address mask for a read session. Mask with a slave device base address to obtain
+ * the correct TWI bus address for the slave device when reading data from it.
+ */
+ #define TWI_ADDRESS_READ 0x00
+
+ /** TWI slave device address mask for a write session. Mask with a slave device base address to obtain
+ * the correct TWI bus address for the slave device when writing data to it.
+ */
+ #define TWI_ADDRESS_WRITE 0x01
+
/* Inline Functions: */
/** Initialises the TWI hardware into master mode, ready for data transmission and reception. This must be
* before any other TWI operations.
diff --git a/LUFA/Drivers/Peripheral/SPI.h b/LUFA/Drivers/Peripheral/SPI.h
index 4e1fd09c..ff45bc3a 100644
--- a/LUFA/Drivers/Peripheral/SPI.h
+++ b/LUFA/Drivers/Peripheral/SPI.h
@@ -45,6 +45,26 @@
* Driver for the hardware SPI port available on most AVR models. This module provides
* an easy to use driver for the setup of and transfer of data over the AVR's SPI port.
*
+ * <b>Example Usage:</b>
+ * \code
+ * // Initialise the SPI driver before first use
+ * SPI_Init(SPI_SPEED_FCPU_DIV_2 | SPI_ORDER_MSB_FIRST | SPI_SCK_LEAD_FALLING |
+ * SPI_SAMPLE_TRAILING | SPI_MODE_MASTER);
+ *
+ * // Send several bytes, ignoring the returned data
+ * SPI_SendByte(0x01);
+ * SPI_SendByte(0x02);
+ * SPI_SendByte(0x03);
+ *
+ * // Receive several bytes, sending a dummy 0x00 byte each time
+ * uint8_t Byte1 = SPI_ReceiveByte();
+ * uint8_t Byte2 = SPI_ReceiveByte();
+ * uint8_t Byte3 = SPI_ReceiveByte();
+ *
+ * // Send a byte, and store the received byte from the same transaction
+ * uint8_t ResponseByte = SPI_TransferByte(0xDC);
+ * \endcode
+ *
* @{
*/
diff --git a/LUFA/Drivers/Peripheral/Serial.h b/LUFA/Drivers/Peripheral/Serial.h
index 2fca02b9..f40201de 100644
--- a/LUFA/Drivers/Peripheral/Serial.h
+++ b/LUFA/Drivers/Peripheral/Serial.h
@@ -45,6 +45,18 @@
* Hardware serial USART driver. This module provides an easy to use driver for
* the setup of and transfer of data over the AVR's USART port.
*
+ * <b>Example Usage:</b>
+ * \code
+ * // Initialise the serial USART driver before first use, with 9600 baud (and no double-speed mode)
+ * Serial_Init(9600, false);
+ *
+ * // Send a string through the USART
+ * Serial_TxString("Test String\r\n");
+ *
+ * // Receive a byte through the USART
+ * uint8_t DataByte = Serial_RxByte();
+ * \endcode
+ *
* @{
*/
diff --git a/LUFA/Drivers/Peripheral/SerialStream.h b/LUFA/Drivers/Peripheral/SerialStream.h
index 87478ee2..bef52ac9 100644
--- a/LUFA/Drivers/Peripheral/SerialStream.h
+++ b/LUFA/Drivers/Peripheral/SerialStream.h
@@ -47,8 +47,24 @@
* \section Module Description
* Serial stream driver for the USART subsystem on supported USB AVRs. This makes use of the functions in the
* regular USART driver (see \ref Group_Serial), but allows the avr-libc standard stream functions (printf,
- * puts, etc.) to work with the
- * USART.
+ * puts, etc.) to work with the USART. Upon configuration, this will redirect the standard input and output
+ * streams to the USART.
+ *
+ * <b>Example Usage:</b>
+ * \code
+ * // Initialise the Serial Stream driver before first use, with 9600 baud (and no double-speed mode)
+ * SerialStream_Init(9600, false);
+ *
+ * // Write a string to the USART via the implicit stdout stream
+ * printf("Test String using stdout\r\n");
+ *
+ * // Write a string to the USART via the explicit USART stream
+ * fprintf(&USARTStream, "Test String using explicit stream handle\r\n");
+ *
+ * // Read in an integer from the USART using the implicit stdin stream
+ * uint16_t TestValue;
+ * scanf("%d", &TestValue);
+ * \endcode
*
* @{
*/
@@ -69,9 +85,6 @@
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
- /* External Variables: */
- extern FILE USARTStream;
-
/* Function Prototypes: */
#if defined(__INCLUDE_FROM_SERIALSTREAM_C)
static int SerialStream_TxByte(char DataByte,
@@ -105,6 +118,13 @@
Serial_ShutDown();
}
+ /* External Variables: */
+ /** Named stream for the USART, once \ref SerialStream_Init() has been called. This may be used with the
+ * file based stream functions (fprintf, fscanf, etc.) that require a handle to the stream rather than
+ * using the stdin and stdout named streams.
+ */
+ extern FILE USARTStream;
+
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
diff --git a/LUFA/Drivers/Peripheral/TWI.h b/LUFA/Drivers/Peripheral/TWI.h
index c85440e4..e8cc834c 100644
--- a/LUFA/Drivers/Peripheral/TWI.h
+++ b/LUFA/Drivers/Peripheral/TWI.h
@@ -48,6 +48,9 @@
* \section Module Description
* Master Mode Hardware TWI driver. This module provides an easy to use driver for the hardware
* TWI present on many AVR models, for the transmission and reception of data on a TWI bus.
+ *
+ * \note The exact API for this driver may vary depending on the target used - see
+ * individual target module documentation for the API specific to your target processor.
*/
#ifndef __TWI_H__