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.
This commit is contained in:
Dean Camera 2010-12-26 14:25:34 +00:00
parent 39ac72f2d1
commit 2073b96d82
18 changed files with 266 additions and 23 deletions

View file

@ -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__

View file

@ -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
*
* @{
*/

View file

@ -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.

View file

@ -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
*
* @{
*/

View file

@ -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
*
* @{
*/

View file

@ -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)
}

View file

@ -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__