Skip to content

Commit e0609a4

Browse files
committed
esp32/machine_hspi.*: Renamed to machine_hw_spi.*
1 parent 192a032 commit e0609a4

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

esp32/machine_hspi.c renamed to esp32/machine_hw_spi.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "extmod/machine_spi.h"
3636
#include "machine_hspi.h"
3737
#include "modmachine.h"
38-
#include "hspi.h"
38+
3939

4040
// if a port didn't define MSB/LSB constants then provide them
4141
#ifndef MICROPY_PY_MACHINE_SPI_MSB
@@ -55,11 +55,12 @@ STATIC void machine_hspi_transfer(mp_obj_base_t *self_in, size_t len, const uint
5555
struct spi_transaction_t transaction = {
5656
.flags = 0,
5757
.length = bits_to_send,
58-
.tx_buffer = src,
59-
.rx_buffer = dest,
58+
.tx_buffer = NULL,
59+
.rx_buffer = NULL,
6060
};
6161
bool shortMsg = len <= 4;
6262

63+
6364
if(shortMsg) {
6465
if (src != NULL) {
6566
memcpy(&transaction.tx_data, src, len);
@@ -68,6 +69,9 @@ STATIC void machine_hspi_transfer(mp_obj_base_t *self_in, size_t len, const uint
6869
if (dest != NULL) {
6970
transaction.flags |= SPI_TRANS_USE_RXDATA;
7071
}
72+
} else {
73+
transaction.tx_buffer = src;
74+
transaction.rx_buffer = dest;
7175
}
7276

7377
spi_device_transmit(self->spi, &transaction);
@@ -108,7 +112,12 @@ STATIC void machine_hspi_init(mp_obj_base_t *self_in, size_t n_args, const mp_ob
108112
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args),
109113
allowed_args, args);
110114

111-
self->host = args[ARG_id].u_int;
115+
int host = args[ARG_id].u_int;
116+
if (host != HSPI_HOST && host != VSPI_HOST) {
117+
mp_raise_ValueError("SPI ID must be either HSPI(1) or VSPI(2)");
118+
}
119+
120+
self->host = host;
112121
self->baudrate = args[ARG_baudrate].u_int;
113122
self->polarity = args[ARG_polarity].u_int ? 1 : 0;
114123
self->phase = args[ARG_phase].u_int ? 1 : 0;
@@ -131,14 +140,15 @@ STATIC void machine_hspi_init(mp_obj_base_t *self_in, size_t n_args, const mp_ob
131140
.mode = self->phase | (self->polarity << 1),
132141
.spics_io_num = -1, // No CS pin
133142
.queue_size = 1,
143+
.flags = self->firstbit == MICROPY_PY_MACHINE_SPI_LSB ? SPI_DEVICE_TXBIT_LSBFIRST | SPI_DEVICE_RXBIT_LSBFIRST : 0,
134144
.pre_cb = NULL
135145
};
136146

137147
//Initialize the SPI bus
138148
// FIXME: Does the DMA matter? There are two
139-
ret=spi_bus_initialize(self->host, &buscfg, 1);
149+
ret = spi_bus_initialize(self->host, &buscfg, 1);
140150
assert(ret == ESP_OK);
141-
ret=spi_bus_add_device(self->host, &devcfg, &self->spi);
151+
ret = spi_bus_add_device(self->host, &devcfg, &self->spi);
142152
assert(ret == ESP_OK);
143153
}
144154

@@ -156,11 +166,6 @@ STATIC void machine_hspi_deinit(mp_obj_base_t *self_in) {
156166

157167
mp_obj_t machine_hspi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
158168
// args[0] holds the id of the peripheral
159-
int host = mp_obj_get_int(args[0]);
160-
if (host != HSPI_HOST && host != VSPI_HOST) {
161-
mp_raise_ValueError("SPI ID must be either HSPI(1) or VSPI(2)");
162-
}
163-
164169
machine_hspi_obj_t *self = m_new_obj(machine_hspi_obj_t);
165170
self->base.type = &machine_hspi_type;
166171
// set defaults

esp32/machine_hspi.h renamed to esp32/machine_hw_spi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
typedef struct _machine_hspi_obj_t {
3333
mp_obj_base_t base;
34-
spi_host_device_t host;
34+
spi_host_device_t host;
3535
uint32_t baudrate;
3636
uint8_t polarity;
3737
uint8_t phase;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy