update base code to rev3.3a

This commit is contained in:
Siwat Sirichai 2023-09-09 22:44:08 +07:00
parent 1e4e8f7347
commit a927c74393
7 changed files with 61 additions and 16 deletions

View File

@ -7,6 +7,8 @@
"unordered_set": "cpp", "unordered_set": "cpp",
"vector": "cpp", "vector": "cpp",
"string_view": "cpp", "string_view": "cpp",
"initializer_list": "cpp" "initializer_list": "cpp",
} "adafruit_ads1x15.h": "c"
},
"cmake.configureOnOpen": true
} }

View File

@ -6,6 +6,7 @@ uint8_t inputBufferB;
PCF8574 inputBankA(INPUT_BANK_A_ADDRESS); PCF8574 inputBankA(INPUT_BANK_A_ADDRESS);
PCF8574 inputBankB(INPUT_BANK_B_ADDRESS); PCF8574 inputBankB(INPUT_BANK_B_ADDRESS);
Adafruit_PWMServoDriver pwmBank = Adafruit_PWMServoDriver(PWM_BANK_ADDRESS); Adafruit_PWMServoDriver pwmBank = Adafruit_PWMServoDriver(PWM_BANK_ADDRESS);
I2C_eeprom ESPMega_EEPROM(EEPROM_ADDRESS);
#ifdef ANALOG_CARD_ENABLE #ifdef ANALOG_CARD_ENABLE
Adafruit_ADS1115 analogInputBankA; Adafruit_ADS1115 analogInputBankA;
Adafruit_ADS1115 analogInputBankB; Adafruit_ADS1115 analogInputBankB;
@ -18,11 +19,11 @@ MCP4725 DAC3(DAC3_ADDRESS);
void ESPMega_begin() void ESPMega_begin()
{ {
Wire.begin(14, 33); Wire.begin(14, 33);
inputBankA.begin(); inputBankA.begin();
inputBankB.begin(); inputBankB.begin();
pwmBank.begin(); pwmBank.begin();
ESPMega_RTC.begin();
ESPMega_EEPROM.begin();
// ESPMegaPRO v3 use the PWMBank to drive Half Bridge // ESPMegaPRO v3 use the PWMBank to drive Half Bridge
// Push Pull Output is required. // Push Pull Output is required.
pwmBank.setOutputMode(true); pwmBank.setOutputMode(true);
@ -56,23 +57,28 @@ bool ESPMega_digitalRead(int id)
refreshInputBankA(); // Only poll if interrupt is not enabled refreshInputBankA(); // Only poll if interrupt is not enabled
#endif #endif
return ((inputBufferA >> id) & 1); // Extract bit from buffer return ((inputBufferA >> (7 - id)) & 1); // Extract bit from buffer
} }
if (id >= 8 && id <= 15) if (id >= 8 && id <= 15)
{ {
id -= 8;
#ifndef USE_INTERRUPT #ifndef USE_INTERRUPT
refreshInputBankB(); // Only poll if interrupt is not enabled refreshInputBankB(); // Only poll if interrupt is not enabled
#endif #endif
if (id >= 8 && id <= 11)
return ((inputBufferB >> id) & 1); // Extract bit from buffer return ((inputBufferB >> (15 - id)) & 1); // Extract bit from buffer
else if (id >= 12 && id <= 15)
return ((inputBufferB >> (id - 12)) & 1);
} }
return false; return false;
} }
void ESPMega_analogWrite(int id, int value) void ESPMega_analogWrite(int id, int value)
{ {
if (id >= 0 && id <= 7)
id += 8;
else if (id >= 8 && id <= 15)
id -= 8;
pwmBank.setPin(id, value); pwmBank.setPin(id, value);
} }
@ -98,12 +104,13 @@ void IRAM_ATTR refreshInputBankB()
int16_t ESPMega_analogRead(int id) int16_t ESPMega_analogRead(int id)
{ {
if (id >= 0 && id <= 3) if (id >= 0 && id <= 3)
return analogInputBankA.readADC_SingleEnded(3-id); return analogInputBankA.readADC_SingleEnded(3 - id);
else if (id >= 4 && id <= 7) else if (id >= 4 && id <= 7)
return analogInputBankB.readADC_SingleEnded(7-id); return analogInputBankB.readADC_SingleEnded(7 - id);
return 0; return 0;
} }
void ESPMega_dacWrite(int id, int value) { void ESPMega_dacWrite(int id, int value)
{
switch (id) switch (id)
{ {
case 0: case 0:
@ -114,7 +121,7 @@ void ESPMega_dacWrite(int id, int value) {
break; break;
case 2: case 2:
DAC2.setValue(value); DAC2.setValue(value);
break; break;
case 3: case 3:
DAC3.setValue(value); DAC3.setValue(value);
break; break;
@ -122,4 +129,25 @@ void ESPMega_dacWrite(int id, int value) {
break; break;
} }
} }
/* void ESPMega_rtcNTPUpdate()
{
ntpTimeClient.update();
if (ntpTimeClient.updated())
{
int day = ntpTimeClient.getDay();
int month = ntpTimeClient.getMonth();
int year = ntpTimeClient.getYear();
int hours = ntpTimeClient.getHours();
int minutes = ntpTimeClient.getMinutes();
int seconds = ntpTimeClient.getSeconds();
ESPMega_RTC.setYear(year);
ESPMega_RTC.setMonth(month);
ESPMega_RTC.setDay(day);
ESPMega_RTC.setHour(hours);
ESPMega_RTC.setMinute(minutes);
ESPMega_RTC.setSecond(seconds);
}
} */
#endif #endif

View File

@ -8,23 +8,28 @@
#ifdef ANALOG_CARD_ENABLE #ifdef ANALOG_CARD_ENABLE
#include <Adafruit_ADS1X15.h> #include <Adafruit_ADS1X15.h>
#include <MCP4725.h> #include <MCP4725.h>
#include <I2C_eeprom.h>
#include <SparkFunDS1307RTC.h>
#endif #endif
#define INPUT_BANK_A_ADDRESS 0x21 #define INPUT_BANK_A_ADDRESS 0x21
#define INPUT_BANK_B_ADDRESS 0x22 #define INPUT_BANK_B_ADDRESS 0x22
#define PWM_BANK_ADDRESS 0x5F #define PWM_BANK_ADDRESS 0x5F
#define OUTPUT_BANK_ADDRESS 0x21 #define RTC_ADDRESS 0x68
#define EEPROM_ADDRESS 0x22
#define ANALOG_INPUT_BANK_A_ADDRESS 0x48 #define ANALOG_INPUT_BANK_A_ADDRESS 0x48
#define ANALOG_INPUT_BANK_B_ADDRESS 0x49 #define ANALOG_INPUT_BANK_B_ADDRESS 0x49
#define DAC0_ADDRESS 0x60 #define DAC0_ADDRESS 0x60
#define DAC1_ADDRESS 0x61 #define DAC1_ADDRESS 0x61
#define DAC2_ADDRESS 0x62 #define DAC2_ADDRESS 0x62
#define DAC3_ADDRESS 0x63 #define DAC3_ADDRESS 0x63
#define EEPROM_ADDRESS 0x70
#define ESPMega_RTC rtc
//#define USE_INTERRUPT //#define USE_INTERRUPT
#define INPUT_BANK_A_INTERRUPT 36 #define INPUT_BANK_A_INTERRUPT 36
#define INPUT_BANK_B_INTERRUPT 39 #define INPUT_BANK_B_INTERRUPT 39
extern I2C_eeprom ESPMega_EEPROM;
/** /**
* Initiate ESPMega PRO Internal Components * Initiate ESPMega PRO Internal Components

View File

@ -18,6 +18,8 @@ lib_deps = adafruit/Adafruit PWM Servo Driver Library@^2.4.1
adafruit/Adafruit BusIO adafruit/Adafruit BusIO
robtillaart/PCF8574@^0.3.7 robtillaart/PCF8574@^0.3.7
arduino-libraries/Arduino_BuiltIn@^1.0.0 arduino-libraries/Arduino_BuiltIn@^1.0.0
SPI SPI@^2.0.0
robtillaart/MCP4725@^0.3.7 robtillaart/MCP4725@^0.3.7
robtillaart/I2C_EEPROM@^1.7.3
sparkfun/SparkFun DS1307 Real-Time Clock (RTC)@^1.0.1
monitor_speed = 115200 monitor_speed = 115200

View File

@ -1,4 +1,4 @@
#include <Arduino.h> #include <ESPMegaPRO.h>
// -------------------------------------- // --------------------------------------
// i2c_scanner // i2c_scanner
// //

View File

@ -0,0 +1,8 @@
#include <ESPMegaPRO.h>
void setup() {
ESPMega_begin();
}
void loop() {
delay(5000);
}