summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2020-09-21 15:51:55 -0500
committerJeff Epler <jepler@gmail.com>2020-09-21 16:44:26 -0500
commit9e8f1820c8b9be728ae0f9e7c197565ac17cc6a8 (patch)
treee7e8fdad54644c6ef538f0be053fd1f414a3a500 /shared-bindings
parent4e4853dcb26aa46db3269db45a8cbbbad61c44d8 (diff)
canio.CAN: switch rx/tx, make both mandatory, move declarations around
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/_canio/CAN.c23
-rw-r--r--shared-bindings/_canio/CAN.h23
2 files changed, 33 insertions, 13 deletions
diff --git a/shared-bindings/_canio/CAN.c b/shared-bindings/_canio/CAN.c
index 3c80b342f..38aed85d3 100644
--- a/shared-bindings/_canio/CAN.c
+++ b/shared-bindings/_canio/CAN.c
@@ -42,26 +42,23 @@
//| """CAN bus protocol"""
//|
//| def __init__(self,
-//| rx: Optional[microcontroller.Pin]=None,
-//| tx: Optional[microcontroller.Pin]=None,
+//| tx: microcontroller.Pin,
+//| rx: microcontroller.Pin,
//| *,
//| baudrate: int = 250000,
//| loopback: bool = False,
+//| silent: bool = False,
//| auto_restart: bool = False,
//| ):
//| """A common shared-bus protocol. The rx and tx pins are generally
//| connected to a transceiver which controls the H and L pins on a
//| shared bus.
//|
-//| Normally, both ``tx`` and ``rx`` pins will be specified. However,
-//| in silent and loopback modes, the other pin may not be required and
-//| can be used for other purposes.
-//|
-//| :param ~microcontroller.Pin rx: the pin to receive with, or None.
-//| :param ~microcontroller.Pin tx: the pin to transmit with, or None.
+//| :param ~microcontroller.Pin rx: the pin to receive with
+//| :param ~microcontroller.Pin tx: the pin to transmit with
//| :param int baudrate: The bit rate of the bus in Hz. All devices on the bus must agree on this value.
-//| :param bool loopback: True if the peripheral will be operated in loopback mode. In loopback mode, the ``rx`` pin's value is ignored, and the device receives the packets it sends.
-//| :param bool silent: True if the peripheral will be operated in silent mode. In silent mode, the ``tx`` pin is always driven to the high logic level. This mode can be used to "sniff" a CAN bus without interfering.
+//| :param bool loopback: When True the ``rx`` pin's value is ignored, and the device receives the packets it sends.
+//| :param bool silent: When True the ``tx`` pin is always driven to the high logic level. This mode can be used to "sniff" a CAN bus without interfering.
//| :param bool auto_restart: If True, will restart communications after entering bus-off state
//| """
//| ...
@@ -69,8 +66,8 @@
STATIC mp_obj_t canio_can_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_rx, ARG_tx, ARG_baudrate, ARG_loopback, ARG_silent, ARG_auto_restart, NUM_ARGS };
static const mp_arg_t allowed_args[] = {
- { MP_QSTR_rx, MP_ARG_OBJ, {.u_obj = mp_const_none} },
- { MP_QSTR_tx, MP_ARG_OBJ, {.u_obj = mp_const_none} },
+ { MP_QSTR_tx, MP_ARG_OBJ | MP_ARG_REQUIRED },
+ { MP_QSTR_rx, MP_ARG_OBJ | MP_ARG_REQUIRED },
{ MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 250000} },
{ MP_QSTR_loopback, MP_ARG_BOOL, {.u_bool = false} },
{ MP_QSTR_silent, MP_ARG_BOOL, {.u_bool = false} },
@@ -89,7 +86,7 @@ STATIC mp_obj_t canio_can_make_new(const mp_obj_type_t *type, size_t n_args, con
canio_can_obj_t *self = m_new_obj(canio_can_obj_t);
self->base.type = &canio_can_type;
- common_hal_canio_can_construct(self, rx_pin, tx_pin, args[ARG_baudrate].u_int, args[ARG_loopback].u_bool, args[ARG_silent].u_bool);
+ common_hal_canio_can_construct(self, tx_pin, rx_pin, args[ARG_baudrate].u_int, args[ARG_loopback].u_bool, args[ARG_silent].u_bool);
common_hal_canio_can_auto_restart_set(self, args[ARG_auto_restart].u_bool);
diff --git a/shared-bindings/_canio/CAN.h b/shared-bindings/_canio/CAN.h
index 81040cf23..c591c8e6b 100644
--- a/shared-bindings/_canio/CAN.h
+++ b/shared-bindings/_canio/CAN.h
@@ -27,5 +27,28 @@
#pragma once
#include "py/obj.h"
+#include "shared-bindings/microcontroller/Pin.h"
+#include "shared-bindings/_canio/Message.h"
extern const mp_obj_type_t canio_can_type;
+
+typedef struct canio_can_obj canio_can_obj_t;
+
+void common_hal_canio_can_construct(canio_can_obj_t *self, mcu_pin_obj_t *tx, mcu_pin_obj_t *rx, int baudrate, bool loopback, bool silent);
+bool common_hal_canio_can_auto_restart_get(canio_can_obj_t *self);
+bool common_hal_canio_can_deinited(canio_can_obj_t *self);
+int common_hal_canio_can_baudrate_get(canio_can_obj_t *self);
+int common_hal_canio_can_bus_off_state_count_get(canio_can_obj_t *self);
+int common_hal_canio_can_error_passive_state_count_get(canio_can_obj_t *self);
+int common_hal_canio_can_error_warning_state_count_get(canio_can_obj_t *self);
+bool common_hal_canio_can_loopback_get(canio_can_obj_t *self);
+int common_hal_canio_can_receive_error_count_get(canio_can_obj_t *self);
+canio_bus_state_t common_hal_canio_can_state_get(canio_can_obj_t *self);
+bool common_hal_canio_can_silent_get(canio_can_obj_t *self);
+int common_hal_canio_can_transmit_error_count_get(canio_can_obj_t *self);
+void common_hal_canio_can_auto_restart_set(canio_can_obj_t *self, bool auto_restart);
+void common_hal_canio_can_check_for_deinit(canio_can_obj_t *self);
+void common_hal_canio_can_deinit(canio_can_obj_t *self);
+void common_hal_canio_can_restart(canio_can_obj_t *self);
+void common_hal_canio_can_send(canio_can_obj_t *self, canio_message_obj_t *message);
+void common_hal_canio_reset(void);