Trammell Hudson avatar Trammell Hudson committed 3ab25cf Draft

save a few bytes of SRAM

Comments (0)

Files changed (2)

+/** \file
+ * Allow cross compilation of code that uses AVR program memory spaces.
+ */
+#ifndef _memspaces_h_
+#define _memspaces_h_
+
+#ifdef __AVR__
+#include <avr/pgmspace.h>
+#else
+#define PROGMEM /* Nop */
+#define pgm_read_byte(p) *((const uint8_t*) p)
+#endif
+
+#endif
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include "memspaces.h"
 
 
-static const uint8_t sin_table[] = {
+static const uint8_t PROGMEM sin_table[] = {
 	0,
 	25,
 	50,
 		sign = -1;
 	}
 
-	int16_t s1 = sin_table[(theta >> 2) + 0];
-	int16_t s2 = sin_table[(theta >> 2) + 1];
+	int16_t s1 = pgm_read_byte(&sin_table[(theta >> 2) + 0]);
+	int16_t s2 = pgm_read_byte(&sin_table[(theta >> 2) + 1]);
 	int8_t result = (s1 + ((s2 - s1) * (theta & 0x3)) / 4) / 2;
 
 	if (sign == -1)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.