Skip to content

Commit

Permalink
Give the SPI module a chance of working... (#3496)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjsg authored Jan 27, 2022
1 parent 8f9295b commit e5892a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions components/modules/spi_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "lextra.h"

#include "driver/spi_master.h"
#include "driver/gpio.h"
#include "esp_heap_caps.h"

#include "esp_log.h"
Expand Down Expand Up @@ -107,6 +108,7 @@ static int lspi_device_transfer( lua_State *L )
//
lua_getfield( L, stack, "mode" );
trans.flags |= options_flags[ luaL_checkoption( L, -1, options[0], options ) ];
lua_pop(L, 1);
//
data_len = 0;
data = opt_checklstring( L, "txdata", "", &data_len );
Expand Down Expand Up @@ -296,6 +298,19 @@ static int lspi_host_device( lua_State *L )
CONFIG_DEVICE_FROM_BOOL_FIELD(halfduplex, SPI_DEVICE_HALFDUPLEX);
CONFIG_DEVICE_FROM_BOOL_FIELD(clk_as_cs, SPI_DEVICE_CLK_AS_CS);
lua_settop( L, stack );

//
if (config.spics_io_num >= 0) {
// Configure the gpio
gpio_config_t cfg;
memset(&cfg, 0, sizeof(cfg));
cfg.mode = GPIO_MODE_OUTPUT;
cfg.pin_bit_mask = 1ULL << config.spics_io_num;
if (!no_err(gpio_config (&cfg)) ||
!no_err(gpio_set_level (config.spics_io_num, (config.flags & SPI_DEVICE_POSITIVE_CS) ? 0 : 1))) {
return luaL_error(L, "failed to configure gpio");
}
}
//
// fill remaining config entries
config.queue_size = 1;
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/spi.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ device:transfer(txdata)
#### Parameters
`trans` table containing the elements of the transaction:

- `command` data for command phase, amount of bits was defined during device creation, optional
- `address` data for address phase, amount of bits was defined during device creation, optional
- `cmd` data for command phase, amount of bits was defined during device creation, optional
- `addr` data for address phase, amount of bits was defined during device creation, optional
- `txdata` string of data to be sent to the device, optional
- `rxlen` number of bytes to be received, optional
- `mode` optional, one of
Expand Down

0 comments on commit e5892a7

Please sign in to comment.