mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-19 09:41:20 +00:00
refactor(examples): reformat peripheral examples with astyle_py
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
#include "driver/spi_slave.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
|
||||
/*
|
||||
SPI receiver (slave) example.
|
||||
|
||||
@@ -71,7 +70,6 @@ Pins in use. The SPI Master can use the GPIO mux, so feel free to change these i
|
||||
|
||||
#endif //CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
|
||||
|
||||
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
#define RCV_HOST HSPI_HOST
|
||||
|
||||
@@ -80,48 +78,48 @@ Pins in use. The SPI Master can use the GPIO mux, so feel free to change these i
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//Called after a transaction is queued and ready for pickup by master. We use this to set the handshake line high.
|
||||
void my_post_setup_cb(spi_slave_transaction_t *trans) {
|
||||
void my_post_setup_cb(spi_slave_transaction_t *trans)
|
||||
{
|
||||
gpio_set_level(GPIO_HANDSHAKE, 1);
|
||||
}
|
||||
|
||||
//Called after transaction is sent/received. We use this to set the handshake line low.
|
||||
void my_post_trans_cb(spi_slave_transaction_t *trans) {
|
||||
void my_post_trans_cb(spi_slave_transaction_t *trans)
|
||||
{
|
||||
gpio_set_level(GPIO_HANDSHAKE, 0);
|
||||
}
|
||||
|
||||
//Main application
|
||||
void app_main(void)
|
||||
{
|
||||
int n=0;
|
||||
int n = 0;
|
||||
esp_err_t ret;
|
||||
|
||||
//Configuration for the SPI bus
|
||||
spi_bus_config_t buscfg={
|
||||
.mosi_io_num=GPIO_MOSI,
|
||||
.miso_io_num=GPIO_MISO,
|
||||
.sclk_io_num=GPIO_SCLK,
|
||||
spi_bus_config_t buscfg = {
|
||||
.mosi_io_num = GPIO_MOSI,
|
||||
.miso_io_num = GPIO_MISO,
|
||||
.sclk_io_num = GPIO_SCLK,
|
||||
.quadwp_io_num = -1,
|
||||
.quadhd_io_num = -1,
|
||||
};
|
||||
|
||||
//Configuration for the SPI slave interface
|
||||
spi_slave_interface_config_t slvcfg={
|
||||
.mode=0,
|
||||
.spics_io_num=GPIO_CS,
|
||||
.queue_size=3,
|
||||
.flags=0,
|
||||
.post_setup_cb=my_post_setup_cb,
|
||||
.post_trans_cb=my_post_trans_cb
|
||||
spi_slave_interface_config_t slvcfg = {
|
||||
.mode = 0,
|
||||
.spics_io_num = GPIO_CS,
|
||||
.queue_size = 3,
|
||||
.flags = 0,
|
||||
.post_setup_cb = my_post_setup_cb,
|
||||
.post_trans_cb = my_post_trans_cb
|
||||
};
|
||||
|
||||
//Configuration for the handshake line
|
||||
gpio_config_t io_conf={
|
||||
.intr_type=GPIO_INTR_DISABLE,
|
||||
.mode=GPIO_MODE_OUTPUT,
|
||||
.pin_bit_mask=(1<<GPIO_HANDSHAKE)
|
||||
gpio_config_t io_conf = {
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pin_bit_mask = (1 << GPIO_HANDSHAKE)
|
||||
};
|
||||
|
||||
//Configure handshake line as output
|
||||
@@ -132,31 +130,31 @@ void app_main(void)
|
||||
gpio_set_pull_mode(GPIO_CS, GPIO_PULLUP_ONLY);
|
||||
|
||||
//Initialize SPI slave interface
|
||||
ret=spi_slave_initialize(RCV_HOST, &buscfg, &slvcfg, SPI_DMA_CH_AUTO);
|
||||
assert(ret==ESP_OK);
|
||||
ret = spi_slave_initialize(RCV_HOST, &buscfg, &slvcfg, SPI_DMA_CH_AUTO);
|
||||
assert(ret == ESP_OK);
|
||||
|
||||
WORD_ALIGNED_ATTR char sendbuf[129]="";
|
||||
WORD_ALIGNED_ATTR char recvbuf[129]="";
|
||||
WORD_ALIGNED_ATTR char sendbuf[129] = "";
|
||||
WORD_ALIGNED_ATTR char recvbuf[129] = "";
|
||||
memset(recvbuf, 0, 33);
|
||||
spi_slave_transaction_t t;
|
||||
memset(&t, 0, sizeof(t));
|
||||
|
||||
while(1) {
|
||||
while (1) {
|
||||
//Clear receive buffer, set send buffer to something sane
|
||||
memset(recvbuf, 0xA5, 129);
|
||||
sprintf(sendbuf, "This is the receiver, sending data for transmission number %04d.", n);
|
||||
|
||||
//Set up a transaction of 128 bytes to send/receive
|
||||
t.length=128*8;
|
||||
t.tx_buffer=sendbuf;
|
||||
t.rx_buffer=recvbuf;
|
||||
t.length = 128 * 8;
|
||||
t.tx_buffer = sendbuf;
|
||||
t.rx_buffer = recvbuf;
|
||||
/* This call enables the SPI slave interface to send/receive to the sendbuf and recvbuf. The transaction is
|
||||
initialized by the SPI master, however, so it will not actually happen until the master starts a hardware transaction
|
||||
by pulling CS low and pulsing the clock etc. In this specific example, we use the handshake line, pulled up by the
|
||||
.post_setup_cb callback that is called as soon as a transaction is ready, to let the master know it is free to transfer
|
||||
data.
|
||||
*/
|
||||
ret=spi_slave_transmit(RCV_HOST, &t, portMAX_DELAY);
|
||||
ret = spi_slave_transmit(RCV_HOST, &t, portMAX_DELAY);
|
||||
|
||||
//spi_slave_transmit does not return until the master has done a transmission, so by here we have sent our data and
|
||||
//received data from the master. Print it.
|
||||
|
Reference in New Issue
Block a user