CuVoodoo STM32F1 firmware template
Enumerations | Functions | Variables
usart_enhanced.h File Reference

library for enhanced USART communication (API) More...

Go to the source code of this file.

Enumerations

enum  usart_enhanced_parity_t {
  USART_ENHANCED_PARITY_NONE, USART_ENHANCED_PARITY_EVEN, USART_ENHANCED_PARITY_ODD, USART_ENHANCED_PARITY_MARK,
  USART_ENHANCED_PARITY_SPACE
}
 enhanced USART setting for the additional parity bit More...
 

Functions

bool usart_enhanced_config (uint32_t usart, uint8_t databits, enum usart_enhanced_parity_t parity)
 configure enhanced USART More...
 
void usart_enhanced_send (uint32_t usart, uint8_t data)
 send data over the enhanced USART using the configuration More...
 
uint8_t usart_enhanced_recv (uint32_t usart)
 receive data over the enhanced USART using the configuration More...
 
bool usart_enhanced_parity_error (uint32_t usart)
 get the parity status of the received data More...
 

Variables

const bool usart_enhanced_even_parity_lut [256]
 know if there is an even number of 1's in a integer More...
 

Detailed Description

library for enhanced USART communication (API)

Author
King Kévin kingk.nosp@m.evin.nosp@m.@cuvo.nosp@m.odoo.nosp@m..info
Date
2018

the USART peripherals only support 8 or 9-bit word and even or odd parity (included in the data bits). The library adds support for 5 to 8-bit words, none/even/odd/mark/space parity (on top of the data bits)

Note
since parity is handled in software, the parity error (PE) flag is unused and should be replaced by the value return by usart_enhanced_parity_error
Remarks
9-bit raw communication is not supported since this is not common and can be done without this library

Definition in file usart_enhanced.h.

Enumeration Type Documentation

◆ usart_enhanced_parity_t

enhanced USART setting for the additional parity bit

Enumerator
USART_ENHANCED_PARITY_NONE 

no parity

USART_ENHANCED_PARITY_EVEN 

even parity

Note
the number of 1's is even
USART_ENHANCED_PARITY_ODD 

odd parity

Note
the number of 1's is odd
USART_ENHANCED_PARITY_MARK 

mark parity

Note
the parity bit is 1
USART_ENHANCED_PARITY_SPACE 

space parity

Note
the parity bit is 0

Definition at line 26 of file usart_enhanced.h.

Function Documentation

◆ usart_enhanced_config()

bool usart_enhanced_config ( uint32_t  usart,
uint8_t  databits,
enum usart_enhanced_parity_t  parity 
)

configure enhanced USART

Parameters
[in]usartUSART peripheral base address
[in]databitsword size in bits (5 to 8)
[in]parityadditional parity bit
Returns
if the input settings are valid and the configuration is successful

Definition at line 68 of file usart_enhanced.c.

◆ usart_enhanced_parity_error()

bool usart_enhanced_parity_error ( uint32_t  usart)

get the parity status of the received data

Parameters
[in]usartUSART peripheral base address
Returns
if there is a parity error
Note
the check only applies to the last data retrieved using usart_enhanced_recv

Definition at line 172 of file usart_enhanced.c.

◆ usart_enhanced_recv()

uint8_t usart_enhanced_recv ( uint32_t  usart)

receive data over the enhanced USART using the configuration

Parameters
[in]usartUSART peripheral base address
Returns
data received
Note
uses usart_recv

Definition at line 131 of file usart_enhanced.c.

◆ usart_enhanced_send()

void usart_enhanced_send ( uint32_t  usart,
uint8_t  data 
)

send data over the enhanced USART using the configuration

Parameters
[in]usartUSART peripheral base address
[in]datadata to be sent
Note
uses usart_send

Definition at line 96 of file usart_enhanced.c.

Variable Documentation

◆ usart_enhanced_even_parity_lut

const bool usart_enhanced_even_parity_lut[256]

know if there is an even number of 1's in a integer

Note
this look up table is only useful for up to 8-bit words, else use __builtin_parity
Remarks
a look-up is a lot faster than making the calculation and doesn't use a lot of (flash) memory

Definition at line 41 of file usart_enhanced.c.