Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SX1276GenericLib USBDevice
Fork of NonPingPong_PICO_LoRa by
MAX44009_lib.h
00001 #include "mbed.h" 00002 00003 //MAX44009 Registers 00004 #define MAX44009_INT_STATUS 0x00 // MAX44009 interrupt status regiter 00005 #define MAX44009_INT_EN 0x01 // MAX44009 Interrupt Enable 00006 #define MAX44009_CONFIG 0x02 // MAX44009 Configuration Register 00007 #define MAX44009_LUX_HI 0x03 // MAX44009 Lux High Byte 00008 #define MAX44009_LUX_LO 0x04 // MAX44009 Lux Low Byte 00009 #define MAX44009_THR_HI 0x05 // MAX44009 Upper Threshold High Byte 00010 #define MAX44009_THR_LO 0x06 // MAX44009 Lower Threshold High Byte 00011 #define MAX44009_THR_TM 0x07 // MAX44009 Threshold Timer 00012 00013 #define DEVICE_ACK 0 00014 #define DEVICE_NACK 1 00015 #define DEVICE_BAD_RESP 2 00016 00017 #define MAX_DEVICES 64 // Maximum number of rom devices allowed 00018 #define ID_LENGTH 6 // Rom ID length in bytes 00019 00020 struct MAX44009_struct { 00021 char rom_id[ID_LENGTH]; // device ROM ID 00022 char I2C_address; // I2C addess, based on GPIO0 and GPIO1 at power up 00023 // Why char? 00024 }; 00025 00026 struct LuxResponse { 00027 double luxValue; // Light level in lux 00028 int status; // Status of Lux read. 0 for success, 1 for error 00029 }; 00030 00031 // ***************************************************************************** 00032 // MAX44009_write_register(char, char, char) writes single byte to MAX44009 00033 // char I2C address 00034 // char MAX44009 register address 00035 // char data byte to be writen 00036 // returns 0 on success ACK, 1 on NACK 00037 // ***************************************************************************** 00038 int MAX44009_write_register(I2C *i2c, char I2C_add, char reg_add, char byte); 00039 00040 /// **************************************************************************** 00041 // MAX44009_write_register(char, char, char *, int) writes multiple bytes to MAX44009 00042 // char I2C address 00043 // char MAX44009 register address 00044 // char * data vector of bytes to be written 00045 // int number of bytes to write 00046 // returns 0 on success ACK, 1 on NACK 00047 // ***************************************************************************** 00048 int MAX44009_write_register(I2C *i2c, char I2C_add, char reg_add, char *bytes, int n); 00049 00050 // ***************************************************************************** 00051 // MAX44009_read_register(char, char, char *, int) reads single byte from MAX44009 00052 // char I2C address 00053 // char MAX44009 register address 00054 // char * data vector for read bytes to be stored in 00055 // returns 0 on success, 1 on fail 00056 // ***************************************************************************** 00057 int MAX44009_read_register(I2C *i2c, char I2C_add, char reg_add, char *bytes); 00058 00059 // ***************************************************************************** 00060 // MAX44009_read_lux_register(char, char, char *, int) reads lux value bytes from MAX44009 00061 // char I2C address 00062 // char MAX44009 register address 00063 // char * data vector for read bytes to be stored in 00064 // returns 0 on success, 1 on fail 00065 // ***************************************************************************** 00066 int MAX44009_read_lux_register(I2C *i2c, char I2C_add, char reg_add, char *bytes); 00067 00068 // ***************************************************************************** 00069 // convert_temperature(char) sends convert command to MAX44009 device 00070 // char I2C address 00071 // ***************************************************************************** 00072 //void convert_temperature(I2C *i2c, char I2C_add); 00073 00074 //****************************************************************************** 00075 // get_luxvalue(char) read lux value from MAX44009 device register 00076 // char I2C address 00077 // returns LuxResponse luxValue = light intensity in lux 00078 // status = register read result 00079 //****************************************************************************** 00080 LuxResponse get_luxvalue(I2C *i2c, char I2C_add); 00081 00082 double calc_lux(char *data);
Generated on Mon Jul 18 2022 15:25:00 by
1.7.2
