kopia lustrzana https://github.com/pimoroni/pimoroni-pico
PimoroniBus: Support machine.Pin.
rodzic
6845972ffe
commit
a03ed44db1
|
|
@ -7,6 +7,7 @@ using namespace pimoroni;
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "pimoroni_bus.h"
|
#include "pimoroni_bus.h"
|
||||||
#include "py/mperrno.h"
|
#include "py/mperrno.h"
|
||||||
|
#include "machine_pin.h"
|
||||||
|
|
||||||
|
|
||||||
void PimoroniBus_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
void PimoroniBus_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||||
|
|
@ -37,12 +38,12 @@ void PimoroniBus_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_
|
||||||
mp_obj_t SPIPins_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
mp_obj_t SPIPins_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||||
enum { ARG_cs, ARG_dc, ARG_sck, ARG_mosi, ARG_miso, ARG_bl };
|
enum { ARG_cs, ARG_dc, ARG_sck, ARG_mosi, ARG_miso, ARG_bl };
|
||||||
static const mp_arg_t allowed_args[] = {
|
static const mp_arg_t allowed_args[] = {
|
||||||
{ MP_QSTR_cs, MP_ARG_INT, {.u_int = SPI_BG_FRONT_CS} },
|
{ MP_QSTR_cs, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(SPI_BG_FRONT_CS)} },
|
||||||
{ MP_QSTR_dc, MP_ARG_INT, {.u_int = SPI_DEFAULT_MISO} },
|
{ MP_QSTR_dc, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(SPI_DEFAULT_MISO)} },
|
||||||
{ MP_QSTR_sck, MP_ARG_INT, {.u_int = SPI_DEFAULT_SCK} },
|
{ MP_QSTR_sck, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(SPI_DEFAULT_SCK)} },
|
||||||
{ MP_QSTR_mosi, MP_ARG_INT, {.u_int = SPI_DEFAULT_MOSI} },
|
{ MP_QSTR_mosi, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(SPI_DEFAULT_MOSI)} },
|
||||||
{ MP_QSTR_miso, MP_ARG_INT, {.u_int = PIN_UNUSED} },
|
{ MP_QSTR_miso, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(PIN_UNUSED)} },
|
||||||
{ MP_QSTR_bl, MP_ARG_INT, {.u_int = PIN_UNUSED} },
|
{ MP_QSTR_bl, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(PIN_UNUSED)} },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse args.
|
// Parse args.
|
||||||
|
|
@ -51,13 +52,13 @@ mp_obj_t SPIPins_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
|
||||||
|
|
||||||
_PimoroniBus_obj_t *self = mp_obj_malloc(_PimoroniBus_obj_t, &SPIPins_type);
|
_PimoroniBus_obj_t *self = mp_obj_malloc(_PimoroniBus_obj_t, &SPIPins_type);
|
||||||
self->pins = new(m_new(SPIPins, 1)) SPIPins{
|
self->pins = new(m_new(SPIPins, 1)) SPIPins{
|
||||||
((args[ARG_sck].u_int >> 3) & 0b1) == 0 ? spi0 : spi1,
|
((mp_hal_get_pin_obj(args[ARG_sck].u_obj) >> 3) & 0b1) == 0 ? spi0 : spi1,
|
||||||
(uint)args[ARG_cs].u_int,
|
mp_hal_get_pin_obj(args[ARG_cs].u_obj),
|
||||||
(uint)args[ARG_sck].u_int,
|
mp_hal_get_pin_obj(args[ARG_sck].u_obj),
|
||||||
(uint)args[ARG_mosi].u_int,
|
mp_hal_get_pin_obj(args[ARG_mosi].u_obj),
|
||||||
(uint)args[ARG_miso].u_int,
|
mp_hal_get_pin_obj(args[ARG_miso].u_obj),
|
||||||
(uint)args[ARG_dc].u_int,
|
mp_hal_get_pin_obj(args[ARG_dc].u_obj),
|
||||||
(uint)args[ARG_bl].u_int
|
mp_hal_get_pin_obj(args[ARG_bl].u_obj)
|
||||||
};
|
};
|
||||||
|
|
||||||
return MP_OBJ_FROM_PTR(self);
|
return MP_OBJ_FROM_PTR(self);
|
||||||
|
|
@ -80,12 +81,12 @@ mp_obj_t SPISlot(mp_obj_t slot_in) {
|
||||||
mp_obj_t ParallelPins_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
mp_obj_t ParallelPins_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||||
enum { ARG_cs, ARG_dc, ARG_wr_sck, ARG_rd_sck, ARG_d0, ARG_bl };
|
enum { ARG_cs, ARG_dc, ARG_wr_sck, ARG_rd_sck, ARG_d0, ARG_bl };
|
||||||
static const mp_arg_t allowed_args[] = {
|
static const mp_arg_t allowed_args[] = {
|
||||||
{ MP_QSTR_cs, MP_ARG_INT, {.u_int = 10} },
|
{ MP_QSTR_cs, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(10)} },
|
||||||
{ MP_QSTR_dc, MP_ARG_INT, {.u_int = 11} },
|
{ MP_QSTR_dc, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(11)} },
|
||||||
{ MP_QSTR_wr_sck, MP_ARG_INT, {.u_int = 12} },
|
{ MP_QSTR_wr_sck, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(12)} },
|
||||||
{ MP_QSTR_rd_sck, MP_ARG_INT, {.u_int = 13} },
|
{ MP_QSTR_rd_sck, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(13)} },
|
||||||
{ MP_QSTR_d0, MP_ARG_INT, {.u_int = 14} },
|
{ MP_QSTR_d0, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(14)} },
|
||||||
{ MP_QSTR_bl, MP_ARG_INT, {.u_int = 2} },
|
{ MP_QSTR_bl, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(2)} },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse args.
|
// Parse args.
|
||||||
|
|
@ -94,12 +95,12 @@ mp_obj_t ParallelPins_make_new(const mp_obj_type_t *type, size_t n_args, size_t
|
||||||
|
|
||||||
_PimoroniBus_obj_t *self = mp_obj_malloc(_PimoroniBus_obj_t, &ParallelPins_type);
|
_PimoroniBus_obj_t *self = mp_obj_malloc(_PimoroniBus_obj_t, &ParallelPins_type);
|
||||||
self->pins = new(m_new(ParallelPins, 1)) ParallelPins{
|
self->pins = new(m_new(ParallelPins, 1)) ParallelPins{
|
||||||
(uint)args[ARG_cs].u_int,
|
mp_hal_get_pin_obj(args[ARG_cs].u_obj),
|
||||||
(uint)args[ARG_dc].u_int,
|
mp_hal_get_pin_obj(args[ARG_dc].u_obj),
|
||||||
(uint)args[ARG_wr_sck].u_int,
|
mp_hal_get_pin_obj(args[ARG_wr_sck].u_obj),
|
||||||
(uint)args[ARG_rd_sck].u_int,
|
mp_hal_get_pin_obj(args[ARG_rd_sck].u_obj),
|
||||||
(uint)args[ARG_d0].u_int,
|
mp_hal_get_pin_obj(args[ARG_d0].u_obj),
|
||||||
args[ARG_bl].u_int == -1 ? PIN_UNUSED : (uint)args[ARG_bl].u_int
|
args[ARG_bl].u_obj == mp_const_none ? PIN_UNUSED : mp_hal_get_pin_obj(args[ARG_bl].u_obj)
|
||||||
};
|
};
|
||||||
|
|
||||||
return MP_OBJ_FROM_PTR(self);
|
return MP_OBJ_FROM_PTR(self);
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue