ECE4760 - Laser Projector (ipb7, jcc384, pfc38)  1
Raster Laser Projection
projector.h File Reference
#include "include.h"
#include "parameters.h"
#include "color.h"

Go to the source code of this file.

Functions

void projector_init (void)
 Initialize projector peripherals, variables etc. MUST be called before calling any other projector functions! More...
 
void projector_set_pixel (struct color const color, unsigned int x, unsigned int y)
 Set the color of a pixel at the specified location. More...
 

Function Documentation

§ projector_init()

void projector_init ( void  )

Initialize projector peripherals, variables etc. MUST be called before calling any other projector functions!

Definition at line 123 of file projector.c.

123  {
125  /* Set Up Pixel CLock */
127 
128  // Open Timer1 with the following configuration:
129  // - T1_ON :: Timer is turned on
130  // - T1_SOURCE_INT :: Clock source is internal
131  // - T1_PS_1_1 :: Prescalar is 1 to 1 (timer sees PBCLK)
132  //
133  // The timer's period is used to fine-tune how long each pixel lasts;
134  // one pixel displayed every time the timer wraps around.
135  OpenTimer1(T1_ON | T1_SOURCE_INT | T1_PS_1_1, PIXEL_ON_TIME);
136 
137  // set up the pin to reset the Gate Latch, set initially high
138  // (the signal is active low)
139  PORTSetPinsDigitalOut(IOPORT_A, BIT_3);
140  mPORTASetBits(BIT_3);
141 
143  /* Set Up CN */
145 
146  // see reference manual 12.3.3.1
147  CNCONASET = BIT_15; // enable CN on Port A (set bit 15 of CNCON to 1)
148  PORTSetPinsDigitalIn(IOPORT_A, BIT_4); // RA4 is input
149  unsigned int ignore = PORTA; // clear interrupt
150  IPC8SET = ((unsigned int) 5) << 18; // set CN interrupt priority
151  // (IPC6<20:18>=5, defaults to 0 at POR)
152  IFS1CLR = BIT_13; // clear CN interrupt flag (set bit 0 of IFS1 to 0)
153  CNENASET = BIT_4; // enable for RA4 (set bit 4 of CNENA to 1)
154  // see family data sheet 11.1.4
155  IEC1SET = BIT_13; // enable CN interrupt (set bit 0 of IEC1 to 1)
156 
158  /* Set Up DMA */
160 
161  // Set up the pins as an output
162  PORTSetPinsDigitalOut(IOPORT_B, BIT_0 | BIT_1 // red
163  | BIT_2 | BIT_3 // blue
164  | BIT_4 | BIT_5); // green
165 
166  // Configure DMA interrupt vector and enable DMA interrupts on CPU
167  INTSetVectorPriority(INT_VECTOR_DMA(PIXEL_DMA_CHN), INT_PRIORITY_LEVEL_5);
168  INTSetVectorSubPriority(INT_VECTOR_DMA(PIXEL_DMA_CHN),
169  INT_SUB_PRIORITY_LEVEL_3);
170  INTEnable(INT_SOURCE_DMA(PIXEL_DMA_CHN), INT_ENABLED);
171 
172  configure_dma_for_row(0);
173 
175  /* Set Up SPI */
177 
178  // SPI Slave Sync output on pin 26
179  PPSOutput(1, RPB15, SS1);
180 
181  // SPI1 data output on pin 17
182  PPSOutput(2, RPB8, SDO1);
183 
184  // SPI channel 1 channel A drives the y axis control mirror.
185  // The messages we send are 16 bits long (4 control bits, 12 signal bits).
186  // The config flags do the following:
187  // - SPICON_MSTEN :: Set to master mode
188  // - SPICON_MODE16 :: Sets the word size to 16 bits
189  // - SPICON_ON :: Module ON Control
190  // - SPICON_FRMPOL :: Polarity of frame signal
191  // - SPICON_CKP :: Reverse clock edges
192  // - SPICON_FRMEN :: Use automatic framing: Serial clock is always on
193  // even when no data is being sent and Slave Select/CS
194  // pulses before each word
195  // The fpbDiv = 2 sets baud rate to Fpb / fpbDiv.
196  SpiChnOpen(Y_MIRROR_SPI_CHN, SPICON_MSTEN | SPICON_MODE16 | SPICON_ON
197  | SPICON_FRMPOL | SPICON_CKP | SPICON_FRMEN, 2);
198 }
#define PIXEL_ON_TIME
How many clock ticks the pixel is on.
Definition: projector.c:48
#define Y_MIRROR_SPI_CHN
Definition: projector.c:42
#define PIXEL_DMA_CHN
Definition: projector.c:41

§ projector_set_pixel()

void projector_set_pixel ( struct color const  color,
unsigned int  x,
unsigned int  y 
)

Set the color of a pixel at the specified location.

Once a pixels value is changed, the new value will be projected the next time the pixel is output (there is no v-sync).

Parameters
colorColor to be displayed
xNumber of pixels from left side
yNumber of pixels from the top

Definition at line 205 of file projector.c.

206  {
210 }
#define BLUE_PHASE_SHIFT
Shift to the right of the blue laser.
Definition: parameters.h:51
char blue
Definition: color.h:43
char red
Definition: color.h:42
Definition: color.h:41
int16_t y
Definition: joystick.h:42
struct color projector_framebuffer[IMAGE_HEIGHT][IMAGE_WIDTH+PHASE_SHIFT_PADDING]
Definition: projector.c:114
char green
Definition: color.h:44
int16_t x
Definition: joystick.h:41
#define GREEN_PHASE_SHIFT
Shift to the right of the green laser.
Definition: parameters.h:43
#define RED_PHASE_SHIFT
Shift to the right of the red laser.
Definition: parameters.h:35