dynamically enable or disable QSPI by default
This commit is contained in:
parent
d8257380d7
commit
af1291ec28
@ -30,7 +30,7 @@
|
||||
#define MICROPY_HW_BOARD_NAME "Makerdiary M60 Keyboard"
|
||||
#define MICROPY_HW_MCU_NAME "nRF52840"
|
||||
|
||||
// not use the RGB LEDs to save energy
|
||||
// RGB LEDs use PWM peripheral, avoid using them to save energy
|
||||
// #define CP_RGB_STATUS_R (&pin_P0_30)
|
||||
// #define CP_RGB_STATUS_G (&pin_P0_29)
|
||||
// #define CP_RGB_STATUS_B (&pin_P0_31)
|
||||
@ -41,7 +41,6 @@
|
||||
#define MICROPY_QSPI_DATA3 NRF_GPIO_PIN_MAP(1, 12)
|
||||
#define MICROPY_QSPI_SCK NRF_GPIO_PIN_MAP(1, 11)
|
||||
#define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(1, 13)
|
||||
#define MICROPY_QSPI_OFF_WHEN_SLEEP
|
||||
|
||||
#define BOARD_HAS_CRYSTAL 1
|
||||
|
||||
|
@ -65,7 +65,7 @@
|
||||
#include "common-hal/audiopwmio/PWMAudioOut.h"
|
||||
#endif
|
||||
|
||||
#if defined(MICROPY_QSPI_CS) && defined(MICROPY_QSPI_OFF_WHEN_SLEEP)
|
||||
#if defined(MICROPY_QSPI_CS)
|
||||
extern void qspi_disable(void);
|
||||
#endif
|
||||
|
||||
@ -299,7 +299,7 @@ void port_interrupt_after_ticks(uint32_t ticks) {
|
||||
}
|
||||
|
||||
void port_sleep_until_interrupt(void) {
|
||||
#if defined(MICROPY_QSPI_CS) && defined(MICROPY_QSPI_OFF_WHEN_SLEEP)
|
||||
#if defined(MICROPY_QSPI_CS)
|
||||
qspi_disable();
|
||||
#endif
|
||||
|
||||
|
@ -39,7 +39,21 @@
|
||||
#include "supervisor/shared/external_flash/qspi_flash.h"
|
||||
|
||||
// When USB is disconnected, disable QSPI in sleep mode to save energy
|
||||
#if defined(MICROPY_QSPI_OFF_WHEN_SLEEP)
|
||||
void qspi_disable(void)
|
||||
{
|
||||
// If VBUS is detected, no need to disable QSPI
|
||||
if (NRF_QSPI->ENABLE && !(NRF_POWER->USBREGSTATUS & POWER_USBREGSTATUS_VBUSDETECT_Msk)) {
|
||||
// Keep CS high when QSPI is diabled
|
||||
nrf_gpio_cfg_output(MICROPY_QSPI_CS);
|
||||
nrf_gpio_pin_write(MICROPY_QSPI_CS, 1);
|
||||
|
||||
// Workaround to disable QSPI according to nRF52840 Revision 1 Errata V1.4 - 3.8
|
||||
NRF_QSPI->TASKS_DEACTIVATE = 1;
|
||||
*(volatile uint32_t *)0x40029054 = 1;
|
||||
NRF_QSPI->ENABLE = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void qspi_enable(void)
|
||||
{
|
||||
if (NRF_QSPI->ENABLE) {
|
||||
@ -60,30 +74,6 @@ void qspi_enable(void)
|
||||
} while (--remaining_attempts);
|
||||
}
|
||||
|
||||
void qspi_disable(void)
|
||||
{
|
||||
// Turn off QSPI when USB is disconnected
|
||||
if (NRF_QSPI->ENABLE && !(NRF_POWER->USBREGSTATUS & POWER_USBREGSTATUS_VBUSDETECT_Msk)) {
|
||||
// Keep CS high when QSPI is diabled
|
||||
nrf_gpio_cfg_output(MICROPY_QSPI_CS);
|
||||
nrf_gpio_pin_write(MICROPY_QSPI_CS, 1);
|
||||
|
||||
// Workaround to disable QSPI according to nRF52840 Revision 1 Errata V1.4 - 3.8
|
||||
NRF_QSPI->TASKS_DEACTIVATE = 1;
|
||||
*(volatile uint32_t *)0x40029054 = 1;
|
||||
NRF_QSPI->ENABLE = 0;
|
||||
}
|
||||
}
|
||||
#else
|
||||
void qspi_enable(void)
|
||||
{
|
||||
}
|
||||
|
||||
void qspi_disable(void)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
bool spi_flash_command(uint8_t command) {
|
||||
qspi_enable();
|
||||
nrf_qspi_cinstr_conf_t cinstr_cfg = {
|
||||
|
Loading…
Reference in New Issue
Block a user