浏览代码

gitflow-feature-stash: ESP32

Klaas, Wilfried 2 年之前
父节点
当前提交
4bcef3a1f1
共有 7 个文件被更改,包括 203 次插入18 次删除
  1. 36 1
      SPS/EEPROM_store.h
  2. 17 4
      SPS/SPS.ino
  3. 58 0
      SPS/debug.h
  4. 37 0
      SPS/hardware.h
  5. 41 0
      SPS/makros.h
  6. 9 1
      SPS/prgmode.ino
  7. 5 12
      SPS/serialprg.ino

+ 36 - 1
SPS/EEPROM_mbv2.h → SPS/EEPROM_store.h

@@ -29,8 +29,43 @@ void writebyte(int addr, byte value) {
 
 void store() {
 }
+#endif
+
+#ifdef ESP32
+#include <EEPROM.h>
+
+const int STORESIZE = 1024;
+byte program[STORESIZE];
+bool loaded = false;
+
+void load() {
+  EEPROM.begin(STORESIZE);
+  EEPROM.readBytes(0, program, STORESIZE);
+  loaded = true;
+}
+
+byte readbyte(int addr) {
+  if (!loaded) {
+    load();
+  }
+  if ((addr >=0) && (addr < STORESIZE)) {
+    return program[addr];
+  }
+  return 0xFF;
+}
+
+void writebyte(int addr, byte value) { 
+  if ((addr >=0) && (addr < STORESIZE)) {
+    program[addr] = value;
+  }
+}
+
+void store() {
+  EEPROM.writeBytes(0, program, STORESIZE);
+}
+#endif
 
-#else
+#if defined(__AVR_ATmega328P__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny861__) || defined(__AVR_ATtiny4313__) 
 
 #include <EEPROM.h>
 #include <avr/eeprom.h>

+ 17 - 4
SPS/SPS.ino

@@ -96,7 +96,7 @@
    #define SPS_SERIAL_PRG: activates the serial programming feature
 */
 // Program im Debugmodus kompilieren, dann werden zus. Ausgaben auf die serielle Schnittstelle geschrieben.
-//#define debug
+#define debug
 
 // defining different hardware platforms
 #ifdef __AVR_ATmega328P__
@@ -108,6 +108,15 @@
 //#define SPS_TONE
 #endif
 
+#ifdef ESP32
+//#define SPS_USE_DISPLAY
+//#define SPS_RECEIVER
+#define SPS_ENHANCEMENT
+#define SPS_SERIAL_PRG
+//#define SPS_SERVO
+//#define SPS_TONE
+#endif
+
 #ifdef __AVR_ATtiny84__
 #define SPS_ENHANCEMENT
 #define SPS_SERIAL_PRG
@@ -128,9 +137,9 @@
 #endif
 
 // libraries
-#include <debug.h>
-#include <makros.h>
-#include "EEPROM_mbv2.h"
+#include "debug.h"
+#include "makros.h"
+#include "EEPROM_store.h"
 
 #ifdef SPS_SERVO
 #include <Servo.h>
@@ -144,6 +153,10 @@
 #include "notes.h"
 #endif
 
+#ifdef ESP32
+#include <analogWrite.h>
+#endif
+
 #include "hardware.h"
 
 // Commands

+ 58 - 0
SPS/debug.h

@@ -0,0 +1,58 @@
+/*
+  debug.h - Definition von 2 Debugfunktionen - Version 0.1
+  Copyright (c) 2012 Wilfried Klaas.  All right reserved.
+
+  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
+*/
+
+// Program im Debugmodus kompilieren, dann werden zus. Ausgaben auf die serielle Schnittstelle geschrieben.
+// Zum aktivieren der Debug Funktion bitte den Define VOR dem #include "debug.h" in die Hauptdatei eintragen.
+//#define debug
+#include <Arduino.h>
+#include <inttypes.h>
+#ifndef debug_lib
+
+#define debug_lib
+#ifdef debug
+#define dbgOut(S) \
+Serial.print(S); 
+#define dbgOut2(S,P) \
+Serial.print(S,P); 
+#define dbgOutLn(S) \
+Serial.println(S); 
+#define dbgOutLn2(S,P) \
+Serial.println(S,P); 
+#define initDebug() \
+  Serial.begin(115200); \
+  Serial.flush(); \
+  delay(100);
+#else
+#define dbgOut(S)
+#define dbgOut2(S,P)
+#define dbgOutLn(S)
+#define dbgOutLn2(S,P)
+#define initDebug()
+#endif
+
+/* 
+void dbgOutHex(uint8_t data) {
+  dbgOut(" 0x");
+  if (data < 0x10) {
+    dbgOut('0');
+  }
+  dbgOut2(data, HEX);
+}
+*/
+#endif

+ 37 - 0
SPS/hardware.h

@@ -165,3 +165,40 @@ const byte DIGIT_DATA_IO = 12;
 const byte DIGIT_CLOCK = 13;
 #endif
 #endif
+
+
+#ifdef ESP32
+// ESP 32 Hardware
+const byte Din_0 = 26;
+const byte Din_1 = 18;
+const byte Din_2 = 19;
+const byte Din_3 = 23;
+
+const byte Dout_0 = 22;
+const byte Dout_1 = 21;
+const byte Dout_2 = 17;
+const byte Dout_3 = 16;
+
+const byte ADC_0 = 36; 
+const byte ADC_1 = 39; 
+const byte PWM_1 = 27;
+const byte PWM_2 = 25;
+
+#ifdef SPS_RCRECEIVER
+const byte RC_0 = 34;
+const byte RC_1 = 35;
+#endif
+
+#ifdef SPS_SERVO
+const byte SERVO_1 = 27;
+const byte SERVO_2 = 25;
+#endif
+
+const byte SW_PRG = 13;
+const byte SW_SEL = 12;
+
+#ifdef SPS_USE_DISPLAY
+const byte DIGIT_DATA_IO = 32;
+const byte DIGIT_CLOCK = 33;
+#endif
+#endif

+ 41 - 0
SPS/makros.h

@@ -0,0 +1,41 @@
+/*
+  makros.cpp - Ein paar nützliche Makros - Version 0.2
+  Copyright (c) 2012 Wilfried Klaas.  All right reserved.
+
+  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 swap
+#define swap(x,y,T) { T TMP_SWAP = x; x = y; y = TMP_SWAP; }
+#endif 
+
+#ifndef between
+#define between(a,x,y) ((a >=x) && (a <= y))
+#endif
+
+#ifndef cbi
+#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
+#endif
+#ifndef sbi
+#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
+#endif
+
+#ifndef ELEMENTS
+#define ELEMENTS(x)    (sizeof(x) / sizeof(x[0]))
+#endif
+
+#ifndef FILLARRAY
+#define FILLARRAY(a,n) a[0]=n, memcpy( ((char*)a)+sizeof(a[0]), a, sizeof(a)-sizeof(a[0]) );
+#endif

+ 9 - 1
SPS/prgmode.ino

@@ -80,7 +80,10 @@ void programMode() {
       }
       while (digitalRead(SW_PRG) == 1);
       delay(DEBOUNCE);
-
+      if (digitalRead(SW_SEL) == 0) {
+        break;
+      }
+      
       blinkD4();
       prgMode = DATA;
       dbgOutLn("dat");
@@ -96,6 +99,9 @@ void programMode() {
       }
       while (digitalRead(SW_PRG) == 1); // S2 = 1
       delay(DEBOUNCE);
+      if (digitalRead(SW_SEL) == 0) {
+        break;
+      }
 
       byte newValue = (cmd << 4) + data;
       if (newValue != Eebyte) {
@@ -108,6 +114,8 @@ void programMode() {
 #ifdef SPS_ENHANCEMENT
   }
 #endif
+  dbgOutLn("save program data");
+  store();
 }
 
 void blinkAll() {

+ 5 - 12
SPS/serialprg.ino

@@ -1,13 +1,5 @@
 #ifdef SPS_SERIAL_PRG
-#ifdef __AVR_ATtiny861__
-#define BAUDRATE 9600
-#endif
-
-#ifdef __AVR_ATtiny84__
-#define BAUDRATE 9600
-#endif
-
-#ifdef __AVR_ATmega328P__
+#if defined(__AVR_ATtiny861__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATmega328P__) || defined(ESP32)
 #define BAUDRATE 9600
 #endif
 
@@ -153,7 +145,7 @@ void serialPrg() {
             Serial.print("ok");
             // adding value to EEPROM
             for (byte x = 0; x < count; x++) {
-              EEPROM.write(readAddress + x, data[x]);
+              writebyte(readAddress + x, data[x]);
             }
           } else {
             Serial.println(", CRC Error");
@@ -163,13 +155,14 @@ void serialPrg() {
           Serial.println();
         } while (!(endOfFile));
         Serial.println("endOfFile");
+        store();
       }
       if (myChar == 'r') {
         // write eeprom as hexfile to receiver
         Serial.println("EEPROM data:");
         int checksum = 0;
-        for (int addr = 0; addr <= E2END; addr++) {
-          value = EEPROM.read(addr);
+        for (int addr = 0; addr <= STORESIZE; addr++) {
+          value = readbyte(addr);
           if ((addr % 8) == 0) {
             printCheckSum(checksum);
             checksum = 0;