Skip to content

Commit

Permalink
Merge pull request #56 from am32-firmware/feature/eeprom_struct
Browse files Browse the repository at this point in the history
Feature/eeprom struct
  • Loading branch information
AlkaMotors authored Nov 8, 2024
2 parents c2abe0e + e159476 commit c658959
Show file tree
Hide file tree
Showing 40 changed files with 315 additions and 963 deletions.
6 changes: 4 additions & 2 deletions Inc/common.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#pragma once
#include <stdint.h>
#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;
Expand Down
1 change: 0 additions & 1 deletion Inc/dshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
62 changes: 62 additions & 0 deletions Inc/eeprom.h
Original file line number Diff line number Diff line change
@@ -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);
1 change: 0 additions & 1 deletion Inc/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "main.h"

extern char out_put;
extern char bi_direction;
extern char inputSet;
extern char dshot;
extern char servoPwm;
Expand Down
2 changes: 2 additions & 0 deletions Inc/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
*/
#define VERSION_MAJOR 2
#define VERSION_MINOR 16

#define EEPROM_VERSION 2
1 change: 0 additions & 1 deletion Mcu/e230/Inc/IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ void setInputPullUp();
void enableHalfTransferInt();
void setInputPullNone();

extern char bi_direction;
extern char inputSet;
extern char dshot;
extern char servoPwm;
Expand Down
17 changes: 0 additions & 17 deletions Mcu/e230/Inc/eeprom.h

This file was deleted.

1 change: 1 addition & 0 deletions Mcu/e230/Inc/phaseouts.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define INC_PHASEOUTS_H_

#include "main.h"
#include "common.h"

void allOff();
void comStep(int newStep);
Expand Down
13 changes: 6 additions & 7 deletions Mcu/e230/Src/phaseouts.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "targets.h"

extern char comp_pwm;
extern char prop_brake_active;

#ifndef PWM_ENABLE_BRIDGE
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion Mcu/f031/Inc/IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ void setInputPullUp();
void enableHalfTransferInt();
void setInputPullNone();

extern char bi_direction;
extern char inputSet;
extern char dshot;
extern char servoPwm;
Expand Down
17 changes: 0 additions & 17 deletions Mcu/f031/Inc/eeprom.h

This file was deleted.

1 change: 1 addition & 0 deletions Mcu/f031/Inc/phaseouts.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define INC_PHASEOUTS_H_

#include "main.h"
#include "common.h"

void allOff();
void comStep(int newStep);
Expand Down
13 changes: 6 additions & 7 deletions Mcu/f031/Src/phaseouts.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "targets.h"

extern char comp_pwm;
extern char prop_brake_active;

#ifndef PWM_ENABLE_BRIDGE
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions Mcu/f051/Inc/IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ void setInputPullUp();
void enableHalfTransferInt();
void setInputPullNone();

extern char bi_direction;

extern char send_telemetry;
extern uint8_t degrees_celsius;

Expand Down
17 changes: 0 additions & 17 deletions Mcu/f051/Inc/eeprom.h

This file was deleted.

1 change: 1 addition & 0 deletions Mcu/f051/Inc/phaseouts.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define INC_PHASEOUTS_H_

#include "main.h"
#include "common.h"

void allOff();
void comStep(char newStep);
Expand Down
13 changes: 6 additions & 7 deletions Mcu/f051/Src/phaseouts.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "targets.h"

extern char comp_pwm;
extern char prop_brake_active;

#ifndef PWM_ENABLE_BRIDGE
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion Mcu/f415/Inc/IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ void setInputPullUp();
void enableHalfTransferInt();
void setInputPullNone();

extern char bi_direction;
extern char inputSet;
extern char dshot;
extern char servoPwm;
Expand Down
Loading

0 comments on commit c658959

Please sign in to comment.