Unverified Commit e5892a72 authored by Philip Gladstone's avatar Philip Gladstone Committed by GitHub
Browse files

Give the SPI module a chance of working... (#3496)

parent 8f9295b0
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "lextra.h" #include "lextra.h"
#include "driver/spi_master.h" #include "driver/spi_master.h"
#include "driver/gpio.h"
#include "esp_heap_caps.h" #include "esp_heap_caps.h"
#include "esp_log.h" #include "esp_log.h"
...@@ -107,6 +108,7 @@ static int lspi_device_transfer( lua_State *L ) ...@@ -107,6 +108,7 @@ static int lspi_device_transfer( lua_State *L )
// //
lua_getfield( L, stack, "mode" ); lua_getfield( L, stack, "mode" );
trans.flags |= options_flags[ luaL_checkoption( L, -1, options[0], options ) ]; trans.flags |= options_flags[ luaL_checkoption( L, -1, options[0], options ) ];
lua_pop(L, 1);
// //
data_len = 0; data_len = 0;
data = opt_checklstring( L, "txdata", "", &data_len ); data = opt_checklstring( L, "txdata", "", &data_len );
...@@ -296,6 +298,19 @@ static int lspi_host_device( lua_State *L ) ...@@ -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(halfduplex, SPI_DEVICE_HALFDUPLEX);
CONFIG_DEVICE_FROM_BOOL_FIELD(clk_as_cs, SPI_DEVICE_CLK_AS_CS); CONFIG_DEVICE_FROM_BOOL_FIELD(clk_as_cs, SPI_DEVICE_CLK_AS_CS);
lua_settop( L, stack ); 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 // fill remaining config entries
config.queue_size = 1; config.queue_size = 1;
......
...@@ -147,8 +147,8 @@ device:transfer(txdata) ...@@ -147,8 +147,8 @@ device:transfer(txdata)
#### Parameters #### Parameters
`trans` table containing the elements of the transaction: `trans` table containing the elements of the transaction:
- `command` data for command phase, amount of bits was defined during device creation, optional - `cmd` 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 - `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 - `txdata` string of data to be sent to the device, optional
- `rxlen` number of bytes to be received, optional - `rxlen` number of bytes to be received, optional
- `mode` optional, one of - `mode` optional, one of
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment