86 lines
1.3 KiB
C
86 lines
1.3 KiB
C
/*
|
|
* Stairs lighting
|
|
* Copyright 2017 (c) Mark van Renswoude
|
|
*
|
|
* https://git.x2software.net/pub/Stairs
|
|
*
|
|
* Source:
|
|
* https://github.com/akafugu/helloworld/blob/master/attiny2313/uart.c
|
|
*/
|
|
#ifndef __TinyUART
|
|
#define __TinyUART
|
|
|
|
#include <stdint.h>
|
|
|
|
#define UART_NO_DATA 0x0100
|
|
|
|
#define BAUD 38400
|
|
// 4.096MHz
|
|
// 4800: 52.3333333
|
|
// 9600: 25.6666667
|
|
// 14400: 16.7777778
|
|
// 19600: 12.06
|
|
// 28800: 7.8889
|
|
// 38400: 5.6667
|
|
|
|
#define MYUBBR ((F_CPU / (BAUD * 16L)) - 1)
|
|
#define BUFFER_SIZE 16
|
|
|
|
|
|
void uart_init(void);
|
|
|
|
/*
|
|
* uart_send
|
|
* Sends a single char to UART without ISR
|
|
*/
|
|
void uart_send(uint8_t c);
|
|
|
|
|
|
uint8_t uart_available(void);
|
|
|
|
|
|
/*
|
|
* uart_receive
|
|
* Receives a single char without ISR
|
|
*/
|
|
uint8_t uart_receive(void);
|
|
|
|
|
|
/*
|
|
* uart_getc
|
|
* Gets a single char from the receive buffer.
|
|
* return uint16_r the received char or UART_NO_DATA
|
|
*/
|
|
uint16_t uart_getc(void);
|
|
|
|
|
|
|
|
/*
|
|
* uart_getc_wait
|
|
* Blocking call to getc. Will not return until a char is received.
|
|
*/
|
|
uint8_t uart_getc_wait(void);
|
|
|
|
|
|
/*
|
|
* uart_putc
|
|
* Puts a single char. Will block until there is enough space in the
|
|
* send buffer.
|
|
*/
|
|
void uart_putc(uint8_t c);
|
|
|
|
|
|
/*
|
|
* uart_puts
|
|
* Sends a string.
|
|
*/
|
|
void uart_puts(const char *s);
|
|
|
|
|
|
/*
|
|
* uart_puts_P
|
|
* Sends a PROGMEM string.
|
|
*/
|
|
void uart_puts_P(const char *s);
|
|
|
|
#endif |