1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-17 22:23:10 +03:00

Move esp8266 platform from "arduino" into "esp8266com"

This commit is contained in:
Ivan Grokhotkov
2015-03-27 12:11:55 +03:00
parent c72529bf6d
commit 2b2a4131a3
143 changed files with 17 additions and 9 deletions

View File

@ -0,0 +1,78 @@
/*
pins_arduino.h - Pin definition functions for Arduino
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2007 David A. Mellis
Modified for ESP8266 platform by Ivan Grokhotkov, 2014-2015.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#define NUM_DIGITAL_PINS 16
#define NUM_ANALOG_INPUTS 1
#define ESP_PINS_OFFSET 0
static const uint8_t SDA = 0;
static const uint8_t SCL = 2;
static const uint8_t SS = 12;
static const uint8_t MOSI = 13;
static const uint8_t MISO = 14;
static const uint8_t SCK = 15;
static const uint8_t BUILTIN_LED = 1;
static const uint8_t A0 = 0;
static const uint8_t E0 = ESP_PINS_OFFSET + 0;
static const uint8_t E1 = ESP_PINS_OFFSET + 1;
static const uint8_t E2 = ESP_PINS_OFFSET + 2;
static const uint8_t E3 = ESP_PINS_OFFSET + 3;
static const uint8_t E4 = ESP_PINS_OFFSET + 4;
static const uint8_t E5 = ESP_PINS_OFFSET + 5;
static const uint8_t E11 = ESP_PINS_OFFSET + 11;
static const uint8_t E12 = ESP_PINS_OFFSET + 12;
static const uint8_t E13 = ESP_PINS_OFFSET + 13;
static const uint8_t E14 = ESP_PINS_OFFSET + 14;
static const uint8_t E15 = ESP_PINS_OFFSET + 15;
static const uint8_t E16 = ESP_PINS_OFFSET + 16;
// These serial port names are intended to allow libraries and architecture-neutral
// sketches to automatically default to the correct port name for a particular type
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
//
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
//
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
//
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
//
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
//
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
// pins are NOT connected to anything by default.
#define SERIAL_PORT_MONITOR Serial
#define SERIAL_PORT_USBVIRTUAL Serial
#define SERIAL_PORT_HARDWARE Serial
#define SERIAL_PORT_HARDWARE_OPEN Serial
#endif /* Pins_Arduino_h */

View File

@ -0,0 +1,153 @@
/*
WifioProtocol.h - virtual IO protocol for the WIFIO board
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
This file is part of the esp8266 core for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef WIFIO_PROTOCOL_H
#define WIFIO_PROTOCOL_H
#include <stdint.h>
#include "Arduino.h"
#include "i2c.h"
inline void protocolError()
{
delay(5);
i2c_stop();
}
namespace wifio {
const uint8_t MAGIC = 0x05;
enum Command {
CMD_NONE,
CMD_SYNC,
CMD_PINMODE,
CMD_DIGITALWRITE,
CMD_DIGITALREAD,
CMD_DIGITALREADRESULT,
CMD_ANALOGWRITE,
CMD_ANALOGREAD,
CMD_ANALOGREADRESULT,
CMD_INVALID,
};
struct CommandHeader {
uint8_t magic : 4;
uint8_t cmd : 4;
};
struct SyncCommand {
CommandHeader header;
uint8_t val : 7;
uint8_t parity : 1;
};
struct PinModeCommand {
CommandHeader header;
uint8_t pin : 5;
uint8_t mode : 2;
uint8_t parity : 1;
};
struct DigitalWriteCommand {
CommandHeader header;
uint8_t pin : 5;
uint8_t value : 1;
uint8_t unused : 1;
uint8_t parity : 1;
};
struct DigitalReadCommand {
CommandHeader header;
uint8_t pin : 5;
uint8_t unused : 2;
uint8_t parity : 1;
};
struct DigitalReadResultCommand {
CommandHeader header;
uint8_t pin : 5;
uint8_t value : 1;
uint8_t unused : 1;
uint8_t parity : 1;
};
struct AnalogWriteCommand {
CommandHeader header;
uint8_t value;
uint8_t pin : 5;
uint8_t unused : 2;
uint8_t parity : 1;
};
struct AnalogReadCommand {
CommandHeader header;
uint8_t pin : 5;
uint8_t unused : 2;
uint8_t parity : 1;
};
struct AnalogReadResultCommand {
CommandHeader header;
uint8_t pin : 5;
uint8_t val_h : 3;
uint8_t val_l : 7;
uint8_t parity : 1;
};
template<typename T>
void sendCommand(uint8_t addr, T& t)
{
// TODO: calculate parity
t.parity = 1;
if (i2c_master_write_to(addr, reinterpret_cast<const uint8_t*>(&t), sizeof(T), true) != sizeof(T))
{
protocolError();
}
}
template<typename TC, typename TR>
bool sendCommandWaitForReply(uint8_t addr, TC& c, Command rt, TR& r, int32_t d_us)
{
c.parity = 1;
if (i2c_master_write_to(addr, reinterpret_cast<const uint8_t*>(&c), sizeof(TC), true) != sizeof(TC))
{
protocolError();
return false;
}
if (d_us)
{
delayMicroseconds(d_us);
}
if (i2c_master_read_from(addr, reinterpret_cast<uint8_t*>(&r), sizeof(TR), true) != sizeof(TR) || r.header.cmd != rt)
{
protocolError();
return false;
}
return true;
}
}// namespace wifio
#endif//WIFIO_PROTOCOL_H

View File

@ -0,0 +1,120 @@
/*
WifioWiring.cpp - Wiring API implementation for the WIFIO board
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
This file is part of the esp8266 core for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "wiring_private.h"
#include "WifioProtocol.h"
namespace wifio {
const int WIFIO_AVR_SLAVE_ADDR=0x23;
void pinMode(int avrPin, int mode) {
PinModeCommand cmd { MAGIC, CMD_PINMODE, static_cast<uint8_t>(avrPin), static_cast<uint8_t>(mode) };
sendCommand(WIFIO_AVR_SLAVE_ADDR, cmd);
}
void digitalWrite(int avrPin, int value) {
DigitalWriteCommand cmd { MAGIC, CMD_DIGITALWRITE, static_cast<uint8_t>(avrPin), static_cast<uint8_t>(value) };
sendCommand(WIFIO_AVR_SLAVE_ADDR, cmd);
}
int digitalRead(int avrPin) {
DigitalReadCommand cmd { MAGIC, CMD_DIGITALREAD, static_cast<uint8_t>(avrPin) };
DigitalReadResultCommand reply = { 0 };
sendCommandWaitForReply(WIFIO_AVR_SLAVE_ADDR, cmd, CMD_DIGITALREADRESULT, reply, 0);
return reply.value;
}
void analogWrite(int avrPin, int value) {
AnalogWriteCommand cmd { MAGIC, CMD_ANALOGWRITE, static_cast<uint8_t>(value), static_cast<uint8_t>(avrPin) };
sendCommand(WIFIO_AVR_SLAVE_ADDR, cmd);
}
int analogRead(int avrPin) {
AnalogReadCommand cmd { MAGIC, CMD_ANALOGREAD, static_cast<uint8_t>(avrPin) };
AnalogReadResultCommand reply = { 0 };
sendCommandWaitForReply(WIFIO_AVR_SLAVE_ADDR, cmd, CMD_ANALOGREADRESULT, reply, 120);
return ((reply.val_h << 7) | reply.val_l);
}
} // namespace wifio
extern "C" void __pinMode(uint8_t pin, uint8_t mode);
extern "C" void __digitalWrite(uint8_t pin, uint8_t val);
extern "C" int __digitalRead(uint8_t pin);
extern "C" void __analogWrite(uint8_t pin, int val);
// extern "C" void __attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode);
// extern "C" void __detachInterrupt(uint8_t pin);
extern "C" void __initPins();
extern "C" int __analogRead(uint8_t pin);
extern "C" void pinMode(uint8_t pin, uint8_t mode){
if (pin >= ESP_PINS_OFFSET) { // esp pin
__pinMode(pin - ESP_PINS_OFFSET, mode);
}
else { // AVR pin
wifio::pinMode(pin, mode);
}
}
extern "C" void digitalWrite(uint8_t pin, uint8_t value) {
if (pin >= ESP_PINS_OFFSET) { // esp pin
__digitalWrite(pin - ESP_PINS_OFFSET, value);
}
else { // AVR pin
wifio::digitalWrite(pin, value);
}
}
extern "C" int digitalRead(uint8_t pin) {
if (pin >= ESP_PINS_OFFSET) {
return __digitalRead(pin - ESP_PINS_OFFSET);
}
else {
return wifio::digitalRead(pin);
}
}
extern "C" int analogRead(uint8_t pin) {
if (pin >= ESP_PINS_OFFSET) {
return __analogRead(pin - ESP_PINS_OFFSET);
}
else {
return wifio::analogRead(pin);
}
}
extern "C" void analogWrite(uint8_t pin, int value) {
if (pin >= ESP_PINS_OFFSET) {
__analogWrite(pin - ESP_PINS_OFFSET, value);
}
else {
wifio::analogWrite(pin, value);
}
}
void initVariant()
{
i2c_freq(100000);
i2c_init(SDA, SCL);
}

View File

@ -0,0 +1,70 @@
/*
pins_arduino.h - Pin definition functions for Arduino
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2007 David A. Mellis
Modified for ESP8266 WIFIO board by Ivan Grokhotkov, 2015.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#define NUM_DIGITAL_PINS 36
#define NUM_ANALOG_INPUTS 1
#define ESP_PINS_OFFSET 20
static const uint8_t SDA = 4;
static const uint8_t SCL = 5;
static const uint8_t SS = 12;
static const uint8_t MOSI = 13;
static const uint8_t MISO = 14;
static const uint8_t SCK = 15;
static const uint8_t A0 = 14;
static const uint8_t A1 = 15;
static const uint8_t A2 = 16;
static const uint8_t A3 = 17;
static const uint8_t A4 = 18;
static const uint8_t A5 = 19;
static const uint8_t A6 = 20;
static const uint8_t A7 = 21;
static const uint8_t E0 = ESP_PINS_OFFSET + 0;
static const uint8_t E1 = ESP_PINS_OFFSET + 1;
static const uint8_t E2 = ESP_PINS_OFFSET + 2;
static const uint8_t E3 = ESP_PINS_OFFSET + 3;
static const uint8_t E4 = ESP_PINS_OFFSET + 4;
static const uint8_t E5 = ESP_PINS_OFFSET + 5;
static const uint8_t E11 = ESP_PINS_OFFSET + 11;
static const uint8_t E12 = ESP_PINS_OFFSET + 12;
static const uint8_t E13 = ESP_PINS_OFFSET + 13;
static const uint8_t E14 = ESP_PINS_OFFSET + 14;
static const uint8_t E15 = ESP_PINS_OFFSET + 15;
static const uint8_t E16 = ESP_PINS_OFFSET + 16;
static const uint8_t BUILTIN_LED = 2;
#define SERIAL_PORT_MONITOR Serial
#define SERIAL_PORT_USBVIRTUAL Serial
#define SERIAL_PORT_HARDWARE Serial
#define SERIAL_PORT_HARDWARE_OPEN Serial
#endif /* Pins_Arduino_h */