BPLightContraption
 All Classes Namespaces Files Functions Variables Macros Pages
serial.h
Go to the documentation of this file.
1 /*! \file
2  * \brief Microcontroller serial communications functions
3  * \details Definitions in serial.c
4  * \author Benjamin Pritchard (ben@bennyp.org)
5  * \copyright 2013 Benjamin Pritchard. Released under the MIT License
6  */
7 
8 #ifndef SERIAL_H
9 #define SERIAL_H
10 
11 /*! \def MYUBRR
12  \brief Integer representing the baud rate. See the
13  ATMega1280 data sheet
14 */
15 
16 /* Set MYUBRR to one of the below corresponding
17  to the baud rate you want */
18 
19 /* 2400 baud */
20 /*#define MYUBRR 416*/
21 
22 /* 9600 baud */
23 /*#define MYUBRR 103*/
24 
25 /* 28.8k baud */
26 /*#define MYUBRR 34*/
27 
28 /* 38.4k baud */
29 #define MYUBRR 25
30 
31 
32 /*! \brief Initializes the serial port
33 
34  Currently, the port is set to 8N1 and the baud rate specified
35  by MYUBRR. This function also enables the receiver interrupt.
36 */
37 void Serial_init(void);
38 
39 
40 /*! \brief Flushes the serial port receive buffer
41 
42  It will block until it gets something to receive
43 */
44 void Serial_flush(void);
45 
46 
47 /*! \brief Retrieve a byte from the receive register
48 
49  Will block until there is something to be retrieved
50 */
51 uint8_t Serial_receive(void);
52 
53 
54 /*! \brief Returns 1 if there is something to be
55  read from the serial port, zero otherwise */
56 uint8_t Serial_needsreading(void);
57 
58 
59 
60 /*! \brief Sends a byte through the serial port */
61 void Serial_send( uint8_t c );
62 
63 /*! \brief Sends 2 bytes through the serial port */
64 void Serial_send2( uint8_t c1, uint8_t c2 );
65 
66 /*! \brief Sends 3 bytes through the serial port */
67 void Serial_send3( uint8_t c1, uint8_t c2, uint8_t c3 );
68 
69 /*! \brief Sends 4 bytes through the serial port */
70 void Serial_send4( uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4 );
71 
72 /*! \brief Sends 5 bytes through the serial port */
73 void Serial_send5( uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4 , uint8_t c5);
74 
75 /*! \brief Sends 6 bytes through the serial port */
76 void Serial_send6( uint8_t c1, uint8_t c2, uint8_t c3, uint8_t c4 , uint8_t c5, uint8_t c6);
77 
78 
79 /*! \brief Sends an array of bytes through the serial port
80 
81  \param[in] arr Array of bytes to send
82  \param[in] len Number of bytes to send
83 */
84 void Serial_sendarr( const uint8_t * arr, uint8_t len);
85 
86 #endif