Skip to content

Commit c046e4f

Browse files
committed
esp32/machine_hw_spi.*: Renamed internals from hspi --> hw_spi
1 parent e0609a4 commit c046e4f

File tree

5 files changed

+74
-33
lines changed

5 files changed

+74
-33
lines changed

esp32/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ include ../py/py.mk
1616

1717
PORT ?= /dev/ttyUSB0
1818
BAUD ?= 460800
19-
FLASH_MODE ?= qio
19+
FLASH_MODE ?= dio
2020
FLASH_FREQ ?= 40m
2121
FLASH_SIZE ?= 4MB
2222
CROSS_COMPILE ?= xtensa-esp32-elf-
@@ -122,6 +122,7 @@ SRC_C = \
122122
machine_pin.c \
123123
machine_touchpad.c \
124124
machine_adc.c \
125+
machine_hw_spi.c \
125126
machine_dac.c \
126127
modmachine.c \
127128
modnetwork.c \
@@ -199,6 +200,7 @@ ESPIDF_DRIVER_O = $(addprefix $(ESPCOMP)/driver/,\
199200
uart.o \
200201
periph_ctrl.o \
201202
ledc.o \
203+
spi_master.o \
202204
gpio.o \
203205
timer.o \
204206
rtc_module.o \

esp32/machine_hw_spi.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "py/stream.h"
3434
#include "py/mphal.h"
3535
#include "extmod/machine_spi.h"
36-
#include "machine_hspi.h"
36+
#include "machine_hw_spi.h"
3737
#include "modmachine.h"
3838

3939

@@ -45,8 +45,8 @@
4545

4646

4747

48-
STATIC void machine_hspi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
49-
machine_hspi_obj_t *self = MP_OBJ_TO_PTR(self_in);
48+
STATIC void machine_hw_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
49+
machine_hw_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
5050
int bits_to_send = len * self->bits;
5151
if (self->deinitialized) {
5252
return;
@@ -82,18 +82,18 @@ STATIC void machine_hspi_transfer(mp_obj_base_t *self_in, size_t len, const uint
8282
}
8383

8484
/******************************************************************************/
85-
// MicroPython bindings for HSPI
85+
// MicroPython bindings for hw_spi
8686

87-
STATIC void machine_hspi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
88-
machine_hspi_obj_t *self = MP_OBJ_TO_PTR(self_in);
89-
mp_printf(print, "HSPI(id=%u, baudrate=%u, polarity=%u, phase=%u, bits=%u, firstbit=%u, sck=%d, mosi=%d, miso=%d)",
87+
STATIC void machine_hw_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
88+
machine_hw_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
89+
mp_printf(print, "hw_spi(id=%u, baudrate=%u, polarity=%u, phase=%u, bits=%u, firstbit=%u, sck=%d, mosi=%d, miso=%d)",
9090
self->host, self->baudrate, self->polarity,
9191
self->phase, self->bits, self->firstbit,
9292
self->sck, self->mosi, self->miso );
9393
}
9494

95-
STATIC void machine_hspi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
96-
machine_hspi_obj_t *self = (machine_hspi_obj_t*)self_in;
95+
STATIC void machine_hw_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
96+
machine_hw_spi_obj_t *self = (machine_hw_spi_obj_t*)self_in;
9797
esp_err_t ret;
9898

9999
enum { ARG_id, ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit, ARG_sck, ARG_mosi, ARG_miso };
@@ -114,7 +114,7 @@ STATIC void machine_hspi_init(mp_obj_base_t *self_in, size_t n_args, const mp_ob
114114

115115
int host = args[ARG_id].u_int;
116116
if (host != HSPI_HOST && host != VSPI_HOST) {
117-
mp_raise_ValueError("SPI ID must be either HSPI(1) or VSPI(2)");
117+
mp_raise_ValueError("SPI ID must be either hw_spi(1) or VSPI(2)");
118118
}
119119

120120
self->host = host;
@@ -152,8 +152,8 @@ STATIC void machine_hspi_init(mp_obj_base_t *self_in, size_t n_args, const mp_ob
152152
assert(ret == ESP_OK);
153153
}
154154

155-
STATIC void machine_hspi_deinit(mp_obj_base_t *self_in) {
156-
machine_hspi_obj_t *self = (machine_hspi_obj_t*)self_in;
155+
STATIC void machine_hw_spi_deinit(mp_obj_base_t *self_in) {
156+
machine_hw_spi_obj_t *self = (machine_hw_spi_obj_t*)self_in;
157157
esp_err_t ret;
158158
if (!self->deinitialized) {
159159
self->deinitialized = true;
@@ -164,28 +164,28 @@ STATIC void machine_hspi_deinit(mp_obj_base_t *self_in) {
164164
}
165165
}
166166

167-
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) {
167+
mp_obj_t machine_hw_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
168168
// args[0] holds the id of the peripheral
169-
machine_hspi_obj_t *self = m_new_obj(machine_hspi_obj_t);
170-
self->base.type = &machine_hspi_type;
169+
machine_hw_spi_obj_t *self = m_new_obj(machine_hw_spi_obj_t);
170+
self->base.type = &machine_hw_spi_type;
171171
// set defaults
172172
mp_map_t kw_args;
173173
mp_map_init_fixed_table(&kw_args, n_kw, args + n_args);
174-
machine_hspi_init((mp_obj_base_t*)self, n_args, args, &kw_args);
174+
machine_hw_spi_init((mp_obj_base_t*)self, n_args, args, &kw_args);
175175
return MP_OBJ_FROM_PTR(self);
176176
}
177177

178-
STATIC const mp_machine_spi_p_t machine_hspi_p = {
179-
.init = machine_hspi_init,
180-
.deinit = machine_hspi_deinit,
181-
.transfer = machine_hspi_transfer,
178+
STATIC const mp_machine_spi_p_t machine_hw_spi_p = {
179+
.init = machine_hw_spi_init,
180+
.deinit = machine_hw_spi_deinit,
181+
.transfer = machine_hw_spi_transfer,
182182
};
183183

184-
const mp_obj_type_t machine_hspi_type = {
184+
const mp_obj_type_t machine_hw_spi_type = {
185185
{ &mp_type_type },
186-
.name = MP_QSTR_HSPI,
187-
.print = machine_hspi_print,
188-
.make_new = machine_hspi_make_new,
189-
.protocol = &machine_hspi_p,
186+
.name = MP_QSTR_hw_spi,
187+
.print = machine_hw_spi_print,
188+
.make_new = machine_hw_spi_make_new,
189+
.protocol = &machine_hw_spi_p,
190190
.locals_dict = (mp_obj_dict_t*)&mp_machine_spi_locals_dict,
191191
};

esp32/machine_hw_spi.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#ifndef MICROPY_INCLUDED_MACHINE_HSPI_H
28-
#define MICROPY_INCLUDED_MACHINE_HSPI_H
27+
#ifndef MICROPY_INCLUDED_MACHINE_HW_SPI_H
28+
#define MICROPY_INCLUDED_MACHINE_HW_SPI_H
2929

3030
#include "driver/spi_master.h"
3131

32-
typedef struct _machine_hspi_obj_t {
32+
typedef struct _machine_hw_spi_obj_t {
3333
mp_obj_base_t base;
3434
spi_host_device_t host;
3535
uint32_t baudrate;
@@ -42,8 +42,8 @@ typedef struct _machine_hspi_obj_t {
4242
int8_t miso;
4343
spi_device_handle_t spi;
4444
bool deinitialized;
45-
} machine_hspi_obj_t;
45+
} machine_hw_spi_obj_t;
4646

47-
extern const mp_obj_type_t machine_hspi_type ;
47+
extern const mp_obj_type_t machine_hw_spi_type ;
4848

49-
#endif // MICROPY_INCLUDED_MACHINE_HSPI_H
49+
#endif // MICROPY_INCLUDED_MACHINE_HW_SPI_H

esp32/mpconfigport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
#define MICROPY_PY_MACHINE_PULSE (1)
123123
#define MICROPY_PY_MACHINE_I2C (1)
124124
#define MICROPY_PY_MACHINE_SPI (1)
125-
#define MICROPY_PY_MACHINE_SPI_MAKE_NEW machine_hspi_make_new
125+
#define MICROPY_PY_MACHINE_SPI_MAKE_NEW machine_hw_spi_make_new
126126
#define MICROPY_PY_MACHINE_SPI_MIN_DELAY (0)
127127
#define MICROPY_PY_MACHINE_SPI_MAX_BAUDRATE (ets_get_cpu_frequency() * 1000000 / 200) // roughly
128128
#define MICROPY_PY_USSL (1)

esp32/scratch.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import machine as m
2+
p = m.Pin(4)
3+
r = m.RTC()
4+
p.init(p.IN, p.PULL_UP)
5+
r.wake_on_ext0(pin = p, level = 0)
6+
m.deepsleep()
7+
8+
import machine as m
9+
pins = (m.Pin(2), m.Pin(4))
10+
for p in pins: p.init(m.Pin.IN, m.Pin.PULL_UP)
11+
12+
r = m.RTC()
13+
r.wake_on_ext1(pins = pins, level = r.WAKEUP_ALL_LOW)
14+
m.deepsleep()
15+
16+
17+
import machine as m
18+
r = m.RTC()
19+
r.irq(trigger=r.ALARM0, wake=m.DEEPSLEEP)
20+
r.alarm(r.ALARM0, 3000)
21+
m.deepsleep()
22+
23+
import machine as m
24+
s = m.SPI(sck=m.Pin(25), mosi = m.Pin(26), miso = m.Pin(5))
25+
s.init()
26+
cs = m.Pin(27)
27+
cs.value(0)
28+
cs.init(m.Pin.OUT, m.Pin.PULL_UP)
29+
cs.value(1)
30+
s.write(bytearray([0x80, 0x01] + [0xAA] * 1000))
31+
cs.value(0)
32+
33+
34+
import machine as m
35+
s = m.SPI(1, sck=m.Pin(25), mosi = m.Pin(26))
36+
s = m.SPI(1, sck=m.Pin(25), mosi = m.Pin(26), miso = m.Pin(5)))
37+
s.transfer(bytearray((1,2,3,4,5)))
38+
s.init(1, sck=m.Pin(25), mosi = m.Pin(26))
39+
cs = m.Pin(27)

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