Skip to content

Commit

Permalink
add ina219
Browse files Browse the repository at this point in the history
  • Loading branch information
pvvx committed Apr 15, 2016
1 parent a15a387 commit aa7da1c
Show file tree
Hide file tree
Showing 13 changed files with 623 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ESPOPTION ?= -p COM2 -b 460800

UPLOADADDR = http://aesp8266/fsupload

UPLOADOVL = ./ovls/bin/10dof.ovl
UPLOADOVL = ./ovls/bin/ina219.ovl

# SPI_SPEED = 40MHz or 80MHz
SPI_SPEED?=80
Expand Down
32 changes: 25 additions & 7 deletions WEBFiles/protect/init.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
mdbfini=protect/mdbini.bin
sys_ram0x60000f00=0x48
sys_ram0x60000f00=0x65
sys_ram0x60000f00=0x6c
sys_ram0x60000f00=0x6c
sys_ram0x60000f00=0x6f
sys_ram0x60000f00=0x21
cfg_pinclr=0
cfg_debug=0
cfg_tcp_port=0
cfg_cdns=1
cfg_save=1
gpio0_out=1
gpio0_dir=1
gpio1_out=1
gpio1_dir=1
gpio2_out=1
gpio2_dir=1
gpio3_out=1
gpio3_dir=1
gpio4_out=1
gpio4_dir=1
gpio5_out=1
gpio5_dir=1
gpio12_out=1
gpio12_dir=1
gpio13_out=1
gpio13_dir=1
gpio14_out=1
gpio14_dir=1
gpio15_out=0
gpio15_dir=1
2 changes: 1 addition & 1 deletion app/include/wifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#endif

#define MAX_PHY_TPW 82 // maximum value of RF Tx Power, unit : 0.25dBm, range 0..82
#define DEF_MAX_PHY_TPW 82 // maximum value of RF Tx Power, unit : 0.25dBm, range 0..82
#define DEF_MAX_PHY_TPW 75 // maximum value of RF Tx Power, unit : 0.25dBm, range 0..82


#ifndef DEBUGSOO
Expand Down
Binary file modified bin/0x07000.bin
Binary file not shown.
71 changes: 71 additions & 0 deletions ovls/ina219/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
OUTNAME = ina219.ovl
TARGET = eagle

ifndef PDIR # {
GEN_IMAGES= eagle.app.v6.out
GEN_BINS = eagle.app.v6.bin

SUBDIRS = main

endif # } PDIR

APPDIR = .
LDDIR = $(WEB_BASE)/ld

LD_FILE = $(LDDIR)/overlay.ld
DEPENDS_eagle.app.v6 = \
$(LD_FILE) \
$(LDDIR)/overlay.ld

COMPONENTS_eagle.app.v6 = \
main/libmain.a

LINK_LIBS = \
-lmgcc


LINKFLAGS_eagle.app.v6 = \
-nostartfiles \
-nodefaultlibs \
-nostdlib \
-L$(WEB_BASE)/lib \
-T$(LD_FILE) \
-Wl,--no-check-sections \
-u call_user_start \
-Wl,-static \
-Wl,-Map -Wl,$(@:.out=.map) \
-Wl,--start-group \
$(LINK_LIBS) \
$(DEP_LIBS_eagle.app.v6) \
-Wl,--end-group

CONFIGURATION_DEFINES += \
-DICACHE_FLASH \
-DPBUF_RSV_FOR_WLAN \
-DLWIP_OPEN_SRC \
-DEBUF_LWIP


DEFINES += $(CONFIGURATION_DEFINES)

DDEFINES += $(CONFIGURATION_DEFINES)

#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#

INCLUDES := $(INCLUDES) -I $(PDIR)include
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile


.PHONY: FORCE
FORCE:
21 changes: 21 additions & 0 deletions ovls/ina219/include/fost02.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef _FOST02_H_
#define _FOST02_H_

#define HDT14BIT 1 // =1 12/14bit, =0 8/12bit
#define PTATD1 39.9 // = 39.6 if Vdd = 3.3V, = 39.9 if Vdd = 5V

#define HTD_MT 0b00000011 //Read Measure Temperature
#define HTD_MH 0b00000101 //Read Measure Humidity
#define HTD_RS 0b00000111 //Read Status Register
#define HTD_WS 0b00000110 //Write Status Register
#define HTD_SR 0b00011110 //Soft reset

//extern adc4value T,RH,Dp;

int OpenHMSdrv(void);
int CloseHMSdrv(void);
void s_connectionreset(void);

void ReadHMS(void);

#endif //_FOST02_H_
23 changes: 23 additions & 0 deletions ovls/ina219/include/i2c_drv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* i2c_drv.h
*
* Created on: 05.03.2016
* Author: PVV
*/

#ifndef _I2C_DRV_H_
#define _I2C_DRV_H_

int i2c_init(uint32 scl, uint32 sda, uint32 time); // 400кГц CPU 160MHz time=92
int i2c_deinit(void);

uint32 i2c_test_sda(void);
void i2c_start(void);
void i2c_stop(void);
uint32 i2c_wrd8ba(uint32 data);

void i2c_set_sda(uint32 x);
void i2c_set_scl(uint32 x);
uint32 i2c_step_scl_sda(uint32 x);

#endif /* _I2C_DRV_H_ */
90 changes: 90 additions & 0 deletions ovls/ina219/include/ina219.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**************************************************************************/
/**************************************************************************/
#ifndef _INA219_H_
#define _INA219_H_

/*=========================================================================
I2C ADDRESS/BITS
-----------------------------------------------------------------------*/
#define INA219_ADDRESS (0x80) // 1000000r (A0+A1=GND)
#define INA219_READ (0x01)
/*=========================================================================*/

/*=========================================================================
CONFIG REGISTER (R/W)
-----------------------------------------------------------------------*/
#define INA219_REG_CONFIG (0x00)
/*---------------------------------------------------------------------*/
#define INA219_CONFIG_RESET (0x8000) // Reset Bit

#define INA219_CONFIG_BVOLTAGERANGE_MASK (0x2000) // Bus Voltage Range Mask
#define INA219_CONFIG_BVOLTAGERANGE_16V (0x0000) // 0-16V Range
#define INA219_CONFIG_BVOLTAGERANGE_32V (0x2000) // 0-32V Range

#define INA219_CONFIG_GAIN_MASK (0x1800) // Gain Mask
#define INA219_CONFIG_GAIN_1_40MV (0x0000) // Gain 1, 40mV Range
#define INA219_CONFIG_GAIN_2_80MV (0x0800) // Gain 2, 80mV Range
#define INA219_CONFIG_GAIN_4_160MV (0x1000) // Gain 4, 160mV Range
#define INA219_CONFIG_GAIN_8_320MV (0x1800) // Gain 8, 320mV Range

#define INA219_CONFIG_BADCRES_MASK (0x0780) // Bus ADC Resolution Mask
#define INA219_CONFIG_BADCRES_9BIT (0x0080) // 9-bit bus res = 0..511
#define INA219_CONFIG_BADCRES_10BIT (0x0100) // 10-bit bus res = 0..1023
#define INA219_CONFIG_BADCRES_11BIT (0x0200) // 11-bit bus res = 0..2047
#define INA219_CONFIG_BADCRES_12BIT (0x0400) // 12-bit bus res = 0..4097

#define INA219_CONFIG_SADCRES_MASK (0x0078) // Shunt ADC Resolution and Averaging Mask
#define INA219_CONFIG_SADCRES_9BIT_1S_84US (0x0000) // 1 x 9-bit shunt sample
#define INA219_CONFIG_SADCRES_10BIT_1S_148US (0x0008) // 1 x 10-bit shunt sample
#define INA219_CONFIG_SADCRES_11BIT_1S_276US (0x0010) // 1 x 11-bit shunt sample
#define INA219_CONFIG_SADCRES_12BIT_1S_532US (0x0018) // 1 x 12-bit shunt sample
#define INA219_CONFIG_SADCRES_12BIT_2S_1060US (0x0048) // 2 x 12-bit shunt samples averaged together
#define INA219_CONFIG_SADCRES_12BIT_4S_2130US (0x0050) // 4 x 12-bit shunt samples averaged together
#define INA219_CONFIG_SADCRES_12BIT_8S_4260US (0x0058) // 8 x 12-bit shunt samples averaged together
#define INA219_CONFIG_SADCRES_12BIT_16S_8510US (0x0060) // 16 x 12-bit shunt samples averaged together
#define INA219_CONFIG_SADCRES_12BIT_32S_17MS (0x0068) // 32 x 12-bit shunt samples averaged together
#define INA219_CONFIG_SADCRES_12BIT_64S_34MS (0x0070) // 64 x 12-bit shunt samples averaged together
#define INA219_CONFIG_SADCRES_12BIT_128S_69MS (0x0078) // 128 x 12-bit shunt samples averaged together

#define INA219_CONFIG_MODE_MASK (0x0007) // Operating Mode Mask
#define INA219_CONFIG_MODE_POWERDOWN (0x0000)
#define INA219_CONFIG_MODE_SVOLT_TRIGGERED (0x0001)
#define INA219_CONFIG_MODE_BVOLT_TRIGGERED (0x0002)
#define INA219_CONFIG_MODE_SANDBVOLT_TRIGGERED (0x0003)
#define INA219_CONFIG_MODE_ADCOFF (0x0004)
#define INA219_CONFIG_MODE_SVOLT_CONTINUOUS (0x0005)
#define INA219_CONFIG_MODE_BVOLT_CONTINUOUS (0x0006)
#define INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS (0x0007)
/*=========================================================================*/

/*=========================================================================
SHUNT VOLTAGE REGISTER (R)
-----------------------------------------------------------------------*/
#define INA219_REG_SHUNTVOLTAGE (0x01)
/*=========================================================================*/

/*=========================================================================
BUS VOLTAGE REGISTER (R)
-----------------------------------------------------------------------*/
#define INA219_REG_BUSVOLTAGE (0x02)
/*=========================================================================*/

/*=========================================================================
POWER REGISTER (R)
-----------------------------------------------------------------------*/
#define INA219_REG_POWER (0x03)
/*=========================================================================*/

/*=========================================================================
CURRENT REGISTER (R)
-----------------------------------------------------------------------*/
#define INA219_REG_CURRENT (0x04)
/*=========================================================================*/

/*=========================================================================
CALIBRATION REGISTER (R/W)
-----------------------------------------------------------------------*/
#define INA219_REG_CALIBRATION (0x05)
/*=========================================================================*/

#endif // _INA219_H_
43 changes: 43 additions & 0 deletions ovls/ina219/main/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of images to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
ifndef PDIR
GEN_LIBS = libmain.a
endif

#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
# Generally values applying to a tree are captured in the
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#DEFINES +=

#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#

#INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./include
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile

Loading

0 comments on commit aa7da1c

Please sign in to comment.