added support for 4 splitflaps

main
Jonas Arnold 4 years ago
parent 3cecb08708
commit 1078a71fca
  1. 112
      ADIS_tinyK22_SplitFlap/source/application.c
  2. 6
      ADIS_tinyK22_SplitFlap/source/multi-splitflap.c
  3. 5
      ADIS_tinyK22_SplitFlap/source/multi-splitflap.h
  4. 34
      ADIS_tinyK22_SplitFlap/source/splitflap_pins.h

@ -23,10 +23,12 @@
#define LED_BLUE_PORT PORTC
#define LED_BLUE_PIN 2U
/* number of splitflaps that are connected / used. max 4. */
#define NUM_SF_USED 2
/* vars */
static McuLED_Handle_t LED_blue;
static SF_Handle_t splitflap0, splitflap1;
static SF_Handle_t splitflap[NUM_SF_USED];
static uint32_t taskParameter1 = 5;
static TaskHandle_t appTaskHandle = NULL;
@ -46,9 +48,17 @@ void App_Init(void){
LED_blue = McuLED_InitLed(&config);
configureSplitflaps();
MultiSplitFlap_Init(2);
MultiSplitFlap_AddFlap(splitflap0);
MultiSplitFlap_AddFlap(splitflap1);
MultiSplitFlap_Init(NUM_SF_USED);
MultiSplitFlap_AddFlap(splitflap[0]);
#if (NUM_SF_USED > 1)
MultiSplitFlap_AddFlap(splitflap[1]);
#endif
#if (NUM_SF_USED > 2)
MultiSplitFlap_AddFlap(splitflap[2]);
#endif
#if (NUM_SF_USED > 3)
MultiSplitFlap_AddFlap(splitflap[3]);
#endif
}
/* App Task */
@ -120,9 +130,9 @@ static void App_Task(void* pv){
while(1){
for(int i = 0; i < sizeof(letters)/sizeof(letters[0]); i++){
McuWait_Waitms(1000);
McuLog_info("Moving to letter '%s', position is %i", letters[i], (int)SF_GetMotorPosition(splitflap0));
SF_MoveToFlap(splitflap0, letters[i]);
McuLog_info("Position after move is is %i", (int)SF_GetMotorPosition(splitflap0));
McuLog_info("Moving to letter '%s', position is %i", letters[i], (int)SF_GetMotorPosition(splitflap[0]));
SF_MoveToFlap(splitflap[0], letters[i]);
McuLog_info("Position after move is is %i", (int)SF_GetMotorPosition(splitflap[0]));
}
}
}
@ -190,8 +200,9 @@ void configureSplitflaps(void){
sf0Config.motorConfig = motor0Config;
/* instanciate splitflap 0 */
splitflap0 = SF_Init(&sf0Config);
splitflap[0] = SF_Init(&sf0Config);
#if (NUM_SF_USED > 1)
/* SPLITFLAP 1 */
/* configure the motor */
McuULN2003_Config_t motor1Config;
@ -210,7 +221,7 @@ void configureSplitflaps(void){
motor1Config.hw[3].pin = STEPPER_MOTOR1_IN4_PIN;
motor1Config.inverted = true;
/* configure magnetic sensor for motor 0 */
/* configure magnetic sensor for motor 1 */
McuGPIO_Config_t magSensor1Config;
McuGPIO_GetDefaultConfig(&magSensor1Config);
magSensor1Config.hw.gpio = MAG_MOTOR1_GPIO;
@ -219,7 +230,7 @@ void configureSplitflaps(void){
magSensor1Config.isInput = true;
magSensor1Config.hw.pull = McuGPIO_PULL_UP;
/* create config instance for splitflap 0 */
/* create config instance for splitflap 1 */
SF_Config_t sf1Config;
sf1Config.setupIdentifier = 1;
sf1Config.hardwareIdentifier = 20; // default value
@ -227,5 +238,84 @@ void configureSplitflaps(void){
sf1Config.motorConfig = motor1Config;
/* instanciate splitflap 1 */
splitflap1 = SF_Init(&sf1Config);
splitflap[1] = SF_Init(&sf1Config);
#endif
#if (NUM_SF_USED > 2)
/* SPLITFLAP 2 */
/* configure the motor */
McuULN2003_Config_t motor2Config;
McuULN2003_GetDefaultConfig(&motor2Config);
motor2Config.hw[0].gpio = STEPPER_MOTOR2_IN1_GPIO;
motor2Config.hw[0].port = STEPPER_MOTOR2_IN1_PORT;
motor2Config.hw[0].pin = STEPPER_MOTOR2_IN1_PIN;
motor2Config.hw[1].gpio = STEPPER_MOTOR2_IN2_GPIO;
motor2Config.hw[1].port = STEPPER_MOTOR2_IN2_PORT;
motor2Config.hw[1].pin = STEPPER_MOTOR2_IN2_PIN;
motor2Config.hw[2].gpio = STEPPER_MOTOR2_IN3_GPIO;
motor2Config.hw[2].port = STEPPER_MOTOR2_IN3_PORT;
motor2Config.hw[2].pin = STEPPER_MOTOR2_IN3_PIN;
motor2Config.hw[3].gpio = STEPPER_MOTOR2_IN4_GPIO;
motor2Config.hw[3].port = STEPPER_MOTOR2_IN4_PORT;
motor2Config.hw[3].pin = STEPPER_MOTOR2_IN4_PIN;
motor2Config.inverted = true;
/* configure magnetic sensor for motor 2 */
McuGPIO_Config_t magSensor2Config;
McuGPIO_GetDefaultConfig(&magSensor2Config);
magSensor2Config.hw.gpio = MAG_MOTOR2_GPIO;
magSensor2Config.hw.port = MAG_MOTOR2_PORT;
magSensor2Config.hw.pin = MAG_MOTOR2_PIN;
magSensor2Config.isInput = true;
magSensor2Config.hw.pull = McuGPIO_PULL_UP;
/* create config instance for splitflap 2 */
SF_Config_t sf2Config;
sf2Config.setupIdentifier = 1;
sf2Config.hardwareIdentifier = 20; // default value
sf2Config.magSensorConfig = magSensor2Config;
sf2Config.motorConfig = motor2Config;
/* instanciate splitflap 2 */
splitflap[2] = SF_Init(&sf2Config);
#endif
#if (NUM_SF_USED > 3)
/* SPLITFLAP 3 */
/* configure the motor */
McuULN2003_Config_t motor3Config;
McuULN2003_GetDefaultConfig(&motor3Config);
motor3Config.hw[0].gpio = STEPPER_MOTOR3_IN1_GPIO;
motor3Config.hw[0].port = STEPPER_MOTOR3_IN1_PORT;
motor3Config.hw[0].pin = STEPPER_MOTOR3_IN1_PIN;
motor3Config.hw[1].gpio = STEPPER_MOTOR3_IN2_GPIO;
motor3Config.hw[1].port = STEPPER_MOTOR3_IN2_PORT;
motor3Config.hw[1].pin = STEPPER_MOTOR3_IN2_PIN;
motor3Config.hw[2].gpio = STEPPER_MOTOR3_IN3_GPIO;
motor3Config.hw[2].port = STEPPER_MOTOR3_IN3_PORT;
motor3Config.hw[2].pin = STEPPER_MOTOR3_IN3_PIN;
motor3Config.hw[3].gpio = STEPPER_MOTOR3_IN4_GPIO;
motor3Config.hw[3].port = STEPPER_MOTOR3_IN4_PORT;
motor3Config.hw[3].pin = STEPPER_MOTOR3_IN4_PIN;
motor3Config.inverted = true;
/* configure magnetic sensor for motor 3 */
McuGPIO_Config_t magSensor3Config;
McuGPIO_GetDefaultConfig(&magSensor3Config);
magSensor3Config.hw.gpio = MAG_MOTOR3_GPIO;
magSensor3Config.hw.port = MAG_MOTOR3_PORT;
magSensor3Config.hw.pin = MAG_MOTOR3_PIN;
magSensor3Config.isInput = true;
magSensor3Config.hw.pull = McuGPIO_PULL_UP;
/* create config instance for splitflap 3 */
SF_Config_t sf3Config;
sf3Config.setupIdentifier = 1;
sf3Config.hardwareIdentifier = 20; // default value
sf3Config.magSensorConfig = magSensor3Config;
sf3Config.motorConfig = motor3Config;
/* instanciate splitflap 3 */
splitflap[3] = SF_Init(&sf3Config);
#endif
}

@ -16,7 +16,7 @@
static dict_t **flapDict;
static uint8_t addedFlaps = 0;
static const uint8_t BYTES_PER_KEY = 3;
static char* flapKeys[NUM_FLAPS]; // reserve memory
static char* flapKeys[10]; // TODO improve
/* function declarations */
void initFlapKeys(uint8_t numberOfFlaps);
@ -24,13 +24,13 @@ void initFlapKeys(uint8_t numberOfFlaps);
/**********************/
/* INIT / DEINIT */
/**********************/
void MultiSplitFlap_Init(){
void MultiSplitFlap_Init(uint8_t numFlaps){
addedFlaps = 0;
flapDict = dictAlloc();
((dict_t*)flapDict)->key=NULL;
((dict_t*)flapDict)->value=NULL;
((dict_t*)flapDict)->next=NULL;
initFlapKeys(NUM_FLAPS);
initFlapKeys(numFlaps);
}
void MultiSplitFlap_Deinit(void){

@ -12,8 +12,9 @@
#define NUM_FLAPS 2 // Number of flaps that can be added to the combination
/* initialize dictionary */
void MultiSplitFlap_Init();
/* initialize dictionary.
* numFlaps: Amount of flaps to be used*/
void MultiSplitFlap_Init(uint8_t numFlaps);
/* de-initialize: deallocate memory etc. */
void MultiSplitFlap_Deinit(void);

@ -59,6 +59,38 @@
#define STEPPER_MOTOR1_IN4_PORT PORTA
#define STEPPER_MOTOR1_IN4_PIN 12U
/* TODO define motors 2 and 3 */
/* motor 2 */
#define STEPPER_MOTOR2_IN1_GPIO GPIOD
#define STEPPER_MOTOR2_IN1_PORT PORTD
#define STEPPER_MOTOR2_IN1_PIN 4U
#define STEPPER_MOTOR2_IN2_GPIO GPIOD
#define STEPPER_MOTOR2_IN2_PORT PORTD
#define STEPPER_MOTOR2_IN2_PIN 5U
#define STEPPER_MOTOR2_IN3_GPIO GPIOD
#define STEPPER_MOTOR2_IN3_PORT PORTD
#define STEPPER_MOTOR2_IN3_PIN 6U
#define STEPPER_MOTOR2_IN4_GPIO GPIOD
#define STEPPER_MOTOR2_IN4_PORT PORTD
#define STEPPER_MOTOR2_IN4_PIN 7U
/* motor 3 */
#define STEPPER_MOTOR3_IN1_GPIO GPIOD
#define STEPPER_MOTOR3_IN1_PORT PORTD
#define STEPPER_MOTOR3_IN1_PIN 0U
#define STEPPER_MOTOR3_IN2_GPIO GPIOD
#define STEPPER_MOTOR3_IN2_PORT PORTD
#define STEPPER_MOTOR3_IN2_PIN 1U
#define STEPPER_MOTOR3_IN3_GPIO GPIOD
#define STEPPER_MOTOR3_IN3_PORT PORTD
#define STEPPER_MOTOR3_IN3_PIN 2U
#define STEPPER_MOTOR3_IN4_GPIO GPIOD
#define STEPPER_MOTOR3_IN4_PORT PORTD
#define STEPPER_MOTOR3_IN4_PIN 3U
#endif /* SPLITFLAP_PINS_H_ */

Loading…
Cancel
Save