SSD1306 OLED display driver 1.7.8 This library is developed to control SSD1306/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays

ssd1306_uart.h
Go to the documentation of this file.
1 /*
2 MIT License
3
4 Copyright (c) 2018, Alexey Dynda
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
32 #ifndef _SSD1306_UART_H_
33 #define _SSD1306_UART_H_
34
35 // This check is required if you want to use ssd1306_uart module outside ssd1306_library
36 #ifndef CONFIG_AVR_UART_AVAILABLE
37 #include "ssd1306_hal/io.h"
38 #endif
39
40 #if defined(CONFIG_AVR_UART_AVAILABLE) && defined(CONFIG_AVR_UART_ENABLE)
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 #include <stdint.h>
47
49 #define UART_BUFFER_RX 32 // :( Still need large buffer to process USART RX bytes
50
51 #ifndef DOXYGEN_SHOULD_SKIP_THIS
52 extern volatile uint8_t g_uart_put_ptr;
53
54 extern volatile uint8_t g_uart_buf[];
55
56 void uart_init_internal(uint32_t baud, uint8_t interrupt);
57 #endif
58
68 static inline void uart_init(uint32_t baud)
69 {
70 #ifdef UART_INTERRUPT_ENABLE
71 uart_init_internal(baud, 1);
72 #else
73 uart_init_internal(baud, 0);
74 #endif
75 }
76
85 void uart_send_byte(uint8_t c);
86
92 uint8_t uart_byte_available(void);
93
100 uint8_t uart_read_byte(void);
101
102 #ifndef DOXYGEN_SHOULD_SKIP_THIS
103 static inline void __uart_read_byte(void)
104 {
105 g_uart_buf[g_uart_put_ptr] = UDR0;
106 g_uart_put_ptr = (g_uart_put_ptr+1) & (UART_BUFFER_RX - 1);
107 }
108
109
110 #ifdef UART_INTERRUPT_ENABLE
111
112 ISR(USART_RX_vect, ISR_BLOCK)
113 {
114 if (bit_is_clear(UCSR0A, FE0)) // Do not perform error checks for now
115 {
116 __uart_read_byte();
117 }
118 else
119 {
120 volatile unsigned char data __attribute__((unused)) = UDR0;
121 }
122 }
123 #endif
124
125 #endif // DOXYGEN_SHOULD_SKIP_THIS
126
127 #ifdef __cplusplus
128 }
129 #endif
130
131 #endif
132
133 #endif
134
UART_BUFFER_RX
#define UART_BUFFER_RX
Definition: ssd1306_uart.h:49
uart_init
static void uart_init(uint32_t baud)
Initializes uart module.
Definition: ssd1306_uart.h:68
io.h
uart_read_byte
uint8_t uart_read_byte(void)
Reads byte from UART RX buffer.
Definition: ssd1306_uart.c:137
uart_byte_available
uint8_t uart_byte_available(void)
Returns non-zero code if there are bytes in RX buffer.
Definition: ssd1306_uart.c:128
uart_send_byte
void uart_send_byte(uint8_t c)
Sends single byte over UART.
Definition: ssd1306_uart.c:117