mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
committed by
david gauchard
parent
98125f8860
commit
eea9999dc5
@ -1,22 +1,22 @@
|
||||
/*
|
||||
SPISlave library for esp8266
|
||||
SPISlave library for esp8266
|
||||
|
||||
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "SPISlave.h"
|
||||
extern "C" {
|
||||
@ -25,35 +25,31 @@ extern "C" {
|
||||
|
||||
void SPISlaveClass::_data_rx(uint8_t * data, uint8_t len)
|
||||
{
|
||||
if (_data_cb)
|
||||
{
|
||||
if(_data_cb) {
|
||||
_data_cb(data, len);
|
||||
}
|
||||
}
|
||||
void SPISlaveClass::_status_rx(uint32_t data)
|
||||
{
|
||||
if (_status_cb)
|
||||
{
|
||||
if(_status_cb) {
|
||||
_status_cb(data);
|
||||
}
|
||||
}
|
||||
void SPISlaveClass::_data_tx(void)
|
||||
{
|
||||
if (_data_sent_cb)
|
||||
{
|
||||
if(_data_sent_cb) {
|
||||
_data_sent_cb();
|
||||
}
|
||||
}
|
||||
void SPISlaveClass::_status_tx(void)
|
||||
{
|
||||
if (_status_sent_cb)
|
||||
{
|
||||
if(_status_sent_cb) {
|
||||
_status_sent_cb();
|
||||
}
|
||||
}
|
||||
void SPISlaveClass::_s_data_rx(void *arg, uint8_t * data, uint8_t len)
|
||||
{
|
||||
reinterpret_cast<SPISlaveClass*>(arg)->_data_rx(data, len);
|
||||
reinterpret_cast<SPISlaveClass*>(arg)->_data_rx(data,len);
|
||||
}
|
||||
void SPISlaveClass::_s_status_rx(void *arg, uint32_t data)
|
||||
{
|
||||
@ -86,8 +82,7 @@ void SPISlaveClass::end()
|
||||
}
|
||||
void SPISlaveClass::setData(uint8_t * data, size_t len)
|
||||
{
|
||||
if (len > 32)
|
||||
{
|
||||
if(len > 32) {
|
||||
len = 32;
|
||||
}
|
||||
hspi_slave_setData(data, len);
|
||||
|
@ -1,22 +1,22 @@
|
||||
/*
|
||||
SPISlave library for esp8266
|
||||
SPISlave library for esp8266
|
||||
|
||||
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#ifndef _SPISLAVE_H_INCLUDED
|
||||
#define _SPISLAVE_H_INCLUDED
|
||||
|
@ -1,22 +1,22 @@
|
||||
/*
|
||||
SPISlave library for esp8266
|
||||
SPISlave library for esp8266
|
||||
|
||||
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "hspi_slave.h"
|
||||
#include "esp8266_peri.h"
|
||||
@ -35,59 +35,48 @@ void ICACHE_RAM_ATTR _hspi_slave_isr_handler(void *arg)
|
||||
|
||||
istatus = SPIIR;
|
||||
|
||||
if (istatus & (1 << SPII1)) //SPI1 ISR
|
||||
{
|
||||
if(istatus & (1 << SPII1)) { //SPI1 ISR
|
||||
status = SPI1S;
|
||||
SPI1S &= ~(0x3E0);//disable interrupts
|
||||
SPI1S |= SPISSRES;//reset
|
||||
SPI1S &= ~(0x1F);//clear interrupts
|
||||
SPI1S |= (0x3E0);//enable interrupts
|
||||
|
||||
if ((status & SPISRBIS) != 0 && (_hspi_slave_tx_data_cb))
|
||||
{
|
||||
if((status & SPISRBIS) != 0 && (_hspi_slave_tx_data_cb)) {
|
||||
_hspi_slave_tx_data_cb(arg);
|
||||
}
|
||||
if ((status & SPISRSIS) != 0 && (_hspi_slave_tx_status_cb))
|
||||
{
|
||||
if((status & SPISRSIS) != 0 && (_hspi_slave_tx_status_cb)) {
|
||||
_hspi_slave_tx_status_cb(arg);
|
||||
}
|
||||
if ((status & SPISWSIS) != 0 && (_hspi_slave_rx_status_cb))
|
||||
{
|
||||
if((status & SPISWSIS) != 0 && (_hspi_slave_rx_status_cb)) {
|
||||
uint32_t s = SPI1WS;
|
||||
_hspi_slave_rx_status_cb(arg, s);
|
||||
}
|
||||
if ((status & SPISWBIS) != 0 && (_hspi_slave_rx_data_cb))
|
||||
{
|
||||
if((status & SPISWBIS) != 0 && (_hspi_slave_rx_data_cb)) {
|
||||
uint8_t i;
|
||||
uint32_t data;
|
||||
_hspi_slave_buffer[32] = 0;
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
data = SPI1W(i);
|
||||
_hspi_slave_buffer[i << 2] = data & 0xff;
|
||||
_hspi_slave_buffer[(i << 2) + 1] = (data >> 8) & 0xff;
|
||||
_hspi_slave_buffer[(i << 2) + 2] = (data >> 16) & 0xff;
|
||||
_hspi_slave_buffer[(i << 2) + 3] = (data >> 24) & 0xff;
|
||||
for(i=0; i<8; i++) {
|
||||
data=SPI1W(i);
|
||||
_hspi_slave_buffer[i<<2] = data & 0xff;
|
||||
_hspi_slave_buffer[(i<<2)+1] = (data >> 8) & 0xff;
|
||||
_hspi_slave_buffer[(i<<2)+2] = (data >> 16) & 0xff;
|
||||
_hspi_slave_buffer[(i<<2)+3] = (data >> 24) & 0xff;
|
||||
}
|
||||
_hspi_slave_rx_data_cb(arg, &_hspi_slave_buffer[0], 32);
|
||||
}
|
||||
}
|
||||
else if (istatus & (1 << SPII0)) //SPI0 ISR
|
||||
{
|
||||
} else if(istatus & (1 << SPII0)) { //SPI0 ISR
|
||||
SPI0S &= ~(0x3ff);//clear SPI ISR
|
||||
}
|
||||
else if (istatus & (1 << SPII2)) {} //I2S ISR
|
||||
} else if(istatus & (1 << SPII2)) {} //I2S ISR
|
||||
}
|
||||
|
||||
void hspi_slave_begin(uint8_t status_len, void * arg)
|
||||
{
|
||||
status_len &= 7;
|
||||
if (status_len > 4)
|
||||
{
|
||||
if(status_len > 4) {
|
||||
status_len = 4; //max 32 bits
|
||||
}
|
||||
if (status_len == 0)
|
||||
{
|
||||
if(status_len == 0) {
|
||||
status_len = 1; //min 8 bits
|
||||
}
|
||||
|
||||
@ -108,25 +97,25 @@ void hspi_slave_begin(uint8_t status_len, void * arg)
|
||||
// Setting SPIC2MOSIDN_S is probably not critical, all tests run fine with this setting
|
||||
SPI1C2 = (0x2 << SPIC2MOSIDN_S) | (0x1 << SPIC2MISODM_S);
|
||||
|
||||
ETS_SPI_INTR_ATTACH(_hspi_slave_isr_handler, arg);
|
||||
ETS_SPI_INTR_ATTACH(_hspi_slave_isr_handler,arg);
|
||||
ETS_SPI_INTR_ENABLE();
|
||||
}
|
||||
|
||||
void hspi_slave_end()
|
||||
{
|
||||
ETS_SPI_INTR_DISABLE();
|
||||
ETS_SPI_INTR_ATTACH(NULL, NULL);
|
||||
ETS_SPI_INTR_DISABLE();
|
||||
ETS_SPI_INTR_ATTACH(NULL, NULL);
|
||||
|
||||
pinMode(SS, INPUT);
|
||||
pinMode(SCK, INPUT);
|
||||
pinMode(MISO, INPUT);
|
||||
pinMode(MOSI, INPUT);
|
||||
pinMode(SS, INPUT);
|
||||
pinMode(SCK, INPUT);
|
||||
pinMode(MISO, INPUT);
|
||||
pinMode(MOSI, INPUT);
|
||||
|
||||
// defaults
|
||||
SPI1S = 0;
|
||||
SPI1U = SPIUSSE | SPIUCOMMAND;
|
||||
SPI1S1 = 0;
|
||||
SPI1P = B110;
|
||||
// defaults
|
||||
SPI1S = 0;
|
||||
SPI1U = SPIUSSE | SPIUCOMMAND;
|
||||
SPI1S1 = 0;
|
||||
SPI1P = B110;
|
||||
}
|
||||
|
||||
void ICACHE_RAM_ATTR hspi_slave_setStatus(uint32_t status)
|
||||
@ -141,13 +130,11 @@ void hspi_slave_setData(uint8_t *data, uint8_t len)
|
||||
uint8_t bi = 0;
|
||||
uint8_t wi = 8;
|
||||
|
||||
for (i = 0; i < 32; i++)
|
||||
{
|
||||
out |= (i < len) ? (data[i] << (bi * 8)) : 0;
|
||||
for(i=0; i<32; i++) {
|
||||
out |= (i<len)?(data[i] << (bi * 8)):0;
|
||||
bi++;
|
||||
bi &= 3;
|
||||
if (!bi)
|
||||
{
|
||||
if(!bi) {
|
||||
SPI1W(wi) = out;
|
||||
out = 0;
|
||||
wi++;
|
||||
|
@ -1,22 +1,22 @@
|
||||
/*
|
||||
SPISlave library for esp8266
|
||||
SPISlave library for esp8266
|
||||
|
||||
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#ifndef _HSPISLAVE_H_INCLUDED
|
||||
#define _HSPISLAVE_H_INCLUDED
|
||||
|
Reference in New Issue
Block a user