Skip to content

Commit

Permalink
3D video
Browse files Browse the repository at this point in the history
  • Loading branch information
mitxela committed Nov 26, 2023
1 parent 2fb62a7 commit 5ead818
Show file tree
Hide file tree
Showing 2 changed files with 638 additions and 39 deletions.
74 changes: 35 additions & 39 deletions candle.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,13 @@

// one slice contains both halves, second half of buffer should be mirror of first

uint32_t framebuffer[ANGULAR_RESOLUTION][ 8 ] = {
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0401FF08, 0x0401FD10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0401FF08, 0x0401FF10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0401FD08, 0x0400FF10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401F701, 0x0401F302, 0x0401FB04, 0x0401FD08, 0x0400FF10, 0x04017F20, 0x04017F40, 0x0401BF80},
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0401FD08, 0x0400FF10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0401FF08, 0x0401FF10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0400FF08, 0x0401FD10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401BF01, 0x04017F02, 0x04017F04, 0x0400FF08, 0x0401FD10, 0x0401F920, 0x0401F340, 0x0401F780},
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0400FF08, 0x0401FD10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0401FF08, 0x0401FF10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0401FD08, 0x0400FF10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401F701, 0x0401F302, 0x0401F904, 0x0401FD08, 0x0400FF10, 0x04017F20, 0x04017F40, 0x0401BF80},
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0401FD08, 0x0400FF10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0401FF08, 0x0401FF10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0401FF08, 0x0401FF10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401BF01, 0x04017F02, 0x04017F04, 0x0400FF08, 0x0401FD10, 0x0401FB20, 0x0401FB40, 0x0401F780},
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0401FF08, 0x0401FF10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0401FF08, 0x0401FF10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0401FF08, 0x0400FF10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401F701, 0x0401FF02, 0x0401FB04, 0x0401FD08, 0x0400FF10, 0x04017F20, 0x04017F40, 0x0401BF80},
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0401FF08, 0x0400FF10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0401FF08, 0x0401FF10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401FF01, 0x0401FF02, 0x0401FF04, 0x0401FF08, 0x0401FD10, 0x0401FF20, 0x0401FF40, 0x0401FF80},
{0x0401BF01, 0x04017F02, 0x04017F04, 0x0400FF08, 0x0401FD10, 0x0401FB20, 0x0401FB40, 0x0401F780},
};
volatile bool active_frame = 0;
uint32_t framebuffer[2][ANGULAR_RESOLUTION][ 8 ];
volatile uint32_t period = 0;
volatile bool idle = 1;

#include "fdata-cube-rotate.h"

#define SIG_START 1
#define MOTOR_TIMEOUT_MS 250
#define IDLE_TIMEOUT_MS 3000
Expand All @@ -66,28 +44,28 @@ void draw_slice( uint32_t slice ){

#define scantime (1.0/24.0/(10.5+7.5+4.5+1.5+1.5+4.5+7.5+10.5))

gpio_put_all( framebuffer[slice][0] );
gpio_put_all( framebuffer[active_frame][slice][0] );
sleep_cycles_break(10.5*scantime*period);

gpio_put_all( framebuffer[slice][1] );
gpio_put_all( framebuffer[active_frame][slice][1] );
sleep_cycles_break(7.5*scantime*period);

gpio_put_all( framebuffer[slice][2] );
gpio_put_all( framebuffer[active_frame][slice][2] );
sleep_cycles_break(4.5*scantime*period);

gpio_put_all( framebuffer[slice][3] );
gpio_put_all( framebuffer[active_frame][slice][3] );
sleep_cycles_break(1.5*scantime*period);

gpio_put_all( framebuffer[slice][4] );
gpio_put_all( framebuffer[active_frame][slice][4] );
sleep_cycles_break(1.5*scantime*period);

gpio_put_all( framebuffer[slice][5] );
gpio_put_all( framebuffer[active_frame][slice][5] );
sleep_cycles_break(4.5*scantime*period);

gpio_put_all( framebuffer[slice][6] );
gpio_put_all( framebuffer[active_frame][slice][6] );
sleep_cycles_break(7.5*scantime*period);

gpio_put_all( framebuffer[slice][7] );
gpio_put_all( framebuffer[active_frame][slice][7] );
sleep_cycles_break(10.5*scantime*period);


Expand Down Expand Up @@ -161,9 +139,18 @@ static inline void check_battery(){

}

void load_frame(bool n, uint32_t* data){
int k=0;
for (int i =0;i<ANGULAR_RESOLUTION; i++) {
for (int j =0;j<8;j++) {
framebuffer[n][i][j] = data[k++];
}
}
}

void clr(){
for (int i =0;i<ANGULAR_RESOLUTION; i++) {
for (int j =0;j<8;j++) framebuffer[i][j] = CATHODES|(1<<j);
for (int j =0;j<8;j++) framebuffer[active_frame][i][j] = CATHODES|(1<<j);
}
}

Expand All @@ -175,8 +162,8 @@ void set_voxel(int32_t r, uint32_t theta, uint32_t z) {
else if (z == 9) rownum == 24;
else rownum = z+8;

framebuffer[theta][r-4] &= ~(1<<rownum);
framebuffer[(theta+12)%24][3-r] &= ~(1<<rownum);
framebuffer[active_frame][theta][r-4] &= ~(1<<rownum);
framebuffer[active_frame][(theta+12)%24][3-r] &= ~(1<<rownum);

}

Expand Down Expand Up @@ -205,9 +192,12 @@ int main(){
systick_hw->csr = M0PLUS_SYST_CSR_ENABLE_BITS | M0PLUS_SYST_CSR_CLKSOURCE_BITS;
systick_hw->rvr = SYSTICK_RVR;

clr();
//clr();
//set_voxel(3, 1, 0);
set_voxel(3, 23, 0);
//set_voxel(3, 23, 0);

uint32_t f = 0;//, ft =0;
load_frame(0, &framedata[f][0][0]);

uint32_t timing = 0;

Expand All @@ -228,6 +218,12 @@ int main(){
if (period > 6250000) pwm_set_gpio_level(MOTOR, 0.9*65535);
else pwm_set_gpio_level(MOTOR, 0.6*65535);

//if (++ft ==3) {
// ft=0;
if (++f==24) f=0;
load_frame(0, &framedata[f][0][0]);
//}

while (gpio_get(IR_SENSOR) == 0) sleep_us(1);


Expand Down
Loading

0 comments on commit 5ead818

Please sign in to comment.