Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conf_general.c
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ int conf_general_measure_flux_linkage_openloop(float current, float duty,
* Send motor configuration if the detection succeeds.
*
* @result
* 2: AS5147 detected successfully
* 2: AS5047 detected successfully
* 1: Hall sensors detected successfully
* 0: No sensors detected and sensorless mode applied successfully
* -1: Detection failed
Expand Down
48 changes: 32 additions & 16 deletions hwconf/Ubox/100v/hw_ubox_100_core.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#define UBOX_QUERY_POWER_KEY_IO() (palReadPad(GPIOC, 13))


void shutdown_ubox_init(void);
void shutdown_init(void);

// Variables
static volatile bool i2c_running = false;
Expand Down Expand Up @@ -131,8 +131,8 @@ void hw_init_gpio(void) {

palSetPadMode(GPIOC, 13, PAL_MODE_OUTPUT_OPENDRAIN | PAL_MODE_INPUT_PULLUP);
UBOX_POWER_KEY_IO_RELEASE();

shutdown_ubox_init();
shutdown_init();
}

void hw_setup_adc_channels(void) {
Expand Down Expand Up @@ -287,21 +287,37 @@ float hw100_250_get_temp(void) {
// Private variables
static bool volatile m_button_pressed = false;
static volatile float m_inactivity_time = 0.0;
static THD_WORKING_AREA(shutdown_ubox_thread_wa, 256);
static THD_WORKING_AREA(shutdown_thread_wa, 256);
static mutex_t m_sample_mutex;
static volatile bool m_init_done = false;
static volatile bool m_sampling_disabled = false;

// Private functions
static THD_FUNCTION(shutdown_ubox_thread, arg);
static THD_FUNCTION(shutdown_thread, arg);

void shutdown_ubox_init(void) {
chMtxObjectInit(&m_sample_mutex);
chThdCreateStatic(shutdown_ubox_thread_wa, sizeof(shutdown_ubox_thread_wa), NORMALPRIO, shutdown_ubox_thread, NULL);
m_init_done = true;
void shutdown_init(void) {
if(!m_init_done){
chMtxObjectInit(&m_sample_mutex);
chThdCreateStatic(shutdown_thread_wa, sizeof(shutdown_thread_wa), NORMALPRIO, shutdown_thread, NULL);
m_init_done = true;
}
}

static bool do_shutdown_ubox(void) {
void shutdown_reset_timer(void) {
m_inactivity_time = 0.0;
}

float shutdown_get_inactivity_time(void) {
return m_inactivity_time;
}

void shutdown_hold(bool hold) {
(void)hold;
}

// TODO: Doesn't use resample. Maybe in future allow resampling if enPOWER_KEY_TYPE is momentary?
bool do_shutdown(bool resample) {
(void)resample;
conf_general_store_backup_data();

chThdSleepMilliseconds(100);
Expand All @@ -310,7 +326,6 @@ static bool do_shutdown_ubox(void) {
return true;
}


typedef enum {
power_key_type_undecided = 0,
power_key_type_momentary,
Expand All @@ -321,7 +336,7 @@ static enPOWER_KEY_TYPE power_key_type = power_key_type_undecided;
static uint32_t power_key_pressed_ms = 0;
static bool power_key_pressed_when_power_on = false;

static THD_FUNCTION(shutdown_ubox_thread, arg) {
static THD_FUNCTION(shutdown_thread, arg) {
(void)arg;
chRegSetThreadName("Shutdown_ubox");

Expand Down Expand Up @@ -352,6 +367,7 @@ static THD_FUNCTION(shutdown_ubox_thread, arg) {
}
} else {
if((power_key_pressed_ms > 50) && (power_key_pressed_ms < 500)) {
// TODO: Could toggle different led types here??
power_key_click = 1;
}
power_key_pressed_ms = 0;
Expand Down Expand Up @@ -394,7 +410,7 @@ static THD_FUNCTION(shutdown_ubox_thread, arg) {
//Inactive after 10 seconds, MCU cancels the enable signal, regulator shuts down if button released.
m_inactivity_time += dt;
if (m_inactivity_time >= 10.0f) {
do_shutdown_ubox();
do_shutdown(false);
}
break;
case SHUTDOWN_MODE_ALWAYS_ON:
Expand All @@ -414,7 +430,7 @@ static THD_FUNCTION(shutdown_ubox_thread, arg) {
break;
case SHUTDOWN_MODE_TOGGLE_BUTTON_ONLY:
if(clicked) {
do_shutdown_ubox();
do_shutdown(true);
}
break;
default: break;
Expand All @@ -434,7 +450,7 @@ static THD_FUNCTION(shutdown_ubox_thread, arg) {
default: break;
}
if (m_inactivity_time >= shutdown_timeout) {
do_shutdown_ubox();
do_shutdown(false);
}
} else {
//Because SHUTDOWN_MODE_ALWAYS_OFF's implementation will check m_inactivity_time.
Expand All @@ -444,7 +460,7 @@ static THD_FUNCTION(shutdown_ubox_thread, arg) {
}

if(power_key_pressed_ms > 2000) {
do_shutdown_ubox();
do_shutdown(true);
}
} else {
m_inactivity_time += dt;
Expand Down
2 changes: 2 additions & 0 deletions hwconf/Ubox/100v/hw_ubox_100_core.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef HW_UBOX_V2_100_CORE_H_
#define HW_UBOX_V2_100_CORE_H_

#define HW_SHUTDOWN_CUSTOM

#ifdef HW_UBOX_V2_100
#define HW_NAME "UBOX_V2_100"
#elif defined (HW_UBOX_SINGLE_100)
Expand Down
8 changes: 8 additions & 0 deletions hwconf/floatwheel/hw_adv_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,19 @@
#define HW_SPI_PORT_MISO GPIOA
#define HW_SPI_PIN_MISO 6

#ifdef ADV200
// IMU: BMI160
#define BMI160_SDA_GPIO GPIOB
#define BMI160_SDA_PIN 2
#define BMI160_SCL_GPIO GPIOA
#define BMI160_SCL_PIN 15
#else
// LSM6DS3
#define LSM6DS3_SDA_GPIO GPIOB
#define LSM6DS3_SDA_PIN 2
#define LSM6DS3_SCL_GPIO GPIOA
#define LSM6DS3_SCL_PIN 15
#endif

// NRF SWD
#define NRF5x_SWDIO_GPIO GPIOB
Expand Down
4 changes: 3 additions & 1 deletion hwconf/shutdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#include "lispif.h"
#endif

#ifdef HW_SHUTDOWN_HOLD_ON
#ifdef HW_SHUTDOWN_CUSTOM
// Do nothing. All shutdown functionality is handled in the hardware file.
#elif defined(HW_SHUTDOWN_HOLD_ON)

// Private variables
bool volatile m_button_pressed = false;
Expand Down
2 changes: 1 addition & 1 deletion package_firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def get_git_revision_short_hash() -> str:
package_dict["Little_FOCer"] = [['Little_FOCer', default_name]]
package_dict["Little_FOCer_V3"] = [['Little_FOCer_V3', default_name]]
package_dict["Little_FOCer_V3_1"] = [['Little_FOCer_V3_1', default_name]]
package_dict["Little_FOCer_4"] = [['Little_FOCer_4', default_name]]
package_dict["Little_FOCer_V4"] = [['Little_FOCer_V4', default_name]]
package_dict["TRONIC_250R"] = [['TRONIC_250R', default_name]]
package_dict["X12_PRO24"] = [['x12_pro24', default_name]]
package_dict["X12_PRO30"] = [['x12_pro30', default_name]]
Expand Down