初始版本

This commit is contained in:
xiaozhengsheng
2025-08-19 09:49:41 +08:00
parent 10f1ddf1c1
commit 6df0f7d96e
2974 changed files with 1712873 additions and 54 deletions

View File

@@ -0,0 +1,203 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "bh1745.h"
#define BH1745_SENSOR_WRITE(p_instance, msg) \
nrf_twi_sensor_write(p_instance->p_sensor_data, \
p_instance->sensor_addr, \
msg, \
ARRAY_SIZE(msg), \
true)
ret_code_t bh1745_init(bh1745_instance_t * p_instance)
{
ASSERT(p_instance != NULL);
if (p_instance->p_sensor_data->p_twi_mngr->p_queue->size < BH1745_MIN_QUEUE_SIZE)
{
return NRF_ERROR_INVALID_LENGTH;
}
static const uint8_t msg1[] = {
BH1745_REG_MODE_CONTROL1,
0x00,
0x00,
0x00
};
ret_code_t err = BH1745_SENSOR_WRITE(p_instance, msg1);
if (err != NRF_SUCCESS)
{
return err;
}
static const uint8_t msg2[] = {
BH1745_REG_INTERRUPT,
0x00,
0x01,
0xFF,
0xFF,
0x00,
0x00
};
return BH1745_SENSOR_WRITE(p_instance, msg2);
}
ret_code_t bh1745_sw_reset(bh1745_instance_t * p_instance)
{
ASSERT(p_instance != NULL);
static const uint8_t send_msg[] = {
BH1745_REG_SYSTEM_CONTROL,
BH1745_SW_RESET_MASK
};
return BH1745_SENSOR_WRITE(p_instance, send_msg);
}
ret_code_t bh1745_int_reset(bh1745_instance_t * p_instance)
{
ASSERT(p_instance != NULL);
static const uint8_t send_msg[] = {
BH1745_REG_SYSTEM_CONTROL,
BH1745_INT_RESET_MASK
};
return BH1745_SENSOR_WRITE(p_instance, send_msg);
}
ret_code_t bh1745_meas_cfg(bh1745_instance_t * p_instance,
bh1745_meas_time_t meas_time,
bool enable,
bh1745_gain_t gain)
{
ASSERT(p_instance != NULL);
if (meas_time > BH1745_MEAS_TIME_5120MS)
{
meas_time = BH1745_MEAS_TIME_5120MS;
}
if (gain > BH1745_GAIN_16X)
{
gain = BH1745_GAIN_16X;
}
uint8_t send_msg[] = {
BH1745_REG_MODE_CONTROL1,
0,
0,
0x02
};
NRF_TWI_SENSOR_REG_SET(send_msg[1], BH1745_MEAS_TIME_MASK, BH1745_MEAS_TIME_POS, meas_time);
NRF_TWI_SENSOR_REG_SET(send_msg[2], BH1745_RGBC_EN_MASK, BH1745_RGBC_EN_POS, enable);
NRF_TWI_SENSOR_REG_SET(send_msg[2], BH1745_ADC_GAIN_MASK, BH1745_ADC_GAIN_POS, gain);
return BH1745_SENSOR_WRITE(p_instance, send_msg);
}
ret_code_t bh1745_data_read(bh1745_instance_t * p_instance,
bh1745_data_callback_t user_callback,
bh1745_data_t * p_data)
{
ASSERT(p_instance != NULL);
ASSERT(p_data != NULL);
ret_code_t err_code;
err_code = nrf_twi_sensor_reg_read(p_instance->p_sensor_data,
p_instance->sensor_addr,
BH1745_REG_MODE_CONTROL2,
NULL,
&p_data->valid,
1);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
err_code = nrf_twi_sensor_reg_read(p_instance->p_sensor_data,
p_instance->sensor_addr,
BH1745_REG_RED_DATA_LSB,
(nrf_twi_sensor_reg_cb_t) user_callback,
(uint8_t *) &p_data->red,
BH1745_DATA_REG_NUM);
return err_code;
}
ret_code_t bh1745_int_cfg(bh1745_instance_t * p_instance,
bool latch,
bh1745_int_source_t source,
bool enable,
bh1745_persistence_t persistance)
{
ASSERT(p_instance != NULL);
uint8_t int_reg = 0;
NRF_TWI_SENSOR_REG_SET(int_reg, BH1745_INT_ENABLE_MASK, BH1745_INT_ENABLE_POS, enable);
NRF_TWI_SENSOR_REG_SET(int_reg, BH1745_INT_SOURCE_MASK, BH1745_INT_SOURCE_POS, source);
NRF_TWI_SENSOR_REG_SET(int_reg, BH1745_INT_LATCH_MASK, BH1745_INT_LATCH_POS, latch);
uint8_t send_msg[] = {
BH1745_REG_INTERRUPT,
int_reg,
persistance
};
return BH1745_SENSOR_WRITE(p_instance, send_msg);
}
ret_code_t bh1745_high_thr_set(bh1745_instance_t * p_instance,
uint16_t threshold)
{
ASSERT(p_instance != NULL);
uint8_t send_msg[] = {
BH1745_REG_TH_LSB,
LSB_16(threshold),
MSB_16(threshold)
};
return BH1745_SENSOR_WRITE(p_instance, send_msg);
}
ret_code_t bh1745_low_thr_set(bh1745_instance_t * p_instance,
uint16_t threshold)
{
ASSERT(p_instance != NULL);
uint8_t send_msg[] = {
BH1745_REG_TL_LSB,
LSB_16(threshold),
MSB_16(threshold)
};
return BH1745_SENSOR_WRITE(p_instance, send_msg);
}

View File

@@ -0,0 +1,359 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef BH1745_H
#define BH1745_H
#include "nrf_twi_sensor.h"
#include "bh1745_internal.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Possible sensor addresses.
*/
#define BH1745_BASE_ADDRESS_LOW 0x38U
#define BH1745_BASE_ADDRESS_HIGH 0x39U
// Minimum nrf_twi_sensor message buffer size and nrf_twi_mngr queue length.
#define BH1745_MIN_QUEUE_SIZE 5
/**
* @brief Sensor driver usage.
*
* Sensor instance has to be defined first in global context using @ref BH1745_INSTANCE DEF.
* After that it has to be initialized using @ref bh1745_init.
* At this point sensor instance is ready and all other functions can be used.
*
* Configuration functions schedule TWI operation using @ref nrf_twi_sensor module.
* After calling function, setting will be automatically send to sensor when TWI bus is free.
*
* There are designated functions to read status sensor registers e.g. @ref bh1745_sys_ctrl_read
* As parameters they receive function to be called after register is read, and pointer where
* register value should be stored. From that value specific parameters can be extracted
* using @ref NRF_TWI_SENSOR_REG_VAL_GET macro.
* Example:
* uint8_t part_id = NRF_TWI_SENSOR_REG_VAL_GET(sys_ctrl_reg,
* BH1745_PART_ID_MASK,
* BH1745_PART_ID_POS);
*
* Other functions are self-explanatory or have description on their usage.
*/
/**
* @brief Measurement time.
*/
typedef enum
{
BH1745_MEAS_TIME_160MS,
BH1745_MEAS_TIME_320MS,
BH1745_MEAS_TIME_640MS,
BH1745_MEAS_TIME_1280MS,
BH1745_MEAS_TIME_2560MS,
BH1745_MEAS_TIME_5120MS
} bh1745_meas_time_t;
/**
* @brief RGBC (red, green, blue, clear) gain setting.
*/
typedef enum
{
BH1745_GAIN_1X,
BH1745_GAIN_2X,
BH1745_GAIN_16X
} bh1745_gain_t;
/**
* @brief Persistence settings.
*/
typedef enum
{
BH1745_TOGGLE_EACH_MEASURE,
BH1745_UPDATE_EACH_MEASURE,
BH1745_UPDATE_EVERY_FOURTH,
BH1745_UPDATE_EVERY_EIGHTH
} bh1745_persistence_t;
/**
* @brief Interrupt source settings.
*/
typedef enum
{
BH1745_RED_CHANNEL,
BH1745_GREEN_CHANNEL,
BH1745_BLUE_CHANNEL,
BH1745_CLEAR_CHANNEL
} bh1745_int_source_t;
/**
* @brief Measurement result.
*/
typedef struct
{
uint16_t red; //!< Raw red color value.
uint16_t green; //!< Raw green color value.
uint16_t blue; //!< Raw blue color value.
uint16_t clear; //!< Raw clear color pass value.
uint8_t valid; //!< Mode control 2 register value, used for checking data validity.
} bh1745_data_t;
/**
* @brief RGBC data callback prototype.
*
* @param result Result of operation (NRF_SUCCESS on success,
* otherwise a relevant error code).
* @param[in] p_user_data Pointer to color data structure.
*/
typedef void (* bh1745_data_callback_t)(ret_code_t result, bh1745_data_t * p_user_data);
/**
* @brief Macro that creates sensor instance.
*
* @param[in] _bh1745_inst_name Sensor instance name.
* @param[in] _p_twi_sensor Pointer to common TWI sensor instance. @ref NRF_TWI_SENSOR_DEF
* @param[in] _sensor_address Sensor base address.
*/
#define BH1745_INSTANCE_DEF(_bh1745_inst_name, _p_twi_sensor, _sensor_address) \
BH1745_INTERNAL_INSTANCE_DEF(_bh1745_inst_name, _p_twi_sensor, _sensor_address)
/**
* @brief Function for initializing the BH1745 sensor instance.
*
* TWI manager queue length has to be at least BH1745_MIN_QUEUE_SIZE.
*
* @param[in] p_instance Pointer to the sensor instance.
*
* @return Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
*/
ret_code_t bh1745_init(bh1745_instance_t * p_instance);
/**
* @brief Function for resetting the BH1745 registers.
*
* @param[in] p_instance Pointer to the sensor instance.
*
* @return Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
*/
ret_code_t bh1745_sw_reset(bh1745_instance_t * p_instance);
/**
* @brief Function for resetting the interrupt.
*
* @param[in] p_instance Pointer to the sensor instance.
*
* @return Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
*/
ret_code_t bh1745_int_reset(bh1745_instance_t * p_instance);
/**
* @brief Function for setting measurement configuration.
*
* @param[in] p_instance Pointer to the sensor instance.
* @param[in] meas_time Measurement time.
* @param[in] enable Enable RGBC measurements.
* @param[in] gain Measurement gain.
*
* @return Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
*/
ret_code_t bh1745_meas_cfg(bh1745_instance_t * p_instance,
bh1745_meas_time_t meas_time,
bool enable,
bh1745_gain_t gain);
/**
* @brief Function for setting interrupt configuration.
*
* @param p_instance Pointer to sensor instance.
* @param latch INT pin latch.
* @arg false INT pin is latched until INTERRUPT register is read or initialized.
* @arg true INT pin is updated after each measurement.
* @param source Interrupt source.
* @param enable Enable INT pin.
* @param persistence Set persistence.
*
* @return Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
*/
ret_code_t bh1745_int_cfg(bh1745_instance_t * p_instance,
bool latch,
bh1745_int_source_t source,
bool enable,
bh1745_persistence_t persistance);
/**
* @brief Function for setting high interrupt threshold.
*
* @param[in] p_instance Pointer to sensor instance.
* @param[in] threshold Threshold value.
*
* @return Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
*/
ret_code_t bh1745_high_thr_set(bh1745_instance_t * p_instance,
uint16_t threshold);
/**
* @brief Function for setting low interrupt threshold.
*
* @param[in] p_instance Pointer to sensor instance.
* @param[in] threshold Threshold value.
*
* @return Return error code from nrf_twi_sensor @ref nrf_twi_sensor_write
*/
ret_code_t bh1745_low_thr_set(bh1745_instance_t * p_instance,
uint16_t threshold);
/**
* @brief Function for getting the BH1745 data.
*
* @param[in] p_instance Pointer to the sensor instance.
* @param[in] user_callback Callback function created by user.
* @param[out] p_data The measurement results.
*
* @return Return error code from nrf_twi_sensor @ref nrf_twi_sensor_reg_read
*/
ret_code_t bh1745_data_read(bh1745_instance_t * p_instance,
bh1745_data_callback_t user_callback,
bh1745_data_t * p_data);
/**
* @brief Function for reading system control register.
*
* @param[in] p_instance Pointer to sensor instance.
* @param[in] user_cb Function to be called after register is read.
* @param[out] reg_val Register value, single uint8_t.
*
* @return Return error code from nrf_twi_sensor @ref nrf_twi_sensor_reg_read
*/
__STATIC_INLINE ret_code_t bh1745_sys_ctrl_read(bh1745_instance_t * p_instance,
nrf_twi_sensor_reg_cb_t user_cb,
uint8_t * reg_val);
/**
* @brief Function for reading interrupt register.
*
* @param[in] p_instance Pointer to sensor instance.
* @param[in] user_cb Function to be called after register is read.
* @param[out] reg_val Register value, single uint8_t.
*
* @return Return error code from nrf_twi_sensor @ref nrf_twi_sensor_reg_read
*/
__STATIC_INLINE ret_code_t bh1745_interrupt_read(bh1745_instance_t * p_instance,
nrf_twi_sensor_reg_cb_t user_cb,
uint8_t * reg_val);
/**
* @brief Function for reading manufacturer id register.
*
* @param[in] p_instance Pointer to sensor instance.
* @param[in] user_cb Function to be called after register is read.
* @param[out] reg_val Register value, single uint8_t.
*
* @return Return error code from nrf_twi_sensor @ref nrf_twi_sensor_reg_read
*/
__STATIC_INLINE ret_code_t bh1745_manu_id_read(bh1745_instance_t * p_instance,
nrf_twi_sensor_reg_cb_t user_cb,
uint8_t * reg_val);
/**
* @brief Function for checking if RGBC data has been updated after last configuration change.
*
* This function should be used in data callback.
*
* @param[in] p_instance Pointer to the sensor instance.
*
* @return True if data is valid.
*/
__STATIC_INLINE bool bh1745_is_data_valid(bh1745_data_t * p_data);
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
__STATIC_INLINE ret_code_t bh1745_sys_ctrl_read(bh1745_instance_t * p_instance,
nrf_twi_sensor_reg_cb_t user_cb,
uint8_t * reg_val)
{
ASSERT(p_instance != NULL);
return nrf_twi_sensor_reg_read(p_instance->p_sensor_data,
p_instance->sensor_addr,
BH1745_REG_SYSTEM_CONTROL,
user_cb,
reg_val,
1);
}
__STATIC_INLINE ret_code_t bh1745_interrupt_read(bh1745_instance_t * p_instance,
nrf_twi_sensor_reg_cb_t user_cb,
uint8_t * reg_val)
{
ASSERT(p_instance != NULL);
return nrf_twi_sensor_reg_read(p_instance->p_sensor_data,
p_instance->sensor_addr,
BH1745_REG_INTERRUPT,
user_cb,
reg_val,
1);
}
__STATIC_INLINE ret_code_t bh1745_manu_id_read(bh1745_instance_t * p_instance,
nrf_twi_sensor_reg_cb_t user_cb,
uint8_t * reg_val)
{
ASSERT(p_instance != NULL);
return nrf_twi_sensor_reg_read(p_instance->p_sensor_data,
p_instance->sensor_addr,
BH1745_REG_MANUFACTURER_ID,
user_cb,
reg_val,
1);
}
__STATIC_INLINE bool bh1745_is_data_valid(bh1745_data_t * p_data)
{
return NRF_TWI_SENSOR_REG_VAL_GET(p_data->valid,
BH1745_VALID_MASK,
BH1745_VALID_POS);
}
#endif //SUPPRESS_INLINE_IMPLEMENTATION
#ifdef __cplusplus
}
#endif
#endif // BH1745_H

View File

@@ -0,0 +1,180 @@
/**
* Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef BH1745_INTERNAL_H
#define BH1745_INTERNAL_H
#include "nrf_twi_sensor.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Possible sensor addresses.
*/
#define BH1745_BASE_ADDRESS_LOW 0x38U
#define BH1745_BASE_ADDRESS_HIGH 0x39U
#define BH1745_MIN_QUEUE_SIZE 5
/**
* @brief Sensor registers.
*/
#define BH1745_REG_SYSTEM_CONTROL 0x40
#define BH1745_REG_MODE_CONTROL1 0x41
#define BH1745_REG_MODE_CONTROL2 0x42
#define BH1745_REG_RED_DATA_LSB 0x50
#define BH1745_REG_DINT_DATA_LSB 0x58
#define BH1745_REG_INTERRUPT 0x60
#define BH1745_REG_PERSISTENCE 0x61
#define BH1745_REG_TH_LSB 0x62
#define BH1745_REG_TL_LSB 0x64
#define BH1745_REG_MANUFACTURER_ID 0x92
#define BH1745_DATA_REG_NUM 8
#define BH1745_MANU_ID 0xE0
#define BH1745_PART_ID 0x0B
/**
* @brief System Control register bitmasks.
*/
// Default value for system control register.
#define BH1745_DEF_SYSTEM_CONTROL 0x0B
// Bitmasks for sw reset.
#define BH1745_SW_RESET_POS 7
#define BH1745_SW_RESET_MASK (1 << BH1745_SW_RESET_POS)
// Bitmasks for int reset.
#define BH1745_INT_RESET_POS 6
#define BH1745_INT_RESET_MASK (1 << BH1745_INT_RESET_POS)
// Bitmasks for part id.
#define BH1745_PART_ID_POS 0
#define BH1745_PART_ID_MASK (0x3F << BH1745_PART_ID_POS)
/**
* @brief Mode Control 1 register bitmasks.
*/
// Bitmasks for meas time.
#define BH1745_MEAS_TIME_POS 0
#define BH1745_MEAS_TIME_MASK (0x07 << BH1745_MEAS_TIME_POS)
/**
* @brief Mode Control 2 register bitmasks.
*/
// Bitmasks for valid.
#define BH1745_VALID_POS 7
#define BH1745_VALID_MASK (1 << BH1745_VALID_POS)
// Bitmasks for rgbc en.
#define BH1745_RGBC_EN_POS 4
#define BH1745_RGBC_EN_MASK (1 << BH1745_RGBC_EN_POS)
// Bitmasks for adc gain.
#define BH1745_ADC_GAIN_POS 0
#define BH1745_ADC_GAIN_MASK (3 << BH1745_ADC_GAIN_POS)
/**
* @brief Interrupt register bitmasks.
*/
// Bitmasks for int status.
#define BH1745_INT_STATUS_POS 7
#define BH1745_INT_STATUS_MASK (1 << BH1745_INT_STATUS_POS)
// Bitmasks for int latch.
#define BH1745_INT_LATCH_POS 4
#define BH1745_INT_LATCH_MASK (1 << BH1745_INT_LATCH_POS)
// Bitmasks for int source.
#define BH1745_INT_SOURCE_POS 2
#define BH1745_INT_SOURCE_MASK (3 << BH1745_INT_SOURCE_POS)
// Bitmasks for int enable.
#define BH1745_INT_ENABLE_POS 0
#define BH1745_INT_ENABLE_MASK (1 << BH1745_INT_ENABLE_POS)
/**
* @brief Persistence register bitmasks.
*/
// Default value for persistence register.
#define BH1745_DEF_PERSISTENCE 0x01
// Bitmasks for persistence.
#define BH1745_PERSISTENCE_POS 0
#define BH1745_PERSISTENCE_MASK (3 << BH1745_PERSISTENCE_POS)
// Default value for high threshold registers.
#define BH1745_DEF_TH 0xFFFF
/**
* @brief Sensor instance information.
*/
typedef struct
{
nrf_twi_sensor_t * const p_sensor_data;
uint8_t const sensor_addr;
} bh1745_instance_t;
#define BH1745_INTERNAL_INSTANCE_DEF(_bh1745_inst_name, _p_twi_sensor, _sensor_address) \
static bh1745_instance_t _bh1745_inst_name = \
{ \
.p_sensor_data = _p_twi_sensor, \
.sensor_addr = _sensor_address \
}
#ifdef __cplusplus
}
#endif
#endif // BH1745_INTERNAL_H