aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2015-01-29 11:29:43 +0100
committerLars-Dominik Braun <lars@6xq.net>2015-01-29 11:29:43 +0100
commit708e9eb417ddf41ec345f2be70c4a32721608e4c (patch)
treed33c3c341f4a0aeac3966be3c6e1ca27eb94a7bc
parentaf4ea653a341f3c25cfbb2e7ec4b633bf73913a7 (diff)
downloadhourglass-708e9eb417ddf41ec345f2be70c4a32721608e4c.tar.gz
hourglass-708e9eb417ddf41ec345f2be70c4a32721608e4c.tar.bz2
hourglass-708e9eb417ddf41ec345f2be70c4a32721608e4c.zip
Replace enums with uint8_t
Saves a few bytes, since enums are 16 bit
-rw-r--r--accel.h6
-rw-r--r--common.h10
-rw-r--r--gyro.c10
-rw-r--r--i2c.h22
-rw-r--r--pwm.h5
-rw-r--r--ui.c48
6 files changed, 55 insertions, 46 deletions
diff --git a/accel.h b/accel.h
index b984fdd..129611c 100644
--- a/accel.h
+++ b/accel.h
@@ -4,7 +4,11 @@
#include <stdbool.h>
#include <stdint.h>
-typedef enum {HORIZON_NONE, HORIZON_POS, HORIZON_NEG} horizon;
+#define HORIZON_NONE 0
+#define HORIZON_POS 1
+#define HORIZON_NEG 2
+
+typedef uint8_t horizon;
void accelInit ();
void accelStart ();
diff --git a/common.h b/common.h
index e879e92..42737eb 100644
--- a/common.h
+++ b/common.h
@@ -27,12 +27,10 @@
extern volatile uint8_t wakeup;
/* wakeup sources */
-enum {
- WAKE_ACCEL = 0,
- WAKE_GYRO = 1,
- WAKE_I2C = 2,
- WAKE_TIMER = 3,
-};
+#define WAKE_ACCEL 0
+#define WAKE_GYRO 1
+#define WAKE_I2C 2
+#define WAKE_TIMER 3
#define shouldWakeup(x) (wakeup & (1 << x))
#define enableWakeup(x) wakeup |= 1 << x;
diff --git a/gyro.c b/gyro.c
index 14e25ed..3079c20 100644
--- a/gyro.c
+++ b/gyro.c
@@ -26,7 +26,15 @@ static volatile int16_t zval = 0;
static int32_t zaccum = 0;
/* calculated zticks */
static int16_t zticks = 0;
-static enum {STOPPED = 0, START_REQUEST, STARTING, STOP_REQUEST, STOPPING, READING, IDLE} state = STOPPED;
+
+#define STOPPED 0
+#define START_REQUEST 1
+#define STARTING 2
+#define STOP_REQUEST 3
+#define STOPPING 4
+#define READING 5
+#define IDLE 6
+static uint8_t state = STOPPED;
/* data ready interrupt
*/
diff --git a/i2c.h b/i2c.h
index 1090ee2..fb481e3 100644
--- a/i2c.h
+++ b/i2c.h
@@ -1,17 +1,17 @@
#ifndef TW_H
#define TW_H
-typedef enum {
- TWM_INVALID = 0,
- TWM_WRITE,
- TWM_READ,
-} twMode;
-
-typedef enum {
- TWST_WAIT = 0,
- TWST_OK = 1,
- TWST_ERR = 2,
-} twStatus;
+#include <stdint.h>
+
+typedef uint8_t twMode;
+#define TWM_INVALID 0
+#define TWM_WRITE 1
+#define TWM_READ 2
+
+typedef uint8_t twStatus;
+#define TWST_WAIT 0
+#define TWST_OK 1
+#define TWST_ERR 2
#include <stdint.h>
diff --git a/pwm.h b/pwm.h
index c5075ef..8ca7b51 100644
--- a/pwm.h
+++ b/pwm.h
@@ -8,9 +8,8 @@ void pwmStop ();
void pwmSet (const uint8_t, const uint8_t);
void pwmSetOff ();
-typedef enum {
- SPEAKER_BEEP,
-} speakerMode;
+typedef uint8_t speakerMode;
+#define SPEAKER_BEEP 0
void speakerStart (const speakerMode);
diff --git a/ui.c b/ui.c
index e45acaf..c7a2364 100644
--- a/ui.c
+++ b/ui.c
@@ -34,30 +34,30 @@
#define FLASH_CONFIRM_FINE_OFF FLASH_ENTER_FINE_OFF
#define FLASH_CONFIRM_FINE_NUM (2)
-typedef enum {
- /* initialize */
- UIMODE_INIT = 0,
- /* deep sleep */
- UIMODE_SLEEP,
- /* select time */
- UIMODE_SELECT_COARSE,
- UIMODE_SELECT_FINE,
- /* idle */
- UIMODE_IDLE,
- /* count time */
- UIMODE_RUN,
- /* flash leds */
- UIMODE_FLASH_ON,
- UIMODE_FLASH_OFF,
-} uimode;
-
-typedef enum {
- FLASH_NONE = 0,
- FLASH_ALARM,
- FLASH_ENTER_COARSE,
- FLASH_CONFIRM_COARSE,
- FLASH_CONFIRM_FINE,
-} flashmode;
+/* UI modes, enum would take 16 bits */
+typedef uint8_t uimode;
+/* initialize */
+#define UIMODE_INIT 0
+/* deep sleep */
+#define UIMODE_SLEEP 1
+/* select time */
+#define UIMODE_SELECT_COARSE 2
+#define UIMODE_SELECT_FINE 3
+/* idle */
+#define UIMODE_IDLE 4
+/* count time */
+#define UIMODE_RUN 5
+/* flash leds */
+#define UIMODE_FLASH_ON 6
+#define UIMODE_FLASH_OFF 7
+
+/* flash modes */
+typedef uint8_t flashmode;
+#define FLASH_NONE 0
+#define FLASH_ALARM 1
+#define FLASH_ENTER_COARSE 2
+#define FLASH_CONFIRM_COARSE 3
+#define FLASH_CONFIRM_FINE 4
/* nextmode is used for deciding which mode _FLASH transitions into */
static uimode mode = UIMODE_INIT;