Team Walter / Mbed OS NonPingPong_PICO_LoRa

Dependencies:   SX1276GenericLib USBDevice

Fork of NonPingPong_PICO_LoRa by Walter Luu

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AO32_lib.h Source File

AO32_lib.h

00001 #include "mbed.h"
00002 
00003 //AO32 Registers
00004 #define AO32_DEVICE_ID      0x00    // AO32 Chip ID
00005 #define AO32_STATUS         0x01    // AO32 Status Register
00006 #define AO32_INT            0x02    // AO32 Interrupt Register
00007 #define AO32_INT_MSK        0x03    // AO32 Interrupt Mask Register
00008 #define AO32_SYS_CFG        0x04    // AO32 SYS configuration
00009 #define AO32_WK_CFG         0x05    // AO32 Wake configuration
00010 #define AO32_MPPT_CFG       0x06    // AO32 Maxim Power Point Tracking configuration
00011 #define AO32_MEAS_CFG       0x07    // AO32 Measurement configuration
00012 #define AO32_DEV_CTRL       0x08    // AO32 Device Control
00013 #define AO32_VOC            0x09    // AO32 VOC Measurement
00014 #define AO32_HARV_H         0x0A    // AO32 Harvesting count High byte
00015 #define AO32_HARV_L         0x0B    // AO32 Harvesting count Low byte
00016 #define AO32_SLP            0x0C    // AO32 Sleep threshold
00017    
00018 
00019 #define DEVICE_ACK      0
00020 #define DEVICE_NACK     1
00021 #define DEVICE_BAD_RESP 2
00022 
00023 #define MAX_DEVICES 64      // Maximum number of rom devices allowed
00024 #define ID_LENGTH   6       // Rom ID length in bytes
00025 
00026 struct AO32_struct {
00027     char rom_id[ID_LENGTH];     // device ROM ID
00028     char I2C_address;           // I2C addess, based on GPIO0 and GPIO1 at power up
00029                                 // Why char?
00030 }; 
00031 
00032 struct VOCMeas {
00033     double VOCvalue;  // Open-Circuit Voltage Measurement in Volt
00034     int status;       // Status of OCV read. 0 for success, 1 for error
00035 };
00036 
00037 struct HarvCnt {
00038     double harvCount;   // Harvester Count "LX Pulses" in decimal
00039     int status;       // Status of harvesting count read. 0 for success, 1 for error
00040 };
00041 
00042 // *****************************************************************************
00043 //   AO32_write_register(char, char, char)  writes single byte to AO32
00044 //                       char   I2C address
00045 //                       char   AO32 register address
00046 //                       char   data byte to be writen
00047 //   returns                    0 on success ACK, 1 on NACK 
00048 // *****************************************************************************
00049 int AO32_write_register(I2C *i2c, char I2C_add, char reg_add, char byte);
00050 
00051 /// ****************************************************************************
00052 //   AO32_write_register(char, char, char *, int)  writes multiple bytes to AO32
00053 //                       char   I2C address
00054 //                       char   AO32 register address
00055 //                       char * data vector of bytes to be written
00056 //                       int    number of bytes to write
00057 //   returns                    0 on success ACK, 1 on NACK 
00058 // *****************************************************************************
00059 int AO32_write_register(I2C *i2c, char I2C_add, char reg_add, char *bytes, int n);
00060 
00061 // *****************************************************************************
00062 //   AO32_read_register(char, char, char *)  reads single byte from AO32
00063 //                       char   I2C address
00064 //                       char   AO32 register address
00065 //                       char * data vector for read bytes to be stored in 
00066 //   returns                    0 on success, 1 on fail 
00067 // *****************************************************************************
00068 int AO32_read_register(I2C *i2c, char I2C_add, char reg_add, char *bytes);
00069 
00070 // *****************************************************************************
00071 //   AO32_read_register(char, char, char *, int)  reads byte(s) from AO32
00072 //                       char   I2C address
00073 //                       char   OT07 register address
00074 //                       char * data vector for read bytes to be stored in 
00075 //                       int    number of bytes to read
00076 //   returns                    0 on success, 1 on fail 
00077 // *****************************************************************************
00078 int AO32_read_register(I2C *i2c, char I2C_add, char reg_add, char *bytes, int n);
00079 
00080 //******************************************************************************
00081 // get_luxvalue(char)       read lux value from AO32 device register
00082 //                 char     I2C address
00083 // returns                  LuxResponse luxValue = light intensity in lux 
00084 //                          status = register read result
00085 //******************************************************************************
00086 //LuxResponse get_luxvalue(I2C *i2c, char I2C_add);
00087 
00088 //******************************************************************************
00089 // get_OCV(char)       read Open Circuit Voltage from AO32 device register
00090 //                 char     I2C address
00091 // returns                  VOCMeas VOCvalue = Open-Circuit Voltage Measurement in Volt
00092 //                          status = Status of OCV read. 0 for success, 1 for error
00093 //******************************************************************************
00094 VOCMeas get_OCV(I2C *i2c, char I2C_add);
00095 
00096 //******************************************************************************
00097 // get_Harvest(char)       read harvesting counts from AO32 device register
00098 //                 char     I2C address
00099 // returns                  HarvCnt harvCount = Harvester Count "LX Pulses" in decimal
00100 //                          status = Status of harvesting count read. 0 for success, 1 for error
00101 //******************************************************************************
00102 HarvCnt get_Harvest(I2C *i2c, char I2C_add);
00103 
00104 double calc_OCV(char *data);
00105 
00106 int calc_Harvest(char *data);