Skip to content

Commit 4880a04

Browse files
committed
Merge pull request nekromant#28 from darkbyte-ru/master
I2C support
2 parents 4cb5f4a + 3c43b15 commit 4880a04

28 files changed

+2280
-99
lines changed

.config

+15-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ CONFIG_ARCH_ESP8266=y
1414
# CONFIG_ARCH_MIPS is not set
1515
# CONFIG_ARCH_MSP430 is not set
1616
# CONFIG_ARCH_NATIVE is not set
17-
# CONFIG_ARCH_NMC is not set
1817
# CONFIG_ARCH_PIC32 is not set
1918
CONFIG_ESP8266_FORCE_IROM=y
2019
CONFIG_ESP8266_LIBC_IROM=y
@@ -102,6 +101,11 @@ CONFIG_LIB_PANIC_NONE=y
102101
# CONFIG_LIB_STLINKY is not set
103102
# CONFIG_LIB_URPC is not set
104103

104+
#
105+
# Data compression
106+
#
107+
# CONFIG_LIB_HEATSHRINK is not set
108+
105109
#
106110
# 3rd-party libraries
107111
#
@@ -115,6 +119,7 @@ CONFIG_LIB_PANIC_NONE=y
115119
# Modules to build
116120
#
117121
CONFIG_CMD_IW=y
122+
CONFIG_CMD_UART=y
118123
CONFIG_CMD_IF=y
119124
CONFIG_CMD_GPIO=y
120125
CONFIG_CMD_FLASH=y
@@ -124,6 +129,14 @@ CONFIG_CMD_TFTP=y
124129
CONFIG_CMD_AT=y
125130
CONFIG_CMD_ADC=y
126131
CONFIG_CMD_DS18B20=y
132+
CONFIG_CMD_I2C=y
133+
CONFIG_CMD_I2C_BMP180=y
134+
CONFIG_CMD_I2C_SHT21=y
135+
CONFIG_CMD_I2C_BH1750=y
136+
CONFIG_CMD_I2C_PCF8591=y
137+
CONFIG_CMD_I2C_TCS3414CS=y
138+
139+
127140
# CONFIG_CMD_DS18B20_DEBUG is not set
128141

129142
#
@@ -187,4 +200,4 @@ CONFIG_VERSION_MAJOR="0"
187200
CONFIG_VERSION_MINOR="2-rc1"
188201
CONFIG_VERSION_CODENAME="Insane Mushroom"
189202
CONFIG_VERSION_STRING="0.2-rc1, Insane Mushroom"
190-
CONFIG_VERSION_GIT="dd2e249ebcbc23f41df6116c8550abc737f687e7"
203+
CONFIG_VERSION_GIT="0400df933188103863940b1ba9d8f21c10163305"

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ build
55
*.o
66
*.d
77
tmp
8-
8+
*.bak
9+
*.old
10+
include/config

include/arch

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../antares/src/arch/esp8266/include

include/driver/i2c_bh1750.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef __I2C_BH1750_H
2+
#define __I2C_BH1750_H
3+
4+
#include "c_types.h"
5+
#include "ets_sys.h"
6+
#include "osapi.h"
7+
8+
#define BH1750_ADDRESS 0x46 //Add Low
9+
//#define BH1750_ADDRESS 0xB8 //Add High
10+
11+
#define BH1750_CONVERSION_TIME 150
12+
#define BH1750_CONTINUOUS_HIGH_RES_MODE 0x10 // 1 lx resolution, 120ms
13+
#define BH1750_CONTINUOUS_HIGH_RES_MODE_2 0x11 // 0.5 lx resolution, 120ms
14+
#define BH1750_CONTINUOUS_LOW_RES_MODE 0x13 // 4 lx resolution, 16ms.
15+
#define BH1750_ONE_TIME_HIGH_RES_MODE 0x20
16+
#define BH1750_ONE_TIME_HIGH_RES_MODE_2 0x21
17+
#define BH1750_ONE_TIME_LOW_RES_MODE 0x23
18+
#define BH1750_POWER_DOWN 0x00 // No active state
19+
#define BH1750_POWER_ON 0x01 // Wating for measurment command
20+
#define BH1750_RESET 0x07 // Reset data register value - not accepted in POWER_DOWN mode
21+
22+
uint16_t LAST_BH_LIGHT;
23+
24+
bool BH1750_Init(uint8 mode);
25+
bool BH1750_Read(void);
26+
27+
#endif

include/driver/i2c_bmp180.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef __I2C_BMP180_H
2+
#define __I2C_BMP180_H
3+
4+
#include "c_types.h"
5+
#include "ets_sys.h"
6+
#include "osapi.h"
7+
8+
#define BMP180_ADDRESS 0xEE
9+
10+
#define BMP180_MAGIC_VERSION 0x55
11+
#define BMP180_CONVERSION_TIME 5
12+
#define BMP180_REG_VERSION 0xD0
13+
#define BMP180_REG_CONTROL 0xF4
14+
#define BMP180_REG_RESULT 0xF6
15+
#define BMP180_COMMAND_TEMPERATURE 0x2E // Max conversion time 4.5ms
16+
#define BMP180_COMMAND_PRESSURE0 0x34 // Max conversion time 4.5ms (OSS = 0)
17+
#define BMP180_COMMAND_PRESSURE1 0x74 // Max conversion time 7.5ms (OSS = 1)
18+
#define BMP180_COMMAND_PRESSURE2 0xB4 // Max conversion time 13.5ms (OSS = 2)
19+
#define BMP180_COMMAND_PRESSURE3 0xF4 // Max conversion time 25.5ms (OSS = 3)
20+
21+
22+
int32_t LAST_BMP_TEMPERATURE;
23+
int32_t LAST_BMP_REAL_PRESSURE;
24+
25+
bool BMP180_Init(void);
26+
bool BMP180_Read(void);
27+
28+
#endif

include/driver/i2c_hd44780.h

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#ifndef i2c_hd44780_h
2+
#define i2c_hd44780_h
3+
4+
#include "ets_sys.h"
5+
#include "osapi.h"
6+
#include "driver/i2c_master.h"
7+
#include "driver/lcd_config.h"
8+
9+
// commands
10+
#define LCD_CLEARDISPLAY 0x01
11+
#define LCD_RETURNHOME 0x02
12+
#define LCD_ENTRYMODESET 0x04
13+
#define LCD_DISPLAYCONTROL 0x08
14+
#define LCD_CURSORSHIFT 0x10
15+
#define LCD_FUNCTIONSET 0x20
16+
#define LCD_SETCGRAMADDR 0x40
17+
#define LCD_SETDDRAMADDR 0x80
18+
19+
// flags for display entry mode
20+
#define LCD_ENTRYRIGHT 0x00
21+
#define LCD_ENTRYLEFT 0x02
22+
#define LCD_ENTRYSHIFTINCREMENT 0x01
23+
#define LCD_ENTRYSHIFTDECREMENT 0x00
24+
25+
// flags for display on/off control
26+
#define LCD_DISPLAYON 0x04
27+
#define LCD_DISPLAYOFF 0x00
28+
#define LCD_CURSORON 0x02
29+
#define LCD_CURSOROFF 0x00
30+
#define LCD_BLINKON 0x01
31+
#define LCD_BLINKOFF 0x00
32+
33+
// flags for display/cursor shift
34+
#define LCD_DISPLAYMOVE 0x08
35+
#define LCD_CURSORMOVE 0x00
36+
#define LCD_MOVERIGHT 0x04
37+
#define LCD_MOVELEFT 0x00
38+
39+
// flags for function set
40+
#define LCD_8BITMODE 0x10
41+
#define LCD_4BITMODE 0x00
42+
#define LCD_2LINE 0x08
43+
#define LCD_1LINE 0x00
44+
#define LCD_5x10DOTS 0x04
45+
#define LCD_5x8DOTS 0x00
46+
47+
// flags for backlight control
48+
#define LCD_BACKLIGHT 0x08
49+
#define LCD_NOBACKLIGHT 0x00
50+
51+
#define En 0x04 // Enable bit
52+
#define Rw 0x02 // Read/Write bit
53+
#define Rs 0x01 // Register select bit
54+
55+
void LCD_clear();
56+
void LCD_home();
57+
void LCD_noDisplay();
58+
void LCD_display();
59+
void LCD_noBlink();
60+
void LCD_blink();
61+
void LCD_noCursor();
62+
void LCD_cursor();
63+
void LCD_scrollDisplayLeft();
64+
void LCD_scrollDisplayRight();
65+
void LCD_printLeft();
66+
void LCD_printRight();
67+
void LCD_leftToRight();
68+
void LCD_rightToLeft();
69+
void LCD_shiftIncrement();
70+
void LCD_shiftDecrement();
71+
void LCD_noBacklight();
72+
void LCD_backlight();
73+
void LCD_autoscroll();
74+
void LCD_noAutoscroll();
75+
void LCD_createChar(uint8, uint8[]);
76+
void LCD_setCursor(uint8, uint8);
77+
uint8 LCD_init();
78+
#endif

include/driver/i2c_hmc5883l.h

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#ifndef __I2C_HMC5883_H
2+
#define __I2C_HMC5883_H
3+
4+
#include "c_types.h"
5+
#include "ets_sys.h"
6+
#include "osapi.h"
7+
8+
#define HMC5883L_ADDRESS 0x3C
9+
//also maybe 1E 3D
10+
11+
#define HMC5883L_REG_CONFIG_A (0x00)
12+
#define HMC5883L_REG_CONFIG_B (0x01)
13+
#define HMC5883L_REG_MODE (0x02)
14+
#define HMC5883L_REG_OUT_X_M (0x03)
15+
#define HMC5883L_REG_OUT_X_L (0x04)
16+
#define HMC5883L_REG_OUT_Z_M (0x05)
17+
#define HMC5883L_REG_OUT_Z_L (0x06)
18+
#define HMC5883L_REG_OUT_Y_M (0x07)
19+
#define HMC5883L_REG_OUT_Y_L (0x08)
20+
#define HMC5883L_REG_STATUS (0x09)
21+
#define HMC5883L_REG_IDENT_A (0x0A)
22+
#define HMC5883L_REG_IDENT_B (0x0B)
23+
#define HMC5883L_REG_IDENT_C (0x0C)
24+
25+
#define PI M_PI
26+
#define M_PI 3.14159265358979323846
27+
28+
typedef enum
29+
{
30+
HMC5883L_SAMPLES_8 = 0b11,
31+
HMC5883L_SAMPLES_4 = 0b10,
32+
HMC5883L_SAMPLES_2 = 0b01,
33+
HMC5883L_SAMPLES_1 = 0b00
34+
} hmc5883l_samples_t;
35+
36+
typedef enum
37+
{
38+
HMC5883L_DATARATE_75HZ = 0b110,
39+
HMC5883L_DATARATE_30HZ = 0b101,
40+
HMC5883L_DATARATE_15HZ = 0b100,
41+
HMC5883L_DATARATE_7_5HZ = 0b011,
42+
HMC5883L_DATARATE_3HZ = 0b010,
43+
HMC5883L_DATARATE_1_5HZ = 0b001,
44+
HMC5883L_DATARATE_0_75_HZ = 0b000
45+
} hmc5883l_dataRate_t;
46+
47+
typedef enum
48+
{
49+
HMC5883L_RANGE_8_1GA = 0b111,
50+
HMC5883L_RANGE_5_6GA = 0b110,
51+
HMC5883L_RANGE_4_7GA = 0b101,
52+
HMC5883L_RANGE_4GA = 0b100,
53+
HMC5883L_RANGE_2_5GA = 0b011,
54+
HMC5883L_RANGE_1_9GA = 0b010,
55+
HMC5883L_RANGE_1_3GA = 0b001,
56+
HMC5883L_RANGE_0_88GA = 0b000
57+
} hmc5883l_range_t;
58+
59+
typedef enum
60+
{
61+
HMC5883L_IDLE = 0b10,
62+
HMC5883L_SINGLE = 0b01,
63+
HMC5883L_CONTINOUS = 0b00
64+
} hmc5883l_mode_t;
65+
66+
typedef struct
67+
{
68+
float X;
69+
float Y;
70+
float Z;
71+
} Vector;
72+
73+
Vector LAST_HMC5883_VECTOR;
74+
75+
bool HMC5883_Init(void);
76+
bool HMC5883_Read(void);
77+
uint16_t HMC5883_ReadDegrees();
78+
79+
#endif

include/driver/i2c_ina219.h

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#ifndef __I2C_INA219_H
2+
#define __I2C_INA219_H
3+
4+
#include "c_types.h"
5+
#include "ets_sys.h"
6+
#include "osapi.h"
7+
8+
//#define INA219_ADDRESS 0x80
9+
#define INA219_ADDRESS 0x82
10+
11+
#define INA219_REG_CONFIG 0x00
12+
#define INA219_REG_SHUNTVOLTAGE 0x01
13+
#define INA219_REG_BUSVOLTAGE 0x02
14+
#define INA219_REG_POWER 0x03
15+
#define INA219_REG_CURRENT 0x04
16+
#define INA219_REG_CALIBRATION 0x05
17+
18+
typedef enum
19+
{
20+
INA219_RANGE_16V = 0b0,
21+
INA219_RANGE_32V = 0b1
22+
} ina219_range_t;
23+
24+
typedef enum
25+
{
26+
INA219_GAIN_40MV = 0b00,
27+
INA219_GAIN_80MV = 0b01,
28+
INA219_GAIN_160MV = 0b10,
29+
INA219_GAIN_320MV = 0b11
30+
} ina219_gain_t;
31+
32+
typedef enum
33+
{
34+
INA219_BUS_RES_9BIT = 0b0000,
35+
INA219_BUS_RES_10BIT = 0b0001,
36+
INA219_BUS_RES_11BIT = 0b0010,
37+
INA219_BUS_RES_12BIT = 0b0011
38+
} ina219_busRes_t;
39+
40+
typedef enum
41+
{
42+
INA219_SHUNT_RES_9BIT_1S = 0b0000,
43+
INA219_SHUNT_RES_10BIT_1S = 0b0001,
44+
INA219_SHUNT_RES_11BIT_1S = 0b0010,
45+
INA219_SHUNT_RES_12BIT_1S = 0b0011,
46+
INA219_SHUNT_RES_12BIT_2S = 0b1001,
47+
INA219_SHUNT_RES_12BIT_4S = 0b1010,
48+
INA219_SHUNT_RES_12BIT_8S = 0b1011,
49+
INA219_SHUNT_RES_12BIT_16S = 0b1100,
50+
INA219_SHUNT_RES_12BIT_32S = 0b1101,
51+
INA219_SHUNT_RES_12BIT_64S = 0b1110,
52+
INA219_SHUNT_RES_12BIT_128S = 0b1111
53+
} ina219_shuntRes_t;
54+
55+
typedef enum
56+
{
57+
INA219_MODE_POWER_DOWN = 0b000,
58+
INA219_MODE_SHUNT_TRIG = 0b001,
59+
INA219_MODE_BUS_TRIG = 0b010,
60+
INA219_MODE_SHUNT_BUS_TRIG = 0b011,
61+
INA219_MODE_ADC_OFF = 0b100,
62+
INA219_MODE_SHUNT_CONT = 0b101,
63+
INA219_MODE_BUS_CONT = 0b110,
64+
INA219_MODE_SHUNT_BUS_CONT = 0b111,
65+
} ina219_mode_t;
66+
67+
enum {
68+
CONFIGURE_READ_POWERDOWN = 0,
69+
GET_VOLTAGE,
70+
GET_CURRENT,
71+
GET_SHUNT_VOLTAGE,
72+
GET_POWER
73+
};
74+
75+
#define INA219_CALIBRATION_VALUE 4096 //RSHUNT = 0.1 ohm; max expected I = 1 A
76+
#define INA219_CONFIG_VALUE (INA219_RANGE_16V << 13 | INA219_GAIN_80MV << 11 | INA219_BUS_RES_12BIT << 7 | INA219_SHUNT_RES_12BIT_1S << 3)
77+
78+
bool INA219_Init(void);
79+
int32_t INA219_GetVal(uint8 mode);
80+
81+
#endif

0 commit comments

Comments
 (0)