From c16b8eaba3a3cf01241b19ea352d7f2715ef2da0 Mon Sep 17 00:00:00 2001 From: Eike Ahmels Date: Tue, 29 Oct 2024 08:14:30 +0100 Subject: [PATCH] rebase and fix auto_advance --- Inc/common.h | 6 +- Inc/dshot.h | 1 - Inc/eeprom.h | 62 +++++ Inc/signal.h | 1 - Inc/version.h | 2 + Mcu/e230/Inc/IO.h | 1 - Mcu/e230/Inc/eeprom.h | 17 -- Mcu/e230/Inc/phaseouts.h | 1 + Mcu/e230/Src/phaseouts.c | 13 +- Mcu/f031/Inc/IO.h | 1 - Mcu/f031/Inc/eeprom.h | 17 -- Mcu/f031/Inc/phaseouts.h | 1 + Mcu/f031/Src/phaseouts.c | 13 +- Mcu/f051/Inc/IO.h | 2 - Mcu/f051/Inc/eeprom.h | 17 -- Mcu/f051/Inc/phaseouts.h | 1 + Mcu/f051/Src/phaseouts.c | 13 +- Mcu/f415/Inc/IO.h | 1 - Mcu/f415/Inc/eeprom.h | 7 - Mcu/f415/Inc/phaseouts.h | 1 + Mcu/f415/Src/phaseouts.c | 15 +- Mcu/f421/Am32.sct | 6 +- Mcu/f421/Inc/IO.h | 1 - Mcu/f421/Inc/eeprom.h | 7 - Mcu/f421/Inc/phaseouts.h | 1 + Mcu/f421/Src/phaseouts.c | 15 +- Mcu/g071/Inc/eeprom.h | 17 -- Mcu/g071/Inc/phaseouts.h | 1 + Mcu/g071/Src/phaseouts.c | 13 +- Mcu/g431/Inc/eeprom.h | 17 -- Mcu/g431/Inc/phaseouts.h | 1 + Mcu/g431/Src/phaseouts.c | 13 +- Mcu/l431/Inc/IO.h | 2 - Mcu/l431/Inc/eeprom.h | 17 -- Mcu/l431/Inc/phaseouts.h | 1 + Mcu/l431/Src/phaseouts.c | 13 +- Src/dshot.c | 18 +- Src/main.c | 428 +++++++++++++-------------------- Src/signal.c | 7 +- Src/sounds.c | 506 +-------------------------------------- 40 files changed, 314 insertions(+), 963 deletions(-) create mode 100644 Inc/eeprom.h delete mode 100644 Mcu/e230/Inc/eeprom.h delete mode 100644 Mcu/f031/Inc/eeprom.h delete mode 100644 Mcu/f051/Inc/eeprom.h delete mode 100644 Mcu/f415/Inc/eeprom.h delete mode 100644 Mcu/f421/Inc/eeprom.h delete mode 100644 Mcu/g071/Inc/eeprom.h delete mode 100644 Mcu/g431/Inc/eeprom.h delete mode 100644 Mcu/l431/Inc/eeprom.h diff --git a/Inc/common.h b/Inc/common.h index ee154498a..df7d1ea2d 100644 --- a/Inc/common.h +++ b/Inc/common.h @@ -1,8 +1,10 @@ -#pragma once +#include +#include "eeprom.h" +#pragma once +extern EEprom_t eepromBuffer; extern uint32_t eeprom_address; -extern uint8_t eepromBuffer[176]; extern uint16_t TIMER1_MAX_ARR; extern uint16_t dshot_frametime_high; extern uint16_t dshot_frametime_low; diff --git a/Inc/dshot.h b/Inc/dshot.h index ed20bbd61..f69e9cfbc 100644 --- a/Inc/dshot.h +++ b/Inc/dshot.h @@ -21,7 +21,6 @@ extern void saveEEpromSettings(void); extern char dshot_telemetry; extern char armed; extern char dir_reversed; -extern char bi_direction; extern char buffer_divider; extern uint8_t last_dshot_command; extern uint32_t commutation_interval; diff --git a/Inc/eeprom.h b/Inc/eeprom.h new file mode 100644 index 000000000..2998b689c --- /dev/null +++ b/Inc/eeprom.h @@ -0,0 +1,62 @@ +#include "main.h" + +#pragma once + +typedef union EEprom_u { + struct { + uint8_t reserved_0; //0 + uint8_t eeprom_version; //1 + uint8_t reserved_1; //2 + struct { + uint8_t major; //3 + uint8_t minor; //4 + } version; + char firmware_name[12]; //5-16 + uint8_t dir_reversed; // 17 + uint8_t bi_direction; // 18 + uint8_t use_sine_start; // 19 + uint8_t comp_pwm; // 20 + uint8_t variable_pwm; // 21 + uint8_t stuck_rotor_protection; // 22 + uint8_t advance_level; // 23 + uint8_t pwm_frequency; // 24 + uint8_t startup_power; // 25 + uint8_t motor_kv; // 26 + uint8_t motor_poles; // 27 + uint8_t brake_on_stop; // 28 + uint8_t stall_protection; // 29 + uint8_t beep_volume; // 30 + uint8_t telementry_on_interval; // 31 + struct { + uint8_t low_threshold; // 32 + uint8_t high_threshold; // 33 + uint8_t neutral; // 34 + uint8_t dead_band; // 35 + } servo; + uint8_t low_voltage_cut_off; // 36 + uint8_t low_cell_volt_cutoff; // 37 + uint8_t rc_car_reverse; // 38 + uint8_t use_hall_sensors; // 39 + uint8_t sine_mode_changeover_thottle_level; // 40 + uint8_t drag_brake_strength; // 41 + uint8_t driving_brake_strength; // 42 + struct { + uint8_t temperature; // 43 + uint8_t current; // 44 + } limits; + uint8_t sine_mode_power; // 45 + uint8_t input_type; // 46 + uint8_t auto_advance; // 47 + uint8_t reserved_2[4]; //48-51 + uint8_t tune[124]; // 52-175 + }; + uint8_t buffer[184]; +} EEprom_t; + +extern EEprom_t eepromBuffer; + +// void save_to_flash(uint8_t *data); +// void read_flash(uint8_t* data, uint32_t address); +// void save_to_flash_bin(uint8_t *data, int length, uint32_t add); +void read_flash_bin(uint8_t* data, uint32_t add, int out_buff_len); +void save_flash_nolib(uint8_t* data, int length, uint32_t add); \ No newline at end of file diff --git a/Inc/signal.h b/Inc/signal.h index 0da9a0cd4..856798414 100644 --- a/Inc/signal.h +++ b/Inc/signal.h @@ -8,7 +8,6 @@ #include "main.h" extern char out_put; -extern char bi_direction; extern char inputSet; extern char dshot; extern char servoPwm; diff --git a/Inc/version.h b/Inc/version.h index 19554e016..0f0d0125e 100644 --- a/Inc/version.h +++ b/Inc/version.h @@ -3,3 +3,5 @@ */ #define VERSION_MAJOR 2 #define VERSION_MINOR 16 + +#define EEPROM_VERSION 2 \ No newline at end of file diff --git a/Mcu/e230/Inc/IO.h b/Mcu/e230/Inc/IO.h index bf20aacf6..352e164a9 100644 --- a/Mcu/e230/Inc/IO.h +++ b/Mcu/e230/Inc/IO.h @@ -24,7 +24,6 @@ void setInputPullUp(); void enableHalfTransferInt(); void setInputPullNone(); -extern char bi_direction; extern char inputSet; extern char dshot; extern char servoPwm; diff --git a/Mcu/e230/Inc/eeprom.h b/Mcu/e230/Inc/eeprom.h deleted file mode 100644 index 8e3304981..000000000 --- a/Mcu/e230/Inc/eeprom.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * bootloader.h - * - * Created on: Mar. 25, 2020 - * Author: Alka - */ -#include "main.h" -#ifndef INC_EEPROM_H_ -#define INC_EEPROM_H_ - -#endif /* INC_BOOTLOADER_H_ */ - -// void save_to_flash(uint8_t *data); -// void read_flash(uint8_t* data, uint32_t address); -// void save_to_flash_bin(uint8_t *data, int length, uint32_t add); -void read_flash_bin(uint8_t* data, uint32_t add, int out_buff_len); -void save_flash_nolib(uint8_t* data, int length, uint32_t add); diff --git a/Mcu/e230/Inc/phaseouts.h b/Mcu/e230/Inc/phaseouts.h index 37612388c..8f30ce902 100644 --- a/Mcu/e230/Inc/phaseouts.h +++ b/Mcu/e230/Inc/phaseouts.h @@ -9,6 +9,7 @@ #define INC_PHASEOUTS_H_ #include "main.h" +#include "common.h" void allOff(); void comStep(int newStep); diff --git a/Mcu/e230/Src/phaseouts.c b/Mcu/e230/Src/phaseouts.c index 477ef61b4..2504c3aa3 100644 --- a/Mcu/e230/Src/phaseouts.c +++ b/Mcu/e230/Src/phaseouts.c @@ -8,7 +8,6 @@ #include "targets.h" -extern char comp_pwm; extern char prop_brake_active; #ifndef PWM_ENABLE_BRIDGE @@ -69,7 +68,7 @@ void proportionalBrake() void phaseBPWM() { - if (!comp_pwm) { // for future + if (!eepromBuffer.comp_pwm) { // for future gpio_mode_QUICK(PHASE_B_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, PHASE_B_GPIO_LOW); GPIO_BC(PHASE_B_GPIO_PORT_LOW) = PHASE_B_GPIO_LOW; @@ -118,7 +117,7 @@ void phaseBLOW() void phaseCPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { gpio_mode_QUICK(PHASE_C_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, PHASE_C_GPIO_LOW); GPIO_BC(PHASE_C_GPIO_PORT_LOW) = PHASE_C_GPIO_LOW; @@ -157,7 +156,7 @@ void phaseCLOW() void phaseAPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { gpio_mode_QUICK(PHASE_A_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, PHASE_A_GPIO_LOW); GPIO_BC(PHASE_A_GPIO_PORT_LOW) = PHASE_A_GPIO_LOW; @@ -194,7 +193,7 @@ void phaseALOW() //////////////////////////////////PHASE 1////////////////////// void phaseBPWM() { - if (!comp_pwm) { // for future + if (!eepromBuffer.comp_pwm) { // for future // gpio_mode_QUICK(PHASE_B_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, // GPIO_PUPD_NONE, PHASE_B_GPIO_LOW); // GPIO_BC(PHASE_B_GPIO_PORT_LOW) = PHASE_B_GPIO_LOW; @@ -233,7 +232,7 @@ void phaseBLOW() void phaseCPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { // gpio_mode_QUICK(PHASE_C_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, // GPIO_PUPD_NONE, // PHASE_C_GPIO_LOW); GPIO_BC(PHASE_C_GPIO_PORT_LOW) = PHASE_C_GPIO_LOW; @@ -272,7 +271,7 @@ void phaseCLOW() void phaseAPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { // gpio_mode_QUICK(PHASE_A_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, // GPIO_PUPD_NONE, // PHASE_A_GPIO_LOW); GPIO_BC(PHASE_A_GPIO_PORT_LOW) = PHASE_A_GPIO_LOW; diff --git a/Mcu/f031/Inc/IO.h b/Mcu/f031/Inc/IO.h index bf20aacf6..352e164a9 100644 --- a/Mcu/f031/Inc/IO.h +++ b/Mcu/f031/Inc/IO.h @@ -24,7 +24,6 @@ void setInputPullUp(); void enableHalfTransferInt(); void setInputPullNone(); -extern char bi_direction; extern char inputSet; extern char dshot; extern char servoPwm; diff --git a/Mcu/f031/Inc/eeprom.h b/Mcu/f031/Inc/eeprom.h deleted file mode 100644 index 8e3304981..000000000 --- a/Mcu/f031/Inc/eeprom.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * bootloader.h - * - * Created on: Mar. 25, 2020 - * Author: Alka - */ -#include "main.h" -#ifndef INC_EEPROM_H_ -#define INC_EEPROM_H_ - -#endif /* INC_BOOTLOADER_H_ */ - -// void save_to_flash(uint8_t *data); -// void read_flash(uint8_t* data, uint32_t address); -// void save_to_flash_bin(uint8_t *data, int length, uint32_t add); -void read_flash_bin(uint8_t* data, uint32_t add, int out_buff_len); -void save_flash_nolib(uint8_t* data, int length, uint32_t add); diff --git a/Mcu/f031/Inc/phaseouts.h b/Mcu/f031/Inc/phaseouts.h index 37612388c..8f30ce902 100644 --- a/Mcu/f031/Inc/phaseouts.h +++ b/Mcu/f031/Inc/phaseouts.h @@ -9,6 +9,7 @@ #define INC_PHASEOUTS_H_ #include "main.h" +#include "common.h" void allOff(); void comStep(int newStep); diff --git a/Mcu/f031/Src/phaseouts.c b/Mcu/f031/Src/phaseouts.c index 0dde9f263..fdcf49e04 100644 --- a/Mcu/f031/Src/phaseouts.c +++ b/Mcu/f031/Src/phaseouts.c @@ -8,7 +8,6 @@ #include "targets.h" -extern char comp_pwm; extern char prop_brake_active; #ifndef PWM_ENABLE_BRIDGE @@ -61,7 +60,7 @@ void proportionalBrake() void phaseBPWM() { - if (!comp_pwm) { // for future + if (!eepromBuffer.comp_pwm) { // for future LL_GPIO_SetPinMode(PHASE_B_GPIO_PORT_LOW, PHASE_B_GPIO_LOW, LL_GPIO_MODE_OUTPUT); PHASE_B_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_B_GPIO_LOW; @@ -99,7 +98,7 @@ void phaseBLOW() void phaseCPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { LL_GPIO_SetPinMode(PHASE_C_GPIO_PORT_LOW, PHASE_C_GPIO_LOW, LL_GPIO_MODE_OUTPUT); PHASE_C_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_C_GPIO_LOW; @@ -137,7 +136,7 @@ void phaseCLOW() void phaseAPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { LL_GPIO_SetPinMode(PHASE_A_GPIO_PORT_LOW, PHASE_A_GPIO_LOW, LL_GPIO_MODE_OUTPUT); PHASE_A_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_A_GPIO_LOW; @@ -174,7 +173,7 @@ void phaseALOW() //////////////////////////////////PHASE 1////////////////////// void phaseBPWM() { - if (!comp_pwm) { // for future + if (!eepromBuffer.comp_pwm) { // for future // LL_GPIO_SetPinMode(PHASE_B_GPIO_PORT_LOW, // PHASE_B_GPIO_LOW, LL_GPIO_MODE_OUTPUT); // PHASE_B_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_B_GPIO_LOW; @@ -213,7 +212,7 @@ void phaseBLOW() void phaseCPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { // LL_GPIO_SetPinMode(PHASE_C_GPIO_PORT_LOW, PHASE_C_GPIO_LOW, // LL_GPIO_MODE_OUTPUT); PHASE_C_GPIO_PORT_LOW->LOW_BITREG_OFF = // PHASE_C_GPIO_LOW; @@ -252,7 +251,7 @@ void phaseCLOW() void phaseAPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { // LL_GPIO_SetPinMode(PHASE_A_GPIO_PORT_LOW, PHASE_A_GPIO_LOW, // LL_GPIO_MODE_OUTPUT); PHASE_A_GPIO_PORT_LOW->LOW_BITREG_OFF = // PHASE_A_GPIO_LOW; diff --git a/Mcu/f051/Inc/IO.h b/Mcu/f051/Inc/IO.h index 755f6a051..8b1d7459e 100644 --- a/Mcu/f051/Inc/IO.h +++ b/Mcu/f051/Inc/IO.h @@ -24,8 +24,6 @@ void setInputPullUp(); void enableHalfTransferInt(); void setInputPullNone(); -extern char bi_direction; - extern char send_telemetry; extern uint8_t degrees_celsius; diff --git a/Mcu/f051/Inc/eeprom.h b/Mcu/f051/Inc/eeprom.h deleted file mode 100644 index 8e3304981..000000000 --- a/Mcu/f051/Inc/eeprom.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * bootloader.h - * - * Created on: Mar. 25, 2020 - * Author: Alka - */ -#include "main.h" -#ifndef INC_EEPROM_H_ -#define INC_EEPROM_H_ - -#endif /* INC_BOOTLOADER_H_ */ - -// void save_to_flash(uint8_t *data); -// void read_flash(uint8_t* data, uint32_t address); -// void save_to_flash_bin(uint8_t *data, int length, uint32_t add); -void read_flash_bin(uint8_t* data, uint32_t add, int out_buff_len); -void save_flash_nolib(uint8_t* data, int length, uint32_t add); diff --git a/Mcu/f051/Inc/phaseouts.h b/Mcu/f051/Inc/phaseouts.h index c66c8940e..8a2167a6a 100644 --- a/Mcu/f051/Inc/phaseouts.h +++ b/Mcu/f051/Inc/phaseouts.h @@ -9,6 +9,7 @@ #define INC_PHASEOUTS_H_ #include "main.h" +#include "common.h" void allOff(); void comStep(char newStep); diff --git a/Mcu/f051/Src/phaseouts.c b/Mcu/f051/Src/phaseouts.c index 77f20842f..eedd2d8e3 100644 --- a/Mcu/f051/Src/phaseouts.c +++ b/Mcu/f051/Src/phaseouts.c @@ -8,7 +8,6 @@ #include "targets.h" -extern char comp_pwm; extern char prop_brake_active; #ifndef PWM_ENABLE_BRIDGE @@ -60,7 +59,7 @@ void proportionalBrake() void phaseBPWM() { - if (!comp_pwm) { // for future + if (!eepromBuffer.comp_pwm) { // for future LL_GPIO_SetPinMode(PHASE_B_GPIO_PORT_LOW, PHASE_B_GPIO_LOW, LL_GPIO_MODE_OUTPUT); PHASE_B_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_B_GPIO_LOW; @@ -98,7 +97,7 @@ void phaseBLOW() void phaseCPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { LL_GPIO_SetPinMode(PHASE_C_GPIO_PORT_LOW, PHASE_C_GPIO_LOW, LL_GPIO_MODE_OUTPUT); PHASE_C_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_C_GPIO_LOW; @@ -136,7 +135,7 @@ void phaseCLOW() void phaseAPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { LL_GPIO_SetPinMode(PHASE_A_GPIO_PORT_LOW, PHASE_A_GPIO_LOW, LL_GPIO_MODE_OUTPUT); PHASE_A_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_A_GPIO_LOW; @@ -173,7 +172,7 @@ void phaseALOW() //////////////////////////////////PHASE 1////////////////////// void phaseBPWM() { - if (!comp_pwm) { // for future + if (!eepromBuffer.comp_pwm) { // for future // LL_GPIO_SetPinMode(PHASE_B_GPIO_PORT_LOW, // PHASE_B_GPIO_LOW, LL_GPIO_MODE_OUTPUT); // PHASE_B_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_B_GPIO_LOW; @@ -212,7 +211,7 @@ void phaseBLOW() void phaseCPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { // LL_GPIO_SetPinMode(PHASE_C_GPIO_PORT_LOW, PHASE_C_GPIO_LOW, // LL_GPIO_MODE_OUTPUT); PHASE_C_GPIO_PORT_LOW->LOW_BITREG_OFF = // PHASE_C_GPIO_LOW; @@ -251,7 +250,7 @@ void phaseCLOW() void phaseAPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { // LL_GPIO_SetPinMode(PHASE_A_GPIO_PORT_LOW, PHASE_A_GPIO_LOW, // LL_GPIO_MODE_OUTPUT); PHASE_A_GPIO_PORT_LOW->LOW_BITREG_OFF = // PHASE_A_GPIO_LOW; diff --git a/Mcu/f415/Inc/IO.h b/Mcu/f415/Inc/IO.h index bf20aacf6..352e164a9 100644 --- a/Mcu/f415/Inc/IO.h +++ b/Mcu/f415/Inc/IO.h @@ -24,7 +24,6 @@ void setInputPullUp(); void enableHalfTransferInt(); void setInputPullNone(); -extern char bi_direction; extern char inputSet; extern char dshot; extern char servoPwm; diff --git a/Mcu/f415/Inc/eeprom.h b/Mcu/f415/Inc/eeprom.h deleted file mode 100644 index 658a91297..000000000 --- a/Mcu/f415/Inc/eeprom.h +++ /dev/null @@ -1,7 +0,0 @@ -#include "main.h" - -// void save_to_flash(uint8_t *data); -// void read_flash(uint8_t* data, uint32_t address); -// void save_to_flash_bin(uint8_t *data, int length, uint32_t add); -void read_flash_bin(uint8_t* data, uint32_t add, int out_buff_len); -void save_flash_nolib(uint8_t* data, int length, uint32_t add); \ No newline at end of file diff --git a/Mcu/f415/Inc/phaseouts.h b/Mcu/f415/Inc/phaseouts.h index 37612388c..8f30ce902 100644 --- a/Mcu/f415/Inc/phaseouts.h +++ b/Mcu/f415/Inc/phaseouts.h @@ -9,6 +9,7 @@ #define INC_PHASEOUTS_H_ #include "main.h" +#include "common.h" void allOff(); void comStep(int newStep); diff --git a/Mcu/f415/Src/phaseouts.c b/Mcu/f415/Src/phaseouts.c index 92b454f84..ca8605ab5 100644 --- a/Mcu/f415/Src/phaseouts.c +++ b/Mcu/f415/Src/phaseouts.c @@ -9,7 +9,6 @@ #include "functions.h" #include "targets.h" -extern char comp_pwm; extern char prop_brake_active; #ifndef PWM_ENABLE_BRIDGE @@ -61,7 +60,7 @@ void proportionalBrake() } // void phaseCPWM() { -// if (!comp_pwm){ +// if (!eepromBuffer.comp_pwm){ // gpio_mode_QUICK(PHASE_C_GPIO_PORT_LOW, // GPIO_MODE_OUTPUT, // GPIO_PULL_NONE, PHASE_C_GPIO_LOW); @@ -88,7 +87,7 @@ void proportionalBrake() void phaseBPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { gpio_mode_QUICK(PHASE_B_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, GPIO_PULL_NONE, PHASE_B_GPIO_LOW); PHASE_B_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_B_GPIO_LOW; @@ -124,7 +123,7 @@ void phaseBLOW() void phaseCPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { gpio_mode_QUICK(PHASE_C_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, GPIO_PULL_NONE, PHASE_C_GPIO_LOW); PHASE_C_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_C_GPIO_LOW; @@ -163,7 +162,7 @@ void phaseCLOW() void phaseAPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { gpio_mode_QUICK(PHASE_A_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, GPIO_PULL_NONE, PHASE_A_GPIO_LOW); PHASE_A_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_A_GPIO_LOW; @@ -200,7 +199,7 @@ void phaseALOW() //////////////////////////////////PHASE 1////////////////////// void phaseBPWM() { - if (!comp_pwm) { // for future + if (!eepromBuffer.comp_pwm) { // for future // gpio_mode_QUICK(PHASE_B_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, // GPIO_PULL_NONE, PHASE_B_GPIO_LOW); // PHASE_B_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_B_GPIO_LOW; @@ -239,7 +238,7 @@ void phaseBLOW() void phaseCPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { // gpio_mode_QUICK(PHASE_C_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, // GPIO_PULL_NONE, // PHASE_C_GPIO_LOW); PHASE_C_GPIO_PORT_LOW->LOW_BITREG_OFF = @@ -279,7 +278,7 @@ void phaseCLOW() void phaseAPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { // gpio_mode_QUICK(PHASE_A_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, // GPIO_PULL_NONE, // PHASE_A_GPIO_LOW); PHASE_A_GPIO_PORT_LOW->LOW_BITREG_OFF = diff --git a/Mcu/f421/Am32.sct b/Mcu/f421/Am32.sct index fafa719fd..ef85ebb7c 100644 --- a/Mcu/f421/Am32.sct +++ b/Mcu/f421/Am32.sct @@ -2,8 +2,8 @@ ; *** Scatter-Loading Description File generated by uVision *** ; ************************************************************* -LR_IROM1 0x08001000 0x0000FFFF { ; load region size_region - ER_IROM1 0x08001000 0x0000FFFF { ; load address = execution address +LR_IROM1 0x08001000 0x00007BDF { ; load region size_region + ER_IROM1 0x08001000 0x00007BDF { ; load address = execution address *.o (RESET, +First) *(InRoot$$Sections) .ANY (+RO) @@ -15,6 +15,6 @@ LR_IROM1 0x08001000 0x0000FFFF { ; load region size_region } LR_FIRMWAREVERSION 0x08007BE0 0x00000020{ FIRMWAREVERSION 0x08007BE0 0x00000020{ - firmwareversion.o (+RO) + firmwareversion.o (+RO) } } diff --git a/Mcu/f421/Inc/IO.h b/Mcu/f421/Inc/IO.h index bf20aacf6..352e164a9 100644 --- a/Mcu/f421/Inc/IO.h +++ b/Mcu/f421/Inc/IO.h @@ -24,7 +24,6 @@ void setInputPullUp(); void enableHalfTransferInt(); void setInputPullNone(); -extern char bi_direction; extern char inputSet; extern char dshot; extern char servoPwm; diff --git a/Mcu/f421/Inc/eeprom.h b/Mcu/f421/Inc/eeprom.h deleted file mode 100644 index 658a91297..000000000 --- a/Mcu/f421/Inc/eeprom.h +++ /dev/null @@ -1,7 +0,0 @@ -#include "main.h" - -// void save_to_flash(uint8_t *data); -// void read_flash(uint8_t* data, uint32_t address); -// void save_to_flash_bin(uint8_t *data, int length, uint32_t add); -void read_flash_bin(uint8_t* data, uint32_t add, int out_buff_len); -void save_flash_nolib(uint8_t* data, int length, uint32_t add); \ No newline at end of file diff --git a/Mcu/f421/Inc/phaseouts.h b/Mcu/f421/Inc/phaseouts.h index 37612388c..8f30ce902 100644 --- a/Mcu/f421/Inc/phaseouts.h +++ b/Mcu/f421/Inc/phaseouts.h @@ -9,6 +9,7 @@ #define INC_PHASEOUTS_H_ #include "main.h" +#include "common.h" void allOff(); void comStep(int newStep); diff --git a/Mcu/f421/Src/phaseouts.c b/Mcu/f421/Src/phaseouts.c index ece742261..9f2eb521e 100644 --- a/Mcu/f421/Src/phaseouts.c +++ b/Mcu/f421/Src/phaseouts.c @@ -9,7 +9,6 @@ #include "functions.h" #include "targets.h" -extern char comp_pwm; extern char prop_brake_active; #ifndef PWM_ENABLE_BRIDGE @@ -61,7 +60,7 @@ void proportionalBrake() } // void phaseCPWM() { -// if (!comp_pwm){ +// if (!eepromBuffer.comp_pwm){ // gpio_mode_QUICK(PHASE_C_GPIO_PORT_LOW, // GPIO_MODE_OUTPUT, // GPIO_PULL_NONE, PHASE_C_GPIO_LOW); @@ -88,7 +87,7 @@ void proportionalBrake() void phaseBPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { gpio_mode_QUICK(PHASE_B_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, GPIO_PULL_NONE, PHASE_B_GPIO_LOW); PHASE_B_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_B_GPIO_LOW; @@ -124,7 +123,7 @@ void phaseBLOW() void phaseCPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { gpio_mode_QUICK(PHASE_C_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, GPIO_PULL_NONE, PHASE_C_GPIO_LOW); PHASE_C_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_C_GPIO_LOW; @@ -163,7 +162,7 @@ void phaseCLOW() void phaseAPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { gpio_mode_QUICK(PHASE_A_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, GPIO_PULL_NONE, PHASE_A_GPIO_LOW); PHASE_A_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_A_GPIO_LOW; @@ -200,7 +199,7 @@ void phaseALOW() //////////////////////////////////PHASE 1////////////////////// void phaseBPWM() { - if (!comp_pwm) { // for future + if (!eepromBuffer.comp_pwm) { // for future // gpio_mode_QUICK(PHASE_B_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, // GPIO_PULL_NONE, PHASE_B_GPIO_LOW); // PHASE_B_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_B_GPIO_LOW; @@ -239,7 +238,7 @@ void phaseBLOW() void phaseCPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { // gpio_mode_QUICK(PHASE_C_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, // GPIO_PULL_NONE, // PHASE_C_GPIO_LOW); PHASE_C_GPIO_PORT_LOW->LOW_BITREG_OFF = @@ -279,7 +278,7 @@ void phaseCLOW() void phaseAPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { // gpio_mode_QUICK(PHASE_A_GPIO_PORT_LOW, GPIO_MODE_OUTPUT, // GPIO_PULL_NONE, // PHASE_A_GPIO_LOW); PHASE_A_GPIO_PORT_LOW->LOW_BITREG_OFF = diff --git a/Mcu/g071/Inc/eeprom.h b/Mcu/g071/Inc/eeprom.h deleted file mode 100644 index 8e3304981..000000000 --- a/Mcu/g071/Inc/eeprom.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * bootloader.h - * - * Created on: Mar. 25, 2020 - * Author: Alka - */ -#include "main.h" -#ifndef INC_EEPROM_H_ -#define INC_EEPROM_H_ - -#endif /* INC_BOOTLOADER_H_ */ - -// void save_to_flash(uint8_t *data); -// void read_flash(uint8_t* data, uint32_t address); -// void save_to_flash_bin(uint8_t *data, int length, uint32_t add); -void read_flash_bin(uint8_t* data, uint32_t add, int out_buff_len); -void save_flash_nolib(uint8_t* data, int length, uint32_t add); diff --git a/Mcu/g071/Inc/phaseouts.h b/Mcu/g071/Inc/phaseouts.h index 37612388c..8f30ce902 100644 --- a/Mcu/g071/Inc/phaseouts.h +++ b/Mcu/g071/Inc/phaseouts.h @@ -9,6 +9,7 @@ #define INC_PHASEOUTS_H_ #include "main.h" +#include "common.h" void allOff(); void comStep(int newStep); diff --git a/Mcu/g071/Src/phaseouts.c b/Mcu/g071/Src/phaseouts.c index 0dde9f263..fdcf49e04 100644 --- a/Mcu/g071/Src/phaseouts.c +++ b/Mcu/g071/Src/phaseouts.c @@ -8,7 +8,6 @@ #include "targets.h" -extern char comp_pwm; extern char prop_brake_active; #ifndef PWM_ENABLE_BRIDGE @@ -61,7 +60,7 @@ void proportionalBrake() void phaseBPWM() { - if (!comp_pwm) { // for future + if (!eepromBuffer.comp_pwm) { // for future LL_GPIO_SetPinMode(PHASE_B_GPIO_PORT_LOW, PHASE_B_GPIO_LOW, LL_GPIO_MODE_OUTPUT); PHASE_B_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_B_GPIO_LOW; @@ -99,7 +98,7 @@ void phaseBLOW() void phaseCPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { LL_GPIO_SetPinMode(PHASE_C_GPIO_PORT_LOW, PHASE_C_GPIO_LOW, LL_GPIO_MODE_OUTPUT); PHASE_C_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_C_GPIO_LOW; @@ -137,7 +136,7 @@ void phaseCLOW() void phaseAPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { LL_GPIO_SetPinMode(PHASE_A_GPIO_PORT_LOW, PHASE_A_GPIO_LOW, LL_GPIO_MODE_OUTPUT); PHASE_A_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_A_GPIO_LOW; @@ -174,7 +173,7 @@ void phaseALOW() //////////////////////////////////PHASE 1////////////////////// void phaseBPWM() { - if (!comp_pwm) { // for future + if (!eepromBuffer.comp_pwm) { // for future // LL_GPIO_SetPinMode(PHASE_B_GPIO_PORT_LOW, // PHASE_B_GPIO_LOW, LL_GPIO_MODE_OUTPUT); // PHASE_B_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_B_GPIO_LOW; @@ -213,7 +212,7 @@ void phaseBLOW() void phaseCPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { // LL_GPIO_SetPinMode(PHASE_C_GPIO_PORT_LOW, PHASE_C_GPIO_LOW, // LL_GPIO_MODE_OUTPUT); PHASE_C_GPIO_PORT_LOW->LOW_BITREG_OFF = // PHASE_C_GPIO_LOW; @@ -252,7 +251,7 @@ void phaseCLOW() void phaseAPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { // LL_GPIO_SetPinMode(PHASE_A_GPIO_PORT_LOW, PHASE_A_GPIO_LOW, // LL_GPIO_MODE_OUTPUT); PHASE_A_GPIO_PORT_LOW->LOW_BITREG_OFF = // PHASE_A_GPIO_LOW; diff --git a/Mcu/g431/Inc/eeprom.h b/Mcu/g431/Inc/eeprom.h deleted file mode 100644 index 8e3304981..000000000 --- a/Mcu/g431/Inc/eeprom.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * bootloader.h - * - * Created on: Mar. 25, 2020 - * Author: Alka - */ -#include "main.h" -#ifndef INC_EEPROM_H_ -#define INC_EEPROM_H_ - -#endif /* INC_BOOTLOADER_H_ */ - -// void save_to_flash(uint8_t *data); -// void read_flash(uint8_t* data, uint32_t address); -// void save_to_flash_bin(uint8_t *data, int length, uint32_t add); -void read_flash_bin(uint8_t* data, uint32_t add, int out_buff_len); -void save_flash_nolib(uint8_t* data, int length, uint32_t add); diff --git a/Mcu/g431/Inc/phaseouts.h b/Mcu/g431/Inc/phaseouts.h index 37612388c..8f30ce902 100644 --- a/Mcu/g431/Inc/phaseouts.h +++ b/Mcu/g431/Inc/phaseouts.h @@ -9,6 +9,7 @@ #define INC_PHASEOUTS_H_ #include "main.h" +#include "common.h" void allOff(); void comStep(int newStep); diff --git a/Mcu/g431/Src/phaseouts.c b/Mcu/g431/Src/phaseouts.c index b930f438b..3b93047b5 100644 --- a/Mcu/g431/Src/phaseouts.c +++ b/Mcu/g431/Src/phaseouts.c @@ -8,7 +8,6 @@ #include "targets.h" -extern char comp_pwm; extern char prop_brake_active; #ifndef PWM_ENABLE_BRIDGE @@ -61,7 +60,7 @@ void proportionalBrake() void phaseBPWM() { - if (!comp_pwm) { // for future + if (!eepromBuffer.comp_pwm) { // for future LL_GPIO_SetPinMode(PHASE_B_GPIO_PORT_LOW, PHASE_B_GPIO_LOW, LL_GPIO_MODE_OUTPUT); PHASE_B_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_B_GPIO_LOW; @@ -99,7 +98,7 @@ void phaseBLOW() void phaseCPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { LL_GPIO_SetPinMode(PHASE_C_GPIO_PORT_LOW, PHASE_C_GPIO_LOW, LL_GPIO_MODE_OUTPUT); PHASE_C_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_C_GPIO_LOW; @@ -137,7 +136,7 @@ void phaseCLOW() void phaseAPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { LL_GPIO_SetPinMode(PHASE_A_GPIO_PORT_LOW, PHASE_A_GPIO_LOW, LL_GPIO_MODE_OUTPUT); PHASE_A_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_A_GPIO_LOW; @@ -174,7 +173,7 @@ void phaseALOW() //////////////////////////////////PHASE 1////////////////////// void phaseBPWM() { - if (!comp_pwm) { // for future + if (!eepromBuffer.comp_pwm) { // for future // LL_GPIO_SetPinMode(PHASE_B_GPIO_PORT_LOW, // PHASE_B_GPIO_LOW, LL_GPIO_MODE_OUTPUT); // PHASE_B_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_B_GPIO_LOW; @@ -213,7 +212,7 @@ void phaseBLOW() void phaseCPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { // LL_GPIO_SetPinMode(PHASE_C_GPIO_PORT_LOW, PHASE_C_GPIO_LOW, // LL_GPIO_MODE_OUTPUT); PHASE_C_GPIO_PORT_LOW->LOW_BITREG_OFF = // PHASE_C_GPIO_LOW; @@ -252,7 +251,7 @@ void phaseCLOW() void phaseAPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { // LL_GPIO_SetPinMode(PHASE_A_GPIO_PORT_LOW, PHASE_A_GPIO_LOW, // LL_GPIO_MODE_OUTPUT); PHASE_A_GPIO_PORT_LOW->LOW_BITREG_OFF = // PHASE_A_GPIO_LOW; diff --git a/Mcu/l431/Inc/IO.h b/Mcu/l431/Inc/IO.h index 755f6a051..8b1d7459e 100644 --- a/Mcu/l431/Inc/IO.h +++ b/Mcu/l431/Inc/IO.h @@ -24,8 +24,6 @@ void setInputPullUp(); void enableHalfTransferInt(); void setInputPullNone(); -extern char bi_direction; - extern char send_telemetry; extern uint8_t degrees_celsius; diff --git a/Mcu/l431/Inc/eeprom.h b/Mcu/l431/Inc/eeprom.h deleted file mode 100644 index 8e3304981..000000000 --- a/Mcu/l431/Inc/eeprom.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * bootloader.h - * - * Created on: Mar. 25, 2020 - * Author: Alka - */ -#include "main.h" -#ifndef INC_EEPROM_H_ -#define INC_EEPROM_H_ - -#endif /* INC_BOOTLOADER_H_ */ - -// void save_to_flash(uint8_t *data); -// void read_flash(uint8_t* data, uint32_t address); -// void save_to_flash_bin(uint8_t *data, int length, uint32_t add); -void read_flash_bin(uint8_t* data, uint32_t add, int out_buff_len); -void save_flash_nolib(uint8_t* data, int length, uint32_t add); diff --git a/Mcu/l431/Inc/phaseouts.h b/Mcu/l431/Inc/phaseouts.h index c66c8940e..8a2167a6a 100644 --- a/Mcu/l431/Inc/phaseouts.h +++ b/Mcu/l431/Inc/phaseouts.h @@ -9,6 +9,7 @@ #define INC_PHASEOUTS_H_ #include "main.h" +#include "common.h" void allOff(); void comStep(char newStep); diff --git a/Mcu/l431/Src/phaseouts.c b/Mcu/l431/Src/phaseouts.c index 77f20842f..eedd2d8e3 100644 --- a/Mcu/l431/Src/phaseouts.c +++ b/Mcu/l431/Src/phaseouts.c @@ -8,7 +8,6 @@ #include "targets.h" -extern char comp_pwm; extern char prop_brake_active; #ifndef PWM_ENABLE_BRIDGE @@ -60,7 +59,7 @@ void proportionalBrake() void phaseBPWM() { - if (!comp_pwm) { // for future + if (!eepromBuffer.comp_pwm) { // for future LL_GPIO_SetPinMode(PHASE_B_GPIO_PORT_LOW, PHASE_B_GPIO_LOW, LL_GPIO_MODE_OUTPUT); PHASE_B_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_B_GPIO_LOW; @@ -98,7 +97,7 @@ void phaseBLOW() void phaseCPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { LL_GPIO_SetPinMode(PHASE_C_GPIO_PORT_LOW, PHASE_C_GPIO_LOW, LL_GPIO_MODE_OUTPUT); PHASE_C_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_C_GPIO_LOW; @@ -136,7 +135,7 @@ void phaseCLOW() void phaseAPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { LL_GPIO_SetPinMode(PHASE_A_GPIO_PORT_LOW, PHASE_A_GPIO_LOW, LL_GPIO_MODE_OUTPUT); PHASE_A_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_A_GPIO_LOW; @@ -173,7 +172,7 @@ void phaseALOW() //////////////////////////////////PHASE 1////////////////////// void phaseBPWM() { - if (!comp_pwm) { // for future + if (!eepromBuffer.comp_pwm) { // for future // LL_GPIO_SetPinMode(PHASE_B_GPIO_PORT_LOW, // PHASE_B_GPIO_LOW, LL_GPIO_MODE_OUTPUT); // PHASE_B_GPIO_PORT_LOW->LOW_BITREG_OFF = PHASE_B_GPIO_LOW; @@ -212,7 +211,7 @@ void phaseBLOW() void phaseCPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { // LL_GPIO_SetPinMode(PHASE_C_GPIO_PORT_LOW, PHASE_C_GPIO_LOW, // LL_GPIO_MODE_OUTPUT); PHASE_C_GPIO_PORT_LOW->LOW_BITREG_OFF = // PHASE_C_GPIO_LOW; @@ -251,7 +250,7 @@ void phaseCLOW() void phaseAPWM() { - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { // LL_GPIO_SetPinMode(PHASE_A_GPIO_PORT_LOW, PHASE_A_GPIO_LOW, // LL_GPIO_MODE_OUTPUT); PHASE_A_GPIO_PORT_LOW->LOW_BITREG_OFF = // PHASE_A_GPIO_LOW; diff --git a/Src/dshot.c b/Src/dshot.c index 218b5ba50..0a3562ae8 100644 --- a/Src/dshot.c +++ b/Src/dshot.c @@ -129,24 +129,24 @@ void computeDshotDMA() play_tone_flag = 5; break; case 7: - dir_reversed = 0; - forward = 1 - dir_reversed; + eepromBuffer.dir_reversed = 0; + forward = 1 - eepromBuffer.dir_reversed; // play_tone_flag = 1; break; case 8: - dir_reversed = 1; - forward = 1 - dir_reversed; + eepromBuffer.dir_reversed = 1; + forward = 1 - eepromBuffer.dir_reversed; // play_tone_flag = 2; break; case 9: - bi_direction = 0; + eepromBuffer.bi_direction = 0; break; case 10: - bi_direction = 1; + eepromBuffer.bi_direction = 1; break; case 12: saveEEpromSettings(); - play_tone_flag = 1 + dir_reversed; + play_tone_flag = 1 + eepromBuffer.dir_reversed; // NVIC_SystemReset(); break; case 13: @@ -162,10 +162,10 @@ void computeDshotDMA() // make_dshot_package(); break; case 20: - forward = 1 - dir_reversed; + forward = 1 - eepromBuffer.dir_reversed; break; case 21: - forward = dir_reversed; + forward = eepromBuffer.dir_reversed; break; } last_dshot_command = dshotcommand; diff --git a/Src/main.c b/Src/main.c index 62dfeacae..feca278a3 100644 --- a/Src/main.c +++ b/Src/main.c @@ -304,7 +304,7 @@ enum inputType { EDTARM, }; - +EEprom_t eepromBuffer; uint32_t eeprom_address = EEPROM_START_ADD; char set_hysteris = 0; uint16_t prop_brake_duty_cycle = 0; @@ -317,34 +317,15 @@ uint16_t target_e_com_time_low; uint8_t compute_dshot_flag = 0; uint8_t crsf_input_channel = 1; uint8_t crsf_output_PWM_channel = 2; -char eeprom_layout_version = 2; -char dir_reversed = 0; -char comp_pwm = 1; -char VARIABLE_PWM = 1; -char bi_direction = 0; -char stuck_rotor_protection = 1; // Turn off for Crawlers -char brake_on_stop = 0; -char stall_protection = 0; -char use_sin_start = 0; -char TLM_ON_INTERVAL = 0; +char eeprom_layout_version = EEPROM_VERSION; uint8_t telemetry_interval_ms = 30; -uint8_t TEMPERATURE_LIMIT = 255; // degrees 255 to disable -char advance_level = 2; // 7.5 degree increments 0 , 7.5, 15, 22.5) char temp_advance = 1; uint16_t motor_kv = 2000; -char motor_poles = 14; -uint16_t CURRENT_LIMIT = 202; -uint8_t sine_mode_power = 5; -char drag_brake_strength = 10; // Drag Brake Power when brake on stop is enabled -uint8_t driving_brake_strength = 10; uint8_t dead_time_override = DEAD_TIME; -char sine_mode_changeover_thottle_level = 5; // Sine Startup Range uint16_t stall_protect_target_interval = TARGET_STALL_PROTECTION_INTERVAL; -char USE_HALL_SENSOR = 0; uint16_t enter_sine_angle = 180; char do_once_sinemode = 0; uint8_t auto_advance_level; -char auto_advance = 0; //============================= Servo Settings ============================== uint16_t servo_low_threshold = 1100; // anything below this point considered 0 @@ -361,10 +342,7 @@ uint16_t low_cell_volt_cutoff = 330; // 3.3volts per cell const char filename[30] __attribute__((section(".file_name"))) = FILE_NAME; _Static_assert(sizeof(FIRMWARE_NAME) <=13,"Firmware name too long"); // max 12 character firmware name plus NULL -uint8_t EEPROM_VERSION; // move these to targets folder or peripherals for each mcu -char RC_CAR_REVERSE = 0; // have to set bidirectional, comp_pwm off and stall - // protection off, no sinusoidal startup uint16_t ADC_CCR = 30; uint16_t current_angle = 90; uint16_t desired_angle = 90; @@ -458,8 +436,6 @@ char send_telemetry = 0; char telemetry_done = 0; char prop_brake_active = 0; -uint8_t eepromBuffer[176] = { 0 }; - char dshot_telemetry = 0; uint8_t last_dshot_command = 0; @@ -630,52 +606,22 @@ float doPidCalculations(struct fastPID* pidnow, int actual, int target) void loadEEpromSettings() { - read_flash_bin(eepromBuffer, eeprom_address, 176); + //*eepromBuffer = *(EEprom_t*)(eeprom_address); + read_flash_bin(eepromBuffer.buffer, eeprom_address, sizeof(eepromBuffer.buffer)); - if (eepromBuffer[17] == 0x01) { - dir_reversed = 1; - } else { - dir_reversed = 0; - } - if (eepromBuffer[18] == 0x01) { - bi_direction = 1; - } else { - bi_direction = 0; - } - if (eepromBuffer[19] == 0x01) { - use_sin_start = 1; - // min_startup_duty = sin_mode_min_s_d; - } - if (eepromBuffer[20] == 0x01) { - comp_pwm = 1; - } else { - comp_pwm = 0; - } - if (eepromBuffer[21] == 0x01) { - VARIABLE_PWM = 1; - } else { - VARIABLE_PWM = 0; - } - if (eepromBuffer[22] == 0x01) { - stuck_rotor_protection = 1; - } else { - stuck_rotor_protection = 0; - } - if (eepromBuffer[23] < 4) { - advance_level = eepromBuffer[23]; - } else { - advance_level = 2; // * 7.5 increments + if (eepromBuffer.advance_level > 3) { + eepromBuffer.advance_level = 2; } - if (eepromBuffer[24] < 49 && eepromBuffer[24] > 7) { - if (eepromBuffer[24] < 49 && eepromBuffer[24] > 23) { - TIMER1_MAX_ARR = map(eepromBuffer[24], 24, 48, TIM1_AUTORELOAD, TIM1_AUTORELOAD / 2); + if (eepromBuffer.pwm_frequency < 49 && eepromBuffer.pwm_frequency > 7) { + if (eepromBuffer.pwm_frequency < 49 && eepromBuffer.pwm_frequency > 23) { + TIMER1_MAX_ARR = map(eepromBuffer.pwm_frequency, 24, 48, TIM1_AUTORELOAD, TIM1_AUTORELOAD / 2); } - if (eepromBuffer[24] < 24 && eepromBuffer[24] > 11) { - TIMER1_MAX_ARR = map(eepromBuffer[24], 12, 24, TIM1_AUTORELOAD * 2, TIM1_AUTORELOAD); + if (eepromBuffer.pwm_frequency < 24 && eepromBuffer.pwm_frequency > 11) { + TIMER1_MAX_ARR = map(eepromBuffer.pwm_frequency, 12, 24, TIM1_AUTORELOAD * 2, TIM1_AUTORELOAD); } - if (eepromBuffer[24] < 12 && eepromBuffer[24] > 7) { - TIMER1_MAX_ARR = map(eepromBuffer[24], 7, 16, TIM1_AUTORELOAD * 3, + if (eepromBuffer.pwm_frequency < 12 && eepromBuffer.pwm_frequency > 7) { + TIMER1_MAX_ARR = map(eepromBuffer.pwm_frequency, 7, 16, TIM1_AUTORELOAD * 3, TIM1_AUTORELOAD / 2 * 3); } SET_AUTO_RELOAD_PWM(TIMER1_MAX_ARR); @@ -686,114 +632,90 @@ void loadEEpromSettings() SET_AUTO_RELOAD_PWM(tim1_arr); } - if (eepromBuffer[25] < 151 && eepromBuffer[25] > 49) { - min_startup_duty = (eepromBuffer[25]); - minimum_duty_cycle = (eepromBuffer[25] / 3); + if (eepromBuffer.startup_power < 151 && eepromBuffer.startup_power > 49) { + min_startup_duty = (eepromBuffer.startup_power); + minimum_duty_cycle = (eepromBuffer.startup_power / 3); stall_protect_minimum_duty = minimum_duty_cycle + 10; } else { min_startup_duty = 150; minimum_duty_cycle = (min_startup_duty / 2) + 10; } - motor_kv = (eepromBuffer[26] * 40) + 20; + motor_kv = (eepromBuffer.motor_kv * 40) + 20; #ifdef THREE_CELL_MAX motor_kv = motor_kv / 2; #endif - motor_poles = eepromBuffer[27]; - if (eepromBuffer[28] == 0x01) { - brake_on_stop = 1; - } else { - brake_on_stop = 0; - } - if (eepromBuffer[29] == 0x01) { - stall_protection = 1; - } else { - stall_protection = 0; - } setVolume(2); - if (eepromBuffer[1] > 0) { // these commands weren't introduced until eeprom version 1. + if (eepromBuffer.eeprom_version > 0) { // these commands weren't introduced until eeprom version 1. #ifdef CUSTOM_RAMP #else - if (eepromBuffer[30] > 11) { + if (eepromBuffer.beep_volume > 11) { setVolume(5); } else { - setVolume(eepromBuffer[30]); + setVolume(eepromBuffer.beep_volume); } #endif - if (eepromBuffer[31] == 0x01) { - TLM_ON_INTERVAL = 1; - } else { - TLM_ON_INTERVAL = 0; - } - servo_low_threshold = (eepromBuffer[32] * 2) + 750; // anything below this point considered 0 - servo_high_threshold = (eepromBuffer[33] * 2) + 1750; + servo_low_threshold = (eepromBuffer.servo.low_threshold * 2) + 750; // anything below this point considered 0 + servo_high_threshold = (eepromBuffer.servo.high_threshold * 2) + 1750; ; // anything above this point considered 2000 (max) - servo_neutral = (eepromBuffer[34]) + 1374; - servo_dead_band = eepromBuffer[35]; + servo_neutral = (eepromBuffer.servo.neutral) + 1374; + servo_dead_band = eepromBuffer.servo.dead_band; - if (eepromBuffer[36] == 0x01) { + if (eepromBuffer.low_voltage_cut_off == 0x01) { LOW_VOLTAGE_CUTOFF = 1; } else { LOW_VOLTAGE_CUTOFF = 0; } - low_cell_volt_cutoff = eepromBuffer[37] + 250; // 2.5 to 3.5 volts per cell range - if (eepromBuffer[38] == 0x01) { - RC_CAR_REVERSE = 1; - } else { - RC_CAR_REVERSE = 0; - } - if (eepromBuffer[39] == 0x01) { -#ifdef HAS_HALL_SENSORS - USE_HALL_SENSOR = 1; -#else - USE_HALL_SENSOR = 0; + low_cell_volt_cutoff = eepromBuffer.low_cell_volt_cutoff + 250; // 2.5 to 3.5 volts per cell range + +#ifndef HAS_HALL_SENSORS + eepromBuffer.use_hall_sensors = 0; #endif - } else { - USE_HALL_SENSOR = 0; + + if (eepromBuffer.sine_mode_changeover_thottle_level < 5 || eepromBuffer.sine_mode_changeover_thottle_level > 25) { // sine mode changeover 5-25 percent throttle + eepromBuffer.sine_mode_changeover_thottle_level = 5; } - if (eepromBuffer[40] > 4 && eepromBuffer[40] < 26) { // sine mode changeover 5-25 percent throttle - sine_mode_changeover_thottle_level = eepromBuffer[40]; + if (eepromBuffer.drag_brake_strength == 0 || eepromBuffer.drag_brake_strength > 10) { // drag brake 1-10 + eepromBuffer.drag_brake_strength = 10; } - if (eepromBuffer[41] > 0 && eepromBuffer[41] < 11) { // drag brake 1-10 - drag_brake_strength = eepromBuffer[41]; + + if (eepromBuffer.driving_brake_strength == 0 || eepromBuffer.driving_brake_strength > 9) { // motor brake 1-9 + eepromBuffer.driving_brake_strength = 10; } - if (eepromBuffer[42] > 0 && eepromBuffer[42] < 10) { // motor brake 1-9 - driving_brake_strength = eepromBuffer[42]; - dead_time_override = DEAD_TIME + (150 - (driving_brake_strength * 10)); - if (dead_time_override > 200) { - dead_time_override = 200; - } - min_startup_duty = eepromBuffer[25] + dead_time_override; - minimum_duty_cycle = eepromBuffer[25] / 2 + dead_time_override; - throttle_max_at_low_rpm = throttle_max_at_low_rpm + dead_time_override; - startup_max_duty_cycle = startup_max_duty_cycle + dead_time_override; + dead_time_override = DEAD_TIME + (150 - (eepromBuffer.driving_brake_strength * 10)); + if (dead_time_override > 200) { + dead_time_override = 200; + } + min_startup_duty = eepromBuffer.startup_power + dead_time_override; + minimum_duty_cycle = eepromBuffer.startup_power / 2 + dead_time_override; + throttle_max_at_low_rpm = throttle_max_at_low_rpm + dead_time_override; + startup_max_duty_cycle = startup_max_duty_cycle + dead_time_override; #ifdef STMICRO - TIM1->BDTR |= dead_time_override; + TIM1->BDTR |= dead_time_override; #endif #ifdef ARTERY - TMR1->brk |= dead_time_override; + TMR1->brk |= dead_time_override; #endif #ifdef GIGADEVICES - TIMER_CCHP(TIMER0) |= dead_time_override; + TIMER_CCHP(TIMER0) |= dead_time_override; #endif - } - if (eepromBuffer[43] >= 70 && eepromBuffer[43] <= 140) { - TEMPERATURE_LIMIT = eepromBuffer[43]; + if (eepromBuffer.limits.temperature < 70 || eepromBuffer.limits.temperature > 140) { + eepromBuffer.limits.temperature = 255; } - if (eepromBuffer[44] > 0 && eepromBuffer[44] < 100) { - CURRENT_LIMIT = eepromBuffer[44] * 2; + if (eepromBuffer.limits.current > 0 && eepromBuffer.limits.current < 100) { use_current_limit = 1; } - if (eepromBuffer[45] > 0 && eepromBuffer[45] < 11) { - sine_mode_power = eepromBuffer[45]; + + if (eepromBuffer.sine_mode_power == 0 || eepromBuffer.sine_mode_power > 10) { + eepromBuffer.sine_mode_power = 5; } - if (eepromBuffer[46] < 10) { - switch (eepromBuffer[46]) { + if (eepromBuffer.input_type >= 0 && eepromBuffer.input_type < 10) { + switch (eepromBuffer.input_type) { case AUTO_IN: dshot = 0; servoPwm = 0; @@ -819,62 +741,26 @@ void loadEEpromSettings() servoPwm = 0; EDT_ARMED = 1; } - if (eepromBuffer[47] == 0x01) { - auto_advance = 1; - } else { - auto_advance = 0; - } if (motor_kv < 300) { low_rpm_throttle_limit = 0; } - low_rpm_level = motor_kv / 100 / (32 / motor_poles); + low_rpm_level = motor_kv / 100 / (32 / eepromBuffer.motor_poles); - high_rpm_level = motor_kv / 12 / (32 / motor_poles); + high_rpm_level = motor_kv / 12 / (32 / eepromBuffer.motor_poles); } reverse_speed_threshold = map(motor_kv, 300, 3000, 1000, 500); // reverse_speed_threshold = 200; -// if (!comp_pwm) { -// bi_direction = 0; +// if (!eepromBuffer.comp_pwm) { +// eepromBuffer.bi_direction = 0; // } } void saveEEpromSettings() { - eepromBuffer[1] = eeprom_layout_version; - if (dir_reversed == 1) { - eepromBuffer[17] = 0x01; - } else { - eepromBuffer[17] = 0x00; - } - if (bi_direction == 1) { - eepromBuffer[18] = 0x01; - } else { - eepromBuffer[18] = 0x00; - } - if (use_sin_start == 1) { - eepromBuffer[19] = 0x01; - } else { - eepromBuffer[19] = 0x00; - } + eepromBuffer.eeprom_version = eeprom_layout_version; - if (comp_pwm == 1) { - eepromBuffer[20] = 0x01; - } else { - eepromBuffer[20] = 0x00; - } - if (VARIABLE_PWM == 1) { - eepromBuffer[21] = 0x01; - } else { - eepromBuffer[21] = 0x00; - } - if (stuck_rotor_protection == 1) { - eepromBuffer[22] = 0x01; - } else { - eepromBuffer[22] = 0x00; - } - eepromBuffer[23] = advance_level; - save_flash_nolib(eepromBuffer, 176, eeprom_address); + save_flash_nolib(eepromBuffer.buffer, sizeof(eepromBuffer.buffer), eeprom_address); } uint16_t getSmoothedCurrent() @@ -969,12 +855,12 @@ void PeriodElapsedCallback() { DISABLE_COM_TIMER_INT(); // disable interrupt commutate(); - commutation_interval = (3*commutation_interval + thiszctime) >> 2; - if(!auto_advance){ + commutation_interval = (3 * commutation_interval + thiszctime) >> 2; + if (!eepromBuffer.auto_advance) { advance = (commutation_interval >> 3) * temp_advance; // 60 divde 8 7.5 degree increments - }else{ + } else { advance = (commutation_interval * auto_advance_level) >> 6; // 60 divde 64 0.9375 degree increments - } + } waitTime = (commutation_interval >> 1) - advance; if (!old_routine) { enableCompInterrupts(); // enable comp interrupt @@ -1042,16 +928,16 @@ void startMotor() void setInput() { - if (bi_direction) { + if (eepromBuffer.bi_direction) { if (dshot == 0) { - if (RC_CAR_REVERSE) { + if (eepromBuffer.rc_car_reverse) { if (newinput > (1000 + (servo_dead_band << 1))) { - if (forward == dir_reversed) { + if (forward == eepromBuffer.dir_reversed) { adjusted_input = 0; // if (running) { prop_brake_active = 1; if (return_to_center) { - forward = 1 - dir_reversed; + forward = 1 - eepromBuffer.dir_reversed; prop_brake_active = 0; return_to_center = 0; } @@ -1062,11 +948,11 @@ void setInput() } } if (newinput < (1000 - (servo_dead_band << 1))) { - if (forward == (1 - dir_reversed)) { + if (forward == (1 - eepromBuffer.dir_reversed)) { adjusted_input = 0; prop_brake_active = 1; if (return_to_center) { - forward = dir_reversed; + forward = eepromBuffer.dir_reversed; prop_brake_active = 0; return_to_center = 0; } @@ -1085,9 +971,9 @@ void setInput() } } else { if (newinput > (1000 + (servo_dead_band << 1))) { - if (forward == dir_reversed) { + if (forward == eepromBuffer.dir_reversed) { if (((commutation_interval > reverse_speed_threshold) && (duty_cycle < 200)) || stepper_sine) { - forward = 1 - dir_reversed; + forward = 1 - eepromBuffer.dir_reversed; zero_crosses = 0; old_routine = 1; maskPhaseInterrupts(); @@ -1099,11 +985,11 @@ void setInput() adjusted_input = map(newinput, 1000 + (servo_dead_band << 1), 2000, 47, 2047); } if (newinput < (1000 - (servo_dead_band << 1))) { - if (forward == (1 - dir_reversed)) { + if (forward == (1 - eepromBuffer.dir_reversed)) { if (((commutation_interval > reverse_speed_threshold) && (duty_cycle < 200)) || stepper_sine) { zero_crosses = 0; old_routine = 1; - forward = dir_reversed; + forward = eepromBuffer.dir_reversed; maskPhaseInterrupts(); brushed_direction_set = 0; } else { @@ -1123,9 +1009,9 @@ void setInput() if (dshot) { if (newinput > 1047) { - if (forward == dir_reversed) { + if (forward == eepromBuffer.dir_reversed) { if (((commutation_interval > reverse_speed_threshold) && (duty_cycle < 200)) || stepper_sine) { - forward = 1 - dir_reversed; + forward = 1 - eepromBuffer.dir_reversed; zero_crosses = 0; old_routine = 1; maskPhaseInterrupts(); @@ -1137,11 +1023,11 @@ void setInput() adjusted_input = ((newinput - 1048) * 2 + 47) - reversing_dead_band; } if (newinput <= 1047 && newinput > 47) { - if (forward == (1 - dir_reversed)) { + if (forward == (1 - eepromBuffer.dir_reversed)) { if (((commutation_interval > reverse_speed_threshold) && (duty_cycle < 200)) || stepper_sine) { zero_crosses = 0; old_routine = 1; - forward = dir_reversed; + forward = eepromBuffer.dir_reversed; maskPhaseInterrupts(); brushed_direction_set = 0; } else { @@ -1159,7 +1045,7 @@ void setInput() adjusted_input = newinput; } #ifndef BRUSHED_MODE - if ((bemf_timeout_happened > bemf_timeout) && stuck_rotor_protection) { + if ((bemf_timeout_happened > bemf_timeout) && eepromBuffer.stuck_rotor_protection) { allOff(); maskPhaseInterrupts(); input = 0; @@ -1173,22 +1059,22 @@ void setInput() #ifdef FIXED_DUTY_MODE input = FIXED_DUTY_MODE_POWER * 20 + 47; #else - if (use_sin_start) { + if (eepromBuffer.use_sine_start) { if (adjusted_input < 30) { // dead band ? input = 0; } - if (adjusted_input > 30 && adjusted_input < (sine_mode_changeover_thottle_level * 20)) { + if (adjusted_input > 30 && adjusted_input < (eepromBuffer.sine_mode_changeover_thottle_level * 20)) { input = map(adjusted_input, 30, - (sine_mode_changeover_thottle_level * 20), 47, 160); + (eepromBuffer.sine_mode_changeover_thottle_level * 20), 47, 160); } - if (adjusted_input >= (sine_mode_changeover_thottle_level * 20)) { - input = map(adjusted_input, (sine_mode_changeover_thottle_level * 20), + if (adjusted_input >= (eepromBuffer.sine_mode_changeover_thottle_level * 20)) { + input = map(adjusted_input, (eepromBuffer.sine_mode_changeover_thottle_level * 20), 2047, 160, 2047); } } else { if (use_speed_control_loop) { if (drive_by_rpm) { - target_e_com_time = 60000000 / map(adjusted_input, 47, 2047, MINIMUM_RPM_SPEED_CONTROL, MAXIMUM_RPM_SPEED_CONTROL) / (motor_poles / 2); + target_e_com_time = 60000000 / map(adjusted_input, 47, 2047, MINIMUM_RPM_SPEED_CONTROL, MAXIMUM_RPM_SPEED_CONTROL) / (eepromBuffer.motor_poles / 2); if (adjusted_input < 47) { // dead band ? input = 0; speedPid.error = 0; @@ -1222,7 +1108,7 @@ void setInput() #endif #ifndef BRUSHED_MODE if (!stepper_sine) { - if (input >= 47 + (80 * use_sin_start) && armed) { + if (input >= 47 + (80 * eepromBuffer.use_sine_start) && armed) { if (running == 0) { allOff(); if (!old_routine) { @@ -1232,18 +1118,18 @@ void setInput() last_duty_cycle = min_startup_duty; } - if (use_sin_start) { + if (eepromBuffer.use_sine_start) { duty_cycle_setpoint = map(input, 137, 2047, minimum_duty_cycle+40, 2000); } else { duty_cycle_setpoint = map(input, 47, 2047, minimum_duty_cycle, 2000); } - if (!RC_CAR_REVERSE) { + if (!eepromBuffer.rc_car_reverse) { prop_brake_active = 0; } } - if (input < 47 + (80 * use_sin_start)) { + if (input < 47 + (80 * eepromBuffer.use_sine_start)) { if (play_tone_flag != 0) { switch (play_tone_flag) { @@ -1266,12 +1152,12 @@ void setInput() play_tone_flag = 0; } - if (!comp_pwm) { + if (!eepromBuffer.comp_pwm) { duty_cycle_setpoint = 0; if (!running) { old_routine = 1; zero_crosses = 0; - if (brake_on_stop) { + if (eepromBuffer.brake_on_stop) { fullBrake(); } else { if (!prop_brake_active) { @@ -1279,7 +1165,7 @@ void setInput() } } } - if (RC_CAR_REVERSE && prop_brake_active) { + if (eepromBuffer.rc_car_reverse && prop_brake_active) { #ifndef PWM_ENABLE_BRIDGE prop_brake_duty_cycle = (getAbsDif(1000, newinput) + 1000); if (prop_brake_duty_cycle >= (TIMER1_MAX_ARR - 1)) { @@ -1295,10 +1181,10 @@ void setInput() old_routine = 1; zero_crosses = 0; bad_count = 0; - if (brake_on_stop) { - if (!use_sin_start) { + if (eepromBuffer.brake_on_stop) { + if (!eepromBuffer.use_sine_start) { #ifndef PWM_ENABLE_BRIDGE - prop_brake_duty_cycle = (1980) + drag_brake_strength * 2; + prop_brake_duty_cycle = (1980) + eepromBuffer.drag_brake_strength * 2; proportionalBrake(); prop_brake_active = 1; #else @@ -1324,14 +1210,14 @@ void setInput() phase_C_position -= 360; } - if (use_sin_start == 1) { + if (eepromBuffer.use_sine_start == 1) { stepper_sine = 1; } duty_cycle_setpoint = 0; } } if (!prop_brake_active) { - if (input >= 47 && (zero_crosses < (30U >> stall_protection))) { + if (input >= 47 && (zero_crosses < (30 >> eepromBuffer.stall_protection))) { if (duty_cycle_setpoint < min_startup_duty) { duty_cycle_setpoint = min_startup_duty; } @@ -1397,7 +1283,7 @@ void tenKhzRoutine() #endif } if (!servoPwm) { - RC_CAR_REVERSE = 0; + eepromBuffer.rc_car_reverse = 0; } } else { inputSet = 0; @@ -1411,7 +1297,7 @@ void tenKhzRoutine() } } - if (TLM_ON_INTERVAL) { + if (eepromBuffer.telementry_on_interval) { telem_ms_count++; if (telem_ms_count > telemetry_interval_ms * 20) { send_telemetry = 1; @@ -1446,7 +1332,7 @@ void tenKhzRoutine() one_khz_loop_counter = 0; if (use_current_limit && running) { use_current_limit_adjust -= (int16_t)(doPidCalculations(¤tPid, actual_current, - CURRENT_LIMIT * 100) + eepromBuffer.limits.current * 2 * 100) / 10000); if (use_current_limit_adjust < minimum_duty_cycle) { use_current_limit_adjust = minimum_duty_cycle; @@ -1455,7 +1341,7 @@ void tenKhzRoutine() use_current_limit_adjust = tim1_arr; } } - if (stall_protection && running) { // this boosts throttle as the rpm gets lower, for crawlers + if (eepromBuffer.stall_protection && running) { // this boosts throttle as the rpm gets lower, for crawlers // and rc cars only, do not use for multirotors. stall_protection_adjust += (doPidCalculations(&stallPid, commutation_interval, stall_protect_target_interval))/ 10000; @@ -1507,7 +1393,7 @@ void tenKhzRoutine() duty_cycle = last_duty_cycle + max_duty_cycle_change; if (commutation_interval > 500) { fast_accel = 1; - temp_advance = advance_level; + temp_advance = eepromBuffer.advance_level; } else { fast_accel = 0; } @@ -1515,19 +1401,19 @@ void tenKhzRoutine() } else if ((last_duty_cycle - duty_cycle) > max_duty_cycle_change) { duty_cycle = last_duty_cycle - max_duty_cycle_change; fast_accel = 0; - temp_advance = advance_level; + temp_advance = eepromBuffer.advance_level; } else { if(duty_cycle < 300 && commutation_interval < 300){ - temp_advance = advance_level; + temp_advance = eepromBuffer.advance_level; }else{ - temp_advance = advance_level; + temp_advance = eepromBuffer.advance_level; } fast_accel = 0; } } if ((armed && running) && input > 47) { - if (VARIABLE_PWM) { + if (eepromBuffer.variable_pwm) { } adjusted_duty_cycle = ((duty_cycle * tim1_arr) / 2000) + 1; @@ -1608,11 +1494,11 @@ void advanceincrement() setPWMCompare3(((2 * pwmSin[phase_C_position]) + gate_drive_offset) * TIMER1_MAX_ARR / 2000); #else setPWMCompare1( - (((2 * pwmSin[phase_A_position] / SINE_DIVIDER) + gate_drive_offset) * TIMER1_MAX_ARR / 2000) * sine_mode_power / 10); + (((2 * pwmSin[phase_A_position] / SINE_DIVIDER) + gate_drive_offset) * TIMER1_MAX_ARR / 2000) * eepromBuffer.sine_mode_power / 10); setPWMCompare2( - (((2 * pwmSin[phase_B_position] / SINE_DIVIDER) + gate_drive_offset) * TIMER1_MAX_ARR / 2000) * sine_mode_power / 10); + (((2 * pwmSin[phase_B_position] / SINE_DIVIDER) + gate_drive_offset) * TIMER1_MAX_ARR / 2000) * eepromBuffer.sine_mode_power / 10); setPWMCompare3( - (((2 * pwmSin[phase_C_position] / SINE_DIVIDER) + gate_drive_offset) * TIMER1_MAX_ARR / 2000) * sine_mode_power / 10); + (((2 * pwmSin[phase_C_position] / SINE_DIVIDER) + gate_drive_offset) * TIMER1_MAX_ARR / 2000) * eepromBuffer.sine_mode_power / 10); #endif } @@ -1650,7 +1536,7 @@ void zcfoundroutine() bad_count = 0; zero_crosses++; - if (stall_protection || RC_CAR_REVERSE) { + if (eepromBuffer.stall_protection || eepromBuffer.rc_car_reverse) { if (zero_crosses >= 20 && commutation_interval <= 2000) { old_routine = 0; enableCompInterrupts(); // enable interrupt @@ -1684,9 +1570,9 @@ void runBrushedLoop() brushed_duty_cycle = map(adjusted_input, 48, 2047, 0, (TIMER1_MAX_ARR - (TIMER1_MAX_ARR / 20))); - if (degrees_celsius > TEMPERATURE_LIMIT) { - duty_cycle_maximum = map(degrees_celsius, TEMPERATURE_LIMIT, - TEMPERATURE_LIMIT + 20, TIMER1_MAX_ARR / 2, 1); + if (degrees_celsius > eepromBuffer.limits.temperature) { + duty_cycle_maximum = map(degrees_celsius, eepromBuffer.limits.temperature, + eepromBuffer.limits.temperature + 20, TIMER1_MAX_ARR / 2, 1); } else { duty_cycle_maximum = TIMER1_MAX_ARR - 50; } @@ -1770,17 +1656,34 @@ int main(void) loadEEpromSettings(); - if (VERSION_MAJOR != eepromBuffer[3] || VERSION_MINOR != eepromBuffer[4]) { - eepromBuffer[3] = VERSION_MAJOR; - eepromBuffer[4] = VERSION_MINOR; - strncpy((char *)&eepromBuffer[5], FIRMWARE_NAME, 12); +#ifdef USE_MAKE + if ( + firmware_info.version_major != eepromBuffer.version.major || + firmware_info.version_minor != eepromBuffer.version.minor || + eeprom_layout_version > eepromBuffer.eeprom_version + ) { + eepromBuffer.version.major = firmware_info.version_major; + eepromBuffer.version.minor = firmware_info.version_minor; + for (int i = 0; i < 12; i++) { + eepromBuffer.firmware_name[i] = firmware_info.device_name[i]; + } saveEEpromSettings(); } - - if (use_sin_start) { - // min_startup_duty = sin_mode_min_s_d; +#else + if (VERSION_MAJOR != eepromBuffer.version.major || VERSION_MINOR != eepromBuffer.version.minor || eeprom_layout_version > eepromBuffer.eeprom_version) { + eepromBuffer.version.major = VERSION_MAJOR; + eepromBuffer.version.minor = VERSION_MINOR; + for (int i = 0; i < 12; i++) { + eepromBuffer.firmware_name[i] = (uint8_t)FIRMWARE_NAME[i]; + } + saveEEpromSettings(); } - if (dir_reversed == 1) { +#endif + // if (eepromBuffer.use_sine_start) { + // min_startup_duty = sin_mode_min_s_d; + // } + + if (eepromBuffer.dir_reversed == 1) { forward = 0; } else { forward = 1; @@ -1789,19 +1692,19 @@ int main(void) // startup_max_duty_cycle = startup_max_duty_cycle * TIMER1_MAX_ARR / 2000 + dead_time_override; // adjust for pwm frequency // throttle_max_at_low_rpm = throttle_max_at_low_rpm * TIMER1_MAX_ARR / 2000; // adjust to new pwm frequency // throttle_max_at_high_rpm = TIMER1_MAX_ARR; // adjust to new pwm frequency - if (!comp_pwm) { - use_sin_start = 0; // sine start requires complementary pwm. + if (!eepromBuffer.comp_pwm) { + eepromBuffer.use_sine_start = 0; // sine start requires complementary pwm. } - if (RC_CAR_REVERSE) { // overrides a whole lot of things! + if (eepromBuffer.rc_car_reverse) { // overrides a whole lot of things! throttle_max_at_low_rpm = 1000; - bi_direction = 1; - use_sin_start = 0; + eepromBuffer.bi_direction = 1; + eepromBuffer.use_sine_start = 0; low_rpm_throttle_limit = 1; - VARIABLE_PWM = 0; - // stall_protection = 1; - comp_pwm = 0; - stuck_rotor_protection = 0; + eepromBuffer.variable_pwm = 0; + // eepromBuffer.stall_protection = 1; + eepromBuffer.comp_pwm = 0; + eepromBuffer.stuck_rotor_protection = 0; minimum_duty_cycle = minimum_duty_cycle + 50; stall_protect_minimum_duty = stall_protect_minimum_duty + 50; min_startup_duty = min_startup_duty + 50; @@ -1834,8 +1737,8 @@ int main(void) comStep(2); #ifdef FIXED_SPEED_MODE use_speed_control_loop = 1; - use_sin_start = 0; - target_e_com_time = 60000000 / FIXED_SPEED_MODE_RPM / (motor_poles / 2); + eepromBuffer.use_sine_start = 0; + target_e_com_time = 60000000 / FIXED_SPEED_MODE_RPM / (eepromBuffer.motor_poles / 2); input = 48; #endif @@ -1843,7 +1746,7 @@ int main(void) #ifdef BRUSHED_MODE // bi_direction = 1; commutation_interval = 5000; - use_sin_start = 0; + eepromBuffer.use_sine_start = 0; maskPhaseInterrupts(); playBrushedStartupTune(); #else @@ -1857,8 +1760,8 @@ int main(void) MX_IWDG_Init(); RELOAD_WATCHDOG_COUNTER(); #ifdef GIMBAL_MODE - bi_direction = 1; - use_sin_start = 1; + eepromBuffer.bi_direction = 1; + eepromBuffer.use_sine_start = 1; #endif #ifdef USE_ADC_INPUT @@ -1913,7 +1816,7 @@ int main(void) RELOAD_WATCHDOG_COUNTER(); e_com_time = ((commutation_intervals[0] + commutation_intervals[1] + commutation_intervals[2] + commutation_intervals[3] + commutation_intervals[4] + commutation_intervals[5]) + 4) >> 1; // COMMUTATION INTERVAL IS 0.5US INCREMENTS - if (VARIABLE_PWM) { + if (eepromBuffer.variable_pwm) { tim1_arr = map(commutation_interval, 96, 200, TIMER1_MAX_ARR / 2, TIMER1_MAX_ARR); } @@ -1992,7 +1895,7 @@ int main(void) if (zero_crosses > 100 && adjusted_input < 200) { bemf_timeout_happened = 0; } - if (use_sin_start && adjusted_input < 160) { + if (eepromBuffer.use_sine_start && adjusted_input < 160) { bemf_timeout_happened = 0; } @@ -2014,7 +1917,7 @@ int main(void) if ((getAbsDif(last_average_interval, average_interval) > average_interval >> 1) && (average_interval < 2000)) { // throttle resitricted before zc 20. zero_crosses = 0; desync_happened++; - if ((!bi_direction && (input > 47)) || commutation_interval > 1000) { + if ((!eepromBuffer.bi_direction && (input > 47)) || commutation_interval > 1000) { running = 0; } old_routine = 1; @@ -2121,8 +2024,8 @@ int main(void) duty_cycle_maximum = 2000; } - if (degrees_celsius > TEMPERATURE_LIMIT) { - duty_cycle_maximum = map(degrees_celsius, TEMPERATURE_LIMIT - 10, TEMPERATURE_LIMIT + 10, + if (degrees_celsius > eepromBuffer.limits.temperature) { + duty_cycle_maximum = map(degrees_celsius, eepromBuffer.limits.temperature - 10, eepromBuffer.limits.temperature + 10, throttle_max_at_high_rpm / 2, 1); } if (zero_crosses < 100 && commutation_interval > 500) { @@ -2141,7 +2044,10 @@ int main(void) if (commutation_interval < 50) { filter_level = 2; } - auto_advance_level = map(duty_cycle, 100, 2000, 13, 23); + + if (eepromBuffer.auto_advance) { + auto_advance_level = map(duty_cycle, 100, 2000, 13, 23); + } /**************** old routine*********************/ #ifdef CUSTOM_RAMP @@ -2213,7 +2119,7 @@ int main(void) do_once_sinemode = 0; } advanceincrement(); - step_delay = map(input, 48, 120, 7000 / motor_poles, 810 / motor_poles); + step_delay = map(input, 48, 120, 7000 / eepromBuffer.motor_poles, 810 / eepromBuffer.motor_poles); delayMicros(step_delay); e_rpm = 600 / step_delay; // in hundreds so 33 e_rpm is 3300 actual erpm @@ -2238,7 +2144,7 @@ int main(void) prop_brake_active = 0; step = changeover_step; // comStep(step);// rising bemf on a same as position 0. - if (stall_protection) { + if (eepromBuffer.stall_protection) { last_duty_cycle = stall_protect_minimum_duty; } commutate(); @@ -2248,9 +2154,9 @@ int main(void) } else { do_once_sinemode = 1; - if (brake_on_stop) { + if (eepromBuffer.brake_on_stop) { #ifndef PWM_ENABLE_BRIDGE - duty_cycle = (TIMER1_MAX_ARR - 19) + drag_brake_strength * 2; + duty_cycle = (TIMER1_MAX_ARR - 19) + eepromBuffer.drag_brake_strength * 2; adjusted_duty_cycle = TIMER1_MAX_ARR - ((duty_cycle * tim1_arr) / TIMER1_MAX_ARR) + 1; proportionalBrake(); SET_DUTY_CYCLE_ALL(adjusted_duty_cycle); diff --git a/Src/signal.c b/Src/signal.c index 5df5c0371..4f96bcaf6 100644 --- a/Src/signal.c +++ b/Src/signal.c @@ -13,7 +13,6 @@ #include "serial_telemetry.h" #include "sounds.h" #include "targets.h" - int max_servo_deviation = 250; int servorawinput; uint16_t smallestnumber = 20000; @@ -63,7 +62,7 @@ void computeServoInput() servo_high_threshold = ((7 * servo_high_threshold + (dma_buffer[1] - dma_buffer[0])) >> 3); if (high_calibration_counts > 50) { servo_high_threshold = servo_high_threshold - 25; - eepromBuffer[33] = (servo_high_threshold - 1750) / 2; + eepromBuffer.servo.high_threshold = (servo_high_threshold - 1750) / 2; high_calibration_set = 1; playDefaultTone(); } @@ -77,7 +76,7 @@ void computeServoInput() } if (low_calibration_counts > 75) { servo_low_threshold = servo_low_threshold + 25; - eepromBuffer[32] = (servo_low_threshold - 750) / 2; + eepromBuffer.servo.low_threshold = (servo_low_threshold - 750) / 2; calibration_required = 0; saveEEpromSettings(); low_calibration_counts = 0; @@ -86,7 +85,7 @@ void computeServoInput() } signaltimeout = 0; } else { - if (bi_direction) { + if (eepromBuffer.bi_direction) { if (dma_buffer[1] - dma_buffer[0] <= servo_neutral) { servorawinput = map((dma_buffer[1] - dma_buffer[0]), servo_low_threshold, servo_neutral, 0, 1000); diff --git a/Src/sounds.c b/Src/sounds.c index af28d4d6b..c87cfdda9 100644 --- a/Src/sounds.c +++ b/Src/sounds.c @@ -62,21 +62,21 @@ void playBlueJayTune() uint16_t frequency; comStep(3); // read_flash_bin(blueJayTuneBuffer , eeprom_address + 48 , 128); - for (int i = 52; i < 176; i += 2) { + for (int i = 0; i < 124; i += 2) { RELOAD_WATCHDOG_COUNTER(); signaltimeout = 0; - if (eepromBuffer[i] == 255) { + if (eepromBuffer.tune[i] == 255) { full_time_count++; } else { - if (eepromBuffer[i + 1] == 0) { - duration = full_time_count * 254 + eepromBuffer[i]; + if (eepromBuffer.tune[i + 1] == 0) { + duration = full_time_count * 254 + eepromBuffer.tune[i]; SET_DUTY_CYCLE_ALL(0); delayMillis(duration); } else { - frequency = getBlueJayNoteFrequency(eepromBuffer[i + 1]); - duration = ((full_time_count * 254 + eepromBuffer[i]) * (100000 / frequency)) / 100; + frequency = getBlueJayNoteFrequency(eepromBuffer.tune[i + 1]); + duration = ((full_time_count * 254 + eepromBuffer.tune[i]) * (100000 / frequency)) / 100; playBJNote(frequency, duration); } full_time_count = 0; @@ -260,497 +260,3 @@ void playBeaconTune3() SET_AUTO_RELOAD_PWM(TIMER1_MAX_ARR); __enable_irq(); } - -// #ifdef GIGADEVICES - -// void pause(uint16_t ms){ -// TIMER_CH0CV(TIMER0) = 0; // volume of the beep, (duty cycle) don't go -// above 25 out of 2000 TIMER_CH1CV(TIMER0) = 0; TIMER_CH2CV(TIMER0) = 0; - -// delayMillis(ms); -// TIMER_CH0CV(TIMER0) = beep_volume; // volume of the beep, (duty cycle) -// don't go above 25 out of 2000 TIMER_CH1CV(TIMER0) = beep_volume; -// TIMER_CH2CV(TIMER0) = beep_volume; -// } - -// void setVolume(uint8_t volume){ -// if(volume > 11){ -// volume = 11; -// } -// if(volume < 0){ -// volume = 0; -// } -// beep_volume = volume * 2; // volume variable from 0 - 11 -// equates to CCR value of 0-22 -// } - -// void setCaptureCompare(){ -// TIMER_CH0CV(TIMER0) = beep_volume; // volume of the beep, (duty cycle) -// don't go above 25 out of 2000 TIMER_CH1CV(TIMER0) = beep_volume; -// TIMER_CH2CV(TIMER0) = beep_volume; -// } - -// void playBJNote(uint16_t freq, uint16_t bduration){ // hz and ms -// uint16_t timerOne_reload = TIM1_AUTORELOAD; - -// TIMER_PSC(TIMER0) = 10; -// timerOne_reload = 4800000 / freq; - -// TIMER_CAR(TIMER0) = timerOne_reload; -// TIMER_CH0CV(TIMER0) = beep_volume * timerOne_reload /TIM1_AUTORELOAD ; -// // volume of the beep, (duty cycle) don't go above 25 out of 2000 -// TIMER_CH1CV(TIMER0) = beep_volume * timerOne_reload /TIM1_AUTORELOAD; -// TIMER_CH2CV(TIMER0) = beep_volume * timerOne_reload /TIM1_AUTORELOAD; - -// delayMillis(bduration); -// } - -// uint16_t getBlueJayNoteFrequency(uint8_t bjarrayfreq){ -// return 10000000/(bjarrayfreq * 247 + 4000); -// } - -// void playBlueJayTune(){ -// uint8_t full_time_count = 0; -// uint16_t duration; -// float frequency; -// comStep(3); -// //read_flash_bin(blueJayTuneBuffer , eeprom_address + 48 , 128); -// for(int i = 52 ; i < 176 ; i+=2){ -// fwdgt_counter_reload(); -// signaltimeout = 0; - -// if(eepromBuffer[i] == 255){ -// full_time_count++; - -// }else{ -// if(eepromBuffer[i+1] == 0){ -// duration = full_time_count * 254 + -// eepromBuffer[i]; TIMER_CH0CV(TIMER0) = 0 ; // TIMER_CH1CV(TIMER0) = 0; -// TIMER_CH2CV(TIMER0) = 0; -// delayMillis(duration); -// }else{ -// frequency = getBlueJayNoteFrequency(eepromBuffer[i+1]); -// duration= (full_time_count * 254 + eepromBuffer[i]) * -// (float)(1000 / frequency); playBJNote(frequency, duration); -// } -// full_time_count = 0; -// } -// } -// allOff(); // turn all channels low again -// TIMER_PSC(TIMER0) = 0; // set prescaler back to 0. -// TIMER_CAR(TIMER0) = TIMER1_MAX_ARR; -// signaltimeout = 0; -// fwdgt_counter_reload(); -// } - -// void playStartupTune(){ -// __disable_irq(); - -// uint8_t value = *(uint8_t*)(eeprom_address+48); -// if(value != 0xFF){ -// playBlueJayTune(); -// }else{ -// TIMER_CAR(TIMER0) = TIM1_AUTORELOAD; -// setCaptureCompare(); -// comStep(3); // activate a pwm channel - -// TIMER_PSC(TIMER0) = 55; // frequency of beep -// delayMillis(200); // duration of beep -// comStep(5); - -// TIMER_PSC(TIMER0) = 40; // next beep is higher frequency -// delayMillis(200); - -// comStep(6); -// TIMER_PSC(TIMER0) = 25; // higher again.. -// delayMillis(200); -// allOff(); // turn all channels low again -// TIMER_PSC(TIMER0) = 0; // set prescaler back to 0. -// signaltimeout = 0; -// } - -// TIMER_CAR(TIMER0) = TIMER1_MAX_ARR; -// __enable_irq(); -// } - -// void playBrushedStartupTune(){ -// __disable_irq(); -// TIMER_CAR(TIMER0) = TIM1_AUTORELOAD; -// setCaptureCompare(); -// comStep(1); // activate a pwm channel -// TIMER_PSC(TIMER0) = 40; // frequency of beep -// delayMillis(300); // duration of beep -// comStep(2); // activate a pwm channel -// TIMER_PSC(TIMER0) = 30; // frequency of beep -// delayMillis(300); // duration of beep -// comStep(3); // activate a pwm channel -// TIMER_PSC(TIMER0) = 25; // frequency of beep -// delayMillis(300); // duration of beep -// comStep(4); -// TIMER_PSC(TIMER0) = 20; // higher again.. -// delayMillis(300); -// allOff(); // turn all channels low again -// TIMER_PSC(TIMER0) = 0; // set prescaler back to 0. -// signaltimeout = 0; -// TIMER_CAR(TIMER0) = TIMER1_MAX_ARR; -// __enable_irq(); -// } - -// void playDuskingTune(){ -// setCaptureCompare(); -// TIMER_CAR(TIMER0) = TIM1_AUTORELOAD; -// comStep(2); // activate a pwm channel -// TIMER_PSC(TIMER0) = 60; // frequency of beep -// delayMillis(200); // duration of beep -// TIMER_PSC(TIMER0) = 55; // next beep is higher frequency -// delayMillis(150); -// TIMER_PSC(TIMER0) = 50; // higher again.. -// delayMillis(150); -// TIMER_PSC(TIMER0) = 45; // frequency of beep -// delayMillis(100); // duration of beep -// TIMER_PSC(TIMER0) = 50; // next beep is higher frequency -// delayMillis(100); -// TIMER_PSC(TIMER0) = 55; // higher again.. -// delayMillis(100); -// TIMER_PSC(TIMER0) = 25; // higher again.. -// delayMillis(200); -// TIMER_PSC(TIMER0) = 55; // higher again.. -// delayMillis(150); -// allOff(); // turn all channels low again -// TIMER_PSC(TIMER0) = 0; // set prescaler back to 0. -// TIMER_CAR(TIMER0) = TIMER1_MAX_ARR; -// } - -// void playInputTune2(){ -// TIMER_CAR(TIMER0) = TIM1_AUTORELOAD; -// __disable_irq(); -// fwdgt_counter_reload(); -// TIMER_PSC(TIMER0) = 60; -// setCaptureCompare(); -// comStep(1); -// delayMillis(75); -// TIMER_PSC(TIMER0) = 80; -// delayMillis(75); -// TIMER_PSC(TIMER0) = 90; -// fwdgt_counter_reload(); -// delayMillis(75); -// allOff(); -// TIMER_PSC(TIMER0) = 0; -// signaltimeout = 0; -// TIMER_CAR(TIMER0) = TIMER1_MAX_ARR; -// __enable_irq(); -// } - -// void playInputTune(){ -// __disable_irq(); -// TIMER_CAR(TIMER0) = TIM1_AUTORELOAD; -// fwdgt_counter_reload(); -// TIMER_PSC(TIMER0) = 80; -// setCaptureCompare(); -// comStep(3); -// delayMillis(100); -// TIMER_PSC(TIMER0) = 70; -// delayMillis(100); -// TIMER_PSC(TIMER0) = 40; -// delayMillis(100); -// allOff(); -// TIMER_PSC(TIMER0) = 0; -// signaltimeout = 0; -// TIMER_CAR(TIMER0) = TIMER1_MAX_ARR; -// __enable_irq(); -// } - -// void playDefaultTone(){ -// TIMER_CAR(TIMER0) = TIM1_AUTORELOAD; -// TIMER_PSC(TIMER0) = 50; -// setCaptureCompare(); -// comStep(2); -// delayMillis(150); -// fwdgt_counter_reload(); -// TIMER_PSC(TIMER0) = 30; -// delayMillis(150); -// allOff(); -// TIMER_PSC(TIMER0) = 0; -// signaltimeout = 0; -// TIMER_CAR(TIMER0) = TIMER1_MAX_ARR; - -// } - -// void playChangedTone(){ -// TIMER_CAR(TIMER0) = TIM1_AUTORELOAD; -// TIMER_PSC(TIMER0) = 40; -// setCaptureCompare(); -// comStep(2); -// delayMillis(150); -// fwdgt_counter_reload(); -// TIMER_PSC(TIMER0) = 80; -// delayMillis(150); -// allOff(); -// TIMER_PSC(TIMER0) = 0; -// signaltimeout = 0; -// TIMER_CAR(TIMER0) = TIMER1_MAX_ARR; - -// } - -// void playBeaconTune3(){ -// TIMER_CAR(TIMER0) = TIM1_AUTORELOAD; -// __disable_irq(); -// setCaptureCompare(); -// for(int i = 119 ; i > 0 ; i = i- 2){ -// fwdgt_counter_reload(); -// comStep(i/20); -// TIMER_PSC(TIMER0) = 10+(i / 2); -// delayMillis(10); -// } -// allOff(); -// TIMER_PSC(TIMER0) = 0; -// signaltimeout = 0; -// TIMER_CAR(TIMER0) = TIMER1_MAX_ARR; -// __enable_irq(); -// } -// #endif - -// #ifdef ARTERY -// void pause(uint16_t ms){ -// TMR1->c1dt = 0; // volume of the beep, (duty cycle) don't go above 25 -// out of 2000 TMR1->c2dt = 0; TMR1->c3dt = 0; - -// delayMillis(ms); -// TMR1->c1dt = beep_volume; // volume of the beep, (duty cycle) don't go -// above 25 out of 2000 TMR1->c2dt = beep_volume; TMR1->c3dt = beep_volume; -// } - -// void setVolume(uint8_t volume){ -// if(volume > 11){ -// volume = 11; -// } -// if(volume < 0){ -// volume = 0; -// } -// beep_volume = volume * 2; // volume variable from 0 - 11 -// equates to CCR value of 0-22 -// } - -// void setCaptureCompare(){ -// TMR1->c1dt = beep_volume; // volume of the beep, (duty cycle) don't go -// above 25 out of 2000 TMR1->c2dt = beep_volume; TMR1->c3dt = beep_volume; -// } - -// void playBJNote(uint16_t freq, uint16_t bduration){ // hz and ms -// uint16_t timerOne_reload = TIM1_AUTORELOAD; - -// TMR1->div = 10; -// timerOne_reload = 4800000 / freq; - -// TMR1->pr = timerOne_reload; -// TMR1->c1dt = beep_volume * timerOne_reload /TIM1_AUTORELOAD ; // volume -// of the beep, (duty cycle) don't go above 25 out of 2000 TMR1->c2dt = -// beep_volume * timerOne_reload /TIM1_AUTORELOAD; TMR1->c3dt = beep_volume * -// timerOne_reload /TIM1_AUTORELOAD; - -// delayMillis(bduration); -// } - -// uint16_t getBlueJayNoteFrequency(uint8_t bjarrayfreq){ -// return 10000000/(bjarrayfreq * 247 + 4000); -// } - -// void playBlueJayTune(){ -// uint8_t full_time_count = 0; -// uint16_t duration; -// uint16_t frequency; -// comStep(3); -// //read_flash_bin(blueJayTuneBuffer , eeprom_address + 48 , 128); -// for(int i = 52 ; i < 176 ; i+=2){ -// WDT->cmd = WDT_CMD_RELOAD; -// signaltimeout = 0; - -// if(eepromBuffer[i] == 255){ -// full_time_count++; - -// }else{ -// if(eepromBuffer[i+1] == 0){ -// duration = full_time_count * 254 + -// eepromBuffer[i]; TMR1->c1dt = 0 ; // TMR1->c2dt = 0; TMR1->c3dt = 0; -// delayMillis(duration); -// }else{ -// frequency = getBlueJayNoteFrequency(eepromBuffer[i+1]); -// duration= ((full_time_count * 254 + eepromBuffer[i]) * -// (100000 / frequency)) / 100; playBJNote(frequency, duration); -// } -// full_time_count = 0; -// } -// } -// allOff(); // turn all channels low again -// TMR1->div = 0; // set prescaler back to 0. -// TMR1->pr = TIMER1_MAX_ARR; -// signaltimeout = 0; -// WDT->cmd = WDT_CMD_RELOAD; -// } - -// void playStartupTune(){ -// __disable_irq(); - -// uint8_t value = *(uint8_t*)(eeprom_address+48); -// if(value != 0xFF){ -// playBlueJayTune(); -// }else{ -// TMR1->pr = TIM1_AUTORELOAD; -// setCaptureCompare(); -// comStep(3); // activate a pwm channel -// WDT->cmd = WDT_CMD_RELOAD; -// TMR1->div = 55; // frequency of beep -// delayMillis(200); // duration of beep -// comStep(5); - -// TMR1->div = 40; // next beep is higher frequency -// delayMillis(200); - -// comStep(6); -// TMR1->div = 25; // higher again.. -// delayMillis(200); -// allOff(); // turn all channels low again -// TMR1->div = 0; // set prescaler back to 0. -// signaltimeout = 0; -// } -// WDT->cmd = WDT_CMD_RELOAD; -// TMR1->pr = TIMER1_MAX_ARR; -// __enable_irq(); -// } - -// void playBrushedStartupTune(){ -// __disable_irq(); -// TMR1->pr = TIM1_AUTORELOAD; -// setCaptureCompare(); -// comStep(1); // activate a pwm channel -// TMR1->div = 40; // frequency of beep -// delayMillis(300); // duration of beep -// comStep(2); // activate a pwm channel -// TMR1->div = 30; // frequency of beep -// delayMillis(300); // duration of beep -// comStep(3); // activate a pwm channel -// TMR1->div = 25; // frequency of beep -// delayMillis(300); // duration of beep -// comStep(4); -// TMR1->div = 20; // higher again.. -// delayMillis(300); -// allOff(); // turn all channels low again -// TMR1->div = 0; // set prescaler back to 0. -// signaltimeout = 0; -// TMR1->pr = TIMER1_MAX_ARR; -// __enable_irq(); -// } - -// void playDuskingTune(){ -// setCaptureCompare(); -// TMR1->pr = TIM1_AUTORELOAD; -// comStep(2); // activate a pwm channel -// TMR1->div = 60; // frequency of beep -// delayMillis(200); // duration of beep -// TMR1->div = 55; // next beep is higher frequency -// delayMillis(150); -// TMR1->div = 50; // higher again.. -// delayMillis(150); -// TMR1->div = 45; // frequency of beep -// delayMillis(100); // duration of beep -// TMR1->div = 50; // next beep is higher frequency -// delayMillis(100); -// TMR1->div = 55; // higher again.. -// delayMillis(100); -// TMR1->div = 25; // higher again.. -// delayMillis(200); -// TMR1->div = 55; // higher again.. -// delayMillis(150); -// allOff(); // turn all channels low again -// TMR1->div = 0; // set prescaler back to 0. -// TMR1->pr = TIMER1_MAX_ARR; -// } - -// void playInputTune2(){ -// TMR1->pr = TIM1_AUTORELOAD; -// __disable_irq(); -// WDT->cmd = WDT_CMD_RELOAD; -// TMR1->div = 60; -// setCaptureCompare(); -// comStep(1); -// delayMillis(75); -// TMR1->div = 80; -// delayMillis(75); -// TMR1->div = 90; -// WDT->cmd = WDT_CMD_RELOAD; -// delayMillis(75); -// allOff(); -// TMR1->div = 0; -// signaltimeout = 0; -// TMR1->pr = TIMER1_MAX_ARR; -// __enable_irq(); -// } - -// void playInputTune(){ -// __disable_irq(); -// TMR1->pr = TIM1_AUTORELOAD; -// WDT->cmd = WDT_CMD_RELOAD; -// TMR1->div = 80; -// setCaptureCompare(); -// comStep(3); -// delayMillis(100); -// TMR1->div = 70; -// delayMillis(100); -// TMR1->div = 40; -// delayMillis(100); -// allOff(); -// TMR1->div = 0; -// signaltimeout = 0; -// TMR1->pr = TIMER1_MAX_ARR; -// __enable_irq(); -// } - -// void playDefaultTone(){ -// TMR1->pr = TIM1_AUTORELOAD; -// TMR1->div = 50; -// setCaptureCompare(); -// comStep(2); -// delayMillis(150); -// WDT->cmd = WDT_CMD_RELOAD; -// TMR1->div = 30; -// delayMillis(150); -// allOff(); -// TMR1->div = 0; -// signaltimeout = 0; -// TMR1->pr = TIMER1_MAX_ARR; - -// } - -// void playChangedTone(){ -// TMR1->pr = TIM1_AUTORELOAD; -// TMR1->div = 40; -// setCaptureCompare(); -// comStep(2); -// delayMillis(150); -// WDT->cmd = WDT_CMD_RELOAD; -// TMR1->div = 80; -// delayMillis(150); -// allOff(); -// TMR1->div = 0; -// signaltimeout = 0; -// TMR1->pr = TIMER1_MAX_ARR; - -// } - -// void playBeaconTune3(){ -// TMR1->pr = TIM1_AUTORELOAD; -// __disable_irq(); -// setCaptureCompare(); -// for(int i = 119 ; i > 0 ; i = i- 2){ -// WDT->cmd = WDT_CMD_RELOAD; -// comStep(i/20); -// TMR1->div = 10+(i / 2); -// delayMillis(10); -// } -// allOff(); -// TMR1->div = 0; -// signaltimeout = 0; -// TMR1->pr = TIMER1_MAX_ARR; -// __enable_irq(); -// } -// #endif