Skip to content

Commit

Permalink
user: Myles Metzler <mdmetzle@gmail.com>
Browse files Browse the repository at this point in the history
branch 'default'
added bitmaps/schematic.h

Added millis() replacement.
delay(x) now delays x ms delay_frame is unchanged.
Made public interface for scanline function call:
set_hbi_hook(&function())
Made 2 function calls avaliable for vertical sync
set_vbi_hook(&function,n) where n=0 or 1, 0 is default
Finished shift function
Some of the framework for the RTTTL player is in, ignore this not implemented yet.
The RTTTL player may infact be split into a support library like pollserial.

Pollserial is now stand alone USART_recieve must be called frequently.
Pollserial.begin(baud) will return a reference to USART_recieve().
Using pollserial with TVout works like this:
TV.set_hbi_hook(pserial.begin(baud));
  • Loading branch information
MylesMetzler committed Oct 21, 2010
1 parent a847947 commit e8cc00a
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 31 deletions.
85 changes: 81 additions & 4 deletions TVout.cpp
Expand Up @@ -59,6 +59,7 @@
#include "TVout.h"
#include "video_gen.h"
#include "spec/hardware_setup.h"
#include "spec/video_properties.h"

// bad style I know but i dont feel like doing it the correct way.
PROGMEM const unsigned char ascii3x5[] ={
Expand All @@ -74,7 +75,7 @@ PROGMEM const unsigned char ascii8x8[] = {
};

PROGMEM const unsigned char bitmap[] = {
#include "bitmaps/demobmp.h"
#include "bitmaps/schematic.h"
};

/* call this to start video output with the default resolution.
Expand Down Expand Up @@ -151,18 +152,34 @@ char TVout::char_line() {
return ((display.hres*8)/font);
}

void TVout::delay(unsigned int x) {
unsigned long time = millis() + x;
while(millis() < time);
}

/* Delay for x frames
* for NTSC 1 second = 60 frames
* for PAL 1 second = 50 frames
* exits at the end of the last display line always
* delay_frame(1) is useful prior to drawing so there is little/no flicker.
*/
void TVout::delay(unsigned int x) {
void TVout::delay_frame(unsigned int x) {
while (x) {
while (display.scanLine != display.stop_render+1);
while (display.scanLine == display.stop_render+1);
x--;
}
}

unsigned long TVout::millis() {
if (display.lines_frame == _NTSC_LINE_FRAME) {
return display.frames * _NTSC_TIME_SCANLINE * _NTSC_LINE_FRAME / 1000;
}
else {
return display.frames * _PAL_TIME_SCANLINE * _PAL_LINE_FRAME / 1000;
}
}

/* plot one point
* at x,y with color 1=white 0=black 2=invert
*/
Expand Down Expand Up @@ -578,6 +595,8 @@ void TVout::shift(uint8_t distance, uint8_t direction) {
uint8_t * src;
uint8_t * dst;
uint8_t * end;
uint8_t shift;
uint8_t tmp;
switch(direction) {
case UP:
dst = display.screen;
Expand All @@ -604,10 +623,46 @@ void TVout::shift(uint8_t distance, uint8_t direction) {
}
break;
case LEFT:
//needs to be implimented
shift = distance & 7;

for (uint8_t line = 0; line < display.vres; line++) {
dst = display.screen + display.hres*line;
src = dst + distance/8;
end = dst + display.hres-2;
while (src <= end) {
tmp = 0;
tmp = *src << shift;
src++;
tmp |= *src >> (8 - shift);
*dst = tmp;
dst++;
}
tmp = 0;
tmp = *src << shift;
*src = 0;
*dst = tmp;
}
break;
case RIGHT:
//needs to be implimented
shift = distance & 7;

for (uint8_t line = 0; line < display.vres; line++) {
dst = display.screen + display.hres-1 + display.hres*line;
src = dst - distance/8;
end = dst - display.hres+2;
while (src >= end) {
tmp = 0;
tmp = *src >> shift;
src--;
tmp |= *src << (8 - shift);
*dst = tmp;
dst--;
}
tmp = 0;
tmp = *src >> shift;
*src = 0;
*dst = tmp;
}
break;
}
}
Expand Down Expand Up @@ -765,6 +820,20 @@ static void inline sp_safe(unsigned char x, unsigned char y, char c, char d) {
}
}


void TVout::set_vbi_hook(void (*func)(), char n) {
if (n == 0)
vbi_hook0 = func;
else if (n == 1)
vbi_hook1 = func;
}


void TVout::set_hbi_hook(void (*func)()) {
hbi_hook = func;
}


void TVout::tone(unsigned int frequency) {
tone(frequency, 0);
}
Expand Down Expand Up @@ -841,4 +910,12 @@ void TVout::tone(unsigned int frequency, unsigned long duration_ms) {
void TVout::noTone() {
TCCR2B = 0;
PORT_SND &= ~(_BV(SND_PIN)); //set pin 11 to 0
}

void TVout::playRTTTL(const char song[]) {

}

void TVout::stopRTTTL() {

}
9 changes: 8 additions & 1 deletion TVout.h
Expand Up @@ -80,7 +80,6 @@ Audio connected to arduino pin 10, hard coded for now
#define resume_render() resume()
#define horz_res() hres()
#define vert_res() vres()
#define delay_frame(x) delay(x)
#define print_str(x,y,s) print(x,y,s)

// Macros for clearer usage
Expand All @@ -104,6 +103,8 @@ class TVout : public TVPrint {

//flow control functions
void delay(unsigned int x);
void delay_frame(unsigned int x);
unsigned long millis();

//basic rendering functions
void set_pixel(uint8_t x, uint8_t y, char c);
Expand All @@ -120,11 +121,17 @@ class TVout : public TVPrint {
//printing functions
void select_font(uint8_t f);
virtual void print_char(uint8_t x, uint8_t y, char c);

//hook setup functions
void set_vbi_hook(void (*func)(), char n = 0);
void set_hbi_hook(void (*func)());

//tone functions
void tone(unsigned int frequency, unsigned long duration_ms);
void tone(unsigned int frequency);
void noTone();
void playRTTTL(const char song[]);
void stopRTTTL();

protected:
virtual void inc_txtline();
Expand Down
96 changes: 96 additions & 0 deletions bitmaps/schematic.h
@@ -0,0 +1,96 @@
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0F,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFE,
0x08,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x02,
0x08,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x02,
0x0B,0x0C,0xE4,0x41,0x00,0x00,0x03,0x12,0x0E,0x22,0x61,0x80,0xB8,0x71,0x82,
0x0B,0x0D,0x94,0x41,0x00,0x00,0x05,0x14,0x11,0x22,0x61,0x80,0xA4,0xC9,0x82,
0x0A,0x95,0x04,0x41,0x00,0x00,0x01,0x14,0x11,0x22,0x52,0x80,0xA4,0x81,0x42,
0x0A,0x95,0x04,0x41,0x00,0x00,0x01,0x18,0x11,0x3E,0x52,0x80,0xB8,0x82,0x42,
0x0A,0x65,0x04,0x41,0x00,0x00,0x01,0x14,0x11,0x22,0x4C,0x80,0xA4,0x83,0xC2,
0x0A,0x65,0x94,0x41,0x00,0x00,0x01,0x12,0x11,0x22,0x4C,0x80,0xA4,0xCA,0x22,
0x0A,0x64,0xE3,0x81,0x00,0x00,0x07,0x92,0x0E,0x22,0x4C,0x80,0xA4,0x74,0x22,
0x08,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x02,
0x0F,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFE,
0x08,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x02,
0x08,0x70,0x00,0x01,0x18,0x08,0x01,0x00,0x01,0x00,0x01,0x00,0x80,0x00,0x02,
0x08,0x90,0x00,0x01,0x1E,0x08,0x02,0x80,0x02,0x80,0x02,0x80,0x80,0x00,0x02,
0x08,0x84,0x5E,0x39,0x1F,0x88,0x04,0x40,0x04,0x40,0x04,0x40,0x80,0x00,0x02,
0x08,0x64,0x92,0x41,0x1F,0xE8,0x08,0x20,0x08,0x20,0x08,0x20,0x80,0x00,0x02,
0x08,0x12,0x92,0x41,0xFF,0xFF,0xF0,0x10,0x10,0x10,0x10,0x1C,0x80,0x00,0x02,
0x08,0x92,0x92,0x41,0x1F,0xE8,0x00,0x08,0x20,0x08,0x20,0x04,0x80,0x00,0x02,
0x08,0xE1,0x12,0x39,0x1F,0x88,0x00,0x04,0x40,0x04,0x40,0x04,0xA1,0x4F,0x02,
0x08,0x01,0x00,0x01,0x1E,0x08,0x00,0x02,0x80,0x02,0x80,0x04,0xB3,0x49,0x82,
0x08,0x02,0x00,0x01,0x18,0x08,0x00,0x01,0x00,0x01,0x00,0x04,0x92,0x48,0x82,
0x08,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x92,0x48,0x82,
0x08,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x9C,0x48,0x82,
0x08,0x00,0x00,0x01,0x18,0x08,0x01,0x00,0x01,0x00,0x01,0x04,0x8C,0x49,0x82,
0x08,0x02,0x14,0xF1,0x1E,0x08,0x02,0x80,0x02,0x80,0x02,0x84,0x8C,0x4F,0x02,
0x08,0x03,0x34,0x99,0x1F,0x88,0x04,0x40,0x04,0x40,0x04,0x44,0x80,0x00,0x02,
0x08,0x01,0x24,0x89,0x1F,0xE8,0x08,0x20,0x08,0x20,0x08,0x24,0x80,0x00,0x02,
0x08,0x01,0x24,0x89,0xFF,0xFF,0xF0,0x10,0x10,0x10,0x10,0x1C,0x80,0x00,0x02,
0x08,0x01,0xC4,0x89,0x1F,0xE8,0x00,0x08,0x20,0x08,0x20,0x00,0x80,0x00,0x02,
0x08,0x00,0xC4,0x99,0x1F,0x88,0x00,0x04,0x40,0x04,0x40,0x00,0x80,0x00,0x02,
0x08,0x00,0xC4,0xF1,0x1E,0x08,0x00,0x02,0x80,0x02,0x80,0x00,0x80,0x00,0x02,
0x08,0x00,0x00,0x01,0x18,0x08,0x00,0x01,0x00,0x01,0x00,0x00,0x80,0x00,0x02,
0x08,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x02,
0x08,0x00,0x00,0x01,0x00,0x00,0x3C,0xF1,0xC1,0xC4,0x4C,0x30,0x80,0x00,0x02,
0x08,0x00,0x00,0x01,0x00,0x00,0x04,0x12,0x42,0x24,0x4C,0x30,0x80,0x00,0x02,
0x08,0x00,0x00,0x01,0x00,0x00,0x04,0x12,0x42,0x24,0x4A,0x50,0x80,0x00,0x02,
0x08,0x00,0x00,0x01,0x00,0x00,0x18,0x62,0x42,0x27,0xCA,0x50,0x80,0x00,0x02,
0x08,0x00,0x00,0x01,0x00,0x00,0x04,0x12,0x42,0x24,0x49,0x90,0x80,0x00,0x02,
0x08,0x00,0x00,0x01,0x00,0x00,0x04,0x12,0x42,0x24,0x49,0x90,0x80,0x00,0x02,
0x08,0x1E,0x64,0xF1,0x00,0x00,0x38,0xE3,0x81,0xC4,0x49,0x90,0x9E,0x64,0xF2,
0x08,0x32,0x64,0x99,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xB2,0x64,0x9A,
0x08,0x20,0x54,0x89,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xA0,0x54,0x8A,
0x08,0x26,0x54,0x89,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xA6,0x54,0x8A,
0x08,0x22,0x4C,0x89,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xA2,0x4C,0x8A,
0x08,0x32,0x4C,0x99,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xB2,0x4C,0x9A,
0x08,0x1E,0x4C,0xF1,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x9E,0x4C,0xF2,
0x08,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x02,
0x0F,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFE,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x30,0x00,0x00,0x04,0x00,0x00,0x40,0x00,0x00,0x00,0x03,0x81,0xC6,0x04,0x00,
0x48,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x04,0x42,0x2A,0x04,0x00,
0x42,0x25,0x87,0x04,0x38,0x3C,0x48,0x8B,0xC8,0x8E,0x08,0x24,0x02,0x0A,0x00,
0x22,0x26,0x48,0x04,0x40,0x02,0x48,0x88,0x28,0x90,0x08,0x24,0x02,0x0A,0x00,
0x11,0x44,0x48,0x04,0x60,0x1E,0x45,0x51,0xE5,0x18,0x08,0x24,0x02,0x11,0x00,
0x09,0x44,0x48,0x04,0x18,0x22,0x45,0x52,0x25,0x06,0x08,0x24,0x02,0x1F,0x00,
0x48,0x84,0x48,0x04,0x08,0x22,0x42,0x22,0x22,0x02,0x04,0x42,0x22,0x20,0x80,
0x30,0x84,0x47,0x04,0x70,0x1E,0x42,0x21,0xE2,0x1C,0x03,0x81,0xCF,0xA0,0x80,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x82,0x8F,0x01,0x00,0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
0x82,0x88,0x80,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
0x44,0x88,0x41,0x0E,0x0F,0x02,0x03,0x8B,0x03,0xC5,0x91,0x07,0x87,0x17,0xE0,
0x44,0x88,0x41,0x10,0x08,0x82,0x04,0x4C,0x80,0x26,0x51,0x04,0x48,0x98,0x80,
0x28,0x88,0x41,0x18,0x08,0x84,0x04,0x48,0x81,0xE4,0x4A,0x04,0x48,0x90,0x80,
0x28,0x88,0x41,0x06,0x08,0x84,0x04,0x48,0x82,0x24,0x4A,0x04,0x48,0x90,0x80,
0x10,0x88,0x81,0x02,0x08,0x88,0x04,0x48,0x82,0x24,0x44,0x04,0x48,0x90,0x80,
0x10,0x8F,0x01,0x1C,0x0F,0x08,0x03,0x88,0x81,0xE4,0x44,0x07,0x87,0x10,0x60,
0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x08,0x04,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x08,0x04,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
4 changes: 2 additions & 2 deletions examples/NTSCserialTerm/NTSCserialTerm.pde
Expand Up @@ -9,11 +9,11 @@ void setup() {
TV.select_font(_5X7);
TV.println("Serial Terminal");
TV.println("-- Version 0.1 --");
pserial.begin(57600);
TV.set_hbi_hook(pserial.begin(57600));
}

void loop() {
if (pserial.available()) {
TV.print((char)pserial.read());
}
}
}
3 changes: 3 additions & 0 deletions keywords.txt
@@ -1,5 +1,7 @@
_NTSC LITERAL1
_PAL LITERAL1
NTSC LITERAL1
PAL LITERAL1
_5X7 LITERAL1
_3X5 LITERAL1
_8X8 LITERAL1
Expand Down Expand Up @@ -29,3 +31,4 @@ select_font KEYWORD2
invert KEYWORD2
fs_bitmap KEYWORD2
tone KEYWORD2
printPGM KEYWORD2
34 changes: 31 additions & 3 deletions pollserial.cpp
Expand Up @@ -26,28 +26,36 @@
#include <avr/io.h>
#include <stdlib.h>
#include "pollserial.h"
#include "video_gen.h"

#define BUFFER_SIZE 64

rbuffer rxbuffer = {0,0,0};

void USART_recieve() {
#if defined ( UDR0 )
if( UCSR0A & _BV(RXC0)) {
uint8_t i = (rxbuffer.head + 1) & (BUFFER_SIZE - 1);
if ( i != rxbuffer.tail) {
rxbuffer.buffer[rxbuffer.head] = UDR0;
rxbuffer.head = i;
}
}
#elif
if( UCSRA & _BV(RXC)) {
uint8_t i = (rxbuffer.head + 1) & (BUFFER_SIZE - 1);
if ( i != rxbuffer.tail) {
rxbuffer.buffer[rxbuffer.head] = UDR;
rxbuffer.head = i;
}
}
#endif
}

void pollserial::begin(long baud) {
pt2Funct pollserial::begin(long baud) {
uint16_t baud_setting;
bool use_u2x;

rxbuffer.buffer = (unsigned char*)malloc(BUFFER_SIZE*sizeof(unsigned char));
fastpoll = &USART_recieve;

// U2X mode is needed for baud rates higher than (CPU Hz / 16)
if (baud > F_CPU / 16) {
Expand All @@ -65,17 +73,32 @@ void pollserial::begin(long baud) {
use_u2x = (nonu2x_baud_error > u2x_baud_error);
}
if (use_u2x) {
#if defined ( UDR0 )
UCSR0A = _BV(U2X0);
#elif
UCSRA = _BV(U2X);
#endif
baud_setting = (F_CPU / 4 / baud - 1) / 2;
}
else {
#if defined ( UDR0 )
UCSR0A = 0;
#elif
UCSRA = 0;
#endif
baud_setting = (F_CPU / 8 / baud - 1) / 2;
}

// assign the baud_setting, a.k.a. (USART Baud Rate Register)
#if defined ( UDR0 )
UBRR0 = baud_setting;
UCSR0B = _BV(RXEN0) | _BV(TXEN0);
#elif
UBRR = baud_setting;
UCSRB = _BV(RXEN) | _BV(TXEN);
#endif

return &USART_recieve;
}

void pollserial::end() {
Expand Down Expand Up @@ -106,6 +129,11 @@ void pollserial::flush() {
}

void pollserial::write(uint8_t c) {
#if defined ( UDR0 )
while (!((UCSR0A) & _BV(UDRE0)));
UDR0 = c;
#elif
while (!((UCSRA) & _BV(UDRE)));
UDR = c;
#endif
}

0 comments on commit e8cc00a

Please sign in to comment.