Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cores/esp8266/core_esp8266_phy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ static const uint8_t ICACHE_FLASH_ATTR phy_init_data[128] =
static bool spoof_init_data = false;

extern int __real_spi_flash_read(uint32_t addr, uint32_t* dst, size_t size);
extern int IRAM_ATTR __wrap_spi_flash_read(uint32_t addr, uint32_t* dst, size_t size);
extern int __wrap_spi_flash_read(uint32_t addr, uint32_t* dst, size_t size);
extern int __get_adc_mode();

/*
Expand Down Expand Up @@ -376,4 +376,4 @@ void user_rf_pre_init()

void IRAM_ATTR user_spi_flash_dio_to_qio_pre_init() {}

};
} // extern "C"
87 changes: 43 additions & 44 deletions cores/esp8266/core_esp8266_si2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Twi
uint8_t twi_rxBuffer[TWI_BUFFER_LENGTH];
volatile int twi_rxBufferIndex = 0;

void (*twi_onSlaveTransmit)(void);
void (*twi_onSlaveTransmit)();
void (*twi_onSlaveReceive)(uint8_t*, size_t);

// ETS queue/timer interfaces
Expand All @@ -136,23 +136,23 @@ class Twi
ETSTimer timer;

// Event/IRQ callbacks, so they can't use "this" and need to be static
static void IRAM_ATTR onSclChange(void);
static void IRAM_ATTR onSdaChange(void);
static void eventTask(ETSEvent* e);
static void IRAM_ATTR onTimer(void* unused);
static void onSclChange();
static void onSdaChange();
static void eventTask(ETSEvent* e);
static void onTimer(void*);

// Allow not linking in the slave code if there is no call to setAddress
bool _slaveEnabled = false;

// Internal use functions
void IRAM_ATTR busywait(unsigned int v);
bool write_start(void);
bool write_stop(void);
bool write_bit(bool bit);
bool read_bit(void);
bool write_byte(unsigned char byte);
unsigned char read_byte(bool nack);
void IRAM_ATTR onTwipEvent(uint8_t status);
void busywait(unsigned int v);
bool write_start();
bool write_stop();
bool write_bit(bool bit);
bool read_bit();
bool write_byte(unsigned char byte);
unsigned char read_byte(bool nack);
void onTwipEvent(uint8_t status);

// Handle the case where a slave needs to stretch the clock with a time-limited busy wait
inline void WAIT_CLOCK_STRETCH()
Expand All @@ -170,24 +170,24 @@ class Twi
}

// Generate a clock "valley" (at the end of a segment, just before a repeated start)
void twi_scl_valley(void);
void twi_scl_valley();

public:
void setClock(unsigned int freq);
void setClockStretchLimit(uint32_t limit);
void init(unsigned char sda, unsigned char scl);
void setAddress(uint8_t address);
unsigned char writeTo(unsigned char address, unsigned char* buf, unsigned int len,
void setClock(unsigned int freq);
void setClockStretchLimit(uint32_t limit);
void init(unsigned char sda, unsigned char scl);
void setAddress(uint8_t address);
unsigned char writeTo(unsigned char address, unsigned char* buf, unsigned int len,
unsigned char sendStop);
unsigned char readFrom(unsigned char address, unsigned char* buf, unsigned int len,
unsigned char sendStop);
unsigned char readFrom(unsigned char address, unsigned char* buf, unsigned int len,
unsigned char sendStop);
uint8_t status();
uint8_t transmit(const uint8_t* data, uint8_t length);
void attachSlaveRxEvent(void (*function)(uint8_t*, size_t));
void attachSlaveTxEvent(void (*function)(void));
void IRAM_ATTR reply(uint8_t ack);
void IRAM_ATTR releaseBus(void);
void enableSlave();
uint8_t status();
uint8_t transmit(const uint8_t* data, uint8_t length);
void attachSlaveRxEvent(void (*function)(uint8_t*, size_t));
void attachSlaveTxEvent(void (*function)());
void reply(uint8_t ack);
void releaseBus();
void enableSlave();
};

static Twi twi;
Expand Down Expand Up @@ -275,7 +275,7 @@ void IRAM_ATTR Twi::busywait(unsigned int v)
}
}

bool Twi::write_start(void)
bool Twi::write_start()
{
SCL_HIGH(twi_scl);
SDA_HIGH(twi_sda);
Expand All @@ -294,7 +294,7 @@ bool Twi::write_start(void)
return true;
}

bool Twi::write_stop(void)
bool Twi::write_stop()
{
SCL_LOW(twi_scl);
SDA_LOW(twi_sda);
Expand Down Expand Up @@ -326,7 +326,7 @@ bool Twi::write_bit(bool bit)
return true;
}

bool Twi::read_bit(void)
bool Twi::read_bit()
{
SCL_LOW(twi_scl);
SDA_HIGH(twi_sda);
Expand Down Expand Up @@ -447,7 +447,7 @@ unsigned char Twi::readFrom(unsigned char address, unsigned char* buf, unsigned
return 0;
}

void Twi::twi_scl_valley(void)
void Twi::twi_scl_valley()
{
SCL_LOW(twi_scl);
busywait(twi_dcount);
Expand Down Expand Up @@ -510,14 +510,14 @@ uint8_t Twi::transmit(const uint8_t* data, uint8_t length)
return 0;
}

void Twi::attachSlaveRxEvent(void (*function)(uint8_t*, size_t))
void Twi::attachSlaveRxEvent(void (*cb)(uint8_t*, size_t))
{
twi_onSlaveReceive = function;
twi_onSlaveReceive = cb;
}

void Twi::attachSlaveTxEvent(void (*function)(void))
void Twi::attachSlaveTxEvent(void (*cb)())
{
twi_onSlaveTransmit = function;
twi_onSlaveTransmit = cb;
}

// DO NOT INLINE, inlining reply() in combination with compiler optimizations causes function
Expand All @@ -541,7 +541,7 @@ void IRAM_ATTR Twi::reply(uint8_t ack)
}
}

void IRAM_ATTR Twi::releaseBus(void)
void IRAM_ATTR Twi::releaseBus()
{
// release bus
// TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT);
Expand Down Expand Up @@ -660,9 +660,8 @@ void IRAM_ATTR Twi::onTwipEvent(uint8_t status)
}
}

void IRAM_ATTR Twi::onTimer(void* unused)
void IRAM_ATTR Twi::onTimer(void*)
{
(void)unused;
twi.releaseBus();
twi.onTwipEvent(TW_BUS_ERROR);
twi.twip_mode = TWIPM_WAIT;
Expand Down Expand Up @@ -709,7 +708,7 @@ void Twi::eventTask(ETSEvent* e)
// Shorthand for if the state is any of the or'd bitmask x
#define IFSTATE(x) if (twip_state_mask & (x))

void IRAM_ATTR Twi::onSclChange(void)
void IRAM_ATTR Twi::onSclChange()
{
unsigned int sda;
unsigned int scl;
Expand Down Expand Up @@ -907,7 +906,7 @@ void IRAM_ATTR Twi::onSclChange(void)
}
}

void IRAM_ATTR Twi::onSdaChange(void)
void IRAM_ATTR Twi::onSdaChange()
{
unsigned int sda;
unsigned int scl;
Expand Down Expand Up @@ -1054,7 +1053,7 @@ extern "C"
twi.attachSlaveRxEvent(cb);
}

void twi_attachSlaveTxEvent(void (*cb)(void))
void twi_attachSlaveTxEvent(void (*cb)())
{
twi.attachSlaveTxEvent(cb);
}
Expand All @@ -1064,12 +1063,12 @@ extern "C"
twi.reply(r);
}

void twi_releaseBus(void)
void twi_releaseBus()
{
twi.releaseBus();
}

void twi_enableSlaveMode(void)
void twi_enableSlaveMode()
{
twi.enableSlave();
}
Expand Down
18 changes: 10 additions & 8 deletions cores/esp8266/core_esp8266_waveform_phase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,21 @@
#include "ets_sys.h"
#include <atomic>

extern "C" {

extern "C" void enablePhaseLockedWaveform (void)
void enablePhaseLockedWaveform ()
{
// Does nothing, added to app to enable linking these versions
// of the waveform functions instead of the default.
DEBUGV("Enabling phase locked waveform generator\n");
}

// No-op calls to override the PWM implementation
extern "C" void _setPWMFreq_weak(uint32_t freq) { (void) freq; }
extern "C" IRAM_ATTR bool _stopPWM_weak(int pin) { (void) pin; return false; }
extern "C" bool _setPWM_weak(int pin, uint32_t val, uint32_t range) { (void) pin; (void) val; (void) range; return false; }
void _setPWMFreq_weak(uint32_t) {}
bool IRAM_ATTR _stopPWM_weak(int) { return false; }
bool _setPWM_weak(int, uint32_t, uint32_t) { return false; }

} // extern "C"

// Timer is 80MHz fixed. 160MHz CPU frequency need scaling.
constexpr bool ISCPUFREQ160MHZ = clockCyclesPerMicrosecond() == 160;
Expand Down Expand Up @@ -111,7 +113,7 @@ namespace {
}

// Interrupt on/off control
static IRAM_ATTR void timer1Interrupt();
static void timer1Interrupt();

// Non-speed critical bits
#pragma GCC optimize ("Os")
Expand Down Expand Up @@ -218,7 +220,7 @@ int startWaveformClockCycles_weak(uint8_t pin, uint32_t highCcys, uint32_t lowCc
}

// Stops a waveform on a pin
IRAM_ATTR int stopWaveform_weak(uint8_t pin) {
int IRAM_ATTR stopWaveform_weak(uint8_t pin) {
// Can't possibly need to stop anything if there is no timer active
if (!waveform.timer1Running) {
return false;
Expand Down Expand Up @@ -252,7 +254,7 @@ IRAM_ATTR int stopWaveform_weak(uint8_t pin) {

// For dynamic CPU clock frequency switch in loop the scaling logic would have to be adapted.
// Using constexpr makes sure that the CPU clock frequency is compile-time fixed.
static inline IRAM_ATTR int32_t scaleCcys(const int32_t ccys, const bool isCPU2X) {
static inline int32_t IRAM_ATTR scaleCcys(const int32_t ccys, const bool isCPU2X) {
if (ISCPUFREQ160MHZ) {
return isCPU2X ? ccys : (ccys >> 1);
}
Expand All @@ -261,7 +263,7 @@ static inline IRAM_ATTR int32_t scaleCcys(const int32_t ccys, const bool isCPU2X
}
}

static IRAM_ATTR void timer1Interrupt() {
static void IRAM_ATTR timer1Interrupt() {
const uint32_t isrStartCcy = ESP.getCycleCount();
int32_t clockDrift = isrStartCcy - waveform.nextEventCcy;
const bool isCPU2X = CPU2X & 1;
Expand Down
Loading
Loading