changed comments & added basic VT100 support

pull/1/head
Ondřej Hruška 10 years ago
parent 877df1a3ed
commit d716190cc5
  1. 6
      lib/adc.h
  2. 6
      lib/arduino_pins.h
  3. 6
      lib/calc.h
  4. 20
      lib/colors.h
  5. 63
      lib/debounce.h
  6. 6
      lib/hsl.h
  7. 36
      lib/lcd.h
  8. 6
      lib/loops.h
  9. 2
      lib/meta.h
  10. 6
      lib/nsdelay.h
  11. 50
      lib/pins.h
  12. 12
      lib/uart.h
  13. 166
      lib/uart_ansi.c
  14. 62
      lib/uart_ansi.h
  15. 31
      lib/ws_rgb.h

@ -1,8 +1,8 @@
#pragma once
/*
Utilities for build-in A/D converter
*/
//
// Utilities for build-in A/D converter
//
#include <avr/io.h>

@ -1,8 +1,8 @@
#pragma once
/**
Pin definitions for Arduino (Pro Mini with ATmega328P)
*/
//
// Pin definitions for Arduino (Pro Mini with ATmega328P)
//
#include "pins.h"

@ -1,8 +1,8 @@
#pragma once
/**
Bit and byte manipulation utilities
*/
//
// Bit and byte manipulation utilities
//
// --- Increment in range ---

@ -1,15 +1,15 @@
#pragma once
/*
Some useful utilities for RGB color manipulation
The XXXc macros don't use cast, so they can be used in array initializers.
xrgb ... 3-byte true-color RGB (8 bits per component)
rgbXX ... XX-bit color value, with equal nr of bits per component
XX_r (_g, _b) ... extract component from the color, and convert it to 0..255
*/
//
// Some useful utilities for RGB color manipulation
//
// The XXXc macros don't use cast, so they can be used in array initializers.
//
// xrgb ... 3-byte true-color RGB (8 bits per component)
// rgbXX ... XX-bit color value, with equal nr of bits per component
//
// XX_r (_g, _b) ... extract component from the color, and convert it to 0..255
//
typedef struct {

@ -1,37 +1,38 @@
#pragma once
/**
An implementation of button debouncer.
//
// An implementation of button debouncer.
//
// ----
//
// You must provide a config file debo_config.h (next to your main.c)
//
// Example:
// #pragma once
// #define DEBO_CHANNELS 2
// #define DDEBO_TICKS 5
//
// ----
//
// A pin is registered like this:
//
// #define BTN1 B,0
// #define BTN2 B,1
//
// debo_add(BTN0); // The function returns number assigned to the pin (0, 1, ...)
// debo_add_rev(BTN1); // active low
// debo_register(&PINB, PB2, 0); // direct access - register, pin & invert
//
// Then periodically call the tick function (perhaps in a timer interrupt):
//
// debo_tick();
//
// To check if input is active, use
//
// debo_get_pin(0); // state of input #0 (registered first)
// debo_get_pin(1); // state of input #1 (registered second)
//
----
You must provide a config file debo_config.h (next to your main.c)
Example:
#pragma once
#define DEBO_CHANNELS 2
#define DDEBO_TICKS 5
----
A pin is registered like this:
#define BTN1 B,0
#define BTN2 B,1
debo_add(BTN0); // The function returns number assigned to the pin (0, 1, ...)
debo_add_rev(BTN1); // active low
debo_register(&PINB, PB2, 0); // direct access - register, pin & invert
Then periodically call the tick function (perhaps in a timer interrupt):
debo_tick();
To check if input is active, use
debo_get_pin(0); // state of input #0 (registered first)
debo_get_pin(1); // state of input #1 (registered second)
*/
#include <avr/io.h>
#include <stdbool.h>

@ -1,8 +1,8 @@
#pragma once
/*
HSL support (addition to colors.h)
*/
//
// HSL support (addition to colors.h)
//
#include "colors.h"

@ -1,24 +1,22 @@
#pragma once
/*
HD44780 LCD display driver - 4-bit mode
LCD pins are configured using a file lcd_config.h, which you
have to add next to your main.c file.
Content can be something like this:
#pragma once
#include "lib/arduino_pins.h"
#define LCD_RS D10
#define LCD_RW D11
#define LCD_E D12
#define LCD_D4 D13
#define LCD_D5 D14
#define LCD_D6 D15
#define LCD_D7 D16
*/
// HD44780 LCD display driver - 4-bit mode
//
// LCD pins are configured using a file lcd_config.h, which you
// have to add next to your main.c file.
//
// Content can be something like this:
//
// #pragma once
// #include "lib/arduino_pins.h"
// #define LCD_RS D10
// #define LCD_RW D11
// #define LCD_E D12
// #define LCD_D4 D13
// #define LCD_D5 D14
// #define LCD_D6 D15
// #define LCD_D7 D16
//
#include <stdint.h>
#include "lcd_config.h"

@ -1,8 +1,8 @@
#pragma once
/**
Custom loops
*/
//
// Custom loops
//
// Repeat code n times (uint8_t counter)
#define repeat(count) repeat_aux(count, _repeat_##__COUNTER__)

@ -1,6 +1,6 @@
#pragma once
/** Weird constructs for the compiler */
// Weird constructs for the compiler
// general macros
#define SECTION(pos) __attribute__((naked, used, section(pos)))

@ -1,8 +1,8 @@
#pragma once
/**
Functions for precise delays (nanoseconds / cycles)
*/
//
// Functions for precise delays (nanoseconds / cycles)
//
#include <avr/io.h>
#include <util/delay_basic.h>

@ -1,30 +1,30 @@
#pragma once
/**
This file provides macros for pin manipulation.
You can define your application pins like so:
// Led at PORTB, pin 1
#define LED B,1
// Switch at PORTD, pin 7
#define SW1 D,7
Now you can use macros from this file to wirh with the pins, eg:
as_output(LED);
as_input(SW1);
pullup_on(SW1);
toggle_pin(LED);
while (pin_is_low(SW1));
- The macros io2XXX() can be used to get literal name of register associated with the pin.
- io2n() provides pin number.
- The XXX_aux() macros are internal and should not be used elsewhere.
- The io_pack() macro is used to pass pin (io) to other macro without expanding it.
*/
//
// This file provides macros for pin manipulation.
//
// You can define your application pins like so:
//
// // Led at PORTB, pin 1
// #define LED B,1
//
// // Switch at PORTD, pin 7
// #define SW1 D,7
//
// Now you can use macros from this file to wirh with the pins, eg:
//
// as_output(LED);
// as_input(SW1);
// pullup_on(SW1);
//
// toggle_pin(LED);
// while (pin_is_low(SW1));
//
// - The macros io2XXX() can be used to get literal name of register associated with the pin.
// - io2n() provides pin number.
// - The XXX_aux() macros are internal and should not be used elsewhere.
// - The io_pack() macro is used to pass pin (io) to other macro without expanding it.
//
#include <avr/io.h>
#include "calc.h"

@ -1,11 +1,11 @@
#pragma once
/*
Utilities for UART communication.
First, init uart with desired baud rate using uart_init().
Then, enable interrupts you want, and that's it.
*/
//
// Utilities for UART communication.
//
// First, init uart with desired baud rate using uart_init().
// Then, enable interrupts you want, and that's it.
//
#include <avr/io.h>
#include <avr/pgmspace.h>

@ -0,0 +1,166 @@
#include <avr/io.h>
#include <stdbool.h>
#include <stdint.h>
#include "uart.h"
#include "uart_ansi.h"
void vt_goto(uint16_t x, uint16_t y)
{
uart_putc(27);
uart_putc('[');
uart_putu(x);
uart_putc(';');
uart_putu(y);
uart_putc('H');
}
void vt_move(int16_t x, int16_t y)
{
vt_move_x(x);
vt_move_y(y);
}
void vt_move_x(int16_t x)
{
if (x < 0) {
vt_left(-x);
} else {
vt_right(x);
}
}
void vt_move_y(int16_t y)
{
if (y < 0) {
vt_up(-y);
} else {
vt_down(y);
}
}
void vt_up(uint16_t y)
{
if (y == 0) return;
uart_putc(27);
uart_putc('[');
uart_putu(y);
uart_putc('A');
}
void vt_down(uint16_t y)
{
if (y == 0) return;
uart_putc(27);
uart_putc('[');
uart_putu(y);
uart_putc('B');
}
void vt_left(uint16_t x)
{
if (x == 0) return;
uart_putc(27);
uart_putc('[');
uart_putu(x);
uart_putc('D');
}
void vt_right(uint16_t x)
{
if (x == 0) return;
uart_putc(27);
uart_putc('[');
uart_putu(x);
uart_putc('C');
}
void vt_scroll(int16_t y)
{
while (y < 0) {
uart_putc(27);
uart_putc('D'); // up
y++;
}
while (y > 0) {
uart_putc(27);
uart_putc('M'); // down
y--;
}
}
void vt_save()
{
uart_putc(27);
uart_putc(7);
}
void vt_restore()
{
uart_putc(27);
uart_putc(8);
}
void vt_style(uint8_t flags)
{
if (flags == VT_NORMAL) {
uart_puts("\x1B[m"); // reset
return;
}
if (flags & VT_BOLD) {
uart_puts("\x1B[1m");
}
if (flags & VT_UNDERLINE) {
uart_puts("\x1B[4m");
}
if (flags & VT_BLINK) {
uart_puts("\x1B[5m");
}
if (flags & VT_REVERSE) {
uart_puts("\x1B[7m");
}
if (flags & VT_HIDDEN) {
uart_puts("\x1B[8m");
}
}
void vt_color(uint8_t fg, uint8_t bg)
{
uart_putc(27);
uart_putc('[');
uart_putu(fg);
uart_putc(';');
uart_putu(bg);
uart_putc('m');
}
void vt_clear()
{
uart_puts("\x1B[2J");
}
void vt_home()
{
uart_puts("\x1B[H");
}

@ -0,0 +1,62 @@
#pragma once
//
// ANSI / VT100 utilities for UART
//
#include <avr/io.h>
#include <stdbool.h>
#include <stdint.h>
#include "uart.h"
#define VT_NORMAL 0
#define VT_BOLD 1
#define VT_UNDERLINE 2
#define VT_BLINK 4
#define VT_REVERSE 8
#define VT_HIDDEN 16
/** Jump to a location on the screen */
void vt_goto(uint16_t x, uint16_t y);
/** Move cursor relative to current location */
void vt_move(int16_t x, int16_t y);
/** Move cursor horizontally */
void vt_move_x(int16_t x);
/** Move cursor vertically */
void vt_move_y(int16_t y);
/** Move cursor up y cells */
void vt_up(uint16_t y);
/** Move cursor down y cells */
void vt_down(uint16_t y);
/** Move cursor left x cells */
void vt_left(uint16_t x);
/** Move cursor right x cells */
void vt_right(uint16_t x);
/** Scroll y lines down (like up/down, but moves window if needed) */
void vt_scroll(int16_t down);
/** Set font style */
void vt_style(uint8_t flags);
/** Set color */
void vt_color(uint8_t fg, uint8_t bg);
/** Save cursor position & text attributes */
void vt_save();
/** Restore cursor to saved values */
void vt_restore();
/** Clear the screen */
void vt_clear();
/** Move cursor to top left corner */
void vt_home();

@ -1,21 +1,20 @@
#pragma once
/**
Utils for driving a WS28xx (tested on WS2812B) RGB LED strips.
It's implemented as macros to avoid overhead when passing values, and to
enable driving multiple strips at once.
To avoid bloating your code, try to reduce the number of invocations -
compute color and then send it.
[IMPORTANT]
Some seemingly random influences can ruin the communication.
If you have enough memory, consider preparing the colors in array,
and sending this array using one of the "ws_send_XXX_array" macros.
*/
//
// Utils for driving a WS28xx (tested on WS2812B) RGB LED strips.
//
// It's implemented as macros to avoid overhead when passing values, and to
// enable driving multiple strips at once.
//
// To avoid bloating your code, try to reduce the number of invocations -
// compute color and then send it.
//
// [IMPORTANT]
//
// Some seemingly random influences can ruin the communication.
// If you have enough memory, consider preparing the colors in array,
// and sending this array using one of the "ws_send_XXX_array" macros.
//
#include <avr/io.h>

Loading…
Cancel
Save