123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- #ifndef BH1745_H
- #define BH1745_H
- #include "nrf_twi_sensor.h"
- #include "bh1745_internal.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define BH1745_BASE_ADDRESS_LOW 0x38U
- #define BH1745_BASE_ADDRESS_HIGH 0x39U
- #define BH1745_MIN_QUEUE_SIZE 5
- 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;
- typedef enum
- {
- BH1745_GAIN_1X,
- BH1745_GAIN_2X,
- BH1745_GAIN_16X
- } bh1745_gain_t;
- typedef enum
- {
- BH1745_TOGGLE_EACH_MEASURE,
- BH1745_UPDATE_EACH_MEASURE,
- BH1745_UPDATE_EVERY_FOURTH,
- BH1745_UPDATE_EVERY_EIGHTH
- } bh1745_persistence_t;
- typedef enum
- {
- BH1745_RED_CHANNEL,
- BH1745_GREEN_CHANNEL,
- BH1745_BLUE_CHANNEL,
- BH1745_CLEAR_CHANNEL
- } bh1745_int_source_t;
- typedef struct
- {
- uint16_t red;
- uint16_t green;
- uint16_t blue;
- uint16_t clear;
- uint8_t valid;
- } bh1745_data_t;
- typedef void (* bh1745_data_callback_t)(ret_code_t result, bh1745_data_t * p_user_data);
- #define BH1745_INSTANCE_DEF(_bh1745_inst_name, _p_twi_sensor, _sensor_address) \
- BH1745_INTERNAL_INSTANCE_DEF(_bh1745_inst_name, _p_twi_sensor, _sensor_address)
- ret_code_t bh1745_init(bh1745_instance_t * p_instance);
- ret_code_t bh1745_sw_reset(bh1745_instance_t * p_instance);
- ret_code_t bh1745_int_reset(bh1745_instance_t * p_instance);
- ret_code_t bh1745_meas_cfg(bh1745_instance_t * p_instance,
- bh1745_meas_time_t meas_time,
- bool enable,
- bh1745_gain_t gain);
- ret_code_t bh1745_int_cfg(bh1745_instance_t * p_instance,
- bool latch,
- bh1745_int_source_t source,
- bool enable,
- bh1745_persistence_t persistance);
- ret_code_t bh1745_high_thr_set(bh1745_instance_t * p_instance,
- uint16_t threshold);
- ret_code_t bh1745_low_thr_set(bh1745_instance_t * p_instance,
- uint16_t threshold);
- ret_code_t bh1745_data_read(bh1745_instance_t * p_instance,
- bh1745_data_callback_t user_callback,
- bh1745_data_t * p_data);
- __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);
- __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);
- __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);
- __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
- #ifdef __cplusplus
- }
- #endif
- #endif
|