forked from flipperdevices/flipperzero-firmware
-
-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support MAX44009 i2c sensor * Fix conversion factor --------- Co-authored-by: wosk <nikita.vostokov@auriga.com> Co-authored-by: Oleksii Kutuzov <oleksii.kutuzov@icloud.com>
- Loading branch information
1 parent
f64b084
commit 5de076e
Showing
10 changed files
with
139 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <MAX44009.h> | ||
#include <math.h> | ||
#include <furi.h> | ||
|
||
void max44009_init() { | ||
furi_hal_i2c_acquire(I2C_BUS); | ||
furi_hal_i2c_write_reg_8(I2C_BUS, MAX44009_ADDR, | ||
MAX44009_REG_CONFIG, MAX44009_REG_CONFIG_CONT_MODE, I2C_TIMEOUT); | ||
furi_hal_i2c_release(I2C_BUS); | ||
} | ||
|
||
int max44009_read_light(float* result) { | ||
uint8_t data_one = 0; | ||
uint8_t exp, mantissa; | ||
int status; | ||
|
||
furi_hal_i2c_acquire(I2C_BUS); | ||
furi_hal_i2c_read_reg_8(I2C_BUS, MAX44009_ADDR, MAX44009_REG_LUX_HI, &data_one, I2C_TIMEOUT); | ||
exp = (data_one & MAX44009_REG_LUX_HI_EXP_MASK) >> 4; | ||
mantissa = (data_one & MAX44009_REG_LUX_HI_MANT_HI_MASK) << 4; | ||
status = furi_hal_i2c_read_reg_8(I2C_BUS, MAX44009_ADDR, MAX44009_REG_LUX_LO, &data_one, I2C_TIMEOUT); | ||
mantissa |= (data_one & MAX44009_REG_LUX_LO_MANT_LO_MASK); | ||
furi_hal_i2c_release(I2C_BUS); | ||
*result = (float)pow(2, exp) * mantissa * 0.045; | ||
FURI_LOG_D("MAX44009", "exp %d, mant %d, lux %f", exp, mantissa, (double)*result); | ||
return status; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <furi.h> | ||
#include <furi_hal.h> | ||
|
||
#pragma once | ||
|
||
// I2C BUS | ||
#define I2C_BUS &furi_hal_i2c_handle_external | ||
#define I2C_TIMEOUT 10 | ||
|
||
#define MAX44009_ADDR (0x4A << 1) | ||
|
||
#define MAX44009_REG_INT_STATUS 0x00 | ||
#define MAX44009_REG_INT_EN 0x01 | ||
#define MAX44009_REG_CONFIG 0x02 | ||
#define MAX44009_REG_CONFIG_CONT_MODE (1 << 7) | ||
#define MAX44009_REG_LUX_HI 0x03 | ||
#define MAX44009_REG_LUX_HI_EXP_MASK 0xF0 | ||
#define MAX44009_REG_LUX_HI_MANT_HI_MASK 0x0F | ||
#define MAX44009_REG_LUX_LO 0x04 | ||
#define MAX44009_REG_LUX_LO_MANT_LO_MASK 0x0F | ||
#define MAX44009_REG_THRESH_HI 0x05 | ||
#define MAX44009_REG_THRESH_LO 0x06 | ||
#define MAX44009_REG_INT_TIME 0x07 | ||
|
||
void max44009_init(); | ||
int max44009_read_light(float* result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters