@@ -96,7 +96,7 @@ static void dma_callback(Adafruit_ZeroDMA *dma) {
9696
9797SPISettings settings (DISPLAY_FREQ, MSBFIRST, SPI_MODE0);
9898
99- // The time required to issue one scanline (240 pixels x 16 bits) over
99+ // The time required to issue one scanline (DISPLAY_SIZE pixels x 16 bits) over
100100// SPI is a known(ish) quantity. The DMA scheduler isn't always perfectly
101101// deterministic though...especially on startup, as things make their way
102102// into caches. Very occasionally, something (not known yet) is causing
@@ -107,7 +107,7 @@ SPISettings settings(DISPLAY_FREQ, MSBFIRST, SPI_MODE0);
107107// below, to allow for caching/scheduling fudge). If so, that's our signal
108108// that something is likely amiss and we take evasive maneuvers, resetting
109109// the affected DMA channel (DMAbuddy::fix()).
110- #define DMA_TIMEOUT ((240 * 16 * 4000 ) / (DISPLAY_FREQ / 1000 ))
110+ #define DMA_TIMEOUT ((DISPLAY_SIZE * 16 * 4000 ) / (DISPLAY_FREQ / 1000 ))
111111
112112static inline uint16_t readBoop (void ) {
113113 uint16_t counter = 0 ;
@@ -228,7 +228,7 @@ void setup() {
228228 eye[e].column [i].descriptor [j].DSTADDR .reg = spi_data_reg;
229229 }
230230 }
231- eye[e].colNum = 240 ; // Force initial wraparound to first column
231+ eye[e].colNum = DISPLAY_SIZE ; // Force initial wraparound to first column
232232 eye[e].colIdx = 0 ;
233233 eye[e].dma_busy = false ;
234234 eye[e].column_ready = false ;
@@ -357,7 +357,7 @@ void setup() {
357357
358358 status = loadEyelid (upperEyelidFilename ?
359359 upperEyelidFilename : (char *)" upper.bmp" ,
360- upperClosed, upperOpen, 239 , maxRam);
360+ upperClosed, upperOpen, DISPLAY_SIZE- 1 , maxRam);
361361
362362 status = loadEyelid (lowerEyelidFilename ?
363363 lowerEyelidFilename : (char *)" lower.bmp" ,
@@ -407,7 +407,7 @@ void setup() {
407407 yield ();
408408 if (boopPin >= 0 ) {
409409 boopThreshold = 0 ;
410- for (int i=0 ; i<240 ; i++) {
410+ for (int i=0 ; i<DISPLAY_SIZE ; i++) {
411411 boopThreshold += readBoop ();
412412 }
413413 boopThreshold = boopThreshold * 110 / 100 ; // 10% overhead
@@ -486,7 +486,7 @@ void loop() {
486486 eyeX = eyeOldX;
487487 eyeY = eyeOldY;
488488 if (dt > eyeMoveDuration) { // Time up? Begin new move.
489- float r = (float )mapDiameter - 240.0 * M_PI_2; // radius of motion
489+ float r = (float )mapDiameter - ( float )DISPLAY_SIZE * M_PI_2; // radius of motion
490490 r *= 0.6 ;
491491 eyeNewX = random (-r, r);
492492 float h = sqrt (r * r - x * x);
@@ -533,10 +533,10 @@ void loop() {
533533 float uq, lq; // So many sloppy temp vars in here for now, sorry
534534 if (tracking) {
535535 // Eyelids naturally "track" the pupils (move up or down automatically)
536- int ix = (int )map2screen (mapRadius - eye[eyeNum].eyeX ) + 120 , // Pupil position
537- iy = (int )map2screen (mapRadius - eye[eyeNum].eyeY ) + 120 ; // on screen
536+ int ix = (int )map2screen (mapRadius - eye[eyeNum].eyeX ) + (DISPLAY_SIZE/ 2 ) , // Pupil position
537+ iy = (int )map2screen (mapRadius - eye[eyeNum].eyeY ) + (DISPLAY_SIZE/ 2 ) ; // on screen
538538 iy += irisRadius * trackFactor;
539- if (eyeNum & 1 ) ix = 239 - ix; // Flip for right eye
539+ if (eyeNum & 1 ) ix = DISPLAY_SIZE - 1 - ix; // Flip for right eye
540540 if (iy > upperOpen[ix]) {
541541 uq = 1.0 ;
542542 } else if (iy < upperClosed[ix]) {
@@ -625,40 +625,40 @@ void loop() {
625625
626626 // Should be possible for these to be local vars,
627627 // but the animation becomes super chunky then, what gives?
628- xPositionOverMap = (int )(eye[eyeNum].eyeX - 120.0 );
629- yPositionOverMap = (int )(eye[eyeNum].eyeY - 120.0 );
628+ xPositionOverMap = (int )(eye[eyeNum].eyeX - (DISPLAY_SIZE/ 2.0 ) );
629+ yPositionOverMap = (int )(eye[eyeNum].eyeY - (DISPLAY_SIZE/ 2.0 ) );
630630
631631 // These are constant across frame and could be stored in eye struct
632632 float upperLidFactor = (1.0 - eye[eyeNum].blinkFactor ) * eye[eyeNum].upperLidFactor ,
633633 lowerLidFactor = (1.0 - eye[eyeNum].blinkFactor ) * eye[eyeNum].lowerLidFactor ;
634634 iPupilFactor = (int )((float )eye[eyeNum].iris .height * 256 * (1.0 / eye[eyeNum].pupilFactor ));
635635
636636 int y1, y2;
637- int lidColumn = (eyeNum & 1 ) ? (239 - x) : x; // Reverse eyelid columns for left eye
637+ int lidColumn = (eyeNum & 1 ) ? (DISPLAY_SIZE - 1 - x) : x; // Reverse eyelid columns for left eye
638638
639639 DmacDescriptor *d = &eye[eyeNum].column [eye[eyeNum].colIdx ].descriptor [0 ];
640640
641641 if (upperOpen[lidColumn] == 255 ) {
642642 // No eyelid data for this line; eyelid image is smaller than screen.
643643 // Great! Make a full scanline of nothing, no rendering needed:
644644 d->BTCTRL .bit .SRCINC = 0 ;
645- d->BTCNT .reg = 240 * 2 ;
645+ d->BTCNT .reg = DISPLAY_SIZE * 2 ;
646646 d->SRCADDR .reg = (uint32_t )&eyelidIndex;
647647 d->DESCADDR .reg = 0 ; // No linked descriptor
648648 } else {
649649 y1 = lowerClosed[lidColumn] + (int )(0.5 + lowerLidFactor *
650650 (float )((int )lowerOpen[lidColumn] - (int )lowerClosed[lidColumn]));
651651 y2 = upperClosed[lidColumn] + (int )(0.5 + upperLidFactor *
652652 (float )((int )upperOpen[lidColumn] - (int )upperClosed[lidColumn]));
653- if (y1 > 239 ) y1 = 239 ; // Clip results in case lidfactor
653+ if (y1 > DISPLAY_SIZE- 1 ) y1 = DISPLAY_SIZE- 1 ; // Clip results in case lidfactor
654654 else if (y1 < 0 ) y1 = 0 ; // is beyond the usual 0.0 to 1.0 range
655- if (y2 > 239 ) y2 = 239 ;
655+ if (y2 > DISPLAY_SIZE- 1 ) y2 = DISPLAY_SIZE- 1 ;
656656 else if (y2 < 0 ) y2 = 0 ;
657657 if (y1 >= y2) {
658658 // Eyelid is fully or partially closed, enough that there are no
659659 // pixels to be rendered for this line. Make "nothing," as above.
660660 d->BTCTRL .bit .SRCINC = 0 ;
661- d->BTCNT .reg = 240 * 2 ;
661+ d->BTCNT .reg = DISPLAY_SIZE * 2 ;
662662 d->SRCADDR .reg = (uint32_t )&eyelidIndex;
663663 d->DESCADDR .reg = 0 ; // No linked descriptors
664664 } else {
@@ -681,11 +681,11 @@ void loop() {
681681 d->BTCNT .reg = renderlen * 2 ;
682682 d->SRCADDR .reg = (uint32_t )eye[eyeNum].column [eye[eyeNum].colIdx ].renderBuf + renderlen * 2 ; // Point to END of data!
683683#else
684- // Full column will be rendered; 240 pixels, point source to end of
684+ // Full column will be rendered; DISPLAY_SIZE pixels, point source to end of
685685 // renderBuf and enable source increment.
686686 d->BTCTRL .bit .SRCINC = 1 ;
687- d->BTCNT .reg = 240 * 2 ;
688- d->SRCADDR .reg = (uint32_t )eye[eyeNum].column [eye[eyeNum].colIdx ].renderBuf + 240 * 2 ;
687+ d->BTCNT .reg = DISPLAY_SIZE * 2 ;
688+ d->SRCADDR .reg = (uint32_t )eye[eyeNum].column [eye[eyeNum].colIdx ].renderBuf + DISPLAY_SIZE * 2 ;
689689 d->DESCADDR .reg = 0 ; // No linked descriptors
690690#endif
691691 // Render column 'x' into eye's next available renderBuf
@@ -704,28 +704,28 @@ void loop() {
704704 uint8_t *displaceX, *displaceY;
705705 int8_t xmul; // Sign of X displacement: +1 or -1
706706 int doff; // Offset into displacement arrays
707- if (x < 120 ) { // Left half of screen (quadrants 2, 3)
708- displaceX = &displace[ 119 - x ];
709- displaceY = &displace[(119 - x) * 120 ];
707+ if (x < (DISPLAY_SIZE/ 2 ) ) { // Left half of screen (quadrants 2, 3)
708+ displaceX = &displace[ (DISPLAY_SIZE/ 2 - 1 ) - x ];
709+ displaceY = &displace[((DISPLAY_SIZE/ 2 - 1 ) - x) * (DISPLAY_SIZE/ 2 ) ];
710710 xmul = -1 ; // X displacement is always negative
711711 } else { // Right half of screen( quadrants 1, 4)
712- displaceX = &displace[ x - 120 ];
713- displaceY = &displace[(x - 120 ) * 120 ];
712+ displaceX = &displace[ x - (DISPLAY_SIZE/ 2 ) ];
713+ displaceY = &displace[(x - (DISPLAY_SIZE/ 2 )) * (DISPLAY_SIZE/ 2 ) ];
714714 xmul = 1 ; // X displacement is always positive
715715 }
716716
717717 for (; y<=y2; y++) { // For each pixel of open eye in this column...
718718 int yy = yPositionOverMap + y;
719719 int dx, dy;
720720
721- if (y < 120 ) { // Lower half of screen (quadrants 3, 4)
722- doff = 119 - y;
721+ if (y < (DISPLAY_SIZE/ 2 ) ) { // Lower half of screen (quadrants 3, 4)
722+ doff = (DISPLAY_SIZE/ 2 - 1 ) - y;
723723 dy = -displaceY[doff];
724724 } else { // Upper half of screen (quadrants 1, 2)
725- doff = y - 120 ;
725+ doff = y - (DISPLAY_SIZE/ 2 ) ;
726726 dy = displaceY[doff];
727727 }
728- dx = displaceX[doff * 120 ];
728+ dx = displaceX[doff * (DISPLAY_SIZE/ 2 ) ];
729729 if (dx < 255 ) { // Inside eyeball area
730730 dx *= xmul; // Flip sign of x offset if in quadrants 2 or 3
731731 int mx = xx + dx; // Polar angle/dist map coords
@@ -795,17 +795,17 @@ void loop() {
795795
796796#if NUM_DESCRIPTORS == 1
797797 // Render upper eyelid if needed
798- for (; y<240 ; y++) *ptr++ = eyelidColor;
798+ for (; y<DISPLAY_SIZE ; y++) *ptr++ = eyelidColor;
799799#else
800- if (y2 >= 239 ) {
800+ if (y2 >= (DISPLAY_SIZE- 1 ) ) {
801801 // No third descriptor; close it off
802802 d->DESCADDR .reg = 0 ;
803803 } else {
804804 next = &eye[eyeNum].column [eye[eyeNum].colIdx ].descriptor [(y1 > 0 ) ? 2 : 1 ];
805805 d->DESCADDR .reg = (uint32_t )next; // link to next descriptor
806806 d = next; // Increment descriptor
807807 d->BTCTRL .bit .SRCINC = 0 ;
808- d->BTCNT .reg = (239 - y2) * 2 ;
808+ d->BTCNT .reg = ((DISPLAY_SIZE- 1 ) - y2) * 2 ;
809809 d->SRCADDR .reg = (uint32_t )&eyelidIndex;
810810 d->DESCADDR .reg = 0 ; // end of descriptor list
811811 }
@@ -840,7 +840,7 @@ void loop() {
840840 // Initialize new SPI transaction & address window...
841841 eye[eyeNum].spi ->beginTransaction (settings);
842842 digitalWrite (eye[eyeNum].cs , LOW); // Chip select
843- eye[eyeNum].display ->setAddrWindow (0 , 0 , 240 , 240 );
843+ eye[eyeNum].display ->setAddrWindow (0 , 0 , DISPLAY_SIZE, DISPLAY_SIZE );
844844 delayMicroseconds (1 );
845845 digitalWrite (eye[eyeNum].dc , HIGH); // Data mode
846846 if (eyeNum == (NUM_EYES-1 )) {
@@ -923,7 +923,7 @@ void loop() {
923923 eye[eyeNum].dma_busy = true ;
924924 eye[eyeNum].dma .startJob ();
925925 eye[eyeNum].dmaStartTime = micros ();
926- if (++eye[eyeNum].colNum >= 240 ) { // If last line sent...
926+ if (++eye[eyeNum].colNum >= DISPLAY_SIZE ) { // If last line sent...
927927 eye[eyeNum].colNum = 0 ; // Wrap to beginning
928928 }
929929 eye[eyeNum].colIdx ^= 1 ; // Alternate 0/1 line structs
0 commit comments