Stepdance Software Library
Loading...
Searching...
No Matches
input_ports.hpp
1#include <sys/_stdint.h>
2/*
3Input Ports Module of the StepDance Control System
4
5This module is responsible for reading input streams on the input ports, and directing them to
6specific channels.
7
8[More Details to be Added]
9
10A part of the Mixing Metaphors Project
11(c) 2025 Ilan Moyer, Jennifer Jacobs, Devon Frost, Emilie Yu
12*/
13#include "channels.hpp"
14#include "imxrt.h"
15
16#ifndef input_ports_h //prevent importing twice
17#define input_ports_h
18
19#define NUM_AVAILABLE_INPUT_PORTS 6 //four in new PCB designs, plus one legacy port in old PCBs. If changed, must adjust ISR functions in input_port
20#define INPUT_A 0
21#define INPUT_B 1
22#define INPUT_C 2
23#define INPUT_D 3
24#define INPUT_B_LEGACY 4 // Port B on legacy DPW Modules
25#define INPUT_C_LEGACY 5 // PORT C on legacy DPW Modules
26
27#define FLEXPWM_CHANNEL_X 0
28#define FLEXPWM_CHANNEL_A 1
29#define FLEXPWM_CHANNEL_B 2
30
31#define FLEXPWM_CLOCK_MHZ 150
32
33#define SIGNAL_MIN_WIDTH_US 2 //standard input format
34
39struct input_port_info_struct{ //we use this structure to store hardware-specific information for each available port
40 // Physical IO
41 uint8_t STEP_TEENSY_PIN; //TEENSY Pin #s
42 uint8_t DIR_TEENSY_PIN;
43
44 // FlexPWM Module Setup
45 uint8_t FLEXPWM_NUM; //FlexPWM number, e.g. 1 for FlexPWM1
46 IMXRT_FLEXPWM_t *FLEXPWM; // pointer to FlexPWM Module
47 uint8_t SUBMODULE; // submodule # 0-3
48 uint8_t FLEXPWM_CHANNEL; // submodule channel, use definitions like FLEXPWM_CHANNEL_X
49 uint8_t STEP_PIN_MUX; //pad mux value for flexpwm module
50 volatile uint32_t *SELECT_INPUT_REGISTER; //pwm pad select register, for pins that can connect to multiple pads
51 uint32_t SELECT_REGISTER_VALUE; //appropriate pad select register value
52 uint8_t IRQ; // the IRQ number for the interrupt source
53 void (*STATIC_ISR)(); // interrupt service routine. This needs to be a static function. We do some acrobatics to be able to call class methods as ISRs.
54};
56
65class InputPort : public Plugin{
66 public:
80 void begin(uint8_t port_number);
93 void enable_signal(uint8_t signal_index);
98 void disable_signal(uint8_t signal_index);
104 void set_ratio(float output_units, float input_units = 1.0);
109 void enroll(RPC *rpc, const String& instance_name);
110
111 volatile uint32_t input_interrupt_cycles; //measures the number of cycles spent in each input interrupt routine.
113
114 // BlockPorts
123 BlockPort output_x; // 2us signal
127 BlockPort output_y; // 3us signal
131 BlockPort output_r; // 4us signal
135 BlockPort output_t; // 5us signal
139 BlockPort output_z; // 6us signal
143 BlockPort output_e; // 7us signal
144
145
146
147
148 private:
149 // Configuration Parameters
150 uint8_t port_number; //the output port ID number
151 static const struct input_port_info_struct port_info[]; //stores setup information for all four input ports
152 static InputPort *indexed_input_ports[NUM_AVAILABLE_INPUT_PORTS]; //keeps pointers to all active input ports, indexed by their port number. Only used for ISR routines.
153
154 IMXRT_FLEXPWM_t *FLEXPWM;
155 uint8_t SUBMODULE;
156 uint8_t SUBMODULE_BIT;
157 uint8_t FLEXPWM_CHANNEL;
158 // The following variables are used within the pulse detection and routing ISR, but we declare them here to save ISR run time.
159 volatile uint16_t last_pulse_width_count; //important that this is UINT16_T to calculate rollover correctly.
160
161 // State Parameters
162 BlockPort *signal_BlockPort_targets[NUM_SIGNALS] = {&output_x, &output_y, &output_r, &output_t, &output_z, &output_e}; //pointers to BlockPorts, indexed by signal number
163 bool signal_enable_flags[NUM_SIGNALS] = {true, true, true};
164
165 // Private Methods
166 void isr(); //this is the actual ISR function
167 static void input_A_isr();
168 static void input_B_isr();
169 static void input_C_isr();
170 static void input_D_isr();
171 static void input_B_legacy_isr();
172 static void input_C_legacy_isr();
173
174
175 // Input Position Registers
176 DecimalPosition position_x;
177 DecimalPosition position_y;
178 DecimalPosition position_r;
179 DecimalPosition position_t;
180 DecimalPosition position_z;
181 DecimalPosition position_e;
182
183 protected:
188 void run();
190};
191
192
193
194#endif
BlockPorts provide a unified interface for mapping inputs and outputs of different StepDance componen...
Definition core.hpp:148
void enable_all_signals()
Enables all input signals (SIGNAL_X, SIGNAL_Y, SIGNAL_Z, SIGNAL_E, SIGNAL_R, SIGNAL_T)....
BlockPort output_y
BlockPort that acts as output for the SIGNAL_Y input.
Definition input_ports.hpp:127
void set_ratio(float output_units, float input_units=1.0)
Sets the ratio between input units and output units for all input signals. Default is 1:1.
BlockPort output_x
BlockPort that acts as output for the SIGNAL_X input.
Definition input_ports.hpp:123
void enable_signal(uint8_t signal_index)
Enables a specific input signal.
void begin(uint8_t port_number)
Initialize the InputPort with a port number corresponding to the target physical port on the Stepdanc...
BlockPort output_t
BlockPort that acts as output for the SIGNAL_T input.
Definition input_ports.hpp:135
void disable_signal(uint8_t signal_index)
Disables a specific input signal.
void disable_all_signals()
Disables all input signals (SIGNAL_X, SIGNAL_Y, SIGNAL_Z, SIGNAL_E, SIGNAL_R, SIGNAL_T).
BlockPort output_z
BlockPort that acts as output for the SIGNAL_Z input.
Definition input_ports.hpp:139
BlockPort output_e
BlockPort that acts as output for the SIGNAL_E input.
Definition input_ports.hpp:143
InputPort()
Default constructor for InputPort.
BlockPort output_r
BlockPort that acts as output for the SIGNAL_R input.
Definition input_ports.hpp:131
RPC class for handling remote procedure calls over serial streams.
Definition rpc.hpp:35