-
Notifications
You must be signed in to change notification settings - Fork 0
/
uart.h
120 lines (106 loc) · 4.58 KB
/
uart.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**************************************************************************//**
* @file uart.h
* @brief Universal asynchronous receiver/transmitter header
* @author Silicon Labs
* @version 1.00
******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
* DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
* obligation to support this Software. Silicon Labs is providing the
* Software "AS IS", with no express or implied warranties of any kind,
* including, but not limited to, any implied warranties of merchantability
* or fitness for any particular purpose or warranties against infringement
* of any proprietary rights of a third party.
*
* Silicon Labs will not be liable for any consequential, incidental, or
* special damages, or any other relief, or for any claim by any third party,
* arising from your use of this Software.
*
******************************************************************************/
#ifndef SRC_UART_H_
#define SRC_UART_H_
#include <em_leuart.h>
#include <em_gpio.h>
#include "sleep.h"
#define LEUART_EM_BLOCK 3 // block EM3 to work down to EM2
#define UART_DATA_BITS leuartDatabits8
#define UART_ENABLE leuartEnable
#define UART_DISABLE leuartDisable
#define UART_PARITY leuartNoParity
#define UART_STOP_BITS leuartStopbits1
#define UART_BAUD_RATE 9600
#define UART_REF_FREQ 0
#define UART_OFF 0
#define UART_ON 1
#define TX_PORT gpioPortD
#define TX_PIN 10
#define RX_PORT gpioPortD
#define RX_PIN 11
#define TX_BUFFER_SIZE 7
#define RECEIVE_BUFFER_SIZE 1000
// ASCII defines
#define DECIMAL_POINT 0x2E
#define SPACE 0x20
#define ASCII_OFFSET 48
#define NEGATIVE_SIGN 0x2D
#define POSITIVE_SIGN 0x2B
#define QUESTION_MARK 0x3F
#define HASHTAG 0x23
#define LOWER_C 0x63
#define UPPER_C 0x43
#define LOWER_D 0x64
#define UPPER_D 0x44
#define LOWER_F 0x66
#define UPPER_F 0x46
#define CF_CMD_IDX 0x02
#define D_CMD_IDX 0x01
/******************************************************************************
* @brief Initialize LEUART peripheral
* @param none
* @return none
*****************************************************************************/
void uart_init(void);
/******************************************************************************
* @brief Send one byte of data via LEUART
* @param data = data to send
* @return none
*****************************************************************************/
void UART_send_byte(uint8_t data);
/******************************************************************************
* @brief Send n bytes of data via LEUART
* @param data = string of data to send, length = length of data
* @return none
*****************************************************************************/
void UART_send_n(char * data, uint32_t length);
/******************************************************************************
* @brief Enable interrupts for LEUART
* @param none
* @return none
*****************************************************************************/
void LEUART0_Interrupt_Enable(void);
/******************************************************************************
* @brief Disable interrupts for LEUART
* @param none
* @return none
*****************************************************************************/
void LEUART0_Interrupt_Disable(void);
/******************************************************************************
* @brief Convert a number from float to ASCII and send over LEUART
* @param number = number to convert and send
* @return none
*****************************************************************************/
void UART_ftoa_send(float number);
#endif /* SRC_UART_H_ */