implemented first version of multi-splitflap, does not work yet

added initialized flag in splitflap.c
prepared RTOS (disabled temporarily)
main
Jonas Arnold 4 years ago
parent ce074fcd38
commit b7128dcf08
  1. 133
      ADIS_tinyK22_SplitFlap/source/application.c
  2. 46
      ADIS_tinyK22_SplitFlap/source/multi-splitflap.c
  3. 30
      ADIS_tinyK22_SplitFlap/source/multi-splitflap.h
  4. 3
      ADIS_tinyK22_SplitFlap/source/platform.c
  5. 9
      ADIS_tinyK22_SplitFlap/source/splitflap.c

@ -13,14 +13,19 @@
#include "McuULN2003.h"
#include "splitflap_pins.h"
#include "splitflap.h"
#include "multi-splitflap.h"
/* blue led pins */
#define LED_BLUE_GPIO GPIOC
#define LED_BLUE_PORT PORTC
#define LED_BLUE_PIN 2U
/* vars */
static McuLED_Handle_t LED_blue;
static SF_Handle_t splitflap0;
static SF_Handle_t splitflap0, splitflap1;
/* function declaration */
void configureSplitflaps(void);
/* Application initialization */
void App_Init(void){
@ -34,50 +39,31 @@ void App_Init(void){
config.hw.pin = LED_BLUE_PIN;
LED_blue = McuLED_InitLed(&config);
/* configure the motor */
McuULN2003_Config_t motor0Config;
McuULN2003_GetDefaultConfig(&motor0Config);
motor0Config.hw[0].gpio = STEPPER_MOTOR0_IN1_GPIO;
motor0Config.hw[0].port = STEPPER_MOTOR0_IN1_PORT;
motor0Config.hw[0].pin = STEPPER_MOTOR0_IN1_PIN;
motor0Config.hw[1].gpio = STEPPER_MOTOR0_IN2_GPIO;
motor0Config.hw[1].port = STEPPER_MOTOR0_IN2_PORT;
motor0Config.hw[1].pin = STEPPER_MOTOR0_IN2_PIN;
motor0Config.hw[2].gpio = STEPPER_MOTOR0_IN3_GPIO;
motor0Config.hw[2].port = STEPPER_MOTOR0_IN3_PORT;
motor0Config.hw[2].pin = STEPPER_MOTOR0_IN3_PIN;
motor0Config.hw[3].gpio = STEPPER_MOTOR0_IN4_GPIO;
motor0Config.hw[3].port = STEPPER_MOTOR0_IN4_PORT;
motor0Config.hw[3].pin = STEPPER_MOTOR0_IN4_PIN;
motor0Config.inverted = true;
/* configure magnetic sensor for motor 0 */
McuGPIO_Config_t magSensor0Config;
McuGPIO_GetDefaultConfig(&magSensor0Config);
magSensor0Config.hw.gpio = MAG_MOTOR0_GPIO;
magSensor0Config.hw.port = MAG_MOTOR0_PORT;
magSensor0Config.hw.pin = MAG_MOTOR0_PIN;
magSensor0Config.isInput = true;
magSensor0Config.hw.pull = McuGPIO_PULL_UP;
/* create config instance for splitflap 0 */
SF_Config_t sfConfig;
sfConfig.magSensorConfig = magSensor0Config;
sfConfig.motorConfig = motor0Config;
/* initialize splitflap 0 */
splitflap0 = SF_Init(&sfConfig, 0);
configureSplitflaps();
MultiSplitFlap_Init();
MultiSplitFlap_AddFlap(splitflap0);
MultiSplitFlap_AddFlap(splitflap1);
}
/* Application run */
void App_Run(void){
char* sentence[] = {"JONAS!"};
MultiSplitFlap_Display(sentence);
PRINTF("Initializing split flap motors.\n");
bool successfulInit = SF_MoveMotorToZeroPosition(splitflap0, 12);
PRINTF("Init of motors done. Success = %s\n\n", successfulInit ? "true" : "false");
bool successfulInit0 = SF_MoveMotorToZeroPosition(splitflap0, 12);
PRINTF("Init of motor 0 done. Success = %s\n\n", successfulInit0 ? "true" : "false");
// if init failed => stop
if(successfulInit == false){
if(successfulInit0 == false){
return;
}
bool successfulInit1 = SF_MoveMotorToZeroPosition(splitflap1, 12);
PRINTF("Init of motor 1 done. Success = %s\n\n", successfulInit1 ? "true" : "false");
// if init failed => stop
if(successfulInit1 == false){
return;
}
@ -104,3 +90,76 @@ void App_Run(void){
void App_Deinit(void){
}
void configureSplitflaps(void){
/* SPLITFLAP 0 */
/* configure the motor */
McuULN2003_Config_t motor0Config;
McuULN2003_GetDefaultConfig(&motor0Config);
motor0Config.hw[0].gpio = STEPPER_MOTOR0_IN1_GPIO;
motor0Config.hw[0].port = STEPPER_MOTOR0_IN1_PORT;
motor0Config.hw[0].pin = STEPPER_MOTOR0_IN1_PIN;
motor0Config.hw[1].gpio = STEPPER_MOTOR0_IN2_GPIO;
motor0Config.hw[1].port = STEPPER_MOTOR0_IN2_PORT;
motor0Config.hw[1].pin = STEPPER_MOTOR0_IN2_PIN;
motor0Config.hw[2].gpio = STEPPER_MOTOR0_IN3_GPIO;
motor0Config.hw[2].port = STEPPER_MOTOR0_IN3_PORT;
motor0Config.hw[2].pin = STEPPER_MOTOR0_IN3_PIN;
motor0Config.hw[3].gpio = STEPPER_MOTOR0_IN4_GPIO;
motor0Config.hw[3].port = STEPPER_MOTOR0_IN4_PORT;
motor0Config.hw[3].pin = STEPPER_MOTOR0_IN4_PIN;
motor0Config.inverted = true;
/* configure magnetic sensor for motor 0 */
McuGPIO_Config_t magSensor0Config;
McuGPIO_GetDefaultConfig(&magSensor0Config);
magSensor0Config.hw.gpio = MAG_MOTOR0_GPIO;
magSensor0Config.hw.port = MAG_MOTOR0_PORT;
magSensor0Config.hw.pin = MAG_MOTOR0_PIN;
magSensor0Config.isInput = true;
magSensor0Config.hw.pull = McuGPIO_PULL_UP;
/* create config instance for splitflap 0 */
SF_Config_t sf0Config;
sf0Config.magSensorConfig = magSensor0Config;
sf0Config.motorConfig = motor0Config;
/* initialize splitflap 0 */
splitflap0 = SF_Init(&sf0Config, 0);
/* SPLITFLAP 1 */
/* configure the motor */
McuULN2003_Config_t motor1Config;
McuULN2003_GetDefaultConfig(&motor1Config);
motor1Config.hw[0].gpio = STEPPER_MOTOR1_IN1_GPIO;
motor1Config.hw[0].port = STEPPER_MOTOR1_IN1_PORT;
motor1Config.hw[0].pin = STEPPER_MOTOR1_IN1_PIN;
motor1Config.hw[1].gpio = STEPPER_MOTOR1_IN2_GPIO;
motor1Config.hw[1].port = STEPPER_MOTOR1_IN2_PORT;
motor1Config.hw[1].pin = STEPPER_MOTOR1_IN2_PIN;
motor1Config.hw[2].gpio = STEPPER_MOTOR1_IN3_GPIO;
motor1Config.hw[2].port = STEPPER_MOTOR1_IN3_PORT;
motor1Config.hw[2].pin = STEPPER_MOTOR1_IN3_PIN;
motor1Config.hw[3].gpio = STEPPER_MOTOR1_IN4_GPIO;
motor1Config.hw[3].port = STEPPER_MOTOR1_IN4_PORT;
motor1Config.hw[3].pin = STEPPER_MOTOR1_IN4_PIN;
motor1Config.inverted = true;
/* configure magnetic sensor for motor 0 */
McuGPIO_Config_t magSensor1Config;
McuGPIO_GetDefaultConfig(&magSensor1Config);
magSensor1Config.hw.gpio = MAG_MOTOR1_GPIO;
magSensor1Config.hw.port = MAG_MOTOR1_PORT;
magSensor1Config.hw.pin = MAG_MOTOR1_PIN;
magSensor1Config.isInput = true;
magSensor1Config.hw.pull = McuGPIO_PULL_UP;
/* create config instance for splitflap 0 */
SF_Config_t sf1Config;
sf1Config.magSensorConfig = magSensor1Config;
sf1Config.motorConfig = motor1Config;
/* initialize splitflap 1 */
splitflap1 = SF_Init(&sf1Config, 1);
}

@ -0,0 +1,46 @@
/*
* multi-splitflap.c
*
* Created on: 07.10.2022
* Author: jonas
*/
#include "multi-splitflap.h"
#include "fsl_debug_console.h"
static dict_t **flapDict;
static uint8_t amountOfFlaps = 0;
void MultiSplitFlap_Init(void){
amountOfFlaps = 0;
flapDict = dictAlloc();
((dict_t*)flapDict)->key=NULL;
((dict_t*)flapDict)->value=NULL;
((dict_t*)flapDict)->next=NULL;
}
void MultiSplitFlap_Deinit(void){
dictDealoc(flapDict);
amountOfFlaps = 0;
}
uint8_t MultiSplitFlap_GetAmountOfSplitFlaps(void){
return amountOfFlaps;
}
void MultiSplitFlap_AddFlap(SF_Handle_t splitflap){
PRINTF("Adding split flap to multi splitflap combination:\n");
addItem(flapDict, (char*)&amountOfFlaps, (SF_Handle_t*)splitflap);
//TODO probably starting with 0 does not work since its a pointer to the number 0
PRINTF("Added flap nr. %i. There are now %i flaps.\n", amountOfFlaps, ++amountOfFlaps);
}
void MultiSplitFlap_Display(char* sentence[]){
SF_Handle_t* sfHandle0 = (SF_Handle_t*)(getItem(*flapDict, (char*)0));
SF_Handle_t* sfHandle1 = (SF_Handle_t*)(getItem(*flapDict, (char*)1));
SF_t* sf0 = (SF_t*)sfHandle0;
SF_t* sf1 = (SF_t*)sfHandle1;
int32_t test = McuULN2003_GetPos(sf1->motor);
}

@ -0,0 +1,30 @@
/*
* multi-splitflap.h
*
* Created on: 07.10.2022
* Author: jonas
*/
#ifndef MULTI_SPLITFLAP_H_
#define MULTI_SPLITFLAP_H_
#include "splitflap.h"
/* initialize dictionary */
void MultiSplitFlap_Init(void);
/* de-initialize: deallocate memory etc. */
void MultiSplitFlap_Deinit(void);
/* add a splitflap to the combination */
void MultiSplitFlap_AddFlap(SF_Handle_t splitflap);
/* display a sentence on the splitflap combination
* splitflaps must be initialized to be able to display something!*/
void MultiSplitFlap_Display(char* sentence[]);
/* returns the amount of registered split flap displays in the combination */
uint8_t MultiSplitFlap_GetAmountOfSplitFlaps(void);
#endif /* MULTI_SPLITFLAP_H_ */

@ -12,6 +12,7 @@
#include "McuGPIO.h"
#include "McuULN2003.h"
#include "splitflap.h"
#include "McuRTOS.h"
void PL_Init(void){
@ -26,10 +27,12 @@ void PL_Init(void){
McuLED_Init();
McuULN2003_Init();
SF_InitConfig();
//McuRTOS_Init();
}
void PL_Deinit(void){
//McuRTOS_Deinit();
SF_DeInitConfig();
McuULN2003_Deinit();
McuLED_Deinit();

@ -20,6 +20,8 @@ static char* SF_Letters[] = { " ", "A", "B", "C", "D", "E", "F", "G", "H", "I",
"L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"!", "?", ":"};
/* flag if this module is initialized (physically) */
static bool initialized = false;
void SF_InitConfig(void){
splitFlapDict = dictAlloc();
@ -86,10 +88,13 @@ bool SF_MoveMotorToZeroPosition(SF_Handle_t instance, uint16_t offsetSteps){
McuULN2003_PowerOff(((SF_t*)instance)->motor);
// success if less than one rotation
return numStepsMoved < SPLITFLAP_STEPS_ONE_ROUND;
initialized = (numStepsMoved < SPLITFLAP_STEPS_ONE_ROUND);
return initialized;
}
void SF_MoveSteps(SF_Handle_t instance, uint32_t steps){
if(initialized){
// run move with acceleration & deceleration
McuULN2003_AccelerationStart(((SF_t*)instance)->motor);
while(steps>0){
@ -104,6 +109,7 @@ void SF_MoveSteps(SF_Handle_t instance, uint32_t steps){
// required since it is possible that one is still active, which would result in the motor getting hot
// no re-init is required
McuULN2003_PowerOff(((SF_t*)instance)->motor);
}
}
bool SF_GetMagSensorAtZeroPosition(SF_Handle_t instance){
@ -135,4 +141,5 @@ int32_t SF_GetMotorPosition(SF_Handle_t instance){
void SF_Deinit(SF_Handle_t instance){
McuULN2003_DeinitMotor(((SF_t*)instance)->motor);
McuGPIO_DeinitGPIO(((SF_t*)instance)->magSensor);
initialized = false;
}

Loading…
Cancel
Save