Skip to content

Commit

Permalink
Rename all ino files to cpp (Excluding speeduino.ino).
Browse files Browse the repository at this point in the history
Confirmed this compiles OK in Arduino IDE 2.x
Frees up 8 bytes of RAM
  • Loading branch information
noisymime committed Oct 6, 2023
1 parent 977ffa3 commit fc536d1
Show file tree
Hide file tree
Showing 48 changed files with 473 additions and 589 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* The command handler manages all the inputs FROM TS which are issued when a command button is clicked by the user
*/

#include "TS_CommandButtonHandler.h"
#include "globals.h"
#include "TS_CommandButtonHandler.h"
#include "utilities.h"
#include "scheduledIO.h"
#include "sensors.h"
Expand Down
29 changes: 29 additions & 0 deletions speeduino/acc_mc33810.ino → speeduino/acc_mc33810.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,37 @@
#include "globals.h"
#include <SPI.h>

uint8_t MC33810_BIT_INJ1 = 1;
uint8_t MC33810_BIT_INJ2 = 2;
uint8_t MC33810_BIT_INJ3 = 3;
uint8_t MC33810_BIT_INJ4 = 4;
uint8_t MC33810_BIT_INJ5 = 5;
uint8_t MC33810_BIT_INJ6 = 6;
uint8_t MC33810_BIT_INJ7 = 7;
uint8_t MC33810_BIT_INJ8 = 8;

uint8_t MC33810_BIT_IGN1 = 1;
uint8_t MC33810_BIT_IGN2 = 2;
uint8_t MC33810_BIT_IGN3 = 3;
uint8_t MC33810_BIT_IGN4 = 4;
uint8_t MC33810_BIT_IGN5 = 5;
uint8_t MC33810_BIT_IGN6 = 6;
uint8_t MC33810_BIT_IGN7 = 7;
uint8_t MC33810_BIT_IGN8 = 8;

volatile PORT_TYPE *mc33810_1_pin_port;
volatile PINMASK_TYPE mc33810_1_pin_mask;
volatile PORT_TYPE *mc33810_2_pin_port;
volatile PINMASK_TYPE mc33810_2_pin_mask;

void initMC33810(void)
{
//Set pin port/masks
mc33810_1_pin_port = portOutputRegister(digitalPinToPort(pinMC33810_1_CS));
mc33810_1_pin_mask = digitalPinToBitMask(pinMC33810_1_CS);
mc33810_2_pin_port = portOutputRegister(digitalPinToPort(pinMC33810_2_CS));
mc33810_2_pin_mask = digitalPinToBitMask(pinMC33810_2_CS);

//Set the output states of both ICs to be off to fuel and ignition
mc33810_1_requestedState = 0;
mc33810_2_requestedState = 0;
Expand Down
52 changes: 27 additions & 25 deletions speeduino/acc_mc33810.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
#define MC33810_H

#include <SPI.h>
#include "globals.h"
#include BOARD_H //Note that this is not a real file, it is defined in globals.h.

volatile PORT_TYPE *mc33810_1_pin_port;
volatile PINMASK_TYPE mc33810_1_pin_mask;
volatile PORT_TYPE *mc33810_2_pin_port;
volatile PINMASK_TYPE mc33810_2_pin_mask;
extern volatile PORT_TYPE *mc33810_1_pin_port;
extern volatile PINMASK_TYPE mc33810_1_pin_mask;
extern volatile PORT_TYPE *mc33810_2_pin_port;
extern volatile PINMASK_TYPE mc33810_2_pin_mask;

//#define MC33810_ONOFF_CMD 3
static uint8_t MC33810_ONOFF_CMD = 0x30; //48 in decimal
volatile uint8_t mc33810_1_requestedState; //Current binary state of the 1st ICs IGN and INJ values
volatile uint8_t mc33810_2_requestedState; //Current binary state of the 2nd ICs IGN and INJ values
volatile uint8_t mc33810_1_returnState; //Current binary state of the 1st ICs IGN and INJ values
volatile uint8_t mc33810_2_returnState; //Current binary state of the 2nd ICs IGN and INJ values
static const uint8_t MC33810_ONOFF_CMD = 0x30; //48 in decimal
static volatile uint8_t mc33810_1_requestedState; //Current binary state of the 1st ICs IGN and INJ values
static volatile uint8_t mc33810_2_requestedState; //Current binary state of the 2nd ICs IGN and INJ values
static volatile uint8_t mc33810_1_returnState; //Current binary state of the 1st ICs IGN and INJ values
static volatile uint8_t mc33810_2_returnState; //Current binary state of the 2nd ICs IGN and INJ values

void initMC33810(void);

Expand All @@ -24,23 +26,23 @@ void initMC33810(void);

//These are default values for which injector is attached to which output on the IC.
//They may (Probably will) be changed during init by the board specific config in init.ino
uint8_t MC33810_BIT_INJ1 = 1;
uint8_t MC33810_BIT_INJ2 = 2;
uint8_t MC33810_BIT_INJ3 = 3;
uint8_t MC33810_BIT_INJ4 = 4;
uint8_t MC33810_BIT_INJ5 = 5;
uint8_t MC33810_BIT_INJ6 = 6;
uint8_t MC33810_BIT_INJ7 = 7;
uint8_t MC33810_BIT_INJ8 = 8;
extern uint8_t MC33810_BIT_INJ1;
extern uint8_t MC33810_BIT_INJ2;
extern uint8_t MC33810_BIT_INJ3;
extern uint8_t MC33810_BIT_INJ4;
extern uint8_t MC33810_BIT_INJ5;
extern uint8_t MC33810_BIT_INJ6;
extern uint8_t MC33810_BIT_INJ7;
extern uint8_t MC33810_BIT_INJ8;

uint8_t MC33810_BIT_IGN1 = 1;
uint8_t MC33810_BIT_IGN2 = 2;
uint8_t MC33810_BIT_IGN3 = 3;
uint8_t MC33810_BIT_IGN4 = 4;
uint8_t MC33810_BIT_IGN5 = 5;
uint8_t MC33810_BIT_IGN6 = 6;
uint8_t MC33810_BIT_IGN7 = 7;
uint8_t MC33810_BIT_IGN8 = 8;
extern uint8_t MC33810_BIT_IGN1;
extern uint8_t MC33810_BIT_IGN2;
extern uint8_t MC33810_BIT_IGN3;
extern uint8_t MC33810_BIT_IGN4;
extern uint8_t MC33810_BIT_IGN5;
extern uint8_t MC33810_BIT_IGN6;
extern uint8_t MC33810_BIT_IGN7;
extern uint8_t MC33810_BIT_IGN8;

#define openInjector1_MC33810() MC33810_1_ACTIVE(); BIT_SET(mc33810_1_requestedState, MC33810_BIT_INJ1); mc33810_1_returnState = SPI.transfer16(word(MC33810_ONOFF_CMD, mc33810_1_requestedState)); MC33810_1_INACTIVE()
#define openInjector2_MC33810() MC33810_1_ACTIVE(); BIT_SET(mc33810_1_requestedState, MC33810_BIT_INJ2); mc33810_1_returnState = SPI.transfer16(word(MC33810_ONOFF_CMD, mc33810_1_requestedState)); MC33810_1_INACTIVE()
Expand Down
65 changes: 65 additions & 0 deletions speeduino/auxiliaries.ino → speeduino/auxiliaries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,77 @@ A full copy of the license may be found in the projects root directory
#include "decoders.h"
#include "timers.h"

static long vvt1_pwm_value;
static long vvt2_pwm_value;
volatile unsigned int vvt1_pwm_cur_value;
volatile unsigned int vvt2_pwm_cur_value;
static long vvt_pid_target_angle;
static long vvt2_pid_target_angle;
static long vvt_pid_current_angle;
static long vvt2_pid_current_angle;
volatile bool vvt1_pwm_state;
volatile bool vvt2_pwm_state;
volatile bool vvt1_max_pwm;
volatile bool vvt2_max_pwm;
volatile char nextVVT;
byte boostCounter;
byte vvtCounter;

volatile PORT_TYPE *boost_pin_port;
volatile PINMASK_TYPE boost_pin_mask;
volatile PORT_TYPE *n2o_stage1_pin_port;
volatile PINMASK_TYPE n2o_stage1_pin_mask;
volatile PORT_TYPE *n2o_stage2_pin_port;
volatile PINMASK_TYPE n2o_stage2_pin_mask;
volatile PORT_TYPE *n2o_arming_pin_port;
volatile PINMASK_TYPE n2o_arming_pin_mask;
volatile PORT_TYPE *aircon_comp_pin_port;
volatile PINMASK_TYPE aircon_comp_pin_mask;
volatile PORT_TYPE *aircon_fan_pin_port;
volatile PINMASK_TYPE aircon_fan_pin_mask;
volatile PORT_TYPE *aircon_req_pin_port;
volatile PINMASK_TYPE aircon_req_pin_mask;
volatile PORT_TYPE *vvt1_pin_port;
volatile PINMASK_TYPE vvt1_pin_mask;
volatile PORT_TYPE *vvt2_pin_port;
volatile PINMASK_TYPE vvt2_pin_mask;
volatile PORT_TYPE *fan_pin_port;
volatile PINMASK_TYPE fan_pin_mask;

#if defined(PWM_FAN_AVAILABLE)//PWM fan not available on Arduino MEGA
volatile bool fan_pwm_state;
unsigned int fan_pwm_max_count; //Used for variable PWM frequency
volatile unsigned int fan_pwm_cur_value;
long fan_pwm_value;
#endif

bool acIsEnabled;
bool acStandAloneFanIsEnabled;
uint8_t acStartDelay;
uint8_t acTPSLockoutDelay;
uint8_t acRPMLockoutDelay;
uint8_t acAfterEngineStartDelay;
bool waitedAfterCranking; // This starts false and prevents the A/C from running until a few seconds after cranking

long boost_pwm_target_value;
volatile bool boost_pwm_state;
volatile unsigned int boost_pwm_cur_value = 0;

uint32_t vvtWarmTime;
bool vvtIsHot;
bool vvtTimeHold;
unsigned int vvt_pwm_max_count; //Used for variable PWM frequency
unsigned int boost_pwm_max_count; //Used for variable PWM frequency

//Old PID method. Retained in case the new one has issues
//integerPID boostPID(&MAPx100, &boost_pwm_target_value, &boostTargetx100, configPage6.boostKP, configPage6.boostKI, configPage6.boostKD, DIRECT);
integerPID_ideal boostPID(&currentStatus.MAP, &currentStatus.boostDuty , &currentStatus.boostTarget, &configPage10.boostSens, &configPage10.boostIntv, configPage6.boostKP, configPage6.boostKI, configPage6.boostKD, DIRECT); //This is the PID object if that algorithm is used. Needs to be global as it maintains state outside of each function call
integerPID vvtPID(&vvt_pid_current_angle, &currentStatus.vvt1Duty, &vvt_pid_target_angle, configPage10.vvtCLKP, configPage10.vvtCLKI, configPage10.vvtCLKD, configPage6.vvtPWMdir); //This is the PID object if that algorithm is used. Needs to be global as it maintains state outside of each function call
integerPID vvt2PID(&vvt2_pid_current_angle, &currentStatus.vvt2Duty, &vvt2_pid_target_angle, configPage10.vvtCLKP, configPage10.vvtCLKI, configPage10.vvtCLKD, configPage4.vvt2PWMdir); //This is the PID object if that algorithm is used. Needs to be global as it maintains state outside of each function call

static inline void checkAirConCoolantLockout(void);
static inline void checkAirConTPSLockout(void);
static inline void checkAirConRPMLockout(void);

/*
Air Conditioning Control
Expand Down
74 changes: 12 additions & 62 deletions speeduino/auxiliaries.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ void airConControl(void);
bool READ_AIRCON_REQUEST(void);
void wmiControl(void);

static inline void checkAirConCoolantLockout(void);
static inline void checkAirConTPSLockout(void);
static inline void checkAirConRPMLockout(void);

#define SIMPLE_BOOST_P 1
#define SIMPLE_BOOST_I 1
#define SIMPLE_BOOST_D 1
Expand Down Expand Up @@ -97,69 +93,23 @@ static inline void checkAirConRPMLockout(void);

#define WMI_TANK_IS_EMPTY() ((configPage10.wmiEmptyEnabled) ? ((configPage10.wmiEmptyPolarity) ? digitalRead(pinWMIEmpty) : !digitalRead(pinWMIEmpty)) : 1)

volatile PORT_TYPE *boost_pin_port;
volatile PINMASK_TYPE boost_pin_mask;
volatile PORT_TYPE *vvt1_pin_port;
volatile PINMASK_TYPE vvt1_pin_mask;
volatile PORT_TYPE *vvt2_pin_port;
volatile PINMASK_TYPE vvt2_pin_mask;
volatile PORT_TYPE *fan_pin_port;
volatile PINMASK_TYPE fan_pin_mask;
volatile PORT_TYPE *n2o_stage1_pin_port;
volatile PINMASK_TYPE n2o_stage1_pin_mask;
volatile PORT_TYPE *n2o_stage2_pin_port;
volatile PINMASK_TYPE n2o_stage2_pin_mask;
volatile PORT_TYPE *n2o_arming_pin_port;
volatile PINMASK_TYPE n2o_arming_pin_mask;
volatile PORT_TYPE *aircon_comp_pin_port;
volatile PINMASK_TYPE aircon_comp_pin_mask;
volatile PORT_TYPE *aircon_fan_pin_port;
volatile PINMASK_TYPE aircon_fan_pin_mask;
volatile PORT_TYPE *aircon_req_pin_port;
volatile PINMASK_TYPE aircon_req_pin_mask;

volatile bool boost_pwm_state;
unsigned int boost_pwm_max_count; //Used for variable PWM frequency
volatile unsigned int boost_pwm_cur_value;
long boost_pwm_target_value;
long boost_cl_target_boost;
byte boostCounter;
byte vvtCounter;
extern volatile PORT_TYPE *vvt1_pin_port;
extern volatile PINMASK_TYPE vvt1_pin_mask;
extern volatile PORT_TYPE *vvt2_pin_port;
extern volatile PINMASK_TYPE vvt2_pin_mask;
extern volatile PORT_TYPE *fan_pin_port;
extern volatile PINMASK_TYPE fan_pin_mask;

#if defined(PWM_FAN_AVAILABLE)//PWM fan not available on Arduino MEGA
volatile bool fan_pwm_state;
unsigned int fan_pwm_max_count; //Used for variable PWM frequency
volatile unsigned int fan_pwm_cur_value;
long fan_pwm_value;
extern unsigned int fan_pwm_max_count; //Used for variable PWM frequency
void fanInterrupt(void);
#endif
uint32_t vvtWarmTime;
bool vvtIsHot;
bool vvtTimeHold;

volatile bool vvt1_pwm_state;
volatile bool vvt2_pwm_state;
volatile bool vvt1_max_pwm;
volatile bool vvt2_max_pwm;
volatile char nextVVT;
unsigned int vvt_pwm_max_count; //Used for variable PWM frequency
volatile unsigned int vvt1_pwm_cur_value;
volatile unsigned int vvt2_pwm_cur_value;
long vvt1_pwm_value;
long vvt2_pwm_value;
long vvt_pid_target_angle;
long vvt2_pid_target_angle;
long vvt_pid_current_angle;
long vvt2_pid_current_angle;

extern unsigned int vvt_pwm_max_count; //Used for variable PWM frequency
extern unsigned int boost_pwm_max_count; //Used for variable PWM frequency


void boostInterrupt(void);
void vvtInterrupt(void);

bool acIsEnabled;
bool acStandAloneFanIsEnabled;
uint8_t acStartDelay;
uint8_t acTPSLockoutDelay;
uint8_t acRPMLockoutDelay;
uint8_t acAfterEngineStartDelay;
bool waitedAfterCranking; // This starts false and prevents the A/C from running until a few seconds after cranking

#endif
3 changes: 1 addition & 2 deletions speeduino/board_avr2560.ino → speeduino/board_avr2560.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

#if defined(CORE_AVR)
#include "globals.h"
#if defined(CORE_AVR)
#include "auxiliaries.h"

// Prescaler values for timers 1-3-4-5. Refer to www.instructables.com/files/orig/F3T/TIKL/H3WSA4V7/F3TTIKLH3WSA4V7.jpg
Expand Down
2 changes: 2 additions & 0 deletions speeduino/board_avr2560.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#ifndef AVR2560_H
#define AVR2560_H

#include "globals.h"
#if defined(CORE_AVR)

#include <avr/interrupt.h>
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "board_stm32_official.h"
#if defined(STM32_CORE_VERSION_MAJOR)
#include "globals.h"

#if defined(STM32_CORE_VERSION_MAJOR)
#include "auxiliaries.h"
#include "idle.h"
#include "scheduler.h"
#include "HardwareTimer.h"
#include "timers.h"

#if HAL_CAN_MODULE_ENABLED
//This activates CAN1 interface on STM32, but it's named as Can0, because that's how Teensy implementation is done
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "globals.h"

#if defined(CORE_TEENSY) && defined(CORE_TEENSY35)
#include "board_teensy35.h"
#include "globals.h"
#include "auxiliaries.h"
#include "idle.h"
#include "scheduler.h"
#include "timers.h"

#if defined(__MK64FX512__) // use for Teensy 3.5 only
FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#include "globals.h"
#if defined(CORE_TEENSY) && defined(__IMXRT1062__)
#include "board_teensy41.h"
#include "globals.h"
#include "auxiliaries.h"
#include "idle.h"
#include "scheduler.h"
#include "timers.h"

FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can0;
FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> Can1;
FlexCAN_T4<CAN3, RX_SIZE_256, TX_SIZE_16> Can2;

static void PIT_isr();
static void TMR1_isr(void);
static void TMR2_isr(void);
static void TMR3_isr(void);
static void TMR4_isr(void);

void initBoard()
{
/*
Expand Down
2 changes: 2 additions & 0 deletions speeduino/board_teensy41.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef TEENSY41_H
#define TEENSY41_H

#if defined(CORE_TEENSY) && defined(__IMXRT1062__)

/*
Expand Down Expand Up @@ -31,6 +32,7 @@
//#define PWM_FAN_AVAILABLE
#define pinIsReserved(pin) ( ((pin) == 0) || ((pin) == 42) || ((pin) == 43) || ((pin) == 44) || ((pin) == 45) || ((pin) == 46) || ((pin) == 47) ) //Forbidden pins like USB


/*
***********************************************************************************************************
* Schedules
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if defined(CORE_TEMPLATE)
#include "globals.h"
#if defined(CORE_TEMPLATE)


void initBoard()
{
Expand Down
3 changes: 2 additions & 1 deletion speeduino/canBroadcast.ino → speeduino/canBroadcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ A full copy of the license may be found in the projects root directory
/*
This is for handling the data broadcasted to various CAN dashes and instrument clusters.
*/
#if defined(NATIVE_CAN_AVAILABLE)
#include "globals.h"
#if defined(NATIVE_CAN_AVAILABLE)
#include "canBroadcast.h"

// Forward declare
void DashMessage(uint16_t DashMessageID);
Expand Down
1 change: 1 addition & 0 deletions speeduino/comms_legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ A full copy of the license may be found in the projects root directory
#include "page_crc.h"
#include "logger.h"
#include "table3d_axis_io.h"
#include BOARD_H
#ifdef RTC_ENABLED
#include "rtc_common.h"
#endif
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit fc536d1

Please sign in to comment.