add SplitFlap project (does not compile yet)

main
Jonas Arnold 4 years ago
parent a92e1c0fc9
commit 92f99dfb58
  1. 77
      ADIS_tinyK22_SplitFlap/source/application.c
  2. 11
      ADIS_tinyK22_SplitFlap/source/application.h
  3. 17
      ADIS_tinyK22_SplitFlap/source/main.c
  4. 30
      ADIS_tinyK22_SplitFlap/source/platform.c
  5. 18
      ADIS_tinyK22_SplitFlap/source/platform.h
  6. 26
      ADIS_tinyK22_SplitFlap/source/splitflap.c
  7. 34
      ADIS_tinyK22_SplitFlap/source/splitflap.h
  8. 64
      ADIS_tinyK22_SplitFlap/source/splitflap_pins.h

@ -5,30 +5,79 @@
* Author: jonas
*/
#include "application.h"
#include "fsl_gpio.h"
#include "pin_mux.h"
#include "McuWait.h"
#include "McuLED.h"
#include "McuGPIO.h"
#include "McuULN2003.h"
#include "splitflap_pins.h"
#include "splitflap.h"
/* manual method, without McuWait:
static void delay(void)
{
uint32_t i;
/* blue led pins */
#define LED_BLUE_GPIO GPIOC
#define LED_BLUE_PORT PORTC
#define LED_BLUE_PIN 2U
for (i = 0; i < 500000; ++i) {
__asm volatile ("nop");
}
}
*/
static McuLED_Handle_t LED_blue;
static SF_Handle_t splitflap0;
/* Application initialization */
void App_Init(void){
McuWait_Init();
/* configure blue LED */
McuLED_Config_t config;
McuLED_GetDefaultConfig(&config);
config.isLowActive = true;
config.isOnInit = false;
config.hw.gpio = LED_BLUE_GPIO;
config.hw.port = LED_BLUE_PORT;
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);
}
/* Application run */
void App_Run(void){
while(1) {
GPIO_PortToggle(BOARD_INITPINS_LED_BLUE_GPIO, BOARD_INITPINS_LED_BLUE_GPIO_PIN_MASK);
McuLED_Toggle(LED_blue);
McuWait_Waitms(100); /* wait for 100 ms */
}
}
/* Application de-initialization */
void App_Deinit(void){
}

@ -8,8 +8,19 @@
#ifndef APPLICATION_H_
#define APPLICATION_H_
#include "splitflap_pins.h"
#define LED_BLUE_GPIO GPIOC
#define LED_BLUE_PORT PORTC
#define LED_BLUE_PIN 2U
/* Application initialization */
void App_Init(void);
/* Application run */
void App_Run(void);
/* Application de-initialization */
void App_Deinit(void);
#endif /* APPLICATION_H_ */

@ -41,6 +41,7 @@
#include "fsl_debug_console.h"
/* TODO: insert other include files here. */
#include "application.h"
#include "platform.h"
/* TODO: insert other definitions and declarations here. */
@ -58,11 +59,25 @@ int main(void) {
BOARD_InitDebugConsole();
#endif
PRINTF("Hello World\n");
/* init platform */
PRINTF("Initializing Platform...\n");
PL_Init();
/* init app */
PRINTF("Initializing App...\n");
App_Init();
/* run app */
PRINTF("Running App...\n");
App_Run();
/* deinit app */
//PRINTF("De-Initializing App...\n");
//App_Deinit();
/* deinit platform */
PRINTF("De-Initializing Platform...\n");
PL_Deinit();
return 0 ;
}

@ -0,0 +1,30 @@
/*
* platform.c
*
* Created on: 29.09.2022
* Author: jonas
*/
#include "platform.h"
#include "McuLib.h"
#include "McuWait.h"
#include "McuLED.h"
#include "McuGPIO.h"
#include "McuULN2003.h"
void PL_Init(void){
McuLib_Init();
McuWait_Init();
McuGPIO_Init();
McuLED_Init();
McuULN2003_Init();
}
void PL_Deinit(void){
McuULN2003_Deinit();
McuLED_Deinit();
McuGPIO_Deinit();
McuWait_Deinit();
McuLib_Deinit();
}

@ -0,0 +1,18 @@
/*
* platform.h
*
* Created on: 29.09.2022
* Author: jonas
*/
#ifndef PLATFORM_H_
#define PLATFORM_H_
/* Platform initialization */
void PL_Init(void);
/* Platform de-initialization */
void PL_Deinit(void);
#endif /* PLATFORM_H_ */

@ -0,0 +1,26 @@
/*
* splitflap.c
*
* Created on: 29.09.2022
* Author: jonas
*/
#include "splitflap.h"
#include "McuULN2003.h"
SF_Handle_t SF_Init(SF_Config_t* instance, int id){
SF_t splitflap;
splitflap.magSensor = McuGPIO_InitGPIO(&instance->magSensorConfig);
splitflap.motor = McuULN2003_InitMotor(&instance->motorConfig);
splitflap.id = id;
return &splitflap;
}
void SF_Deinit(SF_t* instance){
McuULN2003_DeinitMotor(&instance->motorConfig);
McuGPIO_DeinitGPIO(&instance->magSensorConfig);
}

@ -0,0 +1,34 @@
/*
* splitflap.h
*
* Created on: 29.09.2022
* Author: jonas
*/
#ifndef SPLITFLAP_H_
#define SPLITFLAP_H_
#include "McuULN2003.h"
#include "McuGPIO.h"
/* define splitflap handle type. SF_Handle_t points to SF_t */
typedef void* SF_Handle_t;
typedef struct {
McuULN2003_Handle_t motor;
McuGPIO_Handle_t magSensor;
int id;
} SF_t;
typedef struct {
McuULN2003_Config_t motorConfig;
McuGPIO_Config_t magSensorConfig;
} SF_Config_t;
/* split flap initialization */
SF_Handle_t SF_Init(SF_Config_t* instance, int id);
/* split flap deinitialization */
void SF_Deinit(SF_Handle_t* instance);
#endif /* SPLITFLAP_H_ */

@ -0,0 +1,64 @@
/*
* splitflap_pins.h
*
* Created on: 29.09.2022
* Author: jonas
*/
#ifndef SPLITFLAP_PINS_H_
#define SPLITFLAP_PINS_H_
/* Magnet sensor */
#define MAG_MOTOR0_GPIO GPIOB
#define MAG_MOTOR0_PORT PORTB
#define MAG_MOTOR0_PIN 19U
#define MAG_MOTOR1_GPIO GPIOB
#define MAG_MOTOR1_PORT PORTB
#define MAG_MOTOR1_PIN 18U
#define MAG_MOTOR2_GPIO GPIOA
#define MAG_MOTOR2_PORT PORTA
#define MAG_MOTOR2_PIN 13U
#define MAG_MOTOR3_GPIO GPIOB
#define MAG_MOTOR3_PORT PORTB
#define MAG_MOTOR3_PIN 3U
/* motor 0 */
#define STEPPER_MOTOR0_IN1_GPIO GPIOC
#define STEPPER_MOTOR0_IN1_PORT PORTC
#define STEPPER_MOTOR0_IN1_PIN 11U
#define STEPPER_MOTOR0_IN2_GPIO GPIOC
#define STEPPER_MOTOR0_IN2_PORT PORTC
#define STEPPER_MOTOR0_IN2_PIN 10U
#define STEPPER_MOTOR0_IN3_GPIO GPIOC
#define STEPPER_MOTOR0_IN3_PORT PORTC
#define STEPPER_MOTOR0_IN3_PIN 9U
#define STEPPER_MOTOR0_IN4_GPIO GPIOC
#define STEPPER_MOTOR0_IN4_PORT PORTC
#define STEPPER_MOTOR0_IN4_PIN 8U
/* motor 1 */
#define STEPPER_MOTOR1_IN1_GPIO GPIOA
#define STEPPER_MOTOR1_IN1_PORT PORTA
#define STEPPER_MOTOR1_IN1_PIN 1U
#define STEPPER_MOTOR1_IN2_GPIO GPIOA
#define STEPPER_MOTOR1_IN2_PORT PORTA
#define STEPPER_MOTOR1_IN2_PIN 2U
#define STEPPER_MOTOR1_IN3_GPIO GPIOA
#define STEPPER_MOTOR1_IN3_PORT PORTA
#define STEPPER_MOTOR1_IN3_PIN 5U
#define STEPPER_MOTOR1_IN4_GPIO GPIOA
#define STEPPER_MOTOR1_IN4_PORT PORTA
#define STEPPER_MOTOR1_IN4_PIN 12U
/* TODO define motors 2 and 3 */
#endif /* SPLITFLAP_PINS_H_ */
Loading…
Cancel
Save