rename folder to template project

This commit is contained in:
Siwat Sirichai 2023-01-22 23:10:40 +07:00
parent 1097e8df1d
commit ea647bc465
13 changed files with 0 additions and 2 deletions

View file

@ -0,0 +1,72 @@
#include <ESPMegaPRO.h>
uint8_t inputBufferA;
uint8_t inputBufferB;
PCF8574 inputBankA(INPUT_BANK_A_ADDRESS);
PCF8574 inputBankB(INPUT_BANK_B_ADDRESS);
Adafruit_PWMServoDriver pwmBank = Adafruit_PWMServoDriver(0x5F);
void ESPMega_begin()
{
Wire.begin(14, 33);
inputBankA.begin();
inputBankB.begin();
pwmBank.begin();
#ifdef USE_INTERRUPT
attachInterrupt(digitalPinToInterrupt(INPUT_BANK_A_INTERRUPT),refreshInputBankA,FALLING);
attachInterrupt(digitalPinToInterrupt(INPUT_BANK_B_INTERRUPT),refreshInputBankB,FALLING);
#endif
}
void ESPMega_loop() {
}
bool ESPMega_digitalRead(int id)
{
if (id >= 0 && id <= 7)
{
#ifndef USE_INTERRUPT
refreshInputBankA(); //Only poll if interrupt is not enabled
#endif
return ((inputBufferA>>id)&1); //Extract bit from buffer
}
if (id >= 8 && id <= 15)
{
id-=8;
#ifndef USE_INTERRUPT
refreshInputBankB(); //Only poll if interrupt is not enabled
#endif
return ((inputBufferB>>id)&1); //Extract bit from buffer
}
return false;
}
void ESPMega_analogWrite(int id, int value)
{
pwmBank.setPin(id, value);
}
void ESPMega_digitalWrite(int id, bool value)
{
if(value)
pwmBank.setPin(id, 4095);
else
pwmBank.setPin(id, 0);
}
void IRAM_ATTR refreshInputBankA()
{
inputBufferA = inputBankA.read8();
}
void IRAM_ATTR refreshInputBankB()
{
inputBufferB = inputBankB.read8();
}

View file

@ -0,0 +1,61 @@
#ifndef ESPMEGA
#define ESPMEGA
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <PCF8574.h>
#define INPUT_BANK_A_ADDRESS 0x20
#define INPUT_BANK_B_ADDRESS 0x21
#define OUTPUT_BANK_ADDRESS 0x21
#define EEPROM_ADDRESS 0x22
//#define USE_INTERRUPT
//#define INPUT_BANK_A_INTERRUPT 35
//#define INPUT_BANK_B_INTERRUPT 39
/**
* Initiate ESPMega PRO Internal Components
*
* This function will initiate the PWM bank, Input banks, and the EEPROM.
*/
void ESPMega_begin();
/**
* Run ESPMega PRO Internal Routines
*
* This function must be called regularly for the correct
* operation of the ESPMega!
*/
void ESPMega_loop();
/**
* Read one of the ESPMega's Digital Input pins (I0-I15)
*
* @param id The number of the pin to be read
* @return The state of the pin (HIGH/LOW)
*/
bool ESPMega_digitalRead(int id);
/**
* Write a pulse wave modulated signal to one of the ESPMega's
* PWM pins (P0-P15)
*
* @param id The number of the pin to write to
* @param value the "HIGH" duty cycle of the PWM wave (0-4095)
*/
void ESPMega_analogWrite(int id, int value);
/**
* Write a digital signal to one of the ESPMega's
* PWM pins (P0-P15)
*
* @param id The number of the pin to write to
* @param value the new state for the pin (HIGH/LOW)
*/
void ESPMega_digitalWrite(int id, bool value);
void IRAM_ATTR refreshInputBankA();
void IRAM_ATTR refreshInputBankB();
#endif

View file

@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html