From 0219963dd7753ef4689dd7d9cc88a7fe2c962ba0 Mon Sep 17 00:00:00 2001 From: 1nct Date: Wed, 3 Aug 2022 19:19:14 +0200 Subject: [PATCH] - Minor changes to variable names, comments & formatting - Removed obsolete parameter previously used in program_mode - Added correction constant regarding base pwm measurement - Revised GPIO definitions (shared.h) --- CV.h | 14 +++-- core0.c | 153 ++++++++++++++++++++++++++++--------------------------- core0.h | 2 +- core1.c | 11 ++-- shared.h | 24 +++++---- 5 files changed, 106 insertions(+), 98 deletions(-) diff --git a/CV.h b/CV.h index 28e1ae3..f7859d2 100644 --- a/CV.h +++ b/CV.h @@ -1,19 +1,18 @@ #pragma once #define CV_ARRAY_SIZE 512 -// All CVs are 8-bit numbers (range 0 - 255) +// All CVs are 8-bit numbers ranging from (0 - 255)dec ≙ (0b00000000 - 0b11111111)bin ≙ (0x00 - 0xFF)hex // Note : CV_1 ≙ index 0, CV_2 ≙ index 1, CV_3 ≙ index 2, ... -// TODO: - Packet Timeout uint8_t CV_ARRAY_DEFAULT [CV_ARRAY_SIZE] = { - 0b00000011, //CV_1 - Basic address CV_1 = 0 is not allowed and used for initiating ADC offset adjustment //TODO: verify - 0b00001000, //CV_2 - V_min - Default = 8 + 0b00000011, //CV_1 - Basic address - CV_1 = 0 and CV_1 > 127 are not valid - Default = 3 + 0b00001000, //CV_2 - V_min - Default = 8 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 0 == Fastest dec/acc rate; 255 == slowest; 0b00000000, //CV_3 - Acceleration rate - CV_3*CV_175 = Time for one discrete speed step change in ms 0b00000000, //CV_4 - Deceleration rate - CV_4*CV_175 = Time for one discrete speed step change in ms ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - 0b01100100, //CV_5 - V_max - Default = 100*16 - 0b00111111, //CV_6 - V_mid - Default = 63*16 + 0b01100100, //CV_5 - V_max - Default = 100*16 + 0b00111111, //CV_6 - V_mid - Default = 63*16 0b00000001, //CV_7 - Version no. (read-only) 0b00001101, //CV_8 - Manufacturer (13 = Public Domain & Do-It-Yourself Decoders) (read-only) 0b10010110, //CV_9 - PWM frequency in Hz = CV_9*100+10000 - Default = (150*100+10000)Hz = 25kHz @@ -135,7 +134,7 @@ uint8_t CV_ARRAY_DEFAULT [CV_ARRAY_SIZE] = { // This Config can cause conflicts when GPIOs controlled by the same slice are enabled at the same time. 0b00000000, //CV_112 - GPIO 24-31 enable PWM 0b00000000, //CV_113 - GPIO 16-23 enable PWM - 0b00111100, //CV_114 - GPIO 8-15 enable PWM + 0b00000000, //CV_114 - GPIO 8-15 enable PWM 0b00000000, //CV_115 - GPIO 0-7 enable PWM //Slice 0 0b00000000, //CV_116 - Wrap Bits 8-15 @@ -204,7 +203,6 @@ uint8_t CV_ARRAY_DEFAULT [CV_ARRAY_SIZE] = { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Offset adjustment for ADC // //If CV_172 = 0xFF = 255 there will be a measurement procedure on startup // -//alternatively, the measurement can be done by writing a 0 to CV_1 on the programming track // 0b11111111, //CV_172 - ADC offset Default: 255 // 0b01111111, //CV_173 - ADC offset measurement cycles Default: 127 // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/core0.c b/core0.c index 741d6f4..7dcf1f8 100644 --- a/core0.c +++ b/core0.c @@ -5,6 +5,7 @@ ////////////////////////// #include "core0.h" +// XIP_BASE + FLASH_TARGET_OFFSET = "0x101FF000" const uint8_t *CV_ARRAY_FLASH = (const uint8_t *) (XIP_BASE + FLASH_TARGET_OFFSET); uint64_t input_bit_buffer = 0; uint16_t level_table[32] = {0}; @@ -98,7 +99,7 @@ void acknowledge() { } -// When Bit matches sent byte -> acknowledge() +// When bit matches sent byte -> acknowledge() void verify_cv_bit(uint16_t cv_address,bool bit_val, uint8_t bit_pos) { uint8_t mask = 0b00000001; bool res = ( (CV_ARRAY_FLASH[cv_address] >> bit_pos) &mask ) == bit_val; @@ -108,11 +109,13 @@ void verify_cv_bit(uint16_t cv_address,bool bit_val, uint8_t bit_pos) { } -// When Byte matches sent byte -> acknowledge() +// When byte matches sent byte -> acknowledge() void verify_cv_byte(uint16_t cv_address, uint8_t cv_data){ if (CV_ARRAY_FLASH[cv_address] == cv_data) acknowledge(); } + +// CV writing function first erases necessary amount of blocks in flash and then rewrites to flash void regular_cv_write(uint16_t cv_index, uint8_t cv_data){ uint8_t CV_ARRAY_TEMP[CV_ARRAY_SIZE]; memcpy(CV_ARRAY_TEMP, CV_ARRAY_FLASH, sizeof(CV_ARRAY_TEMP)); @@ -123,41 +126,39 @@ void regular_cv_write(uint16_t cv_index, uint8_t cv_data){ } -// CV writing function first erases block in flashes and then rewrites to flash -// Writing to read-only functions also gets handled here (e.g. complete reset to default) +// There are some exceptions to writing CVs - e.g. writing to a read only CV is not valid - this gets handled here void write_cv_handler(uint16_t cv_index, uint8_t cv_data){ switch (cv_index) { - // CV_1 => Value = 0 is not allowed - case 0: + case 0: //CV_1 + // CV_1 => Value = 0 is not allowed if (cv_data == 0 || cv_data > 127) break; - // CV_7 & CV_8 are read-only - // ADC offset Adjustment (CV_7; Value = 7); - case 6: + case 6: //CV_7 + // Read only (CV_7 - Version no.) + // ADC offset Adjustment (CV_7; Value = 7); if (cv_data == 7) adc_offset_adjustment(8192); break; - // Reset all CVs to Default (CV_8; Value = 8) - case 7: + case 7: //CV_8 + // Read only (CV_8 - Manufacturer ID) + // Reset all CVs to Default (CV_8; Value = 8) if (cv_data == 8){ flash_range_erase(FLASH_TARGET_OFFSET, FLASH_SECTOR_SIZE); flash_range_program(FLASH_TARGET_OFFSET, CV_ARRAY_DEFAULT, FLASH_PAGE_SIZE * 2); } break; - // CV_17 must have a value between 11000000->(192dec) and 11100111->(231dec) inclusive // CV_17 == 192 && CV_18 == 0 -> Address = 0 is also not valid and therefore shall not be set - case 16: + case 16: //CV_17 if ( (cv_data < 192 || cv_data > 231) || (CV_ARRAY_FLASH[17] == 0 && cv_data == 192) ) break; else regular_cv_write(cv_index,cv_data); break; - case 17: + case 17: //CV_18 if(CV_ARRAY_FLASH[16] == 192 && cv_data == 0) break; else regular_cv_write(cv_index,cv_data); break; // CV_31 & CV_32 Index high byte isn't implemented and shall not be set - case 30: - case 31: + case 30: //CV_31 + case 31: //CV_32 break; - // Regular CV write is carried out default: regular_cv_write(cv_index,cv_data); @@ -166,7 +167,7 @@ void write_cv_handler(uint16_t cv_index, uint8_t cv_data){ // CV Programming function resets core1 and evaluates the type of programming instruction (e.g. write byte) -void program_mode(uint8_t number_of_bytes, const uint8_t * const byte_array, bool restart_core1){ +void program_mode(uint8_t number_of_bytes, const uint8_t * const byte_array){ //First check for valid programming command ("address" 112-127) if (byte_array[number_of_bytes - 1]<128 && byte_array[number_of_bytes - 1]>111){ uint8_t instruction_type_mask = 0b00001100; @@ -210,25 +211,28 @@ void program_mode(uint8_t number_of_bytes, const uint8_t * const byte_array, boo } - - - // Set outputs according to configuration (PWM on/off, PWM duty cycle/level, ...) void set_outputs(uint32_t functions_to_set_bitmask) { + // Get outputs with pwm enabled and preset outputs_to_set_PWM variable with resulting GPIO Bitmask + uint32_t PWM_enabled_outputs = get_32bit_CV(111); + uint32_t outputs_to_set_PWM = PWM_enabled_outputs; + + // Get enabled output configuration corresponding to set functions and direction uint32_t outputs_to_set = 0; - uint32_t outputs_with_PWM_enabled = get_32bit_CV(111); //get outputs with pwm enabled (bitmask) // TODO: Verify - should be fine... - uint32_t outputs_to_set_PWM = outputs_with_PWM_enabled; uint32_t temp_mask = 1; for (uint8_t i = 0; i < 32; i++) { if (temp_mask & functions_to_set_bitmask ){ - //outputs_to_set |= get_32bit_CV(i * 8 + 260 - 4 * get_direction(0)); //TODO: verify + outputs_to_set |= get_32bit_CV(i * 8 + 260 - 4 * get_direction(0)); } temp_mask<<=1; } - outputs_to_set &= GPIO_ALLOWED_OUTPUTS; // Prevent illegal GPIO outputs_to_set_PWM &= outputs_to_set; // Outputs with PWM to be enabled outputs_to_set &= ~outputs_to_set_PWM; // Outputs without PWM to be enabled + + // Set regular outputs without PWM, preventing illegal GPIO by masking with GPIO_ALLOWED_OUTPUTS gpio_put_masked(GPIO_ALLOWED_OUTPUTS, outputs_to_set); + + // Set PWM enabled outputs to desired level temp_mask = 1; for (uint8_t i = 0; i < 32; ++i) { if(temp_mask & outputs_to_set_PWM){ @@ -236,7 +240,7 @@ void set_outputs(uint32_t functions_to_set_bitmask) { pwm_gpio_to_channel(i); pwm_gpio_to_slice_num(i); } - else if (temp_mask & outputs_with_PWM_enabled){ + else if (temp_mask & PWM_enabled_outputs){ pwm_set_gpio_level(i,0); } temp_mask<<=1; @@ -248,15 +252,19 @@ void set_outputs(uint32_t functions_to_set_bitmask) { void update_active_functions(uint32_t new_function_bitmask, uint8_t clr_bit_ind, bool direction_change) { static uint32_t active_functions; static uint32_t prev_active_func; - if (direction_change){ - set_outputs(prev_active_func); - } + + // Outputs depend on direction + // In case of a direction change every output needs to be set according to configuration for the other direction + if (direction_change) set_outputs(active_functions); + + // In case of a change in active functions only the function group corresponding to the instruction is considered + // Check for changes and set outputs accordingly else{ - new_function_bitmask &= ~(clr_bit_arr[clr_bit_ind]); //clear every bit except bits corresponding to group of functions - active_functions &= clr_bit_arr[clr_bit_ind]; //clear bits corresponding to group of functions - active_functions |= new_function_bitmask; //write bits corresponding to group of functions - uint32_t changes = active_functions ^ prev_active_func; //xor effectively checks for changes from previous state - if(changes)set_outputs(active_functions); + new_function_bitmask &= ~(clr_bit_arr[clr_bit_ind]); // Clear every bit except bits corresponding to group of functions + active_functions &= clr_bit_arr[clr_bit_ind]; // Clear bits corresponding to group of functions + active_functions |= new_function_bitmask; // Write bits corresponding to group of functions + uint32_t changes = active_functions ^ prev_active_func; // Checks for changes from previous state + if(changes) set_outputs(active_functions); prev_active_func = active_functions; } } @@ -334,11 +342,14 @@ void instruction_evaluation(uint8_t number_of_bytes,const uint8_t * const byte_a //0011-1111 (128 Speed Step Control) - 2 Byte length if (command_byte_n == 0b00111111){ - bool prev_dir = get_direction(0); + static bool prev_dir; uint32_t speed_step = byte_array[command_byte_start_index - 1]; multicore_fifo_push_blocking(speed_step); // In case of a direction change, functions need to be updated because functions might depend on direction state - if (get_direction(0) != prev_dir) update_active_functions(0,0,true); + if (get_direction(0) != prev_dir) { + update_active_functions(0,0,true); + prev_dir = get_direction(0); + } } // 10XX-XXXX (Function Group Instruction) @@ -379,30 +390,22 @@ void instruction_evaluation(uint8_t number_of_bytes,const uint8_t * const byte_a bool reset_package_check(uint8_t number_of_bytes,const uint8_t * const byte_array){ if (byte_array[number_of_bytes-1] == 0b00000000 && byte_array[number_of_bytes-2] == 0b00000000){ uint32_t speed_step = 1; - multicore_fifo_push_blocking(speed_step); - update_active_functions(0,0,0); //TODO: is this correct? + multicore_fifo_push_blocking(speed_step); // Emergency Stop + update_active_functions(0,0,0); // Disables all functions return true; } - else { - return false; - } + else return false; } // Checks for valid package - looking for correct preamble int8_t check_for_package() { //returns number of bytes if valid bit-pattern is found. Otherwise -1 is returned. uint64_t package3Masked = input_bit_buffer & PACKAGE_MASK_3_BYTES; - if (package3Masked == PACKAGE_3_BYTES) { - return 3; - } + if (package3Masked == PACKAGE_3_BYTES) return 3; uint64_t package4Masked = input_bit_buffer & PACKAGE_MASK_4_BYTES; - if (package4Masked == PACKAGE_4_BYTES) { - return 4; - } + if (package4Masked == PACKAGE_4_BYTES) return 4; uint64_t package5Masked = input_bit_buffer & PACKAGE_MASK_5_BYTES; - if (package5Masked == PACKAGE_5_BYTES) { - return 5; - } + if (package5Masked == PACKAGE_5_BYTES) return 5; return -1; } @@ -420,7 +423,7 @@ void evaluation(){ static bool core1_launched = false; static bool reset_package_flag; int8_t number_of_bytes = check_for_package(); - // number of bytes is != -1 when the package is valid + // number_of_bytes contains the amount of bytes when the package is valid, otherwise -1 if (number_of_bytes != -1) { // Split data into 8Bit array uint8_t byte_array[SIZE_BYTE_ARRAY] = {0}; @@ -440,7 +443,7 @@ void evaluation(){ } // When previous packet was a reset package -> enter program mode else if (reset_package_flag) { - program_mode(number_of_bytes,byte_array,true); + program_mode(number_of_bytes,byte_array); } // Check for reset package and set flag when reset package is received else { @@ -481,28 +484,30 @@ void track_signal_fall(unsigned int gpio, long unsigned int events) { } -// Output initialization function - configures pwm frequency and clock divider according to CV_ARRAY_FLASH[] +// Output initialization function - Configures pwm frequency and clock divider according to CV_111 - CV_171 void init_outputs(){ gpio_init_mask(GPIO_ALLOWED_OUTPUTS); - gpio_set_dir_out_masked(GPIO_ALLOWED_OUTPUTS); //note: This might also disable UART on GPIO0 & GPIO1 - uint32_t Outputs_with_PWM_enabled = get_32bit_CV(111); // TODO: Verify - should be fine... + gpio_set_dir_out_masked(GPIO_ALLOWED_OUTPUTS); // Note: This might also disable UART on GPIO0 & GPIO1 + uint32_t PWM_enabled_outputs = get_32bit_CV(111) & GPIO_ALLOWED_OUTPUTS; uint32_t slice, channel; uint16_t wrap, level; - uint32_t temp_mask = 1; + uint8_t clock_divider; + uint32_t mask = 1; for (uint8_t i = 0; i < 32; ++i) { - if (Outputs_with_PWM_enabled&temp_mask){ + if (PWM_enabled_outputs & mask){ slice = pwm_gpio_to_slice_num(i); - channel = pwm_gpio_to_channel(i); //0 for Channel A, 1 for Channel B - wrap = get_16bit_CV(115 + slice*7); // TODO: Verify - level = get_16bit_CV(118 + 7*slice+ 2*channel); // TODO: Verify + channel = pwm_gpio_to_channel(i); // Channel A = "0"; Channel B = "1" + wrap = get_16bit_CV(115 + 7*slice); + level = get_16bit_CV(118 + 7*slice + 2*channel); + clock_divider = CV_ARRAY_FLASH[117+7*slice] + 1; gpio_set_function(i,GPIO_FUNC_PWM); pwm_set_wrap(slice,wrap); pwm_set_gpio_level(i,0); level_table[i] = level; - pwm_set_clkdiv_int_frac(slice,CV_ARRAY_FLASH[117+7*slice],0); + pwm_set_clkdiv_int_frac(slice,clock_divider,0); pwm_set_enabled(slice,true); } - temp_mask<<=1; + mask<<=1; } } @@ -514,25 +519,25 @@ uint16_t measure_base_pwm(bool direction, uint8_t iterations){ else gpio = MOTOR_REV_PIN; float level_arr[iterations]; for (int i = 0; i < iterations; ++i) { - uint16_t level = 0; + uint16_t max_level = (_125M/(CV_ARRAY_FLASH[8]*100+10000)); + uint16_t level = max_level/20; float measurement; do { pwm_set_gpio_level(gpio, level); busy_wait_ms(15); - level += 10; + level += max_level/500; measurement = measure(CV_ARRAY_FLASH[60], CV_ARRAY_FLASH[61], CV_ARRAY_FLASH[62], CV_ARRAY_FLASH[63], direction); } - // (Measurement - ADC_Offset) < 5.0f while((measurement - (float)CV_ARRAY_FLASH[171]) < 5.0f); level_arr[i] = (float)level; - busy_wait_ms(500); + busy_wait_ms(100); } - // Find and return overall average discarding outliers in measurement - return (uint16_t)two_std_dev(level_arr,5); + // Find and return overall average discarding outliers in measurement - multiply with 0.9 + return (uint16_t)(0.9f*two_std_dev(level_arr,5)); } @@ -544,13 +549,13 @@ void cv_setup_check(){ // Check for flash factory setting and set CV_FLASH_ARRAY to default values when factory condition is found. if ( CV_ARRAY_FLASH[64] ){ uint8_t arr[4] = {125,8,7,124}; - program_mode(4,arr,false); //reset to CV_ARRAY_DEFAULT (write CV_8 = 8) + program_mode(4,arr); //reset to CV_ARRAY_DEFAULT (write CV_8 = 8) } // Check for adc offset setup if ( CV_ARRAY_FLASH[171] == 0xFF ){ uint8_t arr[4] = {125,7,6,124}; - program_mode(4,arr,false); //ADC offset adjustment (write CV_7 = 7) + program_mode(4,arr); //ADC offset adjustment (write CV_7 = 7) } // Check for base PWM configuration - used for feed-forward @@ -560,9 +565,9 @@ void cv_setup_check(){ uint8_t base_pwm_fwd_high_byte = base_pwm_fwd>>8; uint8_t base_pwm_fwd_low_byte = base_pwm_fwd&0x00FF; uint8_t arr0[4] = {125,base_pwm_fwd_high_byte,175,124}; - program_mode(4,arr0,false); + program_mode(4,arr0); uint8_t arr1[4] = {125,base_pwm_fwd_low_byte,176,124}; - program_mode(4,arr1,false); + program_mode(4,arr1); } // Reverse Direction if (get_16bit_CV(177) == 0){ @@ -570,9 +575,9 @@ void cv_setup_check(){ uint8_t base_pwm_rev_high_byte = base_pwm_rev>>8; uint8_t base_pwm_rev_low_byte = base_pwm_rev&0x00FF; uint8_t arr0[4] = {125,base_pwm_rev_high_byte,177,124}; - program_mode(4,arr0,false); + program_mode(4,arr0); uint8_t arr1[4] = {125,base_pwm_rev_low_byte,178,124}; - program_mode(4,arr1,false); + program_mode(4,arr1); } } diff --git a/core0.h b/core0.h index 4576a29..1cb0602 100644 --- a/core0.h +++ b/core0.h @@ -30,7 +30,7 @@ void verify_cv_bit(uint16_t cv_address,bool bit_val, uint8_t bit_pos); void verify_cv_byte(uint16_t cv_address, uint8_t cv_data); void regular_cv_write(uint16_t cv_index, uint8_t cv_data); void write_cv_handler(uint16_t cv_index, uint8_t cv_data); -void program_mode(uint8_t number_of_bytes, const uint8_t byte_array[], bool restart_core1); +void program_mode(uint8_t number_of_bytes, const uint8_t byte_array[]); void set_outputs(uint32_t functions_to_set_bitmask); void update_active_functions(uint32_t byte, uint8_t clr_bit_ind,bool direction_change); bool error_detection(int8_t number_of_bytes, const uint8_t byte_array[]); diff --git a/core1.c b/core1.c index 42ce5ac..598aeb3 100644 --- a/core1.c +++ b/core1.c @@ -19,7 +19,7 @@ void update_speed_dir(pid_params *pid, uint32_t speed_step_target){ if (pid->speed_step_target == 128) pid->end_target_index = 0; else pid->end_target_index = (pid->speed_step_target-129); } - // Reverse + // Reverse else { pid->direction = false^reverse_dir; if (pid->speed_step_target == 0) pid->end_target_index = 0; @@ -75,11 +75,12 @@ bool speed_helper(struct repeating_timer *t) { // Helper function to adjust pwm level/duty cycle. void adjust_pwm_level(uint16_t level, pid_params *pid) { + // Forward if (pid->direction) { pwm_set_gpio_level(MOTOR_REV_PIN, 0); pwm_set_gpio_level(MOTOR_FWD_PIN, level); } - //Reverse + // Reverse else { pwm_set_gpio_level(MOTOR_FWD_PIN, 0); pwm_set_gpio_level(MOTOR_REV_PIN, level); @@ -241,12 +242,12 @@ void init_pid(pid_params *pid){ pid->cd_1 = (2*pid->tau-pid->t)/(2*pid->tau+pid->t); pid->int_lim_max = 10*(float)CV_ARRAY_FLASH[51]; pid->int_lim_min = -10*(float)CV_ARRAY_FLASH[52]; - pid->k_ff = (float)CV_ARRAY_FLASH[46]/10000; // 0.005f; + pid->k_ff = (float)CV_ARRAY_FLASH[46]/10000; pid->max_output = (float)(_125M/(CV_ARRAY_FLASH[8]*100+10000)); pid->x_1_rev = 0.0f; pid->x_1_fwd = 0.0f; - pid->y_1_fwd = (float)get_16bit_CV(175); //(float)measure_base_pwm(pid,1); - pid->y_1_rev = (float)get_16bit_CV(177); //(float)measure_base_pwm(pid,0); + pid->y_1_fwd = (float)get_16bit_CV(175); + pid->y_1_rev = (float)get_16bit_CV(177); pid->x_2_rev = (float)pid->speed_table[126]; pid->x_2_fwd = (float)pid->speed_table[126]; diff --git a/shared.h b/shared.h index 572c8af..1652762 100644 --- a/shared.h +++ b/shared.h @@ -14,23 +14,27 @@ #include "hardware/adc.h" #include "hardware/flash.h" #include "hardware/irq.h" + +// Constant Value of 125 x 10⁶ #define _125M 125000000 + +// GPIO used for DCC-Signal, Motor PWM or ADC #define DCC_INPUT_PIN 21u #define MOTOR_FWD_PIN 23u #define MOTOR_REV_PIN 22u #define FWD_V_EMF_ADC_PIN 28u #define REV_V_EMF_ADC_PIN 29u -//Aux output pins (GPIO 24,25,26,27) -#define AUX_PIN_MASK (1u<<24) | (1u<<25) | (1u<<26) | (1u<<27) -//GPIO pins configured as inputs (Input functionality not implemented yet) -#define GPIO_INPUT_MASK 0b00000000000000000000000000000000 -//GPIO pins configured as outputs -#define GPIO_OUTPUT_MASK 0b00000000000000000000000000000000 -//GPIO pin mask to prevent setting illegal GPIOs (ADC, Motor, DCC Input Pin) + +// GPIO used directly (GPIO 0-5 incl.) as outputs or to switch auxiliary output transistors (GPIO 24-27 incl.) +#define GPIO_OUTPUT_PIN_MASK (1u<<24) | (1u<<25) | (1u<<26) | (1u<<27) | (1u<<5) | (1u<<4) | (1u<<3) | (1u<<2) | (1u<<1) | (1u<<0) +// GPIO pin mask to prevent setting illegal GPIOs (ADC, Motor, DCC Input Pin) #define GPIO_ILLEGAL_MASK (1u<