diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2015-01-29 11:29:43 +0100 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2015-01-29 11:29:43 +0100 |
commit | 708e9eb417ddf41ec345f2be70c4a32721608e4c (patch) | |
tree | d33c3c341f4a0aeac3966be3c6e1ca27eb94a7bc | |
parent | af4ea653a341f3c25cfbb2e7ec4b633bf73913a7 (diff) | |
download | hourglass-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.h | 6 | ||||
-rw-r--r-- | common.h | 10 | ||||
-rw-r--r-- | gyro.c | 10 | ||||
-rw-r--r-- | i2c.h | 22 | ||||
-rw-r--r-- | pwm.h | 5 | ||||
-rw-r--r-- | ui.c | 48 |
6 files changed, 55 insertions, 46 deletions
@@ -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 (); @@ -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; @@ -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 */ @@ -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> @@ -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); @@ -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; |