Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize peripherals on both cores to prevent lockups in webconfig #776

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions headers/gp2040aux.h
Expand Up @@ -10,6 +10,7 @@

#include "gpaddon.h"
#include "addonmanager.h"
#include "peripheralmanager.h"

class GP2040Aux {
public:
Expand Down
8 changes: 6 additions & 2 deletions headers/peripheralmanager.h
Expand Up @@ -9,8 +9,8 @@

class PeripheralManager {
public:
PeripheralManager();
~PeripheralManager() {}
PeripheralManager(){}
PeripheralManager(PeripheralManager const&) = delete;
void operator=(PeripheralManager const&) = delete;
static PeripheralManager& getInstance() // Thread-safe storage ensures cross-thread talk
{
Expand All @@ -22,6 +22,10 @@ class PeripheralManager {
PeripheralSPI* getSPI(uint8_t block);
PeripheralUSB* getUSB(uint8_t block);

void initUSB();
void initI2C();
void initSPI();

bool isI2CEnabled(uint8_t block);
bool isSPIEnabled(uint8_t block);
bool isUSBEnabled(uint8_t block);
Expand Down
4 changes: 4 additions & 0 deletions src/gp2040.cpp
Expand Up @@ -48,6 +48,10 @@ GP2040::~GP2040() {
}

void GP2040::setup() {
PeripheralManager::getInstance().initI2C();
PeripheralManager::getInstance().initSPI();
PeripheralManager::getInstance().initUSB();

// Reduce CPU if any USB host add-on is enabled
const AddonOptions & addonOptions = Storage::getInstance().getAddonOptions();
if ( addonOptions.keyboardHostOptions.enabled ||
Expand Down
4 changes: 4 additions & 0 deletions src/gp2040aux.cpp
Expand Up @@ -25,6 +25,10 @@ GP2040Aux::~GP2040Aux() {
}

void GP2040Aux::setup() {
PeripheralManager::getInstance().initI2C();
PeripheralManager::getInstance().initSPI();
PeripheralManager::getInstance().initUSB();

InputHistoryAddon* inputHistoryAddon = new InputHistoryAddon();
I2CDisplayAddon* i2CDisplayAddon = new I2CDisplayAddon();

Expand Down
15 changes: 10 additions & 5 deletions src/peripheralmanager.cpp
@@ -1,16 +1,21 @@
#include "peripheralmanager.h"
#include "storagemanager.h"

PeripheralManager::PeripheralManager() {
void PeripheralManager::initUSB(){
const PeripheralOptions& peripheralOptions = Storage::getInstance().getPeripheralOptions();
if (peripheralOptions.blockUSB0.enabled) blockUSB0.setConfig(0, peripheralOptions.blockUSB0.dp, peripheralOptions.blockUSB0.enable5v, peripheralOptions.blockUSB0.order);
}

void PeripheralManager::initI2C(){
const PeripheralOptions& peripheralOptions = Storage::getInstance().getPeripheralOptions();
if (peripheralOptions.blockI2C0.enabled) blockI2C0.setConfig(0, peripheralOptions.blockI2C0.sda, peripheralOptions.blockI2C0.scl, peripheralOptions.blockI2C0.speed);
if (peripheralOptions.blockI2C1.enabled) blockI2C1.setConfig(1, peripheralOptions.blockI2C1.sda, peripheralOptions.blockI2C1.scl, peripheralOptions.blockI2C1.speed);

if (peripheralOptions.blockI2C1.enabled) blockI2C1.setConfig(1, peripheralOptions.blockI2C1.sda, peripheralOptions.blockI2C1.scl, peripheralOptions.blockI2C1.speed);
}

void PeripheralManager::initSPI(){
const PeripheralOptions& peripheralOptions = Storage::getInstance().getPeripheralOptions();
if (peripheralOptions.blockSPI0.enabled) blockSPI0.setConfig(0, peripheralOptions.blockSPI0.tx, peripheralOptions.blockSPI0.rx, peripheralOptions.blockSPI0.sck, peripheralOptions.blockSPI0.cs);
if (peripheralOptions.blockSPI1.enabled) blockSPI1.setConfig(1, peripheralOptions.blockSPI1.tx, peripheralOptions.blockSPI1.rx, peripheralOptions.blockSPI1.sck, peripheralOptions.blockSPI1.cs);

if (peripheralOptions.blockUSB0.enabled) blockUSB0.setConfig(0, peripheralOptions.blockUSB0.dp, peripheralOptions.blockUSB0.enable5v, peripheralOptions.blockUSB0.order);
}

PeripheralI2C* PeripheralManager::getI2C(uint8_t block) {
Expand Down