You've already forked Core2forAWS-MicroPython
mirror of
https://github.com/m5stack/Core2forAWS-MicroPython.git
synced 2026-05-20 10:30:31 -07:00
stm32/can: Factor CAN driver into low-level and Python bindings.
can.c now contains the low-level C interface to the CAN peripheral, and pyb_can.c the Python-level class/methods/constants.
This commit is contained in:
@@ -256,6 +256,7 @@ SRC_C = \
|
||||
qspi.c \
|
||||
uart.c \
|
||||
can.c \
|
||||
pyb_can.c \
|
||||
usb.c \
|
||||
wdt.c \
|
||||
eth.c \
|
||||
|
||||
+122
-816
File diff suppressed because it is too large
Load Diff
+46
-3
@@ -26,15 +26,58 @@
|
||||
#ifndef MICROPY_INCLUDED_STM32_CAN_H
|
||||
#define MICROPY_INCLUDED_STM32_CAN_H
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
#define PYB_CAN_1 (1)
|
||||
#define PYB_CAN_2 (2)
|
||||
#define PYB_CAN_3 (3)
|
||||
|
||||
#define MASK16 (0)
|
||||
#define LIST16 (1)
|
||||
#define MASK32 (2)
|
||||
#define LIST32 (3)
|
||||
|
||||
enum {
|
||||
CAN_STATE_STOPPED,
|
||||
CAN_STATE_ERROR_ACTIVE,
|
||||
CAN_STATE_ERROR_WARNING,
|
||||
CAN_STATE_ERROR_PASSIVE,
|
||||
CAN_STATE_BUS_OFF,
|
||||
};
|
||||
|
||||
typedef enum _rx_state_t {
|
||||
RX_STATE_FIFO_EMPTY = 0,
|
||||
RX_STATE_MESSAGE_PENDING,
|
||||
RX_STATE_FIFO_FULL,
|
||||
RX_STATE_FIFO_OVERFLOW,
|
||||
} rx_state_t;
|
||||
|
||||
typedef struct _pyb_can_obj_t {
|
||||
mp_obj_base_t base;
|
||||
mp_obj_t rxcallback0;
|
||||
mp_obj_t rxcallback1;
|
||||
mp_uint_t can_id : 8;
|
||||
bool is_enabled : 1;
|
||||
bool extframe : 1;
|
||||
byte rx_state0;
|
||||
byte rx_state1;
|
||||
uint16_t num_error_warning;
|
||||
uint16_t num_error_passive;
|
||||
uint16_t num_bus_off;
|
||||
CAN_HandleTypeDef can;
|
||||
} pyb_can_obj_t;
|
||||
|
||||
extern const mp_obj_type_t pyb_can_type;
|
||||
|
||||
void can_init0(void);
|
||||
void can_deinit(void);
|
||||
void can_rx_irq_handler(uint can_id, uint fifo_id);
|
||||
void can_sce_irq_handler(uint can_id);
|
||||
void can_deinit_all(void);
|
||||
bool can_init(pyb_can_obj_t *can_obj, uint32_t mode, uint32_t prescaler, uint32_t sjw, uint32_t bs1, uint32_t bs2, bool auto_restart);
|
||||
void can_deinit(pyb_can_obj_t *self);
|
||||
|
||||
void can_clearfilter(uint32_t f, uint8_t bank);
|
||||
int can_receive(CAN_TypeDef *can, int fifo, CanRxMsgTypeDef *msg, uint32_t timeout_ms);
|
||||
HAL_StatusTypeDef CAN_Transmit(CAN_HandleTypeDef *hcan, uint32_t Timeout);
|
||||
|
||||
void pyb_can_handle_callback(pyb_can_obj_t *self, uint fifo_id, mp_obj_t callback, mp_obj_t irq_reason);
|
||||
|
||||
#endif // MICROPY_INCLUDED_STM32_CAN_H
|
||||
|
||||
+1
-1
@@ -731,7 +731,7 @@ soft_reset_exit:
|
||||
timer_deinit();
|
||||
uart_deinit_all();
|
||||
#if MICROPY_HW_ENABLE_CAN
|
||||
can_deinit();
|
||||
can_deinit_all();
|
||||
#endif
|
||||
machine_deinit();
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -79,7 +79,6 @@
|
||||
#include "timer.h"
|
||||
#include "uart.h"
|
||||
#include "storage.h"
|
||||
#include "can.h"
|
||||
#include "dma.h"
|
||||
#include "i2c.h"
|
||||
#include "usb.h"
|
||||
@@ -792,66 +791,6 @@ void UART10_IRQHandler(void) {
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(MICROPY_HW_CAN1_TX)
|
||||
void CAN1_RX0_IRQHandler(void) {
|
||||
IRQ_ENTER(CAN1_RX0_IRQn);
|
||||
can_rx_irq_handler(PYB_CAN_1, CAN_FIFO0);
|
||||
IRQ_EXIT(CAN1_RX0_IRQn);
|
||||
}
|
||||
|
||||
void CAN1_RX1_IRQHandler(void) {
|
||||
IRQ_ENTER(CAN1_RX1_IRQn);
|
||||
can_rx_irq_handler(PYB_CAN_1, CAN_FIFO1);
|
||||
IRQ_EXIT(CAN1_RX1_IRQn);
|
||||
}
|
||||
|
||||
void CAN1_SCE_IRQHandler(void) {
|
||||
IRQ_ENTER(CAN1_SCE_IRQn);
|
||||
can_sce_irq_handler(PYB_CAN_1);
|
||||
IRQ_EXIT(CAN1_SCE_IRQn);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MICROPY_HW_CAN2_TX)
|
||||
void CAN2_RX0_IRQHandler(void) {
|
||||
IRQ_ENTER(CAN2_RX0_IRQn);
|
||||
can_rx_irq_handler(PYB_CAN_2, CAN_FIFO0);
|
||||
IRQ_EXIT(CAN2_RX0_IRQn);
|
||||
}
|
||||
|
||||
void CAN2_RX1_IRQHandler(void) {
|
||||
IRQ_ENTER(CAN2_RX1_IRQn);
|
||||
can_rx_irq_handler(PYB_CAN_2, CAN_FIFO1);
|
||||
IRQ_EXIT(CAN2_RX1_IRQn);
|
||||
}
|
||||
|
||||
void CAN2_SCE_IRQHandler(void) {
|
||||
IRQ_ENTER(CAN2_SCE_IRQn);
|
||||
can_sce_irq_handler(PYB_CAN_2);
|
||||
IRQ_EXIT(CAN2_SCE_IRQn);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MICROPY_HW_CAN3_TX)
|
||||
void CAN3_RX0_IRQHandler(void) {
|
||||
IRQ_ENTER(CAN3_RX0_IRQn);
|
||||
can_rx_irq_handler(PYB_CAN_3, CAN_FIFO0);
|
||||
IRQ_EXIT(CAN3_RX0_IRQn);
|
||||
}
|
||||
|
||||
void CAN3_RX1_IRQHandler(void) {
|
||||
IRQ_ENTER(CAN3_RX1_IRQn);
|
||||
can_rx_irq_handler(PYB_CAN_3, CAN_FIFO1);
|
||||
IRQ_EXIT(CAN3_RX1_IRQn);
|
||||
}
|
||||
|
||||
void CAN3_SCE_IRQHandler(void) {
|
||||
IRQ_ENTER(CAN3_SCE_IRQn);
|
||||
can_sce_irq_handler(PYB_CAN_3);
|
||||
IRQ_EXIT(CAN3_SCE_IRQn);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_PYB_LEGACY
|
||||
|
||||
#if defined(MICROPY_HW_I2C1_SCL)
|
||||
|
||||
Reference in New Issue
Block a user