Move I2C initalisations into more logical spots
This commit is contained in:
@@ -30,7 +30,7 @@ static void MX_TIM2_Init(void);
|
|||||||
static void MX_DMA_Init(void);
|
static void MX_DMA_Init(void);
|
||||||
static void MX_GPIO_Init(void);
|
static void MX_GPIO_Init(void);
|
||||||
static void MX_ADC2_Init(void);
|
static void MX_ADC2_Init(void);
|
||||||
|
#define SWD_ENABLE
|
||||||
void Setup_HAL() {
|
void Setup_HAL() {
|
||||||
SystemClock_Config();
|
SystemClock_Config();
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) {
|
|||||||
__HAL_FLASH_CLEAR_FLAG(
|
__HAL_FLASH_CLEAR_FLAG(
|
||||||
FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_BSY);
|
FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_BSY);
|
||||||
HAL_FLASH_Unlock();
|
HAL_FLASH_Unlock();
|
||||||
HAL_Delay(10);
|
HAL_Delay(1);
|
||||||
resetWatchdog();
|
resetWatchdog();
|
||||||
HAL_FLASHEx_Erase(&pEraseInit, &failingAddress);
|
HAL_FLASHEx_Erase(&pEraseInit, &failingAddress);
|
||||||
//^ Erase the page of flash (1024 bytes on this stm32)
|
//^ Erase the page of flash (1024 bytes on this stm32)
|
||||||
|
|||||||
@@ -144,12 +144,12 @@ void fusb_send_hardrst() {
|
|||||||
|
|
||||||
void fusb_setup() {
|
void fusb_setup() {
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_9;
|
GPIO_InitStruct.Pin = GPIO_PIN_9;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
||||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 12, 0);
|
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 10, 0);
|
||||||
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
|
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
|
||||||
|
|
||||||
if (!I2CBB::lock2()) {
|
if (!I2CBB::lock2()) {
|
||||||
|
|||||||
@@ -12,11 +12,10 @@
|
|||||||
|
|
||||||
// Initialisation to be performed with scheduler active
|
// Initialisation to be performed with scheduler active
|
||||||
void postRToSInit() {
|
void postRToSInit() {
|
||||||
|
|
||||||
/* Init the IPC objects */
|
|
||||||
FRToSI2C::FRToSInit();
|
|
||||||
#ifdef POW_PD
|
#ifdef POW_PD
|
||||||
//Spawn all of the USB-C processors
|
if (usb_pd_detect() == true) {
|
||||||
fusb302_start_processing();
|
//Spawn all of the USB-C processors
|
||||||
|
fusb302_start_processing();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,9 @@ void preRToSInit() {
|
|||||||
*/
|
*/
|
||||||
HAL_Init();
|
HAL_Init();
|
||||||
Setup_HAL(); // Setup all the HAL objects
|
Setup_HAL(); // Setup all the HAL objects
|
||||||
FRToSI2C::init();
|
|
||||||
HAL_Delay(50);
|
|
||||||
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET);
|
|
||||||
HAL_Delay(50);
|
|
||||||
#ifdef I2C_SOFT
|
#ifdef I2C_SOFT
|
||||||
I2CBB::init();
|
I2CBB::init();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
/* Init the IPC objects */
|
||||||
|
FRToSI2C::FRToSInit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,22 +17,13 @@
|
|||||||
#include "int_n.h"
|
#include "int_n.h"
|
||||||
#include "hard_reset.h"
|
#include "hard_reset.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void fusb302_start_processing() {
|
void fusb302_start_processing() {
|
||||||
/* Initialize the FUSB302B */
|
/* Initialize the FUSB302B */
|
||||||
resetWatchdog();
|
|
||||||
fusb_setup();
|
fusb_setup();
|
||||||
resetWatchdog();
|
|
||||||
/* Create the policy engine thread. */
|
|
||||||
PolicyEngine::init();
|
|
||||||
|
|
||||||
/* Create the protocol layer threads. */
|
|
||||||
ProtocolReceive::init();
|
|
||||||
ProtocolTransmit::init();
|
|
||||||
ResetHandler::init();
|
ResetHandler::init();
|
||||||
resetWatchdog();
|
PolicyEngine::init();
|
||||||
/* Create the INT_N thread. */
|
ProtocolTransmit::init();
|
||||||
|
ProtocolReceive::init();
|
||||||
InterruptHandler::init();
|
InterruptHandler::init();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
|
|
||||||
osThreadId InterruptHandler::TaskHandle=NULL;
|
osThreadId InterruptHandler::TaskHandle = NULL;
|
||||||
uint32_t InterruptHandler::TaskBuffer[InterruptHandler::TaskStackSize];
|
uint32_t InterruptHandler::TaskBuffer[InterruptHandler::TaskStackSize];
|
||||||
osStaticThreadDef_t InterruptHandler::TaskControlBlock;
|
osStaticThreadDef_t InterruptHandler::TaskControlBlock;
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ void InterruptHandler::init() {
|
|||||||
void InterruptHandler::Thread(const void *arg) {
|
void InterruptHandler::Thread(const void *arg) {
|
||||||
(void) arg;
|
(void) arg;
|
||||||
union fusb_status status;
|
union fusb_status status;
|
||||||
volatile uint32_t events;
|
uint32_t events;
|
||||||
bool notifSent = false;
|
bool notifSent = false;
|
||||||
while (true) {
|
while (true) {
|
||||||
/* If the INT_N line is low */
|
/* If the INT_N line is low */
|
||||||
|
|||||||
@@ -12,8 +12,6 @@
|
|||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
uint8_t PCBVersion = 0;
|
uint8_t PCBVersion = 0;
|
||||||
// File local variables
|
|
||||||
bool usb_pd_available = false;
|
|
||||||
bool settingsWereReset = false;
|
bool settingsWereReset = false;
|
||||||
// FreeRTOS variables
|
// FreeRTOS variables
|
||||||
|
|
||||||
@@ -32,44 +30,17 @@ uint32_t MOVTaskBuffer[MOVTaskStackSize];
|
|||||||
osStaticThreadDef_t MOVTaskControlBlock;
|
osStaticThreadDef_t MOVTaskControlBlock;
|
||||||
|
|
||||||
// End FreeRTOS
|
// End FreeRTOS
|
||||||
|
|
||||||
// Main sets up the hardware then hands over to the FreeRTOS kernel
|
// Main sets up the hardware then hands over to the FreeRTOS kernel
|
||||||
int main(void) {
|
int main(void) {
|
||||||
preRToSInit();
|
preRToSInit();
|
||||||
|
|
||||||
setTipX10Watts(0); // force tip off
|
setTipX10Watts(0); // force tip off
|
||||||
resetWatchdog();
|
resetWatchdog();
|
||||||
OLED::initialize(); // start up the LCD
|
|
||||||
OLED::setFont(0); // default to bigger font
|
OLED::setFont(0); // default to bigger font
|
||||||
// Testing for which accelerometer is mounted
|
// Testing for which accelerometer is mounted
|
||||||
resetWatchdog();
|
|
||||||
usb_pd_available = usb_pd_detect();
|
|
||||||
resetWatchdog();
|
|
||||||
settingsWereReset = restoreSettings(); // load the settings from flash
|
settingsWereReset = restoreSettings(); // load the settings from flash
|
||||||
#ifdef ACCEL_MMA
|
|
||||||
if (MMA8652FC::detect()) {
|
|
||||||
PCBVersion = 1;
|
|
||||||
MMA8652FC::initalize(); // this sets up the I2C registers
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
#ifdef ACCEL_LIS
|
|
||||||
if (LIS2DH12::detect()) {
|
|
||||||
PCBVersion = 2;
|
|
||||||
// Setup the ST Accelerometer
|
|
||||||
LIS2DH12::initalize(); // startup the accelerometer
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
PCBVersion = 3;
|
|
||||||
systemSettings.SleepTime = 0;
|
|
||||||
systemSettings.ShutdownTime = 0; // No accel -> disable sleep
|
|
||||||
systemSettings.sensitivity = 0;
|
|
||||||
}
|
|
||||||
resetWatchdog();
|
resetWatchdog();
|
||||||
|
|
||||||
/* Create the thread(s) */
|
/* Create the thread(s) */
|
||||||
/* definition and creation of GUITask */
|
/* definition and creation of GUITask */
|
||||||
|
|
||||||
osThreadStaticDef(GUITask, startGUITask, osPriorityBelowNormal, 0,
|
osThreadStaticDef(GUITask, startGUITask, osPriorityBelowNormal, 0,
|
||||||
GUITaskStackSize, GUITaskBuffer, &GUITaskControlBlock);
|
GUITaskStackSize, GUITaskBuffer, &GUITaskControlBlock);
|
||||||
GUITaskHandle = osThreadCreate(osThread(GUITask), NULL);
|
GUITaskHandle = osThreadCreate(osThread(GUITask), NULL);
|
||||||
|
|||||||
@@ -632,6 +632,7 @@ void showDebugMenu(void) {
|
|||||||
uint8_t idleScreenBGF[sizeof(idleScreenBG)];
|
uint8_t idleScreenBGF[sizeof(idleScreenBG)];
|
||||||
/* StartGUITask function */
|
/* StartGUITask function */
|
||||||
void startGUITask(void const *argument __unused) {
|
void startGUITask(void const *argument __unused) {
|
||||||
|
OLED::initialize(); // start up the LCD
|
||||||
|
|
||||||
uint8_t tempWarningState = 0;
|
uint8_t tempWarningState = 0;
|
||||||
bool buttonLockout = false;
|
bool buttonLockout = false;
|
||||||
|
|||||||
@@ -23,8 +23,28 @@
|
|||||||
uint8_t accelInit = 0;
|
uint8_t accelInit = 0;
|
||||||
uint32_t lastMovementTime = 0;
|
uint32_t lastMovementTime = 0;
|
||||||
void startMOVTask(void const *argument __unused) {
|
void startMOVTask(void const *argument __unused) {
|
||||||
OLED::setRotation(systemSettings.OrientationMode & 1);
|
#ifdef ACCEL_MMA
|
||||||
|
if (MMA8652FC::detect()) {
|
||||||
|
PCBVersion = 1;
|
||||||
|
MMA8652FC::initalize(); // this sets up the I2C registers
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
#ifdef ACCEL_LIS
|
||||||
|
if (LIS2DH12::detect()) {
|
||||||
|
PCBVersion = 2;
|
||||||
|
// Setup the ST Accelerometer
|
||||||
|
LIS2DH12::initalize(); // startup the accelerometer
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
PCBVersion = 3;
|
||||||
|
systemSettings.SleepTime = 0;
|
||||||
|
systemSettings.ShutdownTime = 0; // No accel -> disable sleep
|
||||||
|
systemSettings.sensitivity = 0;
|
||||||
|
}
|
||||||
postRToSInit();
|
postRToSInit();
|
||||||
|
OLED::setRotation(systemSettings.OrientationMode & 1);
|
||||||
|
|
||||||
lastMovementTime = 0;
|
lastMovementTime = 0;
|
||||||
int16_t datax[MOVFilter] = { 0 };
|
int16_t datax[MOVFilter] = { 0 };
|
||||||
int16_t datay[MOVFilter] = { 0 };
|
int16_t datay[MOVFilter] = { 0 };
|
||||||
|
|||||||
Reference in New Issue
Block a user