Show Posts
|
|
Pages: [1] 2
|
|
3
|
Products / Arduino Due / Re: VGA library
|
on: March 06, 2013, 04:18:32 am
|
|
Hi stimmer
Yes all my codes is absolutelly free for anything use :-)
Many thanks your great works !
Kamil
|
|
|
|
|
4
|
Products / Arduino Due / Re: VGA library
|
on: February 24, 2013, 09:22:35 am
|
Rossler chaotic attractor #undef printf #include <VGA.h>
float a = 0.2; float b = 0.2; float c = 8;
float x,y,z;
float xnn = 0; float ynn = 0; float znn = 0;
float dt = 0.02; int cnt = 0; boolean vis;
void setup() { VGA.begin(800,600); VGA.clear(); VGA.drawText(" Rossler chaotic attractor ",25,25,0,1); VGA.drawText("dx/dt = -y - z",25,50,1); VGA.drawText("dy/dt = x + ax",25,60,1); VGA.drawText("dz/dt = b + z(x-c)",25,70,1); VGA.drawText("a = 0.2",25,90,1); VGA.drawText("b = 0.2",25,100,1); VGA.drawText("c = 8",25,110,1); }
void loop() { xnn = -(y+z); ynn = x+a*y; znn = b+x*z-c*z;
x = x+xnn*dt; y = y+ynn*dt; z = z+znn*dt; VGA.drawPixel(350+(16*((z/2)-x)), 200+(12*((z/2)-y)), vis); if (cnt == 1500) { vis = !vis; cnt =0; } cnt ++; }
|
|
|
|
|
7
|
Products / Arduino Due / Re: VGA output
|
on: December 11, 2012, 04:38:06 pm
|
SVGA Novel 4D chaotic attractor :-) /* Novel 4D Chaotic Attractor v1.0 by JLS 2012 */
/* Arduino Due SVGA-Out 800x600 v0.3 by stimmer http://arduino.cc/forum/index.php/topic,130742.0.html Please do not attempt to understand this code :-) */
int bins[256]; void __attribute__((aligned(64))) doLine(byte *p){ asm volatile ( "isb \n\t" "dsb \n\t" "movw r1,#0x4254 \n\t" "movt r1,#0x4009 \n\t" "ldr r0,[r1] \n\t" "subs r0,#40 \n\t" "lsls r0,r0,#1 \n\t" "orr r0,#1 \n\t" "add r0,pc \n\t" "isb \n\t" ".align 5 \n\t" "bx r0 \n\t" ".rept 90 \n\t" "nop \n\t" ".endr \n\t" //this is debugging code, but because the timimg is so sensitive I have to leave it in "ldr r0,[r1] \n\t" "subs r0,#128 \n\t" "ldr r2,[%[bins],r0,lsl #2] \n\t" "adds r2,#1 \n\t" "str r2,[%[bins],r0,lsl #2] \n\t" //"movw r1,#0x40DC \n\t" //"movt r1,#0x400C \n\t" //"str %[bytes],[r1] \n\t" "movw r1,#0x40E8 \n\t" "movt r1,#0x400C \n\t" "movw r0,26 \n\t" "movt r0,#0x1203 \n\t" "str r0,[r1] \n\t" "movw r1,#0x4028 \n\t" "movt r1,#0x400C \n\t" "mov r0,1<<4 \n\t" "str r0,[r1] \n\t" "movw r1,#0x0e04 \n\t" "movt r1,#0x400e \n\t" "mov r0,1<<26 \n\t" ".rept 12\n\t nop\n\t .endr\n\t" "str r0,[r1] \n\t" :[bytes]"+r"(p) :[bins]"r"(bins) :"r0","r1","r2" ); }
void __attribute__((aligned(64))) DMAC_Handler() { REG_PIOA_PER = 1<<26; uint32_t dummy=REG_DMAC_EBCISR; }
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; uint16_t fb[600][52] __attribute__((aligned(256)));
void __attribute__((aligned(64))) PWM_Handler() { long dummy=REG_PWM_ISR1; if(line < 600){ //byte * p=fb[line]; doLine(0); } if(line==601) digitalWriteDirect(42,1); //or digitalWriteDirect(42,0); to invert vsync if(line==605) digitalWriteDirect(42,0); //or digitalWriteDirect(42,1); line++; if(line == 628){ REG_DMAC_SADDR4=(uint32_t)fb; line=0; } }
void setup(){ pinMode(42,OUTPUT); pinMode(43,OUTPUT); // vsync=42 hsync=43 // video output is on SPI MOSI pin (bottom middle on SAM3 3x2 SPI connector) REG_PIOA_PDR =1<<20; REG_PIOA_ABSR|=1<<20; REG_PMC_PCER1= 1<<4; REG_PWM_WPCR= 0x50574dfc; REG_PWM_CLK= 0x00010001; REG_PWM_DIS= 1<<2; REG_PWM_CMR2=0x0; // REG_PWM_CMR2=0x200; //to invert hsync polarity REG_PWM_CPRD2=2218; REG_PWM_CDTY2=1949; REG_PWM_SCM=0; REG_PWM_IER1=1<<2; REG_PWM_ENA= 1<<2; NVIC_EnableIRQ(PWM_IRQn);
REG_PMC_PCER1= 1<<7; REG_DMAC_WPMR=DMAC_WPMR_WPKEY(0x444d4143); REG_DMAC_EN=1; REG_DMAC_GCFG=0x00; REG_DMAC_EBCIER=1<<4; REG_DMAC_DADDR4=(uint32_t)®_SPI0_TDR; REG_DMAC_DSCR4=0; REG_DMAC_CTRLB4=0x20310000; REG_DMAC_CFG4= 0x01412210; NVIC_EnableIRQ(DMAC_IRQn);
REG_PIOA_PDR = (1<<25)|(1<<27)|(1<<28); REG_PIOA_PER = 1<<26; REG_PIOA_ABSR&=~((1<<25)|(1<<27)|(1<<28)); REG_PMC_PCER0= 1<<24; REG_SPI0_WPMR=0x53504900; REG_SPI0_CR=0x1; REG_SPI0_MR=0x00000011; SPI0->SPI_CSR[0]=0x00000280; }
inline void putPixel(int x,int y,byte c=1){ if((x<0)||(x>=800)||(y<0)||(y>=600))return; uint16_t mask=1<<((~x)&15); if(c) fb[y][x>>4]|= mask; else fb[y][x>>4]&=~mask; }
float x = 2; float y = 1; float z = 1; float u = 2; float oldx,oldy,oldz,oldu;
float dt = 0.0005;
float a = 10; float b = 12; float c = 50; float d = 2; float e = 4; int xx,yy; int cnt = 0; int col = 1;
void loop(){ oldx = x; oldy = y; oldz = z; oldu = u; x = oldx + dt * (oldy*oldz-a*oldx); y = oldy + dt * (b*oldy-oldx*oldz); z = oldz + dt * (oldx*oldy-c*oldz+d*oldu); u = oldu + dt * (oldx*oldz-e*oldu); xx = 400+1.5*x; yy = 300+1.3*y; if (cnt == 1000) { col = rand()%2; cnt = 0; } cnt++; if ((xx>=0)&(xx<=799)&(yy>=0)&(yy<=599)) putPixel(xx,yy,col); }
|
|
|
|
|
8
|
Products / Arduino Due / Re: VGA output
|
on: December 09, 2012, 10:05:08 am
|
SVGA New Strange Attractor :-) Update ! /* New Strange Attractor v1.1 by JLS 2012 */
/* Arduino Due SVGA-Out 800x600 v0.3 by stimmer http://arduino.cc/forum/index.php/topic,130742.0.html Please do not attempt to understand this code :-) */
int bins[256]; void __attribute__((aligned(64))) doLine(byte *p){ asm volatile ( "isb \n\t" "dsb \n\t" "movw r1,#0x4254 \n\t" "movt r1,#0x4009 \n\t" "ldr r0,[r1] \n\t" "subs r0,#40 \n\t" "lsls r0,r0,#1 \n\t" "orr r0,#1 \n\t" "add r0,pc \n\t" "isb \n\t" ".align 5 \n\t" "bx r0 \n\t" ".rept 90 \n\t" "nop \n\t" ".endr \n\t" //this is debugging code, but because the timimg is so sensitive I have to leave it in "ldr r0,[r1] \n\t" "subs r0,#128 \n\t" "ldr r2,[%[bins],r0,lsl #2] \n\t" "adds r2,#1 \n\t" "str r2,[%[bins],r0,lsl #2] \n\t" //"movw r1,#0x40DC \n\t" //"movt r1,#0x400C \n\t" //"str %[bytes],[r1] \n\t" "movw r1,#0x40E8 \n\t" "movt r1,#0x400C \n\t" "movw r0,26 \n\t" "movt r0,#0x1203 \n\t" "str r0,[r1] \n\t" "movw r1,#0x4028 \n\t" "movt r1,#0x400C \n\t" "mov r0,1<<4 \n\t" "str r0,[r1] \n\t" "movw r1,#0x0e04 \n\t" "movt r1,#0x400e \n\t" "mov r0,1<<26 \n\t" ".rept 12\n\t nop\n\t .endr\n\t" "str r0,[r1] \n\t" :[bytes]"+r"(p) :[bins]"r"(bins) :"r0","r1","r2" ); }
void __attribute__((aligned(64))) DMAC_Handler() { REG_PIOA_PER = 1<<26; uint32_t dummy=REG_DMAC_EBCISR; }
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; uint16_t fb[600][52] __attribute__((aligned(256)));
void __attribute__((aligned(64))) PWM_Handler() { long dummy=REG_PWM_ISR1; if(line < 600){ //byte * p=fb[line]; doLine(0); } if(line==601) digitalWriteDirect(42,1); //or digitalWriteDirect(42,0); to invert vsync if(line==605) digitalWriteDirect(42,0); //or digitalWriteDirect(42,1); line++; if(line == 628){ REG_DMAC_SADDR4=(uint32_t)fb; line=0; } }
float x = 1; float y = 1; float a,b,c,d; int xx,yy; void rndval(){ randomSeed(analogRead(8)); a = 2+(random(500)/100); randomSeed(analogRead(9)); b = 2+(random(500)/100); randomSeed(analogRead(10)); c = 2+(random(500)/100); randomSeed(analogRead(11)); d = 2+(random(500)/100); }
void setup(){ pinMode(42,OUTPUT); pinMode(43,OUTPUT); // vsync=42 hsync=43 // video output is on SPI MOSI pin (bottom middle on SAM3 3x2 SPI connector) REG_PIOA_PDR =1<<20; REG_PIOA_ABSR|=1<<20; REG_PMC_PCER1= 1<<4; REG_PWM_WPCR= 0x50574dfc; REG_PWM_CLK= 0x00010001; REG_PWM_DIS= 1<<2; REG_PWM_CMR2=0x0; // REG_PWM_CMR2=0x200; //to invert hsync polarity REG_PWM_CPRD2=2218; REG_PWM_CDTY2=1949; REG_PWM_SCM=0; REG_PWM_IER1=1<<2; REG_PWM_ENA= 1<<2; NVIC_EnableIRQ(PWM_IRQn);
REG_PMC_PCER1= 1<<7; REG_DMAC_WPMR=DMAC_WPMR_WPKEY(0x444d4143); REG_DMAC_EN=1; REG_DMAC_GCFG=0x00; REG_DMAC_EBCIER=1<<4; REG_DMAC_DADDR4=(uint32_t)®_SPI0_TDR; REG_DMAC_DSCR4=0; REG_DMAC_CTRLB4=0x20310000; REG_DMAC_CFG4= 0x01412210; NVIC_EnableIRQ(DMAC_IRQn);
REG_PIOA_PDR = (1<<25)|(1<<27)|(1<<28); REG_PIOA_PER = 1<<26; REG_PIOA_ABSR&=~((1<<25)|(1<<27)|(1<<28)); REG_PMC_PCER0= 1<<24; REG_SPI0_WPMR=0x53504900; REG_SPI0_CR=0x1; REG_SPI0_MR=0x00000011; SPI0->SPI_CSR[0]=0x00000280; }
inline void putPixel(int x,int y,byte c=1){ if((x<0)||(x>=800)||(y<0)||(y>=600))return; uint16_t mask=1<<((~x)&15); if(c) fb[y][x>>4]|= mask; else fb[y][x>>4]&=~mask; }
void cls(){ for(int bb=0;bb<599;bb++){ for(int aa=0;aa<799;aa++)putPixel(aa,bb,0); } }
void loop(){ rndval(); cls(); for (int i=0; i <= 30000; i++){ double oldx = x; double oldy = y; x = sin(-a*oldy)-cos(b*oldx); y = sin(c*oldx)-cos(d*oldy); xx = 400+140*x; yy = 300+140*y; if ((xx>=0)&(xx<=799)&(yy>=0)&(yy<=599)) putPixel(xx,yy,1); } }
|
|
|
|
|
9
|
Products / Arduino Due / Re: VGA output
|
on: November 27, 2012, 05:30:42 pm
|
SVGA Quadrup Two Orbit Fractal :-) /* Quadrup Two Orbit Fractal v1.1 by JLS 2012 */
/* Arduino Due SVGA-Out 800x600 v0.3 by stimmer http://arduino.cc/forum/index.php/topic,130742.0.html Please do not attempt to understand this code :-) */
int bins[256]; void __attribute__((aligned(64))) doLine(byte *p){ asm volatile ( "isb \n\t" "dsb \n\t" "movw r1,#0x4254 \n\t" "movt r1,#0x4009 \n\t" "ldr r0,[r1] \n\t" "subs r0,#40 \n\t" "lsls r0,r0,#1 \n\t" "orr r0,#1 \n\t" "add r0,pc \n\t" "isb \n\t" ".align 5 \n\t" "bx r0 \n\t" ".rept 90 \n\t" "nop \n\t" ".endr \n\t" //this is debugging code, but because the timimg is so sensitive I have to leave it in "ldr r0,[r1] \n\t" "subs r0,#128 \n\t" "ldr r2,[%[bins],r0,lsl #2] \n\t" "adds r2,#1 \n\t" "str r2,[%[bins],r0,lsl #2] \n\t" //"movw r1,#0x40DC \n\t" //"movt r1,#0x400C \n\t" //"str %[bytes],[r1] \n\t" "movw r1,#0x40E8 \n\t" "movt r1,#0x400C \n\t" "movw r0,26 \n\t" "movt r0,#0x1203 \n\t" "str r0,[r1] \n\t" "movw r1,#0x4028 \n\t" "movt r1,#0x400C \n\t" "mov r0,1<<4 \n\t" "str r0,[r1] \n\t" "movw r1,#0x0e04 \n\t" "movt r1,#0x400e \n\t" "mov r0,1<<26 \n\t" ".rept 12\n\t nop\n\t .endr\n\t" "str r0,[r1] \n\t" :[bytes]"+r"(p) :[bins]"r"(bins) :"r0","r1","r2" ); }
void __attribute__((aligned(64))) DMAC_Handler() { REG_PIOA_PER = 1<<26; uint32_t dummy=REG_DMAC_EBCISR; }
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; uint16_t fb[600][52] __attribute__((aligned(256)));
void __attribute__((aligned(64))) PWM_Handler() { long dummy=REG_PWM_ISR1; if(line < 600){ //byte * p=fb[line]; doLine(0); } if(line==601) digitalWriteDirect(42,1); //or digitalWriteDirect(42,0); to invert vsync if(line==605) digitalWriteDirect(42,0); //or digitalWriteDirect(42,1); line++; if(line == 628){ REG_DMAC_SADDR4=(uint32_t)fb; line=0; } }
void setup(){ pinMode(42,OUTPUT); pinMode(43,OUTPUT); // vsync=42 hsync=43 // video output is on SPI MOSI pin (bottom middle on SAM3 3x2 SPI connector) REG_PIOA_PDR =1<<20; REG_PIOA_ABSR|=1<<20; REG_PMC_PCER1= 1<<4; REG_PWM_WPCR= 0x50574dfc; REG_PWM_CLK= 0x00010001; REG_PWM_DIS= 1<<2; REG_PWM_CMR2=0x0; // REG_PWM_CMR2=0x200; //to invert hsync polarity REG_PWM_CPRD2=2218; REG_PWM_CDTY2=1949; REG_PWM_SCM=0; REG_PWM_IER1=1<<2; REG_PWM_ENA= 1<<2; NVIC_EnableIRQ(PWM_IRQn);
REG_PMC_PCER1= 1<<7; REG_DMAC_WPMR=DMAC_WPMR_WPKEY(0x444d4143); REG_DMAC_EN=1; REG_DMAC_GCFG=0x00; REG_DMAC_EBCIER=1<<4; REG_DMAC_DADDR4=(uint32_t)®_SPI0_TDR; REG_DMAC_DSCR4=0; REG_DMAC_CTRLB4=0x20310000; REG_DMAC_CFG4= 0x01412210; NVIC_EnableIRQ(DMAC_IRQn);
REG_PIOA_PDR = (1<<25)|(1<<27)|(1<<28); REG_PIOA_PER = 1<<26; REG_PIOA_ABSR&=~((1<<25)|(1<<27)|(1<<28)); REG_PMC_PCER0= 1<<24; REG_SPI0_WPMR=0x53504900; REG_SPI0_CR=0x1; REG_SPI0_MR=0x00000011; SPI0->SPI_CSR[0]=0x00000280; Serial.begin(9600); }
inline void putPixel(int x,int y,byte c=1){ if((x<0)||(x>=800)||(y<0)||(y>=600))return; uint16_t mask=1<<((~x)&15); if(c) fb[y][x>>4]|= mask; else fb[y][x>>4]&=~mask; }
inline int getPixel(int x,int y){ if((x<0)||(x>=800)||(y<0)||(y>=600))return -1; uint16_t mask=1<<((~x)&15); return (fb[y][x>>4] & mask)?1:0; }
#define sgn(x) (((x)>0)?1:((x)<0)?-1:0) void drawLine(int x0, int y0, int x1, int y1,int c){ int dx=abs(x1-x0), dy=abs(y1-y0),sx=sgn(x1-x0),sy=sgn(y1-y0); int err=dx-dy; do{ putPixel(x0,y0,c<2?c:!getPixel(x0,y0)); int e2=2*err; if (e2 > -dy){err-=dy;x0+=sx;} if (e2 < dx){err+=dx;y0+=sy;} } while ((x0!=x1)||(y0!=y1)); }
float a = 34; float b = 0.9; float c = 5; float x = 1; float y = 0; int xx,yy; int cnt = 0; int col = 1;
void loop(){ double oldx = x; double oldy = y; x = oldy-(oldx/abs(oldx))*sin(log(abs(b*oldx-c)))*atan(abs((pow(c*oldx-b,2)))); y = a-oldx; xx = 285+7*x; yy = 210+5.5*y; if (cnt == 1000) { col = rand()%2; cnt = 0; } cnt++; if ((xx>=0)&(xx<=799)&(yy>=0)&(yy<=599)) putPixel(xx,yy,col); }
|
|
|
|
|
11
|
Products / Arduino Due / Re: VGA output
|
on: November 26, 2012, 05:15:42 pm
|
SVGA Three Ply Orbit Fractal :-) /* Three Ply Orbit Fractal v1.1 by JLS 2012 */
/* Arduino Due SVGA-Out 800x600 v0.3 by stimmer http://arduino.cc/forum/index.php/topic,130742.0.html Please do not attempt to understand this code :-) */
int bins[256]; void __attribute__((aligned(64))) doLine(byte *p){ asm volatile ( "isb \n\t" "dsb \n\t" "movw r1,#0x4254 \n\t" "movt r1,#0x4009 \n\t" "ldr r0,[r1] \n\t" "subs r0,#40 \n\t" "lsls r0,r0,#1 \n\t" "orr r0,#1 \n\t" "add r0,pc \n\t" "isb \n\t" ".align 5 \n\t" "bx r0 \n\t" ".rept 90 \n\t" "nop \n\t" ".endr \n\t" //this is debugging code, but because the timimg is so sensitive I have to leave it in "ldr r0,[r1] \n\t" "subs r0,#128 \n\t" "ldr r2,[%[bins],r0,lsl #2] \n\t" "adds r2,#1 \n\t" "str r2,[%[bins],r0,lsl #2] \n\t" //"movw r1,#0x40DC \n\t" //"movt r1,#0x400C \n\t" //"str %[bytes],[r1] \n\t" "movw r1,#0x40E8 \n\t" "movt r1,#0x400C \n\t" "movw r0,26 \n\t" "movt r0,#0x1203 \n\t" "str r0,[r1] \n\t" "movw r1,#0x4028 \n\t" "movt r1,#0x400C \n\t" "mov r0,1<<4 \n\t" "str r0,[r1] \n\t" "movw r1,#0x0e04 \n\t" "movt r1,#0x400e \n\t" "mov r0,1<<26 \n\t" ".rept 12\n\t nop\n\t .endr\n\t" "str r0,[r1] \n\t" :[bytes]"+r"(p) :[bins]"r"(bins) :"r0","r1","r2" ); }
void __attribute__((aligned(64))) DMAC_Handler() { REG_PIOA_PER = 1<<26; uint32_t dummy=REG_DMAC_EBCISR; }
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; uint16_t fb[600][52] __attribute__((aligned(256)));
void __attribute__((aligned(64))) PWM_Handler() { long dummy=REG_PWM_ISR1; if(line < 600){ //byte * p=fb[line]; doLine(0); } if(line==601) digitalWriteDirect(42,1); //or digitalWriteDirect(42,0); to invert vsync if(line==605) digitalWriteDirect(42,0); //or digitalWriteDirect(42,1); line++; if(line == 628){ REG_DMAC_SADDR4=(uint32_t)fb; line=0; } }
void setup(){ pinMode(42,OUTPUT); pinMode(43,OUTPUT); // vsync=42 hsync=43 // video output is on SPI MOSI pin (bottom middle on SAM3 3x2 SPI connector) REG_PIOA_PDR =1<<20; REG_PIOA_ABSR|=1<<20; REG_PMC_PCER1= 1<<4; REG_PWM_WPCR= 0x50574dfc; REG_PWM_CLK= 0x00010001; REG_PWM_DIS= 1<<2; REG_PWM_CMR2=0x0; // REG_PWM_CMR2=0x200; //to invert hsync polarity REG_PWM_CPRD2=2218; REG_PWM_CDTY2=1949; REG_PWM_SCM=0; REG_PWM_IER1=1<<2; REG_PWM_ENA= 1<<2; NVIC_EnableIRQ(PWM_IRQn);
REG_PMC_PCER1= 1<<7; REG_DMAC_WPMR=DMAC_WPMR_WPKEY(0x444d4143); REG_DMAC_EN=1; REG_DMAC_GCFG=0x00; REG_DMAC_EBCIER=1<<4; REG_DMAC_DADDR4=(uint32_t)®_SPI0_TDR; REG_DMAC_DSCR4=0; REG_DMAC_CTRLB4=0x20310000; REG_DMAC_CFG4= 0x01412210; NVIC_EnableIRQ(DMAC_IRQn);
REG_PIOA_PDR = (1<<25)|(1<<27)|(1<<28); REG_PIOA_PER = 1<<26; REG_PIOA_ABSR&=~((1<<25)|(1<<27)|(1<<28)); REG_PMC_PCER0= 1<<24; REG_SPI0_WPMR=0x53504900; REG_SPI0_CR=0x1; REG_SPI0_MR=0x00000011; SPI0->SPI_CSR[0]=0x00000280; Serial.begin(9600); }
inline void putPixel(int x,int y,byte c=1){ if((x<0)||(x>=800)||(y<0)||(y>=600))return; uint16_t mask=1<<((~x)&15); if(c) fb[y][x>>4]|= mask; else fb[y][x>>4]&=~mask; }
inline int getPixel(int x,int y){ if((x<0)||(x>=800)||(y<0)||(y>=600))return -1; uint16_t mask=1<<((~x)&15); return (fb[y][x>>4] & mask)?1:0; }
#define sgn(x) (((x)>0)?1:((x)<0)?-1:0) void drawLine(int x0, int y0, int x1, int y1,int c){ int dx=abs(x1-x0), dy=abs(y1-y0),sx=sgn(x1-x0),sy=sgn(y1-y0); int err=dx-dy; do{ putPixel(x0,y0,c<2?c:!getPixel(x0,y0)); int e2=2*err; if (e2 > -dy){err-=dy;x0+=sx;} if (e2 < dx){err+=dx;y0+=sy;} } while ((x0!=x1)||(y0!=y1)); }
float a = -55; float b = -1; float c = -41; float x = 1; float y = 0; int xx,yy; int cnt = 0; int col = 1;
void loop(){ double oldx = x; double oldy = y; x = oldy-(oldx/abs(oldx))*abs(sin(oldx)*cos(b)+c-oldx*sin(a+b+c)); y = a-oldx; xx = 400+x/5; yy = 300+y/5; if (cnt == 1000) { col = rand()%2; cnt = 0; } cnt++; if ((xx>=0)&(xx<=799)&(yy>=0)&(yy<=599)) putPixel(xx,yy,col); }
|
|
|
|
|
12
|
Products / Arduino Due / Re: VGA output
|
on: November 26, 2012, 05:05:18 pm
|
SVGA Hopalong Orbit Fractal :-) /* Hopalong Orbit Fractal v1.1 by JLS 2012 */
/* Arduino Due SVGA-Out 800x600 v0.3 by stimmer http://arduino.cc/forum/index.php/topic,130742.0.html Please do not attempt to understand this code :-) */
int bins[256]; void __attribute__((aligned(64))) doLine(byte *p){ asm volatile ( "isb \n\t" "dsb \n\t" "movw r1,#0x4254 \n\t" "movt r1,#0x4009 \n\t" "ldr r0,[r1] \n\t" "subs r0,#40 \n\t" "lsls r0,r0,#1 \n\t" "orr r0,#1 \n\t" "add r0,pc \n\t" "isb \n\t" ".align 5 \n\t" "bx r0 \n\t" ".rept 90 \n\t" "nop \n\t" ".endr \n\t" //this is debugging code, but because the timimg is so sensitive I have to leave it in "ldr r0,[r1] \n\t" "subs r0,#128 \n\t" "ldr r2,[%[bins],r0,lsl #2] \n\t" "adds r2,#1 \n\t" "str r2,[%[bins],r0,lsl #2] \n\t" //"movw r1,#0x40DC \n\t" //"movt r1,#0x400C \n\t" //"str %[bytes],[r1] \n\t" "movw r1,#0x40E8 \n\t" "movt r1,#0x400C \n\t" "movw r0,26 \n\t" "movt r0,#0x1203 \n\t" "str r0,[r1] \n\t" "movw r1,#0x4028 \n\t" "movt r1,#0x400C \n\t" "mov r0,1<<4 \n\t" "str r0,[r1] \n\t" "movw r1,#0x0e04 \n\t" "movt r1,#0x400e \n\t" "mov r0,1<<26 \n\t" ".rept 12\n\t nop\n\t .endr\n\t" "str r0,[r1] \n\t" :[bytes]"+r"(p) :[bins]"r"(bins) :"r0","r1","r2" ); }
void __attribute__((aligned(64))) DMAC_Handler() { REG_PIOA_PER = 1<<26; uint32_t dummy=REG_DMAC_EBCISR; }
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; uint16_t fb[600][52] __attribute__((aligned(256)));
void __attribute__((aligned(64))) PWM_Handler() { long dummy=REG_PWM_ISR1; if(line < 600){ //byte * p=fb[line]; doLine(0); } if(line==601) digitalWriteDirect(42,1); //or digitalWriteDirect(42,0); to invert vsync if(line==605) digitalWriteDirect(42,0); //or digitalWriteDirect(42,1); line++; if(line == 628){ REG_DMAC_SADDR4=(uint32_t)fb; line=0; } }
void setup(){ pinMode(42,OUTPUT); pinMode(43,OUTPUT); // vsync=42 hsync=43 // video output is on SPI MOSI pin (bottom middle on SAM3 3x2 SPI connector) REG_PIOA_PDR =1<<20; REG_PIOA_ABSR|=1<<20; REG_PMC_PCER1= 1<<4; REG_PWM_WPCR= 0x50574dfc; REG_PWM_CLK= 0x00010001; REG_PWM_DIS= 1<<2; REG_PWM_CMR2=0x0; // REG_PWM_CMR2=0x200; //to invert hsync polarity REG_PWM_CPRD2=2218; REG_PWM_CDTY2=1949; REG_PWM_SCM=0; REG_PWM_IER1=1<<2; REG_PWM_ENA= 1<<2; NVIC_EnableIRQ(PWM_IRQn);
REG_PMC_PCER1= 1<<7; REG_DMAC_WPMR=DMAC_WPMR_WPKEY(0x444d4143); REG_DMAC_EN=1; REG_DMAC_GCFG=0x00; REG_DMAC_EBCIER=1<<4; REG_DMAC_DADDR4=(uint32_t)®_SPI0_TDR; REG_DMAC_DSCR4=0; REG_DMAC_CTRLB4=0x20310000; REG_DMAC_CFG4= 0x01412210; NVIC_EnableIRQ(DMAC_IRQn);
REG_PIOA_PDR = (1<<25)|(1<<27)|(1<<28); REG_PIOA_PER = 1<<26; REG_PIOA_ABSR&=~((1<<25)|(1<<27)|(1<<28)); REG_PMC_PCER0= 1<<24; REG_SPI0_WPMR=0x53504900; REG_SPI0_CR=0x1; REG_SPI0_MR=0x00000011; SPI0->SPI_CSR[0]=0x00000280; Serial.begin(9600); }
inline void putPixel(int x,int y,byte c=1){ if((x<0)||(x>=800)||(y<0)||(y>=600))return; uint16_t mask=1<<((~x)&15); if(c) fb[y][x>>4]|= mask; else fb[y][x>>4]&=~mask; }
inline int getPixel(int x,int y){ if((x<0)||(x>=800)||(y<0)||(y>=600))return -1; uint16_t mask=1<<((~x)&15); return (fb[y][x>>4] & mask)?1:0; }
#define sgn(x) (((x)>0)?1:((x)<0)?-1:0) void drawLine(int x0, int y0, int x1, int y1,int c){ int dx=abs(x1-x0), dy=abs(y1-y0),sx=sgn(x1-x0),sy=sgn(y1-y0); int err=dx-dy; do{ putPixel(x0,y0,c<2?c:!getPixel(x0,y0)); int e2=2*err; if (e2 > -dy){err-=dy;x0+=sx;} if (e2 < dx){err+=dx;y0+=sy;} } while ((x0!=x1)||(y0!=y1)); }
float a = 0.5; float b = -0.6; float c = 0.7; float x = 1; float y = 0; int xx,yy; int cnt = 0; int col = 1;
void loop(){ double oldx = x; double oldy = y; x = oldy-(oldx/abs(oldx))*sqrt(abs(b*oldx-c)); y = a-oldx; xx = 400+10*x; yy = 300+10*y; if (cnt == 1000) { col = rand()%2; cnt = 0; } cnt++; if ((xx>=0)&(xx<=799)&(yy>=0)&(yy<=599)) putPixel(xx,yy,col); }
|
|
|
|
|
13
|
Products / Arduino Due / Re: VGA output
|
on: November 26, 2012, 04:55:52 pm
|
|
Hi Stimmer
800x600 is great work many thanks :-)
Kamil
P.S. is possible 640x480 with some colors ?
|
|
|
|
|
14
|
Products / Arduino Due / Re: USB Host MouseController problem
|
on: November 23, 2012, 04:47:37 pm
|
|
I´m testing your code but not working - same problem. Few first blink working - after few second stoped blinking. When mouse move again few second working.
Arduino IDE v1.5.1r2 WinXP SP3 and Genius USB mouse Net Scroll 120 powering over USB programming port
Kamil
|
|
|
|
|
15
|
Products / Arduino Due / USB Host MouseController problem
|
on: November 22, 2012, 05:22:11 pm
|
|
Hi all please help me
I´m testing USB Host MouseController example - working great ! But when adding some code like ADC read or pin control, that working only when moves mouse !!!!!
This is normal or error in USB Host library ?
Thanks help Kamil
P.S. sorry my bad english
|
|
|
|
|