rudihorn
5 years ago
committed by
GitHub
7 changed files with 232 additions and 22 deletions
@ -0,0 +1,80 @@ |
|||||
|
/**
|
||||
|
* Marlin 3D Printer Firmware |
||||
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
|
* |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
* |
||||
|
*/ |
||||
|
|
||||
|
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) |
||||
|
|
||||
|
#include "../../inc/MarlinConfig.h" |
||||
|
#include "MarlinSerial.h" |
||||
|
|
||||
|
#if ENABLED(EMERGENCY_PARSER) |
||||
|
#include "../../feature/e_parser.h" |
||||
|
#endif |
||||
|
|
||||
|
#define DECLARE_SERIAL_PORT(ser_num) \ |
||||
|
void _rx_complete_irq_ ## ser_num (serial_t * obj); \ |
||||
|
MarlinSerial MSerial ## ser_num (USART ## ser_num, &_rx_complete_irq_ ## ser_num); \ |
||||
|
void _rx_complete_irq_ ## ser_num (serial_t * obj) { MSerial ## ser_num ._rx_complete_irq(obj); } |
||||
|
|
||||
|
#define DECLARE_SERIAL_PORT_EXP(ser_num) DECLARE_SERIAL_PORT(ser_num) |
||||
|
|
||||
|
#if defined(SERIAL_PORT) && SERIAL_PORT >= 0 |
||||
|
DECLARE_SERIAL_PORT_EXP(SERIAL_PORT) |
||||
|
#endif |
||||
|
|
||||
|
#if defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0 |
||||
|
DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2) |
||||
|
#endif |
||||
|
|
||||
|
#if defined(DGUS_SERIAL_PORT) && DGUS_SERIAL_PORT >= 0 |
||||
|
DECLARE_SERIAL_PORT_EXP(DGUS_SERIAL_PORT) |
||||
|
#endif |
||||
|
|
||||
|
void MarlinSerial::begin(unsigned long baud, uint8_t config) { |
||||
|
HardwareSerial::begin(baud, config); |
||||
|
// replace the IRQ callback with the one we have defined
|
||||
|
#if ENABLED(EMERGENCY_PARSER) |
||||
|
_serial.rx_callback = _rx_callback; |
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
// This function is Copyright (c) 2006 Nicholas Zambetti.
|
||||
|
void MarlinSerial::_rx_complete_irq(serial_t *obj) { |
||||
|
// No Parity error, read byte and store it in the buffer if there is room
|
||||
|
unsigned char c; |
||||
|
|
||||
|
if (uart_getc(obj, &c) == 0) { |
||||
|
|
||||
|
rx_buffer_index_t i = (unsigned int)(obj->rx_head + 1) % SERIAL_RX_BUFFER_SIZE; |
||||
|
|
||||
|
// if we should be storing the received character into the location
|
||||
|
// just before the tail (meaning that the head would advance to the
|
||||
|
// current location of the tail), we're about to overflow the buffer
|
||||
|
// and so we don't write the character or advance the head.
|
||||
|
if (i != obj->rx_tail) { |
||||
|
obj->rx_buff[obj->rx_head] = c; |
||||
|
obj->rx_head = i; |
||||
|
} |
||||
|
|
||||
|
#if ENABLED(EMERGENCY_PARSER) |
||||
|
emergency_parser.update(emergency_state, c); |
||||
|
#endif |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
|
@ -0,0 +1,54 @@ |
|||||
|
/**
|
||||
|
* Marlin 3D Printer Firmware |
||||
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
|
* |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
* |
||||
|
*/ |
||||
|
#pragma once |
||||
|
|
||||
|
#include "../../inc/MarlinConfigPre.h" |
||||
|
|
||||
|
#if ENABLED(EMERGENCY_PARSER) |
||||
|
#include "../../feature/e_parser.h" |
||||
|
#endif |
||||
|
|
||||
|
typedef void (*usart_rx_callback_t)(serial_t * obj); |
||||
|
|
||||
|
class MarlinSerial : public HardwareSerial { |
||||
|
public: |
||||
|
MarlinSerial(void* peripheral, usart_rx_callback_t rx_callback) : |
||||
|
HardwareSerial(peripheral), _rx_callback(rx_callback) |
||||
|
#if ENABLED(EMERGENCY_PARSER) |
||||
|
, emergency_state(EmergencyParser::State::EP_RESET) |
||||
|
#endif |
||||
|
{ } |
||||
|
|
||||
|
void begin(unsigned long baud, uint8_t config); |
||||
|
inline void begin(unsigned long baud) { begin(baud, SERIAL_8N1); } |
||||
|
|
||||
|
void _rx_complete_irq(serial_t* obj); |
||||
|
|
||||
|
protected: |
||||
|
usart_rx_callback_t _rx_callback; |
||||
|
#if ENABLED(EMERGENCY_PARSER) |
||||
|
EmergencyParser::State emergency_state; |
||||
|
#endif |
||||
|
}; |
||||
|
|
||||
|
extern MarlinSerial MSerial1; |
||||
|
extern MarlinSerial MSerial2; |
||||
|
extern MarlinSerial MSerial3; |
||||
|
extern MarlinSerial MSerial4; |
||||
|
extern MarlinSerial MSerial5; |
@ -0,0 +1,55 @@ |
|||||
|
/**
|
||||
|
* Marlin 3D Printer Firmware |
||||
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
|
* |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
* |
||||
|
*/ |
||||
|
|
||||
|
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) |
||||
|
|
||||
|
#include "../../inc/MarlinConfigPre.h" |
||||
|
|
||||
|
#if ENABLED(EMERGENCY_PARSER) |
||||
|
|
||||
|
#include "usb_serial.h" |
||||
|
#include "../../feature/e_parser.h" |
||||
|
|
||||
|
EmergencyParser::State emergency_state = EmergencyParser::State::EP_RESET; |
||||
|
|
||||
|
int8_t (*USBD_CDC_Receive_original) (uint8_t *Buf, uint32_t *Len) = nullptr; |
||||
|
|
||||
|
static int8_t USBD_CDC_Receive_hook(uint8_t *Buf, uint32_t *Len) { |
||||
|
for (uint32_t i = 0; i < *Len; i++) |
||||
|
emergency_parser.update(emergency_state, Buf[i]); |
||||
|
return USBD_CDC_Receive_original(Buf, Len); |
||||
|
} |
||||
|
|
||||
|
typedef struct _USBD_CDC_Itf { |
||||
|
int8_t (* Init)(void); |
||||
|
int8_t (* DeInit)(void); |
||||
|
int8_t (* Control)(uint8_t cmd, uint8_t *pbuf, uint16_t length); |
||||
|
int8_t (* Receive)(uint8_t *Buf, uint32_t *Len); |
||||
|
int8_t (* Transferred)(void); |
||||
|
} USBD_CDC_ItfTypeDef; |
||||
|
|
||||
|
extern USBD_CDC_ItfTypeDef USBD_CDC_fops; |
||||
|
|
||||
|
void USB_Hook_init() { |
||||
|
USBD_CDC_Receive_original = USBD_CDC_fops.Receive; |
||||
|
USBD_CDC_fops.Receive = USBD_CDC_Receive_hook; |
||||
|
} |
||||
|
|
||||
|
#endif // EMERGENCY_PARSER
|
||||
|
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
|
@ -0,0 +1,21 @@ |
|||||
|
/**
|
||||
|
* Marlin 3D Printer Firmware |
||||
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
|
* |
||||
|
* This program is free software: you can redistribute it and/or modify |
||||
|
* it under the terms of the GNU General Public License as published by |
||||
|
* the Free Software Foundation, either version 3 of the License, or |
||||
|
* (at your option) any later version. |
||||
|
* |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
* |
||||
|
*/ |
||||
|
#pragma once |
||||
|
|
||||
|
void USB_Hook_init(); |
Loading…
Reference in new issue