kopia lustrzana https://gitlab.com/markol/Teathimble_Firmware
Some refactoring
rodzic
cbeec817b6
commit
62f2a4871b
|
@ -9,8 +9,8 @@
|
||||||
//#define RXD1 DIO7
|
//#define RXD1 DIO7
|
||||||
//#define TXD1 DIO8
|
//#define TXD1 DIO8
|
||||||
|
|
||||||
// ATmega32U4 doesn't have a serial port 0, maybe its a USB?
|
|
||||||
// do some munging of port 0 to port 1 the help serial.c
|
// do some munging of serial port
|
||||||
#define UCSR0A UCSRA
|
#define UCSR0A UCSRA
|
||||||
#define U2X0 U2X
|
#define U2X0 U2X
|
||||||
#define UBRR0 UBRRL
|
#define UBRR0 UBRRL
|
||||||
|
|
8
config.h
8
config.h
|
@ -154,7 +154,6 @@
|
||||||
|
|
||||||
#define ENCODER_PIN 17
|
#define ENCODER_PIN 17
|
||||||
|
|
||||||
|
|
||||||
#define PWR_OUT1_PIN 18
|
#define PWR_OUT1_PIN 18
|
||||||
#define PWR_OUT2_PIN 19
|
#define PWR_OUT2_PIN 19
|
||||||
#define ANALOG_IN_PIN 33
|
#define ANALOG_IN_PIN 33
|
||||||
|
@ -180,12 +179,6 @@
|
||||||
#define F_CPU 16000000UL
|
#define F_CPU 16000000UL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** \def MOTHERBOARD
|
|
||||||
This is the motherboard, as opposed to the extruder. See extruder/ directory
|
|
||||||
for GEN3 extruder firmware.
|
|
||||||
*/
|
|
||||||
#define MOTHERBOARD
|
|
||||||
|
|
||||||
/** \def DEBUG_LED_PIN
|
/** \def DEBUG_LED_PIN
|
||||||
|
|
||||||
Enable flashing of a LED during motor stepping.
|
Enable flashing of a LED during motor stepping.
|
||||||
|
@ -197,6 +190,7 @@
|
||||||
http://reprap.org/wiki/Teacup_Firmware#Doing_precision_profiling
|
http://reprap.org/wiki/Teacup_Firmware#Doing_precision_profiling
|
||||||
*/
|
*/
|
||||||
#define DEBUG_LED_PIN PC1
|
#define DEBUG_LED_PIN PC1
|
||||||
|
|
||||||
////////////////DEBUG/////////////////////
|
////////////////DEBUG/////////////////////
|
||||||
#define SIMINFO
|
#define SIMINFO
|
||||||
#define DEBUG
|
#define DEBUG
|
||||||
|
|
|
@ -8,18 +8,26 @@
|
||||||
#define IS_ENDING(c) (c == '\n' || c == '\r')
|
#define IS_ENDING(c) (c == '\n' || c == '\r')
|
||||||
#define ATOI(c) (c - '0')
|
#define ATOI(c) (c - '0')
|
||||||
|
|
||||||
|
#define STATE_ERROR 1
|
||||||
|
|
||||||
GCODE_PARAM params[8];
|
GCODE_PARAM params[8];
|
||||||
uint8_t current_parameter;
|
uint8_t current_parameter;
|
||||||
TARGET next_target;
|
TARGET next_target;
|
||||||
|
|
||||||
|
// Parser is implemented as a finite state automata (DFA)
|
||||||
|
// This is pointer holds function with actions expected for current progress, each of these functions
|
||||||
|
// changes its value on state change
|
||||||
uint8_t (*current_state)(uint8_t c);
|
uint8_t (*current_state)(uint8_t c);
|
||||||
|
|
||||||
|
//a few state functions prototypes
|
||||||
uint8_t start_parsing_parameter(uint8_t );
|
uint8_t start_parsing_parameter(uint8_t );
|
||||||
uint8_t start_parse_number(uint8_t);
|
uint8_t start_parsing_number(uint8_t);
|
||||||
|
|
||||||
|
|
||||||
/// convert a floating point input value into an integer with appropriate scaling.
|
/// convert a floating point input value into an integer with appropriate scaling.
|
||||||
/// \param *df pointer to floating point structure that holds fp value to convert
|
/// \param mantissa the actual digits of our floating point number
|
||||||
|
/// \param exponent scale mantissa by \f$10^{-exponent}\f$
|
||||||
|
/// \param sign positive or negative?
|
||||||
/// \param multiplicand multiply by this amount during conversion to integer
|
/// \param multiplicand multiply by this amount during conversion to integer
|
||||||
///
|
///
|
||||||
/// Tested for up to 42'000 mm (accurate), 420'000 mm (precision 10 um) and
|
/// Tested for up to 42'000 mm (accurate), 420'000 mm (precision 10 um) and
|
||||||
|
@ -65,7 +73,7 @@ void parser_init()
|
||||||
next_target.f_multiplier = 256;
|
next_target.f_multiplier = 256;
|
||||||
parser_reset();
|
parser_reset();
|
||||||
}
|
}
|
||||||
|
// this function executes command after is parsed
|
||||||
void process_command()
|
void process_command()
|
||||||
{
|
{
|
||||||
for(int i = 1; i <= current_parameter; ++i)
|
for(int i = 1; i <= current_parameter; ++i)
|
||||||
|
@ -100,11 +108,12 @@ void process_command()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t gcode_error(uint8_t c)
|
|
||||||
|
uint8_t gcode_syntax_error(uint8_t c)
|
||||||
{
|
{
|
||||||
if IS_ENDING(c)
|
if IS_ENDING(c)
|
||||||
parser_reset();
|
parser_reset();
|
||||||
return 1;
|
return STATE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t start_parsing_parameter(uint8_t c)
|
uint8_t start_parsing_parameter(uint8_t c)
|
||||||
|
@ -120,11 +129,11 @@ uint8_t start_parsing_parameter(uint8_t c)
|
||||||
if IS_LETTER(c)
|
if IS_LETTER(c)
|
||||||
{
|
{
|
||||||
params[current_parameter].name = c;
|
params[current_parameter].name = c;
|
||||||
current_state = start_parse_number;
|
current_state = start_parsing_number;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
current_state = gcode_error;
|
current_state = gcode_syntax_error;
|
||||||
return 1;
|
return STATE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t parse_digit(uint8_t c)
|
uint8_t parse_digit(uint8_t c)
|
||||||
|
@ -161,11 +170,11 @@ uint8_t parse_digit(uint8_t c)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_state = gcode_error;
|
current_state = gcode_syntax_error;
|
||||||
return 1;
|
return STATE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t start_parse_number(uint8_t c)
|
uint8_t start_parsing_number(uint8_t c)
|
||||||
{
|
{
|
||||||
current_state = parse_digit;
|
current_state = parse_digit;
|
||||||
//negative number
|
//negative number
|
||||||
|
@ -179,8 +188,8 @@ uint8_t start_parse_number(uint8_t c)
|
||||||
parse_digit(c);
|
parse_digit(c);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
current_state = gcode_error;
|
current_state = gcode_syntax_error;
|
||||||
return 1;
|
return STATE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t gcode_parse_char(uint8_t c) {
|
uint8_t gcode_parse_char(uint8_t c) {
|
||||||
|
@ -192,7 +201,7 @@ uint8_t gcode_parse_char(uint8_t c) {
|
||||||
|
|
||||||
if IS_ENDING(c)
|
if IS_ENDING(c)
|
||||||
{
|
{
|
||||||
if ( result == 1) //error
|
if ( result == STATE_ERROR) //error
|
||||||
return 2;
|
return 2;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ extern const uint32_t powers[]; // defined in msg.c
|
||||||
/// accept the next character and process it
|
/// accept the next character and process it
|
||||||
uint8_t gcode_parse_char(uint8_t c);
|
uint8_t gcode_parse_char(uint8_t c);
|
||||||
|
|
||||||
|
/// setup variables
|
||||||
void parser_init();
|
void parser_init();
|
||||||
|
|
||||||
#endif /* _GCODE_PARSE_H */
|
#endif /* _GCODE_PARSE_H */
|
|
@ -4,7 +4,6 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "motor.h"
|
#include "motor.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,12 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "pinio.h"
|
#include "pinio.h"
|
||||||
//#include "clock.h"
|
|
||||||
//#include "cpu.h"
|
/** \def MOTHERBOARD
|
||||||
//#include "memory_barrier.h"
|
This is the motherboard, as opposed to the extruder. See extruder/ directory
|
||||||
|
for GEN3 extruder firmware.
|
||||||
|
*/
|
||||||
|
#define MOTHERBOARD
|
||||||
|
|
||||||
#ifdef MOTHERBOARD
|
#ifdef MOTHERBOARD
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
|
Ładowanie…
Reference in New Issue