form of HeloWorld_IHM04A1
Dependencies: FastPWM mbed ST_INTERFACES
Fork of HelloWorld_IHM04A1 by
Revision 6:b9b32d6c2b40, committed 2017-03-24
- Comitter:
- davide.aliprandi@st.com
- Date:
- Fri Mar 24 11:00:26 2017 +0100
- Parent:
- 5:4c1e581bbb8b
- Child:
- 7:20ff5668f5fe
- Commit message:
- Aligning to ARM mbed coding style.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Jun 15 12:51:03 2016 +0000
+++ b/main.cpp Fri Mar 24 11:00:26 2017 +0100
@@ -1,6 +1,6 @@
/**
******************************************************************************
- * @file Multi/Examples/MotionControl/IHM04A1_ExampleFor4UniDirMotors/Src/main.c
+ * @file main.cpp
* @author IPC Rennes
* @version V1.0.0
* @date May 16, 2016
@@ -40,34 +40,31 @@
******************************************************************************
*/
+
/* Includes ------------------------------------------------------------------*/
/* mbed specific header files. */
#include "mbed.h"
/* Component specific header files. */
-#include "l6206_class.h"
-
+#include "L6206.h"
/* Definitions ---------------------------------------------------------------*/
-
#define MAX_MOTOR (4)
-
/* Variables -----------------------------------------------------------------*/
static volatile uint16_t gLastError;
static volatile uint8_t gStep = 0;
-
/* Variables -----------------------------------------------------------------*/
/* Initialization parameters. */
-L6206_Init_t init =
+L6206_init_t init =
{
L6206_CONF_PARAM_PARALLE_BRIDGES,
{L6206_CONF_PARAM_FREQ_PWM1A, L6206_CONF_PARAM_FREQ_PWM2A, L6206_CONF_PARAM_FREQ_PWM1B, L6206_CONF_PARAM_FREQ_PWM2B},
@@ -81,8 +78,7 @@
L6206 *motor;
/* User button on Nucleo board */
-InterruptIn mybutton_irq(USER_BUTTON);
-
+InterruptIn my_button_irq(USER_BUTTON);
/* Functions -----------------------------------------------------------------*/
@@ -92,7 +88,7 @@
* @param error number of the error
* @retval None
*/
-void Error_Handler(uint16_t error)
+void my_error_handler(uint16_t error)
{
/* Backup error number */
gLastError = error;
@@ -105,40 +101,36 @@
* @param None
* @retval None
* @note If needed, implement it, and then attach and enable it:
-* + motor->AttachFlagInterrupt(MyFlagInterruptHandler);
+* + motor->attach_flag_interrupt(my_flag_irq_handler);
*/
-void MyFlagInterruptHandler(void)
+void my_flag_irq_handler(void)
{
/* Code to be customised */
/************************/
/* Get the state of bridge A */
- uint16_t bridgeState = motor->GetBridgeStatus(0);
+ uint16_t bridgeState = motor->get_bridge_status(0);
- if (bridgeState == 0)
- {
- if ((motor->GetDeviceState(0) != INACTIVE)||
- (motor->GetDeviceState(1) != INACTIVE))
- {
+ if (bridgeState == 0) {
+ if ((motor->get_device_state(0) != INACTIVE)||
+ (motor->get_device_state(1) != INACTIVE)) {
/* Bridge A was disabling due to overcurrent or over temperature */
/* When at least on of its motor was running */
- Error_Handler(0XBAD0);
+ my_error_handler(0XBAD0);
}
}
/* Get the state of bridge B */
- bridgeState = motor->GetBridgeStatus(1);
+ bridgeState = motor->get_bridge_status(1);
- if (bridgeState == 0)
- {
- if ((motor->GetDeviceState(2) != INACTIVE)||
- (motor->GetDeviceState(3) != INACTIVE))
- {
+ if (bridgeState == 0) {
+ if ((motor->get_device_state(2) != INACTIVE)||
+ (motor->get_device_state(3) != INACTIVE)) {
/* Bridge A was disabling due to overcurrent or over temperature */
/* When at least on of its motor was running */
- Error_Handler(0XBAD1);
+ my_error_handler(0XBAD1);
}
}
- }
+}
/* Private functions ---------------------------------------------------------*/
@@ -149,17 +141,15 @@
* @retval None
*/
-void button_pressed(void)
+void my_button_pressed(void)
{
- mybutton_irq.disable_irq();
+ my_button_irq.disable_irq();
gStep++;
- if (gStep > MAX_MOTOR)
- {
+ if (gStep > MAX_MOTOR) {
gStep = 0;
}
wait_ms(200);
- mybutton_irq.enable_irq();
-
+ my_button_irq.enable_irq();
}
@@ -175,90 +165,81 @@
/* Initializing Motor Control Component. */
motor = new L6206( D2, A4, D5, D4, A0, A1);
- /* When Init method is called with NULL pointer, the L6206 parameters are set */
+ /* When init method is called with NULL pointer, the L6206 parameters are set */
/* with the predefined values from file l6206_target_config.h, otherwise the */
- /* parameters are set using the initDeviceParameters structure values. */
- if (motor->Init(&init) != COMPONENT_OK)
+ /* parameters are set using the init structure values. */
+ if (motor->init(&init) != COMPONENT_OK) {
exit(EXIT_FAILURE);
+ }
- /* Attach the function MyFlagInterruptHandler (defined below) to the flag interrupt */
- motor->AttachFlagInterrupt(MyFlagInterruptHandler);
+ /* Attach the function my_flag_irq_handler (defined below) to the flag interrupt */
+ motor->attach_flag_interrupt(my_flag_irq_handler);
- /* Attach the function Error_Handler (defined below) to the error Handler*/
- motor->AttachErrorHandler(Error_Handler);
+ /* Attach the function my_error_handler (defined below) to the error Handler*/
+ motor->attach_error_handler(my_error_handler);
/* Printing to the console. */
printf("Motor Control Application Example for 4 Motor\r\n\n");
-
/* Select the configuration with no bridge paralleling, two unidirectionnal motors on bridge A
and two unidirectionnal motors on bridge B */
- motor->SetDualFullBridgeConfig(PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B);
+ motor->set_dual_full_bridge_config(PARALLELING_NONE___2_UNDIR_MOTOR_BRIDGE_A__2_UNDIR_MOTOR_BRIDGE_B);
/* Set PWM Frequency of bridge A inputs to 1000 Hz */
- motor->SetBridgeInputPwmFreq(0,1000);
+ motor->set_bridge_input_pwm_freq(0,1000);
/* Set PWM Frequency of bridge B inputs to 2000 Hz */
- motor->SetBridgeInputPwmFreq(1,2000);
+ motor->set_bridge_input_pwm_freq(1,2000);
- // Attach button_pressed function to Irq
- mybutton_irq.fall(&button_pressed);
+ // Attach my_button_pressed function to Irq
+ my_button_irq.fall(&my_button_pressed);
/* Infinite loop */
- while(1)
- {
+ while (true) {
- if (gStep > 0)
- {
- printf("Run motor 0 at 20%% of the maximum speed\n");
+ if (gStep > 0) {
+ printf("run motor 0 at 20%% of the maximum speed\n");
/* Set speed of motor 0 to 20% */
- motor->SetSpeed(0,20);
+ motor->set_speed(0,20);
/* start motor 0 */
- motor->Run(0, BDCMotor::FWD);
+ motor->run(0, BDCMotor::FWD);
}
- if (gStep > 1)
- {
- printf("Run motor 1 at 30%% of the maximum speed\n");
+ if (gStep > 1) {
+ printf("run motor 1 at 30%% of the maximum speed\n");
/* Set speed of motor 1 to 30 % */
- motor->SetSpeed(1,30);
+ motor->set_speed(1,30);
/* start motor 1 */
- motor->Run(1, BDCMotor::FWD);
+ motor->run(1, BDCMotor::FWD);
}
- if (gStep > 2)
- {
- printf("Run motor 2 at 40%% of the maximum speed\n");
+ if (gStep > 2) {
+ printf("run motor 2 at 40%% of the maximum speed\n");
/* Set speed of motor 2 to 40 % */
- motor->SetSpeed(2,40);
+ motor->set_speed(2,40);
/* start motor 2 */
- motor->Run(2, BDCMotor::FWD);
+ motor->run(2, BDCMotor::FWD);
}
- if (gStep > 3)
- {
- printf("Run motor 3 at 50%% of the maximum speed\n");
+ if (gStep > 3) {
+ printf("run motor 3 at 50%% of the maximum speed\n");
/* Set speed of motor 3 to 50 % */
- motor->SetSpeed(3,50);
+ motor->set_speed(3,50);
/* start motor 3 */
- motor->Run(3, BDCMotor::FWD);
+ motor->run(3, BDCMotor::FWD);
}
- if (gStep > 0)
- {
+ if (gStep > 0) {
wait_ms(1000);
- motor->HardHiZ(0);
- motor->HardHiZ(1);
- motor->HardHiZ(2);
- motor->HardHiZ(3);
+ motor->hard_hiz(0);
+ motor->hard_hiz(1);
+ motor->hard_hiz(2);
+ motor->hard_hiz(3);
wait_ms(1000);
}
}
}
-
-
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
