diff --git a/platformio.ini b/platformio.ini
index 039c50da..07c307bf 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -15,14 +15,12 @@ framework=arduino
build_unflags = -Os
build_flags = -O3 -ffast-math
lib_deps = EEPROM
-src_filter = +<*> -<.git/> - - - - - -
[env:teensy35]
platform=teensy
board=teensy35
framework=arduino
lib_deps = EEPROM, FlexCAN
-src_filter = +<*> -<.git/> - - - - - -
;Not currently working
;[env:LaunchPad_tm4c1294ncpdt]
@@ -38,7 +36,6 @@ framework = arduino
board = genericSTM32F103RB
lib_deps = EEPROM
build_flags = -fpermissive -std=gnu++11
-src_filter = +<*> -<.git/> - - - - - -
[env:bluepill_f103c8]
platform = ststm32
@@ -48,7 +45,6 @@ board = bluepill_f103c8
lib_deps = EEPROM
;build_flags = -fpermissive -std=gnu++11 -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,-Map,output.map
build_flags = -fpermissive -std=gnu++11 -Os
-src_filter = +<*> -<.git/> - - - - - -
;SAMD21
[env:samd21]
diff --git a/speeduino/src/boards/avr2560.h b/speeduino/board_avr2560.h
similarity index 93%
rename from speeduino/src/boards/avr2560.h
rename to speeduino/board_avr2560.h
index 4c19031f..5d922e8c 100644
--- a/speeduino/src/boards/avr2560.h
+++ b/speeduino/board_avr2560.h
@@ -2,13 +2,12 @@
#define AVR2560_H
#if defined(CORE_AVR)
-//#include "sam.h"
-
/*
***********************************************************************************************************
* General
*/
#define PORT_TYPE uint8_t //Size of the port variables (Eg inj1_pin_port).
+ void initBoard();
#endif //CORE_AVR
#endif //AVR2560_H
diff --git a/speeduino/board_avr2560.ino b/speeduino/board_avr2560.ino
new file mode 100644
index 00000000..65eccb41
--- /dev/null
+++ b/speeduino/board_avr2560.ino
@@ -0,0 +1,11 @@
+
+#include "globals.h"
+
+#if defined(CORE_AVR)
+
+void initBoard()
+{
+
+}
+
+#endif
\ No newline at end of file
diff --git a/speeduino/board_samd21.h b/speeduino/board_samd21.h
new file mode 100644
index 00000000..79eb558e
--- /dev/null
+++ b/speeduino/board_samd21.h
@@ -0,0 +1,159 @@
+ #ifndef SAMD21_H
+#define SAMD21_H
+#if defined(CORE_SAMD21)
+
+#include "sam.h"
+
+/*
+***********************************************************************************************************
+* General
+*/
+ #define PORT_TYPE uint32_t //Size of the port variables (Eg inj1_pin_port). Most systems use a byte, but SAMD21 is a 32-bit unsigned int
+ #define BOARD_NR_GPIO_PINS 52 //Not sure this is correct
+ #define BOARD_DIGITAL_GPIO_PINS 52 //Pretty sure this isn't right
+ void initBoard();
+
+ //Additional analog pins (These won't work without other changes)
+ #define PIN_A6 (8ul)
+ #define PIN_A7 (9ul)
+ #define PIN_A8 (10ul)
+ #define PIN_A9 (11ul)
+ #define PIN_A13 (9ul)
+ #define PIN_A14 (9ul)
+ #define PIN_A15 (9ul)
+
+ static const uint8_t A6 = PIN_A6;
+ static const uint8_t A7 = PIN_A7;
+ static const uint8_t A8 = PIN_A8;
+ static const uint8_t A9 = PIN_A9;
+ static const uint8_t A13 = PIN_A13;
+ static const uint8_t A14 = PIN_A14;
+ static const uint8_t A15 = PIN_A15;
+
+/*
+***********************************************************************************************************
+* Schedules
+*/
+ //See : https://electronics.stackexchange.com/questions/325159/the-value-of-the-tcc-counter-on-an-atsam-controller-always-reads-as-zero
+ #define FUEL1_COUNTER TCC0->COUNT.reg
+ #define FUEL2_COUNTER TCC0->COUNT.reg
+ #define FUEL3_COUNTER TCC0->COUNT.reg
+ #define FUEL4_COUNTER TCC0->COUNT.reg
+ //The below are NOT YET RIGHT!
+ #define FUEL5_COUNTER TCC0->COUNT.reg
+ #define FUEL6_COUNTER TCC0->COUNT.reg
+ #define FUEL7_COUNTER TCC0->COUNT.reg
+ #define FUEL8_COUNTER TCC0->COUNT.reg
+
+ #define IGN1_COUNTER TCC1->COUNT.reg
+ #define IGN2_COUNTER TCC1->COUNT.reg
+ #define IGN3_COUNTER TCC2->COUNT.reg
+ #define IGN4_COUNTER TCC2->COUNT.reg
+ //The below are NOT YET RIGHT!
+ #define IGN5_COUNTER TCC1->COUNT.reg
+ #define IGN6_COUNTER TCC1->COUNT.reg
+ #define IGN7_COUNTER TCC2->COUNT.reg
+ #define IGN8_COUNTER TCC2->COUNT.reg
+
+ #define FUEL1_COMPARE TCC0->CC[0].bit.CC
+ #define FUEL2_COMPARE TCC0->CC[1].bit.CC
+ #define FUEL3_COMPARE TCC0->CC[2].bit.CC
+ #define FUEL4_COMPARE TCC0->CC[3].bit.CC
+ //The below are NOT YET RIGHT!
+ #define FUEL5_COMPARE TCC0->CC0
+ #define FUEL6_COMPARE TCC0->CC1
+ #define FUEL7_COMPARE TCC0->CC2
+ #define FUEL8_COMPARE TCC0->CC3
+
+ #define IGN1_COMPARE TCC1->CC[0].bit.CC
+ #define IGN2_COMPARE TCC1->CC[1].bit.CC
+ #define IGN3_COMPARE TCC2->CC[0].bit.CC
+ #define IGN4_COMPARE TCC2->CC[1].bit.CC
+ //The below are NOT YET RIGHT!
+ #define IGN5_COMPARE TCC1->CC[0].bit.CC
+ #define IGN6_COMPARE TCC1->CC[1].bit.CC
+ #define IGN7_COMPARE TCC2->CC[0].bit.CC
+ #define IGN8_COMPARE TCC2->CC[1].bit.CC
+
+ #define FUEL1_TIMER_ENABLE() TCC0->INTENSET.bit.MC0 = 0x1
+ #define FUEL2_TIMER_ENABLE() TCC0->INTENSET.bit.MC1 = 0x1
+ #define FUEL3_TIMER_ENABLE() TCC0->INTENSET.bit.MC2 = 0x1
+ #define FUEL4_TIMER_ENABLE() TCC0->INTENSET.bit.MC3 = 0x1
+ //The below are NOT YET RIGHT!
+ #define FUEL5_TIMER_ENABLE() TCC0->INTENSET.bit.MC0 = 0x1
+ #define FUEL6_TIMER_ENABLE() TCC0->INTENSET.bit.MC1 = 0x1
+ #define FUEL7_TIMER_ENABLE() TCC0->INTENSET.bit.MC2 = 0x1
+ #define FUEL8_TIMER_ENABLE() TCC0->INTENSET.bit.MC3 = 0x1
+
+ #define FUEL1_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0
+ #define FUEL2_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0
+ #define FUEL3_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0
+ #define FUEL4_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0
+ //The below are NOT YET RIGHT!
+ #define FUEL5_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0
+ #define FUEL6_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0
+ #define FUEL7_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0
+ #define FUEL8_TIMER_DISABLE() TCC0->INTENSET.bit.MC0 = 0x0
+
+ #define IGN1_TIMER_ENABLE() TCC1->INTENSET.bit.MC0 = 0x1
+ #define IGN2_TIMER_ENABLE() TCC1->INTENSET.bit.MC1 = 0x1
+ #define IGN3_TIMER_ENABLE() TCC2->INTENSET.bit.MC0 = 0x1
+ #define IGN4_TIMER_ENABLE() TCC2->INTENSET.bit.MC1 = 0x1
+ //The below are NOT YET RIGHT!
+ #define IGN5_TIMER_ENABLE() TCC1->INTENSET.bit.MC0 = 0x1
+ #define IGN6_TIMER_ENABLE() TCC1->INTENSET.bit.MC1 = 0x1
+ #define IGN7_TIMER_ENABLE() TCC2->INTENSET.bit.MC0 = 0x1
+ #define IGN8_TIMER_ENABLE() TCC2->INTENSET.bit.MC1 = 0x1
+
+ #define IGN1_TIMER_DISABLE() TCC1->INTENSET.bit.MC0 = 0x0
+ #define IGN2_TIMER_DISABLE() TCC1->INTENSET.bit.MC1 = 0x0
+ #define IGN3_TIMER_DISABLE() TCC2->INTENSET.bit.MC0 = 0x0
+ #define IGN4_TIMER_DISABLE() TCC2->INTENSET.bit.MC1 = 0x0
+ //The below are NOT YET RIGHT!
+ #define IGN5_TIMER_DISABLE() TCC1->INTENSET.bit.MC0 = 0x0
+ #define IGN6_TIMER_DISABLE() TCC1->INTENSET.bit.MC1 = 0x0
+ #define IGN7_TIMER_DISABLE() TCC2->INTENSET.bit.MC0 = 0x0
+ #define IGN8_TIMER_DISABLE() TCC2->INTENSET.bit.MC1 = 0x0
+
+ #define MAX_TIMER_PERIOD 139808 // 2.13333333uS * 65535
+ #define MAX_TIMER_PERIOD_SLOW 139808
+ #define uS_TO_TIMER_COMPARE(uS) ((uS * 15) >> 5) //Converts a given number of uS into the required number of timer ticks until that time has passed.
+ //Hack compatibility with AVR timers that run at different speeds
+ #define uS_TO_TIMER_COMPARE_SLOW(uS) ((uS * 15) >> 5)
+
+/*
+***********************************************************************************************************
+* Auxilliaries
+*/
+ //Uses the 2nd TC
+ //The 2nd TC is referred to as TC4
+ #define ENABLE_BOOST_TIMER() TC4->COUNT16.INTENSET.bit.MC0 = 0x1 // Enable match interrupts on compare channel 0
+ #define DISABLE_BOOST_TIMER() TC4->COUNT16.INTENSET.bit.MC0 = 0x0
+
+ #define ENABLE_VVT_TIMER() TC4->COUNT16.INTENSET.bit.MC1 = 0x1
+ #define DISABLE_VVT_TIMER() TC4->COUNT16.INTENSET.bit.MC1 = 0x0
+
+ #define BOOST_TIMER_COMPARE TC4->COUNT16.CC[0].reg
+ #define BOOST_TIMER_COUNTER TC4->COUNT16.COUNT.bit.COUNT
+ #define VVT_TIMER_COMPARE TC4->COUNT16.CC[1].reg
+ #define VVT_TIMER_COUNTER TC4->COUNT16.COUNT.bit.COUNT
+
+/*
+***********************************************************************************************************
+* Idle
+*/
+ //3rd TC is aliased as TC5
+ #define IDLE_COUNTER TC5->COUNT16.COUNT.bit.COUNT
+ #define IDLE_COMPARE TC5->COUNT16.CC[0].reg
+
+ #define IDLE_TIMER_ENABLE() TC5->COUNT16.INTENSET.bit.MC0 = 0x1
+ #define IDLE_TIMER_DISABLE() TC5->COUNT16.INTENSET.bit.MC0 = 0x0
+
+/*
+***********************************************************************************************************
+* CAN / Second serial
+*/
+ Uart CANSerial (&sercom3, 0, 1, SERCOM_RX_PAD_1, UART_TX_PAD_0);
+
+#endif //CORE_SAMD21
+#endif //SAMD21_H
\ No newline at end of file
diff --git a/speeduino/board_samd21.ino b/speeduino/board_samd21.ino
new file mode 100644
index 00000000..8e3df1a9
--- /dev/null
+++ b/speeduino/board_samd21.ino
@@ -0,0 +1,11 @@
+
+#include "globals.h"
+
+#if defined(CORE_SAMD21)
+
+void initBoard()
+{
+
+}
+
+#endif
\ No newline at end of file
diff --git a/speeduino/src/boards/stm32.h b/speeduino/board_stm32.h
similarity index 100%
rename from speeduino/src/boards/stm32.h
rename to speeduino/board_stm32.h
diff --git a/speeduino/src/boards/teensy35.h b/speeduino/board_teensy35.h
similarity index 100%
rename from speeduino/src/boards/teensy35.h
rename to speeduino/board_teensy35.h
diff --git a/speeduino/globals.h b/speeduino/globals.h
index 9a9e417a..a4156e8b 100644
--- a/speeduino/globals.h
+++ b/speeduino/globals.h
@@ -12,16 +12,16 @@
#define BOARD_NR_GPIO_PINS 62
#define LED_BUILTIN 13
#define CORE_AVR
- #define BOARD_H "src/boards/avr2560.h"
+ #define BOARD_H "board_avr2560.h"
//#define TIMER5_MICROS
#elif defined(CORE_TEENSY)
- #define BOARD_H "src/boards/teensy35.h"
+ #define BOARD_H "board_teensy35.h"
#elif defined(STM32_MCU_SERIES) || defined(ARDUINO_ARCH_STM32) || defined(__STM32F1__) || defined(STM32F4) || defined(STM32)
#define CORE_STM32
- #define BOARD_H "src/boards/stm32.h"
+ #define BOARD_H "board_stm32.h"
#ifndef word
#define word(h, l) ((h << 8) | l) //word() function not defined for this platform in the main library
#endif
@@ -53,7 +53,7 @@
#define portInputRegister(port) (volatile byte *)( &(port->regs->IDR) )
#endif
#elif defined(__SAMD21G18A__)
- #define BOARD_H "src/boards/samd21.h"
+ #define BOARD_H "board_samd21.h"
#define CORE_SAMD21
#else
#error Incorrect board selected. Please select the correct board (Usually Mega 2560) and upload again
diff --git a/speeduino/init.ino b/speeduino/init.ino
index 574e1aa5..a895a0d3 100644
--- a/speeduino/init.ino
+++ b/speeduino/init.ino
@@ -13,9 +13,11 @@
#include "decoders.h"
#include "corrections.h"
#include "idle.h"
+#include BOARD_H //Note that this is not a real file, it is defined in globals.h.
void initialiseAll()
{
+ initBoard();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
table3D_setSize(&fuelTable, 16);
diff --git a/speeduino/src/FlashStorage/FlashAsEEPROM.cpp b/speeduino/src/FlashStorage/FlashAsEEPROM.cpp
index 571033eb..2950abe4 100755
--- a/speeduino/src/FlashStorage/FlashAsEEPROM.cpp
+++ b/speeduino/src/FlashStorage/FlashAsEEPROM.cpp
@@ -18,6 +18,7 @@
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#if defined(__SAMD21G18A__)
#include "FlashAsEEPROM.h"
FlashStorage(eeprom_storage, EEPROM_EMULATION);
@@ -70,4 +71,6 @@ void EEPROMClass::commit()
}
}
-EEPROMClass EEPROM;
\ No newline at end of file
+EEPROMClass EEPROM;
+
+#endif
\ No newline at end of file
diff --git a/speeduino/src/FlashStorage/FlashStorage.cpp b/speeduino/src/FlashStorage/FlashStorage.cpp
index 37a6cd33..dd09615c 100755
--- a/speeduino/src/FlashStorage/FlashStorage.cpp
+++ b/speeduino/src/FlashStorage/FlashStorage.cpp
@@ -16,8 +16,11 @@
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#if defined(__SAMD21G18A__)
#include "FlashStorage.h"
+
+
static const uint32_t pageSizes[] = { 8, 16, 32, 64, 128, 256, 512, 1024 };
FlashClass::FlashClass(const void *flash_addr, uint32_t size) :
@@ -97,3 +100,5 @@ void FlashClass::read(const volatile void *flash_ptr, void *data, uint32_t size)
{
memcpy(data, (const void *)flash_ptr, size);
}
+
+#endif
\ No newline at end of file
diff --git a/speeduino/storage.ino b/speeduino/storage.ino
index d7f1ae53..b26889c2 100644
--- a/speeduino/storage.ino
+++ b/speeduino/storage.ino
@@ -4,16 +4,16 @@ Copyright (C) Josh Stewart
A full copy of the license may be found in the projects root directory
*/
-#include "storage.h"
+
#include "globals.h"
#include "table.h"
#include "comms.h"
#if defined(CORE_SAMD21)
#include "src/FlashStorage/FlashAsEEPROM.h"
#else
-#include
+ #include
#endif
-
+#include "storage.h"
void writeAllConfig()
{
writeConfig(1);