Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move I2C initalisations into more logical spots
  • Loading branch information
Ralim committed Sep 5, 2020
1 parent d9c05db commit d48b279
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 58 deletions.
2 changes: 1 addition & 1 deletion workspace/TS100/Core/BSP/Miniware/Setup.c
Expand Up @@ -30,7 +30,7 @@ static void MX_TIM2_Init(void);
static void MX_DMA_Init(void);
static void MX_GPIO_Init(void);
static void MX_ADC2_Init(void);

#define SWD_ENABLE
void Setup_HAL() {
SystemClock_Config();

Expand Down
2 changes: 1 addition & 1 deletion workspace/TS100/Core/BSP/Miniware/flash.c
Expand Up @@ -23,7 +23,7 @@ uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) {
__HAL_FLASH_CLEAR_FLAG(
FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_BSY);
HAL_FLASH_Unlock();
HAL_Delay(10);
HAL_Delay(1);
resetWatchdog();
HAL_FLASHEx_Erase(&pEraseInit, &failingAddress);
//^ Erase the page of flash (1024 bytes on this stm32)
Expand Down
4 changes: 2 additions & 2 deletions workspace/TS100/Core/BSP/Miniware/fusb302b.cpp
Expand Up @@ -144,12 +144,12 @@ void fusb_send_hardrst() {

void fusb_setup() {
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.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
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);

if (!I2CBB::lock2()) {
Expand Down
9 changes: 4 additions & 5 deletions workspace/TS100/Core/BSP/Miniware/postRTOS.cpp
Expand Up @@ -12,11 +12,10 @@

// Initialisation to be performed with scheduler active
void postRToSInit() {

/* Init the IPC objects */
FRToSI2C::FRToSInit();
#ifdef POW_PD
//Spawn all of the USB-C processors
fusb302_start_processing();
if (usb_pd_detect() == true) {
//Spawn all of the USB-C processors
fusb302_start_processing();
}
#endif
}
8 changes: 2 additions & 6 deletions workspace/TS100/Core/BSP/Miniware/preRTOS.cpp
Expand Up @@ -17,13 +17,9 @@ void preRToSInit() {
*/
HAL_Init();
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
I2CBB::init();

#endif

/* Init the IPC objects */
FRToSI2C::FRToSInit();
}
13 changes: 2 additions & 11 deletions workspace/TS100/Core/Drivers/FUSB302/fusbpd.cpp
Expand Up @@ -17,22 +17,13 @@
#include "int_n.h"
#include "hard_reset.h"



void fusb302_start_processing() {
/* Initialize the FUSB302B */
resetWatchdog();
fusb_setup();
resetWatchdog();
/* Create the policy engine thread. */
ResetHandler::init();
PolicyEngine::init();

/* Create the protocol layer threads. */
ProtocolReceive::init();
ProtocolTransmit::init();
ResetHandler::init();
resetWatchdog();
/* Create the INT_N thread. */
ProtocolReceive::init();
InterruptHandler::init();
}
#endif
4 changes: 2 additions & 2 deletions workspace/TS100/Core/Drivers/FUSB302/int_n.cpp
Expand Up @@ -28,7 +28,7 @@
#include "task.h"
#include "BSP.h"

osThreadId InterruptHandler::TaskHandle=NULL;
osThreadId InterruptHandler::TaskHandle = NULL;
uint32_t InterruptHandler::TaskBuffer[InterruptHandler::TaskStackSize];
osStaticThreadDef_t InterruptHandler::TaskControlBlock;

Expand All @@ -41,7 +41,7 @@ void InterruptHandler::init() {
void InterruptHandler::Thread(const void *arg) {
(void) arg;
union fusb_status status;
volatile uint32_t events;
uint32_t events;
bool notifSent = false;
while (true) {
/* If the INT_N line is low */
Expand Down
29 changes: 0 additions & 29 deletions workspace/TS100/Core/Src/main.cpp
Expand Up @@ -12,8 +12,6 @@
#include "Settings.h"
#include "cmsis_os.h"
uint8_t PCBVersion = 0;
// File local variables
bool usb_pd_available = false;
bool settingsWereReset = false;
// FreeRTOS variables

Expand All @@ -32,44 +30,17 @@ uint32_t MOVTaskBuffer[MOVTaskStackSize];
osStaticThreadDef_t MOVTaskControlBlock;

// End FreeRTOS

// Main sets up the hardware then hands over to the FreeRTOS kernel
int main(void) {
preRToSInit();

setTipX10Watts(0); // force tip off
resetWatchdog();
OLED::initialize(); // start up the LCD
OLED::setFont(0); // default to bigger font
// Testing for which accelerometer is mounted
resetWatchdog();
usb_pd_available = usb_pd_detect();
resetWatchdog();
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();

/* Create the thread(s) */
/* definition and creation of GUITask */

osThreadStaticDef(GUITask, startGUITask, osPriorityBelowNormal, 0,
GUITaskStackSize, GUITaskBuffer, &GUITaskControlBlock);
GUITaskHandle = osThreadCreate(osThread(GUITask), NULL);
Expand Down
1 change: 1 addition & 0 deletions workspace/TS100/Core/Threads/GUIThread.cpp
Expand Up @@ -632,6 +632,7 @@ void showDebugMenu(void) {
uint8_t idleScreenBGF[sizeof(idleScreenBG)];
/* StartGUITask function */
void startGUITask(void const *argument __unused) {
OLED::initialize(); // start up the LCD

uint8_t tempWarningState = 0;
bool buttonLockout = false;
Expand Down
22 changes: 21 additions & 1 deletion workspace/TS100/Core/Threads/MOVThread.cpp
Expand Up @@ -23,8 +23,28 @@
uint8_t accelInit = 0;
uint32_t lastMovementTime = 0;
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();
OLED::setRotation(systemSettings.OrientationMode & 1);

lastMovementTime = 0;
int16_t datax[MOVFilter] = { 0 };
int16_t datay[MOVFilter] = { 0 };
Expand Down

0 comments on commit d48b279

Please sign in to comment.