Repo unification

This commit is contained in:
2024-03-12 21:22:26 +02:00
parent 7aa7edba33
commit 02cb3a9c70
152 changed files with 14575 additions and 2038 deletions

41
firmware/src/logic/coil.c Normal file
View File

@@ -0,0 +1,41 @@
/**** Includes ****/
#include "coil.h"
/**** Private definitions ****/
/**** Private constants ****/
static const int16_t TARGET_HANDBRAKE = COIL_TARGET_HANDBRAKE;
static const int16_t LOCK_VOLTAGE = COIL_LOCK_VOLTAGE;
/**** Private variables ****/
/**** Private function declarations ****/
/**** Public function definitions ****/
int16_t coil_target(uint8_t force, uint8_t hbrake_act)
{
if(hbrake_act)
{
return TARGET_HANDBRAKE;
}
else if(force==0)
{
return 0;
}
else if(force >= 100)
{
return LOCK_VOLTAGE;
}
else
{
// Calculate target
uint32_t t = (uint32_t)force * LOCK_VOLTAGE;
t /= 100;
if(t > LOCK_VOLTAGE) return LOCK_VOLTAGE;
else if(t < 0) return 0;
else return (int16_t)t;
}
return 0;
}
/**** Private function definitions ****/

17
firmware/src/logic/coil.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef COIL_H_
#define COIL_H_
/**** Includes ****/
#include <stdint.h>
/**** Public definitions ****/
#define COIL_TARGET_HANDBRAKE -1
#define COIL_LOCK_VOLTAGE 6500
/**** Public function declarations ****/
int16_t coil_target(uint8_t force, uint8_t hbrake_act);
#ifdef TESTING
#endif
#endif /* COIL_H_ */

View File

@@ -0,0 +1,108 @@
/**** Includes ****/
#include "display.h"
/**** Private definitions ****/
/**** Private constants ****/
static const uint8_t BACKLIGHT_DIMM = DSP_BACKLIGHT_DIMM_PERCENT;
static const uint8_t BACKLIGHT_BRIGTH = DSP_BACKLIGHT_BRIGTH_PERCENT;
/**** Private variables ****/
/**** Private function declarations ****/
static uint8_t img_gen_dot10(uint8_t percent);
static uint8_t img_gen_dot20(uint8_t percent);
static uint8_t img_gen_bar(uint8_t percent);
/**** Public function definitions ****/
void dsp_init_ctrl(dsp_ctrl_t* ctrl)
{
ctrl->img_lock = 0;
ctrl->act_img = 0x00;
}
void dsp_set_lock(dsp_ctrl_t* ctrl)
{
ctrl->img_lock = 1;
}
void dsp_reset_lock(dsp_ctrl_t* ctrl)
{
ctrl->img_lock = 0;
}
uint8_t dsp_img_percent(uint8_t value, dsp_style_t style, dsp_ctrl_t* ctrl)
{
if(ctrl->img_lock) return ctrl->act_img;
switch(style)
{
case LED_DSP_BAR:
ctrl->act_img = img_gen_bar(value);
break;
case LED_DSP_DOT10:
ctrl->act_img = img_gen_dot10(value);
break;
default:
ctrl->act_img = img_gen_dot20(value);
break;
}
return ctrl->act_img;
}
uint8_t dsp_img_raw(uint8_t image, dsp_ctrl_t* ctrl)
{
if(ctrl->img_lock) return ctrl->act_img;
ctrl->act_img = image & 0x3F;
return ctrl->act_img;
}
uint8_t dsp_get_act_img(dsp_ctrl_t* ctrl)
{
return ctrl->act_img;
}
uint8_t dsp_backlight(uint8_t dimm_act)
{
if(dimm_act) return BACKLIGHT_DIMM;
else return BACKLIGHT_BRIGTH;
}
/**** Private function definitions ****/
static uint8_t img_gen_dot10(uint8_t percent)
{
if(percent<6) return 0x01;
else if(percent<16) return 0x03;
else if(percent<26) return 0x02;
else if(percent<36) return 0x06;
else if(percent<46) return 0x04;
else if(percent<56) return 0x0C;
else if(percent<66) return 0x08;
else if(percent<76) return 0x18;
else if(percent<86) return 0x10;
else if(percent<96) return 0x30;
else return 0x20;
}
static uint8_t img_gen_dot20(uint8_t percent)
{
if(percent<11) return 0x01;
else if(percent<31) return 0x02;
else if(percent<51) return 0x04;
else if(percent<71) return 0x08;
else if(percent<91) return 0x10;
else return 0x20;
}
static uint8_t img_gen_bar(uint8_t percent)
{
if(percent<11) return 0x01;
else if(percent<31) return 0x03;
else if(percent<51) return 0x07;
else if(percent<71) return 0x0F;
else if(percent<91) return 0x1F;
else return 0x3F;
}

View File

@@ -0,0 +1,37 @@
#ifndef LOGIC_DISPLAY_H_
#define LOGIC_DISPLAY_H_
/**** Includes ****/
#include <stdint.h>
/**** Public definitions ****/
#define DSP_BACKLIGHT_DIMM_PERCENT 50
#define DSP_BACKLIGHT_BRIGTH_PERCENT 100
typedef enum {
LED_DSP_DOT20,
LED_DSP_DOT10,
LED_DSP_BAR
} dsp_style_t;
typedef struct {
uint8_t img_lock;
uint8_t act_img;
} dsp_ctrl_t;
/**** Public function declarations ****/
void dsp_init_ctrl(dsp_ctrl_t* ctrl);
void dsp_set_lock(dsp_ctrl_t* ctrl);
void dsp_reset_lock(dsp_ctrl_t* ctrl);
uint8_t dsp_img_percent(uint8_t value, dsp_style_t style, dsp_ctrl_t* ctrl);
uint8_t dsp_img_raw(uint8_t image, dsp_ctrl_t* ctrl);
uint8_t dsp_get_act_img(dsp_ctrl_t* ctrl);
uint8_t dsp_backlight(uint8_t dimm_act);
#ifdef TESTING
#endif
#endif /* LOGIC_DISPLAY_H_ */

View File

@@ -0,0 +1,63 @@
/**** Includes ****/
#include "force.h"
/**** Private definitions ****/
/**** Private constants ****/
static const uint16_t MAX_HBRAKE_HOLD_TIME = FORCE_MAX_HBRAKE_HOLD_TIME;
/**** Private variables ****/
/**** Private function declarations ****/
/**** Public function definitions ****/
#ifdef TESTING
#endif
uint8_t force_next(uint8_t handbrake, uint8_t brakes, fbrake_mode_t bmode, uint8_t user_force, uint16_t hbarke_act_time)
{
// Do force logic
if((handbrake)&&(hbarke_act_time < MAX_HBRAKE_HOLD_TIME))
{
return 0;
}
else if(brakes)
{
switch(bmode)
{
case FORCE_BMODE_KEEP:
return user_force;
break;
case FORCE_BMODE_LOCK:
return 100;
break;
default: //FORCE_BMODE_OPEN
return 0;
break;
}
}
else
{
return user_force;
}
return 0;
}
fbrake_mode_t force_cycle_bmode(fbrake_mode_t bmode)
{
switch(bmode)
{
case FORCE_BMODE_OPEN:
return FORCE_BMODE_KEEP;
case FORCE_BMODE_KEEP:
return FORCE_BMODE_LOCK;
default:
return FORCE_BMODE_OPEN;
}
}
/**** Private function definitions ****/

View File

@@ -0,0 +1,23 @@
#ifndef FORCE_H_
#define FORCE_H_
/**** Includes ****/
#include <stdint.h>
/**** Public definitions ****/
#define FORCE_MAX_HBRAKE_HOLD_TIME 1000
typedef enum {
FORCE_BMODE_OPEN,
FORCE_BMODE_KEEP,
FORCE_BMODE_LOCK
} fbrake_mode_t;
/**** Public function declarations ****/
uint8_t force_next(uint8_t handbrake, uint8_t brakes, fbrake_mode_t bmode, uint8_t user_force, uint16_t hbarke_act_time);
fbrake_mode_t force_cycle_bmode(fbrake_mode_t bmode);
#ifdef TESTING
#endif
#endif /* FORCE_H_ */

42
firmware/src/logic/pot.c Normal file
View File

@@ -0,0 +1,42 @@
/**** Includes ****/
#include "pot.h"
/**** Private definitions ****/
/**** Private constants ****/
/**** Private variables ****/
/**** Private function declarations ****/
/**** Public function definitions ****/
#ifdef TESTING
#endif
uint8_t pot_mv_to_percent(uint16_t value, pot_cfg_t* cfg)
{
// Setup limits
uint16_t bottom = 0;
uint16_t top = cfg->reference;
// Adjust for top and bottom deadband
if(bottom < cfg->deadband) bottom = cfg->deadband;
if(top > cfg->deadband) top -= cfg->deadband;
// Calculate percent
if(value <= bottom) return 0;
else if(value >= top) return 100;
else
{
// Adjust values for offset
if(bottom)
{
value = value - bottom;
top = top - bottom;
};
uint32_t y = (uint32_t)value * 100;
y = y/(uint32_t)top;
return (uint16_t)y;
}
}
/**** Private function definitions ****/

19
firmware/src/logic/pot.h Normal file
View File

@@ -0,0 +1,19 @@
#ifndef POTENTIOMETER_H_
#define POTENTIOMETER_H_
/**** Includes ****/
#include <stdint.h>
/**** Public definitions ****/
typedef struct {
uint16_t reference;
uint16_t deadband;
} pot_cfg_t;
/**** Public function declarations ****/
uint8_t pot_mv_to_percent(uint16_t value, pot_cfg_t* cfg);
#ifdef TESTING
#endif
#endif /* POTENTIOMETER_H_ */

View File

@@ -0,0 +1,52 @@
/**** Includes ****/
#include "user_force.h"
/**** Private definitions ****/
/**** Private constants ****/
static const uint8_t MAX_PERCENT = USER_FORCE_MAX_PERCENT;
static const uint8_t MIN_PERCENT = USER_FORCE_MIN_PERCENT;
/**** Private variables ****/
/**** Private function declarations ****/
/**** Public function definitions ****/
#ifdef TESTING
#endif
uint8_t user_force_btn(uint8_t prev_force, uint8_t up_act, uint8_t down_act, uint8_t delta)
{
uint8_t new_froce = prev_force;
if(up_act)
{
new_froce = prev_force + delta;
// Limit overflow and top value
if(new_froce < prev_force) new_froce = 100;
else if(new_froce < MIN_PERCENT) new_froce = MIN_PERCENT;
};
if(down_act)
{
new_froce = prev_force - delta;
// Limit overflow and top value
if(new_froce > prev_force) new_froce = 0;
else if(new_froce > MAX_PERCENT) new_froce = MAX_PERCENT;
};
// Do deadband
if(new_froce < MIN_PERCENT) new_froce = 0;
else if(new_froce > MAX_PERCENT) new_froce = 100;
return new_froce;
}
uint8_t user_force_pot(uint8_t prev_force, uint8_t pot, uint8_t hyst)
{
uint8_t new_froce = pot;
if(new_froce < MIN_PERCENT) new_froce = 0;
else if(new_froce > MAX_PERCENT) new_froce = 100;
return new_froce;
}
/**** Private function definitions ****/

View File

@@ -0,0 +1,18 @@
#ifndef USER_FORCE_H_
#define USER_FORCE_H_
/**** Includes ****/
#include <stdint.h>
/**** Public definitions ****/
#define USER_FORCE_MAX_PERCENT 90
#define USER_FORCE_MIN_PERCENT 10
/**** Public function declarations ****/
uint8_t user_force_btn(uint8_t prev_force, uint8_t up_act, uint8_t down_act, uint8_t delta);
uint8_t user_force_pot(uint8_t prev_force, uint8_t pot, uint8_t hyst);
#ifdef TESTING
#endif
#endif /* USER_FORCE_H_ */