After working out how to do a timer interrupt I've had a go at making a VGA framebuffer. It is rather low-res at present(160x240) and fuzzy but I hope to be able to improve that. It has 8-bit colour (RRRGGGBB).
I cannot get Eagle to run right now so will have to describe the schematic in text:
Due pin 2 -> VGA pin 13 (HSync)
Due pin 3 -> VGA pin 14 (VSync)
Due pin 25 -> 820R resistor -> VGA pin 3 (blue)
Due pin 26 -> 390R resistor -> VGA pin 3 (blue)
Due pin 27 -> 2k2 resistor -> VGA pin 2 (green)
Due pin 28 -> 1k resistor -> VGA pin 2 (green)
Due pin 14 -> 470R resistor -> VGA pin 2 (green)
Due pin 15 -> 2k2 resistor -> VGA pin 1 (red)
Due pin 29 -> 1k resistor -> VGA pin 1 (red)
Due pin 11 -> 470R resistor -> VGA pin 1(red)
Due pin GND -> VGA pins 5,6,7,8,10
inline void digitalWriteDirect(int pin, boolean val){
if(val) g_APinDescription[pin].pPort -> PIO_SODR = g_APinDescription[pin].ulPin;
else g_APinDescription[pin].pPort -> PIO_CODR = g_APinDescription[pin].ulPin;
}
volatile short line;
byte fb[240][160];
void TC0_Handler()
{
long dummy=REG_TC0_SR0;
if(line < 480){
int i,j=line>>1;
for(i=0;i<160;i++) REG_PIOD_ODSR = fb[j][i];
REG_PIOD_ODSR = 0;
}
if(line==490) digitalWriteDirect(3,1);
if(line==492) digitalWriteDirect(3,0);
line++; if(line == 525) line=0;
}
void setup(){
for(int i=0;i<160;i++)for(int j=0;j<240;j++)fb[j][i]=j+i;
pinMode(3,OUTPUT); pinMode(2,OUTPUT); // vsync=3 hsync=2
pinMode(25,OUTPUT); pinMode(26,OUTPUT); // blue (26=msb,25=lsb)
pinMode(27,OUTPUT); pinMode(28,OUTPUT); pinMode(14,OUTPUT); // green (14=msb,28,27=lsb)
pinMode(15,OUTPUT); pinMode(29,OUTPUT); pinMode(11,OUTPUT); // red (11=msb,29,15=lsb)
REG_PIOD_OWER= 0xff;
REG_PMC_PCER0= 1<<27;
REG_PIOB_PDR = 1<<25;
REG_PIOB_ABSR= 1<<25;
REG_TC0_WPMR = 0x54494D00;
REG_TC0_CMR0 = 0b00000000000010011100010000000000;
REG_TC0_RC0 = 1334;
REG_TC0_RA0 = 1174;
REG_TC0_CCR0 = 0b101;
REG_TC0_IER0 = 0b00010000;
REG_TC0_IDR0 = 0b11101111;
NVIC_EnableIRQ(TC0_IRQn);
}
#include <complex>
using namespace std;
const byte cmap[]={0b00000000,0b11100000,0b11100100,0b11101000,0b11101100,0b11110000,0b11110100,0b11111000,0b11111100,
0b11011100,0b10111100,0b10011100,0b01111100,0b01011100,0b00111100,0b00011100,0b00011101,0b00011110,
0b00011111,0b00011011,0b00010111,0b00010011,0b00001111,0b00001011,0b00000111,0b00000011,0b00100011,
0b01000011,0b01100011,0b10000011,0b10100011,0b11000011,0b11100011,0b11100010,0b11100001,0b11100000,0b00000000};
void loop(){
for(int i=0;i<160;i++){
for(int j=0;j<240;j++){
complex<float> z(0,0),c(i/320.0,(j+240.0)/640.0);
int n;
for(n=1;n<sizeof(cmap);n++){
z=z*z+c;
if(norm(z)>4.0)break;
}
fb[j][i]=cmap[sizeof(cmap)-n];
}
}
for(;;);
}