Skip to content

Commit a27ba9f

Browse files
committed
some coding correction in the spi module
1 parent d8a594a commit a27ba9f

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

ext_mod/esp32_additions/spi/include/esp32_spi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222

2323
struct _esp32_hw_spi_dev_obj_t{
24+
mp_obj_base_t base;
2425
spi_device_interface_config_t devcfg;
2526
esp32_hw_spi_bus_obj_t *spi_bus;
2627
uint8_t bits;
@@ -51,7 +52,6 @@
5152
} state;
5253

5354
};
54-
5555
typedef struct _esp32_hw_spi_default_pins_t{
5656
int8_t mosi_io_num; ///< GPIO pin for Master Out Slave In (=spi_d) signal, or -1 if not used.
5757
int8_t miso_io_num; ///< GPIO pin for Master In Slave Out (=spi_q) signal, or -1 if not used.

ext_mod/esp32_additions/spi/src/esp32_spi.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "freertos/task.h"
4646
#include "esp_system.h"
4747
#include "esp_cpu.h"
48+
#include "hal/spi_ll.h"
4849

4950

5051
// SPI DEVICE CLASS
@@ -727,11 +728,11 @@ mp_obj_t esp32_hw_spi_bus_make_new(const mp_obj_type_t *type, size_t n_args, siz
727728
self = &esp32_hw_spi_bus_obj[host - 1];
728729
default_pins = &default_pins_array[host - 1];
729730
#if SOC_SPI_SUPPORT_OCT
730-
default_oct_pins = &default_pins_array[host - 1];
731+
default_oct_pins = &default_oct_pins_array[host - 1];
731732
#endif
732733
} else {
733734
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("SPI(%d) doesn't exist"), host);
734-
return mp_obj_none;
735+
return mp_const_none;
735736
}
736737

737738
if (self->state == MACHINE_HW_SPI_STATE_INIT) {
@@ -783,9 +784,9 @@ mp_obj_t esp32_hw_spi_bus_make_new(const mp_obj_type_t *type, size_t n_args, siz
783784
data7 = machine_pin_get_id(args[ARG_data7].u_obj);
784785
}
785786

786-
if (data2 != -1 && data5 != -1 && data6 != -1 && data7 != -1) {
787+
if (data4 != -1 && data5 != -1 && data6 != -1 && data7 != -1) {
787788
if (args[ARG_sck].u_obj == MP_OBJ_NULL) {
788-
sck = default_oct_pins->sck_io_num;
789+
sck = default_oct_pins->sclk_io_num;
789790
} else if (args[ARG_sck].u_obj == mp_const_none) {
790791
sck = -1;
791792
} else {
@@ -807,14 +808,6 @@ mp_obj_t esp32_hw_spi_bus_make_new(const mp_obj_type_t *type, size_t n_args, siz
807808
} else {
808809
miso = machine_pin_get_id(args[ARG_miso].u_obj);
809810
}
810-
811-
if (args[ARG_cs].u_obj == MP_OBJ_NULL) {
812-
miso = default_oct_pins->cs_io_num;
813-
} else if (args[ARG_miso].u_obj == mp_const_none) {
814-
miso = -1;
815-
} else {
816-
miso = machine_pin_get_id(args[ARG_miso].u_obj);
817-
}
818811

819812
if (args[ARG_hd].u_obj == MP_OBJ_NULL) {
820813
hd = -1;
@@ -838,7 +831,7 @@ mp_obj_t esp32_hw_spi_bus_make_new(const mp_obj_type_t *type, size_t n_args, siz
838831
data7 = -1;
839832

840833
if (args[ARG_sck].u_obj == MP_OBJ_NULL) {
841-
sck = default_pins->sck_io_num;
834+
sck = default_pins->sclk_io_num
842835
} else if (args[ARG_sck].u_obj == mp_const_none) {
843836
sck = -1;
844837
} else {
@@ -881,7 +874,7 @@ mp_obj_t esp32_hw_spi_bus_make_new(const mp_obj_type_t *type, size_t n_args, siz
881874
#else
882875

883876
if (args[ARG_sck].u_obj == MP_OBJ_NULL) {
884-
sck = default_pins->sck_io_num;
877+
sck = default_pins->sclk_io_num;
885878
} else if (args[ARG_sck].u_obj == mp_const_none) {
886879
sck = -1;
887880
} else {

0 commit comments

Comments
 (0)