Move defined constants to enums

This commit is contained in:
Brian Schwind 2016-10-11 21:39:22 +09:00
parent cd594a4296
commit 6449f243fc
2 changed files with 22 additions and 13 deletions

View file

@ -168,7 +168,7 @@ void tsl2561_init(tsl2561_t *device)
disable(device->i2c_addr);
}
void tsl2561_set_integration_time(tsl2561_t *device, uint8_t integration_time_id)
void tsl2561_set_integration_time(tsl2561_t *device, tsl2561_integration_time_t integration_time_id)
{
enable(device->i2c_addr);
write_register(device->i2c_addr, TSL2561_REG_TIMING, integration_time_id | device->gain);
@ -177,7 +177,7 @@ void tsl2561_set_integration_time(tsl2561_t *device, uint8_t integration_time_id
device->integration_time = integration_time_id;
}
void tsl2561_set_gain(tsl2561_t *device, uint8_t gain)
void tsl2561_set_gain(tsl2561_t *device, tsl2561_gain_t gain)
{
enable(device->i2c_addr);
write_register(device->i2c_addr, TSL2561_REG_TIMING, gain | device->integration_time);

View file

@ -11,29 +11,38 @@
#include <stdbool.h>
// I2C Addresses
#define TSL2561_I2C_ADDR_VCC 0x49
#define TSL2561_I2C_ADDR_GND 0x29
#define TSL2561_I2C_ADDR_FLOAT 0x39 // Default
typedef enum
{
TSL2561_I2C_ADDR_VCC = 0x49,
TSL2561_I2C_ADDR_GND = 0x29,
TSL2561_I2C_ADDR_FLOAT = 0x39 // Default
} tsl2561_i2c_addr_t;
// Integration time IDs
#define TSL2561_INTEGRATION_13MS 0x00
#define TSL2561_INTEGRATION_101MS 0x01
#define TSL2561_INTEGRATION_402MS 0x02 // Default
typedef enum
{
TSL2561_INTEGRATION_13MS = 0x00,
TSL2561_INTEGRATION_101MS = 0x01,
TSL2561_INTEGRATION_402MS = 0x02 // Default
} tsl2561_integration_time_t;
// Gain IDs
#define TSL2561_GAIN_1X 0x00
#define TSL2561_GAIN_16X 0x10
typedef enum
{
TSL2561_GAIN_1X = 0x00, // Default
TSL2561_GAIN_16X = 0x10
} tsl2561_gain_t;
typedef struct {
uint8_t i2c_addr;
tsl2561_i2c_addr_t i2c_addr;
uint8_t integration_time;
uint8_t gain;
uint8_t package_type;
} tsl2561_t;
void tsl2561_init(tsl2561_t *device);
void tsl2561_set_integration_time(tsl2561_t *device, uint8_t integration_time_id);
void tsl2561_set_gain(tsl2561_t *device, uint8_t gain);
void tsl2561_set_integration_time(tsl2561_t *device, tsl2561_integration_time_t integration_time_id);
void tsl2561_set_gain(tsl2561_t *device, tsl2561_gain_t gain);
bool tsl2561_read_lux(tsl2561_t *device, uint32_t *lux);
#endif // __TSL2561_H__