MCUdude / MegaCore

Arduino hardware package for ATmega64, ATmega128, ATmega165, ATmega169, ATmega325, ATmega329, ATmega640, ATmega645, ATmega649, ATmega1280, ATmega1281, ATmega2560, ATmega2561, ATmega3250, ATmega3290, ATmega6450, ATmega6490, AT90CAN32, AT90CAN64 and AT90CAN128
Other
374 stars 115 forks source link

add Serial rx callback function #180

Closed lshw closed 2 years ago

lshw commented 2 years ago

example:

//return false drop char, bool rxcap(char ch) { if (ch == '1') { //if get char '1' Serial.println("callback!"); Serial.setRxCallBack(0); //disable CallBack return false; //del char '1' from rx buff } return true; }

void setup() { Serial.begin(115200); Serial.setRxCallBack(rxcap); }

void loop() { while(Serial.available()) Serial.write(Serial.read()); }

~

MCUdude commented 2 years ago

Care to explain what its intended purpose is? It doesn't seem to be a part of the official Arduino API, and your example doesn't quite show why it is useful.

lshw commented 2 years ago

This function can perform real-time operations, such as xon/xoff, or When avr uses multiple serial ports, use this function to realize that each serial port has a different size of receive buffer, or real-time mirroring from one serial port to another serial port, or can filter the received content first. refill the system's receive buffer,

MCUdude commented 2 years ago

Thanks for the explanation. Instead of submitting the PR here, please submit it to this repo instead. https://github.com/MCUdude/MCUdude_corefiles

MCUdude_corefiles are used as a submodule for MightyCore, MiniCore, MegaCore, and MajorCore.