ATtiny85 Template Code
Code snippets for the ATtiny85
 All Files Functions Variables Typedefs Enumerations Enumerator Macros
softuart.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------*
2 * Software UART for ATtiny processors
3 *---------------------------------------------------------------------------*
4 * 14-Apr-2014 ShaneG
5 *
6 * Provides an implementation of a UART for serial communications. Includes
7 * some formatted output utility functions and debug output support.
8 *--------------------------------------------------------------------------*/
9 #ifndef __SOFTUART_H
10 #define __SOFTUART_H
11 
12 //--- Required definitions
13 #include <stdint.h>
14 #include <avr/pgmspace.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 //---------------------------------------------------------------------------
21 // Core operations
22 //---------------------------------------------------------------------------
23 
26 void uartInit();
27 
34 void uartSend(char ch);
35 
45 uint8_t uartAvail();
46 
55 char uartRecv();
56 
57 //---------------------------------------------------------------------------
58 // Basic output for data types.
59 //---------------------------------------------------------------------------
60 
68 void uartPrint(const char *cszString);
69 
77 void uartPrintP(const char *cszString);
78 
85 void uartInt(uint16_t value);
86 
93 void uartHex(uint16_t value);
94 
95 //---------------------------------------------------------------------------
96 // Formatted output
97 //---------------------------------------------------------------------------
98 
120 void uartFormat(const char *cszString, ...);
121 
143 void uartFormatP(const char *cszString, ...);
144 
145 //---------------------------------------------------------------------------
146 // Debugging output support (requires formatted print functions)
147 //---------------------------------------------------------------------------
148 
149 #if defined(DEBUG)
150 # define PRINT(msg) uartPrintP(PSTR("DEBUG: ")), uartPrintP(PSTR(msg))
151 # define PRINTF(fmt, ...) uartPrintP(PSTR("DEBUG: ")), uartFormatP(PSTR(fmt), __VA_ARGS__)
152 #else
153 # define PRINT(msg)
154 # define PRINTF(fmt, ...)
155 #endif
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #endif /* __SOFTUART_H */
void uartInt(uint16_t value)
Definition: uart_print.c:50
void uartInit()
Definition: uart_send.c:30
char uartRecv()
Definition: uart_recv.c:65
void uartSend(char ch)
Definition: uart_send.c:52
uint8_t uartAvail()
Definition: uart_recv.c:51
void uartPrint(const char *cszString)
Definition: uart_print.c:22
void uartFormatP(const char *cszString,...)
Definition: uart_format.c:119
void uartFormat(const char *cszString,...)
Definition: uart_format.c:82
void uartPrintP(const char *cszString)
Definition: uart_print.c:36
void uartHex(uint16_t value)
Definition: uart_print.c:74