Skip to content

Commit

Permalink
esp8266/machine_spi: Rename machine_hspi to machine_spi.
Browse files Browse the repository at this point in the history
This renames the type, functions and file to match other ports.

Signed-off-by: Damien George <[email protected]>
  • Loading branch information
dpgeorge committed Nov 30, 2023
1 parent c554df5 commit 911662c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion ports/esp8266/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ SRC_C = \
machine_bitstream.c \
machine_pin.c \
machine_rtc.c \
machine_hspi.c \
machine_spi.c \
modesp.c \
network_wlan.c \
ets_alt_task.c \
Expand Down
1 change: 0 additions & 1 deletion ports/esp8266/boards/esp8266_common.ld
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ SECTIONS
*modmachine.o(.literal*, .text*)
*machine_wdt.o(.literal*, .text*)
*machine_spi.o(.literal*, .text*)
*machine_hspi.o(.literal*, .text*)
*hspi.o(.literal*, .text*)
*modesp.o(.literal* .text*)
*modespnow.o(.literal* .text*)
Expand Down
34 changes: 17 additions & 17 deletions ports/esp8266/machine_hspi.c → ports/esp8266/machine_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@

#if MICROPY_PY_MACHINE_SPI

typedef struct _machine_hspi_obj_t {
typedef struct _machine_spi_obj_t {
mp_obj_base_t base;
uint32_t baudrate;
uint8_t polarity;
uint8_t phase;
} machine_hspi_obj_t;
} machine_spi_obj_t;

STATIC void machine_hspi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8_t *src, uint8_t *dest) {
(void)self_in;

if (dest == NULL) {
Expand Down Expand Up @@ -94,14 +94,14 @@ STATIC void machine_hspi_transfer(mp_obj_base_t *self_in, size_t len, const uint
/******************************************************************************/
// MicroPython bindings for HSPI

STATIC void machine_hspi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
machine_hspi_obj_t *self = MP_OBJ_TO_PTR(self_in);
STATIC void machine_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
machine_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "HSPI(id=1, baudrate=%u, polarity=%u, phase=%u)",
self->baudrate, self->polarity, self->phase);
}

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) {
machine_hspi_obj_t *self = (machine_hspi_obj_t *)self_in;
STATIC void machine_spi_init(mp_obj_base_t *self_in, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
machine_spi_obj_t *self = (machine_spi_obj_t *)self_in;

enum { ARG_baudrate, ARG_polarity, ARG_phase };
static const mp_arg_t allowed_args[] = {
Expand Down Expand Up @@ -150,7 +150,7 @@ STATIC void machine_hspi_init(mp_obj_base_t *self_in, size_t n_args, const mp_ob
spi_mode(HSPI, self->phase, self->polarity);
}

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) {
mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
MP_MACHINE_SPI_CHECK_FOR_LEGACY_SOFTSPI_CONSTRUCTION(n_args, n_kw, args);

// args[0] holds the id of the peripheral
Expand All @@ -159,29 +159,29 @@ mp_obj_t machine_hspi_make_new(const mp_obj_type_t *type, size_t n_args, size_t
mp_raise_ValueError(NULL);
}

machine_hspi_obj_t *self = mp_obj_malloc(machine_hspi_obj_t, &machine_hspi_type);
machine_spi_obj_t *self = mp_obj_malloc(machine_spi_obj_t, &machine_spi_type);
// set defaults
self->baudrate = 80000000L;
self->polarity = 0;
self->phase = 0;
mp_map_t kw_args;
mp_map_init_fixed_table(&kw_args, n_kw, args + n_args);
machine_hspi_init((mp_obj_base_t *)self, n_args - 1, args + 1, &kw_args);
machine_spi_init((mp_obj_base_t *)self, n_args - 1, args + 1, &kw_args);
return MP_OBJ_FROM_PTR(self);
}

STATIC const mp_machine_spi_p_t machine_hspi_p = {
.init = machine_hspi_init,
.transfer = machine_hspi_transfer,
STATIC const mp_machine_spi_p_t machine_spi_p = {
.init = machine_spi_init,
.transfer = machine_spi_transfer,
};

MP_DEFINE_CONST_OBJ_TYPE(
machine_hspi_type,
machine_spi_type,
MP_QSTR_HSPI,
MP_TYPE_FLAG_NONE,
make_new, machine_hspi_make_new,
print, machine_hspi_print,
protocol, &machine_hspi_p,
make_new, machine_spi_make_new,
print, machine_spi_print,
protocol, &machine_spi_p,
locals_dict, &mp_machine_spi_locals_dict
);

Expand Down
2 changes: 1 addition & 1 deletion ports/esp8266/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_SoftI2C), MP_ROM_PTR(&mp_machine_soft_i2c_type) },
#endif
#if MICROPY_PY_MACHINE_SPI
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&machine_hspi_type) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&machine_spi_type) },
{ MP_ROM_QSTR(MP_QSTR_SoftSPI), MP_ROM_PTR(&mp_machine_soft_spi_type) },
#endif

Expand Down
1 change: 0 additions & 1 deletion ports/esp8266/modmachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

extern const mp_obj_type_t pyb_pin_type;
extern const mp_obj_type_t pyb_rtc_type;
extern const mp_obj_type_t machine_hspi_type;

MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_info_obj);

Expand Down

0 comments on commit 911662c

Please sign in to comment.