Skip to content

Commit

Permalink
global reformatting
Browse files Browse the repository at this point in the history
reformat with astyle for 2-space indent
  • Loading branch information
tridge committed Dec 1, 2024
1 parent 001a32f commit 4ae63f4
Show file tree
Hide file tree
Showing 98 changed files with 11,252 additions and 11,021 deletions.
32 changes: 16 additions & 16 deletions Inc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,26 @@ extern uint16_t send_extended_dshot;
// }PID;

typedef struct fastPID {
int32_t error;
uint32_t Kp;
uint32_t Ki;
uint32_t Kd;
int32_t integral;
int32_t derivative;
int32_t last_error;
int32_t pid_output;
int32_t integral_limit;
int32_t output_limit;
int32_t error;
uint32_t Kp;
uint32_t Ki;
uint32_t Kd;
int32_t integral;
int32_t derivative;
int32_t last_error;
int32_t pid_output;
int32_t integral_limit;
int32_t output_limit;
} fastPID;

/*
input signal types
*/
enum inputType {
AUTO_IN = 0,
DSHOT_IN = 1,
SERVO_IN = 2,
SERIAL_IN = 3,
EDTARM_IN = 4,
DRONECAN_IN = 5,
AUTO_IN = 0,
DSHOT_IN = 1,
SERVO_IN = 2,
SERIAL_IN = 3,
EDTARM_IN = 4,
DRONECAN_IN = 5,
};
116 changes: 58 additions & 58 deletions Inc/eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,65 @@
#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 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
struct {
uint8_t can_node; // 176
uint8_t esc_index; // 177
uint8_t require_arming; // 178
uint8_t telem_rate; // 179
uint8_t require_zero_throttle; // 180
uint8_t filter_hz; // 181
uint8_t debug_rate; // 182
uint8_t term_enable; // 183
uint8_t reserved[8]; // 184-191
} can;
};
uint8_t buffer[192];
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
struct {
uint8_t can_node; // 176
uint8_t esc_index; // 177
uint8_t require_arming; // 178
uint8_t telem_rate; // 179
uint8_t require_zero_throttle; // 180
uint8_t filter_hz; // 181
uint8_t debug_rate; // 182
uint8_t term_enable; // 183
uint8_t reserved[8]; // 184-191
} can;
};
uint8_t buffer[192];
} EEprom_t;

extern EEprom_t eepromBuffer;
Expand Down
4 changes: 2 additions & 2 deletions Inc/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ void delayMillis(uint32_t millis);
long map(long x, long in_min, long in_max, long out_min, long out_max);
#ifdef ARTERY
void gpio_mode_QUICK(gpio_type* gpio_periph, uint32_t mode,
uint32_t pull_up_down, uint32_t pin);
uint32_t pull_up_down, uint32_t pin);
void gpio_mode_set(gpio_type* gpio_periph, uint32_t mode, uint32_t pull_up_down,
uint32_t pin);
uint32_t pin);
#endif
#endif /* FUNCTIONS_H_ */
2 changes: 1 addition & 1 deletion Inc/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extern char crawler_mode;
extern uint16_t ADC_raw_volts;
extern uint16_t servo_low_threshold; // anything below this point considered 0
extern uint16_t
servo_high_threshold; // anything above this point considered 2000 (max)
servo_high_threshold; // anything above this point considered 2000 (max)
extern uint16_t servo_neutral;
extern uint8_t servo_dead_band;
extern char inputSet;
Expand Down
6 changes: 3 additions & 3 deletions Inc/targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -2147,12 +2147,12 @@

#endif

#ifdef HARDWARE_GROUP_F0_045
#ifdef HARDWARE_GROUP_F0_045
#define PHASE_A_COMP COMP_PA0 // pa0
#define PHASE_B_COMP COMP_PA4 // pa4
#define PHASE_C_COMP COMP_PA5 // pa5
#endif
#ifdef HARDWARE_GROUP_F0_504
#ifdef HARDWARE_GROUP_F0_504
#define PHASE_A_COMP COMP_PA5 // pa5
#define PHASE_B_COMP COMP_PA0 // pa0
#define PHASE_C_COMP COMP_PA4 // pa4
Expand All @@ -2172,7 +2172,7 @@
#define PHASE_B_COMP COMP_PA0 // pa0
#define PHASE_C_COMP COMP_PA5 // pa5
#endif
#ifdef HARDWARE_GROUP_F0_540
#ifdef HARDWARE_GROUP_F0_540
#define PHASE_A_COMP COMP_PA5 // pa5
#define PHASE_B_COMP COMP_PA4 // pa4
#define PHASE_C_COMP COMP_PA0 // pa0
Expand Down
2 changes: 1 addition & 1 deletion Mcu/e230/Inc/IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ extern uint8_t degrees_celsius;
extern uint16_t ADC_raw_volts;
extern uint16_t servo_low_threshold; // anything below this point considered 0
extern uint16_t
servo_high_threshold; // anything above this point considered 2000 (max)
servo_high_threshold; // anything above this point considered 2000 (max)
extern uint16_t servo_neutral;
extern uint8_t servo_dead_band;
2 changes: 1 addition & 1 deletion Mcu/e230/Inc/serial_telemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define SERIAL_TELEMETRY_H_

void makeTelemPackage(uint8_t temp, uint16_t voltage, uint16_t current,
uint16_t consumption, uint16_t e_rpm);
uint16_t consumption, uint16_t e_rpm);

void telem_UART_Init(void);
void send_telem_DMA();
Expand Down
143 changes: 72 additions & 71 deletions Mcu/e230/Src/ADC.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,87 +20,88 @@ extern uint16_t ADC_raw_current;
extern uint16_t ADC_raw_input;

void ADC_DMA_Callback()
{ // read dma buffer and set extern variables
{
// read dma buffer and set extern variables

#ifdef USE_ADC_INPUT
ADC_raw_temp = ADCDataDMA[3];
ADC_raw_volts = ADCDataDMA[1] / 2;
ADC_raw_current = ADCDataDMA[2];
ADC_raw_input = ADCDataDMA[0];
ADC_raw_temp = ADCDataDMA[3];
ADC_raw_volts = ADCDataDMA[1] / 2;
ADC_raw_current = ADCDataDMA[2];
ADC_raw_input = ADCDataDMA[0];

#else
ADC_raw_temp = ADCDataDMA[2];
ADC_raw_temp = ADCDataDMA[2];
#ifdef PA6_VOLTAGE
ADC_raw_volts = ADCDataDMA[1];
ADC_raw_current = ADCDataDMA[0];
ADC_raw_volts = ADCDataDMA[1];
ADC_raw_current = ADCDataDMA[0];
#else
ADC_raw_volts = ADCDataDMA[0];
ADC_raw_current = ADCDataDMA[1];
ADC_raw_volts = ADCDataDMA[0];
ADC_raw_current = ADCDataDMA[1];
#endif
#endif
}

void ADC_Init(void)
{
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_ADC);
rcu_periph_clock_enable(RCU_DMA);
rcu_adc_clock_config(RCU_ADCCK_APB2_DIV6);

/* config the GPIO as analog mode */
gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE,
GPIO_PIN_3 | GPIO_PIN_6);

dma_parameter_struct dma_data_parameter;

/* ADC DMA_channel configuration */
dma_deinit(DMA_CH0);

/* initialize DMA single data mode */
dma_data_parameter.periph_addr = (uint32_t)(&ADC_RDATA);
dma_data_parameter.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_data_parameter.memory_addr = (uint32_t)(&ADCDataDMA);
dma_data_parameter.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_data_parameter.periph_width = DMA_PERIPHERAL_WIDTH_16BIT;
dma_data_parameter.memory_width = DMA_MEMORY_WIDTH_16BIT;
dma_data_parameter.direction = DMA_PERIPHERAL_TO_MEMORY;
dma_data_parameter.number = 3U;
dma_data_parameter.priority = DMA_PRIORITY_LOW;
dma_init(DMA_CH0, &dma_data_parameter);

dma_circulation_enable(DMA_CH0);

/* enable DMA channel */
dma_channel_enable(DMA_CH0);

adc_special_function_config(ADC_CONTINUOUS_MODE, DISABLE);
/* ADC scan function enable */
adc_special_function_config(ADC_SCAN_MODE, ENABLE);
/* ADC data alignment config */
adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
/* ADC channel length config */
adc_channel_length_config(ADC_REGULAR_CHANNEL, 3U);

adc_tempsensor_vrefint_enable(); // enable the temp sensor

/* ADC regular channel config */
adc_regular_channel_config(0, ADC_CHANNEL_3, ADC_SAMPLETIME_55POINT5);
adc_regular_channel_config(1, ADC_CHANNEL_6, ADC_SAMPLETIME_55POINT5);
adc_regular_channel_config(2, ADC_CHANNEL_16, ADC_SAMPLETIME_55POINT5);

/* ADC trigger config */
adc_external_trigger_source_config(ADC_REGULAR_CHANNEL,
ADC_EXTTRIG_REGULAR_NONE);
adc_external_trigger_config(ADC_REGULAR_CHANNEL, ENABLE);

/* enable ADC interface */
adc_enable();
delayMicros(1000);
/* ADC calibration and reset calibration */
adc_calibration_enable();

/* ADC DMA function enable */
adc_dma_mode_enable();
/* ADC software trigger enable */
adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_ADC);
rcu_periph_clock_enable(RCU_DMA);
rcu_adc_clock_config(RCU_ADCCK_APB2_DIV6);

/* config the GPIO as analog mode */
gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE,
GPIO_PIN_3 | GPIO_PIN_6);

dma_parameter_struct dma_data_parameter;

/* ADC DMA_channel configuration */
dma_deinit(DMA_CH0);

/* initialize DMA single data mode */
dma_data_parameter.periph_addr = (uint32_t)(&ADC_RDATA);
dma_data_parameter.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_data_parameter.memory_addr = (uint32_t)(&ADCDataDMA);
dma_data_parameter.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_data_parameter.periph_width = DMA_PERIPHERAL_WIDTH_16BIT;
dma_data_parameter.memory_width = DMA_MEMORY_WIDTH_16BIT;
dma_data_parameter.direction = DMA_PERIPHERAL_TO_MEMORY;
dma_data_parameter.number = 3U;
dma_data_parameter.priority = DMA_PRIORITY_LOW;
dma_init(DMA_CH0, &dma_data_parameter);

dma_circulation_enable(DMA_CH0);

/* enable DMA channel */
dma_channel_enable(DMA_CH0);

adc_special_function_config(ADC_CONTINUOUS_MODE, DISABLE);
/* ADC scan function enable */
adc_special_function_config(ADC_SCAN_MODE, ENABLE);
/* ADC data alignment config */
adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
/* ADC channel length config */
adc_channel_length_config(ADC_REGULAR_CHANNEL, 3U);

adc_tempsensor_vrefint_enable(); // enable the temp sensor

/* ADC regular channel config */
adc_regular_channel_config(0, ADC_CHANNEL_3, ADC_SAMPLETIME_55POINT5);
adc_regular_channel_config(1, ADC_CHANNEL_6, ADC_SAMPLETIME_55POINT5);
adc_regular_channel_config(2, ADC_CHANNEL_16, ADC_SAMPLETIME_55POINT5);

/* ADC trigger config */
adc_external_trigger_source_config(ADC_REGULAR_CHANNEL,
ADC_EXTTRIG_REGULAR_NONE);
adc_external_trigger_config(ADC_REGULAR_CHANNEL, ENABLE);

/* enable ADC interface */
adc_enable();
delayMicros(1000);
/* ADC calibration and reset calibration */
adc_calibration_enable();

/* ADC DMA function enable */
adc_dma_mode_enable();
/* ADC software trigger enable */
adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
}
Loading

0 comments on commit 4ae63f4

Please sign in to comment.