Hello guys, again here I am with some newbiee questions.
I'm trying to tiding up a bit of code, and I want to simplify the code by defining actions so I can call them and erase some repetition.
I commented the next bit of code so you could see if what I'm trying to do is correct or not.
I'm using KEIL uVision 5 and running the code in a STM32F103C8
// I'm pretty sure that this is correct, is a define just to know which pin is connected to the stteper motor
#define StepperA GPIO_PIN_9
#define StepperB GPIO_PIN_8
#define StepperC GPIO_PIN_7
#define StepperD GPIO_PIN_6
#define StepperE GPIO_PIN_5
// This is what I'm NOT sure if is wright, I have seen this done is some libraries in the past, but never exactly like this, so can you tell me is this is ok?
#define StepperInit (HAL_GPIO_WritePin(GPIOB, StepperA, GPIO_PIN_RESET),HAL_GPIO_WritePin(GPIOB, StepperB, GPIO_PIN_SET),HAL_GPIO_WritePin(GPIOB, StepperC, GPIO_PIN_SET),HAL_GPIO_WritePin(GPIOB, StepperD, GPIO_PIN_SET))
#define StepperP1 (HAL_GPIO_WritePin(GPIOB, StepperA, GPIO_PIN_SET),HAL_GPIO_WritePin(GPIOB, StepperB, GPIO_PIN_RESET),HAL_GPIO_WritePin(GPIOB, StepperC, GPIO_PIN_SET),HAL_GPIO_WritePin(GPIOB, StepperD, GPIO_PIN_SET))
#define StepperP2 (HAL_GPIO_WritePin(GPIOB, StepperA, GPIO_PIN_SET),HAL_GPIO_WritePin(GPIOB, StepperB, GPIO_PIN_RESET),HAL_GPIO_WritePin(GPIOB, StepperC, GPIO_PIN_RESET),HAL_GPIO_WritePin(GPIOB, StepperD, GPIO_PIN_RESET))
#define StepperP3 (HAL_GPIO_WritePin(GPIOB, StepperA, GPIO_PIN_RESET),HAL_GPIO_WritePin(GPIOB, StepperB, GPIO_PIN_SET),HAL_GPIO_WritePin(GPIOB, StepperC, GPIO_PIN_RESET),HAL_GPIO_WritePin(GPIOB, StepperD, GPIO_PIN_RESET))
// Again, of this I'm pretty sure that works
#define StepperE_H (HAL_GPIO_WritePin(GPIOB, StepperE, GPIO_PIN_SET))
#define StepperE_L (HAL_GPIO_WritePin(GPIOB, StepperE, GPIO_PIN_RESET))
// Then in the rest of the code, I would use it like this for example:
//Init Stepper Motor
StepperE_H; // Enable HIGH
StepperInit; // Init A,B,C,D
HAL_Delay(1);
StepperE_L; // Enable LOW
So, please can you help me to know if the definition of multiple GPIO set and reset lines can be done in a single line of a #define ?