ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
Macros | Functions | Variables
uart.c File Reference

Uart driver for ESP8266. More...

#include "user_config.h"
#include "uart.h"
#include "uart_register.h"

Go to the source code of this file.

Macros

#define UARTS   2
 

Functions

void uart_rx_enable (uint8 uart_no)
 Enable receive interrupts for a uart. More...
 
void uart_rx_disable (uint8 uart_no)
 Disable receive interrupts for a uart. More...
 
void uart_tx_enable (uint8_t uart_no)
 Enable transmit interrupts for a uart. More...
 
void uart_tx_disable (uint8_t uart_no)
 Disable transmit interrupts for a uart. More...
 
void tx_fifo_flush (int uart_no)
 Flush transmit fifo for a uart. More...
 
void rx_fifo_flush (int uart_no)
 Flush receive fifo for a uart. More...
 
MEMSPACE int tx_fifo_used (int uart_no)
 Get the number of bytes used in transmit fifo. More...
 
MEMSPACE int tx_fifo_free (int uart_no)
 Get the number of bytes free in transmit fifo. More...
 
MEMSPACE int tx_fifo_empty (int uart_no)
 Test if the transmit fifo is empty. More...
 
MEMSPACE int rx_fifo_used (int uart_no)
 Get the number of bytes used in receive fifo. More...
 
MEMSPACE int rx_fifo_free (int uart_no)
 Get the number of bytes free in receive fifo. More...
 
MEMSPACE int rx_fifo_empty (int uart_no)
 Test if the receive fifo is empty. More...
 
MEMSPACE int tx_fifo_putb (int uart_no, uint8_t c)
 Add a byte to the trasmit fifo We assume that tx_fifo_free() was called! More...
 
MEMSPACE int rx_fifo_getb (int uart_no)
 Remove a byte from the receive fifo We assume that rx_fifo_used() was called! More...
 
MEMSPACE int tx_fifo_write (int uart_no, uint8_t *buf, int size)
 Write a data buffer to the transmit fifo Note: This function does not wait/block util there is enough free space to meet the request. So you must check that the return value matches the size. More...
 
MEMSPACE int rx_fifo_read (int uart_no, uint8_t *buf, int size)
 Read a data buffer from the receive fifo Note: This function does not wait/block util there is enough free space to meet the request. So you must check that the return value matches the size. More...
 
LOCAL MEMSPACE int uart_putb (uint8 uart_no, uint8 data)
 Polled Blocking I/O functions that poll. More...
 
LOCAL MEMSPACE int uart_getb (int uart_no)
 Read a byte from a uart Note: This function waits/blocks util the read can happen. More...
 
MEMSPACE int uart_putc (uint8 uart_no, char c)
 Write a byte from a uart with NL to CR/NL conversion Note: This function waits/blocks util the write can happen. More...
 
MEMSPACE int uart_getc (int uart_no)
 Read a byte from a uart with NL to CR/NL conversion Note: This function waits/blocks util the read can happen. More...
 
MEMSPACE int uart0_putc (uint8 c)
 Write a byte to uart0 with NL to CR/NL conversion Note: This function waits/blocks util the write can happen. More...
 
MEMSPACE int uart0_getc ()
 Read a byte from uart0 with NL to CR/NL conversion Note: This function waits/blocks util the read can happen. More...
 
MEMSPACE int uart1_putc (uint8 c)
 Write a byte to uart1 with NL to CR/NL conversion Note: This function waits/blocks util the write can happen. More...
 
MEMSPACE int uart1_getc ()
 Read a byte from uart1 with NL to CR/NL conversion Note: This function waits/blocks util the read can happen. More...
 
MEMSPACE void uart_flush (uint8_t uart_no)
 Flush TX buffer Note: This function waits/blocks util the write happen. More...
 
int kbhiteol (int uart_no)
 Has an EOL been read on stdin ? More...
 
int kbhit (int uart_no)
 Has ANY character been read in stdin. More...
 
void uart_callback (void *p)
 Uart interrupt callback function Process all receive and transmit events here. More...
 
MEMSPACE void UART_SetPrintPort (uint8 uart_no)
 Install debug uart. More...
 
MEMSPACE void uart_config (uint8 uart_no, uint32_t baud, uint8_t data_bits, uint8_t stop_bits, uint8_t parity)
 Uart configuration, baud rate, data and stop bits, parity. More...
 
MEMSPACE void uart_init (UartBaudRate uart0_br, UartBaudRate uart1_br)
 initialize uart0 and uart1 Defaults: 8 = data bits, 1 = stop bits, no parity More...
 
MEMSPACE void uart_reattach ()
 Reinitialize uart0 and uart1 calls uart_init() More...
 

Variables

int uart_debug_port = 0
 

Detailed Description

Uart driver for ESP8266.

Uart driver for ESP8266 based on Esprissif documents.

Copyright © 2015 Mike Gore, GPL License
You are free to use this code under the terms of GPL
please retain a copy of this notice in any code you use it in.

This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

See also
http://bbs.espressif.com/viewtopic.php?f=21&t=414
Copyright © 2015 Mike Gore, GPL License
You are free to use this code under the terms of GPL
please retain a copy of this notice in any code you use it in.

This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file uart.c.

Macro Definition Documentation

#define UARTS   2

Definition at line 34 of file uart.c.

Function Documentation

int kbhit ( int  uart_no)

Has ANY character been read in stdin.

Parameters
[in]uart_nouart number
Returns
byte read

Definition at line 585 of file uart.c.

Referenced by testpage().

int kbhiteol ( int  uart_no)

Has an EOL been read on stdin ?

Parameters
[in]uart_nouart number
Returns
byte read

Definition at line 572 of file uart.c.

Referenced by user_tasks().

MEMSPACE int rx_fifo_empty ( int  uart_no)

Test if the receive fifo is empty.

Parameters
[in]uart_nouart number
Returns
1 if empty, 0 otherwise

Definition at line 182 of file uart.c.

Referenced by uart_getb().

void rx_fifo_flush ( int  uart_no)

Flush receive fifo for a uart.

Parameters
[in]uart_nouart number
Returns
void

Definition at line 105 of file uart.c.

MEMSPACE int rx_fifo_free ( int  uart_no)

Get the number of bytes free in receive fifo.

Parameters
[in]uart_nouart number
Returns
bytes free

Definition at line 168 of file uart.c.

MEMSPACE int rx_fifo_getb ( int  uart_no)

Remove a byte from the receive fifo We assume that rx_fifo_used() was called!

Parameters
[in]uart_nouart number
Returns
c, (or 0 if fill user error)

Definition at line 217 of file uart.c.

Referenced by uart_getb().

MEMSPACE int rx_fifo_read ( int  uart_no,
uint8_t buf,
int  size 
)

Read a data buffer from the receive fifo Note: This function does not wait/block util there is enough free space to meet the request. So you must check that the return value matches the size.

Parameters
[in]uart_nouart number
[in]*bufoutput buffer
[in]sizesize of output buffer
Returns
number of bytes actually read from the fifo - may not be size!

Definition at line 264 of file uart.c.

MEMSPACE int rx_fifo_used ( int  uart_no)

Get the number of bytes used in receive fifo.

Parameters
[in]uart_nouart number
Returns
bytes in use

Definition at line 155 of file uart.c.

Referenced by rx_fifo_getb(), and rx_fifo_read().

MEMSPACE int tx_fifo_empty ( int  uart_no)

Test if the transmit fifo is empty.

Parameters
[in]uart_nouart number
Returns
1 if empty, 0 otherwise

Definition at line 143 of file uart.c.

Referenced by uart_flush().

void tx_fifo_flush ( int  uart_no)

Flush transmit fifo for a uart.

Parameters
[in]uart_nouart number
Returns
void

Definition at line 94 of file uart.c.

MEMSPACE int tx_fifo_free ( int  uart_no)

Get the number of bytes free in transmit fifo.

Parameters
[in]uart_nouart number
Returns
bytes free

Definition at line 130 of file uart.c.

Referenced by tx_fifo_putb(), tx_fifo_write(), and uart_putb().

MEMSPACE int tx_fifo_putb ( int  uart_no,
uint8_t  c 
)

Add a byte to the trasmit fifo We assume that tx_fifo_free() was called!

Parameters
[in]uart_nouart number
[in]cbyte to add
Returns
c, (or 0 if full user error)

Definition at line 199 of file uart.c.

Referenced by uart_putb().

MEMSPACE int tx_fifo_used ( int  uart_no)

Get the number of bytes used in transmit fifo.

Parameters
[in]uart_nouart number
Returns
bytes in use

Definition at line 118 of file uart.c.

Referenced by uart_flush().

MEMSPACE int tx_fifo_write ( int  uart_no,
uint8_t buf,
int  size 
)

Write a data buffer to the transmit fifo Note: This function does not wait/block util there is enough free space to meet the request. So you must check that the return value matches the size.

Parameters
[in]uart_nouart number
[in]*bufoutput buffer
[in]sizesize of input buffer
Returns
number of bytes sent

Definition at line 237 of file uart.c.

MEMSPACE int uart0_getc ( void  )

Read a byte from uart0 with NL to CR/NL conversion Note: This function waits/blocks util the read can happen.

Returns
byte read

Definition at line 369 of file uart.c.

MEMSPACE int uart0_putc ( uint8  c)

Write a byte to uart0 with NL to CR/NL conversion Note: This function waits/blocks util the write can happen.

Parameters
[in]cbyte to write
Returns
void

Definition at line 358 of file uart.c.

MEMSPACE int uart1_getc ( void  )

Read a byte from uart1 with NL to CR/NL conversion Note: This function waits/blocks util the read can happen.

Returns
byte read

Definition at line 393 of file uart.c.

MEMSPACE int uart1_putc ( uint8  c)

Write a byte to uart1 with NL to CR/NL conversion Note: This function waits/blocks util the write can happen.

Parameters
[in]cbyte to write
Returns
void

Definition at line 382 of file uart.c.

void uart_callback ( void *  p)

Uart interrupt callback function Process all receive and transmit events here.

=================================================================

/**

Parameters
[in]*pcallback pointer - currently unused
Returns
void

Definition at line 604 of file uart.c.

MEMSPACE void uart_config ( uint8  uart_no,
uint32_t  baud,
uint8_t  data_bits,
uint8_t  stop_bits,
uint8_t  parity 
)

Uart configuration, baud rate, data and stop bits, parity.

Parameters
[in]uart_nouart number
[in]baudbaud
[in]data_bitsnumber of data bits, 5 .. 8
[in]stop_bitsnumber of stop bits, ONE_STOP_BIT|TWO_STOP_BIT
[in]parityparity, NO_PARITY,ODD_PARITY,EVEN_PARITY
Returns
void

Definition at line 714 of file uart.c.

MEMSPACE void uart_flush ( uint8_t  uart_no)

Flush TX buffer Note: This function waits/blocks util the write happen.

Returns
void

Definition at line 406 of file uart.c.

LOCAL MEMSPACE int uart_getb ( int  uart_no)

Read a byte from a uart Note: This function waits/blocks util the read can happen.

Parameters
[in]uart_nouart number
Returns
byte read

Definition at line 304 of file uart.c.

Referenced by uart_getc().

MEMSPACE int uart_getc ( int  uart_no)

Read a byte from a uart with NL to CR/NL conversion Note: This function waits/blocks util the read can happen.

Parameters
[in]uart_nouart number
Returns
byte read

Definition at line 337 of file uart.c.

Referenced by uart0_getc(), and uart1_getc().

MEMSPACE void uart_init ( UartBaudRate  uart0_br,
UartBaudRate  uart1_br 
)

initialize uart0 and uart1 Defaults: 8 = data bits, 1 = stop bits, no parity

Parameters
[in]uart0_brbaud rate for uart 0
[in]uart1_brbaud rate for uart 1
Returns
void

Definition at line 773 of file uart.c.

Referenced by setup().

LOCAL MEMSPACE int uart_putb ( uint8  uart_no,
uint8  data 
)

Polled Blocking I/O functions that poll.

Write a byte to a uart Note: This function waits/blocks util the write can happen

Parameters
[in]uart_nouart number
[in]databyte to write
Returns
void

Definition at line 289 of file uart.c.

Referenced by uart_putc().

MEMSPACE int uart_putc ( uint8  uart_no,
char  c 
)

Write a byte from a uart with NL to CR/NL conversion Note: This function waits/blocks util the write can happen.

Parameters
[in]uart_nouart number
[in]ccharacter
Returns
void

Definition at line 323 of file uart.c.

Referenced by _uart0_fn(), fatfs_ls(), uart0_putc(), and uart1_putc().

MEMSPACE void uart_reattach ( void  )

Reinitialize uart0 and uart1 calls uart_init()

Returns
void

Definition at line 822 of file uart.c.

void uart_rx_disable ( uint8  uart_no)

Disable receive interrupts for a uart.

Parameters
[in]uart_nouart number
Returns
void

Definition at line 62 of file uart.c.

void uart_rx_enable ( uint8  uart_no)

Enable receive interrupts for a uart.

Parameters
[in]uart_nouart number
Returns
void

Definition at line 52 of file uart.c.

MEMSPACE void UART_SetPrintPort ( uint8  uart_no)

Install debug uart.

Returns
void

Definition at line 682 of file uart.c.

void uart_tx_disable ( uint8_t  uart_no)

Disable transmit interrupts for a uart.

Parameters
[in]uart_nouart number
Returns
void

Definition at line 82 of file uart.c.

void uart_tx_enable ( uint8_t  uart_no)

Enable transmit interrupts for a uart.

Parameters
[in]uart_nouart number
Returns
void

Definition at line 72 of file uart.c.

Referenced by tx_fifo_putb(), tx_fifo_write(), and uart_flush().

Variable Documentation

int uart_debug_port = 0

Definition at line 43 of file uart.c.