Skip to content

Spi slave improvments #6580

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

Merged
merged 11 commits into from
Oct 31, 2019
9 changes: 6 additions & 3 deletions libraries/SPISlave/src/SPISlave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@ void SPISlaveClass::_s_status_tx(void *arg)
{
reinterpret_cast<SPISlaveClass*>(arg)->_status_tx();
}

void SPISlaveClass::begin()
void SPISlaveClass::begin() //backwards compatibility
{
begin(4);
}
void SPISlaveClass::begin(uint8_t statusLength)
{
hspi_slave_onData(&_s_data_rx);
hspi_slave_onDataSent(&_s_data_tx);
hspi_slave_onStatus(&_s_status_rx);
hspi_slave_onStatusSent(&_s_status_tx);
hspi_slave_begin(4, this);
hspi_slave_begin(statusLength, this);
}
void SPISlaveClass::end()
{
Expand Down
1 change: 1 addition & 0 deletions libraries/SPISlave/src/SPISlave.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class SPISlaveClass
{}
~SPISlaveClass() {}
void begin();
void begin(uint8_t statusLength);
void end();
void setData(uint8_t * data, size_t len);
void setData(const char * data)
Expand Down
11 changes: 8 additions & 3 deletions libraries/SPISlave/src/hspi_slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ void ICACHE_RAM_ATTR _hspi_slave_isr_handler(void *arg)

void hspi_slave_begin(uint8_t status_len, void * arg)
{
status_len &= 7;
if(status_len > 4) {
status_len = 4; //max 32 bits
}
if(status_len == 0) {
else if(status_len == 0) {
status_len = 1; //min 8 bits
}

Expand All @@ -85,7 +84,13 @@ void hspi_slave_begin(uint8_t status_len, void * arg)
pinMode(MISO, SPECIAL);
pinMode(MOSI, SPECIAL);

SPI1S = SPISE | SPISBE | 0x3E0; // SPI_SLAVE_REG
SPI1S = SPISE | SPISBE | SPISTRIE | SPISWBIE | SPISRSIE | SPISWSIE | SPISRBIE; //(0x63E0)
//setting config bits in SPI_SLAVE_REG, defined in "esp8266_peri.h" :
//SPISE - spi slave enable
//SPISBE - allows work (read/write) with buffer, without this only? status available
//SPISTRIE - enables TRANS?? interrupt
//other SPISxxIE - enables corresponding interrupts (read(R)/write(W) status(S) and buffer(B))

SPI1U = SPIUMISOH | SPIUCOMMAND | SPIUSSE; // SPI_USER_REG
SPI1CLK = 0;
SPI1U2 = (7 << SPILCOMMAND); // SPI_USER2_REG
Expand Down